PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | admin/taxonomy/class-taxonomy-columns.php +51 -73 18.0 → trunk View file →
@@ -4,8 +4,11 @@
4 4 *
5 5 * @package WPSEO\Admin
6 6 */
7 7
8 +use Yoast\WP\SEO\Helpers\Score_Icon_Helper;
9 +use Yoast\WP\SEO\Repositories\Indexable_Repository;
10 +
8 11 /**
9 12 * This class adds columns to the taxonomy table.
10 13 */
11 14 class WPSEO_Taxonomy_Columns {
@@ -31,8 +34,22 @@
31 34 */
32 35 private $taxonomy;
33 36
34 37 /**
38 + * Holds the Indexable_Repository.
39 + *
40 + * @var Indexable_Repository
41 + */
42 + protected $indexable_repository;
43 +
44 + /**
45 + * Holds the Score_Icon_Helper.
46 + *
47 + * @var Score_Icon_Helper
48 + */
49 + protected $score_icon_helper;
50 +
51 + /**
35 52 * WPSEO_Taxonomy_Columns constructor.
36 53 */
37 54 public function __construct() {
38 55
@@ -44,8 +61,10 @@
44 61 }
45 62
46 63 $this->analysis_seo = new WPSEO_Metabox_Analysis_SEO();
47 64 $this->analysis_readability = new WPSEO_Metabox_Analysis_Readability();
65 + $this->indexable_repository = YoastSEO()->classes->get( Indexable_Repository::class );
66 + $this->score_icon_helper = YoastSEO()->helpers->score_icon;
48 67 }
49 68
50 69 /**
51 70 * Adds an SEO score column to the terms table, right after the description column.
@@ -64,13 +83,15 @@
64 83 foreach ( $columns as $column_name => $column_value ) {
65 84 $new_columns[ $column_name ] = $column_value;
66 85
67 86 if ( $column_name === 'description' && $this->analysis_seo->is_enabled() ) {
68 - $new_columns['wpseo-score'] = '<span class="yoast-tooltip yoast-tooltip-n yoast-tooltip-alt" data-label="' . esc_attr__( 'SEO score', 'wordpress-seo' ) . '"><span class="yoast-column-seo-score yoast-column-header-has-tooltip"><span class="screen-reader-text">' . __( 'SEO score', 'wordpress-seo' ) . '</span></span></span>';
87 + $new_columns['wpseo-score'] = '<span class="yoast-tooltip yoast-tooltip-n yoast-tooltip-alt" data-label="' . esc_attr__( 'SEO score', 'wordpress-seo' ) . '"><span class="yoast-column-seo-score yoast-column-header-has-tooltip"><span class="screen-reader-text">'
88 + . __( 'SEO score', 'wordpress-seo' ) . '</span></span></span>';
69 89 }
70 90
71 91 if ( $column_name === 'description' && $this->analysis_readability->is_enabled() ) {
72 - $new_columns['wpseo-score-readability'] = '<span class="yoast-tooltip yoast-tooltip-n yoast-tooltip-alt" data-label="' . esc_attr__( 'Readability score', 'wordpress-seo' ) . '"><span class="yoast-column-readability yoast-column-header-has-tooltip"><span class="screen-reader-text">' . __( 'Readability score', 'wordpress-seo' ) . '</span></span></span>';
92 + $new_columns['wpseo-score-readability'] = '<span class="yoast-tooltip yoast-tooltip-n yoast-tooltip-alt" data-label="' . esc_attr__( 'Readability score', 'wordpress-seo' ) . '"><span class="yoast-column-readability yoast-column-header-has-tooltip"><span class="screen-reader-text">'
93 + . __( 'Readability score', 'wordpress-seo' ) . '</span></span></span>';
73 94 }
74 95 }
75 96
76 97 return $new_columns;
@@ -98,14 +119,24 @@
98 119 return $content;
99 120 }
100 121
101 122 /**
102 - * Retrieves the taxonomy from the $_GET variable.
123 + * Retrieves the taxonomy from the $_GET or $_POST variable.
103 124 *
104 - * @return string The current taxonomy.
125 + * @return string|null The current taxonomy or null when it is not set.
105 126 */
106 127 public function get_current_taxonomy() {
107 - return filter_input( $this->get_taxonomy_input_type(), 'taxonomy' );
128 + // phpcs:disable WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
129 + if ( ! empty( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' ) {
130 + if ( isset( $_POST['taxonomy'] ) && is_string( $_POST['taxonomy'] ) ) {
131 + return sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) );
132 + }
133 + }
134 + elseif ( isset( $_GET['taxonomy'] ) && is_string( $_GET['taxonomy'] ) ) {
135 + return sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) );
136 + }
137 + // phpcs:enable WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended
138 + return null;
108 139 }
109 140
110 141 /**
111 142 * Returns the posted/get taxonomy value if it is set.
@@ -112,13 +143,19 @@
112 143 *
113 144 * @return string|null
114 145 */
115 146 private function get_taxonomy() {
147 + // phpcs:disable WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
116 148 if ( wp_doing_ajax() ) {
117 - return FILTER_INPUT( INPUT_POST, 'taxonomy' );
149 + if ( isset( $_POST['taxonomy'] ) && is_string( $_POST['taxonomy'] ) ) {
150 + return sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) );
151 + }
118 152 }
119 -
120 - return FILTER_INPUT( INPUT_GET, 'taxonomy' );
153 + elseif ( isset( $_GET['taxonomy'] ) && is_string( $_GET['taxonomy'] ) ) {
154 + return sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) );
155 + }
156 + // phpcs:enable WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended
157 + return null;
121 158 }
122 159
123 160 /**
124 161 * Parses the value for the score column.
@@ -127,24 +164,11 @@
127 164 *
128 165 * @return string
129 166 */
130 167 private function get_score_value( $term_id ) {
131 - $term = get_term( $term_id, $this->taxonomy );
168 + $indexable = $this->indexable_repository->find_by_id_and_type( (int) $term_id, 'term' );
132 169
133 - // When the term isn't indexable.
134 - if ( ! $this->is_indexable( $term ) ) {
135 - return $this->create_score_icon(
136 - new WPSEO_Rank( WPSEO_Rank::NO_INDEX ),
137 - __( 'Term is set to noindex.', 'wordpress-seo' )
138 - );
139 - }
140 -
141 - // When there is a focus key word.
142 - $focus_keyword = $this->get_focus_keyword( $term );
143 - $score = (int) WPSEO_Taxonomy_Meta::get_term_meta( $term_id, $this->taxonomy, 'linkdex' );
144 - $rank = WPSEO_Rank::from_numeric_score( $score );
145 -
146 - return $this->create_score_icon( $rank, $rank->get_label() );
170 + return $this->score_icon_helper->for_seo( $indexable, '', __( 'Term is set to noindex.', 'wordpress-seo' ) );
147 171 }
148 172
149 173 /**
150 174 * Parses the value for the readability score column.
@@ -154,35 +178,18 @@
154 178 * @return string The HTML for the readability score indicator.
155 179 */
156 180 private function get_score_readability_value( $term_id ) {
157 181 $score = (int) WPSEO_Taxonomy_Meta::get_term_meta( $term_id, $this->taxonomy, 'content_score' );
158 - $rank = WPSEO_Rank::from_numeric_score( $score );
159 182
160 - return $this->create_score_icon( $rank );
183 + return $this->score_icon_helper->for_readability( $score );
161 184 }
162 185
163 186 /**
164 - * Creates an icon by the given values.
165 - *
166 - * @param WPSEO_Rank $rank The ranking object.
167 - * @param string $title Optional. The title to show. Defaults to the rank label.
168 - *
169 - * @return string The HTML for a score icon.
170 - */
171 - private function create_score_icon( WPSEO_Rank $rank, $title = '' ) {
172 - if ( empty( $title ) ) {
173 - $title = $rank->get_label();
174 - }
175 -
176 - return '<div aria-hidden="true" title="' . esc_attr( $title ) . '" class="wpseo-score-icon ' . esc_attr( $rank->get_css_class() ) . '"></div><span class="screen-reader-text wpseo-score-text">' . $title . '</span>';
177 - }
178 -
179 - /**
180 187 * Check if the taxonomy is indexable.
181 188 *
182 189 * @param mixed $term The current term.
183 190 *
184 - * @return bool Whether or not the term is indexable.
191 + * @return bool Whether the term is indexable.
185 192 */
186 193 private function is_indexable( $term ) {
187 194 // When the no_index value is not empty and not default, check if its value is index.
188 195 $no_index = WPSEO_Taxonomy_Meta::get_term_meta( $term->term_id, $this->taxonomy, 'noindex' );
@@ -202,37 +209,8 @@
202 209 return true;
203 210 }
204 211
205 212 /**
206 - * Returns the focus keyword if this is set, otherwise it will give the term name.
207 - *
208 - * @param stdClass|WP_Term $term The current term.
209 - *
210 - * @return string
211 - */
212 - private function get_focus_keyword( $term ) {
213 - $focus_keyword = WPSEO_Taxonomy_Meta::get_term_meta( 'focuskw', $term->term_id, $term->taxonomy );
214 - if ( $focus_keyword !== false ) {
215 - return $focus_keyword;
216 - }
217 -
218 - return $term->name;
219 - }
220 -
221 - /**
222 - * Checks if a taxonomy is being added via a POST method. If not, it defaults to a GET request.
223 - *
224 - * @return int
225 - */
226 - private function get_taxonomy_input_type() {
227 - if ( ! empty( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' ) {
228 - return INPUT_POST;
229 - }
230 -
231 - return INPUT_GET;
232 - }
233 -
234 - /**
235 213 * Wraps the WPSEO_Metabox check to determine whether the metabox should be displayed either by
236 214 * choice of the admin or because the taxonomy is not public.
237 215 *
238 216 * @since 7.0
@@ -238,12 +216,12 @@
238 216 * @since 7.0
239 217 *
240 218 * @param string|null $taxonomy Optional. The taxonomy to test, defaults to the current taxonomy.
241 219 *
242 - * @return bool Whether or not the meta box (and associated columns etc) should be hidden.
220 + * @return bool Whether the meta box (and associated columns etc) should be hidden.
243 221 */
244 222 private function display_metabox( $taxonomy = null ) {
245 - $current_taxonomy = sanitize_text_field( $this->get_current_taxonomy() );
223 + $current_taxonomy = $this->get_current_taxonomy();
246 224
247 225 if ( ! isset( $taxonomy ) && ! empty( $current_taxonomy ) ) {
248 226 $taxonomy = $current_taxonomy;
249 227 }