WordPress.org

Making WordPress.org

Changeset 4475


Ignore:
Timestamp:
12/04/2016 07:11:17 PM (18 months ago)
Author:
obenland
Message:

Plugin Directory: Improve formatting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r3716 r4475  
    416416            $original = preg_quote( $original, '/' );
    417417            $content  = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", '${1}___TRANSLATION___${3}', $content ); // Don't use $translation, it may contain backreference-like characters.
    418             $content  = str_replace( '___TRANSLATION___', $translation, $content );     }
     418            $content  = str_replace( '___TRANSLATION___', $translation, $content );
     419        }
    419420
    420421        return $content;
     
    424425     * Returns a list of translation locales for a given plugin slug and branch.
    425426     *
    426      * @param string $slug    Plugin slug.
    427      * @param string $branch  Branch - 'stable-readme' for example.
    428      * @param string $min_percent    Only return locales where percent_translated is >= this value.
     427     * @param string $slug        Plugin slug.
     428     * @param string $branch      Branch - 'stable-readme' for example.
     429     * @param int    $min_percent Optional. Only return locales where percent_translated is >= this value.
    429430     * @return array
    430431     */
     
    434435        $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $slug . '/' . $branch, array( 'https' ) );
    435436
    436         $http = new \WP_Http();
     437        $out    = array();
     438        $http   = new \WP_Http();
    437439        $result = $http->request( $api_url );
    438440
    439         $out = array();
    440         if ( !is_wp_error( $result ) ) {
    441             $json = $result['body'];
    442             if ( $data = json_decode( $json ) ) {
    443                 if ( isset( $data->translation_sets ) ) {
    444                     foreach ( $data->translation_sets as $translation ) {
    445                         if ( $translation->percent_translated >= $min_percent )
    446                             $out[] = $translation->wp_locale;
     441        if ( ! is_wp_error( $result ) ) {
     442            $data = json_decode( $result['body'] );
     443
     444            if ( $data && isset( $data->translation_sets ) ) {
     445                foreach ( $data->translation_sets as $translation ) {
     446                    if ( $translation->percent_translated >= $min_percent ) {
     447                        $out[] = $translation->wp_locale;
    447448                    }
    448449                }
     
    452453        return $out;
    453454    }
    454 
    455455}
Note: See TracChangeset for help on using the changeset viewer.