@automattic/newspack-blocks 4.12.1 → 4.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [4.12.2](https://github.com/Automattic/newspack-blocks/compare/v4.12.1...v4.12.2) (2025-06-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **homepage-articles:** add style to head ([#2123](https://github.com/Automattic/newspack-blocks/issues/2123)) ([9305927](https://github.com/Automattic/newspack-blocks/commit/9305927466817d7287d2e6a4f2f3dcf9d473f941))
7
+ * the warning generated by get_term_classes because the get_the_terms might return null element ([#2115](https://github.com/Automattic/newspack-blocks/issues/2115)) ([04808de](https://github.com/Automattic/newspack-blocks/commit/04808de9aa37f810a74aa1335261422013b316e7))
8
+
1
9
  ## [4.12.1](https://github.com/Automattic/newspack-blocks/compare/v4.12.0...v4.12.1) (2025-05-29)
2
10
 
3
11
 
package/composer.lock CHANGED
@@ -800,21 +800,22 @@
800
800
  },
801
801
  {
802
802
  "name": "phpcompatibility/phpcompatibility-wp",
803
- "version": "2.1.6",
803
+ "version": "2.1.7",
804
804
  "source": {
805
805
  "type": "git",
806
806
  "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git",
807
- "reference": "80ccb1a7640995edf1b87a4409fa584cd5869469"
807
+ "reference": "5bfbbfbabb3df2b9a83e601de9153e4a7111962c"
808
808
  },
809
809
  "dist": {
810
810
  "type": "zip",
811
- "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/80ccb1a7640995edf1b87a4409fa584cd5869469",
812
- "reference": "80ccb1a7640995edf1b87a4409fa584cd5869469",
811
+ "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/5bfbbfbabb3df2b9a83e601de9153e4a7111962c",
812
+ "reference": "5bfbbfbabb3df2b9a83e601de9153e4a7111962c",
813
813
  "shasum": ""
814
814
  },
815
815
  "require": {
816
816
  "phpcompatibility/php-compatibility": "^9.0",
817
- "phpcompatibility/phpcompatibility-paragonie": "^1.0"
817
+ "phpcompatibility/phpcompatibility-paragonie": "^1.0",
818
+ "squizlabs/php_codesniffer": "^3.3"
818
819
  },
819
820
  "require-dev": {
820
821
  "dealerdirect/phpcodesniffer-composer-installer": "^1.0"
@@ -864,9 +865,13 @@
864
865
  {
865
866
  "url": "https://opencollective.com/php_codesniffer",
866
867
  "type": "open_collective"
868
+ },
869
+ {
870
+ "url": "https://thanks.dev/u/gh/phpcompatibility",
871
+ "type": "thanks_dev"
867
872
  }
868
873
  ],
869
- "time": "2025-01-16T22:34:19+00:00"
874
+ "time": "2025-05-12T16:38:37+00:00"
870
875
  },
871
876
  {
872
877
  "name": "phpcsstandards/phpcsextra",
@@ -2526,16 +2531,16 @@
2526
2531
  },
2527
2532
  {
2528
2533
  "name": "squizlabs/php_codesniffer",
2529
- "version": "3.12.0",
2534
+ "version": "3.13.0",
2530
2535
  "source": {
2531
2536
  "type": "git",
2532
2537
  "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git",
2533
- "reference": "2d1b63db139c3c6ea0c927698e5160f8b3b8d630"
2538
+ "reference": "65ff2489553b83b4597e89c3b8b721487011d186"
2534
2539
  },
2535
2540
  "dist": {
2536
2541
  "type": "zip",
2537
- "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/2d1b63db139c3c6ea0c927698e5160f8b3b8d630",
2538
- "reference": "2d1b63db139c3c6ea0c927698e5160f8b3b8d630",
2542
+ "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/65ff2489553b83b4597e89c3b8b721487011d186",
2543
+ "reference": "65ff2489553b83b4597e89c3b8b721487011d186",
2539
2544
  "shasum": ""
2540
2545
  },
2541
2546
  "require": {
@@ -2606,7 +2611,7 @@
2606
2611
  "type": "thanks_dev"
2607
2612
  }
2608
2613
  ],
2609
- "time": "2025-03-18T05:04:51+00:00"
2614
+ "time": "2025-05-11T03:36:00+00:00"
2610
2615
  },
2611
2616
  {
2612
2617
  "name": "symfony/console",
@@ -839,14 +839,18 @@ class Newspack_Blocks {
839
839
  $tags = get_the_terms( $post_id, 'post_tag' );
840
840
  if ( ! empty( $tags ) ) {
841
841
  foreach ( $tags as $tag ) {
842
- $classes[] = 'tag-' . $tag->slug;
842
+ if ( ! empty( $tag->slug ) ) {
843
+ $classes[] = 'tag-' . $tag->slug;
844
+ }
843
845
  }
844
846
  }
845
847
 
846
848
  $categories = get_the_terms( $post_id, 'category' );
847
849
  if ( ! empty( $categories ) ) {
848
850
  foreach ( $categories as $cat ) {
849
- $classes[] = 'category-' . $cat->slug;
851
+ if ( ! empty( $cat->slug ) ) {
852
+ $classes[] = 'category-' . $cat->slug;
853
+ }
850
854
  }
851
855
  }
852
856
 
@@ -854,7 +858,9 @@ class Newspack_Blocks {
854
858
  $terms = get_the_terms( $post_id, $tax['slug'] );
855
859
  if ( ! empty( $terms ) ) {
856
860
  foreach ( $terms as $term ) {
857
- $classes[] = $term->taxonomy . '-' . $term->slug;
861
+ if ( ! empty( $term->taxonomy ) && ! empty( $term->slug ) ) {
862
+ $classes[] = $term->taxonomy . '-' . $term->slug;
863
+ }
858
864
  }
859
865
  }
860
866
  }
@@ -7,7 +7,7 @@
7
7
  * Author URI: https://newspack.com/
8
8
  * Text Domain: newspack-blocks
9
9
  * Domain Path: /languages
10
- * Version: 4.12.1
10
+ * Version: 4.12.2
11
11
  *
12
12
  * @package Newspack_Blocks
13
13
  */
@@ -15,7 +15,7 @@
15
15
  define( 'NEWSPACK_BLOCKS__PLUGIN_FILE', __FILE__ );
16
16
  define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
17
17
  define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( NEWSPACK_BLOCKS__PLUGIN_FILE ) );
18
- define( 'NEWSPACK_BLOCKS__VERSION', '4.12.1' );
18
+ define( 'NEWSPACK_BLOCKS__VERSION', '4.12.2' );
19
19
 
20
20
  require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks.php';
21
21
  require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-api.php';
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@automattic/newspack-blocks",
3
- "version": "4.12.1",
3
+ "version": "4.12.2",
4
4
  "author": "Automattic",
5
5
  "devDependencies": {
6
6
  "@rushstack/eslint-patch": "^1.11.0",
7
7
  "@testing-library/dom": "^10.4.0",
8
8
  "@testing-library/user-event": "^14.6.1",
9
9
  "@types/lodash": "^4.17.16",
10
- "@wordpress/browserslist-config": "^6.22.0",
10
+ "@wordpress/browserslist-config": "^6.23.0",
11
11
  "eslint": "^8.57.0",
12
12
  "fetch-mock-jest": "^1.5.1",
13
13
  "html-entities": "^2.6.0",
@@ -232,22 +232,40 @@ function newspack_blocks_render_block_homepage_articles( $attributes ) {
232
232
  return;
233
233
  }
234
234
 
235
+ // If the block is rendered in wp_kses_post() call, ensure the `time` tag is allowed.
236
+ \add_filter(
237
+ 'wp_kses_allowed_html',
238
+ function( $tags ) {
239
+ $tags['time'] = [
240
+ 'class' => true,
241
+ 'datetime' => true,
242
+ ];
243
+ return $tags;
244
+ }
245
+ );
246
+
235
247
  // Gather all Homepage Articles blocks on the page and output only the needed CSS.
236
- // This CSS will be printed along with the first found block markup.
248
+ // This CSS will be printed in the document head once.
237
249
  global $newspack_blocks_hpb_all_blocks;
238
- $inline_style_html = '';
250
+ static $has_enqueued_styles = false;
251
+
239
252
  if ( ! is_array( $newspack_blocks_hpb_all_blocks ) ) {
240
253
  $newspack_blocks_hpb_all_blocks = newspack_blocks_retrieve_homepage_articles_blocks(
241
254
  parse_blocks( get_the_content() ),
242
255
  $block_name
243
256
  );
244
- $all_used_attrs = newspack_blocks_collect_all_attribute_values( array_column( $newspack_blocks_hpb_all_blocks, 'attrs' ) );
245
- $css_string = newspack_blocks_get_homepage_articles_css_string( $all_used_attrs );
246
- ob_start();
247
- ?>
248
- <style id="newspack-blocks-inline-css" type="text/css"><?php echo esc_html( $css_string ); ?></style>
249
- <?php
250
- $inline_style_html = ob_get_clean();
257
+ $all_used_attrs = newspack_blocks_collect_all_attribute_values( array_column( $newspack_blocks_hpb_all_blocks, 'attrs' ) );
258
+
259
+ if ( ! $has_enqueued_styles ) {
260
+ $css_string = newspack_blocks_get_homepage_articles_css_string( $all_used_attrs );
261
+
262
+ // Enqueue CSS in head instead of adding inline to block content.
263
+ wp_register_style( 'newspack-blocks-homepage-articles-inline', false, [], \NEWSPACK_BLOCKS__VERSION );
264
+ wp_enqueue_style( 'newspack-blocks-homepage-articles-inline' );
265
+ wp_add_inline_style( 'newspack-blocks-homepage-articles-inline', $css_string );
266
+
267
+ $has_enqueued_styles = true;
268
+ }
251
269
  }
252
270
 
253
271
  // This will let the FSE plugin know we need CSS/JS now.
@@ -362,7 +380,6 @@ function newspack_blocks_render_block_homepage_articles( $attributes ) {
362
380
  class="<?php echo esc_attr( $classes ); ?>"
363
381
  style="<?php echo esc_attr( $styles ); ?>"
364
382
  >
365
- <?php echo $inline_style_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
366
383
  <div data-posts data-current-post-id="<?php the_ID(); ?>">
367
384
  <?php if ( '' !== $attributes['sectionHeader'] ) : ?>
368
385
  <h2 class="article-section-title">
@@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
22
22
 
23
23
  require_once __DIR__ . '/composer/autoload_real.php';
24
24
 
25
- return ComposerAutoloaderInitb9650d081ed197aa9a82911260d0ec4e::getLoader();
25
+ return ComposerAutoloaderInit88aae354c1f49f907c8989c59764ad48::getLoader();
@@ -2,7 +2,7 @@
2
2
 
3
3
  // autoload_real.php @generated by Composer
4
4
 
5
- class ComposerAutoloaderInitb9650d081ed197aa9a82911260d0ec4e
5
+ class ComposerAutoloaderInit88aae354c1f49f907c8989c59764ad48
6
6
  {
7
7
  private static $loader;
8
8
 
@@ -22,12 +22,12 @@ class ComposerAutoloaderInitb9650d081ed197aa9a82911260d0ec4e
22
22
  return self::$loader;
23
23
  }
24
24
 
25
- spl_autoload_register(array('ComposerAutoloaderInitb9650d081ed197aa9a82911260d0ec4e', 'loadClassLoader'), true, true);
25
+ spl_autoload_register(array('ComposerAutoloaderInit88aae354c1f49f907c8989c59764ad48', 'loadClassLoader'), true, true);
26
26
  self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27
- spl_autoload_unregister(array('ComposerAutoloaderInitb9650d081ed197aa9a82911260d0ec4e', 'loadClassLoader'));
27
+ spl_autoload_unregister(array('ComposerAutoloaderInit88aae354c1f49f907c8989c59764ad48', 'loadClassLoader'));
28
28
 
29
29
  require __DIR__ . '/autoload_static.php';
30
- call_user_func(\Composer\Autoload\ComposerStaticInitb9650d081ed197aa9a82911260d0ec4e::getInitializer($loader));
30
+ call_user_func(\Composer\Autoload\ComposerStaticInit88aae354c1f49f907c8989c59764ad48::getInitializer($loader));
31
31
 
32
32
  $loader->register(true);
33
33
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  namespace Composer\Autoload;
6
6
 
7
- class ComposerStaticInitb9650d081ed197aa9a82911260d0ec4e
7
+ class ComposerStaticInit88aae354c1f49f907c8989c59764ad48
8
8
  {
9
9
  public static $classMap = array (
10
10
  'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
@@ -13,7 +13,7 @@ class ComposerStaticInitb9650d081ed197aa9a82911260d0ec4e
13
13
  public static function getInitializer(ClassLoader $loader)
14
14
  {
15
15
  return \Closure::bind(function () use ($loader) {
16
- $loader->classMap = ComposerStaticInitb9650d081ed197aa9a82911260d0ec4e::$classMap;
16
+ $loader->classMap = ComposerStaticInit88aae354c1f49f907c8989c59764ad48::$classMap;
17
17
 
18
18
  }, null, ClassLoader::class);
19
19
  }
@@ -3,7 +3,7 @@
3
3
  'name' => 'automattic/newspack-blocks',
4
4
  'pretty_version' => 'dev-trunk',
5
5
  'version' => 'dev-trunk',
6
- 'reference' => 'c5ee4d4c7f2cf68abd97466b2dd570b77ec06365',
6
+ 'reference' => '9a0ef42df61b174e9f18694735f72abc32951477',
7
7
  'type' => 'wordpress-plugin',
8
8
  'install_path' => __DIR__ . '/../../',
9
9
  'aliases' => array(),
@@ -13,7 +13,7 @@
13
13
  'automattic/newspack-blocks' => array(
14
14
  'pretty_version' => 'dev-trunk',
15
15
  'version' => 'dev-trunk',
16
- 'reference' => 'c5ee4d4c7f2cf68abd97466b2dd570b77ec06365',
16
+ 'reference' => '9a0ef42df61b174e9f18694735f72abc32951477',
17
17
  'type' => 'wordpress-plugin',
18
18
  'install_path' => __DIR__ . '/../../',
19
19
  'aliases' => array(),