Making WordPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.