functions.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <?php
  2. function gwp24_styles() {
  3. wp_enqueue_style(
  4. 'gwp-style',
  5. get_stylesheet_uri(),
  6. [],
  7. wp_get_theme()->get( 'Version' )
  8. );
  9. }
  10. add_action( 'wp_enqueue_scripts', 'gwp24_styles' );
  11. /***********************************************************
  12. ######################## GForms ############################
  13. ************************************************************/
  14. function gwp24_add_gf_capabilities(){
  15. $role = get_role( 'editor' );
  16. $role->add_cap( 'gform_full_access' );
  17. }
  18. add_action( 'admin_init', 'gwp24_add_gf_capabilities' );
  19. add_filter( 'gform_upload_path', 'gwp24_change_upload_path', 10, 2 );
  20. function gwp24_change_upload_path( $path_info, $form_id ) {
  21. $path_info['path'] = '/var/www/greenwoodpromise.com/html/wp-content/uploads/_apps/';
  22. $path_info['url'] = 'https://greenwoodpromise.com/wp-content/uploads/_apps/';
  23. return $path_info;
  24. }
  25. /***********************************************************
  26. ###################### BrowserSync #########################
  27. ************************************************************/
  28. function add_cors_http_header(){
  29. header('Access-Control-Allow-Origin: https://gwp.ovid:333');
  30. header('Access-Control-Allow-Credentials: true');
  31. header('Access-Control-Allow-Headers: X-WP-Nonce', false );
  32. }
  33. add_action('init','add_cors_http_header');
  34. function gwp24_browsersync_save() {
  35. $args = [
  36. 'blocking' => false,
  37. 'sslverify' => false
  38. ];
  39. $request = wp_remote_get('https://gwp.ovid:333/__browser_sync__?method=reload', $args);
  40. }
  41. add_action('rest_after_insert_page', 'gwp24_browsersync_save', 10, 3);
  42. add_action('rest_after_insert_post', 'gwp24_browsersync_save', 10, 3);
  43. add_action('save_post', 'gwp24_browsersync_save', 10, 3);
  44. add_action('customize_save_after', 'gwp24_browsersync_save', 10, 3);
  45. add_action('wp_update_nav_menu', 'gwp24_browsersync_save', 10, 3);
  46. add_action('updated_option', 'gwp24_browsersync_save', 10, 3);
  47. /***********************************************************
  48. ######################## Old Site ##########################
  49. ************************************************************/
  50. function gwp24_enqueue_assets() {
  51. wp_enqueue_script ( 'site-js', get_template_directory_uri() . '/js/site.js' );
  52. wp_enqueue_style( 'site-css', get_template_directory_uri() . '/css/site.css');
  53. }
  54. add_action( 'wp_enqueue_scripts', 'gwp24_enqueue_assets' );
  55. //remove_theme_support( 'block-templates' );
  56. add_theme_support( 'block-template-parts' );
  57. //remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
  58. //remove_action( 'wp_footer', 'wp_enqueue_global_styles', 1 );
  59. add_action( 'init', 'dwp23_disable_emojis' );
  60. function dwp23_disable_emojis() {
  61. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  62. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  63. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  64. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  65. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  66. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  67. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  68. add_filter( 'emoji_svg_url', '__return_false' );
  69. }
  70. /***********************************************************
  71. ######################## Editor ############################
  72. ************************************************************/
  73. add_theme_support('disable-custom-colors');
  74. //add_action( 'enqueue_block_assets', 'gwp24_block_styles', 5 );
  75. function gwp24_block_styles(){
  76. wp_enqueue_style('gwp24-css', get_stylesheet_directory_uri() . '/css/site.css');
  77. }
  78. add_action( 'admin_enqueue_scripts', 'gwp24_admin_styles' );
  79. function gwp24_admin_styles() {
  80. wp_enqueue_style( 'style-editor', get_template_directory_uri().'/style-editor.css' );
  81. }
  82. remove_theme_support( 'core-block-patterns' );
  83. add_filter( 'should_load_remote_block_patterns', 'gwp24_disable_remote_patterns' );
  84. function gwp24_disable_remote_patterns() {
  85. return false;
  86. }
  87. add_filter(
  88. 'block_editor_settings_all',
  89. function( $settings ) {
  90. $settings['enableOpenverseMediaCategory'] = false;
  91. return $settings;
  92. },
  93. 10
  94. );
  95. //add_filter( 'allowed_block_types_all', 'gwp24_allowed_block_types', 25, 2 );
  96. function gwp24_allowed_block_types( $allowed_blocks, $editor_context ) {
  97. return array(
  98. 'core/paragraph',
  99. 'core/heading',
  100. 'core/list',
  101. 'core/list-item',
  102. 'core/table',
  103. 'core/columns',
  104. 'core/column',
  105. 'core/image',
  106. 'core/gallery',
  107. 'core/cover',
  108. 'core/quote',
  109. 'core/file',
  110. 'core/video',
  111. 'core/audio',
  112. 'core/separator',
  113. 'core/spacer',
  114. 'core/shortcode',
  115. 'core/html',
  116. 'core/freeform',
  117. 'core/verse',
  118. 'core/code',
  119. 'core/preformatted',
  120. 'core/pullquote',
  121. 'core/button',
  122. 'core/buttons',
  123. 'core/media-text',
  124. 'core/more',
  125. 'core/nextpage',
  126. 'core/group',
  127. 'core/heading',
  128. 'core/subhead',
  129. 'core/text-columns',
  130. 'core/row',
  131. 'core/post-list',
  132. );
  133. }
  134. /***********************************************************
  135. ######################## Blocks ############################
  136. ************************************************************/
  137. function gwp24_restrict_locking_ui( $settings, $context ) {
  138. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  139. return $settings;
  140. }
  141. add_filter( 'block_editor_settings_all', 'gwp24_restrict_locking_ui', 10, 2 );
  142. /***********************************************************
  143. ######################### Admin ############################
  144. ************************************************************/
  145. add_filter('admin_title', 'gwp24_admin_title', 10, 2);
  146. function gwp24_admin_title($admin_title, $title) {
  147. return $title .' - '. get_bloginfo('name');
  148. }
  149. add_filter ('update_footer', 'gwp24_footer_ver', 999);
  150. function gwp24_footer_ver ($default) {
  151. return ''. get_bloginfo( 'version' );
  152. }
  153. add_filter ('admin_footer_text', 'gwp24_footer_filter');
  154. function gwp24_footer_filter ($default) {
  155. return '';
  156. }
  157. add_action('admin_head', 'mytheme_remove_help_tabs');
  158. function mytheme_remove_help_tabs() {
  159. $screen = get_current_screen();
  160. $screen->remove_help_tabs();
  161. }
  162. add_action( 'admin_head-profile.php', 'gwp24_remove_admin_color' );
  163. function gwp24_remove_admin_color() {
  164. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  165. }
  166. add_action( 'init', 'gwp24_admin_post_labels' );
  167. function gwp24_admin_post_labels() {
  168. global $wp_post_types;
  169. $labels = &$wp_post_types['post']->labels;
  170. $labels->name = 'News';
  171. $labels->singular_name = 'News';
  172. $labels->add_new = 'Add News';
  173. $labels->add_new_item = 'Add News';
  174. $labels->edit_item = 'Edit News';
  175. $labels->new_item = 'News';
  176. $labels->view_item = 'View News';
  177. $labels->search_items = 'Search News';
  178. $labels->not_found = 'No News found';
  179. $labels->not_found_in_trash = 'No News found in Trash';
  180. $labels->all_items = 'All News';
  181. $labels->menu_name = 'News';
  182. $labels->name_admin_bar = 'News';
  183. }
  184. /***********************************************************
  185. ####################### Admin Bar ##########################
  186. ************************************************************/
  187. add_filter( 'show_admin_bar', '__return_false' );
  188. add_action( 'admin_bar_menu', 'gwp24_remove_adminbar', 999 );
  189. function gwp24_remove_adminbar( $wp_admin_bar ) {
  190. $wp_admin_bar->remove_node( 'wp-logo' );
  191. $wp_admin_bar->remove_node( 'updates' );
  192. $wp_admin_bar->remove_menu('comments');
  193. $wp_admin_bar->remove_menu('customize');
  194. $wp_admin_bar->remove_menu('new-content');
  195. $wp_admin_bar->remove_menu( 'edit' );
  196. $wp_admin_bar->remove_menu( 'new-user' );
  197. $wp_admin_bar->remove_menu( 'new-post' );
  198. $wp_admin_bar->remove_menu( 'new-page' );
  199. $wp_admin_bar->remove_node( 'new-media' );
  200. $wp_admin_bar->remove_node( 'view-site' );
  201. }
  202. add_filter( 'gettext', 'gwp24_change_howdy_text', 10, 2 );
  203. function gwp24_change_howdy_text( $translation, $original ) {
  204. if( 'Howdy, %1$s' == $original )
  205. $translation = '%1$s';
  206. return $translation;
  207. }
  208. /* for email */
  209. add_filter( 'gettext', 'gwp24_change_howdy_text', 10, 2 );
  210. function gwp24_change_howdy_text( $translation, $original ) {
  211. if( 'Howdy, %1$s' == $original )
  212. $translation = '%1$s';
  213. return $translation;
  214. }
  215. /***********************************************************
  216. #################### Admin Menus ###########################
  217. ************************************************************/
  218. add_action('admin_menu', function () {
  219. remove_menu_page('edit-comments.php');
  220. });
  221. add_filter( 'custom_menu_order', 'gwp24_menu_order' );
  222. add_filter( 'menu_order', 'gwp24_menu_order' );
  223. function gwp24_menu_order( $menu_order ) {
  224. if (!$menu_order) return true;
  225. return array(
  226. 'index.php',
  227. 'separator1',
  228. 'edit.php?post_type=page',
  229. 'edit.php',
  230. 'edit-comments.php',
  231. 'separator2',
  232. 'upload.php',
  233. 'theme-settings',
  234. 'themes.php',
  235. 'plugins.php',
  236. 'tools.php',
  237. 'users.php',
  238. 'separator-last'
  239. );
  240. }
  241. add_filter( 'gform_menu_position', 'gwp23_gform_menu_position', 10, 1 );
  242. function gwp23_gform_menu_position( $position ) {
  243. return 15;
  244. }
  245. //add_action('wp_dashboard_setup', 'gwp24_remove_dashboard_widgets' );
  246. function gwp24_remove_dashboard_widgets() {
  247. remove_meta_box( 'rg_forms_dashboard', 'dashboard', 'side' );
  248. }
  249. add_filter('screen_options_show_screen', '__return_false');
  250. add_action( 'admin_menu', 'gwp24_remove_admin_pages', 99 );
  251. function gwp24_remove_admin_pages() {
  252. global $current_user;
  253. $user_id = get_current_user_id();
  254. if($user_id != '1') {
  255. remove_menu_page('plugins.php');
  256. remove_menu_page('tools.php');
  257. remove_menu_page('options-general.php');
  258. remove_menu_page('gutenberg');
  259. remove_menu_page('users.php');
  260. remove_submenu_page('themes.php', 'themes-editor.php');
  261. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  262. remove_submenu_page( 'themes.php', 'themes.php' );
  263. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  264. remove_submenu_page( 'themes.php', 'theme_options' );
  265. remove_submenu_page('gf_edit_forms', 'gf_new_form');
  266. remove_submenu_page('gf_edit_forms', 'gf_export');
  267. remove_submenu_page('gf_edit_forms', 'gf_addons');
  268. remove_submenu_page('gf_edit_forms', 'gf_settings');
  269. remove_submenu_page('gf_edit_forms', 'gf_help');
  270. remove_submenu_page('gf_edit_forms', 'gf_system_status');
  271. }
  272. }
  273. /***********************************************************
  274. ###################### Dashboard ###########################
  275. ************************************************************/
  276. add_action( 'wp_dashboard_setup', 'gwp24_disable_dashboard_items' );
  277. function gwp24_disable_dashboard_items() {
  278. remove_action('admin_notices', 'update_nag');
  279. remove_action( 'welcome_panel', 'wp_welcome_panel' );
  280. remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
  281. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  282. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  283. remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
  284. }
  285. //add_filter( 'screen_options_show_screen', '__return_false' );
  286. /***********************************************************
  287. ###################### Last Login ##########################
  288. ************************************************************/
  289. add_action( 'wp_login', 'gwp24_login_timestamp', 20, 2 );
  290. function gwp24_login_timestamp( $user_login, $user ) {
  291. update_user_meta( $user->ID, 'last_login', time() );
  292. }
  293. add_filter( 'manage_users_columns', 'gwp24_user_last_login_column' );
  294. function gwp24_user_last_login_column( $columns ) {
  295. $columns['last_login'] = 'Last Login'; // column ID / column Title
  296. return $columns;
  297. }
  298. add_filter( 'manage_users_custom_column', 'gwp24_last_login_column', 10, 3 );
  299. function gwp24_last_login_column( $output, $column_id, $user_id ){
  300. if( $column_id == 'last_login' ) {
  301. $last_login = get_user_meta( $user_id, 'last_login', true );
  302. $date_format = 'j M, Y';
  303. $output = $last_login ? date( $date_format, $last_login ) : '-';
  304. }
  305. return $output;
  306. }
  307. add_filter( 'manage_users_sortable_columns', 'gwp24_sortable_columns' );
  308. function gwp24_sortable_columns( $columns ) {
  309. return wp_parse_args( array(
  310. 'last_login' => 'last_login'
  311. ), $columns );
  312. }
  313. add_action( 'pre_get_users', 'gwp24_sort_last_login_column' );
  314. function gwp24_sort_last_login_column( $query ) {
  315. if( !is_admin() ) { return; }
  316. $orderby = $query->get('orderby');
  317. if( 'last_login' == $orderby ) {
  318. $query->set('meta_key','last_login');
  319. $query->set('orderby','meta_value');
  320. }
  321. return $query;
  322. }
  323. /***********************************************************
  324. ###################### Log in/out ##########################
  325. ************************************************************/
  326. add_filter( 'wp_nav_menu_items', 'gwp24_loginout_menu_link', 10, 2 );
  327. function gwp24_loginout_menu_link( $items, $args ) {
  328. if ($args->theme_location == 'bottom') {
  329. if (is_user_logged_in()) {
  330. $items .= '<li class="nav-item"><a class="navbar-brand" href="'. wp_logout_url() .'"><i class="bi bi-person-circle fs-5"></i></a></li>';
  331. } else {
  332. $items .= '<li class="nav-item"><a class="navbar-brand" href="'. wp_login_url() .'"><i class="bi bi-person-circle fs-5"></i></a></li>';
  333. }
  334. }
  335. return $items;
  336. }
  337. add_action( 'login_enqueue_scripts', 'gwp24_login_logo' );
  338. function gwp24_login_logo() {
  339. $logo_image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
  340. ?>
  341. <style type="text/css">
  342. #login h1 a, .login h1 a {
  343. background-image: url(<?php echo esc_url( $logo_image[0] ); ?>);
  344. }
  345. body.login {
  346. background-color: #006837 !important;
  347. }
  348. .login #nav a {
  349. color: #E9E4DC !important;
  350. }
  351. .login #backtoblog a {
  352. display: none !important;
  353. }
  354. </style>
  355. <?php }
  356. add_filter( 'login_headerurl', 'gwp24_login_url' );
  357. function gwp24_login_url() { return home_url(); }
  358. add_filter( 'login_headertext', 'gwp24_login_title' );
  359. function gwp24_login_title() { return get_option( 'blogname' ); }
  360. /***********************************************************
  361. ######################## Header ############################
  362. ************************************************************/
  363. add_action( 'init', 'gwp24_cleaner_header' );
  364. function gwp24_cleaner_header() {
  365. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  366. remove_action('wp_head', 'wlwmanifest_link');
  367. remove_action('wp_head', 'rsd_link');
  368. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  369. remove_action('wp_head', 'wp_generator');
  370. remove_action('wp_head', 'feed_links_extra', 3 );
  371. remove_action('wp_head', 'feed_links', 2 );
  372. }
  373. add_action( 'wp_head', 'gwp24_favicon', 100 );
  374. function gwp24_favicon() {
  375. echo '<link rel="icon" href="' . esc_url( get_stylesheet_directory_uri() . '/img/_gwp_icon.svg' ) . '" type="image/svg+xml">';
  376. }
  377. add_action('wp_head', 'gwp24_add_analytics');
  378. function gwp24_add_analytics() { ?>
  379. <script async src="https://www.googletagmanager.com/gtag/js?id=G-53FCS3FYTN"></script>
  380. <script>
  381. window.dataLayer = window.dataLayer || [];
  382. function gtag(){dataLayer.push(arguments);}
  383. gtag('js', new Date());
  384. gtag('config', 'G-53FCS3FYTN');
  385. </script>
  386. <?php }
  387. /***********************************************************
  388. ####################### Comments ###########################
  389. ************************************************************/
  390. add_filter('comments_open', '__return_false', 20, 2);
  391. add_filter('pings_open', '__return_false', 20, 2);
  392. add_action('admin_init','gwp24_disable_comments');
  393. function gwp24_disable_comments() {
  394. $post_types = get_post_types();
  395. foreach ($post_types as $post_type) {
  396. if(post_type_supports($post_type,'comments')) {
  397. remove_post_type_support($post_type,'comments');
  398. remove_post_type_support($post_type,'trackbacks');
  399. }
  400. }
  401. }
  402. /***********************************************************
  403. ##################### SVG ##########################
  404. ************************************************************/
  405. // Allow SVG
  406. add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
  407. global $wp_version;
  408. if ( $wp_version !== '4.7.1' ) {
  409. return $data;
  410. }
  411. $filetype = wp_check_filetype( $filename, $mimes );
  412. return [
  413. 'ext' => $filetype['ext'],
  414. 'type' => $filetype['type'],
  415. 'proper_filename' => $data['proper_filename']
  416. ];
  417. }, 10, 4 );
  418. function cc_mime_types( $mimes ){
  419. $mimes['svg'] = 'image/svg+xml';
  420. return $mimes;
  421. }
  422. add_filter( 'upload_mimes', 'cc_mime_types' );
  423. function fix_svg() {
  424. echo '<style type="text/css">
  425. .attachment-266x266, .thumbnail img {
  426. width: 100% !important;
  427. height: auto !important;
  428. }
  429. </style>';
  430. }
  431. add_action( 'admin_head', 'fix_svg' );