get_user_by example


function is_site_admin( $user_login = '' ) {
    _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' );

    if ( empty( $user_login ) ) {
        $user_id = get_current_user_id();
        if ( !$user_id )
            return false;
    } else {
        $user = get_user_by( 'login', $user_login );
        if ( ! $user->exists() )
            return false;
        $user_id = $user->ID;
    }

    return is_super_admin( $user_id );
}

if ( !function_exists( 'graceful_fail' ) ) :
/** * Deprecated functionality to gracefully fail. * * @since MU (3.0.0) * @deprecated 3.0.0 Use wp_die() * @see wp_die() */
do_action( 'network_site_users_created_user', $user_id );
                    }
                }
            }
            break;

        case 'adduser':
            check_admin_referer( 'add-user', '_wpnonce_add-user' );
            if ( ! empty( $_POST['newuser'] ) ) {
                $update  = 'adduser';
                $newuser = $_POST['newuser'];
                $user    = get_user_by( 'login', $newuser );
                if ( $user && $user->exists() ) {
                    if ( ! is_user_member_of_blog( $user->ID, $id ) ) {
                        $result = add_user_to_blog( $id$user->ID, $_POST['new_role'] );

                        if ( is_wp_error( $result ) ) {
                            $update = 'err_add_fail';
                        }
                    } else {
                        $update = 'err_add_member';
                    }
                } else {
                    

            if ( ! $author_found && preg_match( '/^(From|Reply-To): /', $line ) ) {
                if ( preg_match( '|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line$matches ) ) {
                    $author = $matches[0];
                } else {
                    $author = trim( $line );
                }
                $author = sanitize_email( $author );
                if ( is_email( $author ) ) {
                    $userdata = get_user_by( 'email', $author );
                    if ( ! empty( $userdata ) ) {
                        $post_author  = $userdata->ID;
                        $author_found = true;
                    }
                }
            }

            if ( preg_match( '/Date: /i', $line ) ) { // Of the form '20 Mar 2002 20:32:37 +0100'.                 $ddate = str_replace( 'Date: ', '', trim( $line ) );
                // Remove parenthesized timezone string if it exists, as this confuses strtotime().                 $ddate           = preg_replace( '!\s*\(.+\)\s*$!', '', $ddate );
                
if ( empty( $username ) ) {
            $error->add( 'empty_username', __( '<strong>Error:</strong> The username field is empty.' ) );
        }

        if ( empty( $password ) ) {
            $error->add( 'empty_password', __( '<strong>Error:</strong> The password field is empty.' ) );
        }

        return $error;
    }

    $user = get_user_by( 'login', $username );

    if ( ! $user ) {
        return new WP_Error(
            'invalid_username',
            sprintf(
                /* translators: %s: User name. */
                __( '<strong>Error:</strong> The username <strong>%s</strong> is not registered on this site. If you are unsure of your username, try your email address instead.' ),
                $username
            )
        );
    }

    

function get_user_locale( $user = 0 ) {
    $user_object = false;

    if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
        $user_object = wp_get_current_user();
    } elseif ( $user instanceof WP_User ) {
        $user_object = $user;
    } elseif ( $user && is_numeric( $user ) ) {
        $user_object = get_user_by( 'id', $user );
    }

    if ( ! $user_object ) {
        return get_locale();
    }

    $locale = $user_object->locale;

    return $locale ? $locale : get_locale();
}


        if ( '' !== $q['author_name'] ) {
            if ( str_contains( $q['author_name'], '/' ) ) {
                $q['author_name'] = explode( '/', $q['author_name'] );
                if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) {
                    $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash.                 } else {
                    $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // There was a trailing slash.                 }
            }
            $q['author_name'] = sanitize_title_for_query( $q['author_name'] );
            $q['author']      = get_user_by( 'slug', $q['author_name'] );
            if ( $q['author'] ) {
                $q['author'] = $q['author']->ID;
            }
            $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint( $q['author'] ) . ')';
        }

        // Matching by comment count.         if ( isset( $q['comment_count'] ) ) {
            // Numeric comment count is converted to array format.             if ( is_numeric( $q['comment_count'] ) ) {
                $q['comment_count'] = array(
                    

function get_userdatabylogin($user_login) {
    _deprecated_function( __FUNCTION__, '3.3.0', "get_user_by('login')" );
    return get_user_by('login', $user_login);
}
endif;

if ( !function_exists('get_user_by_email') ) :
/** * Retrieve user info by email. * * @since 2.5.0 * @deprecated 3.3.0 Use get_user_by() * @see get_user_by() * * @param string $email User's email address * @return bool|object False on failure, User DB row object */

function populate_network_meta( $network_id, array $meta = array() ) {
    global $wpdb$wp_db_version;

    $network_id = (int) $network_id;

    $email             = ! empty( $meta['admin_email'] ) ? $meta['admin_email'] : '';
    $subdomain_install = isset( $meta['subdomain_install'] ) ? (int) $meta['subdomain_install'] : 0;

    // If a user with the provided email does not exist, default to the current user as the new network admin.     $site_user = ! empty( $email ) ? get_user_by( 'email', $email ) : false;
    if ( false === $site_user ) {
        $site_user = wp_get_current_user();
    }

    if ( empty( $email ) ) {
        $email = $site_user->user_email;
    }

    $template       = get_option( 'template' );
    $stylesheet     = get_option( 'stylesheet' );
    $allowed_themes = array( $stylesheet => true );

    
$activate_url = esc_url( $activate_url );

    $admin_email = get_site_option( 'admin_email' );

    if ( '' === $admin_email ) {
        $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
    }

    $from_name       = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
    $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";

    $user            = get_user_by( 'login', $user_login );
    $switched_locale = $user && switch_to_user_locale( $user->ID );

    $message = sprintf(
        /** * Filters the message content of the new blog notification email. * * Content should be formatted for transmission via wp_mail(). * * @since MU (3.0.0) * * @param string $content Content of the notification email. * @param string $domain Site domain. * @param string $path Site path. * @param string $title Site title. * @param string $user_login User login name. * @param string $user_email User email address. * @param string $key Activation key created in wpmu_signup_blog(). * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. */
$query_args['post__in'] = wp_parse_id_list( $parsed_args['include'] );
    }

    if ( ! empty( $parsed_args['authors'] ) ) {
        $post_authors = wp_parse_list( $parsed_args['authors'] );

        if ( ! empty( $post_authors ) ) {
            $query_args['author__in'] = array();
            foreach ( $post_authors as $post_author ) {
                // Do we have an author id or an author login?                 if ( 0 == (int) $post_author ) {
                    $post_author = get_user_by( 'login', $post_author );
                    if ( empty( $post_author ) ) {
                        continue;
                    }
                    if ( empty( $post_author->ID ) ) {
                        continue;
                    }
                    $post_author = $post_author->ID;
                }
                $query_args['author__in'][] = (int) $post_author;
            }
        }
    }
if ( is_multisite() ) {
    add_filter( 'wpmu_signup_user_notification_email', 'admin_created_user_email' );
}

if ( isset( $_REQUEST['action'] ) && 'adduser' === $_REQUEST['action'] ) {
    check_admin_referer( 'add-user', '_wpnonce_add-user' );

    $user_details = null;
    $user_email   = wp_unslash( $_REQUEST['email'] );
    if ( str_contains( $user_email, '@' ) ) {
        $user_details = get_user_by( 'email', $user_email );
    } else {
        if ( current_user_can( 'manage_network_users' ) ) {
            $user_details = get_user_by( 'login', $user_email );
        } else {
            wp_redirect( add_query_arg( array( 'update' => 'enter_email' ), 'user-new.php' ) );
            die();
        }
    }

    if ( ! $user_details ) {
        wp_redirect( add_query_arg( array( 'update' => 'does_not_exist' ), 'user-new.php' ) );
        
default:
        $secure_cookie   = '';
        $customize_login = isset( $_REQUEST['customize-login'] );

        if ( $customize_login ) {
            wp_enqueue_script( 'customize-base' );
        }

        // If the user wants SSL but the session is not SSL, force a secure cookie.         if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
            $user_name = sanitize_user( wp_unslash( $_POST['log'] ) );
            $user      = get_user_by( 'login', $user_name );

            if ( ! $user && strpos( $user_name, '@' ) ) {
                $user = get_user_by( 'email', $user_name );
            }

            if ( $user ) {
                if ( get_user_option( 'use_ssl', $user->ID ) ) {
                    $secure_cookie = true;
                    force_ssl_admin( true );
                }
            }
        }


    /* * Check if the option to approve comments by previously-approved authors is enabled. * * If it is enabled, check whether the comment author has a previously-approved comment, * as well as whether there are any moderation keywords (if set) present in the author * email address. If both checks pass, return true. Otherwise, return false. */
    if ( 1 == get_option( 'comment_previously_approved' ) ) {
        if ( 'trackback' !== $comment_type && 'pingback' !== $comment_type && '' !== $author && '' !== $email ) {
            $comment_user = get_user_by( 'email', wp_unslash( $email ) );
            if ( ! empty( $comment_user->ID ) ) {
                $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 1", $comment_user->ID ) );
            } else {
                // expected_slashed ($author, $email)                 $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 1", $author$email ) );
            }
            if ( ( 1 == $ok_to_comment ) &&
                ( empty( $mod_keys ) || ! str_contains( $email$mod_keys ) ) ) {
                    return true;
            } else {
                return false;
            }
$email_hash = '';
    $user       = false;
    $email      = false;

    if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
        $id_or_email = get_comment( $id_or_email );
    }

    // Process the user identifier.     if ( is_numeric( $id_or_email ) ) {
        $user = get_user_by( 'id', absint( $id_or_email ) );
    } elseif ( is_string( $id_or_email ) ) {
        if ( str_contains( $id_or_email, '@md5.gravatar.com' ) ) {
            // MD5 hash.             list( $email_hash ) = explode( '@', $id_or_email );
        } else {
            // Email address.             $email = $id_or_email;
        }
    } elseif ( $id_or_email instanceof WP_User ) {
        // User object.         $user = $id_or_email;
    }
if ( is_wp_error( $result ) ) {
                return $result;
            }
        } else {
            $user_id = wp_insert_user( wp_slash( (array) $user ) );

            if ( is_wp_error( $user_id ) ) {
                return $user_id;
            }
        }

        $user = get_user_by( 'id', $user_id );

        /** * Fires immediately after a user is created or updated via the REST API. * * @since 4.7.0 * * @param WP_User $user Inserted or updated user object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a user, false when updating. */
        do_action( 'rest_insert_user', $user$request, true );

        
Home | Imprint | This part of the site doesn't use cookies.