Skip to content

Conversation

@mreishus
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

The newspack_blocks_render_block_homepage_articles() function does this:

	$articles_rest_url = add_query_arg(
		array_merge(
			array_map(
				function( $attribute ) {
					return false === $attribute ? '0' : $attribute;
				},
				$attributes
			),
			[
				'page' => 2,
			]
		),
		rest_url( '/newspack-blocks/v1/articles' )
	);

However, array_map only works one level deep into arrays. When nested arrays are passed in, this code converts the sub array's value to the string "Array" which generates a warning:

[30-Jan-2024 18:51:17 UTC] Warning: Array to string conversion in (...)/wp-content/plugins/editing-toolkit-plugin/prod/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/view.php on line 160 

Fix: Use map_deep() from WordPress instead ( https://developer.wordpress.org/reference/functions/map_deep/ ).

Example of one of the values passed in that causes this warning, before and after the mapping:

    [before] => Array                                                                                                       
        (                                                                                                                   
            [action] => hide                                                                                                
            [rules] => Array                                                                                                
                (                                                                                                           
                    [0] => Array                                                                                            
                        (                                                                                                   
                            [major] => category                                                                             
                            [minor] => 22388                                                                                
                        )                                                                                                   
                                                                                                                            
                )                                                                                                           
                                                                                                                            
            [match_all] => 0                                                                                                
        )                                                                                                                   

    [after] => Array
        (
            [action] => hide
            [rules] => Array
            [match_all] => 0
        )

Notice that $v['rules'] is transformed from an actual array to the string Array.

How to test the changes in this Pull Request:

  1. See D136469-code for an example of this applied to WPCOM, with specific sites listed that exhibit the warning and testing directions.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@mreishus mreishus requested a review from a team as a code owner January 30, 2024 19:37
@mreishus mreishus self-assigned this Jan 30, 2024
@adekbadek
Copy link
Member

Thanks!

@adekbadek adekbadek merged commit 24085d8 into master Feb 1, 2024
@adekbadek adekbadek deleted the update/homepage-articles branch February 1, 2024 13:49
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0-epic-test-epic-release-flow-raz.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0-epic-ras-acc.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 8, 2024
# [3.0.0-alpha.1](v2.6.2...v3.0.0-alpha.1) (2024-02-08)

### Bug Fixes

* **homepage-articles:** use map_deep to construct articles_rest_url and resolve PHP 8.1 warnings ([#1655](#1655)) ([24085d8](24085d8))
* prevent error in modal-checkout check ([7e2a6c7](7e2a6c7))

### Features

* **ci:** add `epic/*` release workflow and rename `master` to `trunk` ([#1656](#1656)) ([c788e55](c788e55))
* deprecate streamlined (Stripe) Donate block version ([#1638](#1638)) ([11bd0d6](11bd0d6))
* **homepage-posts:** add custom taxonomy exclusions filter ([#1641](#1641)) ([b140a99](b140a99))
* **reader-revenue:** make NYP and Stripe Gateway optional ([#1645](#1645)) ([1322d7c](1322d7c))

### BREAKING CHANGES

* streamlined (Stripe) Donate block version is no more
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 20, 2024
# [3.0.0](v2.6.2...v3.0.0) (2024-02-20)

### Bug Fixes

* **homepage-articles:** use map_deep to construct articles_rest_url and resolve PHP 8.1 warnings ([#1655](#1655)) ([24085d8](24085d8))
* prevent error in modal-checkout check ([7e2a6c7](7e2a6c7))

### Features

* **ci:** add `epic/*` release workflow and rename `master` to `trunk` ([#1656](#1656)) ([c788e55](c788e55))
* deprecate streamlined (Stripe) Donate block version ([#1638](#1638)) ([11bd0d6](11bd0d6))
* **homepage-posts:** add custom taxonomy exclusions filter ([#1641](#1641)) ([b140a99](b140a99))
* **reader-revenue:** make NYP and Stripe Gateway optional ([#1645](#1645)) ([1322d7c](1322d7c))

### BREAKING CHANGES

* streamlined (Stripe) Donate block version is no more
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants