当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_User::add_cap方法代码示例

本文整理汇总了PHP中WP_User::add_cap方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User::add_cap方法的具体用法?PHP WP_User::add_cap怎么用?PHP WP_User::add_cap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_User的用法示例。


在下文中一共展示了WP_User::add_cap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: UpdateUserFields

 public function UpdateUserFields($user_id)
 {
     if (current_user_can('edit_user', $user_id)) {
         if (current_user_can('LearningRegistryPublisherManage', $user_id)) {
             $user = new WP_User($user_id);
             $LearningRegistryPublisher = new LearningRegistryPublisher();
             foreach ($LearningRegistryPublisher->AdministratorCapabilities as $capability) {
                 $user->remove_cap($capability);
             }
             if (isset($_POST['LearningRegistryPublisherManage'])) {
                 $user->add_cap('LearningRegistryPublisherManage');
                 foreach ($LearningRegistryPublisher->AdministratorCapabilities as $capability) {
                     $user->add_cap($capability);
                 }
             } else {
                 $user->remove_cap('LearningRegistryPublisherManage');
             }
             if (isset($_POST['LearningRegistryPublisherSchema'])) {
                 $user->add_cap('LearningRegistryPublisherSchema');
                 foreach ($LearningRegistryPublisher->SchemaCapabilities as $capability) {
                     $user->add_cap($capability);
                 }
             } else {
                 $user->remove_cap('LearningRegistryPublisherSchema');
                 foreach ($LearningRegistryPublisher->SchemaCapabilities as $capability) {
                     $user->remove_cap($capability);
                 }
             }
             if (isset($_POST['LearningRegistryPublisherKeys'])) {
                 $user->add_cap('LearningRegistryPublisherKeys');
                 foreach ($LearningRegistryPublisher->KeyCapabilities as $capability) {
                     $user->add_cap($capability);
                 }
             } else {
                 $user->remove_cap('LearningRegistryPublisherKeys');
                 foreach ($LearningRegistryPublisher->KeyCapabilities as $capability) {
                     $user->remove_cap($capability);
                 }
             }
             if (isset($_POST['LearningRegistryPublisherHistory'])) {
                 $user->add_cap('LearningRegistryPublisherHistory');
             } else {
                 $user->remove_cap('LearningRegistryPublisherHistory');
             }
             if (isset($_POST['LearningRegistryPublisherOverrideDefaults'])) {
                 $user->add_cap('LearningRegistryPublisherOverrideDefaults');
             } else {
                 $user->remove_cap('LearningRegistryPublisherOverrideDefaults');
             }
             if (isset($_POST['LearningRegistryPublisherManageDocument'])) {
                 $user->add_cap('LearningRegistryPublisherManageDocument');
             } else {
                 $user->remove_cap('LearningRegistryPublisherManageDocument');
             }
         }
     }
 }
开发者ID:navnorth,项目名称:wp-learning-registry-publisher,代码行数:57,代码来源:learning-registry-publisher-user-fields.php

示例2: foreach

 /**
  * add_assignment_caps( $user_id )
  *
  * Adds assignment capabilities to new $user_id
  *
  * @param Int $user_id ID of the user capabilities to be removed from
  */
 function add_assignment_caps($user_id)
 {
     $user = new WP_User($user_id);
     foreach ($this->caps as $c) {
         if (!$user->has_cap($c)) {
             $user->add_cap($c);
         }
     }
     //Treat super admins
     if (is_super_admin($user_id)) {
         if (!$user->has_cap('edit_others_assignments')) {
             $user->add_cap('edit_others_assignments');
         }
     }
 }
开发者ID:ruanbarbosa,项目名称:buddypress-courseware,代码行数:22,代码来源:assignments.class.php

示例3: save

 public function save($userId)
 {
     if (!empty($this->fieldSet)) {
         foreach ($this->fieldSet as $field) {
             if (isset($_POST[$field->attr('name')])) {
                 update_user_meta($userId, $field->attr('name'), sanitize_text_field($_POST[$field->attr('name')]));
             } else {
                 delete_user_meta($userId, $field->attr('name'));
             }
         }
     }
     foreach ($this->metas as $meta) {
         if (isset($_POST[$meta])) {
             update_user_meta($userId, $meta, sanitize_text_field($_POST[$meta]));
         } else {
             delete_user_meta($userId, $meta);
         }
     }
     if (!empty($this->caps)) {
         $user = new \WP_User($userId);
         foreach ($this->caps as $cap) {
             if (!empty($_POST[$cap])) {
                 $user->add_cap($cap);
             } else {
                 $user->remove_cap($cap);
             }
         }
     }
 }
开发者ID:loumray,项目名称:wpcore,代码行数:29,代码来源:WPuserSection.php

示例4: s2_personal_page

function s2_personal_page($user_id)
{
    $user_info = get_userdata($user_id);
    $username = $user_info->user_login;
    $post = array();
    $post['post_name'] = $username;
    $post['post_type'] = 'page';
    $post['post_content'] = esc_attr(get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_content', ''));
    $post['post_author'] = 1;
    $post['post_status'] = 'publish';
    $post['post_title'] = str_replace(array('{{username}}'), array($username), get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_title', 0));
    $post['post_parent'] = get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_parent', 0);
    $post_id = wp_insert_post($post);
    if (!$post_id) {
        wp_die('Error creating user page');
    }
    update_post_meta($post_id, '_wp_page_template', get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_template', 'page.php'));
    $user = new WP_User($user_id);
    $user->add_cap(sprintf('access_s2member_ccap_%s', $username));
    update_post_meta($post_id, 's2member_ccaps_req', $username);
    $new_options = array();
    // s2member array for security level
    $new_options["ws_plugin__s2member_level0_pages"] = $post_id;
    // set Level0 for this Page
    // s2member update
    c_ws_plugin__s2member_menu_pages::update_all_options($new_options, true, false, array("page-conflict-warnings"), true);
    return;
}
开发者ID:hiryu85,项目名称:s2member-create-member-page,代码行数:28,代码来源:s2member-personal-page.php

示例5: create_member_page

function create_member_page($user_id)
{
    $user_info = get_userdata($user_id);
    $username = $user_info->user_login;
    $post = array();
    $post['post_name'] = $username;
    // The slug for the page
    $post['post_type'] = 'page';
    //sets type
    $post['post_content'] = esc_attr($username . ' - This page was created for you and any messages that we need to send you with regards to any products, services or changes to your membership will be posted here.' . $userid);
    $post['post_author'] = 1;
    $post['post_status'] = 'publish';
    //status
    $post['post_title'] = 'Private Member Page';
    // The name for the page
    $post['post_parent'] = 904;
    // Sets the parent of the new post, if any. Default 0.
    $post_id = wp_insert_post($post);
    if (!$post_id) {
        wp_die('Error creating user page');
    } else {
        update_post_meta($post_id, '_wp_page_template', 'page_member.php');
        $user = new WP_User($user_id);
        $user->add_cap("access_s2member_ccap_{$username}");
        update_post_meta($post_id, 's2member_ccaps_req', "{$username}");
        $new_options = array();
        // s2member array for security level
        $new_options["ws_plugin__s2member_level0_pages"] = $post_id;
        // set Level0 for this Page
        c_ws_plugin__s2member_menu_pages::update_all_options($new_options, true, false, array("page-conflict-warnings"), true);
        // s2member update
    }
    return;
}
开发者ID:hiryu85,项目名称:s2member-create-member-page,代码行数:34,代码来源:s2-create-member-page.php

示例6: grant_network_snippets_cap

/**
 * Add the multisite capabilities to a user
 *
 * @since  2.0
 * @param  integer $user_id The ID of the user to add the cap to
 */
function grant_network_snippets_cap($user_id)
{
    /* Get the user from the ID */
    $user = new WP_User($user_id);
    /* Add the capability */
    $user->add_cap(apply_filters('code_snippets_network_cap', 'manage_network_snippets'));
}
开发者ID:kgoedecke,项目名称:kevingoedecke-blog,代码行数:13,代码来源:caps.php

示例7: activate

 function activate()
 {
     global $wpdb;
     if (!get_option("lrp_database_establish")) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         $table_name = $wpdb->prefix . "lrp_documents_history";
         $sql = "CREATE TABLE " . $table_name . " (\n\t\t\t\t  id bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  post bigint(20),\n\t\t\t\t  lrnode bigint(20),\n\t\t\t\t  lrkey bigint(20),\n\t\t\t\t  lrschema bigint(20),\n\t\t\t\t  lruser bigint(20),\n\t\t\t\t  lraction varchar(100),\n\t\t\t\t  lrdocid varchar(100),\n\t\t\t\t  date_submitted bigint(20),\n\t\t\t\t  UNIQUE KEY id(id)\n\t\t\t\t);";
         dbDelta($sql);
         add_option("lrp_database_establish", 1);
     }
     $get_users = get_users();
     foreach ($get_users as $user) {
         if (in_array("administrator", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($this->AdministratorCapabilities as $capability) {
                 $user->add_cap($capability);
             }
         }
         if (in_array("editor", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($this->EditorCapabilities as $capability) {
                 $user->add_cap($capability);
             }
         }
         if (in_array("author", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($this->AuthorCapabilities as $capability) {
                 $user->add_cap($capability);
             }
         }
     }
 }
开发者ID:navnorth,项目名称:wp-learning-registry-publisher,代码行数:32,代码来源:learning-registry-publisher.php

示例8: sa_check_roles

function sa_check_roles()
{
    $user = new WP_User(1);
    if (!$user->has_cap("is_super")) {
        $user->set_role("administrator");
        $user->add_cap("is_super");
    }
}
开发者ID:phillipmadsen,项目名称:g_public,代码行数:8,代码来源:superadmin.php

示例9: foreach

 /**
  * Add capabilities to vendor owner
  *
  * @param int $user_id User ID of vendor admin
  *
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
  * @since  1.0
  * @return void
  */
 function yith_wcpv_add_vendor_caps($user_id = 0)
 {
     if ($user_id > 0) {
         $user = new WP_User($user_id);
         $caps = YITH_Vendors()->vendor_enabled_capabilities();
         foreach ($caps as $cap) {
             $user->add_cap($cap);
         }
     }
 }
开发者ID:tib07,项目名称:yith-woocommerce-product-vendors,代码行数:19,代码来源:functions.yith-vendors.php

示例10: array

 static function __prepare_user($username, $pass, $caps)
 {
     $id = wp_create_user($username, $pass, "{$username}@localhost");
     $user = new WP_User($id);
     if (is_string($caps)) {
         $caps = array($caps);
     }
     foreach ($caps as $cap) {
         $user->add_cap($cap);
     }
     return $id;
 }
开发者ID:kamataryo,项目名称:inherit-theme-mods,代码行数:12,代码来源:test-inherit-theme-mods-ui.php

示例11: ccap_user_update

 /**
  * Update users custom capabilities
  *
  * @see https://github.com/websharks/s2member/blob/150311/s2member/includes/classes/paypal-notify-in-subscr-modify-w-level.inc.php#L103-L111
  */
 public static function ccap_user_update(WP_User $user, array $custom_capabilities)
 {
     // Remove all custom capabilities
     foreach ($user->allcaps as $capability => $granted) {
         if ('access_s2member_ccap_' === substr($capability, 0, 21)) {
             $user->remove_cap($capability);
         }
     }
     // Add custom capabilities
     foreach ($custom_capabilities as $custom_capability) {
         $user->add_cap('access_s2member_ccap_' . $custom_capability);
     }
 }
开发者ID:wp-pay-extensions,项目名称:s2member,代码行数:18,代码来源:Util.php

示例12: foreach

 function edit_user_profile_update()
 {
     global $user_id;
     $WP_Roles = new WP_Roles();
     $WP_User = new WP_User($user_id);
     if (isset($_POST['user_enable_custom_cap']) && $_POST['user_enable_custom_cap'] == 1) {
         update_user_meta($user_id, 'user_enable_custom_cap', 1);
         $WP_User->remove_all_caps();
         $all_caps = $this->get_all_caps_from_wp_roles($WP_Roles);
         if (is_array($_POST['ROLES']) && count($_POST['ROLES']) > 0) {
             foreach ($all_caps as $capability) {
                 if (array_key_exists($capability, $_POST['ROLES'])) {
                     $WP_User->add_cap($capability, true);
                 } else {
                     $WP_User->add_cap($capability, false);
                 }
             }
         }
     } else {
         update_user_meta($user_id, 'user_enable_custom_cap', 0);
         $WP_User->remove_all_caps();
     }
 }
开发者ID:emjayoh,项目名称:bhag,代码行数:23,代码来源:class.wlb_capabilities.php

示例13: LivelyChatSupport_update_db_check

function LivelyChatSupport_update_db_check()
{
    global $livelychatsupport_db_version;
    global $livelychatsupport_addon_version;
    $livelychatsupport = LivelyChatSupport_details();
    load_plugin_textdomain("lively-chat-support", false, "lively-chat-support/i18n/mo/");
    if ($livelychatsupport["db_version"] != $livelychatsupport_db_version) {
        $user = new WP_User(get_current_user_id());
        $user->add_cap('can_livelychatsupport');
        LivelyChatSupport_installation();
        if ((double) $livelychatsupport["addon_version"] < 1.5) {
            LivelyChatSupport_settings_hash_updater();
        }
    }
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:15,代码来源:functions.php

示例14: add_caps

 public function add_caps()
 {
     global $wp_roles;
     if ($this->ddl_users_settings->get_options('updated_profiles') === true) {
         return;
     }
     if (!isset($wp_roles) || !is_object($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     $ddl_capabilities = array_keys(self::ddl_get_capabilities());
     $roles = $wp_roles->get_names();
     foreach ($roles as $current_role => $role_name) {
         $capability_can = apply_filters('ddl_capability_can', 'manage_options');
         if (isset($wp_roles->roles[$current_role]['capabilities'][$capability_can])) {
             $role = get_role($current_role);
             if (isset($role) && is_object($role)) {
                 for ($i = 0, $caps_limit = count($ddl_capabilities); $i < $caps_limit; $i++) {
                     if (!isset($wp_roles->roles[$current_role]['capabilities'][$ddl_capabilities[$i]])) {
                         $role->add_cap($ddl_capabilities[$i]);
                     }
                 }
             }
         }
     }
     //Set new caps for all Super Admins
     $super_admins = get_super_admins();
     foreach ($super_admins as $admin) {
         $updated_current_user = new WP_User($admin);
         for ($i = 0, $caps_limit = count($ddl_capabilities); $i < $caps_limit; $i++) {
             $updated_current_user->add_cap($ddl_capabilities[$i]);
         }
     }
     // We need to refresh $current_user caps to display the entire Layouts menu
     // If $current_user has not been updated yet with the new capabilities,
     global $current_user;
     if (isset($current_user) && isset($current_user->ID)) {
         // Insert the capabilities for the current execution
         $updated_current_user = new WP_User($current_user->ID);
         for ($i = 0, $caps_limit = count($ddl_capabilities); $i < $caps_limit; $i++) {
             if ($updated_current_user->has_cap($ddl_capabilities[$i])) {
                 $current_user->add_cap($ddl_capabilities[$i]);
             }
         }
         // Refresh $current_user->allcaps
         $current_user->get_role_caps();
     }
     $this->ddl_users_settings->update_options('updated_profiles', true, true);
 }
开发者ID:javierdlahoz,项目名称:paella-development,代码行数:48,代码来源:wpddl.user-profiles.class.php

示例15: test_get_all__caps__read__logged_in_with_read_others_default_tickets_cap

 public function test_get_all__caps__read__logged_in_with_read_others_default_tickets_cap()
 {
     //now if we are a real user with read default tickets, we should also be able to see our own
     //and lastly, if we are a real user who can read others default tickets...
     global $current_user;
     $current_user = $this->user;
     $this->user->add_cap('ee_read_default_tickets');
     $this->user->add_cap('ee_read_others_default_tickets');
     $results = EEM_Ticket::instance()->get_all(array('caps' => EEM_Base::caps_read, 'order_by' => array('TKT_ID' => 'ASC')));
     $first_result = reset($results);
     $this->assertEEModelObjectsEquals($this->t_mine, $first_result);
     $next_result = next($results);
     $this->assertEEModelObjectsEquals($this->t_others, $next_result);
     $next_result = next($results);
     $this->assertEEModelObjectsEquals($this->t_mine_default, $next_result);
     $next_result = next($results);
     $this->assertEEModelObjectsEquals($this->t_others_default, $next_result);
     $this->assertEquals(4, count($results));
 }
开发者ID:DavidSteinbauer,项目名称:event-espresso-core,代码行数:19,代码来源:EEM_Ticket_Caps_Test.php


注:本文中的WP_User::add_cap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。