Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during import --- Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /wp-content/plugins/custom-post-type-ui/inc/utility.php:941 #840

Closed
lquidfire opened this issue Feb 17, 2022 · 3 comments

Comments

@lquidfire
Copy link

lquidfire commented Feb 17, 2022

Hi there!

Thanks very much for this plugin!

I installed the CPT UI on my staging site, configured it all to my liking (1 taxonomy). All was well.

Then I installed the plugin on my prod site, and tried to import the taxonomy from the staging site (see attachment for the export)
leatimes-export.txt
. However, it threw a fatal error at me. Please see below.

An error of type E_ERROR was caused in line 941 of the file [redacted]/wp-content/plugins/custom-post-type-ui/inc/utility.php.

Error message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in [redacted]/wp-content/plugins/custom-post-type-ui/inc/utility.php:941

Stack trace: #0 [redacted]/wp-content/plugins/custom-post-type-ui/inc/utility.php(941): in_array()
#1 [redacted]/wp-includes/class-wp-hook.php(303): cptui_published_post_format_fix()
#2 [redacted]/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters()
#3 [redacted]/wp-includes/plugin.php(470): WP_Hook->do_action()
#4 [redacted]/wp-content/plugins/custom-post-type-ui/custom-post-type-ui.php(325): do_action()
#5 [redacted]/wp-includes/class-wp-hook.php(303): cptui_create_custom_post_types()
#6 [redacted]/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters()
#7 [redacted]/wp-includes/plugin.php(470): WP_Hook->do_action()
#8 [redacted]/wp-settings.php(578): do_action()
#9 [redacted]/wp-config.php(82): require_once('/home/6154aa92c...')
#10 [redacted]/wp-load.php(50): require_once('/home/6154aa92c...')
#11 [redacted]/wp-login.php(12): require('/home/6154aa92c...')
#12 {main} thrown

Also: I cannot activate the plugin now without it throwing an error. Where can I find the data that I need to delete so I can use the plugin again?

@tw2113
Copy link
Member

tw2113 commented Feb 17, 2022

Is it an error that's debilitating your ability to use the admin/site in general? or is it all usable still, except this gets thrown at the moment?

The error is coming from a spot that is regarding saved post types, apparently somehow the "supports" section doesn't have at least an empty array going on for one of the types. In this case, it's just null.

By any chance did you uncheck all of the items in the "supports" section and just leave them blank?

Really quick fix, that I'm more than willing to add to the plugin permanently is going to be changing line 941 from this file

https://github.com/WebDevStudios/custom-post-type-ui/blob/master/inc/utility.php#L941

from:

if ( in_array( 'post-formats', $type['supports'], true ) ) {

to

if ( is_array( $type['supports'] ) && in_array( 'post-formats', $type['supports'], true ) ) {

Hopefully that change would get you back up to full speed, for whatever errors you're encountering.

@lquidfire
Copy link
Author

This error is debilitating, since it throws a Fatal error and all of WordPress is unreachable. WP Recovery Mode allows me to get in and disable the plugin, after which the site can be reached again.

Your reply helped me to find my mistake: I tried to import a taxonomy on the "Import Post Types" page.

Thank you for the line of code: With that I was able to repair the broken site.

Perhaps there should be a way to warn a user when they are trying to import a post on the taxonomy import page, or the other way around. For, the taxonomy was now imported as a Post (since your fix), and that should also not have happened.

I hope this helps!

@tw2113
Copy link
Member

tw2113 commented Feb 18, 2022

Hmm. Noted on the debilitating part.

Good catch on the imported into the wrong spot part. I still want to guard against foreach errors so I will get that handled in a future release.

Finding a way to warn against importing in the wrong spot, feels like it'd be a tall challenge to figure out how to determine. Closest I can think of off the top of my head is checking for post type or taxonomy specific properties in the JSON being imported, and return early if things don't match up. However, I'm not sure how elegant that could be done either.

At least at the moment, I'm definitely going to better guard against PHP errors, and try to recall the note about which spot was imported into, in support requests where importing is mentioned.

Closing this task in terms of open issues, and will handle the PHP fixes in #841

Thanks for the feedback @lquidfire

@tw2113 tw2113 closed this as completed Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants