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