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

本文目录[隐藏]1移除特定插件的2移除所有插件的

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

remove-plugin-actions-wpdaxue_com

移除特定插件的

上图中,我们移除了所有的“编辑”链接和 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;
}

本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等软件的安装与卸载,精通CSS、JavaScript、PHP、ASP、C、C++、C#、Java、Ruby、Perl、Lisp、Python、Objective-C、ActionScript、Pascal等单词的拼写,熟悉Windows、Linux、OS X、Android、iOS、WP8等系统的开关机。

通过下面的方式来联系我们:

电邮:138762189@qq.com

联系QQ:点击这里给我发消息

官方站:www.tadke.com

※ ※ 联系请加我的企鹅号 ※※

※ ※技术支持请微信联系站长 ※※

Copyright © 2023 Tadke.com. 琼ICP备20000547号