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

Synced Newspack Blocks: Update to 4.5.2 #40636

Merged
merged 27 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f8fb1e9
Sync newspack-blocks to 4.5.2
tbradsha Dec 16, 2024
73e653f
Update script to auto-add textdomain to block.json
tbradsha Dec 16, 2024
7520915
Update script to detect potential ENT_COMPAT needs
tbradsha Dec 16, 2024
26ed945
Script tweaks
tbradsha Dec 16, 2024
f51d4b3
More script tweaks
tbradsha Dec 16, 2024
e385469
Add .phpcs.dir.xml via script
tbradsha Dec 16, 2024
58c59a2
Finish up 4.5.2 block sync
tbradsha Dec 16, 2024
428a09d
Update baseline
tbradsha Dec 16, 2024
c1caf91
Update Phan baseline in script
tbradsha Dec 16, 2024
de03fc9
Commit changes from script
tbradsha Dec 16, 2024
3af28b0
Add ENT_COMPAT again
tbradsha Dec 16, 2024
bdee6ad
Add changelog
tbradsha Dec 16, 2024
307bbd4
Add .phpcsignore
tbradsha Dec 17, 2024
f334dbe
Commit synced blocks with PHPCS lint disabled
tbradsha Dec 17, 2024
0b0dba3
Allow one to resync current version
tbradsha Dec 17, 2024
ba51ed5
Update eslint and phpcbf calls
tbradsha Dec 17, 2024
83b0491
Commit less-linted JS/TS files
tbradsha Dec 17, 2024
3135249
Clean up paths
tbradsha Dec 17, 2024
ed996dd
Once again apply ENT_COMPAT changes
tbradsha Dec 17, 2024
de0c564
Update README
tbradsha Dec 17, 2024
c354232
Update index.php version number via script
tbradsha Dec 17, 2024
877a79d
Don't run Phan on synced files
tbradsha Dec 17, 2024
38dafc1
Remove Phan from README
tbradsha Dec 17, 2024
8465bfc
Simplify PHP textdomain fix
tbradsha Dec 18, 2024
5d3d690
Catch additional textdomain cases
tbradsha Dec 19, 2024
2f56f6b
Adjust docs wording
tbradsha Dec 19, 2024
bc7ac12
Remove `ENT_COMPAT` step
tbradsha Dec 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ then
echo --branch=master
echo "--nodemodules (to use defined in package.json)"
echo "--path=/path/to/newspack-blocks"
echo --release=v2.0.0
echo --release=v4.0.0
echo
echo You can find the latest release ID on https://github.com/Automattic/newspack-blocks/releases/latest
echo
Expand All @@ -61,7 +61,10 @@ then

if [[ "$CURRENT_VERSION" == "$NAME" ]]; then
echo "The current version $CURRENT_VERSION of the newspack-blocks is synced."
exit 0
read -rp "Do you want to proceed anyway? (y/N): " proceed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you could source the file from the monorepo root tools/includes/proceed_p.sh to use our fancy function for doing prompts like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any advantage of sourcing vs a simple read? :^)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proceed_p function handles a bunch of edge cases. It doesn't matter a whole lot though. 🤷

if [[ ! "$proceed" =~ ^[Yy]$ ]]; then
exit 0
fi
fi
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function newspack_blocks_render_block_carousel( $attributes ) {
// This will let the FSE plugin know we need CSS/JS now.
do_action( 'newspack_blocks_render_post_carousel' );

++$newspack_blocks_carousel_id;
$newspack_blocks_carousel_id++;
$autoplay = isset( $attributes['autoplay'] ) ? $attributes['autoplay'] : false;
$delay = isset( $attributes['delay'] ) ? absint( $attributes['delay'] ) : 3;
$authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array();
Expand Down Expand Up @@ -47,18 +47,18 @@ function newspack_blocks_render_block_carousel( $attributes ) {
$authors = Newspack_Blocks::prepare_authors();
$newspack_blocks_post_id[ $post_id ] = true;

$article_classes = array(
$article_classes = [
'post-has-image',
'swiper-slide',
);
];

// Add classes based on the post's assigned categories and tags.
$article_classes[] = Newspack_Blocks::get_term_classes( $post_id );

// Get sponsors for this post.
$sponsors = Newspack_Blocks::get_all_sponsors( $post_id );

++$counter;
$counter++;
$has_featured_image = has_post_thumbnail();
$post_type = get_post_type();
$post_link = Newspack_Blocks::get_post_link( $post_id );
Expand All @@ -72,7 +72,7 @@ function newspack_blocks_render_block_carousel( $attributes ) {
$show_credit = $attributes['showCredit'];

// Validate the value of the "image fit" attribute.
$image_fits = array( 'cover', 'contain' );
$image_fits = [ 'cover', 'contain' ];
$image_fit = in_array( $attributes['imageFit'], $image_fits, true ) ? $attributes['imageFit'] : $image_fits[0];
?>

Expand Down Expand Up @@ -129,7 +129,7 @@ function newspack_blocks_render_block_carousel( $attributes ) {
<div class="entry-meta">
<?php
if ( ! empty( $sponsors ) ) :
$sponsor_classes = array( 'entry-sponsors' );
$sponsor_classes = [ 'entry-sponsors' ];
if ( Newspack_Blocks::newspack_display_sponsors_and_authors( $sponsors ) ) {
$sponsor_classes[] = 'plus-author';
}
Expand Down Expand Up @@ -250,12 +250,12 @@ function newspack_blocks_render_block_carousel( $attributes ) {
);
$autoplay_ui = $autoplay ? newspack_blocks_carousel_block_autoplay_ui( $newspack_blocks_carousel_id ) : '';

$data_attributes = array(
$data_attributes = [
'data-current-post-id=' . $post_id,
'data-slides-per-view=' . esc_attr( $slides_per_view ),
'data-slide-count=' . $counter,
'data-aspect-ratio=' . esc_attr( $aspect_ratio ),
);
];

if ( $autoplay ) {
$data_attributes[] = 'data-autoplay=1';
Expand Down Expand Up @@ -399,7 +399,7 @@ function newspack_blocks_register_carousel() {
),
),
'render_callback' => 'newspack_blocks_render_block_carousel',
'supports' => array(),
'supports' => [],
),
'carousel'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,87 +38,87 @@ public function register_routes() {
register_rest_route(
$this->namespace,
'/articles',
array(
array(
[
[
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'callback' => [ $this, 'get_items' ],
'args' => $this->get_attribute_schema(),
'permission_callback' => '__return_true',
),
)
],
]
);

// Endpoint to get articles in the editor, in regular/query mode.
register_rest_route(
$this->namespace,
'/newspack-blocks-posts',
array(
[
'methods' => \WP_REST_Server::READABLE,
'callback' => array( 'Newspack_Blocks_API', 'posts_endpoint' ),
'callback' => [ 'Newspack_Blocks_API', 'posts_endpoint' ],
'args' => array_merge(
$this->get_attribute_schema(),
array(
'exclude' => array( // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
[
'exclude' => [ // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
),
'include' => array(
],
'include' => [
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
),
)
],
]
),
'permission_callback' => function () {
'permission_callback' => function() {
return current_user_can( 'edit_posts' );
},
)
]
);

// Endpoint to get articles in the editor, in specific posts mode.
register_rest_route(
$this->namespace,
'/newspack-blocks-specific-posts',
array(
[
'methods' => \WP_REST_Server::READABLE,
'callback' => array( 'Newspack_Blocks_API', 'specific_posts_endpoint' ),
'args' => array(
'search' => array(
'callback' => [ 'Newspack_Blocks_API', 'specific_posts_endpoint' ],
'args' => [
'search' => [
'sanitize_callback' => 'sanitize_text_field',
),
'postsToShow' => array(
],
'postsToShow' => [
'sanitize_callback' => 'absint',
),
'postType' => array(
],
'postType' => [
'type' => 'array',
'items' => array(
'type' => 'string',
),
'default' => array(),
),
),
'permission_callback' => function () {
],
],
'permission_callback' => function() {
return current_user_can( 'edit_posts' );
},
)
]
);

// Endpoint to get styles in the editor.
register_rest_route(
$this->namespace,
'/homepage-articles-css',
array(
[
'methods' => \WP_REST_Server::READABLE,
'callback' => array( 'Newspack_Blocks_API', 'css_endpoint' ),
'permission_callback' => function () {
'callback' => [ 'Newspack_Blocks_API', 'css_endpoint' ],
'permission_callback' => function() {
return current_user_can( 'edit_posts' );
},
)
]
);
}

Expand All @@ -130,16 +130,16 @@ public function register_routes() {
*/
public function get_items( $request ) {
$page = (int) $request->get_param( 'page' ) ?? 1;
$exclude_ids = $request->get_param( 'exclude_ids' ) ?? array();
$exclude_ids = $request->get_param( 'exclude_ids' ) ?? [];
$next_page = $page + 1;
$attributes = wp_parse_args(
$request->get_params() ?? array(),
$request->get_params() ?? [],
wp_list_pluck( $this->get_attribute_schema(), 'default' )
);

$deduplicate = $request->get_param( 'deduplicate' ) ?? 1;
if ( ! $deduplicate ) {
$exclude_ids = array();
$exclude_ids = [];
}

$article_query_args = Newspack_Blocks::build_articles_query( $attributes, apply_filters( 'newspack_blocks_block_name', 'newspack-blocks/homepage-articles' ) );
Expand All @@ -148,23 +148,23 @@ public function get_items( $request ) {
$query = ! empty( $exclude_ids ) ?
array_merge(
$article_query_args,
array(
[
'post__not_in' => $exclude_ids, // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in
)
]
) :
array_merge(
$article_query_args,
array(
[
'paged' => $page,
)
]
);

// Run Query.
$article_query = new WP_Query( $query );

// Defaults.
$items = array();
$ids = array();
$items = [];
$ids = [];
$next_url = '';

Newspack_Blocks::filter_excerpt( $attributes );
Expand All @@ -174,9 +174,9 @@ public function get_items( $request ) {
$article_query->the_post();
$html = Newspack_Blocks::template_inc(
__DIR__ . '/templates/article.php',
array(
[
'attributes' => $attributes,
)
]
);

$items[]['html'] = $html;
Expand All @@ -191,26 +191,26 @@ public function get_items( $request ) {
$next_url = add_query_arg(
array_merge(
array_map(
function ( $attribute ) {
function( $attribute ) {
return false === $attribute ? '0' : $attribute;
},
$attributes
),
array(
[
'exclude_ids' => false,
'page' => $next_page,
)
]
),
rest_url( '/newspack-blocks/v1/articles' )
);
}

return rest_ensure_response(
array(
[
'items' => $items,
'ids' => $ids,
'next' => $next_url,
)
]
);
}

Expand All @@ -228,15 +228,15 @@ public function get_attribute_schema() {

$this->attribute_schema = array_merge(
$block_json['attributes'],
array(
'exclude_ids' => array(
[
'exclude_ids' => [
'type' => 'array',
'default' => array(),
'items' => array(
'default' => [],
'items' => [
'type' => 'integer',
),
),
)
],
],
]
);
}
return $this->attribute_schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

call_user_func(
function ( $data ) {
function( $data ) {
$attributes = apply_filters( 'newspack_blocks_homepage_posts_block_attributes', $data['attributes'] );
$authors = Newspack_Blocks::prepare_authors();
$classes = array();
Expand Down Expand Up @@ -42,14 +42,14 @@ function ( $data ) {

// This global will be used by the newspack_blocks_filter_hpb_srcset filter.
global $newspack_blocks_hpb_rendering_context;
$newspack_blocks_hpb_rendering_context = array( 'attrs' => $attributes );
$newspack_blocks_hpb_rendering_context = [ 'attrs' => $attributes ];

// Disable lazy loading by using an arbitraty `loading` attribute other than `lazy`.
// Empty string or `false` would still result in `lazy`.
if ( $attributes['disableImageLazyLoad'] ) {
$thumbnail_args['loading'] = 'none';
}
if ( $attributes['fetchPriority'] && in_array( $attributes['fetchPriority'], array( 'high', 'low', 'auto' ), true ) ) {
if ( $attributes['fetchPriority'] && in_array( $attributes['fetchPriority'], [ 'high', 'low', 'auto' ], true ) ) {
$thumbnail_args['fetchpriority'] = $attributes['fetchPriority'];
}

Expand Down Expand Up @@ -165,7 +165,7 @@ class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
<div class="entry-meta">
<?php
if ( ! empty( $sponsors ) ) :
$sponsor_classes = array( 'entry-sponsors' );
$sponsor_classes = [ 'entry-sponsors' ];
if ( Newspack_Blocks::newspack_display_sponsors_and_authors( $sponsors ) ) {
$sponsor_classes[] = 'plus-author';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

call_user_func(
function ( $data ) {
function( $data ) {
echo Newspack_Blocks::template_inc( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
__DIR__ . '/articles-loop.php',
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

call_user_func(
function ( $data ) {
function( $data ) {
$attributes = $data['attributes'];
$article_query = $data['article_query'];

Expand Down
Loading
Loading