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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

0.0
/admin/taxonomy/class-taxonomy-fields-presenter.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin
6
 */
7

8
/**
9
 * Class WPSEO_Taxonomy_Presenter.
10
 */
11
class WPSEO_Taxonomy_Fields_Presenter {
12

13
        /**
14
         * The taxonomy meta data for the current term.
15
         *
16
         * @var array
17
         */
18
        private $tax_meta;
19

20
        /**
21
         * Constructs the WPSEO_Taxonomy_Fields_Presenter class.
22
         *
23
         * @param stdClass $term The current term.
24
         */
25
        public function __construct( $term ) {
×
26
                $this->tax_meta = WPSEO_Taxonomy_Meta::get_term_meta( (int) $term->term_id, $term->taxonomy );
×
27
        }
28

29
        /**
30
         * Displaying the form fields.
31
         *
32
         * @param array $fields Array with the fields that will be displayed.
33
         *
34
         * @return string
35
         */
UNCOV
36
        public function html( array $fields ) {
×
UNCOV
37
                $content = '';
×
UNCOV
38
                foreach ( $fields as $field_name => $field_configuration ) {
×
UNCOV
39
                        $content .= $this->form_row( 'wpseo_' . $field_name, $field_configuration );
×
40
                }
UNCOV
41
                return $content;
×
42
        }
43

44
        /**
45
         * Create a row in the form table.
46
         *
47
         * @param string $field_name          Variable the row controls.
48
         * @param array  $field_configuration Array with the field configuration.
49
         *
50
         * @return string
51
         */
52
        private function form_row( $field_name, array $field_configuration ) {
×
53
                $esc_field_name = esc_attr( $field_name );
×
54

55
                $options = (array) $field_configuration['options'];
×
56

57
                if ( ! empty( $field_configuration['description'] ) ) {
×
58
                        $options['description'] = $field_configuration['description'];
×
59
                }
60

61
                $label            = $this->get_label( $field_configuration['label'], $esc_field_name );
×
62
                $field            = $this->get_field( $field_configuration['type'], $esc_field_name, $this->get_field_value( $field_name ), $options );
×
63
                $help_content     = ( $field_configuration['options']['help'] ?? '' );
×
64
                $help_button_text = ( $field_configuration['options']['help-button'] ?? '' );
×
65
                $help             = new WPSEO_Admin_Help_Panel( $field_name, $help_button_text, $help_content );
×
66

67
                return $this->parse_row( $label, $help, $field );
×
68
        }
69

70
        /**
71
         * Generates the html for the given field config.
72
         *
73
         * @param string $field_type  The fieldtype, e.g: text, checkbox, etc.
74
         * @param string $field_name  The name of the field.
75
         * @param string $field_value The value of the field.
76
         * @param array  $options     Array with additional options.
77
         *
78
         * @return string
79
         */
80
        private function get_field( $field_type, $field_name, $field_value, array $options ) {
×
81

82
                $class            = $this->get_class( $options );
×
83
                $field            = '';
×
84
                $description      = '';
×
85
                $aria_describedby = '';
×
86

87
                if ( ! empty( $options['description'] ) ) {
×
88
                        $aria_describedby = ' aria-describedby="' . $field_name . '-desc"';
×
89
                        $description      = '<p id="' . $field_name . '-desc" class="yoast-metabox__description">' . $options['description'] . '</p>';
×
90
                }
91

92
                switch ( $field_type ) {
93
                        case 'div':
×
94
                                $field .= '<div id="' . $field_name . '"></div>';
×
95
                                break;
×
96
                        case 'url':
×
97
                                $field .= '<input name="' . $field_name . '" id="' . $field_name . '" ' . $class . ' type="url" value="' . esc_attr( urldecode( $field_value ) ) . '" size="40"' . $aria_describedby . '/>';
×
98
                                break;
×
99
                        case 'text':
×
100
                                $field .= '<input name="' . $field_name . '" id="' . $field_name . '" ' . $class . ' type="text" value="' . esc_attr( $field_value ) . '" size="40"' . $aria_describedby . '/>';
×
101
                                break;
×
102
                        case 'checkbox':
×
103
                                $field .= '<input name="' . $field_name . '" id="' . $field_name . '" type="checkbox" ' . checked( $field_value ) . $aria_describedby . '/>';
×
104
                                break;
×
105
                        case 'textarea':
×
106
                                $rows = 3;
×
107
                                if ( ! empty( $options['rows'] ) ) {
×
108
                                        $rows = $options['rows'];
×
109
                                }
110
                                $field .= '<textarea class="large-text" rows="' . esc_attr( $rows ) . '" id="' . $field_name . '" name="' . $field_name . '"' . $aria_describedby . '>' . esc_textarea( $field_value ) . '</textarea>';
×
111
                                break;
×
112
                        case 'upload':
×
UNCOV
113
                                $field .= '<input'
×
114
                                        . ' id="' . $field_name . '"'
×
115
                                        . ' type="text"'
×
116
                                        . ' size="36"'
×
117
                                        . ' name="' . $field_name . '"'
×
118
                                        . ' value="' . esc_attr( $field_value ) . '"' . $aria_describedby . ''
×
119
                                        . ' readonly="readonly"'
×
120
                                        . ' /> ';
×
UNCOV
121
                                $field .= '<input'
×
122
                                        . ' id="' . esc_attr( $field_name ) . '_button"'
×
123
                                        . ' class="wpseo_image_upload_button button"'
×
124
                                        . ' data-target="' . esc_attr( $field_name ) . '"'
×
125
                                        . ' data-target-id="hidden_' . esc_attr( $field_name ) . '-id"'
×
126
                                        . ' type="button"'
×
127
                                        . ' value="' . esc_attr__( 'Upload Image', 'wordpress-seo' ) . '"'
×
128
                                        . ' /> ';
×
UNCOV
129
                                $field .= '<input'
×
130
                                        . ' id="' . esc_attr( $field_name ) . '_button"'
×
131
                                        . ' class="wpseo_image_remove_button button"'
×
132
                                        . ' type="button"'
×
133
                                        . ' value="' . esc_attr__( 'Clear Image', 'wordpress-seo' ) . '"'
×
134
                                        . ' />';
×
135
                                break;
×
136
                        case 'select':
×
137
                                if ( is_array( $options ) && $options !== [] ) {
×
138
                                        $field .= '<select name="' . $field_name . '" id="' . $field_name . '"' . $aria_describedby . '>';
×
139

140
                                        $select_options = ( array_key_exists( 'options', $options ) ) ? $options['options'] : $options;
×
141

142
                                        foreach ( $select_options as $option => $option_label ) {
×
143
                                                $selected = selected( $option, $field_value, false );
×
144
                                                $field   .= '<option ' . $selected . ' value="' . esc_attr( $option ) . '">' . esc_html( $option_label ) . '</option>';
×
145
                                        }
146
                                        unset( $option, $option_label, $selected );
×
147

148
                                        $field .= '</select>';
×
149
                                }
150
                                break;
×
151
                        case 'hidden':
×
152
                                $field .= '<input name="' . $field_name . '" id="hidden_' . $field_name . '" type="hidden" value="' . esc_attr( $field_value ) . '" />';
×
153
                                break;
×
154
                }
155

156
                return $field . $description;
×
157
        }
158

159
        /**
160
         * Getting the value for given field_name.
161
         *
162
         * @param string $field_name The fieldname to get the value for.
163
         *
164
         * @return string
165
         */
166
        private function get_field_value( $field_name ) {
×
167
                if ( isset( $this->tax_meta[ $field_name ] ) && $this->tax_meta[ $field_name ] !== '' ) {
×
168
                        return $this->tax_meta[ $field_name ];
×
169
                }
170

171
                return '';
×
172
        }
173

174
        /**
175
         * Getting the class attributes if $options contains a class key.
176
         *
177
         * @param array $options The array with field options.
178
         *
179
         * @return string
180
         */
181
        private function get_class( array $options ) {
×
182
                if ( ! empty( $options['class'] ) ) {
×
183
                        return ' class="' . esc_attr( $options['class'] ) . '"';
×
184
                }
185

186
                return '';
×
187
        }
188

189
        /**
190
         * Getting the label HTML.
191
         *
192
         * @param string $label      The label value.
193
         * @param string $field_name The target field.
194
         *
195
         * @return string
196
         */
197
        private function get_label( $label, $field_name ) {
×
198
                if ( $label !== '' ) {
×
199
                        return '<label for="' . $field_name . '">' . esc_html( $label ) . '</label>';
×
200
                }
201

202
                return '';
×
203
        }
204

205
        /**
206
         * Returns the HTML for the row which contains label, help and the field.
207
         *
208
         * @param string                 $label The html for the label if there was a label set.
209
         * @param WPSEO_Admin_Help_Panel $help  The help panel to render in this row.
210
         * @param string                 $field The html for the field.
211
         *
212
         * @return string
213
         */
214
        private function parse_row( $label, WPSEO_Admin_Help_Panel $help, $field ) {
×
215
                if ( $label !== '' || $help !== '' ) {
×
216
                        return $label . $help->get_button_html() . $help->get_panel_html() . $field;
×
217
                }
218

219
                return $field;
×
220
        }
221
}
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