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.../src/builders
File: indexable-author-builder.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Builders;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Exceptions\Indexable\Author_Not_Built_Exception;
[4] Fix | Delete
use Yoast\WP\SEO\Helpers\Author_Archive_Helper;
[5] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Post_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Models\Indexable;
[8] Fix | Delete
use Yoast\WP\SEO\Values\Indexables\Indexable_Builder_Versions;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Author Builder for the indexables.
[12] Fix | Delete
*
[13] Fix | Delete
* Formats the author meta to indexable format.
[14] Fix | Delete
*/
[15] Fix | Delete
class Indexable_Author_Builder {
[16] Fix | Delete
[17] Fix | Delete
use Indexable_Social_Image_Trait;
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* The author archive helper.
[21] Fix | Delete
*
[22] Fix | Delete
* @var Author_Archive_Helper
[23] Fix | Delete
*/
[24] Fix | Delete
private $author_archive;
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* The latest version of the Indexable_Author_Builder.
[28] Fix | Delete
*
[29] Fix | Delete
* @var int
[30] Fix | Delete
*/
[31] Fix | Delete
protected $version;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Holds the options helper instance.
[35] Fix | Delete
*
[36] Fix | Delete
* @var Options_Helper
[37] Fix | Delete
*/
[38] Fix | Delete
protected $options_helper;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Holds the taxonomy helper instance.
[42] Fix | Delete
*
[43] Fix | Delete
* @var Post_Helper
[44] Fix | Delete
*/
[45] Fix | Delete
protected $post_helper;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Indexable_Author_Builder constructor.
[49] Fix | Delete
*
[50] Fix | Delete
* @param Author_Archive_Helper $author_archive The author archive helper.
[51] Fix | Delete
* @param Indexable_Builder_Versions $versions The Indexable version manager.
[52] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[53] Fix | Delete
* @param Post_Helper $post_helper The post helper.
[54] Fix | Delete
*/
[55] Fix | Delete
public function __construct(
[56] Fix | Delete
Author_Archive_Helper $author_archive,
[57] Fix | Delete
Indexable_Builder_Versions $versions,
[58] Fix | Delete
Options_Helper $options_helper,
[59] Fix | Delete
Post_Helper $post_helper
[60] Fix | Delete
) {
[61] Fix | Delete
$this->author_archive = $author_archive;
[62] Fix | Delete
$this->version = $versions->get_latest_version_for_type( 'user' );
[63] Fix | Delete
$this->options_helper = $options_helper;
[64] Fix | Delete
$this->post_helper = $post_helper;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Formats the data.
[69] Fix | Delete
*
[70] Fix | Delete
* @param int $user_id The user to retrieve the indexable for.
[71] Fix | Delete
* @param Indexable $indexable The indexable to format.
[72] Fix | Delete
*
[73] Fix | Delete
* @return Indexable The extended indexable.
[74] Fix | Delete
*
[75] Fix | Delete
* @throws Author_Not_Built_Exception When author is not built.
[76] Fix | Delete
*/
[77] Fix | Delete
public function build( $user_id, Indexable $indexable ) {
[78] Fix | Delete
$exception = $this->check_if_user_should_be_indexed( $user_id );
[79] Fix | Delete
if ( $exception ) {
[80] Fix | Delete
throw $exception;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
$meta_data = $this->get_meta_data( $user_id );
[84] Fix | Delete
[85] Fix | Delete
$indexable->object_id = $user_id;
[86] Fix | Delete
$indexable->object_type = 'user';
[87] Fix | Delete
$indexable->permalink = \get_author_posts_url( $user_id );
[88] Fix | Delete
$indexable->title = $meta_data['wpseo_title'];
[89] Fix | Delete
$indexable->description = $meta_data['wpseo_metadesc'];
[90] Fix | Delete
$indexable->is_cornerstone = false;
[91] Fix | Delete
$indexable->is_robots_noindex = ( $meta_data['wpseo_noindex_author'] === 'on' );
[92] Fix | Delete
$indexable->is_robots_nofollow = null;
[93] Fix | Delete
$indexable->is_robots_noarchive = null;
[94] Fix | Delete
$indexable->is_robots_noimageindex = null;
[95] Fix | Delete
$indexable->is_robots_nosnippet = null;
[96] Fix | Delete
$indexable->is_public = ( $indexable->is_robots_noindex ) ? false : null;
[97] Fix | Delete
$indexable->has_public_posts = $this->author_archive->author_has_public_posts( $user_id );
[98] Fix | Delete
$indexable->blog_id = \get_current_blog_id();
[99] Fix | Delete
[100] Fix | Delete
$this->reset_social_images( $indexable );
[101] Fix | Delete
$this->handle_social_images( $indexable );
[102] Fix | Delete
[103] Fix | Delete
$timestamps = $this->get_object_timestamps( $user_id );
[104] Fix | Delete
$indexable->object_published_at = $timestamps->published_at;
[105] Fix | Delete
$indexable->object_last_modified = $timestamps->last_modified;
[106] Fix | Delete
[107] Fix | Delete
$indexable->version = $this->version;
[108] Fix | Delete
[109] Fix | Delete
return $indexable;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Retrieves the meta data for this indexable.
[114] Fix | Delete
*
[115] Fix | Delete
* @param int $user_id The user to retrieve the meta data for.
[116] Fix | Delete
*
[117] Fix | Delete
* @return array List of meta entries.
[118] Fix | Delete
*/
[119] Fix | Delete
protected function get_meta_data( $user_id ) {
[120] Fix | Delete
$keys = [
[121] Fix | Delete
'wpseo_title',
[122] Fix | Delete
'wpseo_metadesc',
[123] Fix | Delete
'wpseo_noindex_author',
[124] Fix | Delete
];
[125] Fix | Delete
[126] Fix | Delete
$output = [];
[127] Fix | Delete
foreach ( $keys as $key ) {
[128] Fix | Delete
$output[ $key ] = $this->get_author_meta( $user_id, $key );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
return $output;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Retrieves the author meta.
[136] Fix | Delete
*
[137] Fix | Delete
* @param int $user_id The user to retrieve the indexable for.
[138] Fix | Delete
* @param string $key The meta entry to retrieve.
[139] Fix | Delete
*
[140] Fix | Delete
* @return string|null The value of the meta field.
[141] Fix | Delete
*/
[142] Fix | Delete
protected function get_author_meta( $user_id, $key ) {
[143] Fix | Delete
$value = \get_the_author_meta( $key, $user_id );
[144] Fix | Delete
if ( \is_string( $value ) && $value === '' ) {
[145] Fix | Delete
return null;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
return $value;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Finds an alternative image for the social image.
[153] Fix | Delete
*
[154] Fix | Delete
* @param Indexable $indexable The indexable.
[155] Fix | Delete
*
[156] Fix | Delete
* @return array|bool False when not found, array with data when found.
[157] Fix | Delete
*/
[158] Fix | Delete
protected function find_alternative_image( Indexable $indexable ) {
[159] Fix | Delete
$gravatar_image = \get_avatar_url(
[160] Fix | Delete
$indexable->object_id,
[161] Fix | Delete
[
[162] Fix | Delete
'size' => 500,
[163] Fix | Delete
'scheme' => 'https',
[164] Fix | Delete
]
[165] Fix | Delete
);
[166] Fix | Delete
if ( $gravatar_image ) {
[167] Fix | Delete
return [
[168] Fix | Delete
'image' => $gravatar_image,
[169] Fix | Delete
'source' => 'gravatar-image',
[170] Fix | Delete
];
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
return false;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Returns the timestamps for a given author.
[178] Fix | Delete
*
[179] Fix | Delete
* @param int $author_id The author ID.
[180] Fix | Delete
*
[181] Fix | Delete
* @return object An object with last_modified and published_at timestamps.
[182] Fix | Delete
*/
[183] Fix | Delete
protected function get_object_timestamps( $author_id ) {
[184] Fix | Delete
global $wpdb;
[185] Fix | Delete
$post_statuses = $this->post_helper->get_public_post_statuses();
[186] Fix | Delete
[187] Fix | Delete
$replacements = [];
[188] Fix | Delete
$replacements[] = 'post_modified_gmt';
[189] Fix | Delete
$replacements[] = 'post_date_gmt';
[190] Fix | Delete
$replacements[] = $wpdb->posts;
[191] Fix | Delete
$replacements[] = 'post_status';
[192] Fix | Delete
$replacements = \array_merge( $replacements, $post_statuses );
[193] Fix | Delete
$replacements[] = 'post_password';
[194] Fix | Delete
$replacements[] = 'post_author';
[195] Fix | Delete
$replacements[] = $author_id;
[196] Fix | Delete
[197] Fix | Delete
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
[198] Fix | Delete
//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
[199] Fix | Delete
//phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
[200] Fix | Delete
return $wpdb->get_row(
[201] Fix | Delete
$wpdb->prepare(
[202] Fix | Delete
'
[203] Fix | Delete
SELECT MAX(p.%i) AS last_modified, MIN(p.%i) AS published_at
[204] Fix | Delete
FROM %i AS p
[205] Fix | Delete
WHERE p.%i IN (' . \implode( ', ', \array_fill( 0, \count( $post_statuses ), '%s' ) ) . ")
[206] Fix | Delete
AND p.%i = ''
[207] Fix | Delete
AND p.%i = %d
[208] Fix | Delete
",
[209] Fix | Delete
$replacements
[210] Fix | Delete
)
[211] Fix | Delete
);
[212] Fix | Delete
//phpcs:enable
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Checks if the user should be indexed.
[217] Fix | Delete
* Returns an exception with an appropriate message if not.
[218] Fix | Delete
*
[219] Fix | Delete
* @param string $user_id The user id.
[220] Fix | Delete
*
[221] Fix | Delete
* @return Author_Not_Built_Exception|null The exception if it should not be indexed, or `null` if it should.
[222] Fix | Delete
*/
[223] Fix | Delete
protected function check_if_user_should_be_indexed( $user_id ) {
[224] Fix | Delete
$exception = null;
[225] Fix | Delete
[226] Fix | Delete
if ( $this->author_archive->are_disabled() ) {
[227] Fix | Delete
$exception = Author_Not_Built_Exception::author_archives_are_disabled( $user_id );
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
// We will check if the author has public posts the WP way, instead of the indexable way, to make sure we get proper results even if SEO optimization is not run.
[231] Fix | Delete
// In case the user has no public posts, we check if the user should be indexed anyway.
[232] Fix | Delete
if ( $this->options_helper->get( 'noindex-author-noposts-wpseo', false ) === true && $this->author_archive->author_has_public_posts_wp( $user_id ) === false ) {
[233] Fix | Delete
$exception = Author_Not_Built_Exception::author_archives_are_not_indexed_for_users_without_posts( $user_id );
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Filter: Include or exclude a user from being build and saved as an indexable.
[238] Fix | Delete
* Return an `Author_Not_Built_Exception` when the indexable should not be build, with an appropriate message telling why it should not be built.
[239] Fix | Delete
* Return `null` if the indexable should be build.
[240] Fix | Delete
*
[241] Fix | Delete
* @param Author_Not_Built_Exception|null $exception An exception if the indexable is not being built, `null` if the indexable should be built.
[242] Fix | Delete
* @param string $user_id The ID of the user that should or should not be excluded.
[243] Fix | Delete
*/
[244] Fix | Delete
return \apply_filters( 'wpseo_should_build_and_save_user_indexable', $exception, $user_id );
[245] Fix | Delete
}
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function