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
File: class-wpseo-meta.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Internals
[4] Fix | Delete
* @since 1.5.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
use Yoast\WP\SEO\Config\Schema_Types;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Schema\Article_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Repository;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* This class implements defaults and value validation for all WPSEO Post Meta values.
[13] Fix | Delete
*
[14] Fix | Delete
* Some guidelines:
[15] Fix | Delete
* - To update a meta value, you can just use update_post_meta() with the full (prefixed) meta key
[16] Fix | Delete
* or the convenience method WPSEO_Meta::set_value() with the internal key.
[17] Fix | Delete
* All updates will be automatically validated.
[18] Fix | Delete
* Meta values will only be saved to the database if they are *not* the same as the default to
[19] Fix | Delete
* keep database load low.
[20] Fix | Delete
* - To retrieve a WPSEO meta value, you **must** use WPSEO_Meta::get_value() which will always return a
[21] Fix | Delete
* string value, either the saved value or the default.
[22] Fix | Delete
* This method can also retrieve a complete set of WPSEO meta values for one specific post, see
[23] Fix | Delete
* the method documentation for the parameters.
[24] Fix | Delete
*
[25] Fix | Delete
* {@internal Unfortunately there isn't a filter available to hook into before returning the results
[26] Fix | Delete
* for get_post_meta(), get_post_custom() and the likes. That would have been the
[27] Fix | Delete
* preferred solution.}}
[28] Fix | Delete
*
[29] Fix | Delete
* {@internal All WP native get_meta() results get cached internally, so no need to cache locally.}}
[30] Fix | Delete
* {@internal Use $key when the key is the WPSEO internal name (without prefix), $meta_key when it
[31] Fix | Delete
* includes the prefix.}}
[32] Fix | Delete
*/
[33] Fix | Delete
class WPSEO_Meta {
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Prefix for all WPSEO meta values in the database.
[37] Fix | Delete
*
[38] Fix | Delete
* {@internal If at any point this would change, quite apart from an upgrade routine,
[39] Fix | Delete
* this also will need to be changed in the wpml-config.xml file.}}
[40] Fix | Delete
*
[41] Fix | Delete
* @var string
[42] Fix | Delete
*/
[43] Fix | Delete
public static $meta_prefix = '_yoast_wpseo_';
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Prefix for all WPSEO meta value form field names and ids.
[47] Fix | Delete
*
[48] Fix | Delete
* @var string
[49] Fix | Delete
*/
[50] Fix | Delete
public static $form_prefix = 'yoast_wpseo_';
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Allowed length of the meta description.
[54] Fix | Delete
*
[55] Fix | Delete
* @var int
[56] Fix | Delete
*/
[57] Fix | Delete
public static $meta_length = 156;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Reason the meta description is not the default length.
[61] Fix | Delete
*
[62] Fix | Delete
* @var string
[63] Fix | Delete
*/
[64] Fix | Delete
public static $meta_length_reason = '';
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Meta box field definitions for the meta box form.
[68] Fix | Delete
*
[69] Fix | Delete
* {@internal
[70] Fix | Delete
* - Titles, help texts, description text and option labels are added via a translate_meta_boxes() method
[71] Fix | Delete
* in the relevant child classes (WPSEO_Metabox and WPSEO_Social_admin) as they are only needed there.
[72] Fix | Delete
* - Beware: even though the meta keys are divided into subsets, they still have to be uniquely named!}}
[73] Fix | Delete
*
[74] Fix | Delete
* @var array
[75] Fix | Delete
* Array format:
[76] Fix | Delete
* (required) 'type' => (string) field type. i.e. text / textarea / checkbox /
[77] Fix | Delete
* radio / select / multiselect / upload etc.
[78] Fix | Delete
* (required) 'title' => (string) table row title.
[79] Fix | Delete
* (recommended) 'default_value' => (string|array) default value for the field.
[80] Fix | Delete
* IMPORTANT:
[81] Fix | Delete
* - if the field has options, the default has to be the
[82] Fix | Delete
* key of one of the options.
[83] Fix | Delete
* - if the field is a text field, the default **has** to be
[84] Fix | Delete
* an empty string as otherwise the user can't save
[85] Fix | Delete
* an empty value/delete the meta value.
[86] Fix | Delete
* - if the field is a checkbox, the only valid values
[87] Fix | Delete
* are 'on' or 'off'.
[88] Fix | Delete
* (semi-required) 'options' => (array) options for used with (multi-)select and radio
[89] Fix | Delete
* fields, required if that's the field type.
[90] Fix | Delete
* key = (string) value which will be saved to db.
[91] Fix | Delete
* value = (string) text label for the option.
[92] Fix | Delete
* (optional) 'autocomplete' => (bool) whether autocomplete is on for text fields,
[93] Fix | Delete
* defaults to true.
[94] Fix | Delete
* (optional) 'class' => (string) classname(s) to add to the actual <input> tag.
[95] Fix | Delete
* (optional) 'description' => (string) description to show underneath the field.
[96] Fix | Delete
* (optional) 'expl' => (string) label for a checkbox.
[97] Fix | Delete
* (optional) 'help' => (string) help text to show on mouse over ? image.
[98] Fix | Delete
* (optional) 'rows' => (int) number of rows for a textarea, defaults to 3.
[99] Fix | Delete
* (optional) 'placeholder' => (string) Currently only used by add-on plugins.
[100] Fix | Delete
* (optional) 'serialized' => (bool) whether the value is expected to be serialized,
[101] Fix | Delete
* i.e. an array or object, defaults to false.
[102] Fix | Delete
* Currently only used by add-on plugins.
[103] Fix | Delete
*/
[104] Fix | Delete
public static $meta_fields = [
[105] Fix | Delete
'general' => [
[106] Fix | Delete
'focuskw' => [
[107] Fix | Delete
'type' => 'hidden',
[108] Fix | Delete
'title' => '',
[109] Fix | Delete
],
[110] Fix | Delete
'title' => [
[111] Fix | Delete
'type' => 'hidden',
[112] Fix | Delete
'title' => '', // Translation added later.
[113] Fix | Delete
'default_value' => '',
[114] Fix | Delete
'description' => '', // Translation added later.
[115] Fix | Delete
'help' => '', // Translation added later.
[116] Fix | Delete
],
[117] Fix | Delete
'metadesc' => [
[118] Fix | Delete
'type' => 'hidden',
[119] Fix | Delete
'title' => '', // Translation added later.
[120] Fix | Delete
'default_value' => '',
[121] Fix | Delete
'class' => 'metadesc',
[122] Fix | Delete
'rows' => 2,
[123] Fix | Delete
'description' => '', // Translation added later.
[124] Fix | Delete
'help' => '', // Translation added later.
[125] Fix | Delete
],
[126] Fix | Delete
'linkdex' => [
[127] Fix | Delete
'type' => 'hidden',
[128] Fix | Delete
'title' => 'linkdex',
[129] Fix | Delete
'default_value' => '0',
[130] Fix | Delete
'description' => '',
[131] Fix | Delete
],
[132] Fix | Delete
'content_score' => [
[133] Fix | Delete
'type' => 'hidden',
[134] Fix | Delete
'title' => 'content_score',
[135] Fix | Delete
'default_value' => '0',
[136] Fix | Delete
'description' => '',
[137] Fix | Delete
],
[138] Fix | Delete
'inclusive_language_score' => [
[139] Fix | Delete
'type' => 'hidden',
[140] Fix | Delete
'title' => 'inclusive_language_score',
[141] Fix | Delete
'default_value' => '0',
[142] Fix | Delete
'description' => '',
[143] Fix | Delete
],
[144] Fix | Delete
'is_cornerstone' => [
[145] Fix | Delete
'type' => 'hidden',
[146] Fix | Delete
'title' => 'is_cornerstone',
[147] Fix | Delete
'default_value' => 'false',
[148] Fix | Delete
'description' => '',
[149] Fix | Delete
],
[150] Fix | Delete
],
[151] Fix | Delete
'advanced' => [
[152] Fix | Delete
'meta-robots-noindex' => [
[153] Fix | Delete
'type' => 'hidden',
[154] Fix | Delete
'title' => '', // Translation added later.
[155] Fix | Delete
'default_value' => '0', // = post-type default.
[156] Fix | Delete
'options' => [
[157] Fix | Delete
'0' => '', // Post type default - translation added later.
[158] Fix | Delete
'2' => '', // Index - translation added later.
[159] Fix | Delete
'1' => '', // No-index - translation added later.
[160] Fix | Delete
],
[161] Fix | Delete
],
[162] Fix | Delete
'meta-robots-nofollow' => [
[163] Fix | Delete
'type' => 'hidden',
[164] Fix | Delete
'title' => '', // Translation added later.
[165] Fix | Delete
'default_value' => '0', // = follow.
[166] Fix | Delete
'options' => [
[167] Fix | Delete
'0' => '', // Follow - translation added later.
[168] Fix | Delete
'1' => '', // No-follow - translation added later.
[169] Fix | Delete
],
[170] Fix | Delete
],
[171] Fix | Delete
'meta-robots-adv' => [
[172] Fix | Delete
'type' => 'hidden',
[173] Fix | Delete
'title' => '', // Translation added later.
[174] Fix | Delete
'default_value' => '',
[175] Fix | Delete
'description' => '', // Translation added later.
[176] Fix | Delete
'options' => [
[177] Fix | Delete
'noimageindex' => '', // Translation added later.
[178] Fix | Delete
'noarchive' => '', // Translation added later.
[179] Fix | Delete
'nosnippet' => '', // Translation added later.
[180] Fix | Delete
],
[181] Fix | Delete
],
[182] Fix | Delete
'bctitle' => [
[183] Fix | Delete
'type' => 'hidden',
[184] Fix | Delete
'title' => '', // Translation added later.
[185] Fix | Delete
'default_value' => '',
[186] Fix | Delete
'description' => '', // Translation added later.
[187] Fix | Delete
],
[188] Fix | Delete
'canonical' => [
[189] Fix | Delete
'type' => 'hidden',
[190] Fix | Delete
'title' => '', // Translation added later.
[191] Fix | Delete
'default_value' => '',
[192] Fix | Delete
'description' => '', // Translation added later.
[193] Fix | Delete
],
[194] Fix | Delete
'redirect' => [
[195] Fix | Delete
'type' => 'url',
[196] Fix | Delete
'title' => '', // Translation added later.
[197] Fix | Delete
'default_value' => '',
[198] Fix | Delete
'description' => '', // Translation added later.
[199] Fix | Delete
],
[200] Fix | Delete
],
[201] Fix | Delete
'social' => [],
[202] Fix | Delete
'schema' => [
[203] Fix | Delete
'schema_page_type' => [
[204] Fix | Delete
'type' => 'hidden',
[205] Fix | Delete
'title' => '',
[206] Fix | Delete
'options' => Schema_Types::PAGE_TYPES,
[207] Fix | Delete
],
[208] Fix | Delete
'schema_article_type' => [
[209] Fix | Delete
'type' => 'hidden',
[210] Fix | Delete
'title' => '',
[211] Fix | Delete
'hide_on_pages' => true,
[212] Fix | Delete
'options' => Schema_Types::ARTICLE_TYPES,
[213] Fix | Delete
],
[214] Fix | Delete
],
[215] Fix | Delete
/* Fields we should validate & save, but not show on any form. */
[216] Fix | Delete
'non_form' => [
[217] Fix | Delete
'linkdex' => [
[218] Fix | Delete
'type' => null,
[219] Fix | Delete
'default_value' => '0',
[220] Fix | Delete
],
[221] Fix | Delete
'zapier_trigger_sent' => [
[222] Fix | Delete
'type' => null,
[223] Fix | Delete
'default_value' => '0',
[224] Fix | Delete
],
[225] Fix | Delete
],
[226] Fix | Delete
];
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Helper property - reverse index of the definition array.
[230] Fix | Delete
*
[231] Fix | Delete
* Format: [full meta key including prefix] => array
[232] Fix | Delete
* ['subset'] => (string) primary index
[233] Fix | Delete
* ['key'] => (string) internal key
[234] Fix | Delete
*
[235] Fix | Delete
* @var array
[236] Fix | Delete
*/
[237] Fix | Delete
public static $fields_index = [];
[238] Fix | Delete
[239] Fix | Delete
/**
[240] Fix | Delete
* Helper property - array containing only the defaults in the format:
[241] Fix | Delete
* [full meta key including prefix] => (string) default value
[242] Fix | Delete
*
[243] Fix | Delete
* @var array
[244] Fix | Delete
*/
[245] Fix | Delete
public static $defaults = [];
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Helper property to define the social network meta field definitions - networks.
[249] Fix | Delete
*
[250] Fix | Delete
* @var array
[251] Fix | Delete
*/
[252] Fix | Delete
private static $social_networks = [
[253] Fix | Delete
'opengraph' => 'opengraph',
[254] Fix | Delete
'twitter' => 'twitter',
[255] Fix | Delete
];
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Helper property to define the social network meta field definitions - fields and their type.
[259] Fix | Delete
*
[260] Fix | Delete
* @var array
[261] Fix | Delete
*/
[262] Fix | Delete
private static $social_fields = [
[263] Fix | Delete
'title' => 'hidden',
[264] Fix | Delete
'description' => 'hidden',
[265] Fix | Delete
'image' => 'hidden',
[266] Fix | Delete
'image-id' => 'hidden',
[267] Fix | Delete
];
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Register our actions and filters.
[271] Fix | Delete
*
[272] Fix | Delete
* @return void
[273] Fix | Delete
*/
[274] Fix | Delete
public static function init() {
[275] Fix | Delete
foreach ( self::$social_networks as $option => $network ) {
[276] Fix | Delete
if ( WPSEO_Options::get( $option, false ) === true ) {
[277] Fix | Delete
foreach ( self::$social_fields as $box => $type ) {
[278] Fix | Delete
self::$meta_fields['social'][ $network . '-' . $box ] = [
[279] Fix | Delete
'type' => $type,
[280] Fix | Delete
'title' => '', // Translation added later.
[281] Fix | Delete
'default_value' => '',
[282] Fix | Delete
'description' => '', // Translation added later.
[283] Fix | Delete
];
[284] Fix | Delete
}
[285] Fix | Delete
}
[286] Fix | Delete
}
[287] Fix | Delete
unset( $option, $network, $box, $type );
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Allow add-on plugins to register their meta fields for management by this class.
[291] Fix | Delete
* Calls to add_filter() must be made before plugins_loaded prio 14.
[292] Fix | Delete
*/
[293] Fix | Delete
$extra_fields = apply_filters( 'add_extra_wpseo_meta_fields', [] );
[294] Fix | Delete
if ( is_array( $extra_fields ) ) {
[295] Fix | Delete
self::$meta_fields = self::array_merge_recursive_distinct( $extra_fields, self::$meta_fields );
[296] Fix | Delete
}
[297] Fix | Delete
unset( $extra_fields );
[298] Fix | Delete
[299] Fix | Delete
foreach ( self::$meta_fields as $subset => $field_group ) {
[300] Fix | Delete
foreach ( $field_group as $key => $field_def ) {
[301] Fix | Delete
[302] Fix | Delete
register_meta(
[303] Fix | Delete
'post',
[304] Fix | Delete
self::$meta_prefix . $key,
[305] Fix | Delete
[ 'sanitize_callback' => [ self::class, 'sanitize_post_meta' ] ]
[306] Fix | Delete
);
[307] Fix | Delete
[308] Fix | Delete
// Set the $fields_index property for efficiency.
[309] Fix | Delete
self::$fields_index[ self::$meta_prefix . $key ] = [
[310] Fix | Delete
'subset' => $subset,
[311] Fix | Delete
'key' => $key,
[312] Fix | Delete
];
[313] Fix | Delete
[314] Fix | Delete
// Set the $defaults property for efficiency.
[315] Fix | Delete
if ( isset( $field_def['default_value'] ) ) {
[316] Fix | Delete
self::$defaults[ self::$meta_prefix . $key ] = $field_def['default_value'];
[317] Fix | Delete
}
[318] Fix | Delete
else {
[319] Fix | Delete
// Meta will always be a string, so let's make the meta meta default also a string.
[320] Fix | Delete
self::$defaults[ self::$meta_prefix . $key ] = '';
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
unset( $subset, $field_group, $key, $field_def );
[325] Fix | Delete
[326] Fix | Delete
self::filter_schema_article_types();
[327] Fix | Delete
[328] Fix | Delete
add_filter( 'update_post_metadata', [ self::class, 'remove_meta_if_default' ], 10, 5 );
[329] Fix | Delete
add_filter( 'add_post_metadata', [ self::class, 'dont_save_meta_if_default' ], 10, 4 );
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Retrieve the meta box form field definitions for the given tab and post type.
[334] Fix | Delete
*
[335] Fix | Delete
* @param string $tab Tab for which to retrieve the field definitions.
[336] Fix | Delete
* @param string $post_type Post type of the current post.
[337] Fix | Delete
*
[338] Fix | Delete
* @return array Array containing the meta box field definitions.
[339] Fix | Delete
*/
[340] Fix | Delete
public static function get_meta_field_defs( $tab, $post_type = 'post' ) {
[341] Fix | Delete
if ( ! isset( self::$meta_fields[ $tab ] ) ) {
[342] Fix | Delete
return [];
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
$field_defs = self::$meta_fields[ $tab ];
[346] Fix | Delete
[347] Fix | Delete
switch ( $tab ) {
[348] Fix | Delete
case 'non-form':
[349] Fix | Delete
// Prevent non-form fields from being passed to forms.
[350] Fix | Delete
$field_defs = [];
[351] Fix | Delete
break;
[352] Fix | Delete
[353] Fix | Delete
case 'advanced':
[354] Fix | Delete
global $post;
[355] Fix | Delete
[356] Fix | Delete
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) && WPSEO_Options::get( 'disableadvanced_meta' ) ) {
[357] Fix | Delete
return [];
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
$post_type = '';
[361] Fix | Delete
if ( isset( $post->post_type ) ) {
[362] Fix | Delete
$post_type = $post->post_type;
[363] Fix | Delete
}
[364] Fix | Delete
elseif ( ! isset( $post->post_type ) && isset( $_GET['post_type'] ) ) {
[365] Fix | Delete
$post_type = sanitize_text_field( $_GET['post_type'] );
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
if ( $post_type === '' ) {
[369] Fix | Delete
return [];
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/* Adjust the no-index text strings based on the post type. */
[373] Fix | Delete
$post_type_object = get_post_type_object( $post_type );
[374] Fix | Delete
[375] Fix | Delete
$field_defs['meta-robots-noindex']['title'] = sprintf( $field_defs['meta-robots-noindex']['title'], $post_type_object->labels->singular_name );
[376] Fix | Delete
$field_defs['meta-robots-noindex']['options']['0'] = sprintf( $field_defs['meta-robots-noindex']['options']['0'], ( ( WPSEO_Options::get( 'noindex-' . $post_type, false ) === true ) ? $field_defs['meta-robots-noindex']['options']['1'] : $field_defs['meta-robots-noindex']['options']['2'] ), $post_type_object->label );
[377] Fix | Delete
$field_defs['meta-robots-nofollow']['title'] = sprintf( $field_defs['meta-robots-nofollow']['title'], $post_type_object->labels->singular_name );
[378] Fix | Delete
[379] Fix | Delete
/* Don't show the breadcrumb title field if breadcrumbs aren't enabled. */
[380] Fix | Delete
if ( WPSEO_Options::get( 'breadcrumbs-enable', false ) !== true && ! current_theme_supports( 'yoast-seo-breadcrumbs' ) ) {
[381] Fix | Delete
unset( $field_defs['bctitle'] );
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
if ( empty( $post->ID ) || ( ! empty( $post->ID ) && self::get_value( 'redirect', $post->ID ) === '' ) ) {
[385] Fix | Delete
unset( $field_defs['redirect'] );
[386] Fix | Delete
}
[387] Fix | Delete
break;
[388] Fix | Delete
[389] Fix | Delete
case 'schema':
[390] Fix | Delete
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) && WPSEO_Options::get( 'disableadvanced_meta' ) ) {
[391] Fix | Delete
return [];
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
$field_defs['schema_page_type']['default'] = WPSEO_Options::get( 'schema-page-type-' . $post_type );
[395] Fix | Delete
[396] Fix | Delete
$article_helper = new Article_Helper();
[397] Fix | Delete
if ( $article_helper->is_article_post_type( $post_type ) ) {
[398] Fix | Delete
$default_schema_article_type = WPSEO_Options::get( 'schema-article-type-' . $post_type );
[399] Fix | Delete
[400] Fix | Delete
/** This filter is documented in inc/options/class-wpseo-option-titles.php */
[401] Fix | Delete
$allowed_article_types = apply_filters( 'wpseo_schema_article_types', Schema_Types::ARTICLE_TYPES );
[402] Fix | Delete
[403] Fix | Delete
if ( ! array_key_exists( $default_schema_article_type, $allowed_article_types ) ) {
[404] Fix | Delete
$default_schema_article_type = WPSEO_Options::get_default( 'wpseo_titles', 'schema-article-type-' . $post_type );
[405] Fix | Delete
}
[406] Fix | Delete
$field_defs['schema_article_type']['default'] = $default_schema_article_type;
[407] Fix | Delete
}
[408] Fix | Delete
else {
[409] Fix | Delete
unset( $field_defs['schema_article_type'] );
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
break;
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
/**
[416] Fix | Delete
* Filter the WPSEO metabox form field definitions for a tab.
[417] Fix | Delete
* {tab} can be 'general', 'advanced' or 'social'.
[418] Fix | Delete
*
[419] Fix | Delete
* @param array $field_defs Metabox form field definitions.
[420] Fix | Delete
* @param string $post_type Post type of the post the metabox is for, defaults to 'post'.
[421] Fix | Delete
*
[422] Fix | Delete
* @return array
[423] Fix | Delete
*/
[424] Fix | Delete
return apply_filters( 'wpseo_metabox_entries_' . $tab, $field_defs, $post_type );
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* Validate the post meta values.
[429] Fix | Delete
*
[430] Fix | Delete
* @param mixed $meta_value The new value.
[431] Fix | Delete
* @param string $meta_key The full meta key (including prefix).
[432] Fix | Delete
*
[433] Fix | Delete
* @return string Validated meta value.
[434] Fix | Delete
*/
[435] Fix | Delete
public static function sanitize_post_meta( $meta_value, $meta_key ) {
[436] Fix | Delete
$field_def = self::$meta_fields[ self::$fields_index[ $meta_key ]['subset'] ][ self::$fields_index[ $meta_key ]['key'] ];
[437] Fix | Delete
$clean = self::$defaults[ $meta_key ];
[438] Fix | Delete
[439] Fix | Delete
switch ( true ) {
[440] Fix | Delete
case ( $meta_key === self::$meta_prefix . 'linkdex' ):
[441] Fix | Delete
$int = WPSEO_Utils::validate_int( $meta_value );
[442] Fix | Delete
if ( $int !== false && $int >= 0 ) {
[443] Fix | Delete
$clean = strval( $int ); // Convert to string to make sure default check works.
[444] Fix | Delete
}
[445] Fix | Delete
break;
[446] Fix | Delete
[447] Fix | Delete
case ( $field_def['type'] === 'checkbox' ):
[448] Fix | Delete
// Only allow value if it's one of the predefined options.
[449] Fix | Delete
if ( in_array( $meta_value, [ 'on', 'off' ], true ) ) {
[450] Fix | Delete
$clean = $meta_value;
[451] Fix | Delete
}
[452] Fix | Delete
break;
[453] Fix | Delete
[454] Fix | Delete
case ( $field_def['type'] === 'select' || $field_def['type'] === 'radio' ):
[455] Fix | Delete
// Only allow value if it's one of the predefined options.
[456] Fix | Delete
if ( isset( $field_def['options'][ $meta_value ] ) ) {
[457] Fix | Delete
$clean = $meta_value;
[458] Fix | Delete
}
[459] Fix | Delete
break;
[460] Fix | Delete
[461] Fix | Delete
case ( $field_def['type'] === 'hidden' && $meta_key === self::$meta_prefix . 'meta-robots-adv' ):
[462] Fix | Delete
$clean = self::validate_meta_robots_adv( $meta_value );
[463] Fix | Delete
break;
[464] Fix | Delete
[465] Fix | Delete
case ( $field_def['type'] === 'url' || $meta_key === self::$meta_prefix . 'canonical' ):
[466] Fix | Delete
// Validate as url(-part).
[467] Fix | Delete
$url = WPSEO_Utils::sanitize_url( $meta_value );
[468] Fix | Delete
if ( $url !== '' ) {
[469] Fix | Delete
$clean = $url;
[470] Fix | Delete
}
[471] Fix | Delete
break;
[472] Fix | Delete
[473] Fix | Delete
case ( $field_def['type'] === 'upload' && in_array( $meta_key, [ self::$meta_prefix . 'opengraph-image', self::$meta_prefix . 'twitter-image' ], true ) ):
[474] Fix | Delete
// Validate as url.
[475] Fix | Delete
$url = WPSEO_Utils::sanitize_url( $meta_value, [ 'http', 'https', 'ftp', 'ftps' ] );
[476] Fix | Delete
if ( $url !== '' ) {
[477] Fix | Delete
$clean = $url;
[478] Fix | Delete
}
[479] Fix | Delete
break;
[480] Fix | Delete
[481] Fix | Delete
case ( $field_def['type'] === 'hidden' && $meta_key === self::$meta_prefix . 'is_cornerstone' ):
[482] Fix | Delete
$clean = $meta_value;
[483] Fix | Delete
[484] Fix | Delete
/*
[485] Fix | Delete
* This used to be a checkbox, then became a hidden input.
[486] Fix | Delete
* To make sure the value remains consistent, we cast 'true' to '1'.
[487] Fix | Delete
*/
[488] Fix | Delete
if ( $meta_value === 'true' ) {
[489] Fix | Delete
$clean = '1';
[490] Fix | Delete
}
[491] Fix | Delete
break;
[492] Fix | Delete
[493] Fix | Delete
case ( $field_def['type'] === 'hidden' && isset( $field_def['options'] ) ):
[494] Fix | Delete
// Only allow value if it's one of the predefined options.
[495] Fix | Delete
if ( isset( $field_def['options'][ $meta_value ] ) ) {
[496] Fix | Delete
$clean = $meta_value;
[497] Fix | Delete
}
[498] Fix | Delete
break;
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function