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;
}

来源:

https://www.wpdaxue.com/remove-plugin-actions.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?