plugin updates

This commit is contained in:
Tony Volpe
2024-11-20 22:40:39 -05:00
parent 0238f0c4ca
commit 3362947c6e
434 changed files with 13405 additions and 9202 deletions

View File

@@ -212,10 +212,13 @@ class WPSEO_Options {
/**
* Retrieve all the options for the SEO plugin in one go.
*
* @param array<string> $specific_options The option groups of the option you want to get.
*
* @return array Array combining the values of all the options.
*/
public static function get_all() {
static::$option_values = static::get_options( static::get_option_names() );
public static function get_all( $specific_options = [] ) {
$option_names = ( empty( $specific_options ) ) ? static::get_option_names() : $specific_options;
static::$option_values = static::get_options( $option_names );
return static::$option_values;
}
@@ -269,14 +272,15 @@ class WPSEO_Options {
/**
* Retrieve a single field from any option for the SEO plugin. Keys are always unique.
*
* @param string $key The key it should return.
* @param mixed $default_value The default value that should be returned if the key isn't set.
* @param string $key The key it should return.
* @param mixed $default_value The default value that should be returned if the key isn't set.
* @param array<string> $option_groups The option groups to retrieve the option from.
*
* @return mixed Returns value if found, $default_value if not.
*/
public static function get( $key, $default_value = null ) {
if ( static::$option_values === null ) {
static::prime_cache();
public static function get( $key, $default_value = null, $option_groups = [] ) {
if ( ! isset( static::$option_values[ $key ] ) ) {
static::prime_cache( $option_groups );
}
if ( isset( static::$option_values[ $key ] ) ) {
return static::$option_values[ $key ];
@@ -297,23 +301,26 @@ class WPSEO_Options {
/**
* Primes our cache.
*
* @param array<string> $option_groups The option groups to prime the cache with.
*
* @return void
*/
private static function prime_cache() {
static::$option_values = static::get_all();
private static function prime_cache( $option_groups = [] ) {
static::$option_values = static::get_all( $option_groups );
static::$option_values = static::add_ms_option( static::$option_values );
}
/**
* Retrieve a single field from an option for the SEO plugin.
*
* @param string $key The key to set.
* @param mixed $value The value to set.
* @param string $key The key to set.
* @param mixed $value The value to set.
* @param string $option_group The lookup table which represents the option_group where the key is stored.
*
* @return mixed|null Returns value if found, $default if not.
*/
public static function set( $key, $value ) {
$lookup_table = static::get_lookup_table();
public static function set( $key, $value, $option_group = '' ) {
$lookup_table = static::get_lookup_table( $option_group );
if ( isset( $lookup_table[ $key ] ) ) {
return static::save_option( $lookup_table[ $key ], $key, $value );
@@ -562,12 +569,15 @@ class WPSEO_Options {
/**
* Retrieves a lookup table to find in which option_group a key is stored.
*
* @param string $option_group The option_group where the key is stored.
*
* @return array The lookup table.
*/
private static function get_lookup_table() {
$lookup_table = [];
private static function get_lookup_table( $option_group = '' ) {
$lookup_table = [];
$option_groups = ( $option_group === '' ) ? static::$options : [ $option_group => static::$options[ $option_group ] ];
foreach ( array_keys( static::$options ) as $option_name ) {
foreach ( array_keys( $option_groups ) as $option_name ) {
$full_option = static::get_option( $option_name );
foreach ( $full_option as $key => $value ) {
$lookup_table[ $key ] = $option_name;