WP_User PHP Class Code Examples

This page contains top rated real world PHP examples of class WP_User extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: user-roles.php Project: edgemm/legendhomes-staging
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;
         default:
             break;
     }
     return $caps;
 }
Example #2
Show file File: class-piklist-user.php Project: igniterealtime/community-plugins
0
 public static function multiple_roles($user_id, $roles = false)
 {
     global $wpdb, $wp_roles, $current_user, $pagenow;
     $roles = $roles ? $roles : (isset($_POST['roles']) && isset($_POST['roles'][0]) ? $_POST['roles'][0] : false);
     if ($roles && current_user_can('edit_user', $current_user->ID)) {
         $editable_roles = get_editable_roles();
         $user = new WP_User($user_id);
         $user_roles = array_intersect(array_values($user->roles), array_keys($editable_roles));
         $_user_role_log = get_user_meta($user_id, $wpdb->prefix . 'capabilities_log', true);
         $user_role_log = $_user_role_log ? $_user_role_log : array();
         $roles = is_array($roles) ? $roles : array($roles);
         foreach ($roles as $role) {
             if (!in_array($role, $user_roles) && $wp_roles->is_role($role)) {
                 $user->add_role($role);
                 array_push($user_role_log, array('action' => 'add', 'role' => $role, 'timestamp' => time()));
             }
         }
         foreach ($user_roles as $role) {
             if (!in_array($role, $roles) && $wp_roles->is_role($role)) {
                 $user->remove_role($role);
                 array_push($user_role_log, array('action' => 'remove', 'role' => $role, 'timestamp' => time()));
             }
         }
         update_user_meta($user_id, $wpdb->prefix . 'capabilities_log', $user_role_log);
     }
 }
Example #3
Show file File: special-mail-tags.php Project: KurtMakesWeb/CandG
0
function wpcf7_special_mail_tag_for_post_data($output, $name)
{
    if (!isset($_POST['_wpcf7_unit_tag']) || empty($_POST['_wpcf7_unit_tag'])) {
        return $output;
    }
    if (!preg_match('/^wpcf7-f(\\d+)-p(\\d+)-o(\\d+)$/', $_POST['_wpcf7_unit_tag'], $matches)) {
        return $output;
    }
    $post_id = (int) $matches[2];
    if (!($post = get_post($post_id))) {
        return $output;
    }
    $user = new WP_User($post->post_author);
    // For backwards compat.
    $name = preg_replace('/^wpcf7\\./', '_', $name);
    if ('_post_id' == $name) {
        $output = (string) $post->ID;
    } elseif ('_post_name' == $name) {
        $output = $post->post_name;
    } elseif ('_post_title' == $name) {
        $output = $post->post_title;
    } elseif ('_post_url' == $name) {
        $output = get_permalink($post->ID);
    } elseif ('_post_author' == $name) {
        $output = $user->display_name;
    } elseif ('_post_author_email' == $name) {
        $output = $user->user_email;
    }
    return $output;
}
Example #4
Show file File: em-functions.php Project: adisonc/MaineLearning
0
/**
 * Notify the blog admin of a new user, normally via email.
 *
 * @since 2.0
 */
function em_new_user_notification()
{
    global $em_temp_user_data;
    $user_id = $em_temp_user_data['user_id'];
    $plaintext_pass = $em_temp_user_data['user_pass'];
    //if you want you can disable this email from going out, and will still consider registration as successful.
    if (get_option('dbem_email_disable_registration')) {
        return true;
    }
    //Copied out of /wp-includes/pluggable.php
    $user = new WP_User($user_id);
    $user_login = stripslashes($user->user_login);
    $user_email = stripslashes($user->user_email);
    // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    // we want to reverse this for the plain text arena of emails.
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $message = sprintf(__('New user registration on your blog %s:', 'dbem'), $blogname) . "\r\n\r\n";
    $message .= sprintf(__('Username: %s', 'dbem'), $user_login) . "\r\n\r\n";
    $message .= sprintf(__('E-mail: %s', 'dbem'), $user_email) . "\r\n";
    @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration', 'dbem'), $blogname), $message);
    if (empty($plaintext_pass)) {
        return;
    }
    //
    ob_start();
    em_locate_template('emails/new-user.php', true);
    $message = ob_get_clean();
    $message = str_replace(array('%password%', '%username%'), array($plaintext_pass, $user_login), $message);
    global $EM_Mailer;
    return $EM_Mailer->send(sprintf(__('[%s] Your username and password', 'dbem'), $blogname), $message, $user_email);
}
Example #5
Show file File: author.php Project: atimmer/wordpress-develop-mirror
0
 function test_get_the_author()
 {
     $author_name = get_the_author();
     $user = new WP_User($this->author_id);
     $this->assertEquals($user->display_name, $author_name);
     $this->assertEquals('test_author', $author_name);
 }
Example #6
Show file File: sem-author-image.php Project: markbaindesign/mbd-wp-theme
0
 /**
  * get_meta()
  *
  * @param int $author_id
  * @return string $image
  **/
 static function get_meta($author_id)
 {
     $user = get_userdata($author_id);
     $author_login = $user->user_login;
     //		if ( empty( $user->user_login ) )
     //			return false;
     if (defined('GLOB_BRACE')) {
         if ($author_image = glob(WP_CONTENT_DIR . '/authors/' . $author_login . '{,-*}.{jpg,jpeg,png}', GLOB_BRACE)) {
             $author_image = current($author_image);
         } else {
             $author_image = false;
         }
     } else {
         if ($author_image = glob(WP_CONTENT_DIR . '/authors/' . $author_login . '-*.jpg')) {
             $author_image = current($author_image);
         } else {
             $author_image = false;
         }
     }
     if ($author_image) {
         $author_image = basename($author_image);
         if (!get_transient('author_image_cache')) {
             $user = new WP_User($author_id);
             if ($user->has_cap('publish_posts') || $user->has_cap('publish_pages')) {
                 set_transient('author_image_cache', $author_id);
             }
         }
     } else {
         $author_image = '';
     }
     update_user_meta($author_id, 'author_image', $author_image);
     return $author_image;
 }
Example #7
Show file File: manager.php Project: akshayxhtmljunkies/brownglock
0
 /**
  * Generates an array with the user capability names.
  * If user has 'administrator' role, system roles are generated.
  * The key is the capability and the value the created screen name.
  * A user cannot manage more capabilities that has himself (Except for administrators).
  *
  * @uses self::_capNamesCB()
  * @return void
  */
 function generateNames()
 {
     if (current_user_can('administrator') || is_multisite() && is_super_admin()) {
         $this->generateSysNames();
     } else {
         global $user_ID;
         $user = new WP_User($user_ID);
         $this->max_level = ak_caps2level($user->allcaps);
         $keys = array_keys($user->allcaps);
         $names = array_map(array($this, '_capNamesCB'), $keys);
         $this->capabilities = $keys ? array_combine($keys, $names) : array();
         $roles = ak_get_roles(true);
         unset($roles['administrator']);
         if (defined('CME_LEGACY_USER_EDIT_FILTER') && CME_LEGACY_USER_EDIT_FILTER || !empty($_REQUEST['page']) && 'capsman' == $_REQUEST['page']) {
             foreach ($user->roles as $role) {
                 // Unset the roles from capability list.
                 unset($this->capabilities[$role]);
                 unset($roles[$role]);
                 // User cannot manage his roles.
             }
         }
         asort($this->capabilities);
         foreach (array_keys($roles) as $role) {
             $r = get_role($role);
             $level = ak_caps2level($r->capabilities);
             if ($level > $this->max_level) {
                 unset($roles[$role]);
             }
         }
         $this->roles = $roles;
     }
 }
Example #8
Show file File: actions.php Project: OneTimeUser/retailwire
0
 /**
  * @see CPAC_Column_Actions::get_actions()
  * @since 2.4.7
  */
 public function get_actions($id)
 {
     $actions = array();
     $user_object = new WP_User($id);
     $screen = get_current_screen();
     if ('site-users-network' == $screen->id) {
         $url = "site-users.php?id={$this->site_id}&";
     } else {
         $url = 'users.php?';
     }
     if (get_current_user_id() == $user_object->ID) {
         $edit_link = 'profile.php';
     } else {
         $edit_link = esc_url(add_query_arg('wp_http_referer', urlencode(stripslashes($_SERVER['REQUEST_URI'])), "user-edit.php?user_id={$user_object->ID}"));
     }
     if (current_user_can('edit_user', $user_object->ID)) {
         $edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a></strong><br />";
         $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
     } else {
         $edit = "<strong>{$user_object->user_login}</strong><br />";
     }
     if (!is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('delete_user', $user_object->ID)) {
         $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user={$user_object->ID}", 'bulk-users') . "'>" . __('Delete') . "</a>";
     }
     if (is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('remove_user', $user_object->ID)) {
         $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url($url . "action=remove&amp;user={$user_object->ID}", 'bulk-users') . "'>" . __('Remove') . "</a>";
     }
     return $actions;
 }
Example #9
Show file File: class-user-integration.php Project: olechka1505/hungrylemur
0
 /**
  * @param WP_User $user
  *
  * @return array
  */
 protected function user_merge_vars(WP_User $user)
 {
     // start with user_login as name, since that's always known
     $merge_vars = array('NAME' => $user->user_login);
     if ('' !== $user->first_name) {
         $merge_vars['NAME'] = $user->first_name;
         $merge_vars['FNAME'] = $user->first_name;
     }
     if ('' !== $user->last_name) {
         $merge_vars['LNAME'] = $user->last_name;
     }
     if ('' !== $user->first_name && '' !== $user->last_name) {
         $merge_vars['NAME'] = sprintf('%s %s', $user->first_name, $user->last_name);
     }
     /**
      * @filter `mc4wp_user_merge_vars`
      * @expects array
      * @param array $merge_vars
      * @param WP_User $user
      *
      * Use this to filter the merge vars of a user
      */
     $merge_vars = (array) apply_filters('mc4wp_user_merge_vars', $merge_vars, $user);
     return $merge_vars;
 }
Example #10
Show file File: class-vendors.php Project: SelaInc/eassignment
0
 public function vendor_not_a_vendor_redirect($user_id = -2)
 {
     // lets try the grab user_id trick
     if ($user_id == -2) {
         $user_id = get_current_user_id();
     }
     if ($user_id == 0) {
         // This is a logged out user, since get_current_user_id returns 0 for non logged in
         // So let's log them in, and then attempt redirect to ref
         $base_url = get_permalink(EDD_FES()->helper->get_option('fes-vendor-dashboard-page', false));
         $base_url = add_query_arg('view', 'login-register', $base_url);
         wp_redirect($base_url);
         exit;
     } else {
         $user = new WP_User($user_id);
         if (current_user_can('pending_vendor')) {
             // are they a pending vendor: display not approved display
             $base_url = get_permalink(EDD_FES()->helper->get_option('fes-vendor-dashboard-page', false));
             $base_url = add_query_arg('user_id', $user_id, $base_url);
             $base_url = add_query_arg('view', 'pending', $base_url);
             wp_redirect($base_url);
             exit;
         } else {
             // are they not a vendor yet: show registration page
             $base_url = get_permalink(EDD_FES()->helper->get_option('fes-vendor-dashboard-page', false));
             $base_url = add_query_arg('user_id', $user_id, $base_url);
             $base_url = add_query_arg('view', 'application', $base_url);
             wp_redirect($base_url);
             exit;
         }
     }
 }
Example #11
Show file File: ms.php Project: atimmer/wordpress-develop-mirror
0
/**
 * Update the status of a user in the database.
 *
 * Used in core to mark a user as spam or "ham" (not spam) in Multisite.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int    $id         The user ID.
 * @param string $pref       The column in the wp_users table to update the user's status
 *                           in (presumably user_status, spam, or deleted).
 * @param int    $value      The new status for the user.
 * @param null   $deprecated Deprecated as of 3.0.2 and should not be used.
 * @return int   The initially passed $value.
 */
function update_user_status($id, $pref, $value, $deprecated = null)
{
    global $wpdb;
    if (null !== $deprecated) {
        _deprecated_argument(__FUNCTION__, '3.0.2');
    }
    $wpdb->update($wpdb->users, array(sanitize_key($pref) => $value), array('ID' => $id));
    $user = new WP_User($id);
    clean_user_cache($user);
    if ($pref == 'spam') {
        if ($value == 1) {
            /**
             * Fires after the user is marked as a SPAM user.
             *
             * @since 3.0.0
             *
             * @param int $id ID of the user marked as SPAM.
             */
            do_action('make_spam_user', $id);
        } else {
            /**
             * Fires after the user is marked as a HAM user. Opposite of SPAM.
             *
             * @since 3.0.0
             *
             * @param int $id ID of the user marked as HAM.
             */
            do_action('make_ham_user', $id);
        }
    }
    return $value;
}
Example #12
Show file File: um-admin-actions.php Project: Makenrro/repos
0
function um_admin_do_action__mass_role_sync($action)
{
    global $ultimatemember;
    if (!is_admin() || !current_user_can('edit_user')) {
        die;
    }
    if (!isset($_REQUEST['post']) || !is_numeric($_REQUEST['post'])) {
        die;
    }
    $post_id = (int) $_REQUEST['post'];
    $post = get_post($post_id);
    $slug = $post->post_name;
    if ($slug != $_REQUEST['um_role']) {
        die;
    }
    if (get_post_meta($post_id, '_um_synced_role', true) != $_REQUEST['wp_role']) {
        die;
    }
    if ($slug == 'admin') {
        $_REQUEST['wp_role'] = 'administrator';
        update_post_meta($post_id, '_um_synced_role', 'administrator');
    }
    $wp_role = $_REQUEST['wp_role'] ? $_REQUEST['wp_role'] : 'subscriber';
    $users = get_users(array('fields' => array('ID'), 'meta_key' => 'role', 'meta_value' => $slug));
    foreach ($users as $user_id) {
        $wp_user_object = new WP_User($user_id);
        $wp_user_object->set_role($wp_role);
    }
    exit(wp_redirect(admin_url('post.php?post=' . $post_id) . '&action=edit&message=1'));
}
Example #13
Show file File: wpDeleteUser.php Project: atimmer/wordpress-develop-mirror
0
 function test_delete_user()
 {
     $user_id = self::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 #14
Show file File: functions-old.php Project: vjdesign/fontaine
0
function remove_the_dashboard()
{
    if (current_user_can('manage_options')) {
        return;
    } else {
        global $menu, $submenu, $user_ID;
        $the_user = new WP_User($user_ID);
        reset($menu);
        $page = key($menu);
        while (__('Dashboard') != $menu[$page][0] && next($menu)) {
            $page = key($menu);
        }
        if (__('Dashboard') == $menu[$page][0]) {
            unset($menu[$page]);
        }
        reset($menu);
        $page = key($menu);
        while (!$the_user->has_cap($menu[$page][1]) && next($menu)) {
            $page = key($menu);
        }
        if (preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) && 'index.php' != $menu[$page][2]) {
            wp_redirect(get_option('siteurl') . '/wp-admin/admin.php?page=options%2Fshipcalc.php');
        }
    }
}
Example #15
Show file File: main.php Project: macconsultinggroup/WordPress
0
function espresso_edit_this($event_id)
{
    global $espresso_premium;
    if ($espresso_premium != true) {
        return;
    }
    global $current_user;
    wp_get_current_user();
    $curauth = wp_get_current_user();
    $user_id = $curauth->ID;
    $user = new WP_User($user_id);
    foreach ($user->roles as $role) {
        //echo $role;
        //Build the edit event link
        $edit_link = '<a class="post-edit-link" href="' . site_url() . '/wp-admin/admin.php?page=events&action=edit&event_id=' . $event_id . '">' . __('Edit Event') . '</a>';
        switch ($role) {
            case 'administrator':
            case 'espresso_event_admin':
            case 'espresso_event_manager':
            case 'espresso_group_admin':
                //If user is an event manager, then show the edit link for their events
                if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_eventmanager' && espresso_member_data('id') != espresso_is_my_event($event_id)) {
                    return;
                }
                return $edit_link;
                break;
        }
    }
}
Example #16
Show file File: class-wc-api-customers.php Project: donpapa26/bakancslistad
0
 /**
  * Validate the request by checking:
  *
  * 1) the ID is a valid integer
  * 2) the ID returns a valid WP_User
  * 3) the current user has the proper permissions
  *
  * @since 2.1
  * @see WC_API_Resource::validate_request()
  * @param integer $id the customer ID
  * @param string $type the request type, unused because this method overrides the parent class
  * @param string $context the context of the request, either `read`, `edit` or `delete`
  * @return int|WP_Error valid user ID or WP_Error if any of the checks fails
  */
 protected function validate_request($id, $type, $context)
 {
     $id = absint($id);
     // validate ID
     if (empty($id)) {
         return new WP_Error('woocommerce_api_invalid_customer_id', __('Invalid customer ID', 'woocommerce'), array('status' => 404));
     }
     // non-existent IDs return a valid WP_User object with the user ID = 0
     $customer = new WP_User($id);
     if (0 === $customer->ID) {
         return new WP_Error('woocommerce_api_invalid_customer', __('Invalid customer', 'woocommerce'), array('status' => 404));
     }
     // validate permissions
     switch ($context) {
         case 'read':
             if (!current_user_can('list_users')) {
                 return new WP_Error('woocommerce_api_user_cannot_read_customer', __('You do not have permission to read this customer', 'woocommerce'), array('status' => 401));
             }
             break;
         case 'edit':
             if (!current_user_can('edit_users')) {
                 return new WP_Error('woocommerce_api_user_cannot_edit_customer', __('You do not have permission to edit this customer', 'woocommerce'), array('status' => 401));
             }
             break;
         case 'delete':
             if (!current_user_can('delete_users')) {
                 return new WP_Error('woocommerce_api_user_cannot_delete_customer', __('You do not have permission to delete this customer', 'woocommerce'), array('status' => 401));
             }
             break;
     }
     return $id;
 }
Example #17
Show file File: sp-api-common-display.php Project: brooklyntri/btc-plugins
0
function sp_build_profile_formlink($userid)
{
    global $spThisUser;
    $sfprofile = sp_get_option('sfprofile');
    switch ($sfprofile['formmode']) {
        case 1:
            # SPF form
            $edit = '';
            if ($userid != $spThisUser->ID) {
                $user = new WP_User($userid);
                $edit = $user->ID . '/edit';
            }
            $site = sp_url('profile/' . $edit);
            return $site;
        case 2:
            # WordPress form
            return SFHOMEURL . 'wp-admin/user-edit.php?user_id=' . $userid;
        case 3:
            # BuddyPress profile page
            $user = new WP_User($userid);
            # try to handle BP switches between username and login ussge
            $username = bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename;
            if (strstr($username, ' ')) {
                $username = $user->user_nicename;
            } else {
                $username = urlencode($username);
            }
            $site = SFSITEURL . 'members/' . str_replace(' ', '', $username) . '/profile/edit/';
            $site = apply_filters('sph_buddypress_profile', $site, $user);
            return $site;
        case 4:
            # Handoff to user specified form
            if ($sfprofile['formpage']) {
                $out = $sfprofile['formpage'];
                if ($sfprofile['formquery']) {
                    $out .= '?' . sp_filter_title_display($sfprofile['formquery']) . '=' . $userid;
                }
            } else {
                $out = '';
            }
            return $out;
        case 5:
            # Mingle account page
            $user = new WP_User($userid);
            $site = SFSITEURL . user_trailingslashit('account');
            $site = apply_filters('sph_mingle_profile', $site, $user);
            return $site;
    }
}
Example #18
Show file File: duo_wordpress.php Project: ChelseaStats/duo_wordpress
0
function duo_authenticate_user($user = "", $username = "", $password = "")
{
    // play nicely with other plugins if they have higher priority than us
    if (is_a($user, 'WP_User')) {
        return $user;
    }
    if (!duo_auth_enabled()) {
        duo_debug_log('Duo not enabled, skipping 2FA.');
        return;
    }
    if (isset($_POST['sig_response'])) {
        // secondary auth
        remove_action('authenticate', 'wp_authenticate_username_password', 20);
        $akey = duo_get_akey();
        $duo_time = duo_get_time();
        $username = Duo::verifyResponse(duo_get_option('duo_ikey'), duo_get_option('duo_skey'), $akey, $_POST['sig_response'], $duo_time);
        if ($username) {
            // Don't use get_user_by(). It doesn't return a WP_User object if wordpress version < 3.3
            $user = new WP_User(0, $username);
            duo_set_cookie($user);
            duo_debug_log("Second factor successful for user: {$username}");
            return $user;
        } else {
            $user = new WP_Error('Duo authentication_failed', __('<strong>ERROR</strong>: Failed or expired two factor authentication'));
            return $user;
        }
    }
    if (strlen($username) > 0) {
        // primary auth
        // Don't use get_user_by(). It doesn't return a WP_User object if wordpress version < 3.3
        $user = new WP_User(0, $username);
        if (!$user) {
            error_log("Failed to retrieve WP user {$username}");
            return;
        }
        if (!duo_role_require_mfa($user)) {
            duo_debug_log("Skipping 2FA for user: {$username} with roles: " . print_r($user->roles, true));
            return;
        }
        remove_action('authenticate', 'wp_authenticate_username_password', 20);
        $user = wp_authenticate_username_password(NULL, $username, $password);
        if (!is_a($user, 'WP_User')) {
            // on error, return said error (and skip the remaining plugin chain)
            return $user;
        } else {
            duo_debug_log("Primary auth succeeded, starting second factor for {$username}");
            duo_start_second_factor($user);
        }
    }
    duo_debug_log('Starting primary authentication');
}
Example #19
Show file File: capabilities.php Project: nkeat12/dv
0
 function test_multisite_administrator_with_manage_network_users_can_not_edit_super_admin()
 {
     if (!is_multisite()) {
         $this->markTestSkipped('Test only runs in multisite');
         return;
     }
     $user = new WP_User(self::factory()->user->create(array('role' => 'administrator')));
     $user->add_cap('manage_network_users');
     $super_admin = new WP_User(self::factory()->user->create(array('role' => 'subscriber')));
     grant_super_admin($super_admin->ID);
     wp_set_current_user($user->ID);
     $this->assertFalse(current_user_can('edit_user', $super_admin->ID));
 }
Example #20
Show file File: login.php Project: Steadroy/leeds-talent-pool
0
 /**
  * authentication of WPP users via the WPP external user validation web service
  */
 public static function authenticate_WPP_user($user, $username, $password)
 {
     // Make sure a username and password are present for us to work with
     if ($username == '' || $password == '') {
         return;
     }
     // Get options for WPP authentication
     $options = ltp_options::get_options();
     $authuser = $options["wpp_user"];
     $authpass = $options["wpp_pass"];
     $url = $options["wpp_url"];
     //$url = "https://inside.wpp.com/WebService/Secured/ExternalUserValidation.asmx/ValidateUser";
     if (!empty($authuser) && !empty($authpass) && !empty($url)) {
         // validate against WPP user validation service
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_FAILONERROR, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 3);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, "username={$username}&password={$password}");
         curl_setopt($ch, CURLOPT_USERPWD, "{$authuser}:{$authpass}");
         $resultxml = curl_exec($ch);
         if ($resultxml !== false) {
             $result = simplexml_load_string($resultxml);
             if ($result !== false) {
                 // valid result - check status code
                 if ($result->Status->Code == 0) {
                     // successful login
                     $email = $result->EmailAddress;
                     $first_name = $result->FirstName;
                     $last_name = $result->LastName;
                     $display_name = $result->FirstName . ' ' . $result->LastName;
                     $company = $result->Company;
                     // try to load Wordpress user
                     $userobj = new WP_User();
                     $user = $userobj->get_data_by('email', $email);
                     // if user doesn't exist, create one
                     if ($user->ID == 0) {
                         // set up user data
                         $userdata = array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'role' => 'wppuser', 'description' => $company);
                         $new_user_id = wp_insert_user($userdata);
                         $user = new WP_User($user->ID);
                         // Attempt to load up the user with that ID
                         return $user;
                     }
                 }
             }
         }
     }
 }
Example #21
Show file File: wpml-tm-mail-notification.class.php Project: nayabbukhari/circulocristiano
0
 /**
  * @param int                      $translator_id
  * @param int|WPML_Translation_Job $job_id
  *
  * @return array|bool
  */
 public function translator_resign_mail($translator_id, $job_id)
 {
     /** @var WPML_Translation_Job $job */
     list($manager_id, $job) = $this->get_mail_elements($job_id);
     if ($manager_id == $translator_id) {
         return false;
     }
     $translator = new WP_User($translator_id);
     $manager = new WP_User($manager_id);
     $tj_url = admin_url('admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=jobs');
     $doc_title = $job->get_title();
     $user_language = $this->sitepress->get_user_admin_language($manager->ID);
     $this->sitepress->switch_locale($user_language);
     list($lang_from, $lang_to) = $this->get_lang_to_from($job, $user_language);
     $mail = array();
     if ($this->notification_settings['resigned'] == ICL_TM_NOTIFICATION_IMMEDIATELY) {
         $mail['to'] = $manager->display_name . ' <' . $manager->user_email . '>';
         $mail['subject'] = sprintf(__('Translator has resigned from job on %s', 'sitepress'), get_bloginfo('name'));
         $original_doc_title = $doc_title ? $doc_title : __("Deleted", "sitepress");
         $mail['body'] = sprintf(__('Translator %s has resigned from the translation job "%s" for %s to %s.%sView translation jobs: %s', 'sitepress'), $translator->display_name, $original_doc_title, $lang_from, $lang_to, "\n", $tj_url);
         $mail['type'] = 'admin';
         $this->enqueue_mail($mail);
     }
     //restore locale
     $this->sitepress->switch_locale();
     return $mail;
 }
Example #22
Show file File: class-wpfront-user-role-editor-user-permissions-pro.php Project: JulieKuehl/auburn-agency
0
 private function has_permission($user_id, $edit_user_id, $cap)
 {
     $user = new WP_User($user_id);
     if (empty($user) || is_wp_error($user)) {
         return FALSE;
     }
     if (!$user->exists()) {
         return FALSE;
     }
     if ($user->has_cap($cap)) {
         return TRUE;
     }
     $edit_user = new WP_User($edit_user_id);
     if (empty($edit_user) || is_wp_error($edit_user)) {
         return FALSE;
     }
     if (!$edit_user->exists()) {
         return FALSE;
     }
     for ($i = 10; $i > -1; $i--) {
         $user_cap = $user->has_cap('level_' . $i);
         $edit_user_cap = $edit_user->has_cap('level_' . $i);
         if ($user_cap) {
             return TRUE;
         }
         if ($edit_user_cap) {
             return FALSE;
         }
     }
     return TRUE;
 }
Example #23
Show file File: ofsocial.php Project: igniterealtime/community-plugins
0
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;
}