functions.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /***********************************************************
  34. ####################### Comments ###########################
  35. ************************************************************/
  36. add_action('admin_menu', function () {
  37. remove_menu_page('edit-comments.php');
  38. });
  39. add_filter('comments_open', '__return_false', 20, 2);
  40. add_filter('pings_open', '__return_false', 20, 2);
  41. add_action('admin_init','lps24_disable_comments');
  42. function lps24_disable_comments() {
  43. $post_types = get_post_types();
  44. foreach ($post_types as $post_type) {
  45. if(post_type_supports($post_type,'comments')) {
  46. remove_post_type_support($post_type,'comments');
  47. remove_post_type_support($post_type,'trackbacks');
  48. }
  49. }
  50. }
  51. /***********************************************************
  52. ###################### Last Login ##########################
  53. ************************************************************/
  54. add_action( 'wp_login', 'lps24_login_timestamp', 20, 2 );
  55. function lps24_login_timestamp( $user_login, $user ) {
  56. update_user_meta( $user->ID, 'last_login', time() );
  57. }
  58. add_filter( 'manage_users_columns', 'lps24_user_last_login_column' );
  59. function lps24_user_last_login_column( $columns ) {
  60. $columns['last_login'] = 'Last Login'; // column ID / column Title
  61. return $columns;
  62. }
  63. add_filter( 'manage_users_custom_column', 'lps24_last_login_column', 10, 3 );
  64. function lps24_last_login_column( $output, $column_id, $user_id ){
  65. if( $column_id == 'last_login' ) {
  66. $last_login = get_user_meta( $user_id, 'last_login', true );
  67. $date_format = 'j M, Y';
  68. $output = $last_login ? date( $date_format, $last_login ) : '-';
  69. }
  70. return $output;
  71. }
  72. add_filter( 'manage_users_sortable_columns', 'lps24_sortable_columns' );
  73. function lps24_sortable_columns( $columns ) {
  74. return wp_parse_args( array(
  75. 'last_login' => 'last_login'
  76. ), $columns );
  77. }
  78. add_action( 'pre_get_users', 'lps24_sort_last_login_column' );
  79. function lps24_sort_last_login_column( $query ) {
  80. if( !is_admin() ) { return; }
  81. $orderby = $query->get('orderby');
  82. if( 'last_login' == $orderby ) {
  83. $query->set('meta_key','last_login');
  84. $query->set('orderby','meta_value');
  85. }
  86. return $query;
  87. }