functions.php 15 KB

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