Skip to content

Commit

Permalink
Merge pull request #1529 from Automattic/master
Browse files Browse the repository at this point in the history
Alpha release Sep 15
  • Loading branch information
laurelfulford authored Sep 15, 2023
2 parents 966fc84 + ebbfce9 commit 036ab3b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 87 deletions.
50 changes: 27 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion includes/class-newspack-blocks-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public static function newspack_blocks_get_primary_category( $object ) {
return '';
}

return $category->name;
$linked_category = '<a href="#">' . $category->name . '</a>';

return apply_filters( 'newspack_blocks_categories', $linked_category );
}

/**
Expand Down
40 changes: 33 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"react": "^17.0.2",
"redux": "^4.2.1",
"redux-saga": "^1.2.3",
"regenerator-runtime": "^0.13.11",
"regenerator-runtime": "^0.14.0",
"swiper": "9.3.2"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/carousel/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/block-editor';
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
import { dateI18n, __experimentalGetSettings } from '@wordpress/date';
import { Component, createRef, Fragment } from '@wordpress/element';
import { Component, createRef, Fragment, RawHTML } from '@wordpress/element';
import {
BaseControl,
Button,
Expand Down Expand Up @@ -303,7 +303,7 @@ class Edit extends Component {
{ showCategory &&
( ! post.newspack_post_sponsors ||
post.newspack_sponsors_show_categories ) && (
<a href="#">{ decodeEntities( post.newspack_category_info ) }</a>
<RawHTML>{ decodeEntities( post.newspack_category_info ) }</RawHTML>
) }
</div>
) }
Expand Down
32 changes: 3 additions & 29 deletions src/blocks/carousel/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,10 @@ function newspack_blocks_render_block_carousel( $attributes ) {
</span>
<?php
endif;
$category = false;

// Use Yoast primary category if set.
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
$primary_term = new WPSEO_Primary_Term( 'category', $post_id );
$category_id = $primary_term->get_primary_term();
if ( $category_id ) {
$category = get_term( $category_id );
}
}

if ( ! $category ) {
$categories_list = get_the_category();
if ( ! empty( $categories_list ) ) {
$category = $categories_list[0];
}
}

if ( $attributes['showCategory'] && $category && ( empty( $sponsors ) || Newspack_Blocks::newspack_display_sponsors_and_categories( $sponsors ) ) ) :
?>
<?php $category_link = get_category_link( $category->term_id ); ?>
<?php if ( ! empty( $category_link ) ) : ?>
<a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>">
<?php endif; ?>
<?php echo esc_html( $category->name ); ?>
<?php if ( ! empty( $category_link ) ) : ?>
</a>
<?php
endif;
endif;
if ( $attributes['showCategory'] && ( empty( $sponsors ) || Newspack_Blocks::newspack_display_sponsors_and_categories( $sponsors ) ) ) :
echo wp_kses_post( newspack_blocks_format_categories( $post_id ) );
endif;
?>
</div>
<?php
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/homepage-articles/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Edit extends Component {
) }
{ showCategory &&
( ! post.newspack_post_sponsors || post.newspack_sponsors_show_categories ) && (
<a href="#">{ decodeEntities( post.newspack_category_info ) }</a>
<RawHTML>{ decodeEntities( post.newspack_category_info ) }</RawHTML>
) }
</div>
) }
Expand Down
32 changes: 9 additions & 23 deletions src/blocks/homepage-articles/templates/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ function( $data ) {
if ( $attributes['fetchPriority'] && in_array( $attributes['fetchPriority'], [ 'high', 'low', 'auto' ], true ) ) {
$thumbnail_args['fetchpriority'] = $attributes['fetchPriority'];
}
$category = false;
// Use Yoast primary category if set.
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
$primary_term = new WPSEO_Primary_Term( 'category', $post_id );
$category_id = $primary_term->get_primary_term();
if ( $category_id ) {
$category = get_term( $category_id );
}
}
if ( ! $category ) {
$categories_list = get_the_category();
if ( ! empty( $categories_list ) ) {
$category = $categories_list[0];
}
}

// Support Newspack Listings hide author/publish date options.
$hide_author = apply_filters( 'newspack_listings_hide_author', false ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
Expand Down Expand Up @@ -105,19 +90,20 @@ class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
<?php endif; ?>

<div class="entry-wrapper">
<?php if ( ! empty( $sponsors ) || ( $attributes['showCategory'] && $category ) ) : ?>
<?php $category_link = get_category_link( $category->term_id ); ?>
<?php if ( ! empty( $sponsors ) || ( $attributes['showCategory'] ) ) : ?>

<div class="cat-links <?php if ( ! empty( $sponsors ) ) : ?>sponsor-label<?php endif; // phpcs:ignore Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace ?>">
<?php if ( ! empty( $sponsors ) ) : ?>
<span class="flag">
<?php echo esc_html( Newspack_Blocks::get_sponsor_label( $sponsors ) ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['showCategory'] && ! empty( $category_link ) && ( empty( $sponsors ) || Newspack_Blocks::newspack_display_sponsors_and_categories( $sponsors ) ) ) : ?>
<a href="<?php echo esc_url( $category_link ); ?>">
<?php echo esc_html( $category->name ); ?>
</a>
<?php endif; ?>
<?php
endif;

if ( $attributes['showCategory'] && ( empty( $sponsors ) || Newspack_Blocks::newspack_display_sponsors_and_categories( $sponsors ) ) ) :
echo wp_kses_post( newspack_blocks_format_categories( $post_id ) );
endif;
?>
</div>
<?php
endif;
Expand Down
34 changes: 34 additions & 0 deletions src/blocks/homepage-articles/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,40 @@ function ( $accumulator, $author ) use ( $author_info, &$index ) {
return implode( '', $elements );
}

/**
* Renders category markup plus filter.
*
* @param string $post_id Post ID.
*/
function newspack_blocks_format_categories( $post_id ) {
$category = false;
// Use Yoast primary category if set.
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
$primary_term = new WPSEO_Primary_Term( 'category', $post_id );
$category_id = $primary_term->get_primary_term();
if ( $category_id ) {
$category = get_term( $category_id );
}
}
if ( ! $category ) {
$categories_list = get_the_category();
if ( ! empty( $categories_list ) ) {
$category = $categories_list[0];
}
}

$category_link = get_category_link( $category->term_id );
$category_formatted = esc_html( $category->name );

if ( ! empty( $category_link ) ) {
$category_formatted = '<a href="' . esc_attr( $category_link ) . '">' . esc_html( $category->name ) . '</a>';
}

if ( $category ) {
return apply_filters( 'newspack_blocks_categories', $category_formatted );
}
}

/**
* Inject amp-state containing all post IDs visible on page load.
*/
Expand Down

0 comments on commit 036ab3b

Please sign in to comment.