Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 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/embed.php

    r41634 r42343  
    6262 */
    6363function wp_embed_defaults( $url = '' ) {
    64     if ( ! empty( $GLOBALS['content_width'] ) )
     64    if ( ! empty( $GLOBALS['content_width'] ) ) {
    6565        $width = (int) $GLOBALS['content_width'];
    66 
    67     if ( empty( $width ) )
     66    }
     67
     68    if ( empty( $width ) ) {
    6869        $width = 500;
     70    }
    6971
    7072    $height = min( ceil( $width * 1.5 ), 1000 );
     
    132134function wp_oembed_add_provider( $format, $provider, $regex = false ) {
    133135    if ( did_action( 'plugins_loaded' ) ) {
    134         $oembed = _wp_oembed_get_object();
    135         $oembed->providers[$format] = array( $provider, $regex );
     136        $oembed                       = _wp_oembed_get_object();
     137        $oembed->providers[ $format ] = array( $provider, $regex );
    136138    } else {
    137139        WP_oEmbed::_add_provider_early( $format, $provider, $regex );
     
    227229function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
    228230    global $wp_embed;
    229     $embed = $wp_embed->autoembed( sprintf( "https://youtube.com/watch?v=%s", urlencode( $matches[2] ) ) );
     231    $embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) );
    230232
    231233    /**
     
    396398
    397399    if ( '' !== $permalink ) {
    398         $url = add_query_arg( array(
    399             'url'    => urlencode( $permalink ),
    400             'format' => ( 'json' !== $format ) ? $format : false,
    401         ), $url );
     400        $url = add_query_arg(
     401            array(
     402                'url'    => urlencode( $permalink ),
     403                'format' => ( 'json' !== $format ) ? $format : false,
     404            ), $url
     405        );
    402406    }
    403407
     
    450454         * and edit wp-embed.js directly.
    451455         */
    452         $output .=<<<JS
     456        $output .= <<<JS
    453457        include "js/wp-embed.min.js"
    454458JS;
     
    518522     * }
    519523     */
    520     $min_max_width = apply_filters( 'oembed_min_max_width', array(
    521         'min' => 200,
    522         'max' => 600
    523     ) );
     524    $min_max_width = apply_filters(
     525        'oembed_min_max_width', array(
     526            'min' => 200,
     527            'max' => 600,
     528        )
     529    );
    524530
    525531    $width  = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
     
    583589        if ( wp_attachment_is_image( $post ) ) {
    584590            $thumbnail_id = $post->ID;
    585         } else if ( wp_attachment_is( 'video', $post ) ) {
     591        } elseif ( wp_attachment_is( 'video', $post ) ) {
    586592            $thumbnail_id = get_post_thumbnail_id( $post );
    587593            $data['type'] = 'video';
     
    591597    if ( $thumbnail_id ) {
    592598        list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
    593         $data['thumbnail_url']    = $thumbnail_url;
    594         $data['thumbnail_width']  = $thumbnail_width;
    595         $data['thumbnail_height'] = $thumbnail_height;
     599        $data['thumbnail_url']                                      = $thumbnail_url;
     600        $data['thumbnail_width']                                    = $thumbnail_width;
     601        $data['thumbnail_height']                                   = $thumbnail_height;
    596602    }
    597603
     
    730736    $allowed_html = array(
    731737        'a'          => array(
    732             'href'         => true,
     738            'href' => true,
    733739        ),
    734740        'blockquote' => array(),
     
    760766
    761767        $url = esc_url( "{$results[2]}#?secret=$secret" );
    762         $q = $results[1];
     768        $q   = $results[1];
    763769
    764770        $html = str_replace( $results[0], ' src=' . $q . $url . $q . ' data-secret=' . $q . $secret . $q, $html );
     
    767773
    768774    $allowed_html['blockquote']['data-secret'] = true;
    769     $allowed_html['iframe']['data-secret'] = true;
     775    $allowed_html['iframe']['data-secret']     = true;
    770776
    771777    $html = wp_kses( $html, $allowed_html );
     
    798804    }
    799805
    800     $link = sprintf( '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>',
     806    $link = sprintf(
     807        '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>',
    801808        esc_url( get_permalink() ),
    802809        /* translators: %s: Name of current post */
     
    874881    <style type="text/css">
    875882    <?php
    876         if ( SCRIPT_DEBUG ) {
    877             readfile( ABSPATH . WPINC . "/css/wp-embed-template.css" );
    878         } else {
    879             /*
    880             * If you're looking at a src version of this file, you'll see an "include"
    881             * statement below. This is used by the `grunt build` process to directly
    882             * include a minified version of wp-oembed-embed.css, instead of using the
    883             * readfile() method from above.
    884             *
    885             * If you're looking at a build version of this file, you'll see a string of
    886             * minified CSS. If you need to debug it, please turn on SCRIPT_DEBUG
    887             * and edit wp-embed-template.css directly.
    888             */
    889             ?>
    890             include "css/wp-embed-template.min.css"
    891             <?php
    892         }
     883    if ( SCRIPT_DEBUG ) {
     884        readfile( ABSPATH . WPINC . '/css/wp-embed-template.css' );
     885    } else {
     886        /*
     887        * If you're looking at a src version of this file, you'll see an "include"
     888        * statement below. This is used by the `grunt build` process to directly
     889        * include a minified version of wp-oembed-embed.css, instead of using the
     890        * readfile() method from above.
     891        *
     892        * If you're looking at a build version of this file, you'll see a string of
     893        * minified CSS. If you need to debug it, please turn on SCRIPT_DEBUG
     894        * and edit wp-embed-template.css directly.
     895        */
     896        ?>
     897        include "css/wp-embed-template.min.css"
     898        <?php
     899    }
    893900    ?>
    894901    </style>
     
    905912    <script type="text/javascript">
    906913    <?php
    907         if ( SCRIPT_DEBUG ) {
    908             readfile( ABSPATH . WPINC . "/js/wp-embed-template.js" );
    909         } else {
    910             /*
    911             * If you're looking at a src version of this file, you'll see an "include"
    912             * statement below. This is used by the `grunt build` process to directly
    913             * include a minified version of wp-embed-template.js, instead of using the
    914             * readfile() method from above.
    915             *
    916             * If you're looking at a build version of this file, you'll see a string of
    917             * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
    918             * and edit wp-embed-template.js directly.
    919             */
    920             ?>
    921             include "js/wp-embed-template.min.js"
    922             <?php
    923         }
     914    if ( SCRIPT_DEBUG ) {
     915        readfile( ABSPATH . WPINC . '/js/wp-embed-template.js' );
     916    } else {
     917        /*
     918        * If you're looking at a src version of this file, you'll see an "include"
     919        * statement below. This is used by the `grunt build` process to directly
     920        * include a minified version of wp-embed-template.js, instead of using the
     921        * readfile() method from above.
     922        *
     923        * If you're looking at a build version of this file, you'll see a string of
     924        * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
     925        * and edit wp-embed-template.js directly.
     926        */
     927        ?>
     928        include "js/wp-embed-template.min.js"
     929        <?php
     930    }
    924931    ?>
    925932    </script>
     
    10751082
    10761083    if ( is_multisite() ) {
    1077         $url_parts = wp_parse_args( wp_parse_url( $url ), array(
    1078             'host'   => '',
     1084        $url_parts = wp_parse_args(
     1085            wp_parse_url( $url ), array(
     1086                'host' => '',
     1087                'path' => '/',
     1088            )
     1089        );
     1090
     1091        $qv = array(
     1092            'domain' => $url_parts['host'],
    10791093            'path'   => '/',
    1080         ) );
    1081 
    1082         $qv = array( 'domain' => $url_parts['host'], 'path' => '/' );
     1094        );
    10831095
    10841096        // In case of subdirectory configs, set the path.
Note: See TracChangeset for help on using the changeset viewer.