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


PHP WP_User类代码示例

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


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

示例1: openfire_authenticate

function openfire_authenticate($user, $username, $password)
{
    global $openfire;
    $openfire->of_logInfo("openfire_authenticate 1 " . $username . " " . $password);
    if (!openfire_wants_to_login()) {
        return new WP_Error('user_logged_out', sprintf(__('You are now logged out of Azure AD.', AADSSO), $username));
    }
    // Don't re-authenticate if already authenticated
    if (strrpos($username, "@") == false || is_a($user, 'WP_User')) {
        return $user;
    }
    $openfire->of_logInfo("openfire_authenticate 2 ");
    // Try to find an existing user in WP where the UPN of the current AAD user is
    // (depending on config) the 'login' or 'email' field
    if ($username && $password && $openfire->of_authenticate_365($username, $password)) {
        $user = get_user_by("email", $username);
        if (!is_a($user, 'WP_User')) {
            $openfire->of_logInfo("openfire_authenticate 3");
            // Since the user was authenticated with AAD, but not found in WordPress,
            // need to decide whether to create a new user in WP on-the-fly, or to stop here.
            $openfire->of_logInfo("openfire_authenticate 4");
            $paras = explode("@", $username);
            $userid = $paras[0] . "." . $paras[1];
            $new_user_id = wp_create_user($userid, $password, $username);
            $user = new WP_User($new_user_id);
            $user->set_role('subscriber');
            $first_name = $openfire->of_get_given_name();
            $last_name = $openfire->get_family_name();
            $display_name = $first_name . " " . $last_name;
            wp_update_user(array('ID' => $new_user_id, 'display_name' => $display_name, 'first_name' => $first_name, 'last_name' => $last_name));
        }
    }
    return $user;
}
开发者ID:igniterealtime,项目名称:community-plugins,代码行数:34,代码来源:ofsocial.php

示例2: getUser

 public static function getUser($jwt)
 {
     global $wpdb;
     if ($jwt instanceof WP_User) {
         return $jwt;
     }
     $user_property = esc_sql(JWT_AUTH_Options::get('user_property'));
     $jwt_attribute = JWT_AUTH_Options::get('jwt_attribute');
     if (trim($user_property) == '' || trim($jwt_attribute) == '') {
         return;
     }
     $id = $jwt->{$jwt_attribute};
     $sql = 'SELECT u.*
             FROM ' . $wpdb->users . '
             WHERE ' . $user_property . ' = %s';
     $userRow = $wpdb->get_row($wpdb->prepare($sql, $id));
     if (is_null($userRow)) {
         return null;
     } elseif ($userRow instanceof WP_Error) {
         self::insertAuth0Error('findAuth0User', $userRow);
         return null;
     }
     $user = new WP_User();
     $user->init($userRow);
     return $user;
 }
开发者ID:mehreencs87,项目名称:wp-jwt-auth,代码行数:26,代码来源:JWT_AUTH_UsersRepo.php

示例3: fromWpItem

 /**
  * Convert a WP menu structure to an associative array.
  *
  * @param array $item An menu item.
  * @param int $position The position (index) of the the menu item.
  * @param string $parent The slug of the parent menu that owns this item. Blank for top level menus.
  * @return array
  */
 public static function fromWpItem($item, $position = 0, $parent = '')
 {
     static $separator_count = 0;
     $default_css_class = empty($parent) ? 'menu-top' : '';
     $item = array('menu_title' => $item[0], 'access_level' => $item[1], 'file' => $item[2], 'page_title' => isset($item[3]) ? $item[3] : '', 'css_class' => isset($item[4]) ? $item[4] : $default_css_class, 'hookname' => isset($item[5]) ? $item[5] : '', 'icon_url' => isset($item[6]) ? $item[6] : 'dashicons-admin-generic', 'position' => $position, 'parent' => $parent);
     if (is_numeric($item['access_level'])) {
         $dummyUser = new WP_User();
         $item['access_level'] = $dummyUser->translate_level_to_cap($item['access_level']);
     }
     if (empty($parent)) {
         $item['separator'] = empty($item['file']) || empty($item['menu_title']) || strpos($item['css_class'], 'wp-menu-separator') !== false;
         //WP 3.0 in multisite mode has two separators with the same filename. Fix by reindexing separators.
         if ($item['separator']) {
             $item['file'] = 'separator_' . $separator_count++;
         }
     } else {
         //Submenus can't contain separators.
         $item['separator'] = false;
     }
     //Flag plugin pages
     $item['is_plugin_page'] = get_plugin_page_hook($item['file'], $parent) != null;
     if (!$item['separator']) {
         $item['url'] = self::generate_url($item['file'], $parent);
     }
     $item['template_id'] = self::template_id($item, $parent);
     return array_merge(self::basic_defaults(), $item);
 }
开发者ID:matthewepler,项目名称:moralcourage,代码行数:35,代码来源:menu-item.php

示例4: wp_install

 /**
  * Installs the blog
  *
  * {@internal Missing Long Description}}
  *
  * @since 2.1.0
  *
  * @param string $blog_title Blog title.
  * @param string $user_name User's username.
  * @param string $user_email User's email.
  * @param bool $public Whether blog is public.
  * @param string $deprecated Optional. Not used.
  * @param string $user_password Optional. User's chosen password. Will default to a random password.
  * @param string $language Optional. Language chosen.
  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
  */
 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '')
 {
     if (!empty($deprecated)) {
         _deprecated_argument(__FUNCTION__, '2.6');
     }
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     populate_options();
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     if ($language) {
         update_option('WPLANG', $language);
     }
     $guessurl = wp_guess_url();
     update_option('siteurl', $guessurl);
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     /*
      * Create default user. If the user already exists, the user tables are
      * being shared among blogs. Just set the role in that case.
      */
     $user_id = username_exists($user_name);
     $user_password = trim($user_password);
     $email_password = false;
     if (!$user_id && empty($user_password)) {
         $user_password = wp_generate_password(12, false);
         $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
         $user_id = wp_create_user($user_name, $user_password, $user_email);
         update_user_option($user_id, 'default_password_nag', true, true);
         $email_password = true;
     } else {
         if (!$user_id) {
             // Password has been provided
             $message = '<em>' . __('Your chosen password.') . '</em>';
             $user_id = wp_create_user($user_name, $user_password, $user_email);
         } else {
             $message = __('User already exists. Password inherited.');
         }
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     flush_rewrite_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.'));
     wp_cache_flush();
     /**
      * Fires after a site is fully installed.
      *
      * @since 3.9.0
      *
      * @param WP_User $user The site owner.
      */
     do_action('wp_install', $user);
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
 }
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:76,代码来源:upgrade.php

示例5: user_meta_shortcode_handler

/**
 * User Meta Shortcode handler
 * Retrieve the value of a property or meta key from the users and usermeta tables.
 * usage: [user_meta user_id=1 key="first_name" size="50" wpautop="on" pre="Pre Label " post="Post Label "]
 * @param  array $atts
 * @param  string $content
 * @return stirng
 */
function user_meta_shortcode_handler($atts, $content = null)
{
    if (!isset($atts['user_id'])) {
        $user = wp_get_current_user();
        $atts['user_id'] = $user->ID;
    }
    if (!isset($atts['size'])) {
        $atts['size'] = '50';
    }
    $user = new WP_User($atts['user_id']);
    if (!$user->exists()) {
        return;
    }
    if ($atts['key'] == 'avatar') {
        return $atts['pre'] . get_avatar($user->ID, $atts['size']) . $atts['post'];
    }
    if ($user->has_prop($atts['key'])) {
        if ($atts['wpautop'] == 'on') {
            $value = wpautop($user->get($atts['key']));
        } else {
            $value = $user->get($atts['key']);
        }
    }
    if (!empty($value)) {
        return $atts['pre'] . $value . $atts['post'];
    }
    return;
}
开发者ID:alvarpoon,项目名称:aeg,代码行数:36,代码来源:pb_user_meta_shortcode.php

示例6: acxu_createUser

function acxu_createUser($args)
{
    global $wp_xmlrpc_server;
    $wp_xmlrpc_server->escape($args);
    $nickname = $args[0];
    //$password = $args[1];
    //if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) )
    //    return $wp_xmlrpc_server->error;
    $user_name = time() . "_" . rand(1000, 9999);
    $user_email = $user_name . "@bbuser.org";
    if (!username_exists($user_name) && !email_exists($user_email)) {
        $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
        $user_id = wp_create_user($user_name, $random_password, $user_email);
        if ($nickname == "") {
            $nickname = $user_email;
        }
        // Update the user to set the nickname
        wp_update_user(array('ID' => $user_id, 'nickname' => $nickname));
        // Get the user object to set the user's role
        $wp_user_object = new WP_User($user_id);
        //http://en.support.wordpress.com/user-roles/
        $wp_user_object->set_role('author');
        return $user_name . " " . $random_password;
    } else {
        return "ERROR: User Name or Email Already Exists";
    }
}
开发者ID:AurangZ,项目名称:securereader,代码行数:27,代码来源:auto-create-xmlrpc-user.php

示例7: save

 public function save($userId)
 {
     if (!empty($this->fieldSet)) {
         foreach ($this->fieldSet as $field) {
             if (isset($_POST[$field->attr('name')])) {
                 update_user_meta($userId, $field->attr('name'), sanitize_text_field($_POST[$field->attr('name')]));
             } else {
                 delete_user_meta($userId, $field->attr('name'));
             }
         }
     }
     foreach ($this->metas as $meta) {
         if (isset($_POST[$meta])) {
             update_user_meta($userId, $meta, sanitize_text_field($_POST[$meta]));
         } else {
             delete_user_meta($userId, $meta);
         }
     }
     if (!empty($this->caps)) {
         $user = new \WP_User($userId);
         foreach ($this->caps as $cap) {
             if (!empty($_POST[$cap])) {
                 $user->add_cap($cap);
             } else {
                 $user->remove_cap($cap);
             }
         }
     }
 }
开发者ID:loumray,项目名称:wpcore,代码行数:29,代码来源:WPuserSection.php

示例8: create_member_page

function create_member_page($user_id)
{
    $user_info = get_userdata($user_id);
    $username = $user_info->user_login;
    $post = array();
    $post['post_name'] = $username;
    // The slug for the page
    $post['post_type'] = 'page';
    //sets type
    $post['post_content'] = esc_attr($username . ' - This page was created for you and any messages that we need to send you with regards to any products, services or changes to your membership will be posted here.' . $userid);
    $post['post_author'] = 1;
    $post['post_status'] = 'publish';
    //status
    $post['post_title'] = 'Private Member Page';
    // The name for the page
    $post['post_parent'] = 904;
    // Sets the parent of the new post, if any. Default 0.
    $post_id = wp_insert_post($post);
    if (!$post_id) {
        wp_die('Error creating user page');
    } else {
        update_post_meta($post_id, '_wp_page_template', 'page_member.php');
        $user = new WP_User($user_id);
        $user->add_cap("access_s2member_ccap_{$username}");
        update_post_meta($post_id, 's2member_ccaps_req', "{$username}");
        $new_options = array();
        // s2member array for security level
        $new_options["ws_plugin__s2member_level0_pages"] = $post_id;
        // set Level0 for this Page
        c_ws_plugin__s2member_menu_pages::update_all_options($new_options, true, false, array("page-conflict-warnings"), true);
        // s2member update
    }
    return;
}
开发者ID:hiryu85,项目名称:s2member-create-member-page,代码行数:34,代码来源:s2-create-member-page.php

示例9: remove_network_snippets_cap

/**
 * Remove the multisite capabilities from a user
 *
 * @since 2.0
 * @param integer $user_id The ID of the user to remove the cap from
 */
function remove_network_snippets_cap($user_id)
{
    /* Get the user from the ID */
    $user = new WP_User($user_id);
    /* Remove the capability */
    $user->remove_cap(apply_filters('code_snippets_network_cap', 'manage_network_snippets'));
}
开发者ID:kgoedecke,项目名称:kevingoedecke-blog,代码行数:13,代码来源:caps.php

示例10: 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

示例11: upgradeSubscriberToAuthor

function upgradeSubscriberToAuthor($user_id)
{
    $user = new WP_User($user_id);
    if (in_array('subscriber', $user->roles)) {
        $user->set_role('author');
    }
}
开发者ID:Cywaithaka,项目名称:bwawwp,代码行数:7,代码来源:example-18.php

示例12: wp_login

 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

示例13: s2_personal_page

function s2_personal_page($user_id)
{
    $user_info = get_userdata($user_id);
    $username = $user_info->user_login;
    $post = array();
    $post['post_name'] = $username;
    $post['post_type'] = 'page';
    $post['post_content'] = esc_attr(get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_content', ''));
    $post['post_author'] = 1;
    $post['post_status'] = 'publish';
    $post['post_title'] = str_replace(array('{{username}}'), array($username), get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_title', 0));
    $post['post_parent'] = get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_parent', 0);
    $post_id = wp_insert_post($post);
    if (!$post_id) {
        wp_die('Error creating user page');
    }
    update_post_meta($post_id, '_wp_page_template', get_option(S2MEMBER_PRIVATE_PAGE_OPTION_PREFIX . 'post_template', 'page.php'));
    $user = new WP_User($user_id);
    $user->add_cap(sprintf('access_s2member_ccap_%s', $username));
    update_post_meta($post_id, 's2member_ccaps_req', $username);
    $new_options = array();
    // s2member array for security level
    $new_options["ws_plugin__s2member_level0_pages"] = $post_id;
    // set Level0 for this Page
    // s2member update
    c_ws_plugin__s2member_menu_pages::update_all_options($new_options, true, false, array("page-conflict-warnings"), true);
    return;
}
开发者ID:hiryu85,项目名称:s2member-create-member-page,代码行数:28,代码来源:s2member-personal-page.php

示例14: 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

示例15: wp_install

function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '')
{
    global $wpdb;
    $base = '/';
    $domain = JQUERY_STAGING_PREFIX . 'jquery.com';
    wp_check_mysql_version();
    wp_cache_flush();
    make_db_current_silent();
    populate_options();
    populate_roles();
    $user_id = wp_create_user($user_name, trim($user_password), $user_email);
    $user = new WP_User($user_id);
    $user->set_role('administrator');
    $guess_url = wp_guess_url();
    foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) {
        $wpdb->{$table} = $prefixed_table;
    }
    install_network();
    populate_network(1, $domain, $user_email, 'jQuery Network', $base, false);
    update_site_option('site_admins', array($user->user_login));
    update_site_option('allowedthemes', array());
    $wpdb->insert($wpdb->blogs, array('site_id' => 1, 'domain' => $domain, 'path' => $base, 'registered' => current_time('mysql')));
    $blog_id = $wpdb->insert_id;
    update_user_meta($user_id, 'source_domain', $domain);
    update_user_meta($user_id, 'primary_blog', $blog_id);
    if (!($upload_path = get_option('upload_path'))) {
        $upload_path = substr(WP_CONTENT_DIR, strlen(ABSPATH)) . '/uploads';
        update_option('upload_path', $upload_path);
    }
    update_option('fileupload_url', get_option('siteurl') . '/' . $upload_path);
    jquery_install_remaining_sites($user);
    wp_new_blog_notification($blog_title, $guess_url, $user_id, $message = __('The password you chose during the install.'));
    wp_cache_flush();
    return array('url' => $guess_url, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}
开发者ID:ravasthi,项目名称:web-base-template,代码行数:35,代码来源:install.php


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