functions.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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( 'admin_bar_menu', 'gwp24_replace_wordpress_howdy', 25 );
  203. function gwp24_replace_wordpress_howdy( $wp_admin_bar ) {
  204. $account = $wp_admin_bar->get_node('my-account');
  205. $newtext = str_replace( 'Howdy,', '', $account->title );
  206. $wp_admin_bar->add_node( array(
  207. 'id' => 'my-account',
  208. 'title' => $newtext,
  209. ));
  210. }
  211. /* for email */
  212. add_filter( 'gettext', 'gwp24_change_howdy_text', 10, 2 );
  213. function gwp24_change_howdy_text( $translation, $original ) {
  214. if( 'Howdy, %1$s' == $original )
  215. $translation = '%1$s';
  216. return $translation;
  217. }
  218. /***********************************************************
  219. #################### Admin Menus ###########################
  220. ************************************************************/
  221. add_action('admin_menu', function () {
  222. remove_menu_page('edit-comments.php');
  223. });
  224. add_filter( 'custom_menu_order', 'gwp24_menu_order' );
  225. add_filter( 'menu_order', 'gwp24_menu_order' );
  226. function gwp24_menu_order( $menu_order ) {
  227. if (!$menu_order) return true;
  228. return array(
  229. 'index.php',
  230. 'separator1',
  231. 'edit.php?post_type=page',
  232. 'edit.php',
  233. 'edit-comments.php',
  234. 'separator2',
  235. 'upload.php',
  236. 'theme-settings',
  237. 'themes.php',
  238. 'plugins.php',
  239. 'tools.php',
  240. 'users.php',
  241. 'separator-last'
  242. );
  243. }
  244. add_filter( 'gform_menu_position', 'gwp23_gform_menu_position', 10, 1 );
  245. function gwp23_gform_menu_position( $position ) {
  246. return 15;
  247. }
  248. //add_action('wp_dashboard_setup', 'gwp24_remove_dashboard_widgets' );
  249. function gwp24_remove_dashboard_widgets() {
  250. remove_meta_box( 'rg_forms_dashboard', 'dashboard', 'side' );
  251. }
  252. add_filter('screen_options_show_screen', '__return_false');
  253. add_action( 'admin_menu', 'gwp24_remove_admin_pages', 99 );
  254. function gwp24_remove_admin_pages() {
  255. global $current_user;
  256. $user_id = get_current_user_id();
  257. if($user_id != '1') {
  258. remove_menu_page('plugins.php');
  259. remove_menu_page('tools.php');
  260. remove_menu_page('options-general.php');
  261. remove_menu_page('gutenberg');
  262. remove_menu_page('users.php');
  263. remove_submenu_page('themes.php', 'themes-editor.php');
  264. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  265. remove_submenu_page( 'themes.php', 'themes.php' );
  266. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  267. remove_submenu_page( 'themes.php', 'theme_options' );
  268. remove_submenu_page('gf_edit_forms', 'gf_new_form');
  269. remove_submenu_page('gf_edit_forms', 'gf_export');
  270. remove_submenu_page('gf_edit_forms', 'gf_addons');
  271. remove_submenu_page('gf_edit_forms', 'gf_settings');
  272. remove_submenu_page('gf_edit_forms', 'gf_help');
  273. remove_submenu_page('gf_edit_forms', 'gf_system_status');
  274. }
  275. }
  276. /***********************************************************
  277. ###################### Dashboard ###########################
  278. ************************************************************/
  279. add_action( 'wp_dashboard_setup', 'gwp24_disable_dashboard_items' );
  280. function gwp24_disable_dashboard_items() {
  281. remove_action('admin_notices', 'update_nag');
  282. remove_action( 'welcome_panel', 'wp_welcome_panel' );
  283. remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
  284. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  285. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  286. remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
  287. }
  288. //add_filter( 'screen_options_show_screen', '__return_false' );
  289. /***********************************************************
  290. ###################### Last Login ##########################
  291. ************************************************************/
  292. add_action( 'wp_login', 'gwp24_login_timestamp', 20, 2 );
  293. function gwp24_login_timestamp( $user_login, $user ) {
  294. update_user_meta( $user->ID, 'last_login', time() );
  295. }
  296. add_filter( 'manage_users_columns', 'gwp24_user_last_login_column' );
  297. function gwp24_user_last_login_column( $columns ) {
  298. $columns['last_login'] = 'Last Login'; // column ID / column Title
  299. return $columns;
  300. }
  301. add_filter( 'manage_users_custom_column', 'gwp24_last_login_column', 10, 3 );
  302. function gwp24_last_login_column( $output, $column_id, $user_id ){
  303. if( $column_id == 'last_login' ) {
  304. $last_login = get_user_meta( $user_id, 'last_login', true );
  305. $date_format = 'j M, Y';
  306. $output = $last_login ? date( $date_format, $last_login ) : '-';
  307. }
  308. return $output;
  309. }
  310. add_filter( 'manage_users_sortable_columns', 'gwp24_sortable_columns' );
  311. function gwp24_sortable_columns( $columns ) {
  312. return wp_parse_args( array(
  313. 'last_login' => 'last_login'
  314. ), $columns );
  315. }
  316. add_action( 'pre_get_users', 'gwp24_sort_last_login_column' );
  317. function gwp24_sort_last_login_column( $query ) {
  318. if( !is_admin() ) { return; }
  319. $orderby = $query->get('orderby');
  320. if( 'last_login' == $orderby ) {
  321. $query->set('meta_key','last_login');
  322. $query->set('orderby','meta_value');
  323. }
  324. return $query;
  325. }
  326. /***********************************************************
  327. ###################### Log in/out ##########################
  328. ************************************************************/
  329. add_filter( 'wp_nav_menu_items', 'gwp24_loginout_menu_link', 10, 2 );
  330. function gwp24_loginout_menu_link( $items, $args ) {
  331. if ($args->theme_location == 'bottom') {
  332. if (is_user_logged_in()) {
  333. $items .= '<li class="nav-item"><a class="navbar-brand" href="'. wp_logout_url() .'"><i class="bi bi-person-circle fs-5"></i></a></li>';
  334. } else {
  335. $items .= '<li class="nav-item"><a class="navbar-brand" href="'. wp_login_url() .'"><i class="bi bi-person-circle fs-5"></i></a></li>';
  336. }
  337. }
  338. return $items;
  339. }
  340. add_action( 'login_enqueue_scripts', 'gwp24_login_logo' );
  341. function gwp24_login_logo() {
  342. $logo_image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
  343. ?>
  344. <style type="text/css">
  345. #login h1 a, .login h1 a {
  346. background-image: url(<?php echo esc_url( $logo_image[0] ); ?>);
  347. }
  348. body.login {
  349. background-color: #006837 !important;
  350. }
  351. .login #nav a {
  352. color: #E9E4DC !important;
  353. }
  354. .login #backtoblog a {
  355. display: none !important;
  356. }
  357. </style>
  358. <?php }
  359. add_filter( 'login_headerurl', 'gwp24_login_url' );
  360. function gwp24_login_url() { return home_url(); }
  361. add_filter( 'login_headertext', 'gwp24_login_title' );
  362. function gwp24_login_title() { return get_option( 'blogname' ); }
  363. /***********************************************************
  364. ######################## Header ############################
  365. ************************************************************/
  366. add_action( 'init', 'gwp24_cleaner_header' );
  367. function gwp24_cleaner_header() {
  368. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  369. remove_action('wp_head', 'wlwmanifest_link');
  370. remove_action('wp_head', 'rsd_link');
  371. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  372. remove_action('wp_head', 'wp_generator');
  373. remove_action('wp_head', 'feed_links_extra', 3 );
  374. remove_action('wp_head', 'feed_links', 2 );
  375. }
  376. add_action( 'wp_head', 'gwp24_favicon', 100 );
  377. function gwp24_favicon() {
  378. echo '<link rel="icon" href="' . esc_url( get_stylesheet_directory_uri() . '/img/_gwp_icon.svg' ) . '" type="image/svg+xml">';
  379. }
  380. add_action('wp_head', 'gwp24_add_analytics');
  381. function gwp24_add_analytics() { ?>
  382. <script async src="https://www.googletagmanager.com/gtag/js?id=G-53FCS3FYTN"></script>
  383. <script>
  384. window.dataLayer = window.dataLayer || [];
  385. function gtag(){dataLayer.push(arguments);}
  386. gtag('js', new Date());
  387. gtag('config', 'G-53FCS3FYTN');
  388. </script>
  389. <?php }
  390. /***********************************************************
  391. ####################### Comments ###########################
  392. ************************************************************/
  393. add_filter('comments_open', '__return_false', 20, 2);
  394. add_filter('pings_open', '__return_false', 20, 2);
  395. add_action('admin_init','gwp24_disable_comments');
  396. function gwp24_disable_comments() {
  397. $post_types = get_post_types();
  398. foreach ($post_types as $post_type) {
  399. if(post_type_supports($post_type,'comments')) {
  400. remove_post_type_support($post_type,'comments');
  401. remove_post_type_support($post_type,'trackbacks');
  402. }
  403. }
  404. }
  405. /***********************************************************
  406. ##################### SVG ##########################
  407. ************************************************************/
  408. // Allow SVG
  409. add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
  410. global $wp_version;
  411. if ( $wp_version !== '4.7.1' ) {
  412. return $data;
  413. }
  414. $filetype = wp_check_filetype( $filename, $mimes );
  415. return [
  416. 'ext' => $filetype['ext'],
  417. 'type' => $filetype['type'],
  418. 'proper_filename' => $data['proper_filename']
  419. ];
  420. }, 10, 4 );
  421. function cc_mime_types( $mimes ){
  422. $mimes['svg'] = 'image/svg+xml';
  423. return $mimes;
  424. }
  425. add_filter( 'upload_mimes', 'cc_mime_types' );
  426. function fix_svg() {
  427. echo '<style type="text/css">
  428. .attachment-266x266, .thumbnail img {
  429. width: 100% !important;
  430. height: auto !important;
  431. }
  432. </style>';
  433. }
  434. add_action( 'admin_head', 'fix_svg' );