functions.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. function lps24_enqueue_assets() {
  3. wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css');
  4. }
  5. add_action( 'wp_enqueue_scripts', 'lps24_enqueue_assets' );
  6. /***********************************************************
  7. ###################### BrowserSync #########################
  8. ************************************************************/
  9. function add_cors_http_header(){
  10. header('Access-Control-Allow-Origin: https://lps.ovid:333');
  11. header('Access-Control-Allow-Credentials: true');
  12. header('Access-Control-Allow-Headers: X-WP-Nonce', false );
  13. }
  14. add_action('init','add_cors_http_header');
  15. function lps24_browsersync_save() {
  16. $args = [
  17. 'blocking' => false,
  18. 'sslverify' => false
  19. ];
  20. $request = wp_remote_get('https://lps.ovid:333/__browser_sync__?method=reload', $args);
  21. }
  22. add_action('rest_after_insert_page', 'lps24_browsersync_save', 10, 3);
  23. add_action('rest_after_insert_post', 'lps24_browsersync_save', 10, 3);
  24. add_action('save_post', 'lps24_browsersync_save', 10, 3);
  25. add_action('customize_save_after', 'lps24_browsersync_save', 10, 3);
  26. add_action('wp_update_nav_menu', 'lps24_browsersync_save', 10, 3);
  27. add_action('updated_option', 'lps24_browsersync_save', 10, 3);
  28. /***********************************************************
  29. ######################### Admin ############################
  30. ************************************************************/
  31. add_filter( 'show_admin_bar', '__return_false' );
  32. add_action( 'admin_bar_menu', 'lps24_remove_adminbar', 999 );
  33. function lps24_remove_adminbar( $wp_admin_bar ) {
  34. $wp_admin_bar->remove_node('wp-logo');
  35. $wp_admin_bar->remove_node('updates');
  36. $wp_admin_bar->remove_menu('comments');
  37. $wp_admin_bar->remove_menu('customize');
  38. $wp_admin_bar->remove_menu('new-content');
  39. $wp_admin_bar->remove_menu('edit');
  40. $wp_admin_bar->remove_menu('new-user');
  41. $wp_admin_bar->remove_menu('new-post');
  42. $wp_admin_bar->remove_menu('new-page');
  43. $wp_admin_bar->remove_node('new-media');
  44. $wp_admin_bar->remove_node('view-site');
  45. }
  46. add_filter( 'custom_menu_order', 'lps24_menu_order' );
  47. add_filter( 'menu_order', 'lps24_menu_order' );
  48. function lps24_menu_order( $menu_order ) {
  49. if (!$menu_order) return true;
  50. return array(
  51. 'index.php',
  52. 'separator1',
  53. 'edit.php?post_type=page',
  54. 'edit.php',
  55. 'edit-comments.php',
  56. 'separator2',
  57. 'upload.php',
  58. 'theme-settings',
  59. 'themes.php',
  60. 'plugins.php',
  61. 'tools.php',
  62. 'users.php',
  63. 'separator-last'
  64. );
  65. }
  66. add_action( 'admin_menu', 'lps24_remove_admin_pages', 99 );
  67. function lps24_remove_admin_pages() {
  68. global $current_user;
  69. $user_id = get_current_user_id();
  70. if($user_id != '0') {
  71. remove_menu_page('plugins.php');
  72. remove_menu_page('tools.php');
  73. remove_menu_page('options-general.php');
  74. remove_menu_page('gutenberg');
  75. remove_menu_page('users.php');
  76. remove_submenu_page('themes.php', 'themes-editor.php');
  77. remove_submenu_page( 'themes.php', 'customize.php?return=' . urlencode($_SERVER['SCRIPT_NAME']));
  78. remove_submenu_page( 'themes.php', 'themes.php' );
  79. remove_submenu_page( 'themes.php', 'theme-editor.php' );
  80. remove_submenu_page( 'themes.php', 'theme_options' );
  81. remove_submenu_page('gf_edit_forms', 'gf_new_form');
  82. remove_submenu_page('gf_edit_forms', 'gf_export');
  83. remove_submenu_page('gf_edit_forms', 'gf_addons');
  84. remove_submenu_page('gf_edit_forms', 'gf_settings');
  85. remove_submenu_page('gf_edit_forms', 'gf_help');
  86. remove_submenu_page('gf_edit_forms', 'gf_system_status');
  87. }
  88. }
  89. add_action( 'wp_dashboard_setup', 'lps24_disable_dashboard_items' );
  90. function lps24_disable_dashboard_items() {
  91. remove_action('admin_notices', 'update_nag');
  92. remove_action('welcome_panel', 'wp_welcome_panel');
  93. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  94. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  95. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  96. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  97. }
  98. add_filter('admin_title', 'lps24_admin_title', 10, 2);
  99. function lps24_admin_title($admin_title, $title) {
  100. return $title .' - '. get_bloginfo('name');
  101. }
  102. add_filter ('admin_footer_text', 'lps24_footer_filter');
  103. function lps24_footer_filter ($default) {
  104. return '';
  105. }
  106. add_filter('gettext', 'lps24_replace_howdy', 10, 3);
  107. function lps24_replace_howdy($translated_text, $text, $domain) {
  108. $new_message = str_replace('Howdy,', '', $text);
  109. return $new_message;
  110. }
  111. add_filter( 'gettext', 'lps24_change_howdy_text', 10, 2 );
  112. function lps24_change_howdy_text( $translation, $original ) {
  113. if( 'Howdy, %1$s' == $original )
  114. $translation = '%1$s';
  115. return $translation;
  116. }
  117. add_action( 'admin_head-profile.php', 'lps24_remove_admin_color' );
  118. function lps24_remove_admin_color() {
  119. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  120. }
  121. add_action('admin_head', 'lps24_remove_help_tabs');
  122. function lps24_remove_help_tabs() {
  123. $screen = get_current_screen();
  124. $screen->remove_help_tabs();
  125. }
  126. add_filter('site_url', 'lps24_wplogin_filter', 10, 3);
  127. function lps24_wplogin_filter( $url, $path, $orig_scheme ) {
  128. $old = array( "/(wp-login\.php)/");
  129. $new = array( "SRH");
  130. return preg_replace( $old, $new, $url, 1);
  131. }
  132. add_filter( 'login_headerurl', 'lps24_login_url' );
  133. function lps24_login_url() { return home_url(); }
  134. add_filter( 'login_headertext', 'lps24_login_title' );
  135. function lps24_login_title() { return get_option( 'blogname' ); }
  136. add_action( 'login_enqueue_scripts', 'lps24_login_logo' );
  137. function lps24_login_logo() {
  138. $logo_image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' );
  139. ?>
  140. <style type="text/css">
  141. #login h1 a, .login h1 a {
  142. background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/_site-icon.png) !important;
  143. }
  144. body.login {
  145. background-color: #001A40 !important;
  146. }
  147. .wp-core-ui .button-primary {
  148. background: #19458c !important;
  149. border-color: #001A40 !important;
  150. }
  151. .wp-core-ui .button-primary.focus,
  152. .wp-core-ui .button-primary.hover,
  153. .wp-core-ui .button-primary:focus,
  154. .wp-core-ui .button-primary:hover {
  155. background: #001A40 !important;
  156. border-color: #001A40 !important;
  157. }
  158. .login #nav a {
  159. color: #E9E4DC !important;
  160. }
  161. .login #backtoblog a {
  162. display: none !important;
  163. }
  164. </style>
  165. <?php }
  166. /***********************************************************
  167. ####################### Comments ###########################
  168. ************************************************************/
  169. add_action('admin_menu', function () {
  170. remove_menu_page('edit-comments.php');
  171. });
  172. add_filter('comments_open', '__return_false', 20, 2);
  173. add_filter('pings_open', '__return_false', 20, 2);
  174. add_action('admin_init','lps24_disable_comments');
  175. function lps24_disable_comments() {
  176. $post_types = get_post_types();
  177. foreach ($post_types as $post_type) {
  178. if(post_type_supports($post_type,'comments')) {
  179. remove_post_type_support($post_type,'comments');
  180. remove_post_type_support($post_type,'trackbacks');
  181. }
  182. }
  183. }
  184. /***********************************************************
  185. ###################### Last Login ##########################
  186. ************************************************************/
  187. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  188. function lps24_login_timestamp( $user_login, $user ) {
  189. update_user_meta( $user->ID, 'last_login', time() );
  190. }
  191. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  192. function lps24_user_last_login_column( $columns ) {
  193. $columns['last_login'] = 'Last Login'; // column ID / column Title
  194. return $columns;
  195. }
  196. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  197. function lps24_last_login_column( $output, $column_id, $user_id ){
  198. if( $column_id == 'last_login' ) {
  199. $last_login = get_user_meta( $user_id, 'last_login', true );
  200. $date_format = 'j M, Y';
  201. $output = $last_login ? date( $date_format, $last_login ) : '-';
  202. }
  203. return $output;
  204. }
  205. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  206. function lps24_sortable_columns( $columns ) {
  207. return wp_parse_args( array(
  208. 'last_login' => 'last_login'
  209. ), $columns );
  210. }
  211. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  212. function lps24_sort_last_login_column( $query ) {
  213. if( !is_admin() ) { return; }
  214. $orderby = $query->get('orderby');
  215. if( 'last_login' == $orderby ) {
  216. $query->set('meta_key','last_login');
  217. $query->set('orderby','meta_value');
  218. }
  219. return $query;
  220. }
  221. /***********************************************************
  222. ######################## Blocks ############################
  223. ************************************************************/
  224. function lps24_restrict_locking_ui( $settings, $context ) {
  225. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  226. return $settings;
  227. }
  228. add_filter( 'block_editor_settings_all', 'lps24_restrict_locking_ui', 10, 2 );
  229. remove_theme_support( 'core-block-patterns' );
  230. add_filter( 'should_load_remote_block_patterns', 'lps24_disable_remote_patterns' );
  231. function lps24_disable_remote_patterns() {
  232. return false;
  233. }
  234. add_filter(
  235. 'block_editor_settings_all',
  236. function( $settings ) {
  237. $settings['enableOpenverseMediaCategory'] = false;
  238. return $settings;
  239. },
  240. 10
  241. );