the prioritisation is correct.
*
* @param array|string $meta_value The value to validate.
*
* @return string Clean value.
*/
public static function validate_meta_robots_adv( $meta_value ) {
$clean = self::$meta_fields['advanced']['meta-robots-adv']['default_value'];
$options = self::$meta_fields['advanced']['meta-robots-adv']['options'];
if ( is_string( $meta_value ) ) {
$meta_value = explode( ',', $meta_value );
}
if ( is_array( $meta_value ) && $meta_value !== [] ) {
$meta_value = array_map( 'trim', $meta_value );
// Individual selected entries.
$cleaning = [];
foreach ( $meta_value as $value ) {
if ( isset( $options[ $value ] ) ) {
$cleaning[] = $value;
}
}
if ( $cleaning !== [] ) {
$clean = implode( ',', $cleaning );
}
unset( $cleaning, $value );
}
return $clean;
}
/**
* Prevent saving of default values and remove potential old value from the database if replaced by a default.
*
* @param bool $check The current status to allow updating metadata for the given type.
* @param int $object_id ID of the current object for which the meta is being updated.
* @param string $meta_key The full meta key (including prefix).
* @param string $meta_value New meta value.
* @param string $prev_value The old meta value.
*
* @return bool|null True = stop saving, null = continue saving.
*/
public static function remove_meta_if_default( $check, $object_id, $meta_key, $meta_value, $prev_value = '' ) {
/* If it's one of our meta fields, check against default. */
if ( isset( self::$fields_index[ $meta_key ] ) && self::meta_value_is_default( $meta_key, $meta_value ) === true ) {
if ( $prev_value !== '' ) {
delete_post_meta( $object_id, $meta_key, $prev_value );
}
else {
delete_post_meta( $object_id, $meta_key );
}
return true; // Stop saving the value.
}
return $check; // Go on with the normal execution (update) in meta.php.
}
/**
* Prevent adding of default values to the database.
*
* @param bool $check The current status to allow adding metadata for the given type.
* @param int $object_id ID of the current object for which the meta is being added.
* @param string $meta_key The full meta key (including prefix).
* @param string $meta_value New meta value.
*
* @return bool|null True = stop saving, null = continue saving.
*/
public static function dont_save_meta_if_default( $check, $object_id, $meta_key, $meta_value ) {
/* If it's one of our meta fields, check against default. */
if ( isset( self::$fields_index[ $meta_key ] ) && self::meta_value_is_default( $meta_key, $meta_value ) === true ) {
return true; // Stop saving the value.
}
return $check; // Go on with the normal execution (add) in meta.php.
}
/**
* Is the given meta value the same as the default value ?
*
* @param string $meta_key The full meta key (including prefix).
* @param mixed $meta_value The value to check.
*
* @return bool
*/
public static function meta_value_is_default( $meta_key, $meta_value ) {
return ( isset( self::$defaults[ $meta_key ] ) && $meta_value === self::$defaults[ $meta_key ] );
}
/**
* Get a custom post meta value.
*
* Returns the default value if the meta value has not been set.
*
* {@internal Unfortunately there isn't a filter available to hook into before returning
* the results for get_post_meta(), get_post_custom() and the likes. That
* would have been the preferred solution.}}
*
* @param string $key Internal key of the value to get (without prefix).
* @param int $postid Post ID of the post to get the value for.
*
* @return string All 'normal' values returned from get_post_meta() are strings.
* Objects and arrays are possible, but not used by this plugin
* and therefore discarted (except when the special 'serialized' field def
* value is set to true - only used by add-on plugins for now).
* Will return the default value if no value was found.
* Will return empty string if no default was found (not one of our keys) or
* if the post does not exist.
*/
public static function get_value( $key, $postid = 0 ) {
global $post;
$postid = absint( $postid );
if ( $postid === 0 ) {
if ( ( isset( $post ) && is_object( $post ) ) && ( isset( $post->post_status ) && $post->post_status !== 'auto-draft' ) ) {
$postid = $post->ID;
}
else {
return '';
}
}
$custom = get_post_custom( $postid ); // Array of strings or empty array.
$table_key = self::$meta_prefix . $key;
// Populate the field_def using the field_index lookup array.
$field_def = [];
if ( isset( self::$fields_index[ $table_key ] ) ) {
$field_def = self::$meta_fields[ self::$fields_index[ $table_key ]['subset'] ][ self::$fields_index[ $table_key ]['key'] ];
}
// Check if we have a custom post meta entry.
if ( isset( $custom[ $table_key ][0] ) ) {
$unserialized = maybe_unserialize( $custom[ $table_key ][0] );
// Check if it is already unserialized.
if ( $custom[ $table_key ][0] === $unserialized ) {
return $custom[ $table_key ][0];
}
// Check whether we need to unserialize it.
if ( isset( $field_def['serialized'] ) && $field_def['serialized'] === true ) {
// Ok, serialize value expected/allowed.
return $unserialized;
}
}
// Meta was either not found or found, but object/array while not allowed to be.
if ( isset( self::$defaults[ self::$meta_prefix . $key ] ) ) {
// Update the default value to the current post type.
switch ( $key ) {
case 'schema_page_type':
case 'schema_article_type':
return '';
}
return self::$defaults[ self::$meta_prefix . $key ];
}
/*
* Shouldn't ever happen, means not one of our keys as there will always be a default available
* for all our keys.
*/
return '';
}
/**
* Update a meta value for a post.
*
* @param string $key The internal key of the meta value to change (without prefix).
* @param mixed $meta_value The value to set the meta to.
* @param int $post_id The ID of the post to change the meta for.
*
* @return bool Whether the value was changed.
*/
public static function set_value( $key, $meta_value, $post_id ) {
/*
* Slash the data, because `update_metadata` will unslash it and we have already unslashed it.
* Related issue: https://github.com/Yoast/YoastSEO.js/issues/2158
*/
$meta_value = wp_slash( $meta_value );
return update_post_meta( $post_id, self::$meta_prefix . $key, $meta_value );
}
/**
* Deletes a meta value for a post.
*
* @param string $key The internal key of the meta value to change (without prefix).
* @param int $post_id The ID of the post to delete the meta for.
*
* @return bool Whether the delete was successful or not.
*/
public static function delete( $key, $post_id ) {
return delete_post_meta( $post_id, self::$meta_prefix . $key );
}
/**
* Used for imports, this functions imports the value of $old_metakey into $new_metakey for those post
* where no WPSEO meta data has been set.
* Optionally deletes the $old_metakey values.
*
* @param string $old_metakey The old key of the meta value.
* @param string $new_metakey The new key, usually the WPSEO meta key (including prefix).
* @param bool $delete_old Whether to delete the old meta key/value-sets.
*
* @return void
*/
public static function replace_meta( $old_metakey, $new_metakey, $delete_old = false ) {
global $wpdb;
/*
* Get only those rows where no wpseo meta values exist for the same post
* (with the exception of linkdex as that will be set independently of whether the post has been edited).
*
* {@internal Query is pretty well optimized this way.}}
*/
$query = $wpdb->prepare(
"
SELECT `a`.*
FROM {$wpdb->postmeta} AS a
WHERE `a`.`meta_key` = %s
AND NOT EXISTS (
SELECT DISTINCT `post_id` , count( `meta_id` ) AS count
FROM {$wpdb->postmeta} AS b
WHERE `a`.`post_id` = `b`.`post_id`
AND `meta_key` LIKE %s
AND `meta_key` <> %s
GROUP BY `post_id`
)
;",
$old_metakey,
$wpdb->esc_like( self::$meta_prefix . '%' ),
self::$meta_prefix . 'linkdex'
);
$oldies = $wpdb->get_results( $query );
if ( is_array( $oldies ) && $oldies !== [] ) {
foreach ( $oldies as $old ) {
update_post_meta( $old->post_id, $new_metakey, $old->meta_value );
}
}
// Delete old keys.
if ( $delete_old === true ) {
delete_post_meta_by_key( $old_metakey );
}
}
/**
* General clean-up of the saved meta values.
* - Remove potentially lingering old meta keys;
* - Remove all default and invalid values.
*
* @return void
*/
public static function clean_up() {
global $wpdb;
/*
* Clean up '_yoast_wpseo_meta-robots'.
*
* Retrieve all '_yoast_wpseo_meta-robots' meta values and convert if no new values found.
*
* {@internal Query is pretty well optimized this way.}}
*
* @todo [JRF => Yoast] Find out all possible values which the old '_yoast_wpseo_meta-robots' could contain
* to convert the data correctly.
*/
$query = $wpdb->prepare(
"
SELECT `a`.*
FROM {$wpdb->postmeta} AS a
WHERE `a`.`meta_key` = %s
AND NOT EXISTS (
SELECT DISTINCT `post_id` , count( `meta_id` ) AS count
FROM {$wpdb->postmeta} AS b
WHERE `a`.`post_id` = `b`.`post_id`
AND ( `meta_key` = %s
OR `meta_key` = %s )
GROUP BY `post_id`
)
;",
self::$meta_prefix . 'meta-robots',
self::$meta_prefix . 'meta-robots-noindex',
self::$meta_prefix . 'meta-robots-nofollow'
);
$oldies = $wpdb->get_results( $query );
if ( is_array( $oldies ) && $oldies !== [] ) {
foreach ( $oldies as $old ) {
$old_values = explode( ',', $old->meta_value );
foreach ( $old_values as $value ) {
if ( $value === 'noindex' ) {
update_post_meta( $old->post_id, self::$meta_prefix . 'meta-robots-noindex', 1 );
}
elseif ( $value === 'nofollow' ) {
update_post_meta( $old->post_id, self::$meta_prefix . 'meta-robots-nofollow', 1 );
}
}
}
}
unset( $query, $oldies, $old, $old_values, $value );
// Delete old keys.
delete_post_meta_by_key( self::$meta_prefix . 'meta-robots' );
/*
* Remove all default values and (most) invalid option values.
* Invalid option values for the multiselect (meta-robots-adv) field will be dealt with seperately.
*
* {@internal Some of the defaults have changed in v1.5, but as the defaults will
* be removed and new defaults will now automatically be passed when no
* data found, this update is automatic (as long as we remove the old
* values which we do in the below routine).}}
*
* {@internal Unfortunately we can't use the normal delete_meta() with key/value combination
* as '' (empty string) values will be ignored and would result in all metas
* with that key being deleted, not just the empty fields.
* Still, the below implementation is largely based on the delete_meta() function.}}
*/
$query = [];
foreach ( self::$meta_fields as $subset => $field_group ) {
foreach ( $field_group as $key => $field_def ) {
if ( ! isset( $field_def['default_value'] ) ) {
continue;
}
if ( isset( $field_def['options'] ) && is_array( $field_def['options'] ) && $field_def['options'] !== [] ) {
$valid = $field_def['options'];
// Remove the default value from the valid options.
unset( $valid[ $field_def['default_value'] ] );
$valid = array_keys( $valid );
$query[] = $wpdb->prepare(
"( meta_key = %s AND meta_value NOT IN ( '" . implode( "','", esc_sql( $valid ) ) . "' ) )",
self::$meta_prefix . $key
);
unset( $valid );
}
elseif ( is_string( $field_def['default_value'] ) && $field_def['default_value'] !== '' ) {
$query[] = $wpdb->prepare(
'( meta_key = %s AND meta_value = %s )',
self::$meta_prefix . $key,
$field_def['default_value']
);
}
else {
$query[] = $wpdb->prepare(
"( meta_key = %s AND meta_value = '' )",
self::$meta_prefix . $key
);
}
}
}
unset( $subset, $field_group, $key, $field_def );
$query = "SELECT meta_id FROM {$wpdb->postmeta} WHERE " . implode( ' OR ', $query ) . ';';
$meta_ids = $wpdb->get_col( $query );
if ( is_array( $meta_ids ) && $meta_ids !== [] ) {
// WP native action.
do_action( 'delete_post_meta', $meta_ids, null, null, null );
$query = "DELETE FROM {$wpdb->postmeta} WHERE meta_id IN( " . implode( ',', $meta_ids ) . ' )';
$count = $wpdb->query( $query );
if ( $count ) {
foreach ( $meta_ids as $object_id ) {
wp_cache_delete( $object_id, 'post_meta' );
}
// WP native action.
do_action( 'deleted_post_meta', $meta_ids, null, null, null );
}
}
unset( $query, $meta_ids, $count, $object_id );
/*
* Deal with the multiselect (meta-robots-adv) field.
*
* Removes invalid option combinations, such as 'none,noarchive'.
*
* Default values have already been removed, so we should have a small result set and
* (hopefully) even smaller set of invalid results.
*/
$query = $wpdb->prepare(
"SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s",
self::$meta_prefix . 'meta-robots-adv'
);
$oldies = $wpdb->get_results( $query );
if ( is_array( $oldies ) && $oldies !== [] ) {
foreach ( $oldies as $old ) {
$clean = self::validate_meta_robots_adv( $old->meta_value );
if ( $clean !== $old->meta_value ) {
if ( $clean !== self::$meta_fields['advanced']['meta-robots-adv']['default_value'] ) {
update_metadata_by_mid( 'post', $old->meta_id, $clean );
}
else {
delete_metadata_by_mid( 'post', $old->meta_id );
}
}
}
}
unset( $query, $oldies, $old, $clean );
do_action( 'wpseo_meta_clean_up' );
}
/**
* Recursively merge a variable number of arrays, using the left array as base,
* giving priority to the right array.
*
* Difference with native array_merge_recursive():
* array_merge_recursive converts values with duplicate keys to arrays rather than
* overwriting the value in the first array with the duplicate value in the second array.
*
* array_merge_recursive_distinct does not change the data types of the values in the arrays.
* Matching keys' values in the second array overwrite those in the first array, as is the
* case with array_merge.
*
* Freely based on information found on http://www.php.net/manual/en/function.array-merge-recursive.php
*
* {@internal Should be moved to a general utility class.}}
*
* @return array
*/
public static function array_merge_recursive_distinct() {
$arrays = func_get_args();
if ( count( $arrays ) < 2 ) {
if ( $arrays === [] ) {
return [];
}
else {
return $arrays[0];
}
}
$merged = array_shift( $arrays );
foreach ( $arrays as $array ) {
foreach ( $array as $key => $value ) {
if ( is_array( $value ) && ( isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) ) {
$merged[ $key ] = self::array_merge_recursive_distinct( $merged[ $key ], $value );
}
else {
$merged[ $key ] = $value;
}
}
unset( $key, $value );
}
return $merged;
}
/**
* Counts the total of all the keywords being used for posts except the given one.
*
* @param string $keyword The keyword to be counted.
* @param int $post_id The id of the post to which the keyword belongs.
*
* @return array
*/
public static function keyword_usage( $keyword, $post_id ) {
if ( empty( $keyword ) ) {
return [];
}
/**
* The indexable repository.
*
* @var Indexable_Repository
*/
$repository = YoastSEO()->classes->get( Indexable_Repository::class );
$post_ids = $repository->query()
->select( 'object_id' )
->where( 'primary_focus_keyword', $keyword )
->where( 'object_type', 'post' )
->where_not_equal( 'object_id', $post_id )
->where_not_equal( 'post_status', 'trash' )
->limit( 2 ) // Limit to 2 results to save time and resources.
->find_array();
// Get object_id from each subarray in $post_ids.
$post_ids = ( is_array( $post_ids ) ) ? array_column( $post_ids, 'object_id' ) : [];
/*
* If Premium is installed, get the additional keywords as well.
* We only check for the additional keywords if we've not already found two.
* In that case there's no use for an additional query as we already know
* that the keyword has been used multiple times before.
*/
if ( count( $post_ids ) < 2 ) {
/**
* Allows enhancing the array of posts' that share their focus keywords with the post's focus keywords.
*
* @param array $post_ids The array of posts' ids that share their related keywords with the post.
* @param string $keyword The keyword to search for.
* @param int $post_id The id of the post the keyword is associated to.
*/
$post_ids = apply_filters( 'wpseo_posts_for_focus_keyword', $post_ids, $keyword, $post_id );
}
return $post_ids;
}
/**
* Returns the post types for the given post ids.
*
* @param array $post_ids The post ids to get the post types for.
*
* @return array The post types.
*/
public static function post_types_for_ids( $post_ids ) {
/**
* The indexable repository.
*
* @var Indexable_Repository
*/
$repository = YoastSEO()->classes->get( Indexable_Repository::class );
// Check if post ids is not empty.
if ( ! empty( $post_ids ) ) {
// Get the post subtypes for the posts that share the keyword.
$post_types = $repository->query()
->select( 'object_sub_type' )
->where_in( 'object_id', $post_ids )
->find_array();
// Get object_sub_type from each subarray in $post_ids.
$post_types = array_column( $post_types, 'object_sub_type' );
}
else {
$post_types = [];
}
return $post_types;
}
/**
* Filter the schema article types.
*
* @return void
*/
public static function filter_schema_article_types() {
/** This filter is documented in inc/options/class-wpseo-option-titles.php */
self::$meta_fields['schema']['schema_article_type']['options'] = apply_filters( 'wpseo_schema_article_types', self::$meta_fields['schema']['schema_article_type']['options'] );
}
}
Fatal error: Uncaught Error: Class 'WPSEO_Meta' not found in /var/www/html/elbrus.com.br/web/blog/wp-content/plugins/wordpress-seo/wp-seo-main.php:340
Stack trace:
#0 /var/www/html/elbrus.com.br/web/blog/wp-includes/class-wp-hook.php(324): wpseo_init('')
#1 /var/www/html/elbrus.com.br/web/blog/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#2 /var/www/html/elbrus.com.br/web/blog/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /var/www/html/elbrus.com.br/web/blog/wp-settings.php(578): do_action('plugins_loaded')
#4 /var/www/html/elbrus.com.br/web/blog/wp-config.php(109): require_once('/var/www/html/e...')
#5 /var/www/html/elbrus.com.br/web/blog/wp-load.php(50): require_once('/var/www/html/e...')
#6 /var/www/html/elbrus.com.br/web/blog/wp-blog-header.php(13): require_once('/var/www/html/e...')
#7 /var/www/html/elbrus.com.br/web/blog/index.php(17): require('/var/www/html/e...')
#8 {main}
thrown in /var/www/html/elbrus.com.br/web/blog/wp-content/plugins/wordpress-seo/wp-seo-main.php on line 340