Making WordPress.org


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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();
Note: See TracChangeset for help on using the changeset viewer.