我编写这段代码是为了将manage\\u options功能添加到我的shop\\u经理中,它确实起到了作用。在将此代码移动到我的live站点之前,我想问一下,是否在正确的位置调用了该函数。我提前谢谢你!
add_action(\'init\', \'activate_cap_shopmanagers\');
function activate_cap_shopmanagers() {
// get the shop manager role\'s object from WP_Role class
$shopmanager = get_role( \'shop_manager\' );
// add the capability
$shopmanager->add_cap( \'manage_options\' );
}
编辑
register_activation_hook( __FILE__, \'my_plugin_activation\' );
function my_plugin_activation() {
add_option( \'my_plugin_activation\',\'just-activated\' );
$shopmanager = get_role( \'shop_manager\' );
$shopmanager->add_cap( \'manage_options\' );
}
add_action( \'admin_init\',\'my_plugin_initialize\' );
function my_plugin_initialize() {
if( is_shop_manager() && get_option( \'my_plugin_activation\' ) == \'just-activated\' ) {
delete_option( \'my_plugin_activation\' );
}
}
is\\u shop\\u manager()是我函数中的一个函数。php
function is_shop_manager() {
global $current_user;
$user = wp_get_current_user();
if ( isset( $user->roles[0] ) && $user->roles[0] == \'shop_manager\' ) {
return true; // when user is shop manager
} else {
return false; // when user is not shop manager
}
}