| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | * Prefix of the transient key for sitemap caches. |
| 17 | 17 | * |
| 18 | 18 | * @var string |
| 19 | 19 | */ |
| 20 | - const STORAGE_KEY_PREFIX = 'yst_sm_'; | |
| 20 | + public const STORAGE_KEY_PREFIX = 'yst_sm_'; | |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Name of the option that holds the global validation value. |
| 24 | 24 | * |
| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | * Name of the option that holds the global validation value. |
| 24 | 24 | * |
| 25 | 25 | * @var string |
| 26 | 26 | */ |
| 27 | - const VALIDATION_GLOBAL_KEY = 'wpseo_sitemap_cache_validator_global'; | |
| 27 | + public const VALIDATION_GLOBAL_KEY = 'wpseo_sitemap_cache_validator_global'; | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The format which creates the key of the option that holds the type validation value. |
| 31 | 31 | * |
| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | * The format which creates the key of the option that holds the type validation value. |
| 31 | 31 | * |
| 32 | 32 | * @var string |
| 33 | 33 | */ |
| 34 | - const VALIDATION_TYPE_KEY_FORMAT = 'wpseo_sitemap_%s_cache_validator'; | |
| 34 | + public const VALIDATION_TYPE_KEY_FORMAT = 'wpseo_sitemap_%s_cache_validator'; | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Get the cache key for a certain type and page. |
| 38 | 38 | * |
| @@ -49,9 +49,9 @@ | ||
| 49 | 49 | */ |
| 50 | 50 | public static function get_storage_key( $type = null, $page = 1 ) { |
| 51 | 51 | |
| 52 | 52 | // Using SITEMAP_INDEX_TYPE for sitemap index cache. |
| 53 | - $type = is_null( $type ) ? WPSEO_Sitemaps::SITEMAP_INDEX_TYPE : $type; | |
| 53 | + $type = ( $type === null ) ? WPSEO_Sitemaps::SITEMAP_INDEX_TYPE : $type; | |
| 54 | 54 | |
| 55 | 55 | $global_cache_validator = self::get_validator(); |
| 56 | 56 | $type_cache_validator = self::get_validator( $type ); |
| 57 | 57 | |
| @@ -109,10 +109,10 @@ | ||
| 109 | 109 | */ |
| 110 | 110 | throw new OutOfRangeException( |
| 111 | 111 | __( |
| 112 | 112 | 'Trying to build the sitemap cache key, but the postfix and prefix combination leaves too little room to do this. You are probably requesting a page that is way out of the expected range.', |
| 113 | - 'wordpress-seo' | |
| 114 | - ) | |
| 113 | + 'wordpress-seo', | |
| 114 | + ), | |
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | $half = ( $max_length / 2 ); |
| @@ -140,9 +140,9 @@ | ||
| 140 | 140 | // Global validator gets cleared when no type is provided. |
| 141 | 141 | $old_validator = null; |
| 142 | 142 | |
| 143 | 143 | // Get the current type validator. |
| 144 | - if ( ! is_null( $type ) ) { | |
| 144 | + if ( $type !== null ) { | |
| 145 | 145 | $old_validator = self::get_validator( $type ); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Refresh validator. |
| @@ -169,9 +169,9 @@ | ||
| 169 | 169 | public static function cleanup_database( $type = null, $validator = null ) { |
| 170 | 170 | |
| 171 | 171 | global $wpdb; |
| 172 | 172 | |
| 173 | - if ( is_null( $type ) ) { | |
| 173 | + if ( $type === null ) { | |
| 174 | 174 | // Clear all cache if no type is provided. |
| 175 | 175 | $like = sprintf( '%s%%', self::STORAGE_KEY_PREFIX ); |
| 176 | 176 | } |
| 177 | 177 | else { |
| @@ -188,10 +188,17 @@ | ||
| 188 | 188 | $where[] = sprintf( "option_name LIKE '%s'", addcslashes( '_transient_' . $like, '_' ) ); |
| 189 | 189 | $where[] = sprintf( "option_name LIKE '%s'", addcslashes( '_transient_timeout_' . $like, '_' ) ); |
| 190 | 190 | |
| 191 | 191 | // Delete transients. |
| 192 | - $query = sprintf( 'DELETE FROM %1$s WHERE %2$s', $wpdb->options, implode( ' OR ', $where ) ); | |
| 193 | - $wpdb->query( $query ); | |
| 192 | + //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to use a direct query here. | |
| 193 | + //phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches. | |
| 194 | + $wpdb->query( | |
| 195 | + $wpdb->prepare( | |
| 196 | + //phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized. | |
| 197 | + 'DELETE FROM %i WHERE ' . implode( ' OR ', array_fill( 0, count( $where ), '%s' ) ), | |
| 198 | + array_merge( [ $wpdb->options ], $where ), | |
| 199 | + ), | |
| 200 | + ); | |
| 194 | 201 | |
| 195 | 202 | wp_cache_delete( 'alloptions', 'options' ); |
| 196 | 203 | } |
| 197 | 204 | |
| @@ -213,9 +220,9 @@ | ||
| 213 | 220 | |
| 214 | 221 | $key = self::get_validator_key( $type ); |
| 215 | 222 | |
| 216 | 223 | $current = get_option( $key, null ); |
| 217 | - if ( ! is_null( $current ) ) { | |
| 224 | + if ( $current !== null ) { | |
| 218 | 225 | return $current; |
| 219 | 226 | } |
| 220 | 227 | |
| 221 | 228 | if ( self::create_validator( $type ) ) { |