publishpress / PublishPress-Blocks

PublishPress Blocks adds the missing blocks and configuration you need to build professional websites. Take the control of the new Gutenberg editor with user edition profile configuration and 20+ new blocks and options.
15 stars 8 forks source link

Error logs #535

Closed htmgarcia closed 3 years ago

htmgarcia commented 3 years ago

PHP Warning: Invalid argument supplied for foreach() in wp-content/plugins/advanced-gutenberg/assets/blocks/recent-posts/block.php on line 897

advgbGetAdditionalTaxInfo() wp-includes/rest-api/endpoints/class-wp-rest-controller.php:433

advgbGetAdditionalTaxInfo() wp-includes/rest-api/endpoints/class-wp-rest-controller.php:433

advgbGetTaxonomyTerms() wp-content/plugins/advanced-gutenberg/assets/blocks/recent-posts/block.php:880

htmgarcia commented 3 years ago

@contactashish13 when editing a Content Display block, if you choose a CPT, filter by taxonomies and choose to display some of them. Then select a different content type (like WC Products). This causes a warning or a blank result in frontend. Please check the 2 cases below.

Case scenario 1

  1. Create a Content Display block
  2. Choose a CPT that have taxonomies
  3. In Filters panel choose at least one taxonomy
  4. In Display settings > Display these taxonomies, choose at least one taxonomy
  5. Choose a different Post type. In particular Products (from WooCommerce)
  6. Save and preview in frontend

Result: The block is not displayed in frontend.

The attributes marked with red doesn't belong to the postType attribute: Screen Shot 2021-05-25 at 15 24 09 If you manually remove these attributes and save changes, the issue is solved.

Case scenario 2

  1. Create a Content Display block
  2. Choose a CPT that have taxonomies
  3. In Display settings > Display these taxonomies, choose at least one taxonomy
  4. Choose a different Post type. In particular Products (from WooCommerce)
  5. Save and preview in frontend

Result: PHP Warning: Invalid argument supplied for foreach() in wp-content/plugins/advanced-gutenberg/assets/blocks/recent-posts/block.php on line 897

If you don't see the warning in frontend, please check the error logs from your site.

The attribute marked with red doesn't belong to the postType attribute: Screen Shot 2021-05-25 at 15 27 43 If you manually remove this attribute and save changes, the issue is solved.

Possible solutions

  1. Reset the attributes "taxonomies" and "showCustomTaxList" when choosing a different Post type.
  2. Reset the attributes "taxonomies" and "showCustomTaxList" if doesn't match with "postType" attribute when loading in editor (for existing broken instances of the block).
contactashish13 commented 3 years ago

@htmgarcia can you mention how number 2 will happen? I'm not very sure how to test this scenario

htmgarcia commented 3 years ago

@contactashish13 number 2 suggestion complement number 1. The problems that solves are Case scenario 1 and Case scenario 2.

htmgarcia commented 3 years ago

If you have a different solution in mind for Case scenario 1 and Case scenario 2, please be my guest.

contactashish13 commented 3 years ago

@htmgarcia your fix indeed solves for both scenarios but how will the below happen? How will an existing block be broken is what I don't understand? Can you please share a scenario for me to test?

Reset the attributes "taxonomies" and "showCustomTaxList" if doesn't match with "postType" attribute when loading in editor (for existing broken instances of the block).

htmgarcia commented 3 years ago

@contactashish13 Case scenario 2 can happen to users who already created an instance of Content Display block with 2.7.0 version. A solution for that case scenario is kind of a deprecation (without being technically one).

While using version 2.7.0, follow the steps from Case scenario 2. Are you able you reproduce the warning? If so, do you see it on the frontend or only in the error logs.

contactashish13 commented 3 years ago

@htmgarcia yes I see the warning in the error.log and have addressed that. I was wondering how to address the number 2 issue so thanks for clarifying... I may be able to do that now.

contactashish13 commented 3 years ago

@htmgarcia I wasn't able to reproduce the error. These are the steps:

  1. Using 2.7.0 created a new block for custom posts, filtered using a taxonomy and display a taxonomy
  2. saved
  3. viewed the post
  4. Changed branch to ppb-538
  5. refreshed the post, block is fine
  6. viewed the post, block is fine
  7. changed the custom post to WooCommerce Products, the block does not break
  8. saved
  9. viewed the post, block is fine

I guess this is because your changes for resetting "taxonomies" and "showCustomTaxList" works properly and no matter what I did, I was unable to break the block.

htmgarcia commented 3 years ago

@contactashish13 I made a screencast reproducing the issue https://youtu.be/wa5a95sN61s

htmgarcia commented 3 years ago

@contactashish13 the PR #559 fixed the warning. Thanks!