functions.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. /***********************************************************
  127. ####################### Comments ###########################
  128. ************************************************************/
  129. add_action('admin_menu', function () {
  130. remove_menu_page('edit-comments.php');
  131. });
  132. add_filter('comments_open', '__return_false', 20, 2);
  133. add_filter('pings_open', '__return_false', 20, 2);
  134. add_action('admin_init','lps24_disable_comments');
  135. function lps24_disable_comments() {
  136. $post_types = get_post_types();
  137. foreach ($post_types as $post_type) {
  138. if(post_type_supports($post_type,'comments')) {
  139. remove_post_type_support($post_type,'comments');
  140. remove_post_type_support($post_type,'trackbacks');
  141. }
  142. }
  143. }
  144. /***********************************************************
  145. ###################### Last Login ##########################
  146. ************************************************************/
  147. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  148. function lps24_login_timestamp( $user_login, $user ) {
  149. update_user_meta( $user->ID, 'last_login', time() );
  150. }
  151. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  152. function lps24_user_last_login_column( $columns ) {
  153. $columns['last_login'] = 'Last Login'; // column ID / column Title
  154. return $columns;
  155. }
  156. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  157. function lps24_last_login_column( $output, $column_id, $user_id ){
  158. if( $column_id == 'last_login' ) {
  159. $last_login = get_user_meta( $user_id, 'last_login', true );
  160. $date_format = 'j M, Y';
  161. $output = $last_login ? date( $date_format, $last_login ) : '-';
  162. }
  163. return $output;
  164. }
  165. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  166. function lps24_sortable_columns( $columns ) {
  167. return wp_parse_args( array(
  168. 'last_login' => 'last_login'
  169. ), $columns );
  170. }
  171. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  172. function lps24_sort_last_login_column( $query ) {
  173. if( !is_admin() ) { return; }
  174. $orderby = $query->get('orderby');
  175. if( 'last_login' == $orderby ) {
  176. $query->set('meta_key','last_login');
  177. $query->set('orderby','meta_value');
  178. }
  179. return $query;
  180. }
  181. /***********************************************************
  182. ######################## Blocks ############################
  183. ************************************************************/
  184. function lps24_restrict_locking_ui( $settings, $context ) {
  185. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  186. return $settings;
  187. }
  188. add_filter( 'block_editor_settings_all', 'lps24_restrict_locking_ui', 10, 2 );
  189. remove_theme_support( 'core-block-patterns' );
  190. add_filter( 'should_load_remote_block_patterns', 'lps24_disable_remote_patterns' );
  191. function lps24_disable_remote_patterns() {
  192. return false;
  193. }
  194. add_filter(
  195. 'block_editor_settings_all',
  196. function( $settings ) {
  197. $settings['enableOpenverseMediaCategory'] = false;
  198. return $settings;
  199. },
  200. 10
  201. );