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.../src/helpers
File: author-archive-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use WP_Query;
[4] Fix | Delete
use Yoast\WP\Lib\Model;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* A helper object for author archives.
[8] Fix | Delete
*/
[9] Fix | Delete
class Author_Archive_Helper {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* The options helper.
[13] Fix | Delete
*
[14] Fix | Delete
* @var Options_Helper
[15] Fix | Delete
*/
[16] Fix | Delete
private $options_helper;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* The post type helper.
[20] Fix | Delete
*
[21] Fix | Delete
* @var Post_Type_Helper
[22] Fix | Delete
*/
[23] Fix | Delete
private $post_type_helper;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Creates a new author archive helper.
[27] Fix | Delete
*
[28] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[29] Fix | Delete
* @param Post_Type_Helper $post_type_helper The post type helper.
[30] Fix | Delete
*/
[31] Fix | Delete
public function __construct(
[32] Fix | Delete
Options_Helper $options_helper,
[33] Fix | Delete
Post_Type_Helper $post_type_helper
[34] Fix | Delete
) {
[35] Fix | Delete
$this->options_helper = $options_helper;
[36] Fix | Delete
$this->post_type_helper = $post_type_helper;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Gets the array of post types that are shown on an author's archive.
[41] Fix | Delete
*
[42] Fix | Delete
* @return array The post types that are shown on an author's archive.
[43] Fix | Delete
*/
[44] Fix | Delete
public function get_author_archive_post_types() {
[45] Fix | Delete
/**
[46] Fix | Delete
* Filters the array of post types that are shown on an author's archive.
[47] Fix | Delete
*
[48] Fix | Delete
* @param array $args The post types that are shown on an author archive.
[49] Fix | Delete
*/
[50] Fix | Delete
return \apply_filters( 'wpseo_author_archive_post_types', [ 'post' ] );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Returns whether the author has at least one public post.
[55] Fix | Delete
*
[56] Fix | Delete
* @param int $author_id The author ID.
[57] Fix | Delete
*
[58] Fix | Delete
* @return bool|null Whether the author has at least one public post.
[59] Fix | Delete
*/
[60] Fix | Delete
public function author_has_public_posts( $author_id ) {
[61] Fix | Delete
// First check if the author has at least one public post.
[62] Fix | Delete
$has_public_post = $this->author_has_a_public_post( $author_id );
[63] Fix | Delete
if ( $has_public_post ) {
[64] Fix | Delete
return true;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
// Then check if the author has at least one post where the status is the same as the global setting.
[68] Fix | Delete
$has_public_post_depending_on_the_global_setting = $this->author_has_a_post_with_is_public_null( $author_id );
[69] Fix | Delete
if ( $has_public_post_depending_on_the_global_setting ) {
[70] Fix | Delete
return null;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
return false;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Returns whether the author has at least one public post.
[78] Fix | Delete
*
[79] Fix | Delete
* **Note**: It uses WP_Query to determine the number of posts,
[80] Fix | Delete
* not the indexables table.
[81] Fix | Delete
*
[82] Fix | Delete
* @param string $user_id The user ID.
[83] Fix | Delete
*
[84] Fix | Delete
* @return bool Whether the author has at least one public post.
[85] Fix | Delete
*/
[86] Fix | Delete
public function author_has_public_posts_wp( $user_id ) {
[87] Fix | Delete
$post_types = \array_intersect( $this->get_author_archive_post_types(), $this->post_type_helper->get_indexable_post_types() );
[88] Fix | Delete
$public_post_stati = \array_values( \array_filter( \get_post_stati(), 'is_post_status_viewable' ) );
[89] Fix | Delete
[90] Fix | Delete
$args = [
[91] Fix | Delete
'post_type' => $post_types,
[92] Fix | Delete
'post_status' => $public_post_stati,
[93] Fix | Delete
'author' => $user_id,
[94] Fix | Delete
'update_post_term_cache' => false,
[95] Fix | Delete
'update_post_meta_cache' => false,
[96] Fix | Delete
'no_found_rows' => true,
[97] Fix | Delete
'fields' => 'ids',
[98] Fix | Delete
'posts_per_page' => 1,
[99] Fix | Delete
];
[100] Fix | Delete
[101] Fix | Delete
$query = new WP_Query( $args );
[102] Fix | Delete
[103] Fix | Delete
if ( $query->have_posts() ) {
[104] Fix | Delete
return true;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
return false;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Checks whether author archives are disabled.
[112] Fix | Delete
*
[113] Fix | Delete
* @return bool `true` if author archives are disabled, `false` if not.
[114] Fix | Delete
*/
[115] Fix | Delete
public function are_disabled() {
[116] Fix | Delete
return $this->options_helper->get( 'disable-author' );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Returns whether the author has at least one public post.
[121] Fix | Delete
*
[122] Fix | Delete
* @codeCoverageIgnore It looks for the first ID through the ORM and converts it to a boolean.
[123] Fix | Delete
*
[124] Fix | Delete
* @param int $author_id The author ID.
[125] Fix | Delete
*
[126] Fix | Delete
* @return bool Whether the author has at least one public post.
[127] Fix | Delete
*/
[128] Fix | Delete
protected function author_has_a_public_post( $author_id ) {
[129] Fix | Delete
$cache_key = 'author_has_a_public_post_' . $author_id;
[130] Fix | Delete
$indexable_exists = \wp_cache_get( $cache_key );
[131] Fix | Delete
[132] Fix | Delete
if ( $indexable_exists === false ) {
[133] Fix | Delete
$indexable_exists = Model::of_type( 'Indexable' )
[134] Fix | Delete
->select( 'id' )
[135] Fix | Delete
->where( 'object_type', 'post' )
[136] Fix | Delete
->where_in( 'object_sub_type', $this->get_author_archive_post_types() )
[137] Fix | Delete
->where( 'author_id', $author_id )
[138] Fix | Delete
->where( 'is_public', 1 )
[139] Fix | Delete
->find_one();
[140] Fix | Delete
[141] Fix | Delete
if ( $indexable_exists === false ) {
[142] Fix | Delete
// Cache no results to prevent full table scanning on authors with no public posts.
[143] Fix | Delete
\wp_cache_set( $cache_key, 0, '', \wp_rand( ( 2 * \HOUR_IN_SECONDS ), ( 4 * \HOUR_IN_SECONDS ) ) );
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
return (bool) $indexable_exists;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* Returns whether the author has at least one post with the is public null.
[152] Fix | Delete
*
[153] Fix | Delete
* @codeCoverageIgnore It looks for the first ID through the ORM and converts it to a boolean.
[154] Fix | Delete
*
[155] Fix | Delete
* @param int $author_id The author ID.
[156] Fix | Delete
*
[157] Fix | Delete
* @return bool Whether the author has at least one post with the is public null.
[158] Fix | Delete
*/
[159] Fix | Delete
protected function author_has_a_post_with_is_public_null( $author_id ) {
[160] Fix | Delete
$cache_key = 'author_has_a_post_with_is_public_null_' . $author_id;
[161] Fix | Delete
$indexable_exists = \wp_cache_get( $cache_key );
[162] Fix | Delete
[163] Fix | Delete
if ( $indexable_exists === false ) {
[164] Fix | Delete
$indexable_exists = Model::of_type( 'Indexable' )
[165] Fix | Delete
->select( 'id' )
[166] Fix | Delete
->where( 'object_type', 'post' )
[167] Fix | Delete
->where_in( 'object_sub_type', $this->get_author_archive_post_types() )
[168] Fix | Delete
->where( 'author_id', $author_id )
[169] Fix | Delete
->where_null( 'is_public' )
[170] Fix | Delete
->find_one();
[171] Fix | Delete
[172] Fix | Delete
if ( $indexable_exists === false ) {
[173] Fix | Delete
// Cache no results to prevent full table scanning on authors with no is public null posts.
[174] Fix | Delete
\wp_cache_set( $cache_key, 0, '', \wp_rand( ( 2 * \HOUR_IN_SECONDS ), ( 4 * \HOUR_IN_SECONDS ) ) );
[175] Fix | Delete
}
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
return (bool) $indexable_exists;
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function