倡萌之前分享过 在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; }
本文WordPress 移除插件列表的“编辑”和“停用”链接到此结束。任何人的光鲜亮丽,必有他该面对的艰难险阻。小编再次感谢大家对我们的支持!