Filter Author Link for Numerous Authors for each to go to unique page

Question

I was looking here:

Change destination author link

But there doesn’t seem to be a suggestion on how to work with multiple authors (not co-authors, but each author publishing their own stories.

This is the main portion of the Link class in a plugin I’m working on. This simply turns every author link to the same link. The code is fine for a single author blog.

Am I not using author_link appropriately? Because adding dump(var) actually lists the author ID 3 times in a single post – with the first dump being “null”.

public function hook() {
    add_filter( 'author_link', array( $this, 'xenword_author_link' ), 10, 1 );
}

/**
 * @return mixed|string
 */
public function xenword_author_link($link, $author_id, $author_nicename) {

    if ( ! class_exists( '\XF' ) ) {
        return false;
    }

    // $author_id = get_the_author_meta('ID');

    if ($author_id == '') {
        return false;
    }

    if ($link == '') {
        return false;
    }

    $xf_author = XF::app()->finder('XF:User')->where('user_id', $author_id )->fetchOne();

    $link = XF::app()->router('public')->buildLink( 'canonical:members/#recent-content', $xf_author );

}

0
LPH 5 months 2022-03-11T00:27:14-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse