Making WordPress.org

Changeset 2983


Ignore:
Timestamp:
04/19/2016 08:09:35 PM (9 years ago)
Author:
obenland
Message:

Plugin Directory: Add meta data on plugin submission.

Adds readme meta data to the plugin post after uploading a new plugin.

See #1570, #1571.

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-custom-fields.php

    r2655 r2983  
    99class Custom_Fields {
    1010    static function display() {
    11         $post = get_post();
     11        $post   = get_post();
    1212        $fields = array(
    1313            'version' => 'Latest Plugin Version',
     
    2222            'header_description' => 'Plugin Description',
    2323        );
     24
    2425        echo '<dl>';
    2526        foreach ( $fields as $field => $text ) {
    26             if ( ! ($value = get_post_meta( $post->ID, $field, true ) ) ) {
     27            if ( ! $value = get_post_meta( $post->ID, $field, true ) ) {
    2728                continue;
    2829            }
    2930            printf( '<dt>%s</dt><dd>%s</dd>', esc_html( $text ), make_clickable( esc_html( $value ) ) );
    3031        }
    31         // Description is stored in the post_excerpt rather than meta
    32         printf( '<dt>%s</dt><dd>%s</dd>', esc_html( $fields['header_description'] ), get_the_excerpt() );
    3332        echo '</dl>';
    3433    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r2976 r2983  
    467467     *     @type int    $author      The ID of the plugin author.
    468468     *     @type string $description The short description of the plugin.
     469     *     @type string $content     The long description of the plugin.
     470     *     @type array  $tags        The tags associated with the plugin.
     471     *     @type array  $tags        The meta information of the plugin.
    469472     * }
    470473     * @return \WP_Post|\WP_Error
    471474     */
    472475    static public function create_plugin_post( array $plugin_info ) {
    473         $title  = !empty( $plugin_info['title'] )       ? $plugin_info['title']       : '';
    474         $slug   = !empty( $plugin_info['slug'] )        ? $plugin_info['slug']        : sanitize_title( $title );
    475         $status = !empty( $plugin_info['status'] )      ? $plugin_info['status']      : 'pending';
    476         $author = !empty( $plugin_info['author'] )      ? $plugin_info['author']      : 0;
    477         $desc   = !empty( $plugin_info['description'] ) ? $plugin_info['description'] : '';
     476        $title   = ! empty( $plugin_info['title'] )       ? $plugin_info['title']       : '';
     477        $slug    = ! empty( $plugin_info['slug'] )        ? $plugin_info['slug']        : sanitize_title( $title );
     478        $status  = ! empty( $plugin_info['status'] )      ? $plugin_info['status']      : 'pending';
     479        $author  = ! empty( $plugin_info['author'] )      ? $plugin_info['author']      : 0;
     480        $desc    = ! empty( $plugin_info['description'] ) ? $plugin_info['description'] : '';
     481        $content = ! empty( $plugin_info['content'] )     ? $plugin_info['content']     : '';
     482        $tags    = ! empty( $plugin_info['tags'] )        ? $plugin_info['tags']        : array();
     483        $meta    = ! empty( $plugin_info['meta'] )        ? $plugin_info['meta']        : array();
    478484
    479485        $id = wp_insert_post( array(
     
    483489            'post_title'   => $title ?: $slug,
    484490            'post_author'  => $author,
    485             'post_content' => '',
     491            'post_content' => $content,
    486492            'post_excerpt' => $desc,
     493            'tags_input'   => $tags,
     494            'meta_input'   => $meta,
    487495        ), true );
    488496
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r2640 r2983  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
     3use WordPressdotorg\Plugin_Directory\Readme_Parser;
    34use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    45use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
     
    122123
    123124        if ( preg_match( '|[^\d\.]|', $this->plugin['Version'] ) ) {
    124             /* translators: %s: style.css */
     125            /* translators: %s: Version header */
    125126            return sprintf( __( 'Version strings can only contain numeric and period characters (like 1.2). Please fix your %s line in your main plugin file and upload the plugin again.', 'wporg-plugins' ),
    126127                '<code>Version:</code>'
     
    129130
    130131        // Prevent duplicate URLs.
    131         $plugin_uri = $this->plugin['PluginURI'];
    132         $author_uri = $this->plugin['AuthorURI'];
    133         if ( ! empty( $plugin_uri ) && ! empty( $author_uri ) && $plugin_uri == $author_uri ) {
     132        if ( ! empty( $this->plugin['PluginURI'] ) && ! empty( $this->plugin['AuthorURI'] ) && $this->plugin['PluginURI'] == $this->plugin['AuthorURI'] ) {
    134133            return __( 'Duplicate plugin and author URLs. A plugin URL is a page/site that provides details about this specific plugin. An author URL is a page/site that provides information about the author of the plugin. You aren&rsquo;t required to provide both, so pick the one that best applies to your URL.', 'wporg-plugins' );
    135134        }
     135
     136        $readme = $this->find_readme_file();
     137        if ( empty( $readme ) ) {
     138            /* translators: 1: readme.txt, 2: readme.md */
     139            return sprintf( __( 'The zip file must include a file named %1$s or %2$s.', 'wporg-plugins' ),
     140                '<code>readme.txt</code>',
     141                '<code>readme.md</code>'
     142            );
     143        }
     144        $readme = new Readme_Parser( $readme );
    136145
    137146        // Pass it through Plugin Check and see how great this plugin really is.
     
    149158        // Let's save everything and get things wrapped up.
    150159
     160        $content = '';
     161        foreach ( $readme->sections as $section => $section_content ) {
     162            $content .= "\n\n<!--section={$section}-->\n{$section_content}";
     163        }
     164
    151165        // Add a Plugin Directory entry for this plugin.
    152166        $plugin_post = Plugin_Directory::create_plugin_post( array(
    153167            'title'       => $this->plugin['Name'],
    154168            'slug'        => $this->plugin_slug,
    155             'status'      => 'pending',
     169            'status'      => 'draft',
    156170            'author'      => get_current_user_id(),
    157             'description' => $this->plugin['Description']
     171            'content'     => $content,
     172            'description' => $this->plugin['Description'],
     173            'tags'        => $readme->tags,
     174            'meta'        => array(
     175                'stable_tag'          => $readme->stable_tag,
     176                'tested'              => $readme->tested,
     177                'requires'            => $readme->requires,
     178                'donate_link'         => $readme->donate_link,
     179                'version'             => $this->plugin['Version'],
     180                'header_plugin_uri'   => $this->plugin['PluginURI'],
     181                'header_author'       => $this->plugin['Author'],
     182                'header_author_uri'   => $this->plugin['AuthorURI'],
     183                'header_textdomain'   => $this->plugin['TextDomain'],
     184                'header_description'  => $this->plugin['Description'],
     185                'support_resolutions' => 0,
     186            ),
    158187        ) );
    159188        if ( is_wp_error( $plugin_post ) ) {
     
    195224            'new',
    196225            'updated',
     226            'about',
     227            'admin',
     228            'wp-admin',
    197229        );
    198230
    199231        return in_array( $this->plugin_slug, $reserved_slugs );
     232    }
     233
     234    /**
     235     * Find the plugin readme file.
     236     *
     237     * Looks for either a readme.txt or readme.md file, prioritizing readme.txt.
     238     *
     239     * @return string The plugin readme.txt or readme.md filename.
     240     */
     241    protected function find_readme_file() {
     242        $files = Filesystem::list_files( "{$this->plugin_dir}/{$this->plugin_slug}", false /* non-recursive */, '!^readme\.(txt|md)$!i' );
     243
     244        // Prioritize readme.txt
     245        foreach ( $files as $file ) {
     246            if ( '.txt' === strtolower( substr( $file, -4 ) ) ) {
     247                return $file;
     248            }
     249        }
     250
     251        return reset( $files );
    200252    }
    201253
Note: See TracChangeset for help on using the changeset viewer.