1

I have used the Advanced Custom Fields plugin to create all the data elements for a company leadership directory page and management bio pages.

On the site blog, management will not be posting articles themselves, but it should appear as if they have. I think this practice is referred to as "guest authors" - authors that don't have user accounts in the WordPress site where the content is posted on their behalf by site admins.

What I'd like to happen is this:

  1. When a guest author is selected for the post (an ACF Custom Post Object), output their name. The name should link to the archive page www.example.com/author/john-doe.
  2. When a quest author is not selected, default to the site admin's author info.
  3. I do NOT want to create ghost user accounts to post as guest authors. (As mentioned, these guest authors have already been defined in detail as part of the team leadership post type in combination with ACF.)

I'm relatively new to WordPress theme development and have been Googling for a way to achieve this. These two posts are the closest I could find to my situation but do not solve what I'm trying to do:

Is this a common practice? If so, can someone direct me to more information? I'd greatly appreciate it!

UPDATE

I’m kinda getting there. So far I’ve managed to write a custom author posts link if a guest author exists.

The resulting URL for a post author and guest author now have matching formats …

post author ex: www(dot)example.com/author/john-doe guest author ex: www(dot)example.com/author/jane-doe

Now I just need to figure out how to hijack the author archive page to display posts from the post author OR the guest author.

FUNCTIONS.PHP CODE:

add_filter( 'the_author_posts_link', 'custom_author_posts_link' );

function custom_author_posts_link($url) {

`global $post;

$post_object = get_field('post_author');

if ( $post_object ) {

`// GUEST AUTHOR EXISTS - override post object to grab relevant guest author info
global $post;
$post = $post_object;
setup_postdata( $post );

$guest_author_slug = $post->post_name;
$guest_author_name = get_field('team_member_name');
$guest_author_posts_link = site_url() . '/author/' .  $guest_author_slug;

$guest_url = sprintf(
    '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
    esc_url( $guest_author_posts_link ),
    esc_attr( sprintf( __( 'Posts by %s' ), $guest_author_name ) ),
    $guest_author_name
);

$guest_url = $link; 

wp_reset_postdata(); // We're done here. Return to main $post object
`

}

return $url;
`

}

UPDATE 2

I've reworked things a bit. Instead of 'hijacking' the author archive page, I've modified the "the_author_posts_link" filter to point to a custom post type, when it's appropriate to do so. Now each of my three author types has an endpoint where I can display their bio and activity.

The blog posts use Advanced Custom Fields which have a select pulling in post objects from the two relevant post types, Team Leadership and Guest Contributors.

add_filter( 'the_author_posts_link', 'custom_author_posts_link' );

function custom_author_posts_link($url) {

    global $post;

    // Check if a post author is defined in the post_author post object. If none is defined, override will     not occur and default post author will display    
    $post_object = get_field('post_author');    

    if ( $post_object ) {

        // Post author exists. Override post object to grab relevant guest author info.
        global $post;
        $post = $post_object;
        setup_postdata( $post );

        $author_type = get_field('author_type');
        $author_slug = $post->post_name;
        $author_name = get_field('author_name');

        // Use the post author type to determine the author link 
        if ( strtolower($author_type) == 'guest contributor' ){
            $author_posts_link = site_url() . '/guest-contributor/' .  $author_slug;
        } else {
            $author_posts_link = site_url() . '/leadership-team/' .  $author_slug;
        }

        // Format the link to return. This is based off the default filter (See WordPress: https://core.trac.    wordpress.org/browser/tags/4.1/src/wp-includes/author-template.php)    
        $guest_url = sprintf(    
            '<a href="%1$s" tit    le="%2$s" rel="author">%3$s</a>',    
            esc_url( $author_po    sts_link ),    
            esc_attr( sprintf(     __( 'Posts     by %s' ), $author_name ) ),    
            $author_name    
        );    

        $url = $guest_url; 

        wp_reset_postdata(); // We're done here, return to main $post object

    }

    return $url;

}

2 Answers 2

1

You could have saved yourself a ton of work and just used the Co-Authors Plus plugin. It has a guest author function. You do have to set them up, but there is no account/password for them, and they can have author pages. (I am not affiliated with them, just use it on several sites.)

1
  • 1
    This can be a comment instead of an answer.
    – bravokeyl
    May 25, 2016 at 12:49
0

If you want something to behave like a "normal" wordpress author then the best thing to do is to create a "dummy" account for it, and if you really want disable the possibility to login to it. For any other solution that mimics the functionality in other ways you first need to fully understand the functionality you are trying to mimic, and by your own words "I'm relatively new to WordPress theme development"....

9
  • As mentioned, I'm looking for a solution that doesn't require dummy accounts. I'm learning, yes, which is why I've posted here looking for advice from the WordPress community. Your comment is more judgmental than helpful.
    – emkmail2
    Jan 28, 2015 at 21:29
  • without any reason why you don't want "dummy" account, dummy accounts will remain the best answer to what you want to do. You are trying to redesign the representation of authors in wordpress, something that was developed over years and integrates with several parts of the system. If this is anything long term, you might keep fighting wordpress with any new version that comes out, and the compatibility with other plugins will be questionable. Jan 29, 2015 at 5:00
  • I've gone this path due to my IT department's overzealous concern for security. They don't like the idea of creating and managing 40+ username and passwords.
    – emkmail2
    Jan 29, 2015 at 16:56
  • [Accidentally posted before completing comment] I've gone this path due to my IT department's overzealous security concerns. They don't like creating and managing 40+ username and passwords. There is a lot going on with the "authors": they "write" posts, present at conferences, present at webinars, some are company leaders, some are guest writers inside the company, some are guest writers outside the company. But, the company's marketing team will be centrally responsible for posting all content on behalf of the 40+ authors.
    – emkmail2
    Jan 29, 2015 at 17:03
  • In my opinion it is easier to disable login for specific users the what you are trying to do. the problem with marketing people is that today they want it done that way, but tomorrow they will request addition feature that will just not play well or will be harder to implement. Jan 29, 2015 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.