PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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/class-primary-term-admin.php +15 -10 18.028.5 View file →
@@ -11,8 +11,10 @@
11 11 class WPSEO_Primary_Term_Admin implements WPSEO_WordPress_Integration {
12 12
13 13 /**
14 14 * Constructor.
15 + *
16 + * @return void
15 17 */
16 18 public function register_hooks() {
17 19 add_filter( 'wpseo_content_meta_section_content', [ $this, 'add_input_fields' ] );
18 20
@@ -26,11 +28,13 @@
26 28 *
27 29 * @return int The post ID.
28 30 */
29 31 protected function get_current_id() {
30 - $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
31 - if ( empty( $post_id ) && isset( $GLOBALS['post_ID'] ) ) {
32 - $post_id = filter_var( $GLOBALS['post_ID'], FILTER_SANITIZE_NUMBER_INT );
32 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are casting to an integer.
33 + $post_id = isset( $_GET['post'] ) && is_string( $_GET['post'] ) ? (int) wp_unslash( $_GET['post'] ) : 0;
34 +
35 + if ( $post_id === 0 && isset( $GLOBALS['post_ID'] ) ) {
36 + $post_id = (int) $GLOBALS['post_ID'];
33 37 }
34 38
35 39 return $post_id;
36 40 }
@@ -63,9 +67,9 @@
63 67 return sprintf(
64 68 '<input class="yoast-wpseo-primary-term" type="hidden" id="%1$s" name="%2$s" value="%3$s" />',
65 69 esc_attr( $this->generate_field_id( $taxonomy_name ) ),
66 70 esc_attr( $this->generate_field_name( $taxonomy_name ) ),
67 - esc_attr( $this->get_primary_term( $taxonomy_name ) )
71 + esc_attr( $this->get_primary_term( $taxonomy_name ) ),
68 72 );
69 73 }
70 74
71 75 /**
@@ -91,8 +95,10 @@
91 95 }
92 96
93 97 /**
94 98 * Adds primary term templates.
99 + *
100 + * @return void
95 101 */
96 102 public function wp_footer() {
97 103 $taxonomies = $this->get_primary_term_taxonomies();
98 104
@@ -152,11 +158,9 @@
152 158 * @param int|null $post_id Default current post ID.
153 159 * @return array
154 160 */
155 161 protected function get_primary_term_taxonomies( $post_id = null ) {
156 - if ( $post_id === null ) {
157 - $post_id = $this->get_current_id();
158 - }
162 + $post_id ??= $this->get_current_id();
159 163
160 164 $taxonomies = wp_cache_get( 'primary_term_taxonomies_' . $post_id, 'wpseo' );
161 165 if ( $taxonomies !== false ) {
162 166 return $taxonomies;
@@ -170,8 +174,10 @@
170 174 }
171 175
172 176 /**
173 177 * Includes templates file.
178 + *
179 + * @return void
174 180 */
175 181 protected function include_js_templates() {
176 182 include_once WPSEO_PATH . 'admin/views/js-templates-primary-term.php';
177 183 }
@@ -190,10 +196,9 @@
190 196
191 197 /**
192 198 * Filters which taxonomies for which the user can choose the primary term.
193 199 *
194 - * @api array $taxonomies An array of taxonomy objects that are primary_term enabled.
195 - *
200 + * @param array $taxonomies An array of taxonomy objects that are primary_term enabled.
196 201 * @param string $post_type The post type for which to filter the taxonomies.
197 202 * @param array $all_taxonomies All taxonomies for this post types, even ones that don't have primary term
198 203 * enabled.
199 204 */
@@ -231,9 +236,9 @@
231 236 [
232 237 'taxonomy' => $taxonomy->name,
233 238 'update_term_meta_cache' => false,
234 239 'fields' => 'id=>name',
235 - ]
240 + ],
236 241 );
237 242
238 243 $mapped_terms_for_js = [];
239 244 foreach ( $terms as $id => $name ) {