- This topic has 12 replies, 3 voices, and was last updated 5 months, 2 weeks ago by
Fernando.
-
AuthorPosts
-
October 3, 2022 at 3:12 pm #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!
October 4, 2022 at 11:27 pm #2363615Fernando Customer Support
Hi Steve,
What specific type of Element are you using? Is this a Block Element – Content Template?
October 5, 2022 at 3:53 pm #2364591Steve
October 5, 2022 at 9:19 pm #2364749Fernando 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.
October 6, 2022 at 12:16 pm #2365580Steve
When I disable the elements I get a proper 404 page, so this appears to be something going on with the Elements on this.
October 7, 2022 at 3:40 am #2366041David
StaffCustomer SupportHi 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 ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 7, 2022 at 12:46 pm #2366588Steve
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!
October 8, 2022 at 6:00 am #2366995David
StaffCustomer SupportHmmm… 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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 11, 2022 at 3:25 pm #2370439Steve
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.
October 11, 2022 at 3:37 pm #2370442Steve
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.
October 11, 2022 at 6:30 pm #2370514Fernando 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.
October 13, 2022 at 2:17 pm #2372771Steve
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.
October 13, 2022 at 6:46 pm #2372888Fernando 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. -
AuthorPosts
- You must be logged in to reply to this topic.