functions.php 9.4 KB

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