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


PHP WP_User::update_user_level_from_caps方法代码示例

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


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

示例1: solvease_roles_capabilities_update_user_role_cap

 /**
  * update user roles and capabilities
  * @param type $user
  * @return boolean
  */
 public function solvease_roles_capabilities_update_user_role_cap($user_id)
 {
     // check if its a valid POST
     if (!isset($_POST['solvease_user_role_cap_nonce']) || !wp_verify_nonce($_POST['solvease_user_role_cap_nonce'], 'solvease_user_role_cap') || $_POST['user_id'] != $user_id) {
         return;
     }
     $user = new WP_User($user_id);
     // capabilities
     $capabilities = isset($_POST['cap']) ? array_keys($_POST['cap']) : array();
     // all user roles
     $all_roles = $this->solvease_roles_capabilities_get_roles();
     // primary roles
     $primary_role = $_POST['primary_role'];
     // secondary roles
     $secondary_roles = isset($_POST['secondary_roles']) ? array_keys($_POST['secondary_roles']) : array();
     // blank user roles
     $user->roles = array();
     // remove all user roles
     $user->remove_all_caps();
     // add primary roles
     if ($primary_role != '' && isset($all_roles[$primary_role])) {
         $user->add_role($primary_role);
     } else {
         return FALSE;
     }
     // add secondary roles
     if (!empty($secondary_roles)) {
         foreach ($secondary_roles as $secondary_role) {
             if (isset($all_roles[$secondary_role]) && $primary_role != $secondary_role) {
                 $user->add_role($secondary_role);
             }
         }
     }
     // add capabilities of user roles
     $user->update_user_level_from_caps();
     // add capabilities
     if (!empty($capabilities)) {
         foreach ($capabilities as $capability) {
             $user->add_cap($capability);
         }
     }
     return $user;
 }
开发者ID:RA2WP,项目名称:RA2WP,代码行数:48,代码来源:class-solvease-wp-roles-capabilities_cap_functionality.php

示例2: update_user

 /**
  * Update user roles and capabilities
  * 
  * @global WP_Roles $wp_roles
  * @param WP_User $user
  * @return boolean
  */
 private function update_user($user)
 {
     global $wp_roles;
     $values = array_values($user->roles);
     $primary_role = array_shift($values);
     // get 1st element from roles array as user primary role
     if (empty($primary_role) || !isset($this->roles[$primary_role])) {
         $primary_role = '';
     }
     if (function_exists('bbp_filter_blog_editable_roles')) {
         // bbPress plugin is active
         $bbp_user_role = bbp_get_user_role($user->ID);
     } else {
         $bbp_user_role = '';
     }
     // revoke all roles and capabilities from this user
     $user->roles = array();
     $user->remove_all_caps();
     // restore primary role
     if (!empty($primary_role)) {
         $user->add_role($primary_role);
     }
     // restore bbPress user role if she had one
     if (!empty($bbp_user_role)) {
         $user->add_role($bbp_user_role);
     }
     // add other roles to user
     foreach ($_POST as $key => $value) {
         $result = preg_match('/^wp_role_(.+)/', $key, $match);
         if ($result === 1) {
             $role = $match[1];
             if (isset($wp_roles->roles[$role])) {
                 $user->add_role($role);
             }
         }
     }
     // add individual capabilities to user
     if (count($this->capabilities_to_save) > 0) {
         foreach ($this->capabilities_to_save as $key => $value) {
             $user->add_cap($key);
         }
     }
     $user->update_user_level_from_caps();
     return true;
 }
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:52,代码来源:class-ure-lib.php


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