0

I´m doing a plugin which must do an import from an api. Inside this import, I have to removed phisicaly pictures before saving new ones. For some reasons this line code wp_delete_attachment( $attachment_id, true ); make this 503 error :

Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

this code is wrapped in a hook to overwrite WPML :

public function delete_attachment_translations( $attachment_id ) {
    remove_action( 'delete_attachment', 'delete_attachment_translations' );

    $langs = apply_filters( 'wpml_active_languages', [] );

    if ( ! empty( $langs ) ) {
        global $wp_filter;

        $hooks = $wp_filter['wp_delete_file']->callbacks[10];
        unset( $wp_filter['wp_delete_file']->callbacks[10] );


        wp_delete_attachment( $attachment_id, true );
 

        $wp_filter['wp_delete_file']->callbacks[10] = $hooks;
    }

    add_action( 'delete_attachment', 'delete_attachment_translations' );
}

Someone has got an idea why and how to fix this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.