WordPress.org

Make WordPress Core

Ticket #9015: 9015.functions_cleanup.diff

File 9015.functions_cleanup.diff, 18.5 KB (added by sivel, 8 years ago)

wrap all functions in function_exists, move standalone code into an init function, function prefixing, and code cleanup

  • wp-content/themes/twentyten/functions.php

     
    11<?php
    22
    3 // Set the content width based on the Theme CSS
    4 $content_width = apply_filters('twentyten_content_width', 640 );
     3if ( ! function_exists( 'twentyten_content_width' ) ) :
     4function twentyten_content_width() {
     5    // Set the content width based on the Theme CSS
     6    return apply_filters('twentyten_content_width', 640 );
     7}
     8endif;
    59
    6 // Your Changeable header business starts here
    7 // No CSS, just IMG call
    8 define( 'HEADER_TEXTCOLOR', '');
    9 define( 'HEADER_IMAGE', '%s/images/header-1.jpg'); // %s is theme dir uri
    10 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width',  940 ) );
    11 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height',  198 ) );
    12 define( 'NO_HEADER_TEXT', true );
     10if ( ! function_exists( 'twentyten_init' ) ) :
     11function twentyten_init() {
     12        // Your Changeable header business starts here
     13        // No CSS, just IMG call
     14        define( 'HEADER_TEXTCOLOR', '');
     15        define( 'HEADER_IMAGE', '%s/images/header-1.jpg'); // %s is theme dir uri
     16        define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width',  940 ) );
     17        define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height',  198 ) );
     18        define( 'NO_HEADER_TEXT', true );
    1319
     20        add_custom_image_header( '', 'twentyten_admin_header_style' );
     21        // and thus ends the changeable header business
     22
     23        add_custom_background();
     24
     25        // This theme needs post thumbnails
     26        add_theme_support( 'post-thumbnails' );
     27
     28        // We'll be using them for custom header images on posts and pages
     29        // so we want them to be 940 pixels wide by 198 pixels tall (larger images will be auto-cropped to fit)
     30        set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
     31
     32        // Make theme available for translation
     33        // Translations can be filed in the /languages/ directory
     34        load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
     35
     36        $locale = get_locale();
     37        $locale_file = TEMPLATEPATH . "/languages/$locale.php";
     38        if ( is_readable( $locale_file ) )
     39            require_once( $locale_file );
     40}
     41endif;
     42add_action( 'init', 'twentyten_init' );
     43
     44if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
    1445function twentyten_admin_header_style() {
    1546?>
    1647<style type="text/css">
     
    2455</style>
    2556<?php
    2657}
     58endif;
    2759
    28 add_custom_image_header('', 'twentyten_admin_header_style');
    29 // and thus ends the changeable header business
    30 
    31 add_custom_background();
    32 
    33 // This theme needs post thumbnails
    34 add_theme_support( 'post-thumbnails' );
    35 
    36 // We'll be using them for custom header images on posts and pages
    37 // so we want them to be 940 pixels wide by 198 pixels tall (larger images will be auto-cropped to fit)
    38 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
    39 
    40 // Make theme available for translation
    41 // Translations can be filed in the /languages/ directory
    42 load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
    43 
    44 $locale = get_locale();
    45 $locale_file = TEMPLATEPATH . "/languages/$locale.php";
    46 if ( is_readable($locale_file) )
    47         require_once($locale_file);
    48 
    4960// Get the page number
     61if ( ! function_exists( 'get_page_number' ) ) :
    5062function get_page_number() {
    5163        if ( get_query_var('paged') )
    52                 echo ' | ' . __( 'Page ' , 'twentyten') . get_query_var('paged');
     64                return ' | ' . __( 'Page ' , 'twentyten') . get_query_var('paged');
    5365}
     66endif;
    5467
     68// Echo the page number
     69if ( ! function_exists( 'the_page_number' ) ) :
     70function the_page_number() {
     71        echo get_page_number();
     72}
     73endif;
     74
    5575// Control excerpt length
    56 function new_excerpt_length($length) {
     76if ( ! function_exists( 'twentyten_excerpt_length' ) ) :
     77function twentyten_excerpt_length( $length ) {
    5778        return 40;
    5879}
    59 add_filter('excerpt_length', 'new_excerpt_length');
     80endif;
     81add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
    6082
    6183
    6284// Make a nice read more link on excerpts
    63 function new_excerpt_more($more) {
     85if ( ! function_exists( 'twentyten_excerpt_more' ) ) :
     86function twentyten_excerpt_more($more) {
    6487        return '&nbsp;&hellip; <a href="'. get_permalink() . '">' . 'Continue&nbsp;reading&nbsp;<span class="meta-nav">&rarr;</span>' . '</a>';
    6588}
    66 add_filter('excerpt_more', 'new_excerpt_more');
     89endif;
     90add_filter( 'excerpt_more', 'twentyten_excerpt_more' );
    6791
    6892
    6993// Template for comments and pingbacks
    70 function twentyten_comment($comment, $args, $depth) {
     94if ( ! function_exists( 'twentyten_comment' ) ) :
     95function twentyten_comment( $comment, $args, $depth ) {
    7196        $GLOBALS ['comment'] = $comment; ?>
    72         <?php if ('' == $comment->comment_type) { ?>
    73         <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     97        <?php if ( '' == $comment->comment_type ) : ?>
     98        <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    7499                <div id="comment-<?php comment_ID(); ?>">
    75100                <div class="comment-author vcard">
    76                         <?php echo get_avatar($comment, 40); ?>
     101                        <?php echo get_avatar( $comment, 40 ); ?>
    77102
    78                         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
     103                        <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
    79104                </div>
    80                 <?php if ($comment->comment_approved == '0') : ?>
    81                         <em><?php _e('Your comment is awaiting moderation.') ?></em>
     105                <?php if ( $comment->comment_approved == '0' ) : ?>
     106                        <em><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
    82107                        <br />
    83108                <?php endif; ?>
    84109
    85                 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
     110                <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf( __( '%1$s at %2$s' ), get_comment_date(),  get_comment_time() ) ?></a><?php edit_comment_link( __( '(Edit)' ),'  ','' ); ?></div>
    86111
    87                 <div class="comment-body"><?php comment_text() ?></div>
     112                <div class="comment-body"><?php comment_text(); ?></div>
    88113
    89114                <div class="reply">
    90                         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
     115                        <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    91116                </div>
    92117        </div>
    93118
    94         <?php } else { ?>
     119        <?php else : ?>
    95120        <li class="post pingback">
    96                 <p><?php _e('Pingback:') ?> <?php comment_author_link ()?><?php edit_comment_link ( 'edit', '&nbsp;&nbsp;', '' ); ?></p>
    97         <?php }
     121                <p><?php _e( 'Pingback:' ); ?> <?php comment_author_link (); ?><?php edit_comment_link( 'edit', '&nbsp;&nbsp;', '' ); ?></p>
     122        <?php endif;
    98123}
     124endif;
    99125
    100126// Make the Visual Editor styles match the theme's styles
    101 function my_editor_style($url) {
    102         if ( !empty($url) )
     127if ( ! function_exists( 'twentyten_editor_style' ) ) :
     128function twentyten_editor_style( $url ) {
     129        if ( ! empty( $url ) )
    103130                $url .= ',';
    104131
    105132        // Change the path here if using sub-directory
     
    107134
    108135        return $url;
    109136}
    110 add_filter('mce_css', 'my_editor_style');
     137endif;
     138add_filter( 'mce_css', 'twentyten_editor_style' );
    111139
    112140// Remove inline styles on gallery shortcode
    113 function remove_gallery_css() {
    114         return "<div class='gallery'>";
     141if ( ! function_exists( 'twentyten_remove_gallery_css' ) ) :
     142function twentyten_remove_gallery_css() {
     143        return "\t\t<div class='gallery'>\n\t\t";
    115144}
    116 add_filter('gallery_style', 'remove_gallery_css');
     145endif;
     146add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
    117147
    118148// For category lists on category archives: Returns other categories except the current one (redundant)
    119 function cats_meow($glue) {
     149if ( ! function_exists( 'twentyten_cats_meow' ) ) :
     150function twentyten_cats_meow( $glue ) {
    120151        $current_cat = single_cat_title( '', false );
    121152        $separator = "\n";
    122         $cats = explode( $separator, get_the_category_list($separator) );
     153        $cats = explode( $separator, get_the_category_list( $separator ) );
    123154        foreach ( $cats as $i => $str ) {
    124155                if ( strstr( $str, ">$current_cat<" ) ) {
    125                         unset($cats[$i]);
     156                        unset( $cats[$i] );
    126157                        break;
    127158                }
    128159        }
    129         if ( empty($cats) )
     160        if ( empty( $cats ) )
    130161                return false;
    131162
    132         return trim(join( $glue, $cats ));
    133 } // end cats_meow
     163        return trim( join( $glue, $cats ) );
     164}
     165endif;
    134166
    135167// For tag lists on tag archives: Returns other tags except the current one (redundant)
    136 function tag_ur_it($glue) {
     168if ( ! function_exists( 'twentyten_tag_ur_it' ) ) :
     169function twentyten_tag_ur_it( $glue ) {
    137170        $current_tag = single_tag_title( '', '',  false );
    138171        $separator = "\n";
    139172        $tags = explode( $separator, get_the_tag_list( "", "$separator", "" ) );
    140173        foreach ( $tags as $i => $str ) {
    141174                if ( strstr( $str, ">$current_tag<" ) ) {
    142                         unset($tags[$i]);
     175                        unset( $tags[$i] );
    143176                        break;
    144177                }
    145178        }
    146         if ( empty($tags) )
     179        if ( empty( $tags ) )
    147180                return false;
    148181
    149         return trim(join( $glue, $tags ));
    150 } // end tag_ur_it
     182        return trim( join( $glue, $tags ) );
     183}
     184endif;
    151185
    152186// Register widgetized areas
    153 function theme_widgets_init() {
     187if ( ! function_exists( 'twentyten_widgets_init' ) ) :
     188function twentyten_widgets_init() {
    154189        // Area 1
    155190        register_sidebar( array (
    156191                'name' => 'Primary Widget Area',
    157192                'id' => 'primary-widget-area',
    158                 'description' => __('The primary widget area' , 'twentyten'),
     193                'description' => __( 'The primary widget area' , 'twentyten' ),
    159194                'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    160195                'after_widget' => "</li>",
    161196                'before_title' => '<h3 class="widget-title">',
     
    166201        register_sidebar( array (
    167202                'name' => 'Secondary Widget Area',
    168203                'id' => 'secondary-widget-area',
    169                 'description' => __('The secondary widget area' , 'twentyten'),
     204                'description' => __( 'The secondary widget area' , 'twentyten' ),
    170205                'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    171206                'after_widget' => "</li>",
    172207                'before_title' => '<h3 class="widget-title">',
     
    177212        register_sidebar( array (
    178213                'name' => 'First Footer Widget Area',
    179214                'id' => 'first-footer-widget-area',
    180                 'description' => __('The first footer widget area' , 'twentyten'),
     215                'description' => __( 'The first footer widget area' , 'twentyten' ),
    181216                'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    182217                'after_widget' => "</li>",
    183218                'before_title' => '<h3 class="widget-title">',
     
    188223        register_sidebar( array (
    189224                'name' => 'Second Footer Widget Area',
    190225                'id' => 'second-footer-widget-area',
    191                 'description' => __('The second footer widget area' , 'twentyten'),
     226                'description' => __( 'The second footer widget area' , 'twentyten' ),
    192227                'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    193228                'after_widget' => "</li>",
    194229                'before_title' => '<h3 class="widget-title">',
     
    199234        register_sidebar( array (
    200235                'name' => 'Third Footer Widget Area',
    201236                'id' => 'third-footer-widget-area',
    202                 'description' => __('The third footer widget area' , 'twentyten'),
     237                'description' => __( 'The third footer widget area' , 'twentyten' ),
    203238                'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    204239                'after_widget' => "</li>",
    205240                'before_title' => '<h3 class="widget-title">',
     
    210245        register_sidebar( array (
    211246                'name' => 'Fourth Footer Widget Area',
    212247                'id' => 'fourth-footer-widget-area',
    213                 'description' => __('The fourth footer widget area' , 'twentyten'),
     248                'description' => __( 'The fourth footer widget area' , 'twentyten' ),
    214249                'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    215250                'after_widget' => "</li>",
    216251                'before_title' => '<h3 class="widget-title">',
    217252                'after_title' => '</h3>',
    218253        ) );
    219254
    220 } // end theme_widgets_init
    221 
    222 // Add all the groovy widget areas
    223 add_action( 'init', 'theme_widgets_init' );
    224  No newline at end of file
     255}
     256endif;
     257add_action( 'init', 'twentyten_widgets_init' );
  • wp-content/themes/twentyten/tag.php

     
    3535                                        <div class="entry-utility">
    3636                                                <span class="cat-links"><span class="entry-utility-prep entry-utility-prep-cat-links"><?php _e( 'Posted in ', 'twentyten' ); ?></span><?php echo get_the_category_list(', '); ?></span>
    3737                                                <span class="meta-sep"> | </span>
    38 <?php if ( $tag_ur_it = tag_ur_it(', ') ) : // Returns tags other than the one queried ?>
     38<?php if ( $tag_ur_it = twentyten_tag_ur_it(', ') ) : // Returns tags other than the one queried ?>
    3939                                                <span class="tag-links"><?php printf( __( 'Also tagged %s', 'twentyten' ), $tag_ur_it ) ?></span>
    4040<?php endif; ?>
    4141                                                <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ) ?></span>
     
    5656                </div><!-- #container -->
    5757
    5858<?php get_sidebar(); ?>
    59 <?php get_footer(); ?>
    60  No newline at end of file
     59<?php get_footer(); ?>
  • wp-content/themes/twentyten/category.php

     
    3636                                        </div><!-- .entry-summary -->
    3737
    3838                                        <div class="entry-utility">
    39 <?php if ( $cats_meow = cats_meow(', ') ) : // Returns categories other than the one queried ?>
     39<?php if ( $cats_meow = twentyten_cats_meow(', ') ) : // Returns categories other than the one queried ?>
    4040                                                <span class="cat-links"><?php printf( __( 'Also posted in %s', 'twentyten' ), $cats_meow ) ?></span>
    4141                                                <span class="meta-sep"> | </span>
    4242<?php endif ?>
     
    5959                </div><!-- #container -->
    6060
    6161<?php get_sidebar(); ?>
    62 <?php get_footer(); ?>
    63  No newline at end of file
     62<?php get_footer(); ?>
  • wp-content/themes/twentyten/header.php

     
    55        if ( is_single() ) {
    66                        single_post_title(); echo ' | '; bloginfo('name');
    77                } elseif ( is_home() || is_front_page() ) {
    8                         bloginfo('name'); echo ' | '; bloginfo('description'); get_page_number();
     8                        bloginfo('name'); echo ' | '; bloginfo('description'); the_page_number();
    99                } elseif ( is_page() ) {
    1010                        single_post_title(''); echo ' | '; bloginfo('name');
    1111                } elseif ( is_search() ) {
    12                         printf(__('Search results for "%s"', 'twentyten'), esc_html($s)); get_page_number(); echo ' | '; bloginfo('name');
     12                        printf(__('Search results for "%s"', 'twentyten'), esc_html($s)); the_page_number(); echo ' | '; bloginfo('name');
    1313                } elseif ( is_404() ) {
    1414                        _e('Not Found', 'twentyten'); echo ' | '; bloginfo('name');
    1515                } else {
    16                         wp_title(''); echo ' | '; bloginfo('name'); get_page_number();
     16                        wp_title(''); echo ' | '; bloginfo('name'); the_page_number();
    1717                }
    1818    ?></title>
    1919
  • wp-content/themes/twentyten/attachment.php

     
    55
    66<?php the_post(); ?>
    77
    8                                 <p class="page-title"><a href="<?php echo get_permalink($post->post_parent) ?>" title="<?php printf( esc_attr__( 'Return to %s', 'twentyten' ), esc_html( get_the_title($post->post_parent), 1 ) ) ?>" rel="gallery">&larr; <?php echo get_the_title($post->post_parent) ?></a></p>
     8                                <p class="page-title"><a href="<?php echo get_permalink( $post->post_parent ) ?>" title="<?php printf( esc_attr__( 'Return to %s', 'twentyten' ), esc_html( get_the_title( $post->post_parent ), 1 ) ) ?>" rel="gallery">&larr; <?php echo get_the_title( $post->post_parent ) ?></a></p>
    99
    1010                                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    1111                                        <h2 class="entry-title"><?php the_title(); ?></h2>
    1212
    1313                                        <div class="entry-meta">
    14                                                 <span class="meta-prep meta-prep-author"><?php _e('By ', 'twentyten'); ?></span>
     14                                                <span class="meta-prep meta-prep-author"><?php _e( 'By ', 'twentyten' ); ?></span>
    1515                                                <span class="author vcard"><a class="url fn n" href="<?php echo get_author_posts_url( $authordata->ID, $authordata->user_nicename ); ?>" title="<?php printf( esc_attr__( 'View all posts by %s', 'twentyten' ), $authordata->display_name ); ?>"><?php the_author(); ?></a></span>
    1616                                                <span class="meta-sep"> | </span>
    1717                                                <span class="meta-prep meta-prep-entry-date"><?php _e('Published ', 'twentyten'); ?></span>
     
    2222                                        <div class="entry-content">
    2323                                                <div class="entry-attachment">
    2424<?php if ( wp_attachment_is_image( $post->ID ) ) : ?>
    25                                                 <p class="attachment"><a href="<?php echo wp_get_attachment_url($post->ID); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
    26                                                         echo wp_get_attachment_image( $post->ID, array($content_width, $content_width) ); // max $content_width wide or high.
     25                                                <p class="attachment"><a href="<?php echo wp_get_attachment_url( $post->ID ); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
     26                                                        echo wp_get_attachment_image( $post->ID, array( twentyten_content_width(), twentyten_content_width() ) ); // max $content_width wide or high.
    2727                                                ?></a></p>
    2828
    2929
     
    3232                                        <div class="nav-next"><?php next_image_link( false ); ?></div>
    3333                                </div><!-- #nav-below -->
    3434<?php else : ?>
    35                                                 <a href="<?php echo wp_get_attachment_url($post->ID) ?>" title="<?php echo esc_attr( get_the_title($post->ID) ); ?>" rel="attachment"><?php echo basename(get_permalink()) ?></a>
     35                                                <a href="<?php echo wp_get_attachment_url( $post->ID ) ?>" title="<?php echo esc_attr( get_the_title( $post->ID ) ); ?>" rel="attachment"><?php echo basename( get_permalink() ) ?></a>
    3636<?php endif; ?>
    3737                                                </div>
    38                                                 <div class="entry-caption"><?php if ( !empty($post->post_excerpt) ) the_excerpt() ?></div>
     38                                                <div class="entry-caption"><?php if ( ! empty( $post->post_excerpt ) ) the_excerpt() ?></div>
    3939
    4040<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' )  ); ?>
    41 <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'twentyten' ) . '&after=</div>') ?>
     41<?php wp_link_pages( 'before=<div class="page-link">' . __( 'Pages:', 'twentyten' ) . '&after=</div>' ) ?>
    4242
    4343                                        </div><!-- .entry-content -->
    4444
     
    6969                </div><!-- #container -->
    7070
    7171<?php get_sidebar(); ?>
    72 <?php get_footer(); ?>
    73  No newline at end of file
     72<?php get_footer(); ?>