@automattic/newspack-blocks 4.29.0 → 4.29.1

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,10 @@
1
+ ## @automattic/newspack-blocks [4.29.1](https://github.com/Automattic/newspack-workspace/compare/newspack-blocks@4.29.0...newspack-blocks@4.29.1) (2026-08-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **author-profile:** hide default avatars when the toggle is on ([#570](https://github.com/Automattic/newspack-workspace/issues/570)) ([4aba9cd](https://github.com/Automattic/newspack-workspace/commit/4aba9cd016d8b5645358640dd27f9ff9070239b1))
7
+
1
8
  # @automattic/newspack-blocks [4.29.0](https://github.com/Automattic/newspack-workspace/compare/newspack-blocks@4.28.0...newspack-blocks@4.29.0) (2026-08-03)
2
9
 
3
10
 
@@ -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.29.0
10
+ * Version: 4.29.1
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.29.0' );
18
+ define( 'NEWSPACK_BLOCKS__VERSION', '4.29.1' );
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/newspack-blocks",
3
- "version": "4.29.0",
3
+ "version": "4.29.1",
4
4
  "author": "Automattic",
5
5
  "description": "=== Newspack Blocks === Contributors: (this should be a list of wordpress.org userid's) Donate link: https://example.com/ Tags: comments, spam Requires at least: 4.5 Tested up to: 5.1.1 Stable tag: 0.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html",
6
6
  "repository": {
@@ -210,9 +210,9 @@ class WP_REST_Newspack_Authors_Controller extends WP_REST_Controller {
210
210
  $guest_author = ( new CoAuthors_Guest_Authors() )->get_guest_author_by( 'id', $guest_author->ID );
211
211
 
212
212
  if ( in_array( 'avatar', $fields, true ) && function_exists( 'coauthors_get_avatar' ) ) {
213
- $avatar = coauthors_get_avatar( $guest_author, 256 );
213
+ $avatar = coauthors_get_avatar( $guest_author, 256, $avatar_hide_default ? 'blank' : '' );
214
214
 
215
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $avatar_hide_default ) ) {
215
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $avatar_hide_default ) ) {
216
216
  $guest_author_data['avatar'] = $avatar;
217
217
  }
218
218
  }
@@ -238,9 +238,9 @@ class WP_REST_Newspack_Authors_Controller extends WP_REST_Controller {
238
238
  ];
239
239
 
240
240
  if ( in_array( 'avatar', $fields, true ) ) {
241
- $avatar = get_avatar( $user->data->ID, 256 );
241
+ $avatar = get_avatar( $user->data->ID, 256, $avatar_hide_default ? 'blank' : '' );
242
242
 
243
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $avatar_hide_default ) ) {
243
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $avatar_hide_default ) ) {
244
244
  $user_data['avatar'] = $avatar;
245
245
  }
246
246
  }
@@ -501,8 +501,8 @@ class WP_REST_Newspack_Authors_Controller extends WP_REST_Controller {
501
501
  ];
502
502
 
503
503
  if ( in_array( 'avatar', $fields, true ) ) {
504
- $avatar = get_avatar( $user->data->ID, 256 );
505
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $avatar_hide_default ) ) {
504
+ $avatar = get_avatar( $user->data->ID, 256, $avatar_hide_default ? 'blank' : '' );
505
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $avatar_hide_default ) ) {
506
506
  $user_data['avatar'] = $avatar;
507
507
  }
508
508
  }
@@ -551,8 +551,8 @@ class WP_REST_Newspack_Authors_Controller extends WP_REST_Controller {
551
551
  ];
552
552
 
553
553
  if ( in_array( 'avatar', $fields, true ) && function_exists( 'coauthors_get_avatar' ) ) {
554
- $avatar = coauthors_get_avatar( $guest_author, 256 );
555
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $avatar_hide_default ) ) {
554
+ $avatar = coauthors_get_avatar( $guest_author, 256, $avatar_hide_default ? 'blank' : '' );
555
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $avatar_hide_default ) ) {
556
556
  $author_data['avatar'] = $avatar;
557
557
  }
558
558
  }
@@ -588,8 +588,8 @@ class WP_REST_Newspack_Authors_Controller extends WP_REST_Controller {
588
588
  ];
589
589
 
590
590
  if ( in_array( 'avatar', $fields, true ) && function_exists( 'coauthors_get_avatar' ) ) {
591
- $avatar = coauthors_get_avatar( $guest_author, 256 );
592
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $avatar_hide_default ) ) {
591
+ $avatar = coauthors_get_avatar( $guest_author, 256, $avatar_hide_default ? 'blank' : '' );
592
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $avatar_hide_default ) ) {
593
593
  $author_data['avatar'] = $avatar;
594
594
  }
595
595
  }
@@ -607,8 +607,8 @@ class WP_REST_Newspack_Authors_Controller extends WP_REST_Controller {
607
607
  ];
608
608
 
609
609
  if ( in_array( 'avatar', $fields, true ) ) {
610
- $avatar = get_avatar( $user->data->ID, 256 );
611
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $avatar_hide_default ) ) {
610
+ $avatar = get_avatar( $user->data->ID, 256, $avatar_hide_default ? 'blank' : '' );
611
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $avatar_hide_default ) ) {
612
612
  $user_data['avatar'] = $avatar;
613
613
  }
614
614
  }
@@ -150,7 +150,7 @@ function newspack_blocks_get_author_or_guest_author( $author_id, $avatar_size =
150
150
  }
151
151
 
152
152
  $author = ( new CoAuthors_Guest_Authors() )->get_guest_author_by( 'id', $author_id );
153
- $avatar = function_exists( 'coauthors_get_avatar' ) ? coauthors_get_avatar( $author, $avatar_size ) : false;
153
+ $avatar = function_exists( 'coauthors_get_avatar' ) ? coauthors_get_avatar( $author, $avatar_size, $hide_default ? 'blank' : '' ) : false;
154
154
 
155
155
  // Format CAP guest author object to return to the render function.
156
156
  if ( $author && isset( $author->ID ) ) {
@@ -161,7 +161,7 @@ function newspack_blocks_get_author_or_guest_author( $author_id, $avatar_size =
161
161
  $author
162
162
  );
163
163
 
164
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $hide_default ) ) {
164
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $hide_default ) ) {
165
165
  $author['avatar'] = $avatar;
166
166
  }
167
167
  }
@@ -176,8 +176,8 @@ function newspack_blocks_get_author_or_guest_author( $author_id, $avatar_size =
176
176
  $wp_user
177
177
  );
178
178
 
179
- $avatar = get_avatar( $author_id, $avatar_size );
180
- if ( $avatar && ( false === strpos( $avatar, 'avatar-default' ) || ! $hide_default ) ) {
179
+ $avatar = get_avatar( $author_id, $avatar_size, $hide_default ? 'blank' : '' );
180
+ if ( \Newspack_Blocks\is_avatar_displayable( $avatar, $hide_default ) ) {
181
181
  $author['avatar'] = $avatar;
182
182
  }
183
183
  }
@@ -61,3 +61,29 @@ function get_authors_roles_slugs() {
61
61
  get_authors_roles()
62
62
  );
63
63
  }
64
+
65
+ /**
66
+ * Whether an avatar should be displayed, honoring a "hide default avatar" preference.
67
+ *
68
+ * Gravatar-served images never carry core's `avatar-default` class (core only
69
+ * emits it when no avatar was found, and the Gravatar branch always reports
70
+ * found), so a generated fallback like `d=mm` is indistinguishable from a real
71
+ * avatar by class alone. When hiding defaults, callers must fetch the avatar
72
+ * with Gravatar's `blank` fallback so it can be detected via the `d=blank`
73
+ * param — mirroring the Author List block's long-standing behavior.
74
+ *
75
+ * @param string|false $avatar Avatar HTML as returned by get_avatar()/coauthors_get_avatar().
76
+ * @param bool $hide_default Whether default (fallback) avatars should be hidden.
77
+ *
78
+ * @return bool True if the avatar should be displayed.
79
+ */
80
+ function is_avatar_displayable( $avatar, $hide_default ) {
81
+ if ( ! $avatar ) {
82
+ return false;
83
+ }
84
+ if ( ! $hide_default ) {
85
+ return true;
86
+ }
87
+ $is_default = false !== strpos( $avatar, 'avatar-default' ) || false !== strpos( $avatar, 'd=blank' );
88
+ return ! $is_default;
89
+ }
@@ -3,7 +3,7 @@
3
3
  'name' => 'automattic/newspack-blocks',
4
4
  'pretty_version' => 'dev-main',
5
5
  'version' => 'dev-main',
6
- 'reference' => '8a5fd59b2162a2b3cce706342177c7fc65f9f215',
6
+ 'reference' => '4aba9cd016d8b5645358640dd27f9ff9070239b1',
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-main',
15
15
  'version' => 'dev-main',
16
- 'reference' => '8a5fd59b2162a2b3cce706342177c7fc65f9f215',
16
+ 'reference' => '4aba9cd016d8b5645358640dd27f9ff9070239b1',
17
17
  'type' => 'wordpress-plugin',
18
18
  'install_path' => __DIR__ . '/../../',
19
19
  'aliases' => array(),