functions.php 9.9 KB

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