Making WordPress.org


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php

    r10833 r10140  
    8686        // Account for potential handbook landing page, which results in an empty $key.
    8787        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" ] ) ) {
    8989                $key = $post->post_name;
    9090            }
     
    117117            }
    118118            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             }   
    123119        }
    124120        $manifest = json_decode( wp_remote_retrieve_body( $response ), true );
     
    132128
    133129        // 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.
    135130        $keys = array_keys( $manifest );
    136131        if ( is_int( array_shift( $keys ) ) ) {
     
    167162        foreach ( $manifest as $key => $doc ) {
    168163            // 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;
    174165            if ( ! $existing && 'index' === $key ) {
    175166                $key = $this->get_post_type();
     
    189180        }
    190181        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." );
    196183        }
    197184    }
     
    250237            $post_data['post_title'] = sanitize_text_field( wp_slash( $doc['title'] ) );
    251238        }
    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 
    260239        $post_id = wp_insert_post( $post_data );
    261240        if ( ! $post_id ) {
     
    432411            'headers' => array(),
    433412        );
    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 );
    441414        if ( ! empty( $last_etag ) ) {
    442415            $args['headers']['If-None-Match'] = $last_etag;
     
    486459        $html = apply_filters( 'wporg_markdown_after_transform', $html, $this->get_post_type() );
    487460
    488         add_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10, 2 );
    489 
    490461        $post_data = array(
    491462            'ID'           => $post_id,
     
    494465        );
    495466
    496         remove_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10 );
    497 
    498467        $fields_from_manifest = $this->update_post_from_manifest( $post_id, $title, false );
    499468        if ( $fields_from_manifest ) {
     
    507476
    508477        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;
    539478    }
    540479
Note: See TracChangeset for help on using the changeset viewer.