wordpress後臺(去除菜單,出去版本插件等通知,解決後臺打開慢)

概要

今天因需求構建一個wordpress網站,應要求屏蔽一些不需要的功能;隨手做下筆記。 如圖

實現功能

1.停用版本更新通知

2.停用插件更新通知

3.停用主題更新通知

4.刪除後臺頂級菜單,子菜單

5.刪除儀表盤頁面模塊

6.移除後臺左上角 WordPress Logo

7.解決停用版本、插件、主題更新通知後,後臺打開慢問題

 

具體操作如下 編輯主題

DUX6.0: 模板函數 (functions.php)

<?php
// Require theme functions
require get_stylesheet_directory() . '/functions-theme.php';

// Customize your functions


//============刪除通知版本其它=============
//停用版本更新通知:打開主題的functions.php文件,加入以下語法,這樣即可關閉版本更新通知。
remove_action('load-update-core.php', 'wp_update_themes'); 
add_filter('pre_site_transient_update_themes', create_function('$a', "return null;"));

//停用插件更新通知:打開主題的functions.php文件,加入以下語法,就可以關閉插件更新通知的訊息了。
remove_action('load-update-core.php', 'wp_update_plugins'); 
add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;"));

//停用主題更新通知:打開主題的functions.php文件,將以下語法加入到主題內,儲存並上傳即可。
remove_action ('load-update-core.php', 'wp_update_themes'); 
add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));

//上面代碼配合下面代碼使用可以解決後臺打開慢的問題

// 徹底關閉自動更新
add_filter('automatic_updater_disabled', '__return_true');
// 關閉更新檢查定時作業
remove_action('init', 'wp_schedule_update_checks');
// 移除已有的版本檢查定時作業
wp_clear_scheduled_hook('wp_version_check');
// 移除已有的插件更新定時作業
wp_clear_scheduled_hook('wp_update_plugins');
// 移除已有的主題更新定時作業 
wp_clear_scheduled_hook('wp_update_themes');
// 移除已有的自動更新定時作業 
wp_clear_scheduled_hook('wp_maybe_auto_update');
// 移除後臺內核更新檢查 
remove_action( 'admin_init', '_maybe_update_core' );
// 移除後臺插件更新檢查 
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-update.php', 'wp_update_plugins' );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
remove_action( 'admin_init', '_maybe_update_plugins' );
// 移除後臺主題更新檢查 
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'load-update-core.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );

//==========刪除後臺頁面部分模塊功能==========
 //移除 WordPress 儀表盤歡迎面板
 remove_action('welcome_panel', 'wp_welcome_panel');
 //移除  儀表盤 中其它模塊
 function example_remove_dashboard_widgets() {
    // Globalize the metaboxes array, this holds all the widgets for wp-admin
    global $wp_meta_boxes;

    // 以下這一行代碼將刪除 "快速發佈" 模塊
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);

    // 以下這一行代碼將刪除 "引入鏈接" 模塊
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);

    // 以下這一行代碼將刪除 "插件" 模塊
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);

    // 以下這一行代碼將刪除 "近期評論" 模塊
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);

    // 以下這一行代碼將刪除 "近期草稿" 模塊
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);

    // 以下這一行代碼將刪除 "WordPress 開發日誌" 模塊
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);

    // 以下這一行代碼將刪除 "其它 WordPress 新聞" 模塊
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

    // 以下這一行代碼將刪除 "概況" 模塊
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
}
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );


//==========刪除後臺導航分類==========
function remove_submenu() {
    //-----------隱藏後臺左側頂級菜單---------
    //刪除“評論”導航菜單
    //remove_submenu_page('edit-comments.php','edit-comments.php');
    //-----------隱藏後臺左側子菜單-----------
    // 刪除"設置"下面的子菜單"隱私"
    // remove_submenu_page( 'options-general.php', 'options-privacy.php' );
    
    // 刪除"外觀"下面的子菜單"編輯"
    //remove_submenu_page( 'themes.php', 'theme-editor.php' );
    
    //刪除“儀表盤”下面的子菜單“更新”
    //remove_submenu_page('index.php','update-core.php');
}

/** 自定義要去除的頂級菜單  OK 暫停使用*/
// function remove_menus() { 
// global $menu; 
// $restricted = array(__('Dashboard'), __(''), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); 
// end ($menu); 
// while (prev($menu)){ 
// $value = explode(' ',$menu[key($menu)][0]); 
// if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} 
// } 
// } 
// if ( is_admin() ) { 
// // 刪除左側菜單 
// add_action('admin_menu', 'remove_menus'); 
// }


/* 根據權限 自定義 去除不需要導航菜單2019.12.17
administrator(管理員) editor(編輯) author(作者) contributor(投稿者) subscriber(訂閱者)
OK
*/ 

function n_a_remove_menu_page(){ 
//remove_submenu_page( 'edit.php', 'post-new.php' ); //移除"文章"下的"寫文章" 
remove_menu_page('tools.php'); 
remove_menu_page('edit-comments.php'); 

//去除非管理員用戶後臺一級菜單和二級菜單舉例,在主題functions.php中添加如下代碼:
if(!current_user_can('administrator') && is_admin()){ 
add_action('admin_menu', 'n_a_remove_menu_page'); 
}

//移除後臺左上角 WordPress Logo
function annointed_admin_bar_remove() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);


//移除修訂版本
remove_action('post_updated','wp_save_post_revision' );
//後臺禁用Google Open Sans字體,加速網站
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}return $translations;
}
 

//刪除後臺底部的”感謝使用WordPress進行創作。”文字
function footerText () {
    return '';
}
add_filter('admin_footer_text', 'footerText', '');

//移除後臺管理界面右上角的“幫助”
add_action('in_admin_header', function(){
    global $current_screen;
    $current_screen->remove_help_tabs();
});

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章