Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#33709 closed defect (bug) (fixed)

Deprecate wp_get_http()

Reported by: johnbillion's profile johnbillion Owned by: swissspidy's profile swissspidy
Milestone: 4.4 Priority: low
Severity: normal Version: 2.5
Component: HTTP API Keywords: has-patch
Focuses: Cc:

Description

The wp_get_http() function isn't used anywhere (apart from itself).

It's a weird function that accepts a URL and a file path, performs a GET request, saves the response to the file, and returns just the response headers with the response code bolted on. If you don't specify a file path then it just performs a HEAD request. It doesn't accept an arguments array like the rest of the HTTP API functions.

Downloading and saving an external file can be done with download_url() or with the filename argument in any HTTP API request.

This function was introduced back in the dark ages before we had a good HTTP API. Let's deprecate it by moving it to wp-includes/deprecated.php and adding a _deprecated_function() call.

Attachments (3)

33709.diff (6.3 KB) - added by swissspidy 9 years ago.
33709.2.diff (6.3 KB) - added by swissspidy 9 years ago.
Use wp_remote_get instead of wp_safe_remote_get in the tests
33709.3.diff (6.4 KB) - added by swissspidy 9 years ago.
Add @see param, write WP_Http correctly.

Download all attachments as: .zip

Change History (19)

#1 @johnbillion
9 years ago

The Tests_HTTP_Functions::test_get_request() unit test also needs to be removed or updated to use wp_remote_get().

#2 follow-up: @DrewAPicture
9 years ago

+1 for deprecation. Would wp_remote_get() be cited as the alternative?

#3 in reply to: ↑ 2 @johnbillion
9 years ago

Replying to DrewAPicture:

+1 for deprecation. Would wp_remote_get() be cited as the alternative?

I think download_url() would be closer. I think that's the original intent of the function, anyway.

#4 @dd32
9 years ago

+1! I would recommend WP_HTTP as the replacement, as download_url() is admin-specific, and WP_HTTP is far more useful (It also allows for returning headers + downloaded file).

@swissspidy
9 years ago

#5 @swissspidy
9 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 4.4

33709.diff does the following:

  • Move the function to wp-includes/deprecated.php, recommending WP_HTTP as the alternative
  • Updates the tests in Tests_HTTP_Functions accordingly to use wp_remote_get, all continue to pass.

@swissspidy
9 years ago

Use wp_remote_get instead of wp_safe_remote_get in the tests

#6 @DrewAPicture
9 years ago

  • Owner set to swissspidy
  • Status changed from new to assigned

Setting ownership to mark the good-first-bug as "claimed".

@swissspidy: There should be an @see tag following the @deprecated tag, see the deprecated functions syntax for guidance.

Also the class name is WP_Http ;)

@swissspidy
9 years ago

Add @see param, write WP_Http correctly.

#7 @swissspidy
9 years ago

  • Keywords commit added

#8 @wonderboymusic
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 33969:

Deprecate wp_get_http() - function isn't used anywhere (apart from itself).

Props swissspidy.
Fixes #33709.

#9 @chris@…
9 years ago

I don't know the official status of the WordPress Importer plugin but it actually uses that function in wordpress-importer/wordpress-importer.php

// fetch the remote url and write it to the placeholder file
$headers = wp_get_http( $url, $upload['file'] );

// request failed
if ( ! $headers ) {
    @unlink( $upload['file'] );
    return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') );
}

#10 follow-up: @DrewAPicture
9 years ago

  • Keywords good-first-bug commit removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Let's reopen this pending resolution of a fix for the importer plugin.

@samuelsidler: Who would be the development point of contact to have WordPress Importer updated to use the HTTP API instead?

#11 in reply to: ↑ 10 @samuelsidler
9 years ago

Replying to DrewAPicture:

@samuelsidler: Who would be the development point of contact to have WordPress Importer updated to use the HTTP API instead?

Looks like @nacin touched it (in a material way) last. AKA, patches welcome.

#12 @nacin
9 years ago

@DrewAPicture, @samuelsidler: @rmccue has been working on a rewrite. He now has commit access to it, and he's planning on a beta release soon. I would not at all be surprised if he included HTTP changes.

#13 @rmccue
9 years ago

Indeed, I've already removed it thanks to #33241 (which can now be closed in favour of this one, I think). Post coming soon on the importer updates.

#14 @SergeyBiryukov
9 years ago

#33241 was marked as a duplicate.

#15 @DrewAPicture
9 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Closing as fixed. See comment:13 for confirmation that wp_get_http() will be removed in the next iteration of the importer.

This ticket was mentioned in Slack in #core by danielbachhuber. View the logs.


9 years ago

Note: See TracTickets for help on using tickets.