0

i'm editing a wordpress plugin and im trying to call a function within the thank you page, and in that function it has wp_update_post function to change the status in the database, the function works fine and i can see that the status was changed in the database yet the php page where the fucntion is called doesn't load and gives 500 internal server error.
the code is

public function update_status( $status = 'donate-processing' ) {

    if ( !$this->id )
        return;

    if ( strpos( $status, 'donate-' ) !== 0 ) {
        $status = 'donate-' . $status;
    }

    wp_update_post( array( 'ID' => $this->id, 'post_status' => $status ) );
    $old_status = get_post_status( $this->id );
    $old_status = substr( $old_status, strlen( 'donate-' ) );
    $status = substr( $status, strlen( 'donate-' ) );
    $this->send_email( $status );
}
5
  • 1
    For 500 errors access to your web server or Wordpress error log is extremely helpful in seeing the error line and error message.
    – mozboz
    Jul 5, 2020 at 18:34
  • the same code is used in different location and there is no problem with that, and there is nothing on the error_log for this
    – omarhabeh
    Jul 5, 2020 at 18:53
  • 1
    Yes Wordpress/apache error log can be difficult because the errors might be going somewhere you can't see them. You need to try and figure that out, or ask your hosting company to help as a 500 should definitely create an error that goes into an error log somewhere, and it will tell you exactly what's happening.
    – mozboz
    Jul 5, 2020 at 18:56
  • Where are you running the update_status function? If you're running it in the update post hook there will be an infinite loop. Jul 6, 2020 at 3:09
  • no im not running it in the update post hook, im calling it from different page that has no hooks or so
    – omarhabeh
    Jul 7, 2020 at 22:13

1 Answer 1

0

Try using save_post hook instead.

Check this example: https://gist.github.com/fgilio/38dfbf9d03654b21302a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.