本文整理汇总了PHP中WP_Roles类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Roles类的具体用法?PHP WP_Roles怎么用?PHP WP_Roles使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Roles类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: un_do_db_upgrade
function un_do_db_upgrade()
{
global $un_default_options, $wp_roles, $wpdb;
$icons = array('idea' => 'icon-lightbulb', 'question' => 'icon-question-sign', 'problem' => 'icon-exclamation-sign', 'praise' => 'icon-heart');
$plural = array('idea' => __('Ideas', 'usernoise'), 'question' => __('Questions', 'usernoise'), 'problem' => __('Problems', 'usernoise'), 'praise' => __('Praises', 'usernoise'));
$index = 0;
$wpdb->un_termmeta = $wpdb->prefix . "un_termmeta";
if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->un_termmeta}'") != $wpdb->un_termmeta) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$sql = "CREATE TABLE `{$wpdb->un_termmeta}` (\n\t\t\t`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`un_term_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t`meta_key` varchar(255) DEFAULT NULL,\n\t\t\t`meta_value` longtext,\n\t\t\tPRIMARY KEY (`meta_id`),\n\t\t\tKEY `un_term_id` (`un_term_id`),\n\t\t\tKEY `meta_key` (`meta_key`)\n\t\t);";
dbDelta($sql);
}
foreach (array('idea' => __('Idea', 'usernoise'), 'question' => __('Question', 'usernoise'), 'problem' => __('Problem', 'usernoise'), 'praise' => __('Praise', 'usernoise')) as $type => $value) {
if (null == ($term = get_term_by('slug', $type, 'feedback_type', ARRAY_A))) {
$term = wp_insert_term($value, FEEDBACK_TYPE, array('slug' => $type));
}
if (null == un_get_term_meta($term['term_id'], 'icon')) {
un_add_term_meta($term['term_id'], 'icon', $icons[$type], true);
un_add_term_meta($term['term_id'], 'plural', $plural[$type], true);
un_add_term_meta($term['term_id'], 'position', $index, true);
}
$index++;
}
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
foreach (un_get_capable_roles() as $role) {
foreach (un_get_feedback_capabilities() as $cap) {
$wp_roles->add_cap($role, $cap);
}
}
update_option('un_db_revision', '2');
}
示例2: check
/**
* given a permission string, check for access requirements
*
* @param string $str the permission to check
*
* @return boolean true if yes, else false
* @access public
*/
function check($str)
{
// Generic cms 'administer users' role tranlates to 'administrator' WordPress role
$str = $this->translatePermission($str, 'WordPress', array('administer users' => 'administrator'));
if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
return FALSE;
}
if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
return TRUE;
}
// for administrators give them all permissions
if (!function_exists('current_user_can')) {
return TRUE;
}
if (current_user_can('super admin') || current_user_can('administrator')) {
return TRUE;
}
// Make string lowercase and convert spaces into underscore
$str = CRM_Utils_String::munge(strtolower($str));
if (is_user_logged_in()) {
// Check whether the logged in user has the capabilitity
if (current_user_can($str)) {
return TRUE;
}
} else {
//check the capabilities of Anonymous user)
$roleObj = new WP_Roles();
if ($roleObj->get_role('anonymous_user') != NULL && array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)) {
return TRUE;
}
}
return FALSE;
}
示例3: delete
/**
* Delete User Role and all User's in role if requested
*
* @param boolean $delete_users
*
* @return boolean
*
* @access public
*/
public function delete($delete_users = false)
{
$role = new WP_Roles();
if ($this->getId() !== 'administrator') {
if ($delete_users) {
if (current_user_can('delete_users')) {
//delete users first
$users = new WP_User_Query(array('number' => '', 'blog_id' => get_current_blog_id(), 'role' => $this->getId()));
foreach ($users->get_results() as $user) {
//user can not delete himself
if ($user instanceof WP_User && $user->ID != get_current_user_id()) {
wp_delete_user($user->ID);
}
}
$role->remove_role($this->getId());
$status = true;
} else {
$status = false;
}
} else {
$role->remove_role($this->getId());
$status = true;
}
} else {
$status = false;
}
return $status;
}
示例4: add_caps
/**
* Adds plugin-specific caps to all roles so that 3rd party plugins can manage them
*/
function add_caps()
{
$version = get_option('post_forking_cap_version');
// Bail Early if we have already set the caps and aren't updating them
if ($version !== false && $this->cap_version <= (int) $version) {
return;
}
add_option('post_forking_cap_version', $this->cap_version, '', 'yes');
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
foreach ($wp_roles->role_names as $role => $label) {
//if the role is a standard role, map the default caps, otherwise, map as a subscriber
$caps = array_key_exists($role, $this->defaults) ? $this->defaults[$role] : $this->defaults['subscriber'];
//loop and assign
foreach ($caps as $cap => $grant) {
//check to see if the user already has this capability, if so, don't re-add as that would override grant
if (!isset($wp_roles->roles[$role]['capabilities'][$cap])) {
$wp_roles->add_cap($role, $cap, $grant);
} else {
$wp_roles->remove_cap($role, $cap);
$wp_roles->add_cap($role, $cap, $grant);
}
}
}
}
示例5: action_plugins_loaded
public function action_plugins_loaded()
{
global $wpdb;
$db_version = get_option('un_version');
if ($db_version == UN_VERSION) {
return;
}
if (!$db_version) {
add_option('un_version', UN_VERSION);
$wpdb->query("UPDATE {$wpdb->postmeta} \n\t\t\t\tINNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id\n\t\t\t\tSET meta_key = '_email' \n\t\t\t\tWHERE meta_key = 'email' AND post_type = 'feedback'\n\t\t\t\t");
}
if (version_compare($db_version, '0.4') == -1) {
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s", FEEDBACK, 'feedback'));
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
foreach (un_get_capable_roles() as $role) {
foreach (un_get_feedback_capabilities() as $cap) {
$wp_roles->add_cap($role, $cap);
}
}
}
if (version_compare($db_version, '0.6') == -1) {
$options = array(UN_USE_FONT, UN_FEEDBACK_BUTTON_TEXT, UN_FEEDBACK_BUTTON_COLOR, UN_FEEDBACK_BUTTON_TEXT_COLOR, UN_FEEDBACK_BUTTON_POSITION, UN_FEEDBACK_FORM_TITLE, UN_FEEDBACK_FORM_TEXT, UN_FEEDBACK_FORM_SHOW_SUMMARY, UN_FEEDBACK_FORM_SHOW_TYPE, UN_FEEDBACK_FORM_SHOW_EMAIL, UN_SUBMIT_FEEDBACK_BUTTON_TEXT, UN_THANKYOU_TITLE, UN_THANKYOU_TEXT, UN_ADMIN_NOTIFY_ON_FEEDBACK, UN_SUBMIT_FEEDBACK_BUTTON_TEXT, UN_SHOW_POWERED_BY, UN_FEEDBACK_BUTTON_SHOW_BORDER, UN_DISABLE_ON_MOBILES, UN_ENABLED, UN_LOAD_IN_FOOTER);
foreach ($options as $option) {
$value = get_option('un_' . $option);
if ($value) {
un_set_option($option, $value);
}
delete_option('un_' . $option);
}
}
update_option('un_version', UN_VERSION);
}
示例6: frontier_post_set_cap
function frontier_post_set_cap()
{
include FRONTIER_POST_DIR . "/include/frontier_post_defaults.php";
$fps_saved_capabilities = frontier_post_get_capabilities();
// Reinstate roles
$fps_roles = new WP_Roles();
$role_list = $fps_roles->get_names();
foreach ($role_list as $key => $item) {
$xrole = get_role($key);
$tmp_caplist = $fps_saved_capabilities[$key];
foreach ($tmp_caplist as $tmp_cap => $tmp_value) {
$fps_cap_name = $tmp_cap;
// Check that the name is a capability (not editor or category)
if (array_key_exists($fps_cap_name, $fp_capability_list) == true) {
if ($tmp_value == "true") {
$xrole->add_cap($tmp_cap);
} else {
$xrole->remove_cap($tmp_cap);
}
$xrole->remove_cap('frontier_post_' . $tmp_cap);
} else {
}
}
// end tmp_caplist
}
// end role_list
}
示例7: handle_rhc_uninstall
function handle_rhc_uninstall()
{
$WP_Roles = new WP_Roles();
foreach (array('calendarize_author', 'edit_' . RHC_CAPABILITY_TYPE, 'read_' . RHC_CAPABILITY_TYPE, 'delete_' . RHC_CAPABILITY_TYPE, 'edit_' . RHC_CAPABILITY_TYPE . 's', 'edit_others_' . RHC_CAPABILITY_TYPE . 's', 'edit_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_published_' . RHC_CAPABILITY_TYPE . 's', 'delete_private_' . RHC_CAPABILITY_TYPE . 's', 'delete_others_' . RHC_CAPABILITY_TYPE . 's', 'publish_' . RHC_CAPABILITY_TYPE . 's', 'read_private_' . RHC_CAPABILITY_TYPE . 's', 'manage_' . RHC_VENUE, 'manage_' . RHC_CALENDAR, 'manage_' . RHC_ORGANIZER) as $cap) {
$WP_Roles->remove_cap(RHC_ADMIN_ROLE, $cap);
}
//-----
}
示例8: wlb_uninstall
function wlb_uninstall()
{
$WP_Roles = new WP_Roles();
foreach (array('wlb_branding', 'wlb_navigation', 'wlb_login', 'wlb_color_scheme', 'wlb_options', 'wlb_role_manager', 'wlb_license', 'wlb_downloads', 'wlb_dashboard_tool') as $cap) {
$WP_Roles->remove_cap(WLB_ADMIN_ROLE, $cap);
}
//-----
}
示例9: get_all_wp_roles
public static function get_all_wp_roles()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
return $wp_roles->get_names();
}
示例10: wp_roles
public function wp_roles()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
$return = $wp_roles->get_names();
return $return;
}
示例11: cab_get_roles
function cab_get_roles()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
$roles = $wp_roles->get_names();
return $roles;
}
示例12: user_roles
/**
* Init dokan user roles
*
* @since Dokan 1.0
* @global WP_Roles $wp_roles
*/
function user_roles()
{
global $wp_roles;
if (class_exists('WP_Roles') && !isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
add_role('seller', __('Seller', 'dokan'), array('read' => true, 'publish_posts' => true, 'edit_posts' => true, 'delete_published_posts' => true, 'edit_published_posts' => true, 'delete_posts' => true, 'manage_categories' => true, 'moderate_comments' => true, 'unfiltered_html' => true, 'upload_files' => true, 'dokandar' => true));
$wp_roles->add_cap('shop_manager', 'dokandar');
$wp_roles->add_cap('administrator', 'dokandar');
}
示例13: bd_pseudo_role_field_get_available_roles
/**
*
* @global WP_Roles $wp_roles
* @return type
*/
function bd_pseudo_role_field_get_available_roles()
{
global $wp_roles;
if (empty($wp_roles)) {
$wp_roles = new WP_Roles();
}
$all_roles = $wp_roles->get_names();
//all roles as role=>role_name
return apply_filters('bp_pseudo_role_field_roles', $all_roles);
}
示例14: get_role_names
function get_role_names()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
$roles = $wp_roles->get_names();
$roles['guest'] = 'Guest';
return $roles;
}
示例15: woocommerce_add_filter_hide_product
public static function woocommerce_add_filter_hide_product($settings)
{
$args = array('post_type' => 'product', 'posts_per_page' => '-1');
$checkproducts = get_posts($args);
if (is_array($checkproducts)) {
foreach ($checkproducts as $product) {
$product_id[] = $product->ID;
$product_title[] = get_the_title($product->ID);
}
}
if (is_array($checkproducts)) {
$newcombinedvalues = array_combine((array) $product_id, (array) $product_title);
}
$get_terms_product = get_terms('product_cat', array('hide_empty' => 'false'));
//var_dump($get_terms_product);
$current_category_products = array();
if (!empty($get_terms_product) && is_array($get_terms_product)) {
foreach ($get_terms_product as $each_term) {
$current_category_products[$each_term->term_id] = $each_term->name;
}
}
//var_dump($current_category_products);
$updated_settings = array();
$mainvariable = array();
foreach ($settings as $section) {
if (isset($section['id']) && '_woo_hide_products_maincontent' == $section['id'] && isset($section['type']) && 'sectionend' == $section['type']) {
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
$getdata = $wp_roles->get_names();
foreach ($getdata as $data => $key) {
$updated_settings[] = array('name' => __('Toggle Shop Products for ' . $key, 'woohideproducts'), 'type' => 'title', 'id' => '_woo_hide_products_' . $data);
$updated_settings[] = array('name' => __('Toggle Type', 'woohideproducts'), 'desc' => __('Toggle Products by category or certain products', 'woohideproducts'), 'tip' => '', 'id' => 'woo_toggle_products_by_type_' . $data, 'css' => '', 'std' => '1', 'defaultvalue' => 'woo_toggle_products_by_type_' . $data, 'type' => 'select', 'options' => array('1' => __('By Products', 'woohideproducts'), '2' => __('By Categories', 'woohideproducts')), 'desc_tip' => true);
$updated_settings[] = array('name' => __('Hide Products in Category', 'woohideproducts'), 'desc' => __('Hide Products in Category Page of WooCommerce', 'woohideproducts'), 'tip' => '', 'id' => 'woo_hide_products_in_category_' . $data, 'css' => '', 'std' => 'yes', 'defaultvalue' => 'woo_hide_products_in_category_' . $data, 'type' => 'checkbox', 'desc_tip' => '');
$updated_settings[] = array('name' => __('Hide Products in Search Result', 'woohideproducts'), 'desc' => __('Hide Products in Search Result of WooCommerce', 'woohideproducts'), 'tip' => '', 'id' => 'woo_hide_products_in_search_' . $data, 'css' => '', 'std' => 'yes', 'defaultvalue' => 'woo_hide_products_in_search_' . $data, 'type' => 'checkbox', 'desc_tip' => '');
$updated_settings[] = array('name' => __('Toggle Include/Exclude Archive Products', 'woohideproducts'), 'desc' => __('Toggle Include Products/Exclude Products in WooCommerce Shop Page', 'woohideproducts'), 'tip' => '', 'id' => 'woo_include_exclude_products_' . $data, 'css' => '', 'std' => '2', 'defaultvalue' => 'woo_include_exclude_products_' . $data, 'type' => 'radio', 'options' => array('1' => __('Include', 'woohideproducts'), '2' => __('Exclude', 'woohideproducts')), 'desc_tip' => true);
$updated_settings[] = array('name' => __('Choose Category', 'woohideproducts'), 'desc' => __('Want to hide products in a bulk way then using this option to hide the products', 'woohideproducts'), 'tip' => '', 'id' => 'woo_toggle_type_category_' . $data, 'css' => '', 'std' => '', 'defaultvalue' => 'woo_toggle_type_category_' . $data, 'type' => 'multiselect', 'options' => $current_category_products);
$updated_settings[] = array('name' => __('Select Product to Toggle Shop', 'woohideproducts'), 'desc' => __('Select Product which will be Toggle Shop in Shop Page', 'woohideproducts'), 'tip' => '', 'id' => 'woo_select_products_' . $data, 'css' => '', 'std' => '', 'type' => 'multiselect', 'options' => $newcombinedvalues);
$updated_settings[] = array('type' => 'sectionend', 'id' => '_woo_hide_products_' . $data);
}
$updated_settings[] = array('name' => __('Toggle Shop Products for Guest', 'woohideproducts'), 'type' => 'title', 'id' => '_woo_hide_products_guest');
$updated_settings[] = array('name' => __('Toggle Type', 'woohideproducts'), 'desc' => __('Toggle Products by category or certain products', 'woohideproducts'), 'tip' => '', 'id' => 'woo_toggle_products_by_type_guest', 'css' => '', 'std' => '1', 'defaultvalue' => 'woo_toggle_products_by_type_guest', 'type' => 'select', 'options' => array('1' => __('By Products', 'woohideproducts'), '2' => __('By Categories', 'woohideproducts')), 'desc_tip' => true);
$updated_settings[] = array('name' => __('Hide Products in Category', 'woohideproducts'), 'desc' => __('Hide Products in Category Page of WooCommerce', 'woohideproducts'), 'tip' => '', 'id' => 'woo_hide_products_in_category_guest', 'css' => '', 'std' => 'yes', 'defaultvalue' => 'woo_hide_products_in_category_guest', 'type' => 'checkbox', 'desc_tip' => '');
$updated_settings[] = array('name' => __('Hide Products in Search Result', 'woohideproducts'), 'desc' => __('Hide Products in Search Result of WooCommerce', 'woohideproducts'), 'tip' => '', 'id' => 'woo_hide_products_in_search_guest', 'css' => '', 'std' => 'yes', 'defaultvalue' => 'woo_hide_products_in_search_guest', 'type' => 'checkbox', 'desc_tip' => '');
$updated_settings[] = array('name' => __('Toggle Include/Exclude Archive Products', 'woohideproducts'), 'desc' => __('Toggle Include Products/Exclude Products in WooCommerce Shop Page', 'woohideproducts'), 'tip' => '', 'id' => 'woo_include_exclude_products_guest', 'css' => '', 'std' => '2', 'defaultvalue' => 'woo_include_exclude_products_guest', 'type' => 'radio', 'options' => array('1' => __('Include', 'woohideproducts'), '2' => __('Exclude', 'woohideproducts')), 'desc_tip' => true);
$updated_settings[] = array('name' => __('Choose Category', 'woohideproducts'), 'desc' => __('Want to hide products in a bulk way then using this option to hide the products', 'woohideproducts'), 'tip' => '', 'id' => 'woo_toggle_type_category_guest', 'css' => '', 'std' => '', 'defaultvalue' => 'woo_toggle_type_category_guest', 'type' => 'multiselect', 'options' => $current_category_products);
$updated_settings[] = array('name' => __('Select Product to Toggle Shop', 'woohideproducts'), 'desc' => __('Select Product which will be Toggle Shop in Shop Page', 'woohideproducts'), 'tip' => '', 'id' => 'woo_select_products_guest', 'css' => '', 'std' => '', 'type' => 'multiselect', 'options' => $newcombinedvalues);
$updated_settings[] = array('type' => 'sectionend', 'id' => '_woo_hide_products_guest');
}
$updated_settings[] = $section;
}
return $updated_settings;
}