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

    r10140 r10833  
    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" ] ) ) {
     88            if ( in_array( $post->post_name, [ 'handbook', $post->post_type, "{$post->post_type}-handbook", 'welcome' ] ) ) {
    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            }   
    119123        }
    120124        $manifest = json_decode( wp_remote_retrieve_body( $response ), true );
     
    128132
    129133        // 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.
    130135        $keys = array_keys( $manifest );
    131136        if ( is_int( array_shift( $keys ) ) ) {
     
    162167        foreach ( $manifest as $key => $doc ) {
    163168            // 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;
    165174            if ( ! $existing && 'index' === $key ) {
    166175                $key = $this->get_post_type();
     
    180189        }
    181190        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            }
    183196        }
    184197    }
     
    237250            $post_data['post_title'] = sanitize_text_field( wp_slash( $doc['title'] ) );
    238251        }
     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
    239260        $post_id = wp_insert_post( $post_data );
    240261        if ( ! $post_id ) {
     
    411432            'headers' => array(),
    412433        );
    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;
    414441        if ( ! empty( $last_etag ) ) {
    415442            $args['headers']['If-None-Match'] = $last_etag;
     
    459486        $html = apply_filters( 'wporg_markdown_after_transform', $html, $this->get_post_type() );
    460487
     488        add_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10, 2 );
     489
    461490        $post_data = array(
    462491            'ID'           => $post_id,
     
    465494        );
    466495
     496        remove_filter( 'wp_kses_allowed_html', [ $this, 'wp_kses_allow_links' ], 10 );
     497
    467498        $fields_from_manifest = $this->update_post_from_manifest( $post_id, $title, false );
    468499        if ( $fields_from_manifest ) {
     
    476507
    477508        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;
    478539    }
    479540
Note: See TracChangeset for help on using the changeset viewer.