Twenty Seventeen: Improves code readability and code standards in files

Adds better DocBlock comments and fixes some spacing issues based on PHP_CodeSniffer WordPress coding standards.

Props sstoqnov.

Fixes #39152.

Built from https://develop.svn.wordpress.org/trunk@39618


git-svn-id: http://core.svn.wordpress.org/trunk@39558 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
David A. Kennedy 2016-12-16 22:08:47 +00:00
parent efb191c2ed
commit 7ad554f955
17 changed files with 184 additions and 148 deletions

View File

@ -30,24 +30,24 @@ if ( post_password_required() ) {
if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
$comments_number = get_comments_number();
if ( '1' === $comments_number ) {
/* translators: %s: post title */
printf( _x( 'One Reply to &ldquo;%s&rdquo;', 'comments title', 'twentyseventeen' ), get_the_title() );
} else {
printf(
/* translators: 1: number of comments, 2: post title */
_nx(
'%1$s Reply to &ldquo;%2$s&rdquo;',
'%1$s Replies to &ldquo;%2$s&rdquo;',
$comments_number,
'comments title',
'twentyseventeen'
),
number_format_i18n( $comments_number ),
get_the_title()
);
}
$comments_number = get_comments_number();
if ( '1' === $comments_number ) {
/* translators: %s: post title */
printf( _x( 'One Reply to &ldquo;%s&rdquo;', 'comments title', 'twentyseventeen' ), get_the_title() );
} else {
printf(
/* translators: 1: number of comments, 2: post title */
_nx(
'%1$s Reply to &ldquo;%2$s&rdquo;',
'%1$s Replies to &ldquo;%2$s&rdquo;',
$comments_number,
'comments title',
'twentyseventeen'
),
number_format_i18n( $comments_number ),
get_the_title()
);
}
?>
</h2>

View File

@ -310,6 +310,7 @@ add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
*
* @since Twenty Seventeen 1.0
*
* @param string $link Link to single post/page.
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyseventeen_excerpt_more( $link ) {

View File

@ -95,7 +95,7 @@ function twentyseventeen_custom_colors_css() {
.colors-custom .site-footer .widget-area a,
.colors-custom .posts-navigation a,
.colors-custom .widget_authors a strong {
-webkit-box-shadow: inset 0 -1px 0 hsl( ' . $hue . ', ' . $saturation . ', 6% ); /* base: rgba(15, 15, 15, 1); */
-webkit-box-shadow: inset 0 -1px 0 hsl( ' . $hue . ', ' . $saturation . ', 6% ); /* base: rgba(15, 15, 15, 1); */
box-shadow: inset 0 -1px 0 hsl( ' . $hue . ', ' . $saturation . ', 6% ); /* base: rgba(15, 15, 15, 1); */
}
@ -201,7 +201,7 @@ function twentyseventeen_custom_colors_css() {
.colors-custom .widget ul li a:focus,
.colors-custom .widget ul li a:hover {
-webkit-box-shadow: inset 0 0 0 hsl( ' . $hue . ', ' . $saturation . ', 13% ), 0 3px 0 hsl( ' . $hue . ', ' . $saturation . ', 13% );
box-shadow: inset 0 0 0 hsl( ' . $hue . ', ' . $saturation. ' , 13% ), 0 3px 0 hsl( ' . $hue . ', ' . $saturation . ', 13% );
box-shadow: inset 0 0 0 hsl( ' . $hue . ', ' . $saturation . ' , 13% ), 0 3px 0 hsl( ' . $hue . ', ' . $saturation . ', 13% );
}
body.colors-custom,
@ -560,7 +560,6 @@ body.colors-custom,
}
}';
/**
* Filters Twenty Seventeen custom colors CSS.
*

View File

@ -111,6 +111,8 @@ endif; // End of twentyseventeen_header_style.
/**
* Customize video play/pause button in the custom header.
*
* @param array $settings Video settings.
*/
function twentyseventeen_video_controls( $settings ) {
$settings['l10n']['play'] = '<span class="screen-reader-text">' . __( 'Play background video', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'play' ) );

View File

@ -123,6 +123,8 @@ add_action( 'customize_register', 'twentyseventeen_customize_register' );
/**
* Sanitize the page layout options.
*
* @param string $input Page layout.
*/
function twentyseventeen_sanitize_page_layout( $input ) {
$valid = array(
@ -139,11 +141,13 @@ function twentyseventeen_sanitize_page_layout( $input ) {
/**
* Sanitize the colorscheme.
*
* @param string $input Color scheme.
*/
function twentyseventeen_sanitize_colorscheme( $input ) {
$valid = array( 'light', 'dark', 'custom' );
if ( in_array( $input, $valid ) ) {
if ( in_array( $input, $valid, true ) ) {
return $input;
}

View File

@ -128,8 +128,8 @@ endif;
/**
* Display a front page section.
*
* @param $partial WP_Customize_Partial Partial associated with a selective refresh request.
* @param $id integer Front page section to display.
* @param WP_Customize_Partial $partial Partial associated with a selective refresh request.
* @param integer $id Front page section to display.
*/
function twentyseventeen_front_page_section( $partial = null, $id = 0 ) {
if ( is_a( $partial, 'WP_Customize_Partial' ) ) {

View File

@ -7,6 +7,7 @@
* @since 1.0
* @version 1.0
*/
?>
<?php $unique_id = esc_attr( uniqid( 'search-form-' ) ); ?>

View File

@ -17,22 +17,22 @@ get_header(); ?>
<main id="main" class="site-main" role="main">
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/* Start the Loop */
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/post/content', get_post_format() );
get_template_part( 'template-parts/post/content', get_post_format() );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
the_post_navigation( array(
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '</span>%title</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '</span></span>',
) );
the_post_navigation( array(
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '</span>%title</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '</span></span>',
) );
endwhile; // End of the loop.
endwhile; // End of the loop.
?>
</main><!-- #main -->

View File

@ -21,10 +21,13 @@
<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
<?php endif; ?>
<?php $description = get_bloginfo( 'description', 'display' );
if ( $description || is_customize_preview() ) : ?>
<p class="site-description"><?php echo $description; ?></p>
<?php endif; ?>
<?php
$description = get_bloginfo( 'description', 'display' );
if ( $description || is_customize_preview() ) :
?>
<p class="site-description"><?php echo $description; ?></p>
<?php endif; ?>
</div><!-- .site-branding-text -->
<?php if ( ( twentyseventeen_is_frontpage() || ( is_home() && is_front_page() ) ) && ! has_nav_menu( 'top' ) ) : ?>

View File

@ -10,7 +10,14 @@
?>
<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php _e( 'Top Menu', 'twentyseventeen' ); ?>">
<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false"><?php echo twentyseventeen_get_svg( array( 'icon' => 'bars' ) ); echo twentyseventeen_get_svg( array( 'icon' => 'close' ) ); _e( 'Menu', 'twentyseventeen' ); ?></button>
<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false">
<?php
echo twentyseventeen_get_svg( array( 'icon' => 'bars' ) );
echo twentyseventeen_get_svg( array( 'icon' => 'close' ) );
_e( 'Menu', 'twentyseventeen' );
?>
</button>
<?php wp_nav_menu( array(
'theme_location' => 'top',
'menu_id' => 'top-menu',

View File

@ -14,22 +14,22 @@
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( is_sticky() && is_home() ) :
if ( is_sticky() && is_home() ) {
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
endif;
}
?>
<header class="entry-header">
<?php
if ( 'post' === get_post_type() ) :
if ( 'post' === get_post_type() ) {
echo '<div class="entry-meta">';
if ( is_single() ) :
if ( is_single() ) {
twentyseventeen_posted_on();
else :
} else {
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
endif;
};
echo '</div><!-- .entry-meta -->';
endif;
};
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
@ -60,20 +60,21 @@
<div class="entry-content">
<?php if ( ! is_single() ) :
<?php
if ( ! is_single() ) {
// If not a single post, highlight the audio file.
if ( ! empty( $audio ) ) :
if ( ! empty( $audio ) ) {
foreach ( $audio as $audio_html ) {
echo '<div class="entry-audio">';
echo $audio_html;
echo '</div><!-- .entry-audio -->';
}
endif;
};
endif;
};
if ( is_single() || empty( $audio ) ) :
if ( is_single() || empty( $audio ) ) {
/* translators: %s: Name of current post */
the_content( sprintf(
@ -88,12 +89,15 @@
'link_after' => '</span>',
) );
endif; ?>
};
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) : ?>
<?php twentyseventeen_entry_footer(); ?>
<?php endif; ?>
<?php
if ( is_single() ) {
twentyseventeen_entry_footer();
}
?>
</article><!-- #post-## -->

View File

@ -20,8 +20,8 @@
<?php if ( 'post' === get_post_type() ) : ?>
<div class="entry-meta">
<?php
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
?>
</div><!-- .entry-meta -->
<?php elseif ( 'page' === get_post_type() && get_edit_post_link() ) : ?>

View File

@ -9,32 +9,33 @@
* @since 1.0
* @version 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( is_sticky() && is_home() ) :
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
endif;
if ( is_sticky() && is_home() ) {
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
}
?>
<header class="entry-header">
<?php
if ( 'post' === get_post_type() ) :
echo '<div class="entry-meta">';
if ( is_single() ) :
twentyseventeen_posted_on();
else :
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
endif;
echo '</div><!-- .entry-meta -->';
endif;
if ( 'post' === get_post_type() ) {
echo '<div class="entry-meta">';
if ( is_single() ) {
twentyseventeen_posted_on();
} else {
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
};
echo '</div><!-- .entry-meta -->';
};
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
} else {
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
} else {
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}
?>
</header><!-- .entry-header -->
@ -48,18 +49,19 @@
<div class="entry-content">
<?php if ( ! is_single() ) :
<?php
if ( ! is_single() ) {
// If not a single post, highlight the gallery.
if ( get_post_gallery() ) :
if ( get_post_gallery() ) {
echo '<div class="entry-gallery">';
echo get_post_gallery();
echo '</div>';
endif;
};
endif;
};
if ( is_single() || ! get_post_gallery() ) :
if ( is_single() || ! get_post_gallery() ) {
/* translators: %s: Name of current post */
the_content( sprintf(
@ -74,12 +76,15 @@
'link_after' => '</span>',
) );
endif; ?>
};
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) : ?>
<?php twentyseventeen_entry_footer(); ?>
<?php endif; ?>
<?php
if ( is_single() ) {
twentyseventeen_entry_footer();
}
?>
</article><!-- #post-## -->

View File

@ -9,26 +9,27 @@
* @since 1.0
* @version 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( is_sticky() && is_home() ) :
if ( is_sticky() && is_home() ) {
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
endif;
}
?>
<header class="entry-header">
<?php
if ( 'post' === get_post_type() ) :
if ( 'post' === get_post_type() ) {
echo '<div class="entry-meta">';
if ( is_single() ) :
if ( is_single() ) {
twentyseventeen_posted_on();
else :
} else {
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
endif;
};
echo '</div><!-- .entry-meta -->';
endif;
};
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
@ -48,7 +49,7 @@
<div class="entry-content">
<?php if ( is_single() || '' === get_the_post_thumbnail() ) :
<?php if ( is_single() || '' === get_the_post_thumbnail() ) {
// Only show content if is a single post, or if there's no featured image.
/* translators: %s: Name of current post */
@ -64,12 +65,15 @@
'link_after' => '</span>',
) );
endif; ?>
};
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) : ?>
<?php twentyseventeen_entry_footer(); ?>
<?php endif; ?>
<?php
if ( is_single() ) {
twentyseventeen_entry_footer();
}
?>
</article><!-- #post-## -->

View File

@ -9,26 +9,27 @@
* @since 1.0
* @version 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( is_sticky() && is_home() ) :
if ( is_sticky() && is_home() ) {
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
endif;
}
?>
<header class="entry-header">
<?php
if ( 'post' === get_post_type() ) :
if ( 'post' === get_post_type() ) {
echo '<div class="entry-meta">';
if ( is_single() ) :
if ( is_single() ) {
twentyseventeen_posted_on();
else :
} else {
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
endif;
}
echo '</div><!-- .entry-meta -->';
endif;
};
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
@ -58,20 +59,21 @@
<div class="entry-content">
<?php if ( ! is_single() ) :
<?php
if ( ! is_single() ) {
// If not a single post, highlight the video file.
if ( ! empty( $video ) ) :
if ( ! empty( $video ) ) {
foreach ( $video as $video_html ) {
echo '<div class="entry-video">';
echo $video_html;
echo '</div>';
}
endif;
};
endif;
};
if ( is_single() || empty( $video ) ) :
if ( is_single() || empty( $video ) ) {
/* translators: %s: Name of current post */
the_content( sprintf(
@ -85,13 +87,15 @@
'link_before' => '<span class="page-number">',
'link_after' => '</span>',
) );
endif; ?>
};
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) : ?>
<?php twentyseventeen_entry_footer(); ?>
<?php endif; ?>
<?php
if ( is_single() ) {
twentyseventeen_entry_footer();
}
?>
</article><!-- #post-## -->

View File

@ -14,28 +14,28 @@
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( is_sticky() && is_home() ) :
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
endif;
if ( is_sticky() && is_home() ) :
echo twentyseventeen_get_svg( array( 'icon' => 'thumb-tack' ) );
endif;
?>
<header class="entry-header">
<?php
if ( 'post' === get_post_type() ) :
echo '<div class="entry-meta">';
if ( is_single() ) :
twentyseventeen_posted_on();
else :
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
endif;
echo '</div><!-- .entry-meta -->';
endif;
if ( 'post' === get_post_type() ) {
echo '<div class="entry-meta">';
if ( is_single() ) {
twentyseventeen_posted_on();
} else {
echo twentyseventeen_time_link();
twentyseventeen_edit_link();
};
echo '</div><!-- .entry-meta -->';
};
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
} else {
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}
if ( is_single() ) {
the_title( '<h1 class="entry-title">', '</h1>' );
} else {
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}
?>
</header><!-- .entry-header -->
@ -49,23 +49,25 @@
<div class="entry-content">
<?php
/* translators: %s: Name of current post */
the_content( sprintf(
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
get_the_title()
) );
/* translators: %s: Name of current post */
the_content( sprintf(
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
get_the_title()
) );
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'twentyseventeen' ),
'after' => '</div>',
'link_before' => '<span class="page-number">',
'link_after' => '</span>',
) );
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'twentyseventeen' ),
'after' => '</div>',
'link_before' => '<span class="page-number">',
'link_after' => '</span>',
) );
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) : ?>
<?php twentyseventeen_entry_footer(); ?>
<?php endif; ?>
<?php
if ( is_single() ) {
twentyseventeen_entry_footer();
}
?>
</article><!-- #post-## -->

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-39617';
$wp_version = '4.8-alpha-39618';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.