Site logo

Archived topic

Author page displaying when blank

12 replies · Started by Steve on October 3, 2022

Viewing posts 1–13 of 13

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!

Hi Steve,

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

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.

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

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 ?

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!

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.

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.

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.

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.

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.

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.

This archived topic is closed to new replies.