Making WordPress.org

Ticket #3421: 3421-2.diff

File 3421-2.diff, 2.8 KB (added by schlessera, 6 years ago)

Fixed a small typo

  • wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/cli.php

    diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/cli.php wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/cli.php
    index 6dbab51f..c70fc026 100644
    class DevHub_CLI { 
    4242                        'excerpt',
    4343                        'revisions',
    4444                        'title',
     45
     46                        // Needed for manual inspection/modification of the post's parent.
     47                        'page-attributes',
    4548                );
    4649                register_post_type( 'command', array(
    4750                        'has_archive' => 'cli/commands',
    class DevHub_CLI { 
    7376        }
    7477
    7578        public static function action_pre_get_posts( $query ) {
    76                 if ( $query->is_main_query() && $query->is_post_type_archive( 'command' ) ) {
     79                if ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive( 'command' ) ) {
    7780                        $query->set( 'post_parent', 0 );
    7881                        $query->set( 'orderby', 'title' );
    7982                        $query->set( 'order', 'ASC' );
    class DevHub_CLI { 
    100103                ) );
    101104                $existing = array();
    102105                foreach( $q->posts as $post ) {
    103                         $cmd_path = rtrim( str_replace( home_url( 'cli/commands/' ), '', get_permalink( $post->ID ) ), '/' );
     106                        $cmd_path = self::get_cmd_path( $post->ID );
    104107                        $existing[ $cmd_path ] = array(
    105108                                'post_id'   => $post->ID,
    106109                                'cmd_path'  => $cmd_path,
    class DevHub_CLI { 
    144147                }
    145148                $post = self::create_post_from_manifest_doc( $doc, $post_parent );
    146149                if ( $post ) {
    147                         $cmd_path = rtrim( str_replace( home_url( 'cli/commands/' ), '', get_permalink( $post->ID ) ), '/' );
     150                        $cmd_path = self::get_cmd_path( $post->ID );
    148151                        if ( ! empty( $doc['repo_url'] ) ) {
    149152                                update_post_meta( $post->ID, 'repo_url', esc_url_raw( $doc['repo_url'] ) );
    150153                        }
    class DevHub_CLI { 
    475478                return $matches;
    476479        }
    477480
     481        /**
     482         * Gets a normalized version of the command path from the post permalink.
     483         *
     484         * This normalization is needed because CPTs share the slug namespace with
     485         * other CPTs, causing unexpected conflicts that result in changed URLs like
     486         * "command-2".
     487         *
     488         * @see https://github.com/wp-cli/handbook/issues/202
     489         *
     490         * @param int $post_id Post ID to get the normalized path for.
     491         *
     492         * @return string Normalized command path.
     493         */
     494        private static function get_cmd_path( $post_id ) {
     495                $cmd_path = rtrim( str_replace( home_url( 'cli/commands/' ), '', get_permalink( $post_id ) ), '/' );
     496                $parts = explode( '/', $cmd_path );
     497                $cleaned_parts = array();
     498                foreach ( $parts as $part ) {
     499                        $matches = null;
     500                        $result = preg_match( '/^(?<cmd>.*)(?<suffix>-[0-9]+)$/', $part, $matches );
     501                        if ( 1 === $result ) {
     502                                $part = $matches['cmd'];
     503                        }
     504                        $cleaned_parts[] = $part;
     505                }
     506                return implode( '/', $cleaned_parts );
     507        }
     508
    478509}
    479510
    480511DevHub_CLI::init();