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: post-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use WP_Post;
[4] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Repository;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* A helper object for post related things.
[8] Fix | Delete
*/
[9] Fix | Delete
class Post_Helper {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Holds the String_Helper instance.
[13] Fix | Delete
*
[14] Fix | Delete
* @var String_Helper
[15] Fix | Delete
*/
[16] Fix | Delete
private $string;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Holds the Post_Type_Helper instance.
[20] Fix | Delete
*
[21] Fix | Delete
* @var Post_Type_Helper
[22] Fix | Delete
*/
[23] Fix | Delete
private $post_type;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Represents the indexables repository.
[27] Fix | Delete
*
[28] Fix | Delete
* @var Indexable_Repository
[29] Fix | Delete
*/
[30] Fix | Delete
private $repository;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Post_Helper constructor.
[34] Fix | Delete
*
[35] Fix | Delete
* @codeCoverageIgnore It only sets dependencies.
[36] Fix | Delete
*
[37] Fix | Delete
* @param String_Helper $string_helper The string helper.
[38] Fix | Delete
* @param Post_Type_Helper $post_type_helper The string helper.
[39] Fix | Delete
*/
[40] Fix | Delete
public function __construct(
[41] Fix | Delete
String_Helper $string_helper,
[42] Fix | Delete
Post_Type_Helper $post_type_helper
[43] Fix | Delete
) {
[44] Fix | Delete
$this->string = $string_helper;
[45] Fix | Delete
$this->post_type = $post_type_helper;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Sets the indexable repository. Done to avoid circular dependencies.
[50] Fix | Delete
*
[51] Fix | Delete
* @required
[52] Fix | Delete
*
[53] Fix | Delete
* @param Indexable_Repository $repository The indexable repository.
[54] Fix | Delete
*
[55] Fix | Delete
* @return void
[56] Fix | Delete
*/
[57] Fix | Delete
public function set_indexable_repository( Indexable_Repository $repository ) {
[58] Fix | Delete
$this->repository = $repository;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Removes all shortcode tags from the given content.
[63] Fix | Delete
*
[64] Fix | Delete
* @codeCoverageIgnore It only wraps a WordPress function.
[65] Fix | Delete
*
[66] Fix | Delete
* @param string $content Content to remove all the shortcode tags from.
[67] Fix | Delete
*
[68] Fix | Delete
* @return string Content without shortcode tags.
[69] Fix | Delete
*/
[70] Fix | Delete
public function strip_shortcodes( $content ) {
[71] Fix | Delete
return \strip_shortcodes( $content );
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Retrieves the post excerpt (without tags).
[76] Fix | Delete
*
[77] Fix | Delete
* @codeCoverageIgnore It only wraps another helper method.
[78] Fix | Delete
*
[79] Fix | Delete
* @param int $post_id Post ID.
[80] Fix | Delete
*
[81] Fix | Delete
* @return string Post excerpt (without tags).
[82] Fix | Delete
*/
[83] Fix | Delete
public function get_the_excerpt( $post_id ) {
[84] Fix | Delete
return $this->string->strip_all_tags( \get_the_excerpt( $post_id ) );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Retrieves the post type of the current post.
[89] Fix | Delete
*
[90] Fix | Delete
* @codeCoverageIgnore It only wraps a WordPress function.
[91] Fix | Delete
*
[92] Fix | Delete
* @param WP_Post|null $post The post.
[93] Fix | Delete
*
[94] Fix | Delete
* @return string|false Post type on success, false on failure.
[95] Fix | Delete
*/
[96] Fix | Delete
public function get_post_type( $post = null ) {
[97] Fix | Delete
return \get_post_type( $post );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Retrieves the post title with fallback to `No title`.
[102] Fix | Delete
*
[103] Fix | Delete
* @param int $post_id Optional. Post ID.
[104] Fix | Delete
*
[105] Fix | Delete
* @return string The post title with fallback to `No title`.
[106] Fix | Delete
*/
[107] Fix | Delete
public function get_post_title_with_fallback( $post_id = 0 ) {
[108] Fix | Delete
$post_title = \get_the_title( $post_id );
[109] Fix | Delete
if ( $post_title ) {
[110] Fix | Delete
return $post_title;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
return \__( 'No title', 'wordpress-seo' );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Retrieves post data given a post ID.
[118] Fix | Delete
*
[119] Fix | Delete
* @codeCoverageIgnore It wraps a WordPress function.
[120] Fix | Delete
*
[121] Fix | Delete
* @param int $post_id Post ID.
[122] Fix | Delete
*
[123] Fix | Delete
* @return WP_Post|null The post.
[124] Fix | Delete
*/
[125] Fix | Delete
public function get_post( $post_id ) {
[126] Fix | Delete
return \get_post( $post_id );
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Updates the has_public_posts field on attachments for a post_parent.
[131] Fix | Delete
*
[132] Fix | Delete
* An attachment is represented by their post parent when:
[133] Fix | Delete
* - The attachment has a post parent.
[134] Fix | Delete
* - The attachment inherits the post status.
[135] Fix | Delete
*
[136] Fix | Delete
* @codeCoverageIgnore It relies too much on dependencies.
[137] Fix | Delete
*
[138] Fix | Delete
* @param int $post_parent Post ID.
[139] Fix | Delete
* @param int $has_public_posts Whether the parent is public.
[140] Fix | Delete
*
[141] Fix | Delete
* @return bool Whether the update was successful.
[142] Fix | Delete
*/
[143] Fix | Delete
public function update_has_public_posts_on_attachments( $post_parent, $has_public_posts ) {
[144] Fix | Delete
$query = $this->repository->query()
[145] Fix | Delete
->select( 'id' )
[146] Fix | Delete
->where( 'object_type', 'post' )
[147] Fix | Delete
->where( 'object_sub_type', 'attachment' )
[148] Fix | Delete
->where( 'post_status', 'inherit' )
[149] Fix | Delete
->where( 'post_parent', $post_parent );
[150] Fix | Delete
[151] Fix | Delete
if ( $has_public_posts !== null ) {
[152] Fix | Delete
$query->where_raw( '( has_public_posts IS NULL OR has_public_posts <> %s )', [ $has_public_posts ] );
[153] Fix | Delete
}
[154] Fix | Delete
else {
[155] Fix | Delete
$query->where_not_null( 'has_public_posts' );
[156] Fix | Delete
}
[157] Fix | Delete
$results = $query->find_array();
[158] Fix | Delete
[159] Fix | Delete
if ( empty( $results ) ) {
[160] Fix | Delete
return true;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
$updated = $this->repository->query()
[164] Fix | Delete
->set( 'has_public_posts', $has_public_posts )
[165] Fix | Delete
->where_id_in( \wp_list_pluck( $results, 'id' ) )
[166] Fix | Delete
->update_many();
[167] Fix | Delete
[168] Fix | Delete
return $updated !== false;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Determines if the post can be indexed.
[173] Fix | Delete
*
[174] Fix | Delete
* @param int $post_id Post ID to check.
[175] Fix | Delete
*
[176] Fix | Delete
* @return bool True if the post can be indexed.
[177] Fix | Delete
*/
[178] Fix | Delete
public function is_post_indexable( $post_id ) {
[179] Fix | Delete
// Don't index posts which are not public (i.e. viewable).
[180] Fix | Delete
$post_type = \get_post_type( $post_id );
[181] Fix | Delete
[182] Fix | Delete
if ( ! $this->post_type->is_of_indexable_post_type( $post_type ) ) {
[183] Fix | Delete
return false;
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
// Don't index excluded post statuses.
[187] Fix | Delete
if ( \in_array( \get_post_status( $post_id ), $this->get_excluded_post_statuses(), true ) ) {
[188] Fix | Delete
return false;
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
// Don't index revisions of posts.
[192] Fix | Delete
if ( \wp_is_post_revision( $post_id ) ) {
[193] Fix | Delete
return false;
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
// Don't index autosaves that are not caught by the auto-draft check.
[197] Fix | Delete
if ( \wp_is_post_autosave( $post_id ) ) {
[198] Fix | Delete
return false;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
return true;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Retrieves the list of excluded post statuses.
[206] Fix | Delete
*
[207] Fix | Delete
* @return array The excluded post statuses.
[208] Fix | Delete
*/
[209] Fix | Delete
public function get_excluded_post_statuses() {
[210] Fix | Delete
return [ 'auto-draft' ];
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Retrieves the list of public posts statuses.
[215] Fix | Delete
*
[216] Fix | Delete
* @return array The public post statuses.
[217] Fix | Delete
*/
[218] Fix | Delete
public function get_public_post_statuses() {
[219] Fix | Delete
/**
[220] Fix | Delete
* Filter: 'wpseo_public_post_statuses' - List of public post statuses.
[221] Fix | Delete
*
[222] Fix | Delete
* @param array $post_statuses Post status list, defaults to array( 'publish' ).
[223] Fix | Delete
*/
[224] Fix | Delete
return \apply_filters( 'wpseo_public_post_statuses', [ 'publish' ] );
[225] Fix | Delete
}
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function