外贸独立站的底层设计密码WordPress 成品站模板
当前位置:首页>WordPress建站>后台定制>WordPress 移除插件列表的“编辑”和“停用”链接

WordPress 移除插件列表的“编辑”和“停用”链接

倡萌之前分享过 在WordPress插件管理界面隐藏已启用的插件,今天分享下 移除插件管理界面的“编辑”和“停用”链接:

remove-plugin-actions-wpdaxue_com

移除特定插件的

上图中,我们移除了所有的“编辑”链接和 Cartpauj PM 插件的“停用”链接,只需要添加下面的代码到主题的 functions.php 即可:

/**
 * 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 行的样例添加插件的主文件目录,所谓主文件,也就是包含类似下面注释的文件:

/*
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
*/

移除所有插件的

上面的方法是移除特定插件的,如果你要移除所有插件的,可以使用下面的代码:

/**
 * 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;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
后台定制

WordPress发布文章前强制要求上传特色图像

2013-10-15 9:10:00

后台定制

WordPress 上传图片时选择缩略图的裁剪位置

2013-10-18 8:44:21

4 条回复 A文章作者 M管理员
  1. 碚子

    💡 去除停用链接少了一行代码unset( $actions[‘deactivate’] );

    • 倡萌

      之前的代码是移除特定插件的,并没有错误,已经补充移除所有插件的代码了

  2. 感觉移除停用按钮好邪恶

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索