WordPress.org

Making WordPress.org

Changeset 6191


Ignore:
Timestamp:
11/29/17 18:36:26 (2 weeks ago)
Author:
danielbachhuber
Message:

devhub/cli: Prepend installation instructions when applicable

See https://github.com/wp-cli/wp-cli/issues/4282

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/cli.php

    r5818 r6191  
    77    private static $supported_post_types = array( 'command' ); 
    88    private static $posts_per_page = 350; 
     9    private static $non_bundled_commands = array( 
     10        'https://github.com/wp-cli/admin-command', 
     11        'https://github.com/wp-cli/dist-archive-command', 
     12        'https://github.com/wp-cli/doctor-command', 
     13        'https://github.com/wp-cli/find-command', 
     14        'https://github.com/wp-cli/profile-command', 
     15        'https://github.com/wp-cli/scaffold-package-command', 
     16    ); 
    917 
    1018    public static function init() { 
     
    274282        } 
    275283 
    276         $content = self::append_subcommands( get_queried_object()->post_content ); 
     284        $content = get_queried_object()->post_content; 
     285        $content = self::prepend_installation( $content ); 
     286        $content = self::append_subcommands( $content ); 
    277287        $items = self::get_tags( 'h([1-4])', $content ); 
    278288        if ( count( $items ) > 1 ) { 
     
    303313        $content = str_replace( ''', '\'', $content ); 
    304314 
     315        $content = self::prepend_installation( $content ); 
    305316        $content = self::append_subcommands( $content ); 
    306317 
     
    363374        add_filter( 'the_content', array( __CLASS__, 'filter_the_content' ) ); 
    364375 
     376        return $content; 
     377    } 
     378 
     379    protected static function prepend_installation( $content ) { 
     380        $repo_url = get_post_meta( get_the_ID(), 'repo_url', true ); 
     381 
     382        // Only non-bundled commands 
     383        if ( ! in_array( $repo_url, self::$non_bundled_commands, true ) ) { 
     384            return; 
     385        } 
     386        $repo_slug = str_replace( 'https://github.com/', '', $repo_url ); 
     387        ob_start(); ?> 
     388        <h3>INSTALLING</h3> 
     389 
     390        <p>Use the <code><?php the_title(); ?></code> command by installing the command's package:</p> 
     391 
     392        <pre><code>wp package install <?php echo esc_html( $repo_slug ); ?></code></pre> 
     393 
     394        <p>Once the package is successfully installed, the <code><?php the_title(); ?></code> command will appear in the list of available commands.</p> 
     395        <?php 
     396        $installing_instructions = ob_get_clean(); 
     397        // Insert before OPTIONS but after description if OPTIONS exists 
     398        $options_match = '#<h3>OPTIONS<\/h3>#'; 
     399        if ( preg_match( $options_match, $content ) ) { 
     400            $content = preg_replace( $options_match, $installing_instructions . '$0', $content ); 
     401        } else { 
     402            // Otherwise, appending to description is fine. 
     403            $content .= $installing_instructions; 
     404        } 
    365405        return $content; 
    366406    } 
Note: See TracChangeset for help on using the changeset viewer.