is_user_logged_in example

if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) {
                    $term_class = $term->term_id;
                }

                $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
                $classes[] = 'term-' . $term_class;
                $classes[] = 'term-' . $term->term_id;
            }
        }
    }

    if ( is_user_logged_in() ) {
        $classes[] = 'logged-in';
    }

    if ( is_admin_bar_showing() ) {
        $classes[] = 'admin-bar';
        $classes[] = 'no-customize-support';
    }

    if ( current_theme_supports( 'custom-background' )
        && ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) ) {
        $classes[] = 'custom-background';
    }
return strtr( $code$lang_codes );
}

/** * Displays an access denied message when a user tries to view a site's dashboard they * do not have access to. * * @since 3.2.0 * @access private */
function _access_denied_splash() {
    if ( ! is_user_logged_in() || is_network_admin() ) {
        return;
    }

    $blogs = get_blogs_of_user( get_current_user_id() );

    if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) {
        return;
    }

    $blog_name = get_bloginfo( 'name' );

    


    /** * Checks if a given request has access to create a comment. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to create items, error object otherwise. */
    public function create_item_permissions_check( $request ) {
        if ( ! is_user_logged_in() ) {
            if ( get_option( 'comment_registration' ) ) {
                return new WP_Error(
                    'rest_comment_login_required',
                    __( 'Sorry, you must be logged in to comment.' ),
                    array( 'status' => 401 )
                );
            }

            /** * Filters whether comments can be created via the REST API without authentication. * * Enables creating comments for anonymous users. * * @since 4.7.0 * * @param bool $allow_anonymous Whether to allow anonymous comments to * be created. Default `false`. * @param WP_REST_Request $request Request used to generate the * response. */
    if ( true === $is_flood ) {
        return $is_flood;
    }

    // Don't throttle admins or moderators.     if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) {
        return false;
    }

    $hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS );

    if ( is_user_logged_in() ) {
        $user         = get_current_user_id();
        $check_column = '`user_id`';
    } else {
        $user         = $ip;
        $check_column = '`comment_author_IP`';
    }

    $sql = $wpdb->prepare(
        "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1",
        $hour_ago,
        $user,
        

        $this->send_header( 'X-Content-Type-Options', 'nosniff' );

        /** * Filters whether to send nocache headers on a REST API request. * * @since 4.4.0 * * @param bool $rest_send_nocache_headers Whether to send no-cache headers. */
        $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
        if ( $send_no_cache_headers ) {
            foreach ( wp_get_nocache_headers() as $header => $header_value ) {
                if ( empty( $header_value ) ) {
                    $this->remove_header( $header );
                } else {
                    $this->send_header( $header$header_value );
                }
            }
        }

        /** * Filters whether the REST API is enabled. * * @since 4.4.0 * @deprecated 4.7.0 Use the {@see 'rest_authentication_errors'} filter to * restrict access to the REST API. * * @param bool $rest_enabled Whether the REST API is enabled. Default true. */

    public function send_headers() {
        global $wp_query;

        $headers       = array();
        $status        = null;
        $exit_required = false;
        $date_format   = 'D, d M Y H:i:s';

        if ( is_user_logged_in() ) {
            $headers = array_merge( $headerswp_get_nocache_headers() );
        } elseif ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
            // Unmoderated comments are only visible for 10 minutes via the moderation hash.             $expires = 10 * MINUTE_IN_SECONDS;

            $headers['Expires']       = gmdate( $date_formattime() + $expires );
            $headers['Cache-Control'] = sprintf(
                'max-age=%d, must-revalidate',
                $expires
            );
        }
        


        $error = new WP_Error(
            'rest_user_invalid_id',
            __( 'Invalid user ID.' ),
            array( 'status' => 404 )
        );

        $id = $request['user_id'];

        if ( 'me' === $id ) {
            if ( ! is_user_logged_in() ) {
                return new WP_Error(
                    'rest_not_logged_in',
                    __( 'You are not currently logged in.' ),
                    array( 'status' => 401 )
                );
            }

            $user = wp_get_current_user();
        } else {
            $id = (int) $id;

            
// If the template hierarchy algorithm has successfully located a PHP template file,         // we will only consider block templates with higher or equal specificity.         $templates = array_slice( $templates, 0, $index + 1 );
    }

    $block_template = resolve_block_template( $type$templates$template );

    if ( $block_template ) {
        $_wp_current_template_id = $block_template->id;

        if ( empty( $block_template->content ) && is_user_logged_in() ) {
            $_wp_current_template_content =
            sprintf(
                /* translators: %s: Template title */
                __( 'Empty template: %s' ),
                $block_template->title
            );
        } elseif ( ! empty( $block_template->content ) ) {
            $_wp_current_template_content = $block_template->content;
        }
        if ( isset( $_GET['_wp-find-template'] ) ) {
            wp_send_json_success( $block_template );
        }

function build_comment_query_vars_from_block( $block ) {

    $comment_args = array(
        'orderby'       => 'comment_date_gmt',
        'order'         => 'ASC',
        'status'        => 'approve',
        'no_found_rows' => false,
    );

    if ( is_user_logged_in() ) {
        $comment_args['include_unapproved'] = array( get_current_user_id() );
    } else {
        $unapproved_email = wp_get_unapproved_comment_author_email();

        if ( $unapproved_email ) {
            $comment_args['include_unapproved'] = array( $unapproved_email );
        }
    }

    if ( ! empty( $block->context['postId'] ) ) {
        $comment_args['post_id'] = (int) $block->context['postId'];
    }

function wp_loginout( $redirect = '', $display = true ) {
    if ( ! is_user_logged_in() ) {
        $link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
    } else {
        $link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
    }

    if ( $display ) {
        /** * Filters the HTML output for the Log In/Log Out link. * * @since 1.5.0 * * @param string $link The HTML link content. */
'status'        => 'approve',
        'post_id'       => $post->ID,
        'no_found_rows' => false,
    );

    if ( get_option( 'thread_comments' ) ) {
        $comment_args['hierarchical'] = 'threaded';
    } else {
        $comment_args['hierarchical'] = false;
    }

    if ( is_user_logged_in() ) {
        $comment_args['include_unapproved'] = array( get_current_user_id() );
    } else {
        $unapproved_email = wp_get_unapproved_comment_author_email();

        if ( $unapproved_email ) {
            $comment_args['include_unapproved'] = array( $unapproved_email );
        }
    }

    $per_page = 0;
    if ( get_option( 'page_comments' ) ) {
        

function _count_posts_cache_key( $type = 'post', $perm = '' ) {
    $cache_key = 'posts-' . $type;

    if ( 'readable' === $perm && is_user_logged_in() ) {
        $post_type_object = get_post_type_object( $type );

        if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
            $cache_key .= '_' . $perm . '_' . get_current_user_id();
        }
    }

    return $cache_key;
}

/** * Counts number of posts of a post type and if user has permissions to view. * * This function provides an efficient method of finding the amount of post's * type a blog has. Another method is to count the amount of items in * get_posts(), but that method has a lot of overhead with doing so. Therefore, * when developing for 2.5+, use this function instead. * * The $perm parameter checks for 'readable' value and if the user can read * private posts, it will display that for the user that is signed in. * * @since 2.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $type Optional. Post type to retrieve count. Default 'post'. * @param string $perm Optional. 'readable' or empty. Default empty. * @return stdClass An object containing the number of posts for each status, * or an empty object if the post type does not exist. */
/** This action is documented in wp-admin/admin.php */
do_action( 'admin_init' );

$action = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';

// Reject invalid parameters. if ( ! is_scalar( $action ) ) {
    wp_die( '', 400 );
}

if ( ! is_user_logged_in() ) {
    if ( empty( $action ) ) {
        /** * Fires on a non-authenticated admin post request where no action is supplied. * * @since 2.6.0 */
        do_action( 'admin_post_nopriv' );
    } else {
        // If no action is registered, return a Bad Request response.         if ( ! has_action( "admin_post_nopriv_{$action}) ) {
            wp_die( '', 400 );
        }

    public function wp_ajax_update_widget() {

        if ( ! is_user_logged_in() ) {
            wp_die( 0 );
        }

        check_ajax_referer( 'update-widget', 'nonce' );

        if ( ! current_user_can( 'edit_theme_options' ) ) {
            wp_die( -1 );
        }

        if ( empty( $_POST['widget-id'] ) ) {
            wp_send_json_error( 'missing_widget-id' );
        }

function render_block_core_loginout( $attributes ) {

    // Build the redirect URL.     $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

    $classes  = is_user_logged_in() ? 'logged-in' : 'logged-out';
    $contents = wp_loginout(
        isset( $attributes['redirectToCurrent'] ) && $attributes['redirectToCurrent'] ? $current_url : '',
        false
    );

    // If logged-out and displayLoginAsForm is true, show the login form.     if ( ! is_user_logged_in() && ! empty( $attributes['displayLoginAsForm'] ) ) {
        // Add a class.         $classes .= ' has-login-form';

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