- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php
r10833 r10140 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" , 'welcome'] ) ) {88 if ( in_array( $post->post_name, [ 'handbook', $post->post_type, "{$post->post_type}-handbook" ] ) ) { 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 }123 119 } 124 120 $manifest = json_decode( wp_remote_retrieve_body( $response ), true ); … … 132 128 133 129 // 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.135 130 $keys = array_keys( $manifest ); 136 131 if ( is_int( array_shift( $keys ) ) ) { … … 167 162 foreach ( $manifest as $key => $doc ) { 168 163 // Already exists, update. 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; 164 $existing = $this->existing[ $key ] ?? $this->existing['slug_only'][ $key ] ?? false; 174 165 if ( ! $existing && 'index' === $key ) { 175 166 $key = $this->get_post_type(); … … 189 180 } 190 181 if ( class_exists( 'WP_CLI' ) ) { 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 } 182 WP_CLI::success( "Successfully created {$created} and updated {$updated} handbook pages." ); 196 183 } 197 184 } … … 250 237 $post_data['post_title'] = sanitize_text_field( wp_slash( $doc['title'] ) ); 251 238 } 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 260 239 $post_id = wp_insert_post( $post_data ); 261 240 if ( ! $post_id ) { … … 432 411 'headers' => array(), 433 412 ); 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; 413 $last_etag = get_post_meta( $post_id, $this->etag_meta_key, true ); 441 414 if ( ! empty( $last_etag ) ) { 442 415 $args['headers']['If-None-Match'] = $last_etag; … … 486 459 $html = apply_filters( 'wporg_markdown_after_transform', $html, $this->get_post_type() ); 487 460 488 add_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10, 2 );489 490 461 $post_data = array( 491 462 'ID' => $post_id, … … 494 465 ); 495 466 496 remove_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10 );497 498 467 $fields_from_manifest = $this->update_post_from_manifest( $post_id, $title, false ); 499 468 if ( $fields_from_manifest ) { … … 507 476 508 477 return true; 509 }510 511 /**512 * Ensures that the 'a' tag and certain of its attributes are allowed in513 * 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 attributes520 * or the context to judge allowed tags by.521 * @param string $context Context name.522 * @return array[]|string523 */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;539 478 } 540 479
Note: See TracChangeset
for help on using the changeset viewer.