PHP WP_User Code Examples

This page contains top rated real world PHP examples of WP_User extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: anspress-roles-cap.php Project: coollog/theboola
1
 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;
 }
Example #2
Show file File: ofsocial.php Project: igniterealtime/community-plugins
1
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;
}
Example #3
Show file File: molie-admin-roles.php Project: pgogy/WordPress-MOLIE
0
 function create()
 {
     $types = array("course", "quiz", "qa", "dis", "user", "amt");
     $AdminCapabilities = array('edit_linkedcanvas?', 'read_linkedcanvas?', 'delete_linkedcanvas?', 'edit_linkedcanvas?s', 'edit_others_linkedcanvas?s', 'publish_linkedcanvas?s', 'read_private_linkedcanvas?s', 'delete_linkedcanvas?s', 'delete_private_linkedcanvas?s', 'delete_published_linkedcanvas?s', 'delete_others_linkedcanvas?s', 'edit_private_linkedcanvas?s', 'edit_published_linkedcanvas?s', 'edit_linkedcanvas?s');
     $AuthorCapabilities = array('edit_linkedcanvas?', 'read_linkedcanvas?', 'delete_linkedcanvas?', 'edit_linkedcanvas?s', 'publish_linkedcanvas?s', 'read_private_linkedcanvas?s', 'delete_linkedcanvas?s', 'delete_private_linkedcanvas?s', 'delete_published_linkedcanvas?s', 'edit_private_linkedcanvas?s', 'edit_published_linkedcanvas?s', 'edit_linkedcanvas?s');
     $get_users = get_users();
     foreach ($get_users as $user) {
         if (in_array("administrator", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($AdminCapabilities as $capability) {
                 foreach ($types as $type) {
                     $user->add_cap(str_replace("?", $type, $capability));
                 }
             }
         }
         if (in_array("editor", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($AuthorCapabilities as $capability) {
                 foreach ($types as $type) {
                     $user->add_cap(str_replace("?", $type, $capability));
                 }
             }
         }
     }
 }
Example #4
Show file File: upgrade.php Project: sb-xs/que-pour-elle
0
 /**
  * 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);
 }
Example #5
Show file File: WPuserSection.php Project: loumray/wpcore
0
 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);
             }
         }
     }
 }
Example #6
Show file File: auto-create-xmlrpc-user.php Project: AurangZ/securereader
0
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";
    }
}
Example #7
Show file File: upgrade.php Project: alx/blogsfera
0
 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '')
 {
     global $wp_rewrite;
     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);
     $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);
     if (!$user_id) {
         $random_password = wp_generate_password();
         $user_id = wp_create_user($user_name, $random_password, $user_email);
     } else {
         $random_password = __('User already exists.  Password inherited.');
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     $wp_rewrite->flush_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
     wp_cache_flush();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
 }
Example #8
Show file File: s2-create-member-page.php Project: hiryu85/s2member-create-member-page
0
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;
}
Example #9
Show file File: caps.php Project: kgoedecke/kevingoedecke-blog
0
/**
 * 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'));
}
Example #10
Show file File: superadmin.php Project: phillipmadsen/g_public
0
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!");
    }
}
Example #11
Show file File: example-18.php Project: Cywaithaka/bwawwp
0
function upgradeSubscriberToAuthor($user_id)
{
    $user = new WP_User($user_id);
    if (in_array('subscriber', $user->roles)) {
        $user->set_role('author');
    }
}
Example #12
Show file File: wp-user.php Project: bi0xid/bach
0
 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;
 }
Example #13
Show file File: s2member-personal-page.php Project: hiryu85/s2member-create-member-page
0
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;
}
Example #14
Show file File: functions-sidebars.php Project: rmccue/wordpress-unit-tests
0
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>'));
}
Example #15
Show file File: install.php Project: ravasthi/web-base-template
0
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);
}
Example #16
Show file File: upgrade-functions.php Project: staylor/develop.svn.wordpress.org
0
 function wp_install($blog_title, $user_name, $user_email, $public, $meta = '')
 {
     global $wp_rewrite;
     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);
     $schema = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
     $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     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);
     if (!$user_id) {
         $random_password = substr(md5(uniqid(microtime())), 0, 6);
         $user_id = wp_create_user($user_name, $random_password, $user_email);
     } else {
         $random_password = __('User already exists.  Password inherited.');
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     $wp_rewrite->flush_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
     wp_cache_flush();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
 }
Example #17
Show file File: class-gravityview-field-created-by.php Project: mgratch/GravityView
0
 /**
  * Exactly like Gravity Forms' User Meta functionality, but instead shows information on the user who created the entry
  * instead of the currently logged-in user.
  *
  * @see http://docs.gravityview.co/article/281-the-createdby-merge-tag Read how to use the `{created_by}` merge tag
  *
  * @since 1.16
  *
  * @param array $matches Array of Merge Tag matches found in text by preg_match_all
  * @param string $text Text to replace
  * @param array $form Gravity Forms form array
  * @param array $entry Entry array
  * @param bool $url_encode Whether to URL-encode output
  * @param bool $esc_html Whether to apply `esc_html()` to output
  *
  * @return string Text, with user variables replaced, if they existed
  */
 public function replace_merge_tag($matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false)
 {
     // If there are no matches OR the Entry `created_by` isn't set or is 0 (no user)
     if (empty($entry['created_by'])) {
         return $text;
     }
     // Get the creator of the entry
     $entry_creator = new WP_User($entry['created_by']);
     foreach ($matches as $match) {
         $full_tag = $match[0];
         $property = $match[1];
         switch ($property) {
             /** @since 1.13.2 */
             case 'roles':
                 $value = implode(', ', $entry_creator->roles);
                 break;
             default:
                 $value = $entry_creator->get($property);
         }
         $value = $url_encode ? urlencode($value) : $value;
         $value = $esc_html ? esc_html($value) : $value;
         $text = str_replace($full_tag, $value, $text);
     }
     unset($entry_creator);
     return $text;
 }
Example #18
Show file File: users.php Project: sdellow/wp-framework
0
 /**
  * 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;
 }
Example #19
Show file File: class-tp-editor-capabilities.php Project: trendwerk/editor-capabilities
0
 /**
  * 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;
 }
Example #20
Show file File: wpDeleteUser.php Project: plis197715/wordpress-develop
0
 function test_delete_user()
 {
     $user_id = $this->factory->user->create(array('role' => 'author'));
     $user = new WP_User($user_id);
     $post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'post');
     // insert a post and make sure the ID is ok
     $post_id = wp_insert_post($post);
     $this->assertTrue(is_numeric($post_id));
     $this->assertTrue($post_id > 0);
     $post = get_post($post_id);
     $this->assertEquals($post_id, $post->ID);
     $post = array('post_author' => $user_id, 'post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_type' => 'nav_menu_item');
     // insert a post and make sure the ID is ok
     $nav_id = wp_insert_post($post);
     $this->assertTrue(is_numeric($nav_id));
     $this->assertTrue($nav_id > 0);
     $post = get_post($nav_id);
     $this->assertEquals($nav_id, $post->ID);
     wp_delete_user($user_id);
     $user = new WP_User($user_id);
     if (is_multisite()) {
         $this->assertTrue($user->exists());
     } else {
         $this->assertFalse($user->exists());
     }
     $this->assertNotNull(get_post($post_id));
     $this->assertEquals('trash', get_post($post_id)->post_status);
     // nav_menu_item is delete_with_user = false so the nav post should remain published.
     $this->assertNotNull(get_post($nav_id));
     $this->assertEquals('publish', get_post($nav_id)->post_status);
     wp_delete_post($nav_id, true);
     $this->assertNull(get_post($nav_id));
     wp_delete_post($post_id, true);
     $this->assertNull(get_post($post_id));
 }
Example #21
Show file File: JWT_AUTH_UsersRepo.php Project: mehreencs87/wp-jwt-auth
0
 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;
 }
Example #22
Show file File: class-update.php Project: SelaInc/eassignment
0
/**
 * Upgrades vendor permissions
 *
 * @since 2.2
 * @return void
 */
function fes_22_upgrade_vendor_permissions()
{
    $fes_version = get_option('fes_db_version', '2.1');
    if (version_compare($fes_version, '2.2', '>=')) {
        return;
    }
    ignore_user_abort(true);
    if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
        set_time_limit(0);
    }
    $step = isset($_GET['step']) ? absint($_GET['step']) : 1;
    $offset = $step == 1 ? 0 : $step * 100;
    $users = new WP_User_Query(array('fields' => 'ID', 'number' => 100, 'offset' => $offset));
    $users = $users->results;
    if ($users && count($users) > 0) {
        foreach ($users as $user => $id) {
            if (user_can($id, 'fes_is_vendor') && !user_can($id, 'fes_is_admin') && !user_can($id, 'administrator') && !user_can($id, 'editor')) {
                $user = new WP_User($id);
                $user->add_role('frontend_vendor');
            }
        }
        // Keys found so upgrade them
        $step++;
        $redirect = add_query_arg(array('page' => 'fes-upgrades', 'edd_upgrade' => 'upgrade_vendor_permissions', 'step' => $step), admin_url('index.php'));
        wp_redirect($redirect);
        exit;
    } else {
        // No more keys found, update the DB version and finish up
        update_option('fes_db_version', fes_plugin_version);
        wp_redirect(admin_url('admin.php?page=fes-about'));
        exit;
    }
}
Example #23
Show file File: learning-registry-publisher.php Project: navnorth/wp-learning-registry-publisher
0
 function activate()
 {
     global $wpdb;
     if (!get_option("lrp_database_establish")) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         $table_name = $wpdb->prefix . "lrp_documents_history";
         $sql = "CREATE TABLE " . $table_name . " (\n\t\t\t\t  id bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  post bigint(20),\n\t\t\t\t  lrnode bigint(20),\n\t\t\t\t  lrkey bigint(20),\n\t\t\t\t  lrschema bigint(20),\n\t\t\t\t  lruser bigint(20),\n\t\t\t\t  lraction varchar(100),\n\t\t\t\t  lrdocid varchar(100),\n\t\t\t\t  date_submitted bigint(20),\n\t\t\t\t  UNIQUE KEY id(id)\n\t\t\t\t);";
         dbDelta($sql);
         add_option("lrp_database_establish", 1);
     }
     $get_users = get_users();
     foreach ($get_users as $user) {
         if (in_array("administrator", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($this->AdministratorCapabilities as $capability) {
                 $user->add_cap($capability);
             }
         }
         if (in_array("editor", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($this->EditorCapabilities as $capability) {
                 $user->add_cap($capability);
             }
         }
         if (in_array("author", $user->roles)) {
             $user = new WP_User($user->data->ID);
             foreach ($this->AuthorCapabilities as $capability) {
                 $user->add_cap($capability);
             }
         }
     }
 }
Example #24
Show file File: menu-item.php Project: matthewepler/moralcourage
0
 /**
  * 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);
 }
Example #25
Show file File: pb_user_meta_shortcode.php Project: alvarpoon/aeg
0
/**
 * 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;
}
Example #26
Show file File: registration-functions.php Project: robertlange81/Website
0
function wp_insert_user($userdata)
{
    global $wpdb;
    extract($userdata);
    // Are we updating or creating?
    if (!empty($ID)) {
        $update = true;
    } else {
        $update = false;
        // Password is not hashed when creating new user.
        $user_pass = md5($user_pass);
    }
    if (empty($user_nicename)) {
        $user_nicename = sanitize_title($user_login);
    }
    if (empty($display_name)) {
        $display_name = $user_login;
    }
    if (empty($nickname)) {
        $nickname = $user_login;
    }
    if (empty($user_registered)) {
        $user_registered = gmdate('Y-m-d H:i:s');
    }
    if ($update) {
        $query = "UPDATE {$wpdb->users} SET user_pass='{$user_pass}', user_email='{$user_email}', user_url='{$user_url}', user_nicename = '{$user_nicename}', display_name = '{$display_name}' WHERE ID = '{$ID}'";
        $query = apply_filters('update_user_query', $query);
        $wpdb->query($query);
        $user_id = $ID;
    } else {
        $query = "INSERT INTO {$wpdb->users} \n\t\t(user_login, user_pass, user_email, user_url, user_registered, user_nicename, display_name)\n\tVALUES \n\t\t('{$user_login}', '{$user_pass}', '{$user_email}', '{$user_url}', '{$user_registered}', '{$user_nicename}', '{$display_name}')";
        $query = apply_filters('create_user_query', $query);
        $wpdb->query($query);
        $user_id = $wpdb->insert_id;
    }
    update_usermeta($user_id, 'first_name', $first_name);
    update_usermeta($user_id, 'last_name', $last_name);
    update_usermeta($user_id, 'nickname', $nickname);
    update_usermeta($user_id, 'description', $description);
    update_usermeta($user_id, 'jabber', $jabber);
    update_usermeta($user_id, 'aim', $aim);
    update_usermeta($user_id, 'yim', $yim);
    if ($update && !empty($role)) {
        $user = new WP_User($user_id);
        $user->set_role($role);
    }
    if (!$update) {
        $user = new WP_User($user_id);
        $user->set_role(get_settings('default_role'));
    }
    wp_cache_delete($user_id, 'users');
    wp_cache_delete($user_login, 'userlogins');
    if ($update) {
        do_action('profile_update', $user_id);
    } else {
        do_action('user_register', $user_id);
    }
    return $user_id;
}
Example #27
Show file File: upgrade.php Project: ramo01/1kapp
0
 /**
  * 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 null $deprecated Optional. Not used.
  * @param string $user_password Optional. User's chosen password. Will default to a random password.
  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
  */
 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '')
 {
     if (!empty($deprecated)) {
         _deprecated_argument(__FUNCTION__, '2.6');
     }
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     if (!is_file(ABSPATH . 'wp-admin/install.sql')) {
         //[ysd]如果有install.sql不设置默认options数据
         populate_options();
     } else {
         validate_active_plugins();
         //[ysd] 禁用 不可用的插件
     }
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     $guessurl = isset($_SERVER['HTTP_APPNAME']) ? 'http://' . substr($_SERVER['HTTP_APPNAME'], 5) . '.1kapp.com' : wp_guess_url();
     //[ysd] 固定了guessurl
     update_option('siteurl', $guessurl);
     update_option('home', $guessurl);
     get_option('siteurl');
     // 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');
     if (!file_exists(ABSPATH . 'wp-admin/without_default')) {
         wp_install_defaults($user_id);
     }
     //[ysd],如果打包时设置了默认数据,才会设置默认数据
     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();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
 }
Example #28
Show file File: factory.php Project: CompositeUK/clone.BuddyPress
0
 /**
  * @ticket BP7243
  */
 public function test_friendship_should_create_default_initiator_and_friend()
 {
     $f = $this->factory->friendship->create_and_get();
     $u1 = new WP_User($f->initiator_user_id);
     $u2 = new WP_User($f->friend_user_id);
     $this->assertTrue($u1->exists());
     $this->assertTrue($u2->exists());
 }
Example #29
Show file File: Extension.php Project: daanbakker1995/vanteun
0
 public static function update_status_unknown_to_success(Pronamic_Pay_Payment $payment, $can_redirect = false)
 {
     $data = new Pronamic_WP_Pay_Extensions_S2Member_PaymentData(array('level' => get_post_meta($payment->get_id(), '_pronamic_payment_s2member_level', true), 'period' => get_post_meta($payment->get_id(), '_pronamic_payment_s2member_period', true), 'ccaps' => get_post_meta($payment->get_id(), '_pronamic_payment_s2member_ccaps', true)));
     $email = $payment->get_email();
     // get account from email
     $user = get_user_by('email', $email);
     // No valid user?
     if (!$user) {
         // Make a random string for password
         $random_string = wp_generate_password(10);
         // Make a user with the username as the email
         $user_id = wp_create_user($email, $random_string, $email);
         // Subject
         $subject = __('Account Confirmation', 'pronamic_ideal') . ' | ' . get_bloginfo('name');
         // Message
         $message = get_option('pronamic_pay_s2member_signup_email_message');
         $message = str_replace(array('%%email%%', '%%password%%'), array($email, $password), $message);
         // Mail
         wp_mail($email, $subject, $message);
         $user = new WP_User($user_id);
     }
     $level = $data->get_level();
     $period = $data->get_period();
     $ccaps = $data->get_ccaps();
     $capability = 'access_s2member_level' . $level;
     $role = 's2member_level' . $level;
     // Update user role
     //$user->add_cap( $capability ); // TODO Perhaps this should line be removed. At s2Member EOT this capability is not removed, which allows the user to illegitimately view the protected content.
     $user->set_role($role);
     $note = sprintf(__('Update user "%s" to role "%s" and added custom capability "%s".', 'pronamic_ideal'), $email, $role, $capability);
     $payment->add_note($note);
     // Custom Capabilities
     if (!empty($ccaps)) {
         $ccaps = Pronamic_WP_Pay_Extensions_S2Member_Util::ccap_string_to_array($ccaps);
         Pronamic_WP_Pay_Extensions_S2Member_Util::ccap_user_update($user, $ccaps);
     }
     // Registration times
     $registration_time = time();
     $registration_times = get_user_option('s2member_paid_registration_times', $user->ID);
     if (empty($registration_times)) {
         $registration_times = array();
     }
     $registration_times['level' . $level] = $registration_time;
     update_user_option($user->ID, 's2member_paid_registration_times', $registration_times);
     if (in_array($period, array('1 L'))) {
         // Lifetime, delete end of time option
         delete_user_option($user->ID, 's2member_auto_eot_time');
     } else {
         // Auto end of time
         // @see https://github.com/WebSharks/s2Member/blob/131126/s2member/includes/classes/utils-time.inc.php#L100
         $eot_time_current = get_user_option('s2member_auto_eot_time', $user->ID);
         if (!is_numeric($eot_time_current)) {
             $eot_time_current = time();
         }
         $eot_time_new = c_ws_plugin__s2member_utils_time::auto_eot_time($user->ID, false, $period, false, $eot_time_current);
         update_user_option($user->ID, 's2member_auto_eot_time', $eot_time_new);
     }
 }
Example #30
Show file File: expire-users.php Project: abhijagtap73/expire-users
0
 /**
  * Change role when user expires?
  */
 function handle_on_expire_default_to_role($expired_user)
 {
     if ($expired_user->on_expire_default_to_role) {
         if (get_role($expired_user->on_expire_default_to_role)) {
             $u = new WP_User($expired_user->user_id);
             $u->set_role($expired_user->on_expire_default_to_role);
         }
     }
 }