本文目錄1移除特定外掛的2移除所有外掛的
之前分享過 在WordPress外掛管理界面隱藏已啟用的外掛,今天分享下 移除外掛管理界面的“編輯”和“停用”鏈接:
移除特定外掛的
上圖中,我們移除瞭所有的“編輯”鏈接和 Cartpauj PM 外掛的“停用”鏈接,隻需要添加下面的代碼到主題的 functions.php 即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/** * WordPress 移除外掛列表特定外掛的“編輯”和“停用”鏈接 * https://www.wpdaxue.com/remove-plugin-actions.html */ add_filter( 'plugin_action_links', 'remove_plugin_actions', 10, 4 ); function remove_plugin_actions( $actions, $plugin_file, $plugin_data, $context ) { // 移除所有“編輯”鏈接 if ( isset( $actions['edit'] ) ) { unset( $actions['edit'] ); } // 移除外掛的“停用”鏈接 if( isset( $actions['deactivate'] ) ) { switch($plugin_file) { // 添加外掛的主文件目錄 case 'cartpauj-pm/pm-main.php': // 註意結尾是英文冒號 unset( $actions['deactivate'] ); break; } } return $actions; } |
/**
* WordPress 移除外掛列表特定外掛的“編輯”和“停用”鏈接
* https://www.wpdaxue.com/remove-plugin-actions.html
*/
add_filter( ‘plugin_action_links’, ‘remove_plugin_actions’, 10, 4 );
function remove_plugin_actions( $actions, $plugin_file, $plugin_data, $context )
{
// 移除所有“編輯”鏈接
if ( isset( $actions[‘edit’] ) )
{
unset( $actions[‘edit’] );
}
// 移除外掛的“停用”鏈接
if( isset( $actions[‘deactivate’] ) )
{
switch($plugin_file)
{
// 添加外掛的主文件目錄
case ‘cartpauj-pm/pm-main.php’: // 註意結尾是英文冒號
unset( $actions[‘deactivate’] );
break;
}
}
return $actions;
}
註:請根據自己的實際,按照 19 行的樣例添加外掛的主文件目錄,所謂主文件,也就是包含類似下面註釋的文件:
1 2 3 4 5 6 7 8 9 10 |
/*
Plugin Name: Cartpauj PM
Plugin URI: http://cartpauj.icomnow.com/projects/cartpauj-pm-plugin
Description: Cartpauj PM allows you to add a simple Private Messaging system to your WordPress site. The messaging is done entirely through the front-end of your site rather than the Dashboard. This is very helpful if you want to keep your users out of the Dashboard area. Enjoy! :)
Version: 1.0.10
Author: Cartpauj
Author URI: http://cartpauj.icomnow.com
Text Domain: cartpaujpm
Copyright: 2009-2011, cartpauj
*/
|
/*
Plugin Name: Cartpauj PM
Plugin URI: http://cartpauj.icomnow.com/projects/cartpauj-pm-plugin
Description: Cartpauj PM allows you to add a simple Private Messaging system to your WordPress site. The messaging is done entirely through the front-end of your site rather than the Dashboard. This is very helpful if you want to keep your users out of the Dashboard area. Enjoy! 🙂
Version: 1.0.10
Author: Cartpauj
Author URI: http://cartpauj.icomnow.com
Text Domain: cartpaujpm
Copyright: 2009-2011, cartpauj
*/
移除所有外掛的
上面的方法是移除特定外掛的,如果你要移除所有外掛的,可以使用下面的代碼:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/** * WordPress 移除外掛列表所有“編輯”和“停用”鏈接 * https://www.wpdaxue.com/remove-plugin-actions.html */ add_filter( 'plugin_action_links', 'remove_plugin_actions', 10, 4 ); function remove_plugin_actions( $actions, $plugin_file, $plugin_data, $context ) { // 移除所有“編輯”鏈接 if ( isset( $actions['edit'] ) ) { unset( $actions['edit'] ); } // 移除外掛的“停用”鏈接 if( isset( $actions['deactivate'] ) ) { unset( $actions['deactivate'] ); } return $actions; } |
/**
* WordPress 移除外掛列表所有“編輯”和“停用”鏈接
* https://www.wpdaxue.com/remove-plugin-actions.html
*/
add_filter( ‘plugin_action_links’, ‘remove_plugin_actions’, 10, 4 );
function remove_plugin_actions( $actions, $plugin_file, $plugin_data, $context )
{
// 移除所有“編輯”鏈接
if ( isset( $actions[‘edit’] ) )
{
unset( $actions[‘edit’] );
}
// 移除外掛的“停用”鏈接
if( isset( $actions[‘deactivate’] ) )
{
unset( $actions[‘deactivate’] );
}
return $actions;
}