Error “implode(): Invalid arguments” when using register_rest_route
-
Hello,
I’ve encountered an issue that was causing me some problems; when using wp_add_object_terms with register_rest_route it gives this error:
Warning: implode(): Invalid arguments passed in C:\wamp64\www\wp-tester\wp-content\plugins\wp-security-audit-log\classes\Sensors\Content.php on line 898
PHP code example:
add_action( 'rest_api_init', function () { register_rest_route( 'my-rest-route/v1', '/example/', array( 'methods' => 'POST', 'callback' => 'rest_api_callback_action' )); }); function rest_api_callback_action($request) { $testAddCat = wp_add_object_terms(5, 'test-category', 'custom-categories'); echo 'Success'; die(); }While I am using a custom post type and assigning a category from a custom taxonomy when the rest API is called in the example above, the issue persists when assigning a default category to a default post.
It appears that in the Content.php file the function gutenberg_post_terms_changed calls $this->CheckCategoriesChange() but does not pass any value for the $old_cats parameter. As a temporary fix I’ve added a couple if statements:
protected function CheckCategoriesChange( $old_cats, $new_cats, $post ) { if( !is_array($old_cats) ) { $old_cats = array(); } if( !is_array($new_cats) ) { $new_cats = array(); } $old_cats = implode( ', ', $old_cats ); $new_cats = implode( ', ', $new_cats ); ...Other Details:
- WordPress version: 4.9.8
- WP Security Audit Log plugin version: 3.2.4
- No other WordPress plugins active, only the default Hello Dolly and Akismet Anti-Spam are installed but inactive.
- Fresh local install with wampserver 3.1.0
- PHP version 5.6.31
Cheers!
The topic ‘Error “implode(): Invalid arguments” when using register_rest_route’ is closed to new replies.