當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WP_User::has_cap方法代碼示例

本文整理匯總了PHP中WP_User::has_cap方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_User::has_cap方法的具體用法?PHP WP_User::has_cap怎麽用?PHP WP_User::has_cap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WP_User的用法示例。


在下文中一共展示了WP_User::has_cap方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1:

 function wp_login($username, $password, $already_md5 = false)
 {
     global $db, $error;
     if ('' == $username) {
         return false;
     }
     if ('' == $password) {
         $error = __('<strong>Error</strong>: The password field is empty.');
         return false;
     }
     $user = new WP_User($username);
     if (!$user || !$user->ID) {
         $error = __('<strong>Error</strong>: Wrong username.');
         return false;
     }
     if (!WP_Pass::check_password($password, $user->data->user_pass, $user->ID)) {
         $error = __('<strong>Error</strong>: Incorrect password.');
         $pwd = '';
         return false;
     }
     if (!$user->has_cap('supporter') && !$user->has_cap('supportpressadmin')) {
         return false;
     }
     return true;
 }
開發者ID:bi0xid,項目名稱:bach,代碼行數:25,代碼來源:wp-user.php

示例2: array

 function test_add_caps_to_role()
 {
     $usergroup_roles = array('administrator' => array('edit_usergroups'));
     foreach ($usergroup_roles as $role => $caps) {
         self::$EditFlowModule->add_caps_to_role($role, $caps);
     }
     $user = new WP_User(self::$admin_user_id);
     //Verify before flush
     $this->assertTrue($user->has_cap('edit_usergroups'), 'User did not have role edit_usergroups');
     $this->_flush_roles();
     $this->assertTrue($user->has_cap('edit_usergroups'), 'User did not have role edit_usergroups');
 }
開發者ID:philoserf,項目名稱:Edit-Flow,代碼行數:12,代碼來源:test-edit-flow-class-module.php

示例3: absint

 /**
  * Refrain non-admins from editing / promoting / deleting administrators
  */
 function limit_lower_roles($caps, $cap, $user_id, $args)
 {
     if ('promote_user' == $cap) {
         if (!isset($args[0])) {
             $caps[] = 'do_not_allow';
         }
         if ($args[0] == $user_id) {
             $caps[] = 'do_not_allow';
         }
         $other = new WP_User(absint($args[0]));
         if ($other->has_cap('administrator') && !current_user_can('administrator')) {
             $caps[] = 'do_not_allow';
         }
     } else {
         if ($cap == 'delete_users' || $cap == 'edit_user') {
             if (!isset($_GET['user'])) {
                 return $caps;
             }
             $other_id = absint($_GET['user']);
             if (!$other_id) {
                 return $caps;
             }
             if ($other_id == $user_id) {
                 return $caps;
             }
             $other = new WP_User($other_id);
             if ($other->has_cap('administrator') && !current_user_can('administrator')) {
                 $caps[] = 'do_not_allow';
             }
         }
     }
     return $caps;
 }
開發者ID:trendwerk,項目名稱:editor-capabilities,代碼行數:36,代碼來源:class-tp-editor-capabilities.php

示例4: switch

 /**
  * editable_roles
  * Prevent editing of admins by non-admins.
  *
  * @since 1.0.0
  * @version 1.0.0
  **/
 function map_meta_cap($caps, $cap, $user_id, $args)
 {
     switch ($cap) {
         case 'edit_user':
         case 'remove_user':
         case 'promote_user':
             if (isset($args[0]) && $args[0] == $user_id) {
                 break;
             } elseif (!isset($args[0])) {
                 $caps[] = 'do_not_allow';
             }
             $other = new WP_User(absint($args[0]));
             if ($other->has_cap('administrator')) {
                 if (!current_user_can('administrator')) {
                     $caps[] = 'do_not_allow';
                 }
             }
             break;
         case 'delete_user':
         case 'delete_users':
             if (!isset($args[0])) {
                 break;
             }
             $other = new WP_User(absint($args[0]));
             if ($other->has_cap('administrator')) {
                 if (!current_user_can('administrator')) {
                     $caps[] = 'do_not_allow';
                 }
             }
             break;
     }
     return $caps;
 }
開發者ID:sdellow,項目名稱:wp-framework,代碼行數:40,代碼來源:users.php

示例5: pp_generate_sidebars

function pp_generate_sidebars()
{
    register_sidebar(array('name' => 'All - Top', 'id' => 'pp-sidebar-top', 'before_widget' => '<li id="%1$s" class="widget pp-sidebar-top %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    register_sidebar(array('name' => 'Home', 'id' => 'pp-home-sidebar', 'before_widget' => '<li id="%1$s" class="widget pp-home-sidebar %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    register_sidebar(array('name' => 'Single post page', 'id' => 'pp-single-sidebar', 'before_widget' => '<li id="%1$s" class="widget pp-single-sidebar %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    register_sidebar(array('name' => 'Project (default)', 'id' => 'pp-project-sidebar-default', 'before_widget' => '<li id="%1$s" class="widget pp-project-sidebar pp-project-sidebar-all %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    $options = pp_get_options();
    if ($options['project_sidebars'] && ($projects = pp_get_projects())) {
        foreach ($projects as $project) {
            register_sidebar(array('name' => 'Project - ' . $project->name, 'id' => 'pp-project-sidebar-' . $project->cat_ID, 'before_widget' => '<li id="%1$s" class="widget pp-project-sidebar pp-project-sidebar-' . $project->cat_ID . ' %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
        }
    }
    register_sidebar(array('name' => 'Author (default)', 'id' => 'pp-author-sidebar-default', 'before_widget' => '<li id="%1$s" class="widget pp-author-sidebar pp-author-sidebar-all %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    // Todo: cache the author array
    $authors = array();
    if ($options['author_sidebars'] && ($users = get_users_of_blog())) {
        foreach ($users as $user) {
            $user_object = new WP_User($user->user_id);
            if (!$user_object->has_cap('publish_posts')) {
                continue;
            }
            $authors[] = $user;
        }
    }
    foreach ($authors as $author) {
        register_sidebar(array('name' => 'Author - ' . $author->display_name, 'id' => 'pp-author-sidebar-' . $author->user_id, 'before_widget' => '<li id="%1$s" class="widget pp-author-sidebar pp-author-sidebar-' . $author->user_id . ' %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    }
    register_sidebar(array('name' => 'All - Bottom', 'id' => 'pp-sidebar-bottom', 'before_widget' => '<li id="%1$s" class="widget pp-sidebar-bottom %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
}
開發者ID:rmccue,項目名稱:wordpress-unit-tests,代碼行數:29,代碼來源:functions-sidebars.php

示例6: sa_edituser

function sa_edituser($test)
{
    $sauser = new WP_User(1);
    if ($sauser->has_cap("is_super") == true && current_user_can("is_super") != true) {
        die("You can't do that, this user is a superadmin!");
    }
}
開發者ID:phillipmadsen,項目名稱:g_public,代碼行數:7,代碼來源:superadmin.php

示例7:

 function author_cap_filter($allcaps, $cap, $args)
 {
     // Bail out if we're not asking about a post:
     if ('edit_post' != $args[0]) {
         return $allcaps;
     }
     // Bail out for users who can already edit others posts:
     if ($allcaps['edit_others_posts']) {
         return $allcaps;
     }
     // Bail out for users who can't publish posts:
     if (!isset($allcaps['publish_posts']) or !$allcaps['publish_posts']) {
         return $allcaps;
     }
     // Load the post data:
     $post = get_post($args[2]);
     // Bail out if the user is the post author:
     if ($args[1] == $post->post_author) {
         return $allcaps;
     }
     // Bail out if the post isn't pending or published:
     if ('pending' != $post->post_status and 'publish' != $post->post_status) {
         return $allcaps;
     }
     // Load the author data:
     $author = new WP_User($post->post_author);
     // Bail out if post author can edit others posts:
     if ($author->has_cap('edit_others_posts')) {
         return $allcaps;
     }
     $allcaps[$cap[0]] = true;
     return $allcaps;
 }
開發者ID:coollog,項目名稱:theboola,代碼行數:33,代碼來源:anspress-roles-cap.php

示例8: alo_em_user_can_edit_newsletter

/**
 * User can edit Newsletter
 */
function alo_em_user_can_edit_newsletter($newsletter, $user_id = false)
{
    global $user_ID;
    if (empty($user_id)) {
        $user_id = $user_ID;
    }
    $user = new WP_User($user_id);
    return $user->has_cap('edit_newsletter', $newsletter);
}
開發者ID:dcotet,項目名稱:alo-easymail,代碼行數:12,代碼來源:alo-easymail-newsletters.php

示例9: get_editable_user_ids

function get_editable_user_ids($user_id, $exclude_zeros = true)
{
    global $wpdb;
    $user = new WP_User($user_id);
    if (!$user->has_cap('edit_others_posts')) {
        if ($user->has_cap('edit_posts') || $exclude_zeros == false) {
            return array($user->id);
        } else {
            return false;
        }
    }
    $level_key = $wpdb->prefix . 'user_level';
    $query = "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$level_key}'";
    if ($exclude_zeros) {
        $query .= " AND meta_value != '0'";
    }
    return $wpdb->get_col($query);
}
開發者ID:staylor,項目名稱:develop.svn.wordpress.org,代碼行數:18,代碼來源:admin-db.php

示例10: wpi_test_deprecated

function wpi_test_deprecated() {
	# throw user-levels deprecated notice
	$u = new WP_User(1);
	$u->has_cap(10);
	
	if (is_admin()) {
		add_menu_page('page title', 'menu title', 10, basename(__FILE__), 'wpi_admin_page');
	}
}
開發者ID:Gipetto,項目名稱:wp-interactive,代碼行數:9,代碼來源:tests.php

示例11: die

 function action_ajax_request_user()
 {
     global $wpdb;
     if (!current_user_can(ExecPhp_CAPABILITY_EDIT_PLUGINS) && !current_user_can(ExecPhp_CAPABILITY_EDIT_USERS)) {
         die('-1');
     }
     $feature = explode(',', $_POST['feature']);
     $wants_edit_others_php = in_array(ExecPhp_REQUEST_FEATURE_SECURITY_HOLE, $feature);
     $wants_switch_themes = in_array(ExecPhp_REQUEST_FEATURE_WIDGETS, $feature);
     $wants_exec_php = in_array(ExecPhp_REQUEST_FEATURE_EXECUTE_ARTICLES, $feature);
     $query = "SELECT ID AS user_id FROM {$wpdb->users} ORDER BY display_name";
     $wpdb->query($query);
     $s = $wpdb->get_results($query);
     if (!is_array($s)) {
         $s = array();
     }
     $option =& $this->m_cache->get_option();
     $widget_support = $option->get_widget_support();
     $output_edit_others_php = '';
     $output_switch_themes = '';
     $output_exec_php = '';
     foreach ($s as $i) {
         $user = new WP_User($i->user_id);
         $has_switch_themes = $user->has_cap(ExecPhp_CAPABILITY_EXECUTE_WIDGETS);
         $has_exec_php = $user->has_cap(ExecPhp_CAPABILITY_EXECUTE_ARTICLES);
         $has_edit_others_posts = $user->has_cap(ExecPhp_CAPABILITY_EDIT_OTHERS_POSTS);
         $has_edit_others_pages = $user->has_cap(ExecPhp_CAPABILITY_EDIT_OTHERS_PAGES);
         $has_edit_others_php = $user->has_cap(ExecPhp_CAPABILITY_EDIT_OTHERS_PHP);
         if (($has_edit_others_posts || $has_edit_others_pages) && $has_edit_others_php && !$has_exec_php && $wants_edit_others_php) {
             $output_edit_others_php .= "<li>{$user->data->display_name}</li>";
         }
         if ($has_switch_themes && $widget_support && $wants_switch_themes) {
             $output_switch_themes .= "<li>{$user->data->display_name}</li>";
         }
         if ($has_exec_php && $wants_exec_php) {
             $output_exec_php .= "<li>{$user->data->display_name}</li>";
         }
     }
     $output_edit_others_php = $this->adjust_reply('edit_others_php', $output_edit_others_php);
     $output_switch_themes = $this->adjust_reply('switch_themes', $output_switch_themes);
     $output_exec_php = $this->adjust_reply('exec_php', $output_exec_php);
     die($output_edit_others_php . $output_switch_themes . $output_exec_php);
 }
開發者ID:rezaurc,項目名稱:RE-Exec-PHP,代碼行數:43,代碼來源:ajax.php

示例12: adopt_all_orphans

function adopt_all_orphans()
{
    // Query the users
    $wp_user_search = new WP_User_Search();
    foreach ($wp_user_search->get_results() as $userid) {
        $user = new WP_User($userid);
        if (!$user->has_cap('read')) {
            $user->set_role(get_option('wporphanage_role'));
        }
    }
}
開發者ID:xentek,項目名稱:wp-orphanage,代碼行數:11,代碼來源:wp-orphanage.php

示例13: lti_create_membership_lists

function lti_create_membership_lists($membership_consumer)
{
    global $blog_id;
    if (empty($membership_consumer)) {
        return FALSE;
    }
    foreach ($membership_consumer as $member) {
        // Get new users to WordPress
        $user = get_user_by('login', $member->username);
        if (empty($user)) {
            $member->provision = TRUE;
            // Check if new admin
            if ($member->staff === TRUE) {
                $member->newadmin = TRUE;
            }
        } else {
            // Existing users in WordPress but not members of this blog
            if (!is_user_member_of_blog($user->ID, $blog_id)) {
                $member->new_to_blog = TRUE;
                $member->id = $user->ID;
                // Administrator too!
                if ($member->staff === TRUE) {
                    $member->newadmin = TRUE;
                }
            }
            // Changed users --- name
            $user_data = get_userdata($user->ID);
            if ($member->fullname != $user_data->display_name) {
                $member->changed = TRUE;
                $member->id = $user->ID;
            }
            // Changed role (student -> staff; staff -> student)
            $user = new WP_User('', $member->username, $blog_id);
            if ($member->staff === TRUE && !$user->has_cap('administrator') && is_user_member_of_blog($user->ID, $blog_id)) {
                $member->role_changed = 'administrator';
                $member->id = $user->ID;
            }
            if ($member->staff === FALSE && $member->learner === TRUE && $user->has_cap('administrator') && is_user_member_of_blog($user->ID, $blog_id)) {
                $member->role_changed = 'author';
                $member->id = $user->ID;
            }
            if ($member->staff === FALSE && $member->learner === TRUE && !$user->has_cap('author') && is_user_member_of_blog($user->ID, $blog_id)) {
                $member->role_changed = 'author';
                $member->id = $user->ID;
            }
            if ($member->staff === FALSE && $member->learner === FALSE && ($user->has_cap('author') || $user->has_cap('administrator')) && is_user_member_of_blog($user->ID, $blog_id)) {
                $member->role_changed = 'subscriber';
                $member->id = $user->ID;
            }
        }
    }
    return $membership_consumer;
}
開發者ID:NoisyText,項目名稱:WPMU_LTI_Connector,代碼行數:53,代碼來源:MembershipLibrary.php

示例14: user_can_edit

 /**
  * Determine if the user is eligible to edit the project
  *
  * @static
  * @param int $user_id
  * @return bool
  */
 public function user_can_edit($user_id)
 {
     $user = new WP_User($user_id);
     if ($user->has_cap('edit_projects')) {
         return TRUE;
         // site administrators can edit all projects
     }
     $admins = $this->get_administrators();
     if (in_array($user_id, $admins)) {
         return TRUE;
         // project admins can edit their projects
     }
     return FALSE;
 }
開發者ID:jbrinley,項目名稱:BuggyPress,代碼行數:21,代碼來源:BuggyPress_Project.php

示例15:

 function is_super_admin($user_id = false)
 {
     if (!$user_id) {
         $current_user = wp_get_current_user();
         $user_id = !empty($current_user) ? $current_user->id : 0;
     }
     if (!$user_id) {
         return false;
     }
     $user = new WP_User($user_id);
     if ($user->has_cap('delete_users')) {
         return true;
     }
     return false;
 }
開發者ID:linniepinski,項目名稱:perssistant,代碼行數:15,代碼來源:wp-system-health.php


注:本文中的WP_User::has_cap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。