Making WordPress.org

Changeset 4622


Ignore:
Timestamp:
01/10/2017 10:13:25 PM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Add default meta fallback values where needed to avoid PHP warnings.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-internal-stats.php

    r3354 r4622  
    109109     */
    110110    protected function sanitize_usage_numbers( $usage, $plugin ) {
    111         $latest_version = get_post_meta( $plugin->ID, 'version', true );
     111        $latest_version = get_post_meta( $plugin->ID, 'version', true ) ?: '0.0';
    112112        $latest_branch = implode( '.', array_slice( explode('.', $latest_version ), 0, 2 ) );
    113113
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php

    r4560 r4622  
    6060        $result['name'] = $post->post_title;
    6161        $result['slug'] = $post->post_name;
    62         $result['version'] = get_post_meta( $post_id, 'version', true );
     62        $result['version'] = get_post_meta( $post_id, 'version', true ) ?: '0.0';
    6363
    6464        $author = get_user_by( 'id', $post->post_author );
     
    9292        }
    9393
    94         $result['requires'] = get_post_meta( $post_id, 'requires', true );
    95         $result['tested'] = get_post_meta( $post_id, 'tested', true );
     94        $result['requires'] = get_post_meta( $post_id, 'requires', true ) ?: false;
     95        $result['tested'] = get_post_meta( $post_id, 'tested', true ) ?: false;
    9696        $result['compatibility'] = array();
    97         $result['rating'] = get_post_meta( $post_id, 'rating', true ) * 20; // Stored as 0.0 ~ 5.0, API outputs as 0..100
     97        $result['rating'] = ( get_post_meta( $post_id, 'rating', true ) ?: 0 ) * 20; // Stored as 0.0 ~ 5.0, API outputs as 0..100
    9898        $result['ratings'] = array_map( 'intval', (array) get_post_meta( $post_id, 'ratings', true ) );
    9999        $result['num_ratings'] = array_sum( $result['ratings'] );
    100         $result['support_threads'] = get_post_meta( $post_id, 'support_threads', true ) ?: 0;
    101         $result['support_threads_resolved'] = get_post_meta( $post_id, 'support_threads_resolved', true ) ?: 0;
    102         $result['active_installs'] = (int)get_post_meta( $post_id, 'active_installs', true );
     100        $result['support_threads'] = intval( get_post_meta( $post_id, 'support_threads', true ) );
     101        $result['support_threads_resolved'] = intval( get_post_meta( $post_id, 'support_threads_resolved', true ) );
     102        $result['active_installs'] = intval( get_post_meta( $post_id, 'active_installs', true ) );
    103103        $result['downloaded'] = intval( get_post_meta( $post_id, 'downloads', true ) );
    104104        $result['last_updated'] = gmdate( 'Y-m-d g:ia \G\M\T', strtotime( $post->post_modified_gmt ) );
     
    124124
    125125        $result['screenshots'] = array();
    126         $descriptions = get_post_meta( $post->ID, 'screenshots', true );
     126        $descriptions = get_post_meta( $post->ID, 'screenshots', true ) ?: array();
    127127        $screen_shots = get_post_meta( $post->ID, 'assets_screenshots', true ) ?: array();
    128128
     
    151151        }
    152152
    153         $result['stable_tag'] = get_post_meta( $post_id, 'stable_tag', true );
     153        $result['stable_tag'] = get_post_meta( $post_id, 'stable_tag', true ) ?: 'trunk';
    154154
    155155        $result['versions'] = array();
     
    163163        }
    164164
    165         $result['donate_link'] = get_post_meta( $post_id, 'donate_link', true );
     165        $result['donate_link'] = get_post_meta( $post_id, 'donate_link', true ) ?: false;
    166166
    167167        $result['banners'] = array();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r4475 r4622  
    347347        $slug   = $post->post_name;
    348348
    349         $post->stable_tag = get_post_meta( $post->ID, 'stable_tag', true );
     349        $post->stable_tag = get_post_meta( $post->ID, 'stable_tag', true ) ?: 'trunk';
    350350
    351351        if ( empty( $slug ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r4514 r4622  
    2020    public static function active_installs( $full = true, $post = null ) {
    2121        $post  = get_post( $post );
    22         $count = get_post_meta( $post->ID, 'active_installs', true );
     22        $count = get_post_meta( $post->ID, 'active_installs', true ) ?: 0;
    2323
    2424        if ( $count <= 10 ) {
     
    131131        }
    132132
    133         $raw_sections = get_post_meta( $plugin->ID, 'sections', true );
     133        $raw_sections = get_post_meta( $plugin->ID, 'sections', true ) ?: array();
    134134        $raw_sections = array_unique( array_merge( $raw_sections, $default_sections ) );
    135135
     
    216216    public static function get_plugin_icon( $post = null, $output = 'raw' ) {
    217217        $plugin    = get_post( $post );
    218         $raw_icons = get_post_meta( $plugin->ID, 'assets_icons', true );
     218        $raw_icons = get_post_meta( $plugin->ID, 'assets_icons', true ) ?: array();
    219219
    220220        $icon = $icon_2x = $svg = $generated = false;
     
    295295
    296296        $banner      = $banner_2x = false;
    297         $raw_banners = get_post_meta( $plugin->ID, 'assets_banners', true );
     297        $raw_banners = get_post_meta( $plugin->ID, 'assets_banners', true ) ?: array();
    298298
    299299        // Split in rtl and non-rtl banners.
     
    449449
    450450        if ( 'latest' == $version || 'latest-stable' == $version ) {
    451             $version = get_post_meta( $post->ID, 'stable_tag', true );
     451            $version = get_post_meta( $post->ID, 'stable_tag', true ) ?: 'trunk';
    452452        }
    453453
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r4620 r4622  
    187187        update_post_meta( $plugin->ID, 'assets_banners_color', wp_slash( $banner_average_color ) );
    188188
    189         $current_stable_tag = get_post_meta( $plugin->ID, 'stable_tag', true );
     189        $current_stable_tag = get_post_meta( $plugin->ID, 'stable_tag', true ) ?: 'trunk';
    190190
    191191        $this->rebuild_invalidate_zips( $plugin_slug, $stable_tag, $current_stable_tag, $svn_changed_tags );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php

    r4505 r4622  
    1818
    1919        // All indexed from 1.
    20         $descriptions = get_post_meta( $plugin->ID, 'screenshots', true );
    21         $screen_shots = get_post_meta( $plugin->ID, 'assets_screenshots', true );
     20        $descriptions = get_post_meta( $plugin->ID, 'screenshots', true ) ?: array();
     21        $screen_shots = get_post_meta( $plugin->ID, 'assets_screenshots', true ) ?: array();;
    2222
    2323        if ( empty( $screen_shots ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-ratings.php

    r3935 r4622  
    3030
    3131        $post        = get_post();
    32         $rating      = get_post_meta( $post->ID, 'rating', true );
     32        $rating      = get_post_meta( $post->ID, 'rating', true ) ?: 0;
    3333        $ratings     = get_post_meta( $post->ID, 'ratings', true ) ?: array();
    3434        $num_ratings = array_sum( $ratings );
Note: See TracChangeset for help on using the changeset viewer.