Changes in sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php [8848:10833]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php
r8848 r10833 86 86 // Account for potential handbook landing page, which results in an empty $key. 87 87 if ( ! $key ) { 88 if ( in_array( $post->post_name, [ 'handbook', $post->post_type, "{$post->post_type}-handbook" ] ) ) {88 if ( in_array( $post->post_name, [ 'handbook', $post->post_type, "{$post->post_type}-handbook", 'welcome' ] ) ) { 89 89 $key = $post->post_name; 90 90 } … … 117 117 } 118 118 return new WP_Error( 'invalid-http-code', 'Markdown source returned non-200 http code.' ); 119 } else { 120 if ( class_exists( 'WP_CLI' ) ) { 121 WP_CLI::log( "Importing manifest from " . $this->get_manifest_url() ); 122 } 119 123 } 120 124 $manifest = json_decode( wp_remote_retrieve_body( $response ), true ); … … 128 132 129 133 // A numeric key suggests the manifest did not explicitly specify keys for each item, so define one. 134 // Note: not explicitly specifying a key means the slugs defined must be unique. 130 135 $keys = array_keys( $manifest ); 131 136 if ( is_int( array_shift( $keys ) ) ) { … … 162 167 foreach ( $manifest as $key => $doc ) { 163 168 // Already exists, update. 164 $existing = $this->existing[ $key ] ?? $this->existing['slug_only'][ $key ] ?? false; 169 $existing = $this->existing[ $key ] 170 ?? $this->existing['slug_only'][ $key ] 171 ?? $this->existing[ $doc['slug'] ] 172 ?? $this->existing['slug_only'][ $doc['slug'] ] 173 ?? false; 165 174 if ( ! $existing && 'index' === $key ) { 166 175 $key = $this->get_post_type(); … … 180 189 } 181 190 if ( class_exists( 'WP_CLI' ) ) { 182 WP_CLI::success( "Successfully created {$created} and updated {$updated} handbook pages." ); 191 if ( 0 === $created && 0 === $updated ) { 192 WP_CLI::success( "No updates detected for any handbook page." ); 193 } else { 194 WP_CLI::success( "Successfully created {$created} and updated {$updated} handbook pages." ); 195 } 183 196 } 184 197 } … … 237 250 $post_data['post_title'] = sanitize_text_field( wp_slash( $doc['title'] ) ); 238 251 } 252 253 /** 254 * Filters the post data used to create a post from the manifest. 255 * 256 * @param array $post_data Post data. 257 */ 258 $post_data = apply_filters( 'wporg_markdown_post_data_pre_insert', $post_data ); 259 239 260 $post_id = wp_insert_post( $post_data ); 240 261 if ( ! $post_id ) { … … 411 432 'headers' => array(), 412 433 ); 413 $last_etag = get_post_meta( $post_id, $this->etag_meta_key, true ); 434 /** 435 * Filters if HTTP ETags should be included in request for remote Markdown 436 * source update. 437 * 438 * @param bool $check_etags Should HTTP ETags be checcked? Default true. 439 */ 440 $last_etag = apply_filters( 'wporg_markdown_check_etags', true ) ? get_post_meta( $post_id, $this->etag_meta_key, true ) : false; 414 441 if ( ! empty( $last_etag ) ) { 415 442 $args['headers']['If-None-Match'] = $last_etag; … … 459 486 $html = apply_filters( 'wporg_markdown_after_transform', $html, $this->get_post_type() ); 460 487 488 add_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10, 2 ); 489 461 490 $post_data = array( 462 491 'ID' => $post_id, … … 465 494 ); 466 495 496 remove_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10 ); 497 467 498 $fields_from_manifest = $this->update_post_from_manifest( $post_id, $title, false ); 468 499 if ( $fields_from_manifest ) { … … 476 507 477 508 return true; 509 } 510 511 /** 512 * Ensures that the 'a' tag and certain of its attributes are allowed in 513 * posts if not already. 514 * 515 * Supported 'a' attributes are those defined for `$allowedposttags` by default. 516 * 517 * This is necessary since the 'a' tag is being removed somewhere along the way. 518 * 519 * @param array[]|string $allowed_tags Allowed HTML tags and their attributes 520 * or the context to judge allowed tags by. 521 * @param string $context Context name. 522 * @return array[]|string 523 */ 524 public function wp_kses_allow_links( $allowed_tags, $context ) { 525 if ( 'post' === $context && is_array( $allowed_tags ) && empty( $allowed_tags[ 'a' ] ) ) { 526 $allowed_tags['a'] = [ 527 'href' => true, 528 'rel' => true, 529 'rev' => true, 530 'name' => true, 531 'target' => true, 532 'download' => [ 533 'valueless' => 'y', 534 ], 535 ]; 536 } 537 538 return $allowed_tags; 478 539 } 479 540
Note: See TracChangeset
for help on using the changeset viewer.