functions.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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://gwp.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( 'admin_bar_menu', 'lps24_replace_wordpress_howdy', 25 );
  107. function lps24_replace_wordpress_howdy( $wp_admin_bar ) {
  108. $account = $wp_admin_bar->get_node('my-account');
  109. $newtext = str_replace( 'Howdy,', '', $account->title );
  110. $wp_admin_bar->add_node( array(
  111. 'id' => 'my-account',
  112. 'title' => $newtext,
  113. ));
  114. }
  115. add_filter( 'gettext', 'lps24_change_howdy_text', 10, 2 );
  116. function lps24_change_howdy_text( $translation, $original ) {
  117. if( 'Howdy, %1$s' == $original )
  118. $translation = '%1$s';
  119. return $translation;
  120. }
  121. add_action( 'admin_head-profile.php', 'lps24_remove_admin_color' );
  122. function lps24_remove_admin_color() {
  123. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  124. }
  125. add_action('admin_head', 'lps24_remove_help_tabs');
  126. function lps24_remove_help_tabs() {
  127. $screen = get_current_screen();
  128. $screen->remove_help_tabs();
  129. }
  130. /***********************************************************
  131. ####################### Comments ###########################
  132. ************************************************************/
  133. add_action('admin_menu', function () {
  134. remove_menu_page('edit-comments.php');
  135. });
  136. add_filter('comments_open', '__return_false', 20, 2);
  137. add_filter('pings_open', '__return_false', 20, 2);
  138. add_action('admin_init','lps24_disable_comments');
  139. function lps24_disable_comments() {
  140. $post_types = get_post_types();
  141. foreach ($post_types as $post_type) {
  142. if(post_type_supports($post_type,'comments')) {
  143. remove_post_type_support($post_type,'comments');
  144. remove_post_type_support($post_type,'trackbacks');
  145. }
  146. }
  147. }
  148. /***********************************************************
  149. ###################### Last Login ##########################
  150. ************************************************************/
  151. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  152. function lps24_login_timestamp( $user_login, $user ) {
  153. update_user_meta( $user->ID, 'last_login', time() );
  154. }
  155. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  156. function lps24_user_last_login_column( $columns ) {
  157. $columns['last_login'] = 'Last Login'; // column ID / column Title
  158. return $columns;
  159. }
  160. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  161. function lps24_last_login_column( $output, $column_id, $user_id ){
  162. if( $column_id == 'last_login' ) {
  163. $last_login = get_user_meta( $user_id, 'last_login', true );
  164. $date_format = 'j M, Y';
  165. $output = $last_login ? date( $date_format, $last_login ) : '-';
  166. }
  167. return $output;
  168. }
  169. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  170. function lps24_sortable_columns( $columns ) {
  171. return wp_parse_args( array(
  172. 'last_login' => 'last_login'
  173. ), $columns );
  174. }
  175. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  176. function lps24_sort_last_login_column( $query ) {
  177. if( !is_admin() ) { return; }
  178. $orderby = $query->get('orderby');
  179. if( 'last_login' == $orderby ) {
  180. $query->set('meta_key','last_login');
  181. $query->set('orderby','meta_value');
  182. }
  183. return $query;
  184. }
  185. /***********************************************************
  186. ######################## Blocks ############################
  187. ************************************************************/
  188. function lps24_restrict_locking_ui( $settings, $context ) {
  189. $settings[ 'canLockBlocks' ] = current_user_can( 'activate_plugins' );
  190. return $settings;
  191. }
  192. add_filter( 'block_editor_settings_all', 'lps24_restrict_locking_ui', 10, 2 );
  193. remove_theme_support( 'core-block-patterns' );
  194. add_filter( 'should_load_remote_block_patterns', 'lps24_disable_remote_patterns' );
  195. function lps24_disable_remote_patterns() {
  196. return false;
  197. }
  198. add_filter(
  199. 'block_editor_settings_all',
  200. function( $settings ) {
  201. $settings['enableOpenverseMediaCategory'] = false;
  202. return $settings;
  203. },
  204. 10
  205. );