Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-embed.php

    r42009 r42343  
    1010    public $handlers = array();
    1111    public $post_ID;
    12     public $usecache = true;
     12    public $usecache      = true;
    1313    public $linkifunknown = true;
    14     public $last_attr = array();
    15     public $last_url = '';
     14    public $last_attr     = array();
     15    public $last_url      = '';
    1616
    1717    /**
     
    8282        $post = get_post();
    8383
    84         if ( ! $post || empty( $_GET['message'] ) )
     84        if ( ! $post || empty( $_GET['message'] ) ) {
    8585            return;
     86        }
    8687
    8788?>
     
    107108     */
    108109    public function register_handler( $id, $regex, $callback, $priority = 10 ) {
    109         $this->handlers[$priority][$id] = array(
     110        $this->handlers[ $priority ][ $id ] = array(
    110111            'regex'    => $regex,
    111112            'callback' => $callback,
     
    157158
    158159        $rawattr = $attr;
    159         $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) );
     160        $attr    = wp_parse_args( $attr, wp_embed_defaults( $url ) );
    160161
    161162        $this->last_attr = $attr;
     
    170171            foreach ( $handlers as $id => $handler ) {
    171172                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
    172                     if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     173                    if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) {
    173174                        /**
    174175                         * Filters the returned embed handler.
     
    183184                         */
    184185                        return apply_filters( 'embed_handler_html', $return, $url, $attr );
     186                    }
    185187                }
    186188            }
     
    217219
    218220        if ( $post_ID ) {
    219             $cache = get_post_meta( $post_ID, $cachekey, true );
     221            $cache      = get_post_meta( $post_ID, $cachekey, true );
    220222            $cache_time = get_post_meta( $post_ID, $cachekey_time, true );
    221223
     
    286288
    287289            $insert_post_args = array(
    288                 'post_name' => $key_suffix,
     290                'post_name'   => $key_suffix,
    289291                'post_status' => 'publish',
    290                 'post_type' => 'oembed_cache',
     292                'post_type'   => 'oembed_cache',
    291293            );
    292294
    293295            if ( $html ) {
    294296                if ( $cached_post_id ) {
    295                     wp_update_post( wp_slash( array(
    296                         'ID' => $cached_post_id,
    297                         'post_content' => $html,
    298                     ) ) );
     297                    wp_update_post(
     298                        wp_slash(
     299                            array(
     300                                'ID'           => $cached_post_id,
     301                                'post_content' => $html,
     302                            )
     303                        )
     304                    );
    299305                } else {
    300                     wp_insert_post( wp_slash( array_merge(
    301                         $insert_post_args,
    302                         array(
    303                             'post_content' => $html,
     306                    wp_insert_post(
     307                        wp_slash(
     308                            array_merge(
     309                                $insert_post_args,
     310                                array(
     311                                    'post_content' => $html,
     312                                )
     313                            )
    304314                        )
    305                     ) ) );
     315                    );
    306316                }
    307317            } elseif ( ! $cache ) {
    308                 wp_insert_post( wp_slash( array_merge(
    309                     $insert_post_args,
    310                     array(
    311                         'post_content' => '{{unknown}}',
     318                wp_insert_post(
     319                    wp_slash(
     320                        array_merge(
     321                            $insert_post_args,
     322                            array(
     323                                'post_content' => '{{unknown}}',
     324                            )
     325                        )
    312326                    )
    313                 ) ) );
     327                );
    314328            }
    315329
     
    336350    public function delete_oembed_caches( $post_ID ) {
    337351        $post_metas = get_post_custom_keys( $post_ID );
    338         if ( empty($post_metas) )
     352        if ( empty( $post_metas ) ) {
    339353            return;
     354        }
    340355
    341356        foreach ( $post_metas as $post_meta_key ) {
    342             if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) )
     357            if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) {
    343358                delete_post_meta( $post_ID, $post_meta_key );
     359            }
    344360        }
    345361    }
     
    361377         * @param array $post_types Array of post types to cache oEmbed results for. Defaults to post types with `show_ui` set to true.
    362378         */
    363         if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ){
     379        if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ) {
    364380            return;
    365381        }
     
    367383        // Trigger a caching
    368384        if ( ! empty( $post->post_content ) ) {
    369             $this->post_ID = $post->ID;
     385            $this->post_ID  = $post->ID;
    370386            $this->usecache = false;
    371387
     
    407423     */
    408424    public function autoembed_callback( $match ) {
    409         $oldval = $this->linkifunknown;
     425        $oldval              = $this->linkifunknown;
    410426        $this->linkifunknown = false;
    411         $return = $this->shortcode( array(), $match[2] );
     427        $return              = $this->shortcode( array(), $match[2] );
    412428        $this->linkifunknown = $oldval;
    413429
     
    426442        }
    427443
    428         $output = ( $this->linkifunknown ) ? '<a href="' . esc_url($url) . '">' . esc_html($url) . '</a>' : $url;
     444        $output = ( $this->linkifunknown ) ? '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>' : $url;
    429445
    430446        /**
     
    455471        }
    456472
    457         $oembed_post_query = new WP_Query( array(
    458             'post_type'              => 'oembed_cache',
    459             'post_status'            => 'publish',
    460             'name'                   => $cache_key,
    461             'posts_per_page'         => 1,
    462             'no_found_rows'          => true,
    463             'cache_results'          => true,
    464             'update_post_meta_cache' => false,
    465             'update_post_term_cache' => false,
    466             'lazy_load_term_meta'    => false,
    467         ) );
     473        $oembed_post_query = new WP_Query(
     474            array(
     475                'post_type'              => 'oembed_cache',
     476                'post_status'            => 'publish',
     477                'name'                   => $cache_key,
     478                'posts_per_page'         => 1,
     479                'no_found_rows'          => true,
     480                'cache_results'          => true,
     481                'update_post_meta_cache' => false,
     482                'update_post_term_cache' => false,
     483                'lazy_load_term_meta'    => false,
     484            )
     485        );
    468486
    469487        if ( ! empty( $oembed_post_query->posts ) ) {
Note: See TracChangeset for help on using the changeset viewer.