• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

timber / timber / 20846050397

09 Jan 2026 08:35AM UTC coverage: 89.608%. Remained the same
20846050397

Pull #3181

travis-ci

web-flow
Merge 5bae5023f into 6ae23b1a2
Pull Request #3181: test: Fix issue with image test that sets a constant

4596 of 5129 relevant lines covered (89.61%)

63.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/src/Integration/CoAuthorsPlusIntegration.php
1
<?php
2

3
namespace Timber\Integration;
4

5
use CoAuthors_Plus;
6
use Timber\Integration\CoAuthorsPlus\CoAuthorsPlusUser;
7
use Timber\Post;
8
use Timber\Timber;
9
use WP_User;
10

11
class CoAuthorsPlusIntegration implements IntegrationInterface
12
{
13
    public function should_init(): bool
×
14
    {
15
        return \class_exists(CoAuthors_Plus::class);
×
16
    }
17

18
    /**
19
     * @codeCoverageIgnore
20
     */
21
    public function init(): void
22
    {
23
        \add_filter('timber/post/authors', [$this, 'authors'], 10, 2);
24

25
        \add_filter('timber/user/class', fn ($class, WP_User $user) => CoAuthorsPlusUser::class, 10, 2);
26
    }
27

28
    /**
29
     * Filters {{ post.authors }} to return authors stored from Co-Authors Plus
30
     * @since 1.1.4
31
     * @param array $author
32
     * @param Post $post
33
     * @return array of User objects
34
     */
35
    public function authors($author, $post)
5✔
36
    {
37
        $authors = [];
5✔
38
        $cauthors = \get_coauthors($post->ID);
5✔
39
        foreach ($cauthors as $author) {
5✔
40
            $uid = $this->get_user_uid($author);
5✔
41
            if ($uid) {
5✔
42
                $authors[] = Timber::get_user($uid);
3✔
43
            } else {
44
                $wp_user = new WP_User($author);
4✔
45
                $user = Timber::get_user($wp_user);
4✔
46
                $user->import($wp_user->data);
4✔
47
                unset($user->user_pass);
4✔
48
                $user->id = $user->ID = (int) $wp_user->ID;
4✔
49
                $authors[] = $user;
4✔
50
            }
51
        }
52
        return $authors;
5✔
53
    }
54

55
    /**
56
     * return the user id for normal authors
57
     * the user login for guest authors if it exists and self::prefer_users == true
58
     * or null
59
     * @internal
60
     * @param object $cauthor
61
     * @return int|null
62
     */
63
    protected function get_user_uid($cauthor)
5✔
64
    {
65
        // if is guest author
66
        if (\is_object($cauthor) && isset($cauthor->type) && $cauthor->type == 'guest-author') {
5✔
67
            // if have have a linked user account
68
            global $coauthors_plus;
69
            if (!$coauthors_plus->force_guest_authors && isset($cauthor->linked_account) && !empty($cauthor->linked_account)) {
4✔
70
                $wp_user = \get_user_by('slug', $cauthor->linked_account);
1✔
71
                return $wp_user->ID;
1✔
72
            } else {
73
                return null;
4✔
74
            }
75
        } else {
76
            return $cauthor->ID;
2✔
77
        }
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc