PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | modules/related-posts/jetpack-related-posts.php +34 -14 16.2-beta → 16.3-a.5 View file →
@@ -7,8 +7,9 @@
7 7
8 8 use Automattic\Jetpack\Assets;
9 9 use Automattic\Jetpack\Blocks;
10 10 use Automattic\Jetpack\Post_Media\Images;
11 +use Automattic\Jetpack\SEO\Content_Gate;
11 12 use Automattic\Jetpack\Status\Request;
12 13 use Automattic\Jetpack\Sync\Settings;
13 14
14 15 /**
@@ -1303,9 +1304,9 @@
1303 1304 $related_posts[ $index ]['id'] = $real_post->ID;
1304 1305 $related_posts[ $index ]['url'] = esc_url( get_permalink( $real_post ) );
1305 1306 $related_posts[ $index ]['title'] = $this->to_utf8( $this->get_title( $real_post->post_title, $real_post->post_content, $real_post->ID ) );
1306 1307 $related_posts[ $index ]['date'] = get_the_date( '', $real_post );
1307 - $related_posts[ $index ]['excerpt'] = html_entity_decode( $this->to_utf8( $this->get_excerpt( $real_post->post_excerpt, $real_post->post_content ) ), ENT_QUOTES, 'UTF-8' );
1308 + $related_posts[ $index ]['excerpt'] = html_entity_decode( $this->to_utf8( $this->get_excerpt( $real_post->post_excerpt, $real_post->post_content, $real_post->ID ) ), ENT_QUOTES, 'UTF-8' );
1308 1309 $related_posts[ $index ]['img'] = $this->generate_related_post_image_params( $real_post->ID );
1309 1310 $related_posts[ $index ]['context'] = $this->generate_related_post_context( $real_post->ID );
1310 1311 }
1311 1312 } else {
@@ -1356,9 +1357,9 @@
1356 1357 'title' => $this->to_utf8( $this->get_title( $post->post_title, $post->post_content, $post->ID ) ),
1357 1358 'author' => $this->generate_related_post_display_author( $post->ID ),
1358 1359 'date' => get_the_date( '', $post->ID ),
1359 1360 'format' => get_post_format( $post->ID ),
1360 - 'excerpt' => html_entity_decode( $this->to_utf8( $this->get_excerpt( $post->post_excerpt, $post->post_content ) ), ENT_QUOTES, 'UTF-8' ),
1361 + 'excerpt' => html_entity_decode( $this->to_utf8( $this->get_excerpt( $post->post_excerpt, $post->post_content, $post->ID ) ), ENT_QUOTES, 'UTF-8' ),
1361 1362 /**
1362 1363 * Filters the rel attribute for the Related Posts' links.
1363 1364 *
1364 1365 * @module related-posts
@@ -1427,11 +1428,14 @@
1427 1428 apply_filters( 'the_title', $post_title, $post_id )
1428 1429 );
1429 1430 }
1430 1431
1431 - $post_title = wp_trim_words( wp_strip_all_tags( strip_shortcodes( $post_content ) ), 5, '…' );
1432 - if ( ! empty( $post_title ) ) {
1433 - return $post_title;
1432 + // Same gate as get_excerpt(): this fallback is five words of the raw body.
1433 + if ( ! Content_Gate::is_gated( $post_id ) ) {
1434 + $post_title = wp_trim_words( wp_strip_all_tags( strip_shortcodes( $post_content ) ), 5, '…' );
1435 + if ( ! empty( $post_title ) ) {
1436 + return $post_title;
1437 + }
1434 1438 }
1435 1439
1436 1440 return __( 'Untitled Post', 'jetpack' );
1437 1441 }
@@ -1440,16 +1444,20 @@
1440 1444 * Returns a plain text post excerpt for title attribute of links.
1441 1445 *
1442 1446 * @param string $post_excerpt - the post excerpt.
1443 1447 * @param string $post_content - the post content.
1448 + * @param int $post_id - the post ID.
1444 1449 * @uses strip_shortcodes, wp_strip_all_tags, wp_trim_words
1445 1450 * @return string
1446 1451 */
1447 - protected function get_excerpt( $post_excerpt, $post_content ) {
1448 - if ( empty( $post_excerpt ) ) {
1452 + protected function get_excerpt( $post_excerpt, $post_content, $post_id ) {
1453 + if ( ! empty( $post_excerpt ) ) {
1454 + $excerpt = $post_excerpt;
1455 + } elseif ( Content_Gate::is_gated( $post_id ) ) {
1456 + // The body fall-through never passes through the `the_content` paywall, so ask the gate directly.
1457 + return '';
1458 + } else {
1449 1459 $excerpt = $post_content;
1450 - } else {
1451 - $excerpt = $post_excerpt;
1452 1460 }
1453 1461
1454 1462 return wp_trim_words( wp_strip_all_tags( strip_shortcodes( $excerpt ) ), 50, '…' );
1455 1463 }
@@ -1494,16 +1502,28 @@
1494 1502 }
1495 1503
1496 1504 // Try to get post image.
1497 1505 $img_url = '';
1498 - $post_image = Images::get_image(
1499 - $post_id,
1500 - $thumbnail_size
1501 - );
1506 + $is_gated = Content_Gate::is_gated( $post_id );
1507 + $image_args = $thumbnail_size;
1508 + if ( $is_gated ) {
1509 + // Restrict to the featured image; every other source parses the body.
1510 + $image_args = array_merge(
1511 + $image_args,
1512 + array(
1513 + 'from_slideshow' => false,
1514 + 'from_gallery' => false,
1515 + 'from_attachment' => false,
1516 + 'from_blocks' => false,
1517 + 'from_html' => false,
1518 + )
1519 + );
1520 + }
1521 + $post_image = Images::get_image( $post_id, $image_args );
1502 1522
1503 1523 if ( is_array( $post_image ) ) {
1504 1524 $img_url = $post_image['src'];
1505 - } elseif ( class_exists( 'Jetpack_Media_Summary' ) ) {
1525 + } elseif ( ! $is_gated && class_exists( 'Jetpack_Media_Summary' ) ) {
1506 1526 $media = Jetpack_Media_Summary::get( $post_id );
1507 1527
1508 1528 if ( is_array( $media ) && ! empty( $media['image'] ) ) {
1509 1529 $img_url = $media['image'];