Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../inc/options
File: class-wpseo-option.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Internals\Options
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* This abstract class and its concrete classes implement defaults and value validation for
[8] Fix | Delete
* all WPSEO options and subkeys within options.
[9] Fix | Delete
*
[10] Fix | Delete
* Some guidelines:
[11] Fix | Delete
* [Retrieving options]
[12] Fix | Delete
* - Use the normal get_option() to retrieve an option. You will receive a complete array for the option.
[13] Fix | Delete
* Any subkeys which were not set, will have their default values in place.
[14] Fix | Delete
* - In other words, you will normally not have to check whether a subkey isset() as they will *always* be set.
[15] Fix | Delete
* They will also *always* be of the correct variable type.
[16] Fix | Delete
* The only exception to this are the options with variable option names based on post_type or taxonomy
[17] Fix | Delete
* as those will not always be available before the taxonomy/post_type is registered.
[18] Fix | Delete
* (they will be available if a value was set, they won't be if it wasn't as the class won't know
[19] Fix | Delete
* that a default needs to be injected).
[20] Fix | Delete
*
[21] Fix | Delete
* [Updating/Adding options]
[22] Fix | Delete
* - For multisite site_options, please use the WPSEO_Options::update_site_option() method.
[23] Fix | Delete
* - For normal options, use the normal add/update_option() functions. As long as the classes here
[24] Fix | Delete
* are instantiated, validation for all options and their subkeys will be automatic.
[25] Fix | Delete
* - On (successful) update of a couple of options, certain related actions will be run automatically.
[26] Fix | Delete
* Some examples:
[27] Fix | Delete
* - on change of wpseo[yoast_tracking], the cron schedule will be adjusted accordingly
[28] Fix | Delete
* - on change of wpseo and wpseo_title, some caches will be cleared
[29] Fix | Delete
*
[30] Fix | Delete
* [Important information about add/updating/changing these classes]
[31] Fix | Delete
* - Make sure that option array key names are unique across options. The WPSEO_Options::get_all()
[32] Fix | Delete
* method merges most options together. If any of them have non-unique names, even if they
[33] Fix | Delete
* are in a different option, they *will* overwrite each other.
[34] Fix | Delete
* - When you add a new array key in an option: make sure you add proper defaults and add the key
[35] Fix | Delete
* to the validation routine in the proper place or add a new validation case.
[36] Fix | Delete
* You don't need to do any upgrading as any option returned will always be merged with the
[37] Fix | Delete
* defaults, so new options will automatically be available.
[38] Fix | Delete
* If the default value is a string which need translating, add this to the concrete class
[39] Fix | Delete
* translate_defaults() method.
[40] Fix | Delete
* - When you remove an array key from an option: if it's important that the option is really removed,
[41] Fix | Delete
* add the WPSEO_Option::clean_up( $option_name ) method to the upgrade run.
[42] Fix | Delete
* This will re-save the option and automatically remove the array key no longer in existence.
[43] Fix | Delete
* - When you rename a sub-option: add it to the clean_option() routine and run that in the upgrade run.
[44] Fix | Delete
* - When you change the default for an option sub-key, make sure you verify that the validation routine will
[45] Fix | Delete
* still work the way it should.
[46] Fix | Delete
* Example: changing a default from '' (empty string) to 'text' with a validation routine with tests
[47] Fix | Delete
* for an empty string will prevent a user from saving an empty string as the real value. So the
[48] Fix | Delete
* test for '' with the validation routine would have to be removed in that case.
[49] Fix | Delete
* - If an option needs specific actions different from defined in this abstract class, you can just overrule
[50] Fix | Delete
* a method by defining it in the concrete class.
[51] Fix | Delete
*
[52] Fix | Delete
* @todo [JRF => testers] Double check that validation will not cause errors when called
[53] Fix | Delete
* from upgrade routine (some of the WP functions may not yet be available).
[54] Fix | Delete
*/
[55] Fix | Delete
abstract class WPSEO_Option {
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Prefix for override option keys that allow or disallow the option key of the same name.
[59] Fix | Delete
*
[60] Fix | Delete
* @var string
[61] Fix | Delete
*/
[62] Fix | Delete
public const ALLOW_KEY_PREFIX = 'allow_';
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Option name - MUST be set in concrete class and set to public.
[66] Fix | Delete
*
[67] Fix | Delete
* @var string
[68] Fix | Delete
*/
[69] Fix | Delete
protected $option_name;
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Option group name for use in settings forms.
[73] Fix | Delete
*
[74] Fix | Delete
* Will be set automagically if not set in concrete class (i.e.
[75] Fix | Delete
* if it conforms to the normal pattern 'yoast' . $option_name . 'options',
[76] Fix | Delete
* only set in concrete class if it doesn't).
[77] Fix | Delete
*
[78] Fix | Delete
* @var string
[79] Fix | Delete
*/
[80] Fix | Delete
public $group_name;
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Whether to include the option in the return for WPSEO_Options::get_all().
[84] Fix | Delete
*
[85] Fix | Delete
* Also determines which options are copied over for ms_(re)set_blog().
[86] Fix | Delete
*
[87] Fix | Delete
* @var bool
[88] Fix | Delete
*/
[89] Fix | Delete
public $include_in_all = true;
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Whether this option is only for when the install is multisite.
[93] Fix | Delete
*
[94] Fix | Delete
* @var bool
[95] Fix | Delete
*/
[96] Fix | Delete
public $multisite_only = false;
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Array of defaults for the option - MUST be set in concrete class.
[100] Fix | Delete
*
[101] Fix | Delete
* Shouldn't be requested directly, use $this->get_defaults();
[102] Fix | Delete
*
[103] Fix | Delete
* @var array
[104] Fix | Delete
*/
[105] Fix | Delete
protected $defaults;
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Array of variable option name patterns for the option - if any.
[109] Fix | Delete
*
[110] Fix | Delete
* Set this when the option contains array keys which vary based on post_type
[111] Fix | Delete
* or taxonomy.
[112] Fix | Delete
*
[113] Fix | Delete
* @var array
[114] Fix | Delete
*/
[115] Fix | Delete
protected $variable_array_key_patterns;
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Array of sub-options which should not be overloaded with multi-site defaults.
[119] Fix | Delete
*
[120] Fix | Delete
* @var array
[121] Fix | Delete
*/
[122] Fix | Delete
public $ms_exclude = [];
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Name for an option higher in the hierarchy to override setting access.
[126] Fix | Delete
*
[127] Fix | Delete
* @var string
[128] Fix | Delete
*/
[129] Fix | Delete
protected $override_option_name;
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Instance of this class.
[133] Fix | Delete
*
[134] Fix | Delete
* @var WPSEO_Option
[135] Fix | Delete
*/
[136] Fix | Delete
protected static $instance;
[137] Fix | Delete
[138] Fix | Delete
[139] Fix | Delete
/* *********** INSTANTIATION METHODS *********** */
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Add all the actions and filters for the option.
[143] Fix | Delete
*/
[144] Fix | Delete
protected function __construct() {
[145] Fix | Delete
[146] Fix | Delete
/* Add filters which get applied to the get_options() results. */
[147] Fix | Delete
$this->add_default_filters(); // Return defaults if option not set.
[148] Fix | Delete
$this->add_option_filters(); // Merge with defaults if option *is* set.
[149] Fix | Delete
[150] Fix | Delete
if ( $this->multisite_only !== true ) {
[151] Fix | Delete
/**
[152] Fix | Delete
* The option validation routines remove the default filters to prevent failing
[153] Fix | Delete
* to insert an option if it's new. Let's add them back afterwards.
[154] Fix | Delete
*/
[155] Fix | Delete
add_action( 'add_option', [ $this, 'add_default_filters_if_same_option' ] ); // Adding back after INSERT.
[156] Fix | Delete
[157] Fix | Delete
add_action( 'update_option', [ $this, 'add_default_filters_if_same_option' ] );
[158] Fix | Delete
[159] Fix | Delete
add_filter( 'pre_update_option', [ $this, 'add_default_filters_if_not_changed' ], PHP_INT_MAX, 3 );
[160] Fix | Delete
[161] Fix | Delete
// Refills the cache when the option has been updated.
[162] Fix | Delete
add_action( 'update_option_' . $this->option_name, [ 'WPSEO_Options', 'clear_cache' ], 10 );
[163] Fix | Delete
}
[164] Fix | Delete
elseif ( is_multisite() ) {
[165] Fix | Delete
/*
[166] Fix | Delete
* The option validation routines remove the default filters to prevent failing
[167] Fix | Delete
* to insert an option if it's new. Let's add them back afterwards.
[168] Fix | Delete
*
[169] Fix | Delete
* For site_options, this method is not foolproof as these actions are not fired
[170] Fix | Delete
* on an insert/update failure. Please use the WPSEO_Options::update_site_option() method
[171] Fix | Delete
* for updating site options to make sure the filters are in place.
[172] Fix | Delete
*/
[173] Fix | Delete
add_action( 'add_site_option_' . $this->option_name, [ $this, 'add_default_filters' ] );
[174] Fix | Delete
add_action( 'update_site_option_' . $this->option_name, [ $this, 'add_default_filters' ] );
[175] Fix | Delete
add_filter( 'pre_update_site_option_' . $this->option_name, [ $this, 'add_default_filters_if_not_changed' ], PHP_INT_MAX, 3 );
[176] Fix | Delete
[177] Fix | Delete
// Refills the cache when the option has been updated.
[178] Fix | Delete
add_action( 'update_site_option_' . $this->option_name, [ 'WPSEO_Options', 'clear_cache' ], 1, 0 );
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
/*
[182] Fix | Delete
* Make sure the option will always get validated, independently of register_setting()
[183] Fix | Delete
* (only available on back-end).
[184] Fix | Delete
*/
[185] Fix | Delete
add_filter( 'sanitize_option_' . $this->option_name, [ $this, 'validate' ] );
[186] Fix | Delete
[187] Fix | Delete
/* Register our option for the admin pages */
[188] Fix | Delete
add_action( 'admin_init', [ $this, 'register_setting' ] );
[189] Fix | Delete
[190] Fix | Delete
/* Set option group name if not given */
[191] Fix | Delete
if ( ! isset( $this->group_name ) || $this->group_name === '' ) {
[192] Fix | Delete
$this->group_name = 'yoast_' . $this->option_name . '_options';
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/* Translate some defaults as early as possible - textdomain is loaded in init on priority 1. */
[196] Fix | Delete
if ( method_exists( $this, 'translate_defaults' ) ) {
[197] Fix | Delete
add_action( 'init', [ $this, 'translate_defaults' ], 2 );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Enrich defaults once custom post types and taxonomies have been registered
[202] Fix | Delete
* which is normally done on the init action.
[203] Fix | Delete
*
[204] Fix | Delete
* @todo [JRF/testers] Verify that none of the options which are only available after
[205] Fix | Delete
* enrichment are used before the enriching.
[206] Fix | Delete
*/
[207] Fix | Delete
if ( method_exists( $this, 'enrich_defaults' ) ) {
[208] Fix | Delete
add_action( 'init', [ $this, 'enrich_defaults' ], 99 );
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
/*
[213] Fix | Delete
* All concrete classes *must* contain the get_instance method.
[214] Fix | Delete
*
[215] Fix | Delete
* {@internal Unfortunately I can't define it as an abstract as it also *has* to be static...}}
[216] Fix | Delete
*
[217] Fix | Delete
* ```
[218] Fix | Delete
* abstract protected static function get_instance();
[219] Fix | Delete
* ```
[220] Fix | Delete
* ---------------
[221] Fix | Delete
*
[222] Fix | Delete
* Concrete classes *may* contain a translate_defaults method.
[223] Fix | Delete
* ```
[224] Fix | Delete
* abstract public function translate_defaults();
[225] Fix | Delete
* ```
[226] Fix | Delete
* ---------------
[227] Fix | Delete
*
[228] Fix | Delete
* Concrete classes *may* contain an enrich_defaults method to add additional defaults once
[229] Fix | Delete
* all post_types and taxonomies have been registered.
[230] Fix | Delete
*
[231] Fix | Delete
* ```
[232] Fix | Delete
* abstract public function enrich_defaults();
[233] Fix | Delete
* ```
[234] Fix | Delete
*/
[235] Fix | Delete
[236] Fix | Delete
/* *********** METHODS INFLUENCING get_option() *********** */
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Add filters to make sure that the option default is returned if the option is not set.
[240] Fix | Delete
*
[241] Fix | Delete
* @return void
[242] Fix | Delete
*/
[243] Fix | Delete
public function add_default_filters() {
[244] Fix | Delete
// Don't change, needs to check for false as could return prio 0 which would evaluate to false.
[245] Fix | Delete
if ( has_filter( 'default_option_' . $this->option_name, [ $this, 'get_defaults' ] ) === false ) {
[246] Fix | Delete
add_filter( 'default_option_' . $this->option_name, [ $this, 'get_defaults' ] );
[247] Fix | Delete
}
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* Adds back the default filters that were removed during validation if the option was changed.
[252] Fix | Delete
* Checks if this option was changed to prevent constantly checking if filters are present.
[253] Fix | Delete
*
[254] Fix | Delete
* @param string $option_name The option name.
[255] Fix | Delete
*
[256] Fix | Delete
* @return void
[257] Fix | Delete
*/
[258] Fix | Delete
public function add_default_filters_if_same_option( $option_name ) {
[259] Fix | Delete
if ( $option_name === $this->option_name ) {
[260] Fix | Delete
$this->add_default_filters();
[261] Fix | Delete
}
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
/**
[265] Fix | Delete
* Adds back the default filters that were removed during validation if the option was not changed.
[266] Fix | Delete
* This is because in that case the latter actions are not called and thus the filters are never
[267] Fix | Delete
* added back.
[268] Fix | Delete
*
[269] Fix | Delete
* @param mixed $value The current value.
[270] Fix | Delete
* @param string $option_name The option name.
[271] Fix | Delete
* @param mixed $old_value The old value.
[272] Fix | Delete
*
[273] Fix | Delete
* @return string The current value.
[274] Fix | Delete
*/
[275] Fix | Delete
public function add_default_filters_if_not_changed( $value, $option_name, $old_value ) {
[276] Fix | Delete
if ( $option_name !== $this->option_name ) {
[277] Fix | Delete
return $value;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
[281] Fix | Delete
$this->add_default_filters();
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
return $value;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Validate webmaster tools & Pinterest verification strings.
[289] Fix | Delete
*
[290] Fix | Delete
* @param string $key Key to check, by type of service.
[291] Fix | Delete
* @param array $dirty Dirty data with the new values.
[292] Fix | Delete
* @param array $old Old data.
[293] Fix | Delete
* @param array $clean Clean data by reference, normally the default values.
[294] Fix | Delete
*
[295] Fix | Delete
* @return void
[296] Fix | Delete
*/
[297] Fix | Delete
public function validate_verification_string( $key, $dirty, $old, &$clean ) {
[298] Fix | Delete
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
[299] Fix | Delete
$meta = $dirty[ $key ];
[300] Fix | Delete
if ( strpos( $meta, 'content=' ) ) {
[301] Fix | Delete
// Make sure we only have the real key, not a complete meta tag.
[302] Fix | Delete
preg_match( '`content=([\'"])?([^\'"> ]+)(?:\1|[ />])`', $meta, $match );
[303] Fix | Delete
if ( isset( $match[2] ) ) {
[304] Fix | Delete
$meta = $match[2];
[305] Fix | Delete
}
[306] Fix | Delete
unset( $match );
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
$meta = sanitize_text_field( $meta );
[310] Fix | Delete
if ( $meta !== '' ) {
[311] Fix | Delete
$regex = '`^[A-Fa-f0-9_-]+$`';
[312] Fix | Delete
$service = '';
[313] Fix | Delete
[314] Fix | Delete
switch ( $key ) {
[315] Fix | Delete
case 'baiduverify':
[316] Fix | Delete
$regex = '`^[A-Za-z0-9_-]+$`';
[317] Fix | Delete
$service = 'Baidu Webmaster tools';
[318] Fix | Delete
break;
[319] Fix | Delete
[320] Fix | Delete
case 'googleverify':
[321] Fix | Delete
$regex = '`^[A-Za-z0-9_-]+$`';
[322] Fix | Delete
$service = 'Google Webmaster tools';
[323] Fix | Delete
break;
[324] Fix | Delete
[325] Fix | Delete
case 'msverify':
[326] Fix | Delete
$service = 'Bing Webmaster tools';
[327] Fix | Delete
break;
[328] Fix | Delete
[329] Fix | Delete
case 'pinterestverify':
[330] Fix | Delete
$service = 'Pinterest';
[331] Fix | Delete
break;
[332] Fix | Delete
[333] Fix | Delete
case 'yandexverify':
[334] Fix | Delete
$service = 'Yandex Webmaster tools';
[335] Fix | Delete
break;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
if ( preg_match( $regex, $meta ) ) {
[339] Fix | Delete
$clean[ $key ] = $meta;
[340] Fix | Delete
}
[341] Fix | Delete
else {
[342] Fix | Delete
// Restore the previous value, if any.
[343] Fix | Delete
if ( isset( $old[ $key ] ) && preg_match( $regex, $old[ $key ] ) ) {
[344] Fix | Delete
$clean[ $key ] = $old[ $key ];
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
if ( function_exists( 'add_settings_error' ) ) {
[348] Fix | Delete
add_settings_error(
[349] Fix | Delete
$this->group_name, // Slug title of the setting.
[350] Fix | Delete
$key, // Suffix-ID for the error message box. WordPress prepends `setting-error-`.
[351] Fix | Delete
/* translators: 1: Verification string from user input; 2: Service name. */
[352] Fix | Delete
sprintf( __( '%1$s does not seem to be a valid %2$s verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>', $service ), // The error message.
[353] Fix | Delete
'error' // CSS class for the WP notice, either the legacy 'error' / 'updated' or the new `notice-*` ones.
[354] Fix | Delete
);
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
Yoast_Input_Validation::add_dirty_value_to_settings_errors( $key, $meta );
[358] Fix | Delete
}
[359] Fix | Delete
}
[360] Fix | Delete
}
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Validates an option as a valid URL. Prints out a WordPress settings error
[365] Fix | Delete
* notice if the URL is invalid.
[366] Fix | Delete
*
[367] Fix | Delete
* @param string $key Key to check, by type of URL setting.
[368] Fix | Delete
* @param array $dirty Dirty data with the new values.
[369] Fix | Delete
* @param array $old Old data.
[370] Fix | Delete
* @param array $clean Clean data by reference, normally the default values.
[371] Fix | Delete
*
[372] Fix | Delete
* @return void
[373] Fix | Delete
*/
[374] Fix | Delete
public function validate_url( $key, $dirty, $old, &$clean ) {
[375] Fix | Delete
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
[376] Fix | Delete
[377] Fix | Delete
$submitted_url = trim( $dirty[ $key ] );
[378] Fix | Delete
$validated_url = filter_var( WPSEO_Utils::sanitize_url( $submitted_url ), FILTER_VALIDATE_URL );
[379] Fix | Delete
[380] Fix | Delete
if ( $validated_url === false ) {
[381] Fix | Delete
if ( function_exists( 'add_settings_error' ) ) {
[382] Fix | Delete
add_settings_error(
[383] Fix | Delete
// Slug title of the setting.
[384] Fix | Delete
$this->group_name,
[385] Fix | Delete
// Suffix-ID for the error message box. WordPress prepends `setting-error-`.
[386] Fix | Delete
$key,
[387] Fix | Delete
// The error message.
[388] Fix | Delete
sprintf(
[389] Fix | Delete
/* translators: %s expands to an invalid URL. */
[390] Fix | Delete
__( '%s does not seem to be a valid url. Please correct.', 'wordpress-seo' ),
[391] Fix | Delete
'<strong>' . esc_url( $submitted_url ) . '</strong>'
[392] Fix | Delete
),
[393] Fix | Delete
// Message type.
[394] Fix | Delete
'error'
[395] Fix | Delete
);
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
// Restore the previous URL value, if any.
[399] Fix | Delete
if ( isset( $old[ $key ] ) && $old[ $key ] !== '' ) {
[400] Fix | Delete
$url = WPSEO_Utils::sanitize_url( $old[ $key ] );
[401] Fix | Delete
if ( $url !== '' ) {
[402] Fix | Delete
$clean[ $key ] = $url;
[403] Fix | Delete
}
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
Yoast_Input_Validation::add_dirty_value_to_settings_errors( $key, $submitted_url );
[407] Fix | Delete
[408] Fix | Delete
return;
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
// The URL format is valid, let's sanitize it.
[412] Fix | Delete
$url = WPSEO_Utils::sanitize_url( $validated_url );
[413] Fix | Delete
[414] Fix | Delete
if ( $url !== '' ) {
[415] Fix | Delete
$clean[ $key ] = $url;
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
/**
[421] Fix | Delete
* Remove the default filters.
[422] Fix | Delete
* Called from the validate() method to prevent failure to add new options.
[423] Fix | Delete
*
[424] Fix | Delete
* @return void
[425] Fix | Delete
*/
[426] Fix | Delete
public function remove_default_filters() {
[427] Fix | Delete
remove_filter( 'default_option_' . $this->option_name, [ $this, 'get_defaults' ] );
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Get the enriched default value for an option.
[432] Fix | Delete
*
[433] Fix | Delete
* Checks if the concrete class contains an enrich_defaults() method and if so, runs it.
[434] Fix | Delete
*
[435] Fix | Delete
* {@internal The enrich_defaults method is used to set defaults for variable array keys
[436] Fix | Delete
* in an option, such as array keys depending on post_types and/or taxonomies.}}
[437] Fix | Delete
*
[438] Fix | Delete
* @return array
[439] Fix | Delete
*/
[440] Fix | Delete
public function get_defaults() {
[441] Fix | Delete
if ( method_exists( $this, 'translate_defaults' ) ) {
[442] Fix | Delete
$this->translate_defaults();
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
if ( method_exists( $this, 'enrich_defaults' ) ) {
[446] Fix | Delete
$this->enrich_defaults();
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
return apply_filters( 'wpseo_defaults', $this->defaults, $this->option_name );
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
/**
[453] Fix | Delete
* Add filters to make sure that the option is merged with its defaults before being returned.
[454] Fix | Delete
*
[455] Fix | Delete
* @return void
[456] Fix | Delete
*/
[457] Fix | Delete
public function add_option_filters() {
[458] Fix | Delete
// Don't change, needs to check for false as could return prio 0 which would evaluate to false.
[459] Fix | Delete
if ( has_filter( 'option_' . $this->option_name, [ $this, 'get_option' ] ) === false ) {
[460] Fix | Delete
add_filter( 'option_' . $this->option_name, [ $this, 'get_option' ] );
[461] Fix | Delete
}
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* Remove the option filters.
[466] Fix | Delete
* Called from the clean_up methods to make sure we retrieve the original old option.
[467] Fix | Delete
*
[468] Fix | Delete
* @return void
[469] Fix | Delete
*/
[470] Fix | Delete
public function remove_option_filters() {
[471] Fix | Delete
remove_filter( 'option_' . $this->option_name, [ $this, 'get_option' ] );
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
/**
[475] Fix | Delete
* Merge an option with its default values.
[476] Fix | Delete
*
[477] Fix | Delete
* This method should *not* be called directly!!! It is only meant to filter the get_option() results.
[478] Fix | Delete
*
[479] Fix | Delete
* @param mixed $options Option value.
[480] Fix | Delete
*
[481] Fix | Delete
* @return mixed Option merged with the defaults for that option.
[482] Fix | Delete
*/
[483] Fix | Delete
public function get_option( $options = null ) {
[484] Fix | Delete
$filtered = $this->array_filter_merge( $options );
[485] Fix | Delete
[486] Fix | Delete
/*
[487] Fix | Delete
* If the option contains variable option keys, make sure we don't remove those settings
[488] Fix | Delete
* - even if the defaults are not complete yet.
[489] Fix | Delete
* Unfortunately this means we also won't be removing the settings for post types or taxonomies
[490] Fix | Delete
* which are no longer in the WP install, but rather that than the other way around.
[491] Fix | Delete
*/
[492] Fix | Delete
if ( isset( $this->variable_array_key_patterns ) ) {
[493] Fix | Delete
$filtered = $this->retain_variable_keys( $options, $filtered );
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
return $filtered;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function