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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../inc/options
File: class-wpseo-option.php
/* *********** METHODS influencing add_option(), update_option() and saving from admin pages. *********** */
[500] Fix | Delete
[501] Fix | Delete
/**
[502] Fix | Delete
* Register (whitelist) the option for the configuration pages.
[503] Fix | Delete
* The validation callback is already registered separately on the sanitize_option hook,
[504] Fix | Delete
* so no need to double register.
[505] Fix | Delete
*
[506] Fix | Delete
* @return void
[507] Fix | Delete
*/
[508] Fix | Delete
public function register_setting() {
[509] Fix | Delete
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
[510] Fix | Delete
return;
[511] Fix | Delete
}
[512] Fix | Delete
[513] Fix | Delete
if ( $this->multisite_only === true ) {
[514] Fix | Delete
$network_settings_api = Yoast_Network_Settings_API::get();
[515] Fix | Delete
if ( $network_settings_api->meets_requirements() ) {
[516] Fix | Delete
$network_settings_api->register_setting( $this->group_name, $this->option_name );
[517] Fix | Delete
}
[518] Fix | Delete
return;
[519] Fix | Delete
}
[520] Fix | Delete
[521] Fix | Delete
register_setting( $this->group_name, $this->option_name );
[522] Fix | Delete
}
[523] Fix | Delete
[524] Fix | Delete
/**
[525] Fix | Delete
* Validate the option.
[526] Fix | Delete
*
[527] Fix | Delete
* @param mixed $option_value The unvalidated new value for the option.
[528] Fix | Delete
*
[529] Fix | Delete
* @return array Validated new value for the option.
[530] Fix | Delete
*/
[531] Fix | Delete
public function validate( $option_value ) {
[532] Fix | Delete
$clean = $this->get_defaults();
[533] Fix | Delete
[534] Fix | Delete
/* Return the defaults if the new value is empty. */
[535] Fix | Delete
if ( ! is_array( $option_value ) || $option_value === [] ) {
[536] Fix | Delete
return $clean;
[537] Fix | Delete
}
[538] Fix | Delete
[539] Fix | Delete
$option_value = array_map( [ 'WPSEO_Utils', 'trim_recursive' ], $option_value );
[540] Fix | Delete
[541] Fix | Delete
$old = $this->get_original_option();
[542] Fix | Delete
if ( ! is_array( $old ) ) {
[543] Fix | Delete
$old = [];
[544] Fix | Delete
}
[545] Fix | Delete
$old = array_merge( $clean, $old );
[546] Fix | Delete
[547] Fix | Delete
$clean = $this->validate_option( $option_value, $clean, $old );
[548] Fix | Delete
[549] Fix | Delete
// Prevent updates to variables that are disabled via the override option.
[550] Fix | Delete
$clean = $this->prevent_disabled_options_update( $clean, $old );
[551] Fix | Delete
[552] Fix | Delete
/* Retain the values for variable array keys even when the post type/taxonomy is not yet registered. */
[553] Fix | Delete
if ( isset( $this->variable_array_key_patterns ) ) {
[554] Fix | Delete
$clean = $this->retain_variable_keys( $option_value, $clean );
[555] Fix | Delete
}
[556] Fix | Delete
[557] Fix | Delete
$this->remove_default_filters();
[558] Fix | Delete
[559] Fix | Delete
return $clean;
[560] Fix | Delete
}
[561] Fix | Delete
[562] Fix | Delete
/**
[563] Fix | Delete
* Checks whether a specific option key is disabled.
[564] Fix | Delete
*
[565] Fix | Delete
* This is determined by whether an override option is available with a key that equals the given key prefixed
[566] Fix | Delete
* with 'allow_'.
[567] Fix | Delete
*
[568] Fix | Delete
* @param string $key Option key.
[569] Fix | Delete
*
[570] Fix | Delete
* @return bool True if option key is disabled, false otherwise.
[571] Fix | Delete
*/
[572] Fix | Delete
public function is_disabled( $key ) {
[573] Fix | Delete
$override_option = $this->get_override_option();
[574] Fix | Delete
if ( empty( $override_option ) ) {
[575] Fix | Delete
return false;
[576] Fix | Delete
}
[577] Fix | Delete
[578] Fix | Delete
return isset( $override_option[ self::ALLOW_KEY_PREFIX . $key ] ) && ! $override_option[ self::ALLOW_KEY_PREFIX . $key ];
[579] Fix | Delete
}
[580] Fix | Delete
[581] Fix | Delete
/**
[582] Fix | Delete
* All concrete classes must contain a validate_option() method which validates all
[583] Fix | Delete
* values within the option.
[584] Fix | Delete
*
[585] Fix | Delete
* @param array $dirty New value for the option.
[586] Fix | Delete
* @param array $clean Clean value for the option, normally the defaults.
[587] Fix | Delete
* @param array $old Old value of the option.
[588] Fix | Delete
*/
[589] Fix | Delete
abstract protected function validate_option( $dirty, $clean, $old );
[590] Fix | Delete
[591] Fix | Delete
/* *********** METHODS for ADDING/UPDATING/UPGRADING the option. *********** */
[592] Fix | Delete
[593] Fix | Delete
/**
[594] Fix | Delete
* Retrieve the real old value (unmerged with defaults).
[595] Fix | Delete
*
[596] Fix | Delete
* @return array|bool The original option value (which can be false if the option doesn't exist).
[597] Fix | Delete
*/
[598] Fix | Delete
protected function get_original_option() {
[599] Fix | Delete
$this->remove_default_filters();
[600] Fix | Delete
$this->remove_option_filters();
[601] Fix | Delete
[602] Fix | Delete
// Get (unvalidated) array, NOT merged with defaults.
[603] Fix | Delete
if ( $this->multisite_only !== true ) {
[604] Fix | Delete
$option_value = get_option( $this->option_name );
[605] Fix | Delete
}
[606] Fix | Delete
else {
[607] Fix | Delete
$option_value = get_site_option( $this->option_name );
[608] Fix | Delete
}
[609] Fix | Delete
[610] Fix | Delete
$this->add_option_filters();
[611] Fix | Delete
$this->add_default_filters();
[612] Fix | Delete
[613] Fix | Delete
return $option_value;
[614] Fix | Delete
}
[615] Fix | Delete
[616] Fix | Delete
/**
[617] Fix | Delete
* Add the option if it doesn't exist for some strange reason.
[618] Fix | Delete
*
[619] Fix | Delete
* @uses WPSEO_Option::get_original_option()
[620] Fix | Delete
*
[621] Fix | Delete
* @return void
[622] Fix | Delete
*/
[623] Fix | Delete
public function maybe_add_option() {
[624] Fix | Delete
if ( $this->get_original_option() === false ) {
[625] Fix | Delete
if ( $this->multisite_only !== true ) {
[626] Fix | Delete
update_option( $this->option_name, $this->get_defaults() );
[627] Fix | Delete
}
[628] Fix | Delete
else {
[629] Fix | Delete
$this->update_site_option( $this->get_defaults() );
[630] Fix | Delete
}
[631] Fix | Delete
}
[632] Fix | Delete
}
[633] Fix | Delete
[634] Fix | Delete
/**
[635] Fix | Delete
* Update a site_option.
[636] Fix | Delete
*
[637] Fix | Delete
* {@internal This special method is only needed for multisite options, but very needed indeed there.
[638] Fix | Delete
* The order in which certain functions and hooks are run is different between
[639] Fix | Delete
* get_option() and get_site_option() which means in practice that the removing
[640] Fix | Delete
* of the default filters would be done too late and the re-adding of the default
[641] Fix | Delete
* filters might not be done at all.
[642] Fix | Delete
* Aka: use the WPSEO_Options::update_site_option() method (which calls this method)
[643] Fix | Delete
* for safely adding/updating multisite options.}}
[644] Fix | Delete
*
[645] Fix | Delete
* @param mixed $value The new value for the option.
[646] Fix | Delete
*
[647] Fix | Delete
* @return bool Whether the update was successful.
[648] Fix | Delete
*/
[649] Fix | Delete
public function update_site_option( $value ) {
[650] Fix | Delete
if ( $this->multisite_only === true && is_multisite() ) {
[651] Fix | Delete
$this->remove_default_filters();
[652] Fix | Delete
$result = update_site_option( $this->option_name, $value );
[653] Fix | Delete
$this->add_default_filters();
[654] Fix | Delete
[655] Fix | Delete
return $result;
[656] Fix | Delete
}
[657] Fix | Delete
else {
[658] Fix | Delete
return false;
[659] Fix | Delete
}
[660] Fix | Delete
}
[661] Fix | Delete
[662] Fix | Delete
/**
[663] Fix | Delete
* Retrieve the real old value (unmerged with defaults), clean and re-save the option.
[664] Fix | Delete
*
[665] Fix | Delete
* @uses WPSEO_Option::get_original_option()
[666] Fix | Delete
* @uses WPSEO_Option::import()
[667] Fix | Delete
*
[668] Fix | Delete
* @param string|null $current_version Optional. Version from which to upgrade, if not set,
[669] Fix | Delete
* version-specific upgrades will be disregarded.
[670] Fix | Delete
*
[671] Fix | Delete
* @return void
[672] Fix | Delete
*/
[673] Fix | Delete
public function clean( $current_version = null ) {
[674] Fix | Delete
$option_value = $this->get_original_option();
[675] Fix | Delete
$this->import( $option_value, $current_version );
[676] Fix | Delete
}
[677] Fix | Delete
[678] Fix | Delete
/**
[679] Fix | Delete
* Clean and re-save the option.
[680] Fix | Delete
*
[681] Fix | Delete
* @uses clean_option() method from concrete class if it exists.
[682] Fix | Delete
*
[683] Fix | Delete
* @todo [JRF/whomever] Figure out a way to show settings error during/after the upgrade - maybe
[684] Fix | Delete
* something along the lines of:
[685] Fix | Delete
* -> add them to a property in this class
[686] Fix | Delete
* -> if that property isset at the end of the routine and add_settings_error function does not exist,
[687] Fix | Delete
* save as transient (or update the transient if one already exists)
[688] Fix | Delete
* -> next time an admin is in the WP back-end, show the errors and delete the transient or only delete it
[689] Fix | Delete
* once the admin has dismissed the message (add ajax function)
[690] Fix | Delete
* Important: all validation routines which add_settings_errors would need to be changed for this to work
[691] Fix | Delete
*
[692] Fix | Delete
* @param array $option_value Option value to be imported.
[693] Fix | Delete
* @param string|null $current_version Optional. Version from which to upgrade, if not set,
[694] Fix | Delete
* version-specific upgrades will be disregarded.
[695] Fix | Delete
* @param array|null $all_old_option_values Optional. Only used when importing old options to
[696] Fix | Delete
* have access to the real old values, in contrast to
[697] Fix | Delete
* the saved ones.
[698] Fix | Delete
*
[699] Fix | Delete
* @return void
[700] Fix | Delete
*/
[701] Fix | Delete
public function import( $option_value, $current_version = null, $all_old_option_values = null ) {
[702] Fix | Delete
if ( $option_value === false ) {
[703] Fix | Delete
$option_value = $this->get_defaults();
[704] Fix | Delete
}
[705] Fix | Delete
elseif ( is_array( $option_value ) && method_exists( $this, 'clean_option' ) ) {
[706] Fix | Delete
$option_value = $this->clean_option( $option_value, $current_version, $all_old_option_values );
[707] Fix | Delete
}
[708] Fix | Delete
[709] Fix | Delete
/*
[710] Fix | Delete
* Save the cleaned value - validation will take care of cleaning out array keys which
[711] Fix | Delete
* should no longer be there.
[712] Fix | Delete
*/
[713] Fix | Delete
if ( $this->multisite_only !== true ) {
[714] Fix | Delete
update_option( $this->option_name, $option_value );
[715] Fix | Delete
}
[716] Fix | Delete
else {
[717] Fix | Delete
$this->update_site_option( $this->option_name, $option_value );
[718] Fix | Delete
}
[719] Fix | Delete
}
[720] Fix | Delete
[721] Fix | Delete
/**
[722] Fix | Delete
* Returns the variable array key patterns for an options class.
[723] Fix | Delete
*
[724] Fix | Delete
* @return array
[725] Fix | Delete
*/
[726] Fix | Delete
public function get_patterns() {
[727] Fix | Delete
return (array) $this->variable_array_key_patterns;
[728] Fix | Delete
}
[729] Fix | Delete
[730] Fix | Delete
/**
[731] Fix | Delete
* Retrieves the option name.
[732] Fix | Delete
*
[733] Fix | Delete
* @return string The set option name.
[734] Fix | Delete
*/
[735] Fix | Delete
public function get_option_name() {
[736] Fix | Delete
return $this->option_name;
[737] Fix | Delete
}
[738] Fix | Delete
[739] Fix | Delete
/*
[740] Fix | Delete
* Concrete classes *may* contain a clean_option method which will clean out old/renamed
[741] Fix | Delete
* values within the option.
[742] Fix | Delete
*
[743] Fix | Delete
* ```
[744] Fix | Delete
* abstract public function clean_option( $option_value, $current_version = null, $all_old_option_values = null );
[745] Fix | Delete
* ```
[746] Fix | Delete
*/
[747] Fix | Delete
[748] Fix | Delete
/* *********** HELPER METHODS for internal use. *********** */
[749] Fix | Delete
[750] Fix | Delete
/**
[751] Fix | Delete
* Helper method - Combines a fixed array of default values with an options array
[752] Fix | Delete
* while filtering out any keys which are not in the defaults array.
[753] Fix | Delete
*
[754] Fix | Delete
* @todo [JRF] - shouldn't this be a straight array merge ? at the end of the day, the validation
[755] Fix | Delete
* removes any invalid keys on save.
[756] Fix | Delete
*
[757] Fix | Delete
* @param array|null $options Optional. Current options. If not set, the option defaults
[758] Fix | Delete
* for the $option_key will be returned.
[759] Fix | Delete
*
[760] Fix | Delete
* @return array Combined and filtered options array.
[761] Fix | Delete
*/
[762] Fix | Delete
protected function array_filter_merge( $options = null ) {
[763] Fix | Delete
[764] Fix | Delete
$defaults = $this->get_defaults();
[765] Fix | Delete
[766] Fix | Delete
if ( ! isset( $options ) || $options === false || $options === [] ) {
[767] Fix | Delete
return $defaults;
[768] Fix | Delete
}
[769] Fix | Delete
[770] Fix | Delete
$options = (array) $options;
[771] Fix | Delete
[772] Fix | Delete
/*
[773] Fix | Delete
$filtered = array();
[774] Fix | Delete
[775] Fix | Delete
if ( $defaults !== array() ) {
[776] Fix | Delete
foreach ( $defaults as $key => $default_value ) {
[777] Fix | Delete
// @todo should this walk through array subkeys ?
[778] Fix | Delete
$filtered[ $key ] = ( isset( $options[ $key ] ) ? $options[ $key ] : $default_value );
[779] Fix | Delete
}
[780] Fix | Delete
}
[781] Fix | Delete
*/
[782] Fix | Delete
$filtered = array_merge( $defaults, $options );
[783] Fix | Delete
[784] Fix | Delete
return $filtered;
[785] Fix | Delete
}
[786] Fix | Delete
[787] Fix | Delete
/**
[788] Fix | Delete
* Sets updated values for variables that are disabled via the override option back to their previous values.
[789] Fix | Delete
*
[790] Fix | Delete
* @param array $updated Updated option value.
[791] Fix | Delete
* @param array $old Old option value.
[792] Fix | Delete
*
[793] Fix | Delete
* @return array Updated option value, with all disabled variables set to their old values.
[794] Fix | Delete
*/
[795] Fix | Delete
protected function prevent_disabled_options_update( $updated, $old ) {
[796] Fix | Delete
$override_option = $this->get_override_option();
[797] Fix | Delete
if ( empty( $override_option ) ) {
[798] Fix | Delete
return $updated;
[799] Fix | Delete
}
[800] Fix | Delete
[801] Fix | Delete
/*
[802] Fix | Delete
* This loop could as well call `is_disabled( $key )` for each iteration,
[803] Fix | Delete
* however this would be worse performance-wise.
[804] Fix | Delete
*/
[805] Fix | Delete
foreach ( $old as $key => $value ) {
[806] Fix | Delete
if ( isset( $override_option[ self::ALLOW_KEY_PREFIX . $key ] ) && ! $override_option[ self::ALLOW_KEY_PREFIX . $key ] ) {
[807] Fix | Delete
$updated[ $key ] = $old[ $key ];
[808] Fix | Delete
}
[809] Fix | Delete
}
[810] Fix | Delete
[811] Fix | Delete
return $updated;
[812] Fix | Delete
}
[813] Fix | Delete
[814] Fix | Delete
/**
[815] Fix | Delete
* Retrieves the value of the override option, if available.
[816] Fix | Delete
*
[817] Fix | Delete
* An override option contains values that may determine access to certain sub-variables
[818] Fix | Delete
* of this option.
[819] Fix | Delete
*
[820] Fix | Delete
* Only regular options in multisite can have override options, which in that case
[821] Fix | Delete
* would be network options.
[822] Fix | Delete
*
[823] Fix | Delete
* @return array Override option value, or empty array if unavailable.
[824] Fix | Delete
*/
[825] Fix | Delete
protected function get_override_option() {
[826] Fix | Delete
if ( empty( $this->override_option_name ) || $this->multisite_only === true || ! is_multisite() ) {
[827] Fix | Delete
return [];
[828] Fix | Delete
}
[829] Fix | Delete
[830] Fix | Delete
return get_site_option( $this->override_option_name, [] );
[831] Fix | Delete
}
[832] Fix | Delete
[833] Fix | Delete
/**
[834] Fix | Delete
* Make sure that any set option values relating to post_types and/or taxonomies are retained,
[835] Fix | Delete
* even when that post_type or taxonomy may not yet have been registered.
[836] Fix | Delete
*
[837] Fix | Delete
* {@internal The wpseo_titles concrete class overrules this method. Make sure that any
[838] Fix | Delete
* changes applied here, also get ported to that version.}}
[839] Fix | Delete
*
[840] Fix | Delete
* @param array $dirty Original option as retrieved from the database.
[841] Fix | Delete
* @param array $clean Filtered option where any options which shouldn't be in our option
[842] Fix | Delete
* have already been removed and any options which weren't set
[843] Fix | Delete
* have been set to their defaults.
[844] Fix | Delete
*
[845] Fix | Delete
* @return array
[846] Fix | Delete
*/
[847] Fix | Delete
protected function retain_variable_keys( $dirty, $clean ) {
[848] Fix | Delete
if ( ( is_array( $this->variable_array_key_patterns ) && $this->variable_array_key_patterns !== [] ) && ( is_array( $dirty ) && $dirty !== [] ) ) {
[849] Fix | Delete
foreach ( $dirty as $key => $value ) {
[850] Fix | Delete
[851] Fix | Delete
// Do nothing if already in filtered options.
[852] Fix | Delete
if ( isset( $clean[ $key ] ) ) {
[853] Fix | Delete
continue;
[854] Fix | Delete
}
[855] Fix | Delete
[856] Fix | Delete
foreach ( $this->variable_array_key_patterns as $pattern ) {
[857] Fix | Delete
[858] Fix | Delete
if ( strpos( $key, $pattern ) === 0 ) {
[859] Fix | Delete
$clean[ $key ] = $value;
[860] Fix | Delete
break;
[861] Fix | Delete
}
[862] Fix | Delete
}
[863] Fix | Delete
}
[864] Fix | Delete
}
[865] Fix | Delete
[866] Fix | Delete
return $clean;
[867] Fix | Delete
}
[868] Fix | Delete
[869] Fix | Delete
/**
[870] Fix | Delete
* Check whether a given array key conforms to one of the variable array key patterns for this option.
[871] Fix | Delete
*
[872] Fix | Delete
* @used-by validate_option() methods for options with variable array keys.
[873] Fix | Delete
*
[874] Fix | Delete
* @param string $key Array key to check.
[875] Fix | Delete
*
[876] Fix | Delete
* @return string Pattern if it conforms, original array key if it doesn't or if the option
[877] Fix | Delete
* does not have variable array keys.
[878] Fix | Delete
*/
[879] Fix | Delete
protected function get_switch_key( $key ) {
[880] Fix | Delete
if ( ! isset( $this->variable_array_key_patterns ) || ( ! is_array( $this->variable_array_key_patterns ) || $this->variable_array_key_patterns === [] ) ) {
[881] Fix | Delete
return $key;
[882] Fix | Delete
}
[883] Fix | Delete
[884] Fix | Delete
foreach ( $this->variable_array_key_patterns as $pattern ) {
[885] Fix | Delete
if ( strpos( $key, $pattern ) === 0 ) {
[886] Fix | Delete
return $pattern;
[887] Fix | Delete
}
[888] Fix | Delete
}
[889] Fix | Delete
[890] Fix | Delete
return $key;
[891] Fix | Delete
}
[892] Fix | Delete
}
[893] Fix | Delete
[894] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function