Making WordPress.org

Changeset 13035

Timestamp:
12/08/2023 05:02:12 AM (8 months ago)
Author:
tellyworth
Message:

Plugin Directory: support new blueprints api field

Supporting functions for including blueprints in the plugins info API.

File:
1 edited

Legend:

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

    r13033 r13035  
    735735                return true;
    736736            }
     737
     738
     739
     740
     741
     742
    737743        }
    738744        return false;
     
    748754        $post = get_post( $post );
    749755
    750         $blueprints = get_post_meta( $post->ID, 'assets_blueprints', true );
     756        $blueprints = );
    751757        // Note: for now, only use a file called `blueprint.json`.
    752758        if ( !isset( $blueprints['blueprint.json'] ) ) {
     
    754760        }
    755761        $blueprint = $blueprints['blueprint.json'];
    756         if ( !$blueprint || !isset( $blueprint['contents'] ) || !is_string( $blueprint['contents'] ) ) {
    757             return false;
    758         }
    759 
    760         $blueprint_url = sprintf( 'https://wordpress.org/plugins/wp-json/plugins/v1/plugin/%s/blueprint.json?rev=%d', $post->post_name, $blueprint['revision'] );
    761 
    762         return sprintf( 'https://playground.wordpress.net/?plugin=%s&blueprint-url=%s', esc_attr($post->post_name), esc_attr($blueprint_url ) );
     762
     763        return sprintf( 'https://playground.wordpress.net/?plugin=%s&blueprint-url=%s', esc_attr($post->post_name), esc_attr($blueprint['url'] ) );
     764    }
     765
     766    /**
     767     * Return a list of blueprints for the given plugin.
     768     *
     769     * @param int|\WP_Post|null $post    Optional. Post ID or post object. Defaults to global $post.
     770     * @return array An array of blueprints.
     771     */
     772    public static function get_blueprints( $post = null ) {
     773        $post = get_post( $post );
     774
     775        $out = array();
     776
     777        $blueprints = get_post_meta( $post->ID, 'assets_blueprints', true );
     778        if ( $blueprints ) {
     779            foreach ( $blueprints as $filename => $item ) {
     780                if ( isset( $item['contents'] ) ) {
     781                    $out[ $filename ] = array(
     782                        'filename' => $filename,
     783                        'url' => sprintf( 'https://wordpress.org/plugins/wp-json/plugins/v1/plugin/%s/blueprint.json?rev=%d', $post->post_name, $item['revision'] )
     784                    );
     785                }
     786            }
     787        }
     788
     789        return $out;
    763790    }
    764791
Note: See TracChangeset for help on using the changeset viewer.