[Support request] Author page displaying when blank

Home Forums Support [Support request] Author page displaying when blank

Home Forums Support Author page displaying when blank

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #2362034
    Steve

    I’m using an Element to replace the default author profile page.

    I also use iThemes Security setting that hides author pages if there are no posts from them, which is a security enhancement.

    What I’m noticing is the author page’s are still there, kind of, for these zero post users, while also noting the title says ‘Page can’t be found’ and it displays a generic profile image for them.

    I noticed this because we have a recurring error in the logs that accompanies this:

    Error message:
    Attempt to read property "post_author" on null
    
     in GeneratePress_Block_Elements::do_dynamic_image_block called at /home/public_html/production/wp-includes/class-wp-block.php (255)
     in WP_Block::render called at /home/public_html/production/wp-includes/class-wp-block.php (241)
     in WP_Block::render called at /home/public_html/production/wp-includes/class-wp-block.php (241)
     in WP_Block::render called at /home/public_html/production/wp-includes/blocks.php (902)
     in render_block called at /home/public_html/production/wp-includes/blocks.php (940)
     in do_blocks called at /home/public_html/production/wp-content/plugins/gp-premium/elements/class-elements-helper.php (151)
     in GeneratePress_Elements_Helper::build_content called at /home/public_html/production/wp-content/plugins/gp-premium/elements/class-block.php (404)
     in GeneratePress_Block_Element::build_hook called at /home/public_html/production/wp-includes/class-wp-hook.php (307)
     in WP_Hook::apply_filters called at /home/public_html/production/wp-includes/class-wp-hook.php (331)
     in WP_Hook::do_action called at /home/public_html/production/wp-includes/plugin.php (476)
     in do_action called at /home/public_html/production/wp-content/themes/generatepress/404.php (22)
     in include called at /home/public_html/production/wp-content/plugins/better-wp-security/core/lib.php (360)
     in ITSEC_Lib::set_404 called at /home/public_html/production/wp-content/plugins/better-wp-security/core/modules/wordpress-tweaks/class-itsec-wordpress-tweaks.php (450)
     in ITSEC_WordPress_Tweaks::disable_unused_author_pages called at /home/public_html/production/wp-includes/class-wp-hook.php (307)
     in WP_Hook::apply_filters called at /home/public_html/production/wp-includes/class-wp-hook.php (331)
     in WP_Hook::do_action called at /home/public_html/production/wp-includes/plugin.php (476)
     in do_action called at /home/public_html/production/wp-includes/template-loader.php (13)
     in require_once called at /home/public_html/production/wp-blog-header.php (19)
     in require called at /home/public_html/production/index.php (17)

    Thanks!

    #2363615
    Fernando
    Customer Support

    Hi Steve,

    What specific type of Element are you using? Is this a Block Element – Content Template?

    #2364591
    Steve

    I have two setup like:

    View post on imgur.com

    I’m adding a link to the elements export file

    #2364749
    Fernando
    Customer Support

    If you temporarily disable these elements, does the issue still occur? If so, it might be best to reach out iThemes Security as these Elements are just hooking to available pages.

    #2365580
    Steve

    When I disable the elements I get a proper 404 page, so this appears to be something going on with the Elements on this.

    #2366041
    David
    Staff
    Customer Support

    Hi there,

    in the case of author archives that have no Posts, what would you want to display in there place ? Or would you sooner it just correctly 404 error ?

    #2366588
    Steve

    Yes exactly, it should 404. The rationale is it exposes user logins, so a 404 would be ideal.

    I just tried this out with a madeup URL (/author/testing123) and it 404’s properly, so it does let a little bit of info out here by rendering this as it does.

    Thanks for your help!

    #2366995
    David
    Staff
    Customer Support

    Hmmm… odd one this, as i am sure we use the is_author() template tag for that author archive display rules which should return false IF the author has no posts….

    What happens if you add this snippet:

    
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 100 === $element_id &&  !is_author() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Change the 100 to match the author archive Content Templates ID.

    #2370439
    Steve

    Hmm, I tried this snippet with both the Content Template ID and the Author Archive Page Hero ID and nothing changed for either.

    I also tried deactivating the ithemes security feature to hide archive pages for authors without posts and no change, same result which is kind of interesting as you’d expect it to maybe have the user’s name and thumb for this.

    #2370442
    Steve

    I am using Dynamic Data for Headline block and ‘Post author name’ as the selection. Not sure if this is the possible issue? It seems to be displaying that hero content element either way.

    #2370514
    Fernando
    Customer Support

    Can you try this instead?:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 100 === $element_id &&  $GLOBALS['wp_query']->found_posts < 1 ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Replace 100 with the Block Element ID.

    #2372771
    Steve

    That works, mostly.

    It does present a page with a line on it, so while that page hero area is gone, there is still a page that is a true 404 page.

    Feel free to check out the link.

    #2372888
    Fernando
    Customer Support

    You’ll need to exclude the ID of the Content template as well. It’s still displaying.

    Use this instead:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
    	$my_element_ids = array( 100, 101 );
        if ( in_array( $element_id, $my_element_ids) &&  $GLOBALS['wp_query']->found_posts < 1 ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Replace 100, 101 with the IDs of the Elements you which to exclude. Make sure the Content Template – Block Element ID is in the array as well.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.