Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related Posts: Remove the call to remove_filter( 'the_content', ...) #13804

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions modules/related-posts/jetpack-related-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public function get_headline() {

/**
* Adds a target to the post content to load related posts into if a shortcode for it did not already exist.
* Will skip adding the target if the post content contains a Related Posts block.
* Will skip adding the target if the post content contains a Related Posts block or if the 'get_the_excerpt'
* hook is in the current filter list.
*
* @filter the_content
*
Expand All @@ -172,7 +173,7 @@ public function get_headline() {
* @returns string
*/
public function filter_add_target_to_dom( $content ) {
if ( has_block( 'jetpack/related-posts', $content ) ) {
if ( has_block( 'jetpack/related-posts' ) ) {
return $content;
}

Expand Down Expand Up @@ -369,17 +370,7 @@ public function render_block( $attributes ) {
'size' => ! empty( $attributes['postsToShow'] ) ? absint( $attributes['postsToShow'] ) : 3,
);

$excludes = $this->parse_numeric_get_arg( 'relatedposts_origin' );

$target_to_dom_priority = has_filter(
'the_content',
array( $this, 'filter_add_target_to_dom' )
);
remove_filter(
'the_content',
array( $this, 'filter_add_target_to_dom' ),
$target_to_dom_priority
);
$excludes = $this->parse_numeric_get_arg( 'relatedposts_origin' );

$related_posts = $this->get_for_post_id(
get_the_ID(),
Expand Down Expand Up @@ -452,7 +443,7 @@ public function render_block( $attributes ) {
*
* @uses absint
*
* @param string $arg Name of the GET variable
* @param string $arg Name of the GET variable.
* @return array $result Parsed value(s)
*/
public function parse_numeric_get_arg( $arg ) {
Expand Down