Polyfilling wp_remote_delete

Alasdair North - 

WordPress core includes the functions wp_remote_get and wp_remote_post, but there aren't any functions for other HTTP methods.

At viaLibri we're building a WordPress plugin that communicates with our API and we need to be able to send DELETE requests. I had a dig into the source code for wp_remote_post and wrote this polyfill.

This solution avoids using private functions and undocumented parameters - unlike some of the other code I've seen out there. I've also wrapped it in function_exists in case the WordPress core team decide to add wp_remote_delete in the future.

if ( ! function_exists( 'wp_remote_delete' ) ) {
  function wp_remote_delete($url, $args) {
    $defaults = array('method' => 'DELETE');
    $r = wp_parse_args( $args, $defaults );
    return wp_remote_request($url, $r);
  }
}

Feel free to use it on your own projects.

← other fixes or blog
I'm the CTO of viaLibri, a director and web developer at Runway, and an active member of St. Barnabas Church.

Latest Posts

comments powered byDisqus