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/clone/wp-conte.../plugins/wordpres.../inc/options
File: class-wpseo-option-social.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
* Option: wpseo_social.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Option_Social extends WPSEO_Option {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Option name.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string
[15] Fix | Delete
*/
[16] Fix | Delete
public $option_name = 'wpseo_social';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Array of defaults for the option.
[20] Fix | Delete
*
[21] Fix | Delete
* Shouldn't be requested directly, use $this->get_defaults();
[22] Fix | Delete
*
[23] Fix | Delete
* @var array
[24] Fix | Delete
*/
[25] Fix | Delete
protected $defaults = [
[26] Fix | Delete
// Form fields.
[27] Fix | Delete
'facebook_site' => '', // Text field.
[28] Fix | Delete
'instagram_url' => '',
[29] Fix | Delete
'linkedin_url' => '',
[30] Fix | Delete
'myspace_url' => '',
[31] Fix | Delete
'og_default_image' => '', // Text field.
[32] Fix | Delete
'og_default_image_id' => '',
[33] Fix | Delete
'og_frontpage_title' => '', // Text field.
[34] Fix | Delete
'og_frontpage_desc' => '', // Text field.
[35] Fix | Delete
'og_frontpage_image' => '', // Text field.
[36] Fix | Delete
'og_frontpage_image_id' => '',
[37] Fix | Delete
'opengraph' => true,
[38] Fix | Delete
'pinterest_url' => '',
[39] Fix | Delete
'pinterestverify' => '',
[40] Fix | Delete
'twitter' => true,
[41] Fix | Delete
'twitter_site' => '', // Text field.
[42] Fix | Delete
'twitter_card_type' => 'summary_large_image',
[43] Fix | Delete
'youtube_url' => '',
[44] Fix | Delete
'wikipedia_url' => '',
[45] Fix | Delete
'other_social_urls' => [],
[46] Fix | Delete
'mastodon_url' => '',
[47] Fix | Delete
];
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Array of sub-options which should not be overloaded with multi-site defaults.
[51] Fix | Delete
*
[52] Fix | Delete
* @var array
[53] Fix | Delete
*/
[54] Fix | Delete
public $ms_exclude = [
[55] Fix | Delete
/* Privacy. */
[56] Fix | Delete
'pinterestverify',
[57] Fix | Delete
];
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Array of allowed twitter card types.
[61] Fix | Delete
*
[62] Fix | Delete
* While we only have the options summary and summary_large_image in the
[63] Fix | Delete
* interface now, we might change that at some point.
[64] Fix | Delete
*
[65] Fix | Delete
* {@internal Uncomment any of these to allow them in validation *and* automatically
[66] Fix | Delete
* add them as a choice in the options page.}}
[67] Fix | Delete
*
[68] Fix | Delete
* @var array
[69] Fix | Delete
*/
[70] Fix | Delete
public static $twitter_card_types = [
[71] Fix | Delete
'summary_large_image' => '',
[72] Fix | Delete
// 'summary' => '',
[73] Fix | Delete
// 'photo' => '',
[74] Fix | Delete
// 'gallery' => '',
[75] Fix | Delete
// 'app' => '',
[76] Fix | Delete
// 'player' => '',
[77] Fix | Delete
// 'product' => '',
[78] Fix | Delete
];
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Add the actions and filters for the option.
[82] Fix | Delete
*/
[83] Fix | Delete
protected function __construct() {
[84] Fix | Delete
parent::__construct();
[85] Fix | Delete
[86] Fix | Delete
add_filter( 'admin_title', [ 'Yoast_Input_Validation', 'add_yoast_admin_document_title_errors' ] );
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Get the singleton instance of this class.
[91] Fix | Delete
*
[92] Fix | Delete
* @return object
[93] Fix | Delete
*/
[94] Fix | Delete
public static function get_instance() {
[95] Fix | Delete
if ( ! ( self::$instance instanceof self ) ) {
[96] Fix | Delete
self::$instance = new self();
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
return self::$instance;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Translate/set strings used in the option defaults.
[104] Fix | Delete
*
[105] Fix | Delete
* @return void
[106] Fix | Delete
*/
[107] Fix | Delete
public function translate_defaults() {
[108] Fix | Delete
self::$twitter_card_types['summary_large_image'] = __( 'Summary with large image', 'wordpress-seo' );
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Validate the option.
[113] Fix | Delete
*
[114] Fix | Delete
* @param array $dirty New value for the option.
[115] Fix | Delete
* @param array $clean Clean value for the option, normally the defaults.
[116] Fix | Delete
* @param array $old Old value of the option.
[117] Fix | Delete
*
[118] Fix | Delete
* @return array Validated clean value for the option to be saved to the database.
[119] Fix | Delete
*/
[120] Fix | Delete
protected function validate_option( $dirty, $clean, $old ) {
[121] Fix | Delete
[122] Fix | Delete
foreach ( $clean as $key => $value ) {
[123] Fix | Delete
switch ( $key ) {
[124] Fix | Delete
/* Text fields. */
[125] Fix | Delete
case 'og_frontpage_desc':
[126] Fix | Delete
case 'og_frontpage_title':
[127] Fix | Delete
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
[128] Fix | Delete
$clean[ $key ] = WPSEO_Utils::sanitize_text_field( $dirty[ $key ] );
[129] Fix | Delete
}
[130] Fix | Delete
break;
[131] Fix | Delete
[132] Fix | Delete
case 'og_default_image_id':
[133] Fix | Delete
case 'og_frontpage_image_id':
[134] Fix | Delete
if ( isset( $dirty[ $key ] ) ) {
[135] Fix | Delete
$clean[ $key ] = (int) $dirty[ $key ];
[136] Fix | Delete
[137] Fix | Delete
if ( $dirty[ $key ] === '' ) {
[138] Fix | Delete
$clean[ $key ] = $dirty[ $key ];
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
break;
[142] Fix | Delete
[143] Fix | Delete
/* URL text fields - no ftp allowed. */
[144] Fix | Delete
case 'facebook_site':
[145] Fix | Delete
case 'instagram_url':
[146] Fix | Delete
case 'linkedin_url':
[147] Fix | Delete
case 'myspace_url':
[148] Fix | Delete
case 'pinterest_url':
[149] Fix | Delete
case 'og_default_image':
[150] Fix | Delete
case 'og_frontpage_image':
[151] Fix | Delete
case 'youtube_url':
[152] Fix | Delete
case 'wikipedia_url':
[153] Fix | Delete
case 'mastodon_url':
[154] Fix | Delete
$this->validate_url( $key, $dirty, $old, $clean );
[155] Fix | Delete
break;
[156] Fix | Delete
[157] Fix | Delete
case 'pinterestverify':
[158] Fix | Delete
$this->validate_verification_string( $key, $dirty, $old, $clean );
[159] Fix | Delete
break;
[160] Fix | Delete
[161] Fix | Delete
/* Twitter user name. */
[162] Fix | Delete
case 'twitter_site':
[163] Fix | Delete
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
[164] Fix | Delete
$twitter_id = $this->validate_twitter_id( $dirty[ $key ] );
[165] Fix | Delete
[166] Fix | Delete
if ( $twitter_id ) {
[167] Fix | Delete
$clean[ $key ] = $twitter_id;
[168] Fix | Delete
}
[169] Fix | Delete
else {
[170] Fix | Delete
if ( isset( $old[ $key ] ) && $old[ $key ] !== '' ) {
[171] Fix | Delete
$twitter_id = sanitize_text_field( ltrim( $old[ $key ], '@' ) );
[172] Fix | Delete
if ( preg_match( '`^[A-Za-z0-9_]{1,25}$`', $twitter_id ) ) {
[173] Fix | Delete
$clean[ $key ] = $twitter_id;
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
if ( function_exists( 'add_settings_error' ) ) {
[177] Fix | Delete
add_settings_error(
[178] Fix | Delete
$this->group_name, // Slug title of the setting.
[179] Fix | Delete
$key, // Suffix-ID for the error message box.
[180] Fix | Delete
sprintf(
[181] Fix | Delete
/* translators: %s expands to a twitter user name. */
[182] Fix | Delete
__( '%s does not seem to be a valid Twitter Username. Please correct.', 'wordpress-seo' ),
[183] Fix | Delete
'<strong>' . esc_html( sanitize_text_field( $dirty[ $key ] ) ) . '</strong>'
[184] Fix | Delete
), // The error message.
[185] Fix | Delete
'error' // Message type.
[186] Fix | Delete
);
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
unset( $twitter_id );
[190] Fix | Delete
[191] Fix | Delete
Yoast_Input_Validation::add_dirty_value_to_settings_errors( $key, $dirty[ $key ] );
[192] Fix | Delete
}
[193] Fix | Delete
break;
[194] Fix | Delete
[195] Fix | Delete
case 'twitter_card_type':
[196] Fix | Delete
if ( isset( $dirty[ $key ], self::$twitter_card_types[ $dirty[ $key ] ] ) && $dirty[ $key ] !== '' ) {
[197] Fix | Delete
$clean[ $key ] = $dirty[ $key ];
[198] Fix | Delete
}
[199] Fix | Delete
break;
[200] Fix | Delete
[201] Fix | Delete
/* Boolean fields. */
[202] Fix | Delete
case 'opengraph':
[203] Fix | Delete
case 'twitter':
[204] Fix | Delete
$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
[205] Fix | Delete
break;
[206] Fix | Delete
[207] Fix | Delete
/* Array fields. */
[208] Fix | Delete
case 'other_social_urls':
[209] Fix | Delete
if ( isset( $dirty[ $key ] ) ) {
[210] Fix | Delete
$items = $dirty[ $key ];
[211] Fix | Delete
if ( ! is_array( $items ) ) {
[212] Fix | Delete
$items = json_decode( $dirty[ $key ], true );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
if ( is_array( $items ) ) {
[216] Fix | Delete
foreach ( $items as $item_key => $item ) {
[217] Fix | Delete
$validated_url = $this->validate_social_url( $item );
[218] Fix | Delete
[219] Fix | Delete
if ( $validated_url === false ) {
[220] Fix | Delete
// Restore the previous URL values, if any.
[221] Fix | Delete
$old_urls = ( isset( $old[ $key ] ) ) ? $old[ $key ] : [];
[222] Fix | Delete
foreach ( $old_urls as $old_item_key => $old_url ) {
[223] Fix | Delete
if ( $old_url !== '' ) {
[224] Fix | Delete
$url = WPSEO_Utils::sanitize_url( $old_url );
[225] Fix | Delete
if ( $url !== '' ) {
[226] Fix | Delete
$clean[ $key ][ $old_item_key ] = $url;
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
break;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
// The URL format is valid, let's sanitize it.
[234] Fix | Delete
$url = WPSEO_Utils::sanitize_url( $validated_url );
[235] Fix | Delete
if ( $url !== '' ) {
[236] Fix | Delete
$clean[ $key ][ $item_key ] = $url;
[237] Fix | Delete
}
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
break;
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
return $clean;
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Validates a social URL.
[251] Fix | Delete
*
[252] Fix | Delete
* @param string $url The url to be validated.
[253] Fix | Delete
*
[254] Fix | Delete
* @return string|false The validated URL or false if the URL is not valid.
[255] Fix | Delete
*/
[256] Fix | Delete
public function validate_social_url( $url ) {
[257] Fix | Delete
$validated_url = filter_var( WPSEO_Utils::sanitize_url( trim( $url ) ), FILTER_VALIDATE_URL );
[258] Fix | Delete
[259] Fix | Delete
return $validated_url;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
/**
[263] Fix | Delete
* Validates a twitter id.
[264] Fix | Delete
*
[265] Fix | Delete
* @param string $twitter_id The twitter id to be validated.
[266] Fix | Delete
* @param bool $strip_at_sign Whether or not to strip the `@` sign.
[267] Fix | Delete
*
[268] Fix | Delete
* @return string|false The validated twitter id or false if it is not valid.
[269] Fix | Delete
*/
[270] Fix | Delete
public function validate_twitter_id( $twitter_id, $strip_at_sign = true ) {
[271] Fix | Delete
$twitter_id = ( $strip_at_sign ) ? sanitize_text_field( ltrim( $twitter_id, '@' ) ) : sanitize_text_field( $twitter_id );
[272] Fix | Delete
[273] Fix | Delete
/*
[274] Fix | Delete
* From the Twitter documentation about twitter screen names:
[275] Fix | Delete
* Typically a maximum of 15 characters long, but some historical accounts
[276] Fix | Delete
* may exist with longer names.
[277] Fix | Delete
* A username can only contain alphanumeric characters (letters A-Z, numbers 0-9)
[278] Fix | Delete
* with the exception of underscores.
[279] Fix | Delete
*
[280] Fix | Delete
* @link https://support.twitter.com/articles/101299-why-can-t-i-register-certain-usernames
[281] Fix | Delete
*/
[282] Fix | Delete
if ( preg_match( '`^[A-Za-z0-9_]{1,25}$`', $twitter_id ) ) {
[283] Fix | Delete
return $twitter_id;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
if ( preg_match( '`^http(?:s)?://(?:www\.)?(?:twitter|x)\.com/(?P<handle>[A-Za-z0-9_]{1,25})/?$`', $twitter_id, $matches ) ) {
[287] Fix | Delete
return $matches['handle'];
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
return false;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Clean a given option value.
[295] Fix | Delete
*
[296] Fix | Delete
* @param array $option_value Old (not merged with defaults or filtered) option value to
[297] Fix | Delete
* clean according to the rules for this option.
[298] Fix | Delete
* @param string|null $current_version Optional. Version from which to upgrade, if not set,
[299] Fix | Delete
* version specific upgrades will be disregarded.
[300] Fix | Delete
* @param array|null $all_old_option_values Optional. Only used when importing old options to have
[301] Fix | Delete
* access to the real old values, in contrast to the saved ones.
[302] Fix | Delete
*
[303] Fix | Delete
* @return array Cleaned option.
[304] Fix | Delete
*/
[305] Fix | Delete
protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) {
[306] Fix | Delete
[307] Fix | Delete
/* Move options from very old option to this one. */
[308] Fix | Delete
$old_option = null;
[309] Fix | Delete
if ( isset( $all_old_option_values ) ) {
[310] Fix | Delete
// Ok, we have an import.
[311] Fix | Delete
if ( isset( $all_old_option_values['wpseo_indexation'] ) && is_array( $all_old_option_values['wpseo_indexation'] ) && $all_old_option_values['wpseo_indexation'] !== [] ) {
[312] Fix | Delete
$old_option = $all_old_option_values['wpseo_indexation'];
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
else {
[316] Fix | Delete
$old_option = get_option( 'wpseo_indexation' );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
if ( is_array( $old_option ) && $old_option !== [] ) {
[320] Fix | Delete
$move = [
[321] Fix | Delete
'opengraph',
[322] Fix | Delete
];
[323] Fix | Delete
foreach ( $move as $key ) {
[324] Fix | Delete
if ( isset( $old_option[ $key ] ) && ! isset( $option_value[ $key ] ) ) {
[325] Fix | Delete
$option_value[ $key ] = $old_option[ $key ];
[326] Fix | Delete
}
[327] Fix | Delete
}
[328] Fix | Delete
unset( $move, $key );
[329] Fix | Delete
}
[330] Fix | Delete
unset( $old_option );
[331] Fix | Delete
[332] Fix | Delete
return $option_value;
[333] Fix | Delete
}
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function