| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * The option values. |
| 17 | 17 | * |
| 18 | - * @var null | |
| 18 | + * @var array|null | |
| 19 | 19 | */ |
| 20 | 20 | protected static $option_values = null; |
| 21 | 21 | |
| 22 | 22 | /** |
| @@ -29,8 +29,10 @@ | ||
| 29 | 29 | 'wpseo_titles' => 'WPSEO_Option_Titles', |
| 30 | 30 | 'wpseo_social' => 'WPSEO_Option_Social', |
| 31 | 31 | 'wpseo_ms' => 'WPSEO_Option_MS', |
| 32 | 32 | 'wpseo_taxonomy_meta' => 'WPSEO_Taxonomy_Meta', |
| 33 | + 'wpseo_llmstxt' => 'WPSEO_Option_Llmstxt', | |
| 34 | + 'wpseo_tracking_only' => 'WPSEO_Option_Tracking_Only', | |
| 33 | 35 | ]; |
| 34 | 36 | |
| 35 | 37 | /** |
| 36 | 38 | * Array of instantiated option objects. |
| @@ -58,9 +60,9 @@ | ||
| 58 | 60 | */ |
| 59 | 61 | protected function __construct() { |
| 60 | 62 | $this->register_hooks(); |
| 61 | 63 | |
| 62 | - foreach ( static::$options as $option_name => $option_class ) { | |
| 64 | + foreach ( static::$options as $option_class ) { | |
| 63 | 65 | static::register_option( call_user_func( [ $option_class, 'get_instance' ] ) ); |
| 64 | 66 | } |
| 65 | 67 | } |
| 66 | 68 | |
| @@ -65,8 +67,10 @@ | ||
| 65 | 67 | } |
| 66 | 68 | |
| 67 | 69 | /** |
| 68 | 70 | * Register our hooks. |
| 71 | + * | |
| 72 | + * @return void | |
| 69 | 73 | */ |
| 70 | 74 | public function register_hooks() { |
| 71 | 75 | add_action( 'registered_taxonomy', [ $this, 'clear_cache' ] ); |
| 72 | 76 | add_action( 'unregistered_taxonomy', [ $this, 'clear_cache' ] ); |
| @@ -90,8 +94,10 @@ | ||
| 90 | 94 | /** |
| 91 | 95 | * Registers an option to the options list. |
| 92 | 96 | * |
| 93 | 97 | * @param WPSEO_Option $option_instance Instance of the option. |
| 98 | + * | |
| 99 | + * @return void | |
| 94 | 100 | */ |
| 95 | 101 | public static function register_option( WPSEO_Option $option_instance ) { |
| 96 | 102 | $option_name = $option_instance->get_option_name(); |
| 97 | 103 | |
| @@ -199,9 +205,9 @@ | ||
| 199 | 205 | |
| 200 | 206 | /** |
| 201 | 207 | * Filter: wpseo_options - Allow developers to change the option name to include. |
| 202 | 208 | * |
| 203 | - * @api array The option names to include in get_all and reset(). | |
| 209 | + * @param array $option_names The option names to include in get_all and reset(). | |
| 204 | 210 | */ |
| 205 | 211 | return apply_filters( 'wpseo_options', $option_names ); |
| 206 | 212 | } |
| 207 | 213 | |
| @@ -207,12 +213,15 @@ | ||
| 207 | 213 | |
| 208 | 214 | /** |
| 209 | 215 | * Retrieve all the options for the SEO plugin in one go. |
| 210 | 216 | * |
| 217 | + * @param array<string> $specific_options The option groups of the option you want to get. | |
| 218 | + * | |
| 211 | 219 | * @return array Array combining the values of all the options. |
| 212 | 220 | */ |
| 213 | - public static function get_all() { | |
| 214 | - static::$option_values = static::get_options( static::get_option_names() ); | |
| 221 | + public static function get_all( $specific_options = [] ) { | |
| 222 | + $option_names = ( empty( $specific_options ) ) ? static::get_option_names() : $specific_options; | |
| 223 | + static::$option_values = static::get_options( $option_names ); | |
| 215 | 224 | |
| 216 | 225 | return static::$option_values; |
| 217 | 226 | } |
| 218 | 227 | |
| @@ -264,16 +273,17 @@ | ||
| 264 | 273 | |
| 265 | 274 | /** |
| 266 | 275 | * Retrieve a single field from any option for the SEO plugin. Keys are always unique. |
| 267 | 276 | * |
| 268 | - * @param string $key The key it should return. | |
| 269 | - * @param mixed $default_value The default value that should be returned if the key isn't set. | |
| 277 | + * @param string $key The key it should return. | |
| 278 | + * @param mixed $default_value The default value that should be returned if the key isn't set. | |
| 279 | + * @param array<string> $option_groups The option groups to retrieve the option from. | |
| 270 | 280 | * |
| 271 | 281 | * @return mixed Returns value if found, $default_value if not. |
| 272 | 282 | */ |
| 273 | - public static function get( $key, $default_value = null ) { | |
| 274 | - if ( static::$option_values === null ) { | |
| 275 | - static::prime_cache(); | |
| 283 | + public static function get( $key, $default_value = null, $option_groups = [] ) { | |
| 284 | + if ( ! isset( static::$option_values[ $key ] ) ) { | |
| 285 | + static::prime_cache( $option_groups ); | |
| 276 | 286 | } |
| 277 | 287 | if ( isset( static::$option_values[ $key ] ) ) { |
| 278 | 288 | return static::$option_values[ $key ]; |
| 279 | 289 | } |
| @@ -282,8 +292,10 @@ | ||
| 282 | 292 | } |
| 283 | 293 | |
| 284 | 294 | /** |
| 285 | 295 | * Resets the cache to null. |
| 296 | + * | |
| 297 | + * @return void | |
| 286 | 298 | */ |
| 287 | 299 | public static function clear_cache() { |
| 288 | 300 | static::$option_values = null; |
| 289 | 301 | } |
| @@ -289,11 +301,15 @@ | ||
| 289 | 301 | } |
| 290 | 302 | |
| 291 | 303 | /** |
| 292 | 304 | * Primes our cache. |
| 305 | + * | |
| 306 | + * @param array<string> $option_groups The option groups to prime the cache with. | |
| 307 | + * | |
| 308 | + * @return void | |
| 293 | 309 | */ |
| 294 | - private static function prime_cache() { | |
| 295 | - static::$option_values = static::get_all(); | |
| 310 | + private static function prime_cache( $option_groups = [] ) { | |
| 311 | + static::$option_values = static::get_all( $option_groups ); | |
| 296 | 312 | static::$option_values = static::add_ms_option( static::$option_values ); |
| 297 | 313 | } |
| 298 | 314 | |
| 299 | 315 | /** |
| @@ -298,15 +314,16 @@ | ||
| 298 | 314 | |
| 299 | 315 | /** |
| 300 | 316 | * Retrieve a single field from an option for the SEO plugin. |
| 301 | 317 | * |
| 302 | - * @param string $key The key to set. | |
| 303 | - * @param mixed $value The value to set. | |
| 318 | + * @param string $key The key to set. | |
| 319 | + * @param mixed $value The value to set. | |
| 320 | + * @param string $option_group The lookup table which represents the option_group where the key is stored. | |
| 304 | 321 | * |
| 305 | 322 | * @return mixed|null Returns value if found, $default if not. |
| 306 | 323 | */ |
| 307 | - public static function set( $key, $value ) { | |
| 308 | - $lookup_table = static::get_lookup_table(); | |
| 324 | + public static function set( $key, $value, $option_group = '' ) { | |
| 325 | + $lookup_table = static::get_lookup_table( $option_group ); | |
| 309 | 326 | |
| 310 | 327 | if ( isset( $lookup_table[ $key ] ) ) { |
| 311 | 328 | return static::save_option( $lookup_table[ $key ], $key, $value ); |
| 312 | 329 | } |
| @@ -543,11 +560,9 @@ | ||
| 543 | 560 | */ |
| 544 | 561 | protected static function is_multisite() { |
| 545 | 562 | static $is_multisite; |
| 546 | 563 | |
| 547 | - if ( $is_multisite === null ) { | |
| 548 | - $is_multisite = is_multisite(); | |
| 549 | - } | |
| 564 | + $is_multisite ??= is_multisite(); | |
| 550 | 565 | |
| 551 | 566 | return $is_multisite; |
| 552 | 567 | } |
| 553 | 568 | |
| @@ -553,15 +568,17 @@ | ||
| 553 | 568 | |
| 554 | 569 | /** |
| 555 | 570 | * Retrieves a lookup table to find in which option_group a key is stored. |
| 556 | 571 | * |
| 572 | + * @param string $option_group The option_group where the key is stored. | |
| 573 | + * | |
| 557 | 574 | * @return array The lookup table. |
| 558 | 575 | */ |
| 559 | - private static function get_lookup_table() { | |
| 560 | - $lookup_table = []; | |
| 576 | + private static function get_lookup_table( $option_group = '' ) { | |
| 577 | + $lookup_table = []; | |
| 578 | + $option_groups = ( $option_group === '' ) ? static::$options : [ $option_group => static::$options[ $option_group ] ]; | |
| 561 | 579 | |
| 562 | - | |
| 563 | - foreach ( array_keys( static::$options ) as $option_name ) { | |
| 580 | + foreach ( array_keys( $option_groups ) as $option_name ) { | |
| 564 | 581 | $full_option = static::get_option( $option_name ); |
| 565 | 582 | foreach ( $full_option as $key => $value ) { |
| 566 | 583 | $lookup_table[ $key ] = $option_name; |
| 567 | 584 | } |