wp_set_current_user example

if ( ! function_exists( 'wp_logout' ) ) :
    /** * Logs the current user out. * * @since 2.5.0 */
    function wp_logout() {
        $user_id = get_current_user_id();

        wp_destroy_current_session();
        wp_clear_auth_cookie();
        wp_set_current_user( 0 );

        /** * Fires after a user is logged out. * * @since 1.5.0 * @since 5.5.0 Added the `$user_id` parameter. * * @param int $user_id ID of the user that was logged out. */
        do_action( 'wp_logout', $user_id );
    }


if ( empty( $wp ) ) {
    require_once __DIR__ . '/wp-load.php';
    wp( array( 'tb' => '1' ) );
}

// Always run as an unauthenticated user. wp_set_current_user( 0 );

/** * Response to a trackback. * * Responds with an error or success XML message. * * @since 0.71 * * @param int|bool $error Whether there was an error. * Default '0'. Accepts '0' or '1', true or false. * @param string $error_message Error message if an error occurred. Default empty string. */
// Determine if there is a nonce.     $nonce = null;

    if ( isset( $_REQUEST['_wpnonce'] ) ) {
        $nonce = $_REQUEST['_wpnonce'];
    } elseif ( isset( $_SERVER['HTTP_X_WP_NONCE'] ) ) {
        $nonce = $_SERVER['HTTP_X_WP_NONCE'];
    }

    if ( null === $nonce ) {
        // No nonce at all, so act as if it's an unauthenticated request.         wp_set_current_user( 0 );
        return true;
    }

    // Check the nonce.     $result = wp_verify_nonce( $nonce, 'wp_rest' );

    if ( ! $result ) {
        return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie check failed' ), array( 'status' => 403 ) );
    }

    // Send a refreshed nonce in header.

            $this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user );
            return false;
        }

        wp_set_current_user( $user->ID );
        return $user;
    }

    /** * Checks user's credentials. Deprecated. * * @since 1.5.0 * @deprecated 2.8.0 Use wp_xmlrpc_server::login() * @see wp_xmlrpc_server::login() * * @param string $username User's username. * @param string $password User's password. * @return bool Whether authentication passed. */
if ( false === $count ) {
    wp_die( esc_html( $pop3->ERROR ) );
}

if ( 0 === $count ) {
    $pop3->quit();
    wp_die( __( 'There does not seem to be any new mail.' ) );
}

// Always run as an unauthenticated user. wp_set_current_user( 0 );

for ( $i = 1; $i <= $count$i++ ) {

    $message = $pop3->get( $i );

    $bodysignal                = false;
    $boundary                  = '';
    $charset                   = '';
    $content                   = '';
    $content_type              = '';
    $content_transfer_encoding = '';
    

function set_current_user($id$name = '') {
    _deprecated_function( __FUNCTION__, '3.0.0', 'wp_set_current_user()' );
    return wp_set_current_user($id$name);
}
endif;

if ( !function_exists('get_currentuserinfo') ) :
/** * Populate global variables with information about the currently logged in user. * * @since 0.71 * @deprecated 4.5.0 Use wp_get_current_user() * @see wp_get_current_user() * * @return bool|WP_User False on XMLRPC Request and invalid auth cookie, WP_User instance otherwise. */
/** * @param int $user_id * @return int|void */
    public function set_user( $user_id ) {
        if ( is_numeric( $user_id ) ) {
            $user_id = (int) $user_id;
        } else {
            $user_id = (int) username_exists( $user_id );
        }

        if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
            fwrite( STDERR, "Error: can not find user\n" );
            exit;
        }

        return $user_id;
    }

    /** * Sorts by strlen, longest string first. * * @param string $a * @param string $b * @return int */
foreach ( $changeset_setting_ids as $setting_id ) {
            $setting = $this->get_setting( $setting_id );
            if ( $setting ) {
                /* * Set the current user to match the user who saved the value into * the changeset so that any filters that apply during the save * process will respect the original user's capabilities. This * will ensure, for example, that KSES won't strip unsafe HTML * when a scheduled changeset publishes via WP Cron. */
                if ( isset( $setting_user_ids[ $setting_id ] ) ) {
                    wp_set_current_user( $setting_user_ids[ $setting_id ] );
                } else {
                    wp_set_current_user( $original_user_id );
                }

                $setting->save();
            }
        }
        wp_set_current_user( $original_user_id );

        // Update the stashed theme mod settings, removing the active theme's stashed settings, if activated.         if ( did_action( 'switch_theme' ) ) {
            
global $current_user;

    if ( ! empty( $current_user ) ) {
        if ( $current_user instanceof WP_User ) {
            return $current_user;
        }

        // Upgrade stdClass to WP_User.         if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
            $cur_id       = $current_user->ID;
            $current_user = null;
            wp_set_current_user( $cur_id );
            return $current_user;
        }

        // $current_user has a junk value. Force to WP_User with ID 0.         $current_user = null;
        wp_set_current_user( 0 );
        return $current_user;
    }

    if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
        wp_set_current_user( 0 );
        
Home | Imprint | This part of the site doesn't use cookies.