From 1cdd079d4b7c6c9d2a6b9fee2ca2a594530dca14 Mon Sep 17 00:00:00 2001 From: Michael Sumner Date: Wed, 7 Feb 2024 16:38:27 +0000 Subject: [PATCH 1/4] fix(admin-functions): allow empty or null --- admin-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin-functions.php b/admin-functions.php index f3df87c0d..cb439e550 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -294,7 +294,7 @@ function duplicate_post_copy_post_taxonomies( $new_id, $post ) { } $taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist' ); - if ( $taxonomies_blacklist === '' ) { + if ( empty( $taxonomies_blacklist ) ) { $taxonomies_blacklist = []; } if ( intval( get_option( 'duplicate_post_copyformat' ) ) === 0 ) { From 98b699a77dcefff876a1df858bb0de22ba8265c0 Mon Sep 17 00:00:00 2001 From: Enrico Battocchi Date: Fri, 17 Feb 2023 00:31:33 +0100 Subject: [PATCH 2/4] Add defensive coding to the upgrade function --- admin-functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin-functions.php b/admin-functions.php index cb439e550..5d365af51 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -151,8 +151,8 @@ function duplicate_post_plugin_upgrade() { ); add_option( 'duplicate_post_show_link_in', $show_links_in_defaults ); - $taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist' ); - if ( $taxonomies_blacklist === '' ) { + $taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist', [] ); + if ( empty( $taxonomies_blacklist ) ) { $taxonomies_blacklist = []; } if ( in_array( 'post_format', $taxonomies_blacklist, true ) ) { From e36463bd9327aa8b375abe5472a506201224a979 Mon Sep 17 00:00:00 2001 From: Enrico Battocchi Date: Fri, 17 Feb 2023 00:31:33 +0100 Subject: [PATCH 3/4] Add default value when retrieving option --- admin-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin-functions.php b/admin-functions.php index 5d365af51..04fc2c3cd 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -293,7 +293,7 @@ function duplicate_post_copy_post_taxonomies( $new_id, $post ) { $post_taxonomies[] = 'post_format'; } - $taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist' ); + $taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist', [] ); if ( empty( $taxonomies_blacklist ) ) { $taxonomies_blacklist = []; } From f9a33febdb04e3bb748ebdd1d688da017e4756a5 Mon Sep 17 00:00:00 2001 From: Enrico Battocchi Date: Fri, 22 Mar 2024 13:34:51 +0100 Subject: [PATCH 4/4] Prevent fatal if the option is a string --- admin-functions.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/admin-functions.php b/admin-functions.php index 04fc2c3cd..a51d65dd7 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -155,6 +155,9 @@ function duplicate_post_plugin_upgrade() { if ( empty( $taxonomies_blacklist ) ) { $taxonomies_blacklist = []; } + elseif ( ! is_array( $taxonomies_blacklist ) ) { + $taxonomies_blacklist = [ $taxonomies_blacklist ]; + } if ( in_array( 'post_format', $taxonomies_blacklist, true ) ) { update_option( 'duplicate_post_copyformat', 0 ); $taxonomies_blacklist = array_diff( $taxonomies_blacklist, [ 'post_format' ] ); @@ -297,6 +300,9 @@ function duplicate_post_copy_post_taxonomies( $new_id, $post ) { if ( empty( $taxonomies_blacklist ) ) { $taxonomies_blacklist = []; } + elseif ( ! is_array( $taxonomies_blacklist ) ) { + $taxonomies_blacklist = [ $taxonomies_blacklist ]; + } if ( intval( get_option( 'duplicate_post_copyformat' ) ) === 0 ) { $taxonomies_blacklist[] = 'post_format'; }