Making WordPress.org

Changeset 13605


Ignore:
Timestamp:
04/29/2024 03:19:13 AM (5 months ago)
Author:
dd32
Message:

Translate: Retrieve WordPress.org API via wp_safe_remote_get() rather than direct file_get_contents().

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-language-pack.php

    r13161 r13605  
    275275     */
    276276    private function get_plugin_stable_tag( $plugin_slug ) {
    277         $plugin = @file_get_contents( "https://api.wordpress.org/plugins/info/1.0/{$plugin_slug}.json?fields=stable_tag" );
     277        $plugin = wp_remote_retrieve_body(
     278            wp_safe_remote_get(
     279                "https://api.wordpress.org/plugins/info/1.0/{$plugin_slug}.json?fields=stable_tag"
     280            )
     281        );
    278282        if ( ! $plugin ) {
    279283            return false;
     
    292296     */
    293297    private function get_latest_theme_version( $theme_slug ) {
    294         $theme = @file_get_contents( "https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]={$theme_slug}" );
     298        $theme = wp_remote_retrieve_body(
     299            wp_safe_remote_get(
     300                "https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]={$theme_slug}"
     301            )
     302        );
    295303        if ( ! $theme ) {
    296304            return false;
     
    309317     */
    310318    private function get_latest_plugin_version( $plugin_slug ) {
    311         $plugin = @file_get_contents( "https://api.wordpress.org/plugins/info/1.0/{$plugin_slug}.json" );
     319        $plugin = wp_remote_retrieve_body(
     320            wp_safe_remote_get(
     321                "https://api.wordpress.org/plugins/info/1.0/{$plugin_slug}.json"
     322            )
     323        );
    312324        if ( ! $plugin ) {
    313325            return false;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-set-plugin-project.php

    r7096 r13605  
    287287     */
    288288    private function get_plugin_details( $slug ) {
    289         $http_context = $this->get_http_context();
    290         $json = @file_get_contents( "https://api.wordpress.org/plugins/info/1.0/{$slug}.json?fields=stable_tag,short_description", false, $http_context );
     289        $json = wp_remote_retrieve_body(
     290            wp_safe_remote_get(
     291                "https://api.wordpress.org/plugins/info/1.0/{$slug}.json?fields=stable_tag,short_description",
     292                array(
     293                    'user-agent' => 'WordPress.org Translate',
     294                )
     295            )
     296        );
    291297
    292298        $details = $json && '{' == $json[0] ? json_decode( $json ) : null;
     
    299305    }
    300306
    301     /**
    302      * Creates a stream context with a default HTTP user-agent.
    303      *
    304      * @return resource Stream context with a default HTTP user-agent.
    305      */
    306     private function get_http_context() {
    307         return stream_context_create( array(
    308             'http' => array(
    309                 'user_agent' => 'WordPress.org Translate',
    310             ),
    311         ) );
    312     }
    313307}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-wp-directory.php

    r6690 r13605  
    200200     */
    201201    public function get_language_packs( $type, $slug ) {
    202         $http_context = stream_context_create( array(
    203             'http' => array(
    204                 'user_agent' => 'WordPress.org Translate',
    205             ),
    206         ) );
    207202        if ( 'plugin' === $type ) {
    208203            $type = 'plugins';
     
    210205            $type = 'themes';
    211206        }
    212         $json = file_get_contents( "https://api.wordpress.org/translations/$type/1.0/?slug={$slug}", null, $http_context );
     207
     208        $json = wp_remote_retrieve_body(
     209            wp_safe_remote_get(
     210                "https://api.wordpress.org/translations/$type/1.0/?slug={$slug}",
     211                array(
     212                    'user-agent' => 'WordPress.org Translate',
     213                )
     214            )
     215        );
    213216        $language_packs = $json && '{' == $json[0] ? json_decode( $json ) : null;
    214217
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-wp-plugins.php

    r6851 r13605  
    150150        $project->icon = $this->get_plugin_icon( $project, 64 );
    151151
    152         $http_context = stream_context_create( array(
    153             'http' => array(
    154                 'user_agent' => 'WordPress.org Translate',
    155             ),
    156         ) );
    157         $json = file_get_contents( "https://api.wordpress.org/translations/plugins/1.0/?slug={$project_slug}", null, $http_context );
     152        $json = wp_remote_retrieve_body(
     153            wp_safe_remote_get(
     154                "https://api.wordpress.org/translations/plugins/1.0/?slug={$project_slug}",
     155                array(
     156                    'user-agent' => 'WordPress.org Translate',
     157                )
     158            )
     159        );
    158160        $language_packs = $json && '{' == $json[0] ? json_decode( $json ) : null;
    159161
Note: See TracChangeset for help on using the changeset viewer.