functions.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. remove_theme_support( 'core-block-patterns' );
  7. /***********************************************************
  8. ###################### BrowserSync #########################
  9. ************************************************************/
  10. function add_cors_http_header(){
  11. header('Access-Control-Allow-Origin: https://lps.ovid:333');
  12. header('Access-Control-Allow-Credentials: true');
  13. header('Access-Control-Allow-Headers: X-WP-Nonce', false );
  14. }
  15. add_action('init','add_cors_http_header');
  16. function lps24_browsersync_save() {
  17. $args = [
  18. 'blocking' => false,
  19. 'sslverify' => false
  20. ];
  21. $request = wp_remote_get('https://gwp.ovid:333/__browser_sync__?method=reload', $args);
  22. }
  23. add_action('rest_after_insert_page', 'lps24_browsersync_save', 10, 3);
  24. add_action('rest_after_insert_post', 'lps24_browsersync_save', 10, 3);
  25. add_action('save_post', 'lps24_browsersync_save', 10, 3);
  26. add_action('customize_save_after', 'lps24_browsersync_save', 10, 3);
  27. add_action('wp_update_nav_menu', 'lps24_browsersync_save', 10, 3);
  28. add_action('updated_option', 'lps24_browsersync_save', 10, 3);
  29. /***********************************************************
  30. ######################### Admin ############################
  31. ************************************************************/
  32. add_filter( 'show_admin_bar', '__return_false' );
  33. add_action( 'admin_head-profile.php', 'lps24_remove_admin_color' );
  34. function lps24_remove_admin_color() {
  35. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  36. }
  37. add_action( 'admin_bar_menu', 'lps24_remove_adminbar', 999 );
  38. function lps24_remove_adminbar( $wp_admin_bar ) {
  39. $wp_admin_bar->remove_node('wp-logo');
  40. $wp_admin_bar->remove_node('updates');
  41. $wp_admin_bar->remove_menu('comments');
  42. $wp_admin_bar->remove_menu('customize');
  43. $wp_admin_bar->remove_menu('new-content');
  44. $wp_admin_bar->remove_menu('edit');
  45. $wp_admin_bar->remove_menu('new-user');
  46. $wp_admin_bar->remove_menu('new-post');
  47. $wp_admin_bar->remove_menu('new-page');
  48. $wp_admin_bar->remove_node('new-media');
  49. $wp_admin_bar->remove_node('view-site');
  50. }
  51. add_action( 'wp_dashboard_setup', 'lps24_disable_dashboard_items' );
  52. function lps24_disable_dashboard_items() {
  53. remove_action('admin_notices', 'update_nag');
  54. remove_action('welcome_panel', 'wp_welcome_panel');
  55. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  56. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  57. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  58. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  59. }
  60. add_filter ('admin_footer_text', 'lps24_footer_filter');
  61. function lps24_footer_filter ($default) {
  62. return '';
  63. }
  64. add_filter( 'admin_bar_menu', 'lps24_replace_wordpress_howdy', 25 );
  65. function lps24_replace_wordpress_howdy( $wp_admin_bar ) {
  66. $account = $wp_admin_bar->get_node('my-account');
  67. $newtext = str_replace( 'Howdy,', '', $account->title );
  68. $wp_admin_bar->add_node( array(
  69. 'id' => 'my-account',
  70. 'title' => $newtext,
  71. ));
  72. }
  73. /* for email */
  74. add_filter( 'gettext', 'lps24_change_howdy_text', 10, 2 );
  75. function lps24_change_howdy_text( $translation, $original ) {
  76. if( 'Howdy, %1$s' == $original )
  77. $translation = '%1$s';
  78. return $translation;
  79. }
  80. /***********************************************************
  81. ####################### Comments ###########################
  82. ************************************************************/
  83. add_action('admin_menu', function () {
  84. remove_menu_page('edit-comments.php');
  85. });
  86. add_filter('comments_open', '__return_false', 20, 2);
  87. add_filter('pings_open', '__return_false', 20, 2);
  88. add_action('admin_init','lps24_disable_comments');
  89. function lps24_disable_comments() {
  90. $post_types = get_post_types();
  91. foreach ($post_types as $post_type) {
  92. if(post_type_supports($post_type,'comments')) {
  93. remove_post_type_support($post_type,'comments');
  94. remove_post_type_support($post_type,'trackbacks');
  95. }
  96. }
  97. }
  98. /***********************************************************
  99. ###################### Last Login ##########################
  100. ************************************************************/
  101. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  102. function lps24_login_timestamp( $user_login, $user ) {
  103. update_user_meta( $user->ID, 'last_login', time() );
  104. }
  105. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  106. function lps24_user_last_login_column( $columns ) {
  107. $columns['last_login'] = 'Last Login'; // column ID / column Title
  108. return $columns;
  109. }
  110. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  111. function lps24_last_login_column( $output, $column_id, $user_id ){
  112. if( $column_id == 'last_login' ) {
  113. $last_login = get_user_meta( $user_id, 'last_login', true );
  114. $date_format = 'j M, Y';
  115. $output = $last_login ? date( $date_format, $last_login ) : '-';
  116. }
  117. return $output;
  118. }
  119. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  120. function lps24_sortable_columns( $columns ) {
  121. return wp_parse_args( array(
  122. 'last_login' => 'last_login'
  123. ), $columns );
  124. }
  125. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  126. function lps24_sort_last_login_column( $query ) {
  127. if( !is_admin() ) { return; }
  128. $orderby = $query->get('orderby');
  129. if( 'last_login' == $orderby ) {
  130. $query->set('meta_key','last_login');
  131. $query->set('orderby','meta_value');
  132. }
  133. return $query;
  134. }