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


PHP WP_Roles::add_role方法代码示例

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


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

示例1: add

 /**
  *
  * @return type
  */
 public function add()
 {
     $name = trim(aam_Core_Request::post('name'));
     $roles = new WP_Roles();
     $role_id = 'aamrole_' . uniqid();
     if ($roles->add_role($role_id, $name)) {
         $response = array('status' => 'success', 'role' => $role_id);
     } else {
         $response = array('status' => 'failure');
     }
     return json_encode($response);
 }
开发者ID:dot2006,项目名称:jobify,代码行数:16,代码来源:role.php

示例2: add_dentix_caps_to_admin

 public function add_dentix_caps_to_admin()
 {
     global $wp_roles;
     if (!isset($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     //create a new role, based on the subscriber role
     $subscriber = $wp_roles->get_role('subscriber');
     $wp_roles->add_role('dentist', __('Dentist', 'dentix'), $subscriber->capabilities);
     $caps = array('read', 'read_patient', 'read_private_patients', 'edit_patients', 'edit_private_patients', 'edit_published_patients', 'edit_others_patients', 'publish_patients', 'delete_patients', 'delete_private_patients', 'delete_published_patients', 'delete_others_patients', 'upload_files');
     $roles = array(get_role('administrator'), get_role('dentist'));
     foreach ($roles as $role) {
         foreach ($caps as $cap) {
             $role->add_cap($cap);
         }
     }
 }
开发者ID:basoro,项目名称:dentix,代码行数:17,代码来源:patient-post-type.php

示例3: add

 /**
  *
  * @return type
  */
 public function add()
 {
     $name = trim(aam_Core_Request::post('name'));
     $roles = new WP_Roles();
     $role_id = 'aamrole_' . uniqid();
     //if inherited role is set get capabilities from it
     $parent = trim(aam_Core_Request::post('inherit'));
     if ($parent && $roles->get_role($parent)) {
         $caps = $roles->get_role($parent)->capabilities;
     } else {
         $caps = array();
     }
     if ($roles->add_role($role_id, $name, $caps)) {
         $response = array('status' => 'success', 'role' => $role_id);
     } else {
         $response = array('status' => 'failure');
     }
     return json_encode($response);
 }
开发者ID:subhadip-sahoo,项目名称:wp-project1,代码行数:23,代码来源:role.php

示例4: wpdm_cal_create_new_role

function wpdm_cal_create_new_role()
{
    global $wpdb;
    $option_name = "{$wpdb->prefix}user_roles";
    $roles = maybe_unserialize(get_option($option_name));
    $nrk = preg_replace('/([^a-z,0-9]+)/is', '_', strtolower($_POST['wpdm_cal_new_role']));
    if (!@array_key_exists($nrk, $roles) && $nrk != '') {
        $role_obj = new WP_Roles();
        $role_obj->add_role($nrk, $_POST['wpdm_cal_new_role'], array('read' => 1, 'level_0' => 1));
        echo $_POST['wpdm_cal_new_role'];
        die;
    } else {
        if (@array_key_exists($nrk, $roles)) {
            die('Role name already exists');
        }
        if ($nrk == '') {
            die('Invalid Role name');
        }
    }
}
开发者ID:seelang2,项目名称:ClassArchive,代码行数:20,代码来源:wpdm-custom-access-level.php

示例5: orbis_update_roles

function orbis_update_roles($roles)
{
    global $wp_roles;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    foreach ($roles as $role => $data) {
        if (isset($data['display_name'], $data['capabilities'])) {
            $display_name = $data['display_name'];
            $capabilities = $data['capabilities'];
            if ($wp_roles->is_role($role)) {
                foreach ($capabilities as $cap => $grant) {
                    $wp_roles->add_cap($role, $cap, $grant);
                }
            } else {
                $wp_roles->add_role($role, $display_name, $capabilities);
            }
        }
    }
}
开发者ID:joffcrabtree,项目名称:wp-orbis-keychains,代码行数:20,代码来源:post.php

示例6: add_role

/**
 * Add role, if it does not exist.
 *
 * @see WP_Roles::add_role() Uses method to add role.
 * @since 2.0.0
 *
 * @param string $role Role name.
 * @param string $display_name Display name for role.
 * @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );
 * @return null|WP_Role WP_Role object if role is added, null if already exists.
 */
function add_role($role, $display_name, $capabilities = array())
{
    global $wp_roles;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    return $wp_roles->add_role($role, $display_name, $capabilities);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:19,代码来源:capabilities.php

示例7: add_role

 /**
  * Updates the list of roles, if the role doesn't already exist.
  *
  * The capabilities are defined in the following format `array( 'read' => true );`
  * To explicitly deny a role a capability you set the value for that capability to false.
  *
  * In this overide method you can extends the capapilities array with format
  * `array( 'read' => true, 'description' => 'Thsi capability allow access to...' );`
  *
  * @brief Add role name with capabilities to list.
  *
  * @param string $role         Role name.
  * @param string $display_name Role display name.
  * @param array  $capabilities Optional. List of role capabilities in the above format.
  * @param string $description  Optional. An extend description for this role.
  * @param string $owner        Optional. Owner of this role
  *
  * @note  This method override the WP_Roles method to extend
  *
  * @return null|WP_Role
  */
 public function add_role($role, $display_name, $capabilities = array(), $description = '', $owner = '')
 {
     // Normalize caps
     $caps = array();
     foreach ($capabilities as $cap) {
         $caps[$cap] = true;
     }
     // Ask to parent
     $role_object = parent::add_role($role, $display_name, $caps);
     // Stability
     if (!is_null($role_object)) {
         if (!isset($this->extend_data[$role])) {
             $this->extend_data[$role] = array($display_name, $description, $owner);
         }
         update_option(self::OPTION_KEY, $this->extend_data);
         /**
          * Fires when a role is added.
          *
          * @since 1.6.0
          *
          * @param string $role   The role key.
          * @param array  $extend The array with extend data for this role
          */
         do_action('wpdk_user_roles_added_role', $role, $this->extend_data[$role]);
     }
     return $role_object;
 }
开发者ID:wpxtreme,项目名称:wpdk,代码行数:48,代码来源:wpdk-user-roles.php

示例8: array

 /**
  * Create a brand new role, with its capabilities. The add_role from parent is simply made more secure.
  *
  * @brief Create a brand new role
  *
  * @since 0.0.1
  *
  * @param string $sRoleName     - role name/key in DB and in the whole system
  * @param string $sRoleLabel    - label of role in WordPress environment ( i.e. in user settings ).
  * @param array  $aCapabilities (optional) Array of capabilities for this role. Default to array().
  *
  * @return mixed WP_Role|WPDKError : the new role, or the error occurred.
  *
  */
 function add_role($sRoleName, $sRoleLabel, $aCapabilities = array())
 {
     // check about role syntax
     if (empty($sRoleName) || empty($sRoleLabel)) {
         return new WPDKError('WPDKRoles', __('Role data cannot be empty.', WPDK_TEXTDOMAIN));
     }
     // check about role data length
     if (strlen($sRoleName) >= self::MAX_LENGTH_OF_ROLE_DATA || strlen($sRoleLabel) >= self::MAX_LENGTH_OF_ROLE_DATA) {
         return new WPDKError('WPDKRoles', sprintf(__('Role data cannot be more than %s chars.', WPDK_TEXTDOMAIN), self::MAX_LENGTH_OF_ROLE_DATA));
     }
     // role name/key can contain only letters, digits and some other chars
     if (1 == preg_match('/[^a-zA-Z0-9_\\-]+/', $sRoleName)) {
         return new WPDKError('WPDKRoles', __('Role name can contain only letters, digits, \'_\' and \'-\' chars.', WPDK_TEXTDOMAIN));
     }
     // this role must be UNIQ in the whole WP system
     if (TRUE == $this->is_role($sRoleName)) {
         return new WPDKError('WPDKRoles', sprintf(__("Can't create two roles with the same name '%s'.", WPDK_TEXTDOMAIN), $sRoleName));
     }
     // create the role
     $cRole = parent::add_role($sRoleName, $sRoleLabel, $aCapabilities);
     // update options with extended data about role and return - role has a prefix to distinguish from cap
     //    return self::update_extended_data( self::ROLE_KEY_PREFIX . $sRoleName, $aNewData );
     return $cRole;
 }
开发者ID:wpxtreme,项目名称:wpdk,代码行数:38,代码来源:wpdk-roles-caps.php

示例9: roles

	/**
	 * Installed roles and capabilities used for Ecart
	 *
	 * Capabilities						Role
	 * _______________________________________________
	 *
	 * ecart_settings					admin
	 * ecart_settings_checkout
	 * ecart_settings_payments
	 * ecart_settings_shipping
	 * ecart_settings_taxes
	 * ecart_settings_presentation
	 * ecart_settings_system
	 * ecart_settings_update
	 * ecart_financials					merchant
	 * ecart_promotions
	 * ecart_products
	 * ecart_categories
	 * ecart_orders						ecart-csr
	 * ecart_customers
	 * ecart_menu
	 *
	 * @author John Dillick
	 * @since 1.1
	 *
	 **/
	function roles () {
		global $wp_roles; // WP_Roles roles container
		if(!$wp_roles) $wp_roles = new WP_Roles();
		$ecart_roles = array('administrator'=>'Administrator', 'ecart-merchant'=>__('Merchant','Ecart'), 'ecart-csr'=>__('Customer Service Rep','Ecart'));
		$caps['ecart-csr'] = array('ecart_customers', 'ecart_orders','ecart_menu','read');
		$caps['ecart-merchant'] = array_merge($caps['ecart-csr'],
			array('ecart_categories',
				'ecart_products',
				'ecart_promotions',
				'ecart_financials',
				'ecart_export_orders',
				'ecart_export_customers',
				'ecart_delete_orders',
				'ecart_delete_customers'));
		$caps['administrator'] = array_merge($caps['ecart-merchant'],
			array('ecart_settings_update',
				'ecart_settings_system',
				'ecart_settings_presentation',
				'ecart_settings_taxes',
				'ecart_settings_shipping',
				'ecart_settings_payments',
				'ecart_settings_checkout',
				'ecart_settings'));
		$wp_roles->remove_role('ecart-csr');
		$wp_roles->remove_role('ecart-merchant');

		foreach($ecart_roles as $role => $display) {
			if($wp_roles->is_role($role)) {
				foreach($caps[$role] as $cap) $wp_roles->add_cap($role, $cap, true);
			} else {
				$wp_roles->add_role($role, $display, array_combine($caps[$role],array_fill(0,count($caps[$role]),true)));
			}
		}
	}
开发者ID:robbiespire,项目名称:paQui,代码行数:60,代码来源:Install.php

示例10: wps_change_roles

function wps_change_roles()
{
    global $wp_roles;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    $wp_roles->add_role('student', 'Student', array('read' => true, 'edit_posts' => true, 'delete_posts' => true));
    $wp_roles->remove_role('teacher');
    $wp_roles->roles['author']['name'] = 'Parent';
    $wp_roles->role_names['author'] = 'Parent';
    $wp_roles->roles['editor']['name'] = 'Teacher';
    $wp_roles->role_names['editor'] = 'Teacher';
}
开发者ID:johnnygan,项目名称:cphedu,代码行数:13,代码来源:functions.php

示例11: bum_manage_roles

/**
 * Handle role stuff
 */
function bum_manage_roles()
{
    $action = isset($_POST['action']) ? $_POST['action'] : $_GET['action'];
    switch ($action) {
        case 'delete-user-role':
            //get vars
            $name = $_GET['delete-id'];
            $roles = new WP_Roles();
            $roles->remove_role($name);
            break;
        case 'edit-user-role':
            //get vars
            $edit_id = $_POST['edit-id'];
        case 'add-user-role':
            //get vars
            $allow = $_POST['role-allow'] == 'yes' ? 'yes' : 'no';
            $name = $_POST['role-name'];
            $id = $_POST['role-slug'] == '' ? sanitize_title($name) : $_POST['role-slug'];
            //add role
            $roles = new WP_Roles();
            if (isset($edit_id)) {
                $roles->remove_role($edit_id);
            }
            $roles->add_role($id, $name, array());
            //save registration part in hidden taxonomy
            $term = get_term_by('slug', sanitize_title(isset($edit_id) ? $edit_id : $id), BUM_HIDDEN_ROLES);
            if ($term) {
                wp_update_term($term->term_id, BUM_HIDDEN_ROLES, array('description' => $allow));
            } else {
                wp_insert_term(sanitize_title(isset($edit_id) ? $edit_id : $id), BUM_HIDDEN_ROLES, array('description' => $allow));
            }
            break;
    }
    echo bum_get_show_view('bum-manage-roles');
}
开发者ID:Jonathonbyrd,项目名称:better-user-management,代码行数:38,代码来源:better-user-management.php

示例12: ajax_add

 /**
  * Handle the Add Role AJAX
  *
  * @param $params
  * @return mixed|void
  */
 public function ajax_add($params)
 {
     global $wp_roles;
     $role_name = pods_var_raw('role_name', $params);
     $role_label = pods_var_raw('role_label', $params);
     $params->capabilities = (array) pods_var_raw('capabilities', $params, array());
     $params->custom_capabilities = (array) pods_var_raw('custom_capabilities', $params, array());
     $params->custom_capabilities = array_filter(array_unique($params->custom_capabilities));
     $capabilities = array();
     foreach ($params->capabilities as $capability => $x) {
         if (empty($capability) || true !== (bool) $x) {
             continue;
         }
         $capabilities[esc_attr($capability)] = true;
     }
     foreach ($params->custom_capabilities as $x => $capability) {
         if (empty($capability) || '--1' == $x) {
             continue;
         }
         $capabilities[esc_attr($capability)] = true;
     }
     if (empty($role_name)) {
         return pods_error(__('Role name is required', 'pods'));
     }
     if (empty($role_label)) {
         return pods_error(__('Role label is required', 'pods'));
     }
     if (!isset($wp_roles)) {
         $wp_roles = new WP_Roles();
     }
     return $wp_roles->add_role($role_name, $role_label, $capabilities);
 }
开发者ID:centaurustech,项目名称:chipin,代码行数:38,代码来源:Roles.php

示例13: cloneUserRole

function cloneUserRole()
{
    global $wp_roles;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    $adm = $wp_roles->get_role('editor');
    // Adding a new role with all admin caps.
    $wp_roles->add_role('doctor', 'Doctor', $adm->capabilities);
}
开发者ID:bself,项目名称:nuimage-wp,代码行数:10,代码来源:functions.php

示例14: removeSuperAdminRole

 protected function removeSuperAdminRole()
 {
     //update the role capabilities and remove super admin role
     $roles = new WP_Roles();
     //get all capabilities first and merge them in one array
     $capabilities = array();
     foreach ($roles->role_objects as $role) {
         $capabilities = array_merge($capabilities, $role->capabilities);
     }
     if (count($capabilities)) {
         //update administrator capability role
         if ($admin = $roles->get_role('administrator')) {
             foreach ($capabilities as $capability => $grand) {
                 $admin->add_cap($capability);
             }
         } else {
             $roles->add_role('administrator', 'Administrator', $capabilities);
         }
         //remove Super Admin Role
         $roles->remove_role('super_admin');
     }
 }
开发者ID:dot2006,项目名称:jobify,代码行数:22,代码来源:migrate.php

示例15: add

 /**
  * Add New Role
  * 
  * @return string
  * 
  * @access public
  */
 public function add()
 {
     $name = trim(aam_Core_Request::post('name'));
     $roles = new WP_Roles();
     if (aam_Core_ConfigPress::getParam('aam.native_role_id') === 'true') {
         $role_id = strtolower($name);
     } else {
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         /////////////////////////////////// SIGOES //////////////////////////////////////////////////////////////////////////
         //$role_id = 'aamrole_' . uniqid(); // QUITA EL CODIGO DEL ROL EN WP_CAPABILITIES
         $role_id = $name;
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     }
     //if inherited role is set get capabilities from it
     $parent = trim(aam_Core_Request::post('inherit'));
     if ($parent && $roles->get_role($parent)) {
         $caps = $roles->get_role($parent)->capabilities;
     } else {
         $caps = array();
     }
     if ($roles->add_role($role_id, $name, $caps)) {
         $response = array('status' => 'success', 'role' => $role_id);
     } else {
         $response = array('status' => 'failure');
     }
     return json_encode($response);
 }
开发者ID:jr01106,项目名称:advanced-access-manager,代码行数:34,代码来源:role.php


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