Author Preview and Author dynamic variables are not working with Archive pages

Hey everyone,

I’m currently facing an issue that I cannot use the Author page preview for a specific author.
Whenever I go to Preview -> Author, and I select an author, it only shows the home page.
Weirdly enough, it shows all of the authors as marked. (See screenshot).

On the other hand, when I visit the page of the Author, I see that the template is connected and it also displays its content, but it does not display the dynamic variables such as {{dc:author:display_name}} (Instead it shows nothing for that tag).

I’m running on the latest version, 6.1.5, and I do not see any javascript errors within the console. I do see a PHP notice within the debug.log:

[01-Mar-2023 06:27:01 UTC] PHP Warning: Dynamic Content return value not scalar : object in /wp-content/themes/pro/cornerstone/includes/classes/Services/DynamicContent.php on line 258

I’m not sure what I’m missing, but I guess it’s an error that is somehow connected to the way the conditionals are checked. Weirdly enough is the fact that all of the users are selected in the dropdown.

Update: I’ve tried it on a clean installation with only the Pro theme activated. The error is the same (See screenshot).

I dug deeper into the core and I’ve been able to address he issue partially (At least in regards of displaying the author tags correctly.

Check out the following core file:
pro/cornerstone/includes/classes/Services/DynamicContent.php

It contains a function called get_contextual_author( $args ) in line 459, which is responsible for fetching the given author based on the available properties.
While this function works great for posts, it does not return the actual author from a given author page.
Maybe this is partially also a naming fault, but generally, if I want to use an archive page template to show the Author page for a single author, I expect to be able to use the dynamic author tags such as {{dc:author:display_name}}

In the latest release, I don’t see any way how you can leverage those dynamic tags for authors on a specific author page.
If I’m using the dynamic user tags, it always returns the current user (which is correct, but not what I need as I need the author).
If I’m using the author tag, nothing is returned instead due to the function mentioned above.
To fix that, I’ve extended the function (for now statically) to represent a check if an author page is given and if it is, fetch the current author from the query vars and load it from the cached users.

The code I added:

if( is_author() ){
  $author_id = get_query_var( 'author' );
  
  if( $author_id ){
    return $this->get_cached_user( $author_id );
  }
}

The full function now:

public function get_contextual_author( $args ) {

  if( is_author() ){
    $author_id = get_query_var( 'author' );
    
    if( $author_id ){
      return $this->get_cached_user( $author_id );
    }
  }

  $post = $this->get_contextual_post( $args );
  if ( ! $post )  {
    return null;
  }
  return $this->get_cached_user( get_post_field( 'post_author', $post ) );
}

This gives us back the possibility of using the author tags on single-author pages.
While this is only one part, here are other areas that need to be investigated by your team:

  • Why the preview with authors on author pages does not work?
  • How does using those tags affect the global author archive page?
  • Will the tags for the same way within the loopers?

Would love to see this structure being optimized and implemented.

1 Like

Hey @TheOwnplay,

We will report this to our developer. I will ask them to chime in on this thread as well.

Please bear with us.

This happened to me this very morning as I was working on a news website for a client. I came to the forum, and found this thread. Thought I was going crazy.

Any update on this, Theme.co?

Still LOVE this theme. It’s the best.

1 Like

Thanks for the kind words.

Yes we will be using code similar to @TheOwnplay . Thanks a bunch for that too. Scheduling it for March 20th in 6.1.8.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.