Making WordPress.org


Ignore:
Timestamp:
04/10/2018 02:42:42 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Use geopattern icon assets in the plugins/update-check API response.

This change populates the update_source table which the update-check API uses, another change is needed to the update check itself to pull them through.
Additionally a bin script to trigger an update for a single row (or all) is included.

See #3265.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php

    r6287 r7072  
    33
    44use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     5use WordPressdotorg\Plugin_Directory\Template;
    56
    67/**
     
    6263        }
    6364
    64         $data           = array(
     65        $data = array(
    6566            'plugin_id'       => $post->ID,
    6667            'plugin_slug'     => $post->post_name,
     
    7576            'requires_php'    => get_post_meta( $post->ID, 'requires_php', true ),
    7677            'upgrade_notice'  => '',
     78            'assets'          => serialize( self::get_plugin_assets( $post ) ),
    7779            'last_updated'    => $post->post_modified,
    7880        );
     
    112114    }
    113115
     116    static function get_plugin_assets( $post ) {
     117        $icons = $banners = $banners_rtl = array();
     118
     119        $raw_icons   = Template::get_plugin_icon( $post, 'raw' );
     120        $raw_banners = Template::get_plugin_banner( $post, 'raw_with_rtl' );
     121
     122        // Banners
     123        if ( !empty( $raw_banners['banner_2x'] ) ) {
     124            $banners['2x'] = $raw_banners['banner_2x'];
     125        }
     126        if ( !empty( $raw_banners['banner'] ) ) {
     127            $banners['1x'] = $raw_banners['banner'];
     128        }
     129        if ( $banners ) {
     130            $banners['default']  = $banners['2x'] ?? $banners['1x'];
     131        }
     132
     133        // RTL Banners (get_plugin_banner 'raw_with_rtl' returns these)
     134        if ( !empty( $raw_banners['banner_2x_rtl'] ) ) {
     135            $banners_rtl['2x'] = $raw_banners['banner_2x_rtl'];
     136        }
     137        if ( !empty( $raw_banners['banner_rtl'] ) ) {
     138            $banners_rtl['1x'] = $raw_banners['banner_rtl'];
     139        }
     140        if ( $banners_rtl ) {
     141            $banners_rtl['default']  = $banners_rtl['2x'] ?? $banners_rtl['1x'];
     142        }
     143
     144        // Icons.
     145        if ( !empty( $raw_icons['icon_2x'] ) ) {
     146            $icons['2x'] = $raw_icons['icon_2x'];
     147        }
     148        if ( !empty( $raw_icons['icon'] ) ) {
     149            $icons['1x'] = $raw_icons['icon'];
     150        }
     151        if ( !empty( $raw_icons['svg'] ) ) {
     152            $icons['svg'] = $raw_icons['svg'];
     153
     154            // We don't need to set the 1x field when it's the SVG.
     155            if ( isset( $icons['1x'] ) && $icons['1x'] == $icons['svg'] ) {
     156                unset( $icons['1x'] );
     157            }
     158        }
     159        if ( $icons ) {
     160            $icons['default'] = $icons['svg'] ?? ( $icons['2x'] ?? $icons['1x'] );
     161        }
     162
     163        return (object) compact( 'icons', 'banners', 'banners_rtl' );
     164    }
     165
    114166}
    115167
     
    128180  `requires_php` varchar(128) NOT NULL DEFAULT '',
    129181  `upgrade_notice` text,
     182  `assets` text NOT NULL DEFAULT '',
    130183  `last_updated` datetime NOT NULL,
    131184  PRIMARY KEY (`plugin_id`),
Note: See TracChangeset for help on using the changeset viewer.