Support » Allgemeine Fragen » Passwortschutz bei Beiträgen und Seiten aktivieren

  • Gelöst cupcakelike

    (@cupcakelike)


    Hallo Leute, Ich brauche dringend eure Hilfe!

    Ich kann in WordPress die integrierte Passwort-Schutz-Funktion unter den Sichtbarkeitsoptionen bei den Seiten und Beiträgen nicht nutzen, weil mir wohl eine Einstellung, Funktion, what ever fehlt!

    (äußert sich so, dass, wenn ich den Link öffne, vor dem Titel ein Geschützt steht, der Inhalt ohne Passwortabfrage komplett zu sehen ist.)

    – habe bereits in den einzelnen content-templates

    <?php if ( post_password_required() ) {
    return;
    } ?>

    eingefügt

    in der function.php (bzw. in der vorgesehenen Datei, die auch funktioniert) bekomme ich bei dem hier einen fatal error.
    (Fatal error: Cannot redeclare post_password_required() (previously declared in… /post-template.php:768) in …/enqueue-setup.php on line 127)

    <?php
    function post_password_required( $post = null ) {
    $post = get_post($post);
    
    if ( empty( $post->post_password ) )
    return false;
    
    if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
    return true;
    
    require_once ABSPATH . WPINC . '/class-phpass.php';
    $hasher = new PasswordHash( 8, true );
    
    $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
    if ( 0 !== strpos( $hash, '$P$B' ) )
    return true;
    
    return ! $hasher->CheckPassword( $post->post_password, $hash );
    }?>

    ich bin echt mit meinem Latein am Ende…

    Weiß jemand, wie ich einfach diese interne Passwortfunktion aktivieren kann? Möchte an sich kein extra Plugin oder Template aktivieren und brauche nur diesen simplen Schutz.

Ansicht von 6 Antworten - 1 bis 6 (von insgesamt 6)
  • Welches Theme benutzt du denn?
    Normalerweise ist diese Funktion „idiotensicher“, will heißen, es ist sogar nur recht umständlich möglich, die standardfunktion (also post ist nicht sichtbar) zu ändern.

    Die Fehlermeldung die du bekommst, kann eigentlich nicht durch das snippet, das du einsetzt entstehen. Die Meldung sagt ja, dass du versuchst, die Funktion nochmal zu definieren.

    Zeig doch mal die Template-Datei, in der der Content ausgegeben wird, obwohl ein Passwort gesetzt ist.

    Thread-Starter cupcakelike

    (@cupcakelike)

    Erstmal: Vielen Dank für deine Antwort!!! Ist wie so ein Hoffnungsschimmer gerade…

    Ich habe mein eigenes Theme erstellt.

    Und die template-Datei (falls du die single.php meinst, bzw. jene, die für den content zuständig ist) sieht aktuell so aus:

    content-blog_event

    <?php
    /**
     * Template part for displaying posts.
     *
     */
    
    ?>
    
    <?php
    if ( post_password_required() ) {
        return;
    }
    ?>
    
    <h1> <?php the_title(); ?></h1>
    
    <section>
    
        <?php
    
        $value = get_field("teaser-text");
    
        if ($value) {
            ?>
            <article class="mg-bt-80">
                <h3 class="pd-0-15"><?php echo get_field('teaser-text') ?></h3>
            </article>
        <?php }
    
        if (have_rows('content')):
    
            while (have_rows('content')) : the_row();
    
                if (get_row_layout() == 'content_left'):
    
                    $left_headline = get_sub_field('headline');
                    $left_text = get_sub_field('text');
                    $left_image = get_sub_field('image');
                    $imagetitle = get_sub_field('imagetitle');
                    ?>
                    <article>
                        <h2><?php echo $left_headline ?></h2>
    
                        <div class="row">
                            <div class="col-md-8 col-xs-12">
                                <?php echo $left_text ?>
                            </div>
    
                            <div class="col-md-4 col-xs-12">
                                <a class="swipebox" title="<?php echo $left_image['alt']; ?>"
                                   href="<?php echo $left_image['url'] ?>">
                                    <img src="<?php echo $left_image['sizes']['large']; ?>"
                                         alt="<?php echo $left_image['alt']; ?>"/>
                                </a>
                                <p class="fs-small text-center pd-tp-10"><?php echo  $imagetitle ?></p>
                            </div>
                        </div>
                    </article>
    
                <?php endif; ?>
    
                <?php if (get_row_layout() == 'content_right'):
                    $right_headline = get_sub_field('headline');
                    $right_text = get_sub_field('text');
                    $right_image = get_sub_field('image');
                    $imagetitle = get_sub_field('imagetitle');
                    ?>
                    <article>
                        <h2><?php echo $right_headline ?></h2>
                        <div class="row">
                            <div class="col-md-8 col-xs-12 pull-right">
                                <?php echo $right_text ?>
                            </div>
    
                            <div class="col-md-4 col-xs-12 pull-left">
                                <a class="swipebox" title="" href="<?php echo $right_image['url'] ?>">
                                    <img src="<?php echo $right_image['sizes']['large']; ?>"
                                         alt="<?php echo $right_image['alt']; ?>"/>
                                </a>
                                <p class="fs-small text-center pd-tp-10"><?php echo $imagetitle ?></p>
                            </div>
                        </div>
                    </article>
    
                <?php endif; endwhile; endif ?>
    
        <?php if (have_rows('editing')):
    
            while (have_rows('editing')) : the_row();
    
                if (get_row_layout() == 'editing_content'):
                    $editing_before = get_sub_field('before');
                    $editing_after = get_sub_field('after');
                    ?>
                    <article>
                        <h2>Vorher/Nachher</h2>
                        <div class="row">
                            <div class="col-xs-12">
                                <div id="container-before-after">
                                    <img src="<?php echo $editing_before['sizes']['large']; ?>"
                                         alt="<?php echo $editing_before['alt']; ?>"/>
                                    <img src="<?php echo $editing_after['sizes']['large']; ?>"
                                         alt="<?php echo $editing_after['alt']; ?>"/>
                                </div>
                            </div>
                        </div>
                    </article>
    
                <?php endif;
            endwhile;
        endif; ?>
    
        <?php if (have_rows('image-gallery')):
    
            while (have_rows('image-gallery')) : the_row();
                if (get_row_layout() == 'gallery'):
                    $gallery_headline = get_sub_field('headline');
                    $gallery_images = get_sub_field('images');
                    ?>
                    <article>
                        <h2><?php echo $gallery_headline ?></h2>
                        <?php if ($gallery_images): ?>
                        <div class="row">
                            <?php foreach ($gallery_images as $image): ?>
                                <section class="col-md-2 col-sm-2 col-xs-4 mg-bt-20">
    
                                    <a class="swipebox" title="" href="<?php echo $image['url'] ?>">
                                        <img src="<?php echo $image['sizes']['thumbnail']; ?>"
                                             alt="<?php echo $image['alt']; ?>"/>
                                    </a>
                                </section>
                            <?php endforeach;
                            endif;
                            ?>
                        </div>
                    </article>
    
                    <?php if (have_rows('credits')): ?>
                    <div class="row">
                        <article class="col-xs-12 mg-tp--40">
                            <h2>Credits</h2>
                            <div class="pd-0-10">
                                <?php
    
                                while (have_rows('credits')) : the_row();
                                    if (get_row_layout() == 'credit_info'):
    
                                        ?>
    
                                        <?php
                                        if (have_rows('name')):
    
                                            // loop through the rows of data
                                            while (have_rows('name')) : the_row();
    
                                                // display a sub field value
                                                $model_name_titel = get_sub_field('titel');
                                                $name_of_model = get_sub_field('name'); ?>
    
                                                <div class="row">
                                                    <div class="col-md-3 col-sm-3 col-xs-12"><b><p><?php echo $model_name_titel; ?></b></div>
                                                    <div class="col-md-3 col-sm-9 col-xs-12"><p><?php echo $name_of_model; ?></div>
                                                </div>
    
                                            <?php endwhile; endif; ?>
    
                                        <?php
                                        if (have_rows('social_media')):
    
                                            // loop through the rows of data
                                            while (have_rows('social_media')) : the_row();
    
                                                // display a sub field value
                                                $social_media_site = get_sub_field('social-media-site');
                                                $social_media_url = get_sub_field('social-media-url'); ?>
    
                                                <div class="row">
                                                    <div class="col-md-3 col-sm-3 col-xs-12"><b><p><?php echo $social_media_site; ?></b></div>
                                                    <div class="col-md-9 col-sm-9 col-xs-12"><p><?php echo $social_media_url; ?></div>
                                                </div>
    
                                            <?php endwhile; endif; ?>
    
                                    <?php endif;
                                endwhile; ?>
                            </div>
                    </div>
                    </article>
                    <?php
                endif;
                    ?>
                <?php endif;
            endwhile;
        endif;
        ?>
    
        <article>
            <h2>Infos</h2>
            <div class="row">
                <div class="col-xs-12">
                    <div class="row">
                        <div class="col-md-3"><b><p>Datum</b></div>
                        <div class="col-md-9"><p><?php echo the_date(); ?></div>
                    </div>
                    <div class="row">
                        <div class="col-md-3"><b><p>Kategorie</b></div>
                        <div class="col-md-9">
                            <p><?php echo get_the_term_list ($post->ID, 'category', '', ', ', '')?></p>
                        </div>
                    </div>
                    <div class="row">
    
                        <div class="col-md-3"><b><p>Tags</p></b></div>
                        <div class="col-md-9"><p><?php echo the_tags('', ', ', '');?></p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-3"><b><p>Location</p></b></div>
                        <div class="col-md-9">
                            <p><?php echo get_the_term_list($post->ID, 'location', '', ', ', '') ?></div>
                    </div>
                </div>
            </div>
        </article>
    </section>
    <div class="clearfix"></div>
    <section>
        <article>
            <h1>Sharing is Caring!</h1>
            <div class="row">
                <h3 class="text-center mg-bt-40">Hat euch der Beitrag gefallen? Dann teilt ihn doch mit deinen Freunden! <br>Ich freue mich über jeden Support :) - Danke!</h3>
    
                <div class="shariff center-block"></div>
            </div>
        </article>
    </section>
    
    <section>
        <?php
        $post_objects = get_field('choosing_posts');
        if( $post_objects ): ?>
            <h1>Passende Beiträge:</h1>
            <?php foreach( $post_objects as $post_object): ?>
    
                <div class="col-md-6 mg-bt-20">
                    <a href="<?php echo get_permalink($post_object->ID) ?>">
    
                        <?php $headerimage   = get_field('header-image', $post_object->ID); ?>
    
                        <div class="item-background" style="background-image: url(<?php echo $headerimage['url']; ?>)"></div>
                        <div class="transparent-background">
                            <img class="item-kreis" src="<?php echo get_template_directory_uri() . '/assets/img/kreis.png'; ?>" alt="">
                            <h3><?php echo get_the_title($post_object->ID)?></h3>
                        </div>
                    </a>
    
                </div>
            <?php endforeach; ?>
        <?php endif;
        ?>
    </section>
    
    <div class="clearfix"></div>
    
    <section class="mg-tp-40">
        <div class="row">
            <div class="col-xs-6">
    
                <?php $next_post = get_next_post(); ?>
    
                <?php if ( !empty( $next_post ) ) : ?>
                    <a class="" href="<?php echo get_permalink( $next_post->ID ); ?>"><h3>« <?php echo $next_post->post_title; ?></h3></a>
                <?php endif; ?>
            </div>
    
            <div class="col-xs-6 pull-right text-right">
    
                <?php $prev_post = get_previous_post(); ?>
    
                <?php if ( !empty( $prev_post ) ) : ?>
                    <a href="<?php echo get_permalink( $prev_post->ID ); ?>"><h3><?php echo $prev_post->post_title; ?> »</h3></a>
                <?php endif; ?></div>
        </div>
    
    </section>
    <div class="clearfix"></div>

    Wie gesagt, da habe ich schon irgendwie versucht diese Funktion einzubauen, die aber so nichts bringt… Ich habe sie u.a. bei der comment.php gefunden, da ich diese aber deaktiviert habe, dachte ich zunächst, dass es irgendwie zusammenhängt.

    Hallo

    Ich habe mir das template angesehen, du verwendest advancedcustomfields oder ?
    Vielleicht hilft dir dieser link weiter
    Hide ACF if password protected

    LG
    urgernj

    Thread-Starter cupcakelike

    (@cupcakelike)

    @urgenj….
    Darauf uss man erstmal kommen, dass ACF der Grund sein könnte…
    Mein Code sieht nun so aus:

    <?php
    /**
     * Template part for displaying posts.
     *
     */
    
    ?>
    
    <?php
    if ( post_password_required() ) {
    
    <h1> <?php the_title(); ?></h1>
    
    <section>
    
        <?php
    
        $value = get_field("teaser-text");
    
        if ($value) {
            ?>
            <article class="mg-bt-80">
                <h3 class="pd-0-15"><?php echo get_field('teaser-text') ?></h3>
            </article>
        <?php }
    
        if (have_rows('content')):
    
            while (have_rows('content')) : the_row();
    
                if (get_row_layout() == 'content_left'):
    
                    $left_headline = get_sub_field('headline');
                    $left_text = get_sub_field('text');
                    $left_image = get_sub_field('image');
                    $imagetitle = get_sub_field('imagetitle');
                    ?>
                    <article>
                        <h2><?php echo $left_headline ?></h2>
    
                        <div class="row">
                            <div class="col-md-8 col-xs-12">
                                <?php echo $left_text ?>
                            </div>
    
                            <div class="col-md-4 col-xs-12">
                                <a class="swipebox" title="<?php echo $left_image['alt']; ?>"
                                   href="<?php echo $left_image['url'] ?>">
                                    <img src="<?php echo $left_image['sizes']['large']; ?>"
                                         alt="<?php echo $left_image['alt']; ?>"/>
                                </a>
                                <p class="fs-small text-center pd-tp-10"><?php echo  $imagetitle ?></p>
                            </div>
                        </div>
                    </article>
    
                <?php endif; ?>
    
                <?php if (get_row_layout() == 'content_right'):
                    $right_headline = get_sub_field('headline');
                    $right_text = get_sub_field('text');
                    $right_image = get_sub_field('image');
                    $imagetitle = get_sub_field('imagetitle');
                    ?>
                    <article>
                        <h2><?php echo $right_headline ?></h2>
                        <div class="row">
                            <div class="col-md-8 col-xs-12 pull-right">
                                <?php echo $right_text ?>
                            </div>
    
                            <div class="col-md-4 col-xs-12 pull-left">
                                <a class="swipebox" title="" href="<?php echo $right_image['url'] ?>">
                                    <img src="<?php echo $right_image['sizes']['large']; ?>"
                                         alt="<?php echo $right_image['alt']; ?>"/>
                                </a>
                                <p class="fs-small text-center pd-tp-10"><?php echo $imagetitle ?></p>
                            </div>
                        </div>
                    </article>
    
                <?php endif; endwhile; endif ?>
    
        <?php if (have_rows('editing')):
    
            while (have_rows('editing')) : the_row();
    
                if (get_row_layout() == 'editing_content'):
                    $editing_before = get_sub_field('before');
                    $editing_after = get_sub_field('after');
                    ?>
                    <article>
                        <h2>Vorher/Nachher</h2>
                        <div class="row">
                            <div class="col-xs-12">
                                <div id="container-before-after">
                                    <img src="<?php echo $editing_before['sizes']['large']; ?>"
                                         alt="<?php echo $editing_before['alt']; ?>"/>
                                    <img src="<?php echo $editing_after['sizes']['large']; ?>"
                                         alt="<?php echo $editing_after['alt']; ?>"/>
                                </div>
                            </div>
                        </div>
                    </article>
    
                <?php endif;
            endwhile;
        endif; ?>
    
        <?php if (have_rows('image-gallery')):
    
            while (have_rows('image-gallery')) : the_row();
                if (get_row_layout() == 'gallery'):
                    $gallery_headline = get_sub_field('headline');
                    $gallery_images = get_sub_field('images');
                    ?>
                    <article>
                        <h2><?php echo $gallery_headline ?></h2>
                        <?php if ($gallery_images): ?>
                        <div class="row">
                            <?php foreach ($gallery_images as $image): ?>
                                <section class="col-md-2 col-sm-2 col-xs-4 mg-bt-20">
    
                                    <a class="swipebox" title="" href="<?php echo $image['url'] ?>">
                                        <img src="<?php echo $image['sizes']['thumbnail']; ?>"
                                             alt="<?php echo $image['alt']; ?>"/>
                                    </a>
                                </section>
                            <?php endforeach;
                            endif;
                            ?>
                        </div>
                    </article>
    
                    <?php if (have_rows('credits')): ?>
                    <div class="row">
                        <article class="col-xs-12 mg-tp--40">
                            <h2>Credits</h2>
                            <div class="pd-0-10">
                                <?php
    
                                while (have_rows('credits')) : the_row();
                                    if (get_row_layout() == 'credit_info'):
    
                                        ?>
    
                                        <?php
                                        if (have_rows('name')):
    
                                            // loop through the rows of data
                                            while (have_rows('name')) : the_row();
    
                                                // display a sub field value
                                                $model_name_titel = get_sub_field('titel');
                                                $name_of_model = get_sub_field('name'); ?>
    
                                                <div class="row">
                                                    <div class="col-md-3 col-sm-3 col-xs-12"><b><p><?php echo $model_name_titel; ?></b></div>
                                                    <div class="col-md-3 col-sm-9 col-xs-12"><p><?php echo $name_of_model; ?></div>
                                                </div>
    
                                            <?php endwhile; endif; ?>
    
                                        <?php
                                        if (have_rows('social_media')):
    
                                            // loop through the rows of data
                                            while (have_rows('social_media')) : the_row();
    
                                                // display a sub field value
                                                $social_media_site = get_sub_field('social-media-site');
                                                $social_media_url = get_sub_field('social-media-url'); ?>
    
                                                <div class="row">
                                                    <div class="col-md-3 col-sm-3 col-xs-12"><b><p><?php echo $social_media_site; ?></b></div>
                                                    <div class="col-md-9 col-sm-9 col-xs-12"><p><?php echo $social_media_url; ?></div>
                                                </div>
    
                                            <?php endwhile; endif; ?>
    
                                    <?php endif;
                                endwhile; ?>
                            </div>
                    </div>
                    </article>
                    <?php
                endif;
                    ?>
                <?php endif;
            endwhile;
        endif;
        ?>
    
        <article>
            <h2>Infos</h2>
            <div class="row">
                <div class="col-xs-12">
                    <div class="row">
                        <div class="col-md-3"><b><p>Datum</b></div>
                        <div class="col-md-9"><p><?php echo the_date(); ?></div>
                    </div>
                    <div class="row">
                        <div class="col-md-3"><b><p>Kategorie</b></div>
                        <div class="col-md-9">
                            <p><?php echo get_the_term_list ($post->ID, 'category', '', ', ', '')?></p>
                        </div>
                    </div>
                    <div class="row">
    
                        <div class="col-md-3"><b><p>Tags</p></b></div>
                        <div class="col-md-9"><p><?php echo the_tags('', ', ', '');?></p>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-3"><b><p>Location</p></b></div>
                        <div class="col-md-9">
                            <p><?php echo get_the_term_list($post->ID, 'location', '', ', ', '') ?></div>
                    </div>
                </div>
            </div>
        </article>
    </section>
    <div class="clearfix"></div>
    <section>
        <article>
            <h1>Sharing is Caring!</h1>
            <div class="row">
                <h3 class="text-center mg-bt-40">Hat euch der Beitrag gefallen? Dann teilt ihn doch mit deinen Freunden! <br>Ich freue mich über jeden Support :) - Danke!</h3>
    
                <div class="shariff center-block"></div>
            </div>
        </article>
    </section>
    
    <section>
        <?php
        $post_objects = get_field('choosing_posts');
        if( $post_objects ): ?>
            <h1>Passende Beiträge:</h1>
            <?php foreach( $post_objects as $post_object): ?>
    
                <div class="col-md-6 mg-bt-20">
                    <a href="<?php echo get_permalink($post_object->ID) ?>">
    
                        <?php $headerimage   = get_field('header-image', $post_object->ID); ?>
    
                        <div class="item-background" style="background-image: url(<?php echo $headerimage['url']; ?>)"></div>
                        <div class="transparent-background">
                            <img class="item-kreis" src="<?php echo get_template_directory_uri() . '/assets/img/kreis.png'; ?>" alt="">
                            <h3><?php echo get_the_title($post_object->ID)?></h3>
                        </div>
                    </a>
    
                </div>
            <?php endforeach; ?>
        <?php endif;
        ?>
    </section>
    
    <div class="clearfix"></div>
    
    <section class="mg-tp-40">
        <div class="row">
            <div class="col-xs-6">
    
                <?php $next_post = get_next_post(); ?>
    
                <?php if ( !empty( $next_post ) ) : ?>
                    <a class="" href="<?php echo get_permalink( $next_post->ID ); ?>"><h3>« <?php echo $next_post->post_title; ?></h3></a>
                <?php endif; ?>
            </div>
    
            <div class="col-xs-6 pull-right text-right">
    
                <?php $prev_post = get_previous_post(); ?>
    
                <?php if ( !empty( $prev_post ) ) : ?>
                    <a href="<?php echo get_permalink( $prev_post->ID ); ?>"><h3><?php echo $prev_post->post_title; ?> »</h3></a>
                <?php endif; ?></div>
        </div>
    
    </section>
    <div class="clearfix"></div>
    }
    ?>

    Ergebnis:
    Template ohne Inhalt wird angezeigt.
    Habe geraude auch das hier Versucht:
    if ( post_password_required() ) {

    echo get_the_password_form();

    } else {
    [Content]
    }

    Funktioniert ebenfalls nicht…

    Auch funktioniert nicht mit einem „!“, also if ( ! post_password_required() )

    Thread-Starter cupcakelike

    (@cupcakelike)

    HINBEKOMMEN!

    Ich habe das ganze mal herausgelöscht und in die single.php eingefügt. also:

    <?php
    /**
     * The template for displaying all single posts.
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
     *
     *
     */
    
    get_header(); ?>
    
            <main id="main" class="site-main" role="main">
    
                <?php
                if ( post_password_required() )
                {
    
                  echo get_the_password_form();
    
                    } 
    
                    else {
                    //Photographie
                    if ( array ('cat' => '139',) )
                    {get_template_part( 'template-parts/content', 'blog_photo');}
    
                    if ( array ('cat' => '140',) )
                    {get_template_part( 'template-parts/content', 'blog_events');} //Die hier wurde die ganze zeit korrigiert...
    
                    }?>
    
            </main><!-- #main -->
        <hr class="mg-tp-80">
    <?php
    get_sidebar();
    get_footer();

    wenn man als nicht eingeloggter User diese Seite besuchen möchte, kommt die Abfrage *-*

    Danke urgernj für den Tipp!!!!

    Nicht direkt ACF ist der Grund dafür, dass es nicht einfach so geklappt hat, sondern der recht komplexe Aufbau deines Templates.
    In Standard-Templates wird eben einfach the_content() benutzt, dort funktioniert das dann ohne weiteres zutun.
    Nur als ergänzende Info 🙂

Ansicht von 6 Antworten - 1 bis 6 (von insgesamt 6)
  • Das Thema „Passwortschutz bei Beiträgen und Seiten aktivieren“ ist für neue Antworten geschlossen.