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..67914f52 100644
|
|
|
class DevHub_CLI { |
| 42 | 42 | 'excerpt', |
| 43 | 43 | 'revisions', |
| 44 | 44 | 'title', |
| | 45 | |
| | 46 | // Needed for manual inspection/modification of the post's parent. |
| | 47 | 'page-attributes', |
| 45 | 48 | ); |
| 46 | 49 | register_post_type( 'command', array( |
| 47 | 50 | 'has_archive' => 'cli/commands', |
| … |
… |
class DevHub_CLI { |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | 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' ) ) { |
| 77 | 80 | $query->set( 'post_parent', 0 ); |
| 78 | 81 | $query->set( 'orderby', 'title' ); |
| 79 | 82 | $query->set( 'order', 'ASC' ); |
| … |
… |
class DevHub_CLI { |
| 100 | 103 | ) ); |
| 101 | 104 | $existing = array(); |
| 102 | 105 | 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 ); |
| 104 | 107 | $existing[ $cmd_path ] = array( |
| 105 | 108 | 'post_id' => $post->ID, |
| 106 | 109 | 'cmd_path' => $cmd_path, |
| … |
… |
class DevHub_CLI { |
| 144 | 147 | } |
| 145 | 148 | $post = self::create_post_from_manifest_doc( $doc, $post_parent ); |
| 146 | 149 | 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 ); |
| 148 | 151 | if ( ! empty( $doc['repo_url'] ) ) { |
| 149 | 152 | update_post_meta( $post->ID, 'repo_url', esc_url_raw( $doc['repo_url'] ) ); |
| 150 | 153 | } |
| … |
… |
class DevHub_CLI { |
| 475 | 478 | return $matches; |
| 476 | 479 | } |
| 477 | 480 | |
| | 481 | /** |
| | 482 | * Gets a normalized version of the command path from the post permalink. |
| | 483 | * |
| | 484 | * This normalization is need 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 | |
| 478 | 509 | } |
| 479 | 510 | |
| 480 | 511 | DevHub_CLI::init(); |