• 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

0.0
/src/presenters/admin/light-switch-presenter.php
1
<?php
2

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

5
use Yoast\WP\SEO\Presenters\Abstract_Presenter;
6

7
/**
8
 * Class Light_Switch_Presenter.
9
 *
10
 * @package Yoast\WP\SEO\Presenters\Admin
11
 */
12
class Light_Switch_Presenter extends Abstract_Presenter {
13

14
        /**
15
         * The variable to create the checkbox for.
16
         *
17
         * @var string
18
         */
19
        protected $var;
20

21
        /**
22
         * The visual label text for the toggle.
23
         *
24
         * @var string
25
         */
26
        protected $label;
27

28
        /**
29
         * Array of two visual labels for the buttons.
30
         *
31
         * @var array
32
         */
33
        protected $buttons;
34

35
        /**
36
         * The name of the underlying checkbox.
37
         *
38
         * @var string
39
         */
40
        protected $name;
41

42
        /**
43
         * The variable current value.
44
         *
45
         * @var string|bool
46
         */
47
        protected $value;
48

49
        /**
50
         * Reverse order of buttons.
51
         *
52
         * @var bool
53
         */
54
        protected $reverse;
55

56
        /**
57
         * The inline Help HTML.
58
         *
59
         * @var string
60
         */
61
        protected $help;
62

63
        /**
64
         * Whether the visual label is displayed in strong text.
65
         *
66
         * @var bool
67
         */
68
        protected $strong;
69

70
        /**
71
         * The disabled attribute HTML.
72
         *
73
         * @var string
74
         */
75
        protected $disabled_attribute;
76

77
        /**
78
         * Light_Switch_Presenter constructor.
79
         *
80
         * @param string      $variable           The variable to create the checkbox for.
81
         * @param string      $label              The visual label text for the toggle.
82
         * @param array       $buttons            Array of two visual labels for the buttons (defaults Disabled/Enabled).
83
         * @param string      $name               The name of the underlying checkbox.
84
         * @param string|bool $value              The variable current value, to determine the checked attribute.
85
         * @param bool        $reverse            Optional. Reverse order of buttons (default true).
86
         * @param string      $help               Optional. Inline Help HTML that will be printed out before the toggle. Default is empty.
87
         * @param bool        $strong             Optional. Whether the visual label is displayed in strong text. Default is false.
88
         *                                        Starting from Yoast SEO 16.5, the visual label is forced to bold via CSS.
89
         * @param string      $disabled_attribute Optional. The disabled HTML attribute. Default is empty.
90
         */
91
        public function __construct(
×
92
                $variable,
93
                $label,
94
                $buttons,
95
                $name,
96
                $value,
97
                $reverse = true,
98
                $help = '',
99
                $strong = false,
100
                $disabled_attribute = ''
101
        ) {
102
                $this->var                = $variable;
×
103
                $this->label              = $label;
×
104
                $this->buttons            = $buttons;
×
105
                $this->name               = $name;
×
106
                $this->value              = $value;
×
107
                $this->reverse            = $reverse;
×
108
                $this->help               = $help;
×
109
                $this->strong             = $strong;
×
110
                $this->disabled_attribute = $disabled_attribute;
×
111
        }
112

113
        /**
114
         * Presents the light switch toggle.
115
         *
116
         * @return string The light switch's HTML.
117
         */
118
        public function present() {
×
119
                if ( empty( $this->buttons ) ) {
×
120
                        $this->buttons = [ \__( 'Disabled', 'wordpress-seo' ), \__( 'Enabled', 'wordpress-seo' ) ];
×
121
                }
122

123
                list( $off_button, $on_button ) = $this->buttons;
×
124

125
                $class = 'switch-light switch-candy switch-yoast-seo';
×
126

127
                if ( $this->reverse ) {
×
128
                        $class .= ' switch-yoast-seo-reverse';
×
129
                }
130

131
                $help_class   = ! empty( $this->help ) ? ' switch-container__has-help' : '';
×
132
                $strong_class = ( $this->strong ) ? ' switch-light-visual-label__strong' : '';
×
133

134
                $output  = '<div class="switch-container' . $help_class . '">';
×
135
                $output .= \sprintf(
×
136
                        '<span class="switch-light-visual-label%1$s" id="%2$s">%3$s</span>%4$s',
×
137
                        $strong_class, // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $strong_class output is hardcoded.
×
138
                        \esc_attr( $this->var . '-label' ),
×
139
                        \esc_html( $this->label ),
×
140
                        $this->help // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: The help contains HTML.
×
141
                );
×
142
                $output .= '<label class="' . $class . '"><b class="switch-yoast-seo-jaws-a11y">&nbsp;</b>';
×
143
                $output .= \sprintf(
×
144
                        '<input type="checkbox" aria-labelledby="%1$s" id="%2$s" name="%3$s" value="on"%4$s%5$s/>',
×
145
                        \esc_attr( $this->var . '-label' ),
×
146
                        \esc_attr( $this->var ),
×
147
                        \esc_attr( $this->name ),
×
148
                        \checked( $this->value, 'on', false ), // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: The output is hardcoded by WordPress.
×
149
                        $this->disabled_attribute // phpcs:ignore WordPress.Security.EscapeOutput -- Reason: $disabled_attribute output is hardcoded.
×
150
                );
×
151
                $output .= '<span aria-hidden="true">';
×
152
                $output .= '<span>' . \esc_html( $off_button ) . '</span>';
×
153
                $output .= '<span>' . \esc_html( $on_button ) . '</span>';
×
154
                $output .= '<a></a>';
×
155
                $output .= '</span></label><div class="clear"></div></div>';
×
156

157
                return $output;
×
158
        }
159
}
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

© 2025 Coveralls, Inc