functions.php 4.4 KB

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