Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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-content/themes/twentyfourteen/functions.php

    r41756 r42343  
    4545
    4646if ( ! function_exists( 'twentyfourteen_setup' ) ) :
    47 /**
    48  * Twenty Fourteen setup.
    49  *
    50  * Set up theme defaults and registers support for various WordPress features.
    51  *
    52  * Note that this function is hooked into the after_setup_theme hook, which
    53  * runs before the init hook. The init hook is too late for some features, such
    54  * as indicating support post thumbnails.
    55  *
    56  * @since Twenty Fourteen 1.0
    57  */
    58 function twentyfourteen_setup() {
    59 
    60         /*
    61          * Make Twenty Fourteen available for translation.
     47        /**
     48         * Twenty Fourteen setup.
    6249         *
    63          * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfourteen
    64          * If you're building a theme based on Twenty Fourteen, use a find and
    65          * replace to change 'twentyfourteen' to the name of your theme in all
    66          * template files.
     50         * Set up theme defaults and registers support for various WordPress features.
     51         *
     52         * Note that this function is hooked into the after_setup_theme hook, which
     53         * runs before the init hook. The init hook is too late for some features, such
     54         * as indicating support post thumbnails.
     55         *
     56         * @since Twenty Fourteen 1.0
    6757         */
    68         load_theme_textdomain( 'twentyfourteen' );
    69 
    70         // This theme styles the visual editor to resemble the theme style.
    71         add_editor_style( array( 'css/editor-style.css', twentyfourteen_font_url(), 'genericons/genericons.css' ) );
    72 
    73         // Add RSS feed links to <head> for posts and comments.
    74         add_theme_support( 'automatic-feed-links' );
    75 
    76         // Enable support for Post Thumbnails, and declare two sizes.
    77         add_theme_support( 'post-thumbnails' );
    78         set_post_thumbnail_size( 672, 372, true );
    79         add_image_size( 'twentyfourteen-full-width', 1038, 576, true );
    80 
    81         // This theme uses wp_nav_menu() in two locations.
    82         register_nav_menus( array(
    83                 'primary'   => __( 'Top primary menu', 'twentyfourteen' ),
    84                 'secondary' => __( 'Secondary menu in left sidebar', 'twentyfourteen' ),
    85         ) );
    86 
    87         /*
    88          * Switch default core markup for search form, comment form, and comments
    89          * to output valid HTML5.
    90          */
    91         add_theme_support( 'html5', array(
    92                 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
    93         ) );
    94 
    95         /*
    96          * Enable support for Post Formats.
    97          * See https://codex.wordpress.org/Post_Formats
    98          */
    99         add_theme_support( 'post-formats', array(
    100                 'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery',
    101         ) );
    102 
    103         // This theme allows users to set a custom background.
    104         add_theme_support( 'custom-background', apply_filters( 'twentyfourteen_custom_background_args', array(
    105                 'default-color' => 'f5f5f5',
    106         ) ) );
    107 
    108         // Add support for featured content.
    109         add_theme_support( 'featured-content', array(
    110                 'featured_content_filter' => 'twentyfourteen_get_featured_posts',
    111                 'max_posts' => 6,
    112         ) );
    113 
    114         // This theme uses its own gallery styles.
    115         add_filter( 'use_default_gallery_style', '__return_false' );
    116 
    117         // Indicate widget sidebars can use selective refresh in the Customizer.
    118         add_theme_support( 'customize-selective-refresh-widgets' );
    119 }
     58        function twentyfourteen_setup() {
     59
     60                /*
     61                 * Make Twenty Fourteen available for translation.
     62                 *
     63                 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfourteen
     64                 * If you're building a theme based on Twenty Fourteen, use a find and
     65                 * replace to change 'twentyfourteen' to the name of your theme in all
     66                 * template files.
     67                 */
     68                load_theme_textdomain( 'twentyfourteen' );
     69
     70                // This theme styles the visual editor to resemble the theme style.
     71                add_editor_style( array( 'css/editor-style.css', twentyfourteen_font_url(), 'genericons/genericons.css' ) );
     72
     73                // Add RSS feed links to <head> for posts and comments.
     74                add_theme_support( 'automatic-feed-links' );
     75
     76                // Enable support for Post Thumbnails, and declare two sizes.
     77                add_theme_support( 'post-thumbnails' );
     78                set_post_thumbnail_size( 672, 372, true );
     79                add_image_size( 'twentyfourteen-full-width', 1038, 576, true );
     80
     81                // This theme uses wp_nav_menu() in two locations.
     82                register_nav_menus(
     83                        array(
     84                                'primary'   => __( 'Top primary menu', 'twentyfourteen' ),
     85                                'secondary' => __( 'Secondary menu in left sidebar', 'twentyfourteen' ),
     86                        )
     87                );
     88
     89                /*
     90                 * Switch default core markup for search form, comment form, and comments
     91                 * to output valid HTML5.
     92                 */
     93                add_theme_support(
     94                        'html5', array(
     95                                'search-form',
     96                                'comment-form',
     97                                'comment-list',
     98                                'gallery',
     99                                'caption',
     100                        )
     101                );
     102
     103                /*
     104                 * Enable support for Post Formats.
     105                 * See https://codex.wordpress.org/Post_Formats
     106                 */
     107                add_theme_support(
     108                        'post-formats', array(
     109                                'aside',
     110                                'image',
     111                                'video',
     112                                'audio',
     113                                'quote',
     114                                'link',
     115                                'gallery',
     116                        )
     117                );
     118
     119                // This theme allows users to set a custom background.
     120                add_theme_support(
     121                        'custom-background', apply_filters(
     122                                'twentyfourteen_custom_background_args', array(
     123                                        'default-color' => 'f5f5f5',
     124                                )
     125                        )
     126                );
     127
     128                // Add support for featured content.
     129                add_theme_support(
     130                        'featured-content', array(
     131                                'featured_content_filter' => 'twentyfourteen_get_featured_posts',
     132                                'max_posts'               => 6,
     133                        )
     134                );
     135
     136                // This theme uses its own gallery styles.
     137                add_filter( 'use_default_gallery_style', '__return_false' );
     138
     139                // Indicate widget sidebars can use selective refresh in the Customizer.
     140                add_theme_support( 'customize-selective-refresh-widgets' );
     141        }
    120142endif; // twentyfourteen_setup
    121143add_action( 'after_setup_theme', 'twentyfourteen_setup' );
    … …  
    171193        register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
    172194
    173         register_sidebar( array(
    174                 'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
    175                 'id'            => 'sidebar-1',
    176                 'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
    177                 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    178                 'after_widget'  => '</aside>',
    179                 'before_title'  => '<h1 class="widget-title">',
    180                 'after_title'   => '</h1>',
    181         ) );
    182         register_sidebar( array(
    183                 'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
    184                 'id'            => 'sidebar-2',
    185                 'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
    186                 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    187                 'after_widget'  => '</aside>',
    188                 'before_title'  => '<h1 class="widget-title">',
    189                 'after_title'   => '</h1>',
    190         ) );
    191         register_sidebar( array(
    192                 'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
    193                 'id'            => 'sidebar-3',
    194                 'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
    195                 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    196                 'after_widget'  => '</aside>',
    197                 'before_title'  => '<h1 class="widget-title">',
    198                 'after_title'   => '</h1>',
    199         ) );
     195        register_sidebar(
     196                array(
     197                        'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
     198                        'id'            => 'sidebar-1',
     199                        'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
     200                        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     201                        'after_widget'  => '</aside>',
     202                        'before_title'  => '<h1 class="widget-title">',
     203                        'after_title'   => '</h1>',
     204                )
     205        );
     206        register_sidebar(
     207                array(
     208                        'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
     209                        'id'            => 'sidebar-2',
     210                        'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
     211                        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     212                        'after_widget'  => '</aside>',
     213                        'before_title'  => '<h1 class="widget-title">',
     214                        'after_title'   => '</h1>',
     215                )
     216        );
     217        register_sidebar(
     218                array(
     219                        'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
     220                        'id'            => 'sidebar-3',
     221                        'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
     222                        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
     223                        'after_widget'  => '</aside>',
     224                        'before_title'  => '<h1 class="widget-title">',
     225                        'after_title'   => '</h1>',
     226                )
     227        );
    200228}
    201229add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
    … …  
    219247                        'subset' => urlencode( 'latin,latin-ext' ),
    220248                );
    221                 $font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
     249                $font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    222250        }
    223251
    … …  
    258286        if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) {
    259287                wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/slider.js', array( 'jquery' ), '20131205', true );
    260                 wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', array(
    261                         'prevText' => __( 'Previous', 'twentyfourteen' ),
    262                         'nextText' => __( 'Next', 'twentyfourteen' )
    263                 ) );
     288                wp_localize_script(
     289                        'twentyfourteen-slider', 'featuredSliderDefaults', array(
     290                                'prevText' => __( 'Previous', 'twentyfourteen' ),
     291                                'nextText' => __( 'Next', 'twentyfourteen' ),
     292                        )
     293                );
    264294        }
    265295
    … …  
    304334
    305335if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) :
    306 /**
    307  * Print the attached image with a link to the next attached image.
    308  *
    309  * @since Twenty Fourteen 1.0
    310  */
    311 function twentyfourteen_the_attached_image() {
    312         $post                = get_post();
    313336        /**
    314          * Filter the default Twenty Fourteen attachment size.
     337         * Print the attached image with a link to the next attached image.
    315338         *
    316339         * @since Twenty Fourteen 1.0
    317          *
    318          * @param array $dimensions {
    319          *     An array of height and width dimensions.
    320          *
    321          *     @type int $height Height of the image in pixels. Default 810.
    322          *     @type int $width  Width of the image in pixels. Default 810.
    323          * }
    324340         */
    325         $attachment_size     = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) );
    326         $next_attachment_url = wp_get_attachment_url();
    327 
    328         /*
    329          * Grab the IDs of all the image attachments in a gallery so we can get the URL
    330          * of the next adjacent image in a gallery, or the first image (if we're
    331          * looking at the last image in a gallery), or, in a gallery of one, just the
    332          * link to that image file.
    333          */
    334         $attachment_ids = get_posts( array(
    335                 'post_parent'    => $post->post_parent,
    336                 'fields'         => 'ids',
    337                 'numberposts'    => -1,
    338                 'post_status'    => 'inherit',
    339                 'post_type'      => 'attachment',
    340                 'post_mime_type' => 'image',
    341                 'order'          => 'ASC',
    342                 'orderby'        => 'menu_order ID',
    343         ) );
    344 
    345         // If there is more than 1 attachment in a gallery...
    346         if ( count( $attachment_ids ) > 1 ) {
    347                 foreach ( $attachment_ids as $idx => $attachment_id ) {
    348                         if ( $attachment_id == $post->ID ) {
    349                                 $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
    350                                 break;
     341        function twentyfourteen_the_attached_image() {
     342                $post = get_post();
     343                /**
     344                 * Filter the default Twenty Fourteen attachment size.
     345                 *
     346                 * @since Twenty Fourteen 1.0
     347                 *
     348                 * @param array $dimensions {
     349                 *     An array of height and width dimensions.
     350                 *
     351                 *     @type int $height Height of the image in pixels. Default 810.
     352                 *     @type int $width  Width of the image in pixels. Default 810.
     353                 * }
     354                 */
     355                $attachment_size     = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) );
     356                $next_attachment_url = wp_get_attachment_url();
     357
     358                /*
     359                 * Grab the IDs of all the image attachments in a gallery so we can get the URL
     360                 * of the next adjacent image in a gallery, or the first image (if we're
     361                 * looking at the last image in a gallery), or, in a gallery of one, just the
     362                 * link to that image file.
     363                 */
     364                $attachment_ids = get_posts(
     365                        array(
     366                                'post_parent'    => $post->post_parent,
     367                                'fields'         => 'ids',
     368                                'numberposts'    => -1,
     369                                'post_status'    => 'inherit',
     370                                'post_type'      => 'attachment',
     371                                'post_mime_type' => 'image',
     372                                'order'          => 'ASC',
     373                                'orderby'        => 'menu_order ID',
     374                        )
     375                );
     376
     377                // If there is more than 1 attachment in a gallery...
     378                if ( count( $attachment_ids ) > 1 ) {
     379                        foreach ( $attachment_ids as $idx => $attachment_id ) {
     380                                if ( $attachment_id == $post->ID ) {
     381                                        $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
     382                                        break;
     383                                }
     384                        }
     385
     386                        // get the URL of the next image attachment...
     387                        if ( $next_id ) {
     388                                $next_attachment_url = get_attachment_link( $next_id );
     389                        } // or get the URL of the first image attachment.
     390                        else {
     391                                $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
    351392                        }
    352393                }
    353394
    354                 // get the URL of the next image attachment...
    355                 if ( $next_id ) {
    356                         $next_attachment_url = get_attachment_link( $next_id );
    357                 }
    358 
    359                 // or get the URL of the first image attachment.
    360                 else {
    361                         $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
    362                 }
    363         }
    364 
    365         printf( '<a href="%1$s" rel="attachment">%2$s</a>',
    366                 esc_url( $next_attachment_url ),
    367                 wp_get_attachment_image( $post->ID, $attachment_size )
    368         );
    369 }
     395                printf(
     396                        '<a href="%1$s" rel="attachment">%2$s</a>',
     397                        esc_url( $next_attachment_url ),
     398                        wp_get_attachment_image( $post->ID, $attachment_size )
     399                );
     400        }
    370401endif;
    371402
    372403if ( ! function_exists( 'twentyfourteen_list_authors' ) ) :
    373 /**
    374  * Print a list of all site contributors who published at least one post.
    375  *
    376  * @since Twenty Fourteen 1.0
    377  */
    378 function twentyfourteen_list_authors() {
    379         $contributor_ids = get_users( array(
    380                 'fields'  => 'ID',
    381                 'orderby' => 'post_count',
    382                 'order'   => 'DESC',
    383                 'who'     => 'authors',
    384         ) );
    385 
    386         foreach ( $contributor_ids as $contributor_id ) :
    387                 $post_count = count_user_posts( $contributor_id );
    388 
    389                 // Move on if user has not published a post (yet).
    390                 if ( ! $post_count ) {
    391                         continue;
    392                 }
    393         ?>
    394 
    395         <div class="contributor">
     404        /**
     405         * Print a list of all site contributors who published at least one post.
     406         *
     407         * @since Twenty Fourteen 1.0
     408         */
     409        function twentyfourteen_list_authors() {
     410                $contributor_ids = get_users(
     411                        array(
     412                                'fields'  => 'ID',
     413                                'orderby' => 'post_count',
     414                                'order'   => 'DESC',
     415                                'who'     => 'authors',
     416                        )
     417                );
     418
     419                foreach ( $contributor_ids as $contributor_id ) :
     420                        $post_count = count_user_posts( $contributor_id );
     421
     422                        // Move on if user has not published a post (yet).
     423                        if ( ! $post_count ) {
     424                                continue;
     425                        }
     426                ?>
     427
     428                <div class="contributor">
    396429                <div class="contributor-info">
    397430                        <div class="contributor-avatar"><?php echo get_avatar( $contributor_id, 132 ); ?></div>
    … …  
    410443        <?php
    411444        endforeach;
    412 }
     445        }
    413446endif;
    414447
    … …  
    575608 */
    576609if ( ! function_exists( 'is_customize_preview' ) ) :
    577 function is_customize_preview() {
    578         global $wp_customize;
    579 
    580         return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview();
    581 }
     610        function is_customize_preview() {
     611                global $wp_customize;
     612
     613                return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview();
     614        }
    582615endif;
Note: See TracChangeset for help on using the changeset viewer.