Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Co-authors plus guest authors do not display #1582

Closed
timburden opened this issue Oct 16, 2017 · 2 comments
Closed

Co-authors plus guest authors do not display #1582

timburden opened this issue Oct 16, 2017 · 2 comments

Comments

@timburden
Copy link

timburden commented Oct 16, 2017

Passing authors to a twig file from get_coauthors() works fine unless the authors are guest authors.

Expected behavior

Guest authors would display properly using author.name and author.link

Actual behavior

These values are null

Steps to reproduce behavior

In a template file:

require_once( dirname( __FILE__ ) . '/includes/class-sjmpost.php' );
$mposts = Timber::get_posts( $args, 'SJMPost' );

class-sjmpost.php

class SJMPost extends TimberPost {

    /**
     * Provides an authors method to twig, which conditionally uses Co-Authors Plus if available.
     */
    function authors() {
        $authors = array();
        if ( function_exists( 'get_coauthors' ) ) {

            $cauthors = get_coauthors( $this->ID );
            foreach ( $cauthors as $author ) {
                    $author = new Timber\User( $author );
                    var_dump( $author );
                    $authors[] = $author;
            }
        } else {
            $authors[] = new Timber\User( $this->post_author );
        }

        return $authors;
    }
}

In twig file:

{{ post.authors | wrap_and_join('<a href="{{item.link}}">{{item.name}}</a>', ' and ' ) }}

wrap_and_join() is just a twig extension for joining arrays of objects with a twig snippet.
At the var_dump( $author ), the user object is filled out properly if the author is a real user, but not if it is a co-authors plus guest author. he following shows partial output from one real user and one guest user:

// real user
object(Timber\User)#1843 (46) {
--
  | ["object_type"]=>
  | string(4) "user"
  | ["_link"]=>
  | NULL
  | ["description"]=>
  | string(0) ""
  | ["display_name"]=>
  | string(16) "Malcolm Johnston"

//guest user

object(Timber\User)#1841 (11) {
--
  | ["object_type"]=>
  | string(4) "user"
  | ["_link"]=>
  | NULL
  | ["description"]=>
  | NULL
  | ["display_name"]=>
  | NULL

What version of WordPress, PHP and Timber are you using?

WP 4.8.1, PHP 7.0.23, Timber 1.5.2

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

Download from WP.org

@timburden
Copy link
Author

My code is based on the snippets provided in this issue: #1158

@Levdbas
Copy link
Member

Levdbas commented May 12, 2023

Usage of external plugin and stale for a while, closing.

@Levdbas Levdbas closed this as completed May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants