• Resolved Ov3rfly

    (@ov3rfly)


    Fresh install of Duplicate Post 4.5 in WordPress 6.1.1 causes this PHP Fatal Error:

    PHP Fatal error:  Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, bool given in .../duplicate-post/admin-functions.php:149

    Function duplicate_post_plugin_upgrade() uses get_option() in line 145 which returns false which is not checked before in_array() call.

    145:	$taxonomies_blacklist = get_option( 'duplicate_post_taxonomies_blacklist' );
    146:	if ( $taxonomies_blacklist === '' ) {
    147:		$taxonomies_blacklist = [];
    148:	}
    149:	if ( in_array( 'post_format', $taxonomies_blacklist, true ) ) {

    Possible fix: Use second parameter in get_option() to supply '' or array() as default return value.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Enrico Battocchi

    (@lopo)

    Hi @ov3rfly,

    we’re sorry to hear you’re experiencing this problem.
    Unfortunately we’re not able to reproduce it on a fresh install, but we wouldn’t expect such problem since before the get_option() call there is an add_option() that should set that option to [] so a false return value is not expected unless the option is set to false or the add_option() has failed for some reason.

    Your report highlights anyway that some defensive coding is definitely advisable there. We’ll try to include it in a future version.

    Thanks for your suggestion!

    Thread Starter Ov3rfly

    (@ov3rfly)

    Here is the full debug entry with stack trace, maybe it helps:

    [09-Feb-2023 18:51:22 UTC] PHP Fatal error:  Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, bool given in [..]/wp-content/plugins/duplicate-post/admin-functions.php:149
    Stack trace:
    #0 [..]/wp-content/plugins/duplicate-post/admin-functions.php(149): in_array()
    #1 [..]/wp-content/plugins/duplicate-post/admin-functions.php(40): duplicate_post_plugin_upgrade()
    #2 [..]/wp-includes/class-wp-hook.php(308): duplicate_post_admin_init()
    #3 [..]/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
    #4 [..]/wp-includes/plugin.php(517): WP_Hook->do_action()
    #5 [..]/wp-admin/admin.php(175): do_action()
    #6 [..]/wp-admin/edit.php(10): require_once('...')
    #7 {main}
      thrown in [..]/wp-content/plugins/duplicate-post/admin-functions.php on line 149

    Initial install seems to set the option to [] which ends up as a:0:{} in database.

    If after initial install WordPress > Settings > Duplicate Post is opened and saved without changes, the option is not set to [] but ends up completely empty in database.

    The add_option() won’t set the option to [] if there is an existing value.

    We can not quickly reproduce the above error at the moment, due to not enough time for that, but we can say that

    a) the fatal error has been observed in WP backend and error log and

    b) this option variable type seem to be used in an inconsistent way.

    Maybe you can track it down further, we set this to “not resolved” for the time being.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP Fatal error: Uncaught TypeError: in_array() … admin-functions.php:149’ is closed to new replies.