functions.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /***********************************************************
  3. ######################### Admin ############################
  4. ************************************************************/
  5. add_filter( 'show_admin_bar', '__return_false' );
  6. add_action( 'admin_head-profile.php', 'lps24_remove_admin_color' );
  7. function lps24_remove_admin_color() {
  8. remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  9. }
  10. add_action( 'admin_bar_menu', 'lps24_remove_adminbar', 999 );
  11. function lps24_remove_adminbar( $wp_admin_bar ) {
  12. $wp_admin_bar->remove_node('wp-logo');
  13. $wp_admin_bar->remove_node('updates');
  14. $wp_admin_bar->remove_menu('comments');
  15. $wp_admin_bar->remove_menu('customize');
  16. $wp_admin_bar->remove_menu('new-content');
  17. $wp_admin_bar->remove_menu('edit');
  18. $wp_admin_bar->remove_menu('new-user');
  19. $wp_admin_bar->remove_menu('new-post');
  20. $wp_admin_bar->remove_menu('new-page');
  21. $wp_admin_bar->remove_node('new-media');
  22. $wp_admin_bar->remove_node('view-site');
  23. }
  24. add_action( 'wp_dashboard_setup', 'lps24_disable_dashboard_items' );
  25. function lps24_disable_dashboard_items() {
  26. remove_action('admin_notices', 'update_nag');
  27. remove_action('welcome_panel', 'wp_welcome_panel');
  28. remove_meta_box('dashboard_primary', 'dashboard', 'side');
  29. remove_meta_box('dashboard_secondary', 'dashboard', 'side');
  30. remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
  31. remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
  32. }
  33. add_filter ('admin_footer_text', 'lps24_footer_filter');
  34. function lps24_footer_filter ($default) {
  35. return '';
  36. }
  37. add_filter( 'admin_bar_menu', 'lps24_replace_wordpress_howdy', 25 );
  38. function lps24_replace_wordpress_howdy( $wp_admin_bar ) {
  39. $account = $wp_admin_bar->get_node('my-account');
  40. $newtext = str_replace( 'Howdy,', '', $account->title );
  41. $wp_admin_bar->add_node( array(
  42. 'id' => 'my-account',
  43. 'title' => $newtext,
  44. ));
  45. }
  46. /* for email */
  47. add_filter( 'gettext', 'lps24_change_howdy_text', 10, 2 );
  48. function lps24_change_howdy_text( $translation, $original ) {
  49. if( 'Howdy, %1$s' == $original )
  50. $translation = '%1$s';
  51. return $translation;
  52. }
  53. /***********************************************************
  54. ####################### Comments ###########################
  55. ************************************************************/
  56. add_action('admin_menu', function () {
  57. remove_menu_page('edit-comments.php');
  58. });
  59. add_filter('comments_open', '__return_false', 20, 2);
  60. add_filter('pings_open', '__return_false', 20, 2);
  61. add_action('admin_init','lps24_disable_comments');
  62. function lps24_disable_comments() {
  63. $post_types = get_post_types();
  64. foreach ($post_types as $post_type) {
  65. if(post_type_supports($post_type,'comments')) {
  66. remove_post_type_support($post_type,'comments');
  67. remove_post_type_support($post_type,'trackbacks');
  68. }
  69. }
  70. }
  71. /***********************************************************
  72. ###################### Last Login ##########################
  73. ************************************************************/
  74. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  75. function lps24_login_timestamp( $user_login, $user ) {
  76. update_user_meta( $user->ID, 'last_login', time() );
  77. }
  78. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  79. function lps24_user_last_login_column( $columns ) {
  80. $columns['last_login'] = 'Last Login'; // column ID / column Title
  81. return $columns;
  82. }
  83. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  84. function lps24_last_login_column( $output, $column_id, $user_id ){
  85. if( $column_id == 'last_login' ) {
  86. $last_login = get_user_meta( $user_id, 'last_login', true );
  87. $date_format = 'j M, Y';
  88. $output = $last_login ? date( $date_format, $last_login ) : '-';
  89. }
  90. return $output;
  91. }
  92. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  93. function lps24_sortable_columns( $columns ) {
  94. return wp_parse_args( array(
  95. 'last_login' => 'last_login'
  96. ), $columns );
  97. }
  98. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  99. function lps24_sort_last_login_column( $query ) {
  100. if( !is_admin() ) { return; }
  101. $orderby = $query->get('orderby');
  102. if( 'last_login' == $orderby ) {
  103. $query->set('meta_key','last_login');
  104. $query->set('orderby','meta_value');
  105. }
  106. return $query;
  107. }