Fix Possible NULL Value of duplicate_post_taxonomies_blacklist
#360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Cloning a post can cause a critical error due to the type of
get_option( 'duplicate_post_taxonomies_blacklist' )
which can be aNULL
value.Related Issues:
duplicate_post_taxonomies_blacklist
option causing cloning errors due to inconsistent output type (array, empty string, null)Summary
This PR can be summarized in the following changelog entry:
duplicate_post_taxonomies_blacklist
option. Props to @michael-sumner.Relevant technical choices:
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
It's a bit tricky to reproduce the problem because it looks like it can be caused by caching, or by pathological situations where the option value has been stored in the wrong way. We'll need to use filters to emulate those cases.
Reproduce the issue with NULL value
duplicate_post_*
rows inwp_options
)functions.php
and add this snippet:add_filter( 'option_duplicate_post_taxonomies_blacklist', '__return_null' );
Fatal error: Uncaught Error: in_array(): Argument #2 ($haystack) must be of type array, null given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 149
functions.php
functions.php
Fatal error: Uncaught Error: array_diff(): Argument #2 must be of type array, null given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 303
functions.php
before proceedingReproduce the issue with a string value
duplicate_post_*
rows inwp_options
)functions.php
and add this snippet:add_filter( 'option_duplicate_post_taxonomies_blacklist', function(){ return 'foo'; } );
Fatal error: Uncaught Error: in_array(): Argument #2 ($haystack) must be of type array, string given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 149
functions.php
functions.php
Fatal error: Uncaught Error: array_diff(): Argument #2 must be of type array, string given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 303
functions.php
before proceedingtest the fix with NULL value
duplicate_post_*
rows inwp_options
)functions.php
and add this snippet:add_filter( 'option_duplicate_post_taxonomies_blacklist', '__return_null' );
Fatal error: Uncaught Error: in_array(): Argument #2 ($haystack) must be of type array, null given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 149
Fatal error: Uncaught Error: array_diff(): Argument #2 must be of type array, null given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 303
functions.php
before proceedingtest the fix with with a string value
duplicate_post_*
rows inwp_options
)functions.php
and add this snippet:add_filter( 'option_duplicate_post_taxonomies_blacklist', function(){ return 'foo'; } );
Fatal error: Uncaught Error: in_array(): Argument #2 ($haystack) must be of type array, string given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 149
Fatal error: Uncaught Error: array_diff(): Argument #2 must be of type array, string given in /home/lopo/src/Yoast/plugin-development-docker/plugins/duplicate-post/admin-functions.php on line 303
Relevant test scenarios
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Documentation
Quality assurance
Innovation
innovation
label and noted the work hours.Fixes #263