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

Fix WP 5.6 array_intersect_key error #263

Merged
merged 4 commits into from
Jul 13, 2021
Merged

Conversation

phpbits
Copy link
Contributor

@phpbits phpbits commented Dec 22, 2020

This PR fixes the error below when using WordPress 5.6. This errors are only visible when on Gutenberg editor.

Screen Shot 2020-12-23 at 4 12 47 AM

@phpbits phpbits mentioned this pull request Dec 22, 2020
5 tasks
@jeffpaul jeffpaul added this to the 1.7.0 milestone Dec 23, 2020
@jeffpaul jeffpaul requested a review from dkotter January 8, 2021 17:03
@dkotter
Copy link
Collaborator

dkotter commented Jan 8, 2021

@phpbits Code looks good but I think this will cause some other errors we will need to solve. Currently, we take that route argument and use that later on, to determine which type of processing we are doing. That check expects a string but we are now going to be passing an array, which I think will cause things to break.

See here for one place this is done: https://github.com/10up/classifai/blob/develop/includes/Classifai/Providers/Azure/ComputerVision.php#L928

@jeffpaul
Copy link
Member

jeffpaul commented Jun 3, 2021

This same error was reported today via email:

I tried running ClassifAI 1.6.0 again today to try and see what I missed,
but unfortunately am getting this error when loading /wp-admin/post-new.php:

Fatal error: Uncaught TypeError: array_intersect_key(): Argument #1 ($array) must be of type array, string given in wp-includes/rest-api/class-wp-rest-server.php:1402 Stack trace: #0 wp-includes/rest-api/class-wp-rest-server.php(1402): array_intersect_key('alt-tags', Array) #1 wp-includes/rest-api/class-wp-rest-server.php(1324): WP_REST_Server->get_data_for_route('/classifai/v1/a...', Array, 'view') #2 wp-includes/rest-api/class-wp-rest-server.php(1243): WP_REST_Server->get_data_for_routes(Array, 'view') #3 wp-includes/rest-api/class-wp-rest-server.php(1160): WP_REST_Server->get_index(Object(WP_REST_Request)) #4 wp-includes/rest-api/class-wp-rest-server.php(1007): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/', Array, NULL) #5 wp-includes/rest-api.php(479): WP_REST_Server->dispatch(Object(WP_REST_Request)) #6 wp-includes/rest-api.php(2520): rest_do_request(Object(WP_REST_Request)) #7 [internal function]: rest_preload_api_request(Array, '/') #8 wp-admin/edit-form-blocks.php(82): array_reduce(Array, 'rest_preload_ap...', Array) #9 wp-admin/post-new.php(72): require('/Users/p/Sites/...') #10 {main} thrown in wp-includes/rest-api/class-wp-rest-server.php on line 1402

@dkotter @dinhtungdu if @phpbits approach is not the optimal path, then is there another approach you'd recommend to help resolve this error?

@dkotter
Copy link
Collaborator

dkotter commented Jun 3, 2021

if @phpbits approach is not the optimal path, then is there another approach you'd recommend to help resolve this error?

I think the fix we have here is correct but there's more needed to ensure this doesn't break other things within Classifai. Anywhere in the plugin we use that route argument, needs to be updated to account for this change from a string to an array.

@jeffpaul
Copy link
Member

jeffpaul commented Jun 3, 2021

@phpbits are you able to make those additional updates as @dkotter noted above?

@jeffpaul jeffpaul mentioned this pull request Jul 7, 2021
21 tasks
@jeffpaul
Copy link
Member

jeffpaul commented Jul 8, 2021

After chatting with @phpbits I'm going to tag in @dinhtungdu to help work on the additional updates from @dkotter.

@dinhtungdu dinhtungdu dismissed a stale review via 864f63b July 13, 2021 07:57
@dinhtungdu dinhtungdu self-assigned this Jul 13, 2021
@dinhtungdu
Copy link
Contributor

@dkotter I updated the PR to address the data type change.

@dinhtungdu dinhtungdu removed their request for review July 13, 2021 07:59
@jeffpaul jeffpaul merged commit b732b92 into 10up:develop Jul 13, 2021
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

Successfully merging this pull request may close these issues.

4 participants