Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wordpress中的代码或插件(哪个优先级更高)_Php_Wordpress_Web_Plugins - Fatal编程技术网

Php wordpress中的代码或插件(哪个优先级更高)

Php wordpress中的代码或插件(哪个优先级更高),php,wordpress,web,plugins,Php,Wordpress,Web,Plugins,我的问题是关于一般情况。我已经为wordpress中的用户角色和功能编写了一些代码,并为此安装了一个插件。 当我更改代码以获得功能时,为不起作用的角色授予更多权限,但同时,当我更改插件中的功能时,它会正常工作 所以我想知道 WP中是否有任何优先级机制来定义插件的优先级以及将首先应用哪个优先级的代码 这是代码…我正在使用角色编辑器插件 function new_role() { add_role('simple_role','Simple Role',array( 'read'

我的问题是关于一般情况。我已经为wordpress中的用户角色和功能编写了一些代码,并为此安装了一个插件。 当我更改代码以获得功能时,为不起作用的角色授予更多权限,但同时,当我更改插件中的功能时,它会正常工作

所以我想知道 WP中是否有任何优先级机制来定义插件的优先级以及将首先应用哪个优先级的代码

这是代码…我正在使用角色编辑器插件

function new_role()
{
    add_role('simple_role','Simple Role',array(
    'read'               =>true,
    'edit_posts'         =>true,
    'publish_posts'      =>true,
    'delete_posts'       =>true,
    'upload_files'       =>true,
    'create_users'       =>true,
    'edit_others_posts'  =>true,
    'delete_others_posts'=>true,
    'edit_themes'=>true
        ));

    add_role('client','Author Role',array('read'=>true, 'edit_posts'=>true,'edit_others_posts'=>true,'delete_posts'=>true));    

    add_role('just_edit','Just Edit',array('read'=>true, 'edit_published_posts'=>true, 'edit_others_posts'=>true, 'edit_posts'=>true, 'create_users'=>true, 'list_users'=>true));
        }
add_action('init','new_role');  

提前感谢

根据您的编辑,您添加的两个操作来自插件。wordpress加载插件没有设置顺序(顺便说一句,主题加载的时间晚于插件)

这就是行动的意义所在

add_action('init','new_role'); 
add_action
$priority
$args
还有两个参数

优先级默认为10,因此所有添加的没有优先级的钩子都将按添加顺序调用,因此如果插件先加载,它将被稍后添加的操作覆盖

解决这个问题的方法是增加一个更高的优先级

 add_action('init','new_role', 100);

要确保您的
新角色
功能是最后一个运行的,可能需要一些变通

代码
。。。哪里