Support » Plugin: WP Security Audit Log » Error “implode(): Invalid arguments” when using register_rest_route

  • Resolved patternmb

    (@patternmb)


    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!

    • This topic was modified 7 months, 1 week ago by  patternmb. Reason: Made other details, slightly more clear
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor robertabela

    (@robert681)

    Thanks @patternmb for reporting this and the recommendation. We will add a fix for this in the next update of the plugin (3.3).

    We just released a minor update today but should be releasing 3.3 before the festive season.

    Stay tuned and do not hesitate to reach out in case you need further assistance.

    Awesome, I look forward to 3.3. I’ll retest my code when it comes out and if there are no issues we can mark this as resolved.

    Thanks!

    Plugin Author WPWhiteSecurity

    (@wpwhitesecurity)

    Hello @patternmb,

    We have just released update 3.3 and can confirm that we have included the fix. You can read more about the latest WP Security Audit Log plugin update in these release notes.

    @wpwhitesecurity @robert681

    Thank you for the update. I’ve just tried 3.3 and everything is looking good.

    Plugin Contributor robertabela

    (@robert681)

    You’re welcome and thank you for the positive review.

    Have a great day and do not hesitate to reach out to us should you have any queries.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Error “implode(): Invalid arguments” when using register_rest_route’ is closed to new replies.