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

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

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

85.19
/src/presenters/admin/badge-presenter.php
1
<?php
2

3
namespace Yoast\WP\SEO\Presenters\Admin;
4

5
use Yoast\WP\SEO\Config\Badge_Group_Names;
6
use Yoast\WP\SEO\Presenters\Abstract_Presenter;
7

8
/**
9
 * Represents the presenter class for "New" badges.
10
 */
11
class Badge_Presenter extends Abstract_Presenter {
12

13
        /**
14
         * Identifier of the badge.
15
         *
16
         * @var string
17
         */
18
        private $id;
19

20
        /**
21
         * Optional link of the badge.
22
         *
23
         * @var string
24
         */
25
        private $link;
26

27
        /**
28
         * Optional group which the badge belongs to.
29
         *
30
         * Each group has a fixed period after which the group will no longer be considered new and the badges will disappear.
31
         *
32
         * @var string
33
         */
34
        private $group;
35

36
        /**
37
         * Optional object storing the group names and expiration versions.
38
         *
39
         * The group names set in Yoast SEO are used by default, but they can be overridden to use custom ones for an add-on.
40
         *
41
         * @var Badge_Group_Names
42
         */
43
        private $badge_group_names;
44

45
        /**
46
         * Badge_Presenter constructor.
47
         *
48
         * @param string                 $id                Id of the badge.
49
         * @param string                 $link              Optional link of the badge.
50
         * @param string                 $group             Optional group which the badge belongs to.
51
         * @param Badge_Group_Names|null $badge_group_names Optional object storing the group names.
52
         */
53
        public function __construct( $id, $link = '', $group = '', $badge_group_names = null ) {
4✔
54
                $this->id    = $id;
4✔
55
                $this->link  = $link;
4✔
56
                $this->group = $group;
4✔
57

58
                if ( ! $badge_group_names instanceof Badge_Group_Names ) {
4✔
59
                        $badge_group_names = new Badge_Group_Names();
4✔
60
                }
61
                $this->badge_group_names = $badge_group_names;
4✔
62
        }
2✔
63

64
        /**
65
         * Presents the New Badge. If a link has been passed, the badge is presented with the link.
66
         * Otherwise a static badge is presented.
67
         *
68
         * @return string The styled New Badge.
69
         */
70
        public function present() {
6✔
71
                if ( ! $this->is_group_still_new() ) {
6✔
72
                        return '';
2✔
73
                }
74

75
                if ( $this->link !== '' ) {
4✔
76
                        return \sprintf(
2✔
77
                                '<a class="yoast-badge yoast-badge__is-link yoast-new-badge" id="%1$s-new-badge" href="%2$s">%3$s</a>',
2✔
78
                                \esc_attr( $this->id ),
2✔
79
                                \esc_url( $this->link ),
2✔
80
                                \esc_html__( 'New', 'wordpress-seo' )
2✔
81
                        );
1✔
82
                }
83

84
                return \sprintf(
2✔
85
                        '<span class="yoast-badge yoast-new-badge" id="%1$s-new-badge">%2$s</span>',
2✔
86
                        \esc_attr( $this->id ),
2✔
87
                        \esc_html__( 'New', 'wordpress-seo' )
2✔
88
                );
1✔
89
        }
90

91
        /**
92
         * Check whether the new badge should be shown according to the group it is in.
93
         *
94
         * @return bool True if still new.
95
         */
96
        public function is_group_still_new() {
×
97
                // If there's no group configured, the new badge is always active.
98
                if ( ! $this->group ) {
×
99
                        return true;
×
100
                }
101

102
                return $this->badge_group_names->is_still_eligible_for_new_badge( $this->group );
×
103
        }
104
}
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