post_password_required example



/* * If the current post is protected by a password and * the visitor has not yet entered the password, * return early without loading the comments. */
if ( post_password_required() ) {
    return;
}

$twenty_twenty_one_comment_count = get_comments_number();
?> <div id="comments" class="comments-area default-max-width <?php echo get_option( 'show_avatars' ) ? 'show-avatars' : ''; ?>"> <?php     if ( have_comments() ) :
        ?>
if ( ! empty( $prepared_post->ID ) && is_sticky( $prepared_post->ID ) ) {
                    return new WP_Error(
                        'rest_invalid_field',
                        __( 'A sticky post can not be password protected.' ),
                        array( 'status' => 400 )
                    );
                }
            }
        }

        if ( ! empty( $schema['properties']['sticky'] ) && ! empty( $request['sticky'] ) ) {
            if ( ! empty( $prepared_post->ID ) && post_password_required( $prepared_post->ID ) ) {
                return new WP_Error(
                    'rest_invalid_field',
                    __( 'A password protected post can not be set to sticky.' ),
                    array( 'status' => 400 )
                );
            }
        }

        // Parent.         if ( ! empty( $schema['properties']['parent'] ) && isset( $request['parent'] ) ) {
            if ( 0 === (int) $request['parent'] ) {
                

function rss_enclosure() {
    if ( post_password_required() ) {
        return;
    }

    foreach ( (array) get_post_custom() as $key => $val ) {
        if ( 'enclosure' === $key ) {
            foreach ( (array) $val as $enc ) {
                $enclosure = explode( "\n", $enc );

                // Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'.                 $t    = preg_split( '/[ \t]/', trim( $enclosure[2] ) );
                $type = $t[0];

                

function get_comment_excerpt( $comment_id = 0 ) {
    $comment = get_comment( $comment_id );

    if ( ! post_password_required( $comment->comment_post_ID ) ) {
        $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
    } else {
        $comment_text = __( 'Password protected' );
    }

    /* translators: Maximum number of words used in a comment excerpt. */
    $comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );

    /** * Filters the maximum number of words used in the comment excerpt. * * @since 4.4.0 * * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. */
if ( ! get_post( $post_id ) ) {
            return new IXR_Error( 404, __( 'Invalid post ID.' ) );
        }

        if ( ! comments_open( $post_id ) ) {
            return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) );
        }

        if (
            'publish' === get_post_status( $post_id ) &&
            ! current_user_can( 'edit_post', $post_id ) &&
            post_password_required( $post_id )
        ) {
            return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
        }

        if (
            'private' === get_post_status( $post_id ) &&
            ! current_user_can( 'read_post', $post_id )
        ) {
            return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
        }

        

        do_action( 'comment_on_draft', $comment_post_id );

        if ( current_user_can( 'read_post', $comment_post_id ) ) {
            return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 );
        } else {
            return new WP_Error( 'comment_on_draft' );
        }
    } elseif ( post_password_required( $comment_post_id ) ) {

        /** * Fires when a comment is attempted on a password-protected post. * * @since 2.9.0 * * @param int $comment_post_id Post ID. */
        do_action( 'comment_on_password_protected', $comment_post_id );

        return new WP_Error( 'comment_on_password_protected' );

    }
/* translators: Comment author title. %s: Comment author name. */
            printf( ent2ncr( __( 'By: %s' ) )get_comment_author_rss() );
        }
        ?> </title> <link><?php comment_link(); ?></link> <dc:creator><![CDATA[<?php echo get_comment_author_rss(); ?>]]></dc:creator> <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_comment_time( 'Y-m-d H:i:s', true, false ), false ); ?></pubDate> <guid isPermaLink="false"><?php comment_guid(); ?></guid> <?php if ( post_password_required( $comment_post ) ) : ?> <description><?php echo ent2ncr( __( 'Protected Comments: Please enter your password to view comments.' ) ); ?></description> <content:encoded><![CDATA[<?php echo get_the_password_form(); ?>]]></content:encoded> <?php else : ?> <description><![CDATA[<?php comment_text_rss(); ?>]]></description> <content:encoded><![CDATA[<?php comment_text(); ?>]]></content:encoded> <?php endif; // End if post_password_required(). ?> <?php         /** * Fires at the end of each RSS2 comment feed item. * * @since 2.1.0 * * @param int $comment_id The ID of the comment being displayed. * @param int $comment_post_id The ID of the post the comment is connected to. */
            if ( get_comment_author_url() ) {
                echo '<uri>' . get_comment_author_url() . '</uri>';
            }
            ?> </author> <id><?php comment_guid(); ?></id> <updated><?php echo mysql2date( 'Y-m-d\TH:i:s\Z', get_comment_time( 'Y-m-d H:i:s', true, false ), false ); ?></updated> <published><?php echo mysql2date( 'Y-m-d\TH:i:s\Z', get_comment_time( 'Y-m-d H:i:s', true, false ), false ); ?></published> <?php if ( post_password_required( $comment_post ) ) : ?> <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content> <?php else : ?> <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content> <?php endif; // End if post_password_required(). ?> <?php         // Return comment threading information (https://www.ietf.org/rfc/rfc4685.txt).         if ( 0 == $comment->comment_parent ) : // This comment is top-level.             ?> <thr:in-reply-to ref="<?php the_guid(); ?>" href="<?php the_permalink_rss(); ?>" type="<?php bloginfo_rss( 'html_type' ); ?>" /> <?php
'<time datetime="%1$s" class="wp-block-latest-posts__post-date">%2$s</time>',
                esc_attr( get_the_date( 'c', $post ) ),
                get_the_date( '', $post )
            );
        }

        if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
            && isset( $attributes['displayPostContentRadio'] ) && 'excerpt' === $attributes['displayPostContentRadio'] ) {

            $trimmed_excerpt = get_the_excerpt( $post );

            if ( post_password_required( $post ) ) {
                $trimmed_excerpt = __( 'This content is password protected.' );
            }

            $list_items_markup .= sprintf(
                '<div class="wp-block-latest-posts__post-excerpt">%1$s</div>',
                $trimmed_excerpt
            );
        }

        if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
            && isset( $attributes['displayPostContentRadio'] ) && 'full_post' === $attributes['displayPostContentRadio'] ) {

            

function render_block_core_footnotes( $attributes$content$block ) {
    // Bail out early if the post ID is not set for some reason.     if ( empty( $block->context['postId'] ) ) {
        return '';
    }

    if ( post_password_required( $block->context['postId'] ) ) {
        return;
    }

    $footnotes = get_post_meta( $block->context['postId'], 'footnotes', true );

    if ( ! $footnotes ) {
        return;
    }

    $footnotes = json_decode( $footnotes, true );

    

function render_block_core_comment_template( $attributes$content$block ) {
    // Bail out early if the post ID is not set for some reason.     if ( empty( $block->context['postId'] ) ) {
        return '';
    }

    if ( post_password_required( $block->context['postId'] ) ) {
        return;
    }

    $comment_query = new WP_Comment_Query(
        build_comment_query_vars_from_block( $block )
    );

    // Get an array of comments for the current post.     $comments = $comment_query->get_comments();
    if ( count( $comments ) === 0 ) {
        return '';
    }

                )
            ),
            __( '(more&hellip;)' )
        );
    }

    $output     = '';
    $has_teaser = false;

    // If post password required and it doesn't match the cookie.     if ( post_password_required( $_post ) ) {
        return get_the_password_form( $_post );
    }

    // If the requested page doesn't exist.     if ( $elements['page'] > count( $elements['pages'] ) ) {
        // Give them the highest numbered page that DOES exist.         $elements['page'] = count( $elements['pages'] );
    }

    $page_no = $elements['page'];
    $content = $elements['pages'][ $page_no - 1 ];
    

function render_block_core_post_comments_form( $attributes$content$block ) {
    if ( ! isset( $block->context['postId'] ) ) {
        return '';
    }

    if ( post_password_required( $block->context['postId'] ) ) {
        return;
    }

    $classes = array( 'comment-respond' ); // See comment further below.     if ( isset( $attributes['textAlign'] ) ) {
        $classes[] = 'has-text-align-' . $attributes['textAlign'];
    }
    if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
        $classes[] = 'has-link-color';
    }
    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

    

function render_block_core_comments_pagination( $attributes$content ) {
    if ( empty( trim( $content ) ) ) {
        return '';
    }

    if ( post_password_required() ) {
        return;
    }

    $classes            = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );

    return sprintf(
        '<div %1$s>%2$s</div>',
        $wrapper_attributes,
        $content
    );
}
if ( isset( $parent_name ) ) {
            $post_type_object = get_post_type_object( $post->post_type );
            echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
        }

        echo "</strong>\n";

        if ( 'excerpt' === $mode
            && ! is_post_type_hierarchical( $this->screen->post_type )
            && current_user_can( 'read_post', $post->ID )
        ) {
            if ( post_password_required( $post ) ) {
                echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
            } else {
                echo esc_html( get_the_excerpt() );
            }
        }

        get_inline_data( $post );
    }

    /** * Handles the post date column output. * * @since 4.3.0 * * @global string $mode List table view mode. * * @param WP_Post $post The current WP_Post object. */
Home | Imprint | This part of the site doesn't use cookies.