本文整理汇总了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;
}
示例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');
}
示例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;
}
示例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;
}
示例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>'));
}
示例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!");
}
}
示例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;
}
示例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);
}
示例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);
}
示例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');
}
}
示例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);
}
示例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'));
}
}
}
示例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;
}
示例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;
}
示例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;
}