[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentyten/ -> functions.php (source)

   1  <?php
   2  /**
   3   * TwentyTen functions and definitions
   4   *
   5   * Sets up the theme and provides some helper functions. Some helper functions
   6   * are used in the theme as custom template tags. Others are attached to action and
   7   * filter hooks in WordPress to change core functionality.
   8   *
   9   * The first function, twentyten_setup(), sets up the theme by registering support
  10   * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11   *
  12   * When using a child theme you can override certain functions (those wrapped
  13   * in a function_exists() call) by defining them first in your child theme's
  14   * functions.php file. The child theme's functions.php file is included before
  15   * the parent theme's file, so the child theme functions would be used.
  16   *
  17   * @link https://developer.wordpress.org/themes/basics/theme-functions/
  18   * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
  19   *
  20   * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  21   * to a filter or action hook. The hook can be removed by using remove_action() or
  22   * remove_filter() and you can attach your own function to the hook.
  23   *
  24   * We can remove the parent theme's hook only after it is attached, which means we need to
  25   * wait until setting up the child theme:
  26   *
  27   * <code>
  28   * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  29   * function my_child_theme_setup() {
  30   *     // We are providing our own filter for excerpt_length (or using the unfiltered value).
  31   *     remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  32   *     ...
  33   * }
  34   * </code>
  35   *
  36   * For more information on hooks, actions, and filters, see https://developer.wordpress.org/plugins/.
  37   *
  38   * @package WordPress
  39   * @subpackage Twenty_Ten
  40   * @since Twenty Ten 1.0
  41   */
  42  
  43  /*
  44   * Set the content width based on the theme's design and stylesheet.
  45   *
  46   * Used to set the width of images and content. Should be equal to the width the theme
  47   * is designed for, generally via the style.css stylesheet.
  48   */
  49  if ( ! isset( $content_width ) ) {
  50      $content_width = 640;
  51  }
  52  
  53  /* Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  54  add_action( 'after_setup_theme', 'twentyten_setup' );
  55  
  56  if ( ! function_exists( 'twentyten_setup' ) ) :
  57      /**
  58       * Set up theme defaults and registers support for various WordPress features.
  59       *
  60       * Note that this function is hooked into the after_setup_theme hook, which runs
  61       * before the init hook. The init hook is too late for some features, such as indicating
  62       * support post thumbnails.
  63       *
  64       * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  65       * functions.php file.
  66       *
  67       * @uses add_theme_support()        To add support for post thumbnails, custom headers and backgrounds, and automatic feed links.
  68       * @uses register_nav_menus()       To add support for navigation menus.
  69       * @uses add_editor_style()         To style the visual editor.
  70       * @uses load_theme_textdomain()    For translation/localization support.
  71       * @uses register_default_headers() To register the default custom header images provided with the theme.
  72       * @uses set_post_thumbnail_size()  To set a custom post thumbnail size.
  73       *
  74       * @since Twenty Ten 1.0
  75       */
  76  	function twentyten_setup() {
  77  
  78          // This theme styles the visual editor with editor-style.css to match the theme style.
  79          add_editor_style();
  80  
  81          // Load regular editor styles into the new block-based editor.
  82          add_theme_support( 'editor-styles' );
  83  
  84          // Load default block styles.
  85          add_theme_support( 'wp-block-styles' );
  86  
  87          // Add support for custom color scheme.
  88          add_theme_support(
  89              'editor-color-palette',
  90              array(
  91                  array(
  92                      'name'  => __( 'Blue', 'twentyten' ),
  93                      'slug'  => 'blue',
  94                      'color' => '#0066cc',
  95                  ),
  96                  array(
  97                      'name'  => __( 'Black', 'twentyten' ),
  98                      'slug'  => 'black',
  99                      'color' => '#000',
 100                  ),
 101                  array(
 102                      'name'  => __( 'Medium Gray', 'twentyten' ),
 103                      'slug'  => 'medium-gray',
 104                      'color' => '#666',
 105                  ),
 106                  array(
 107                      'name'  => __( 'Light Gray', 'twentyten' ),
 108                      'slug'  => 'light-gray',
 109                      'color' => '#f1f1f1',
 110                  ),
 111                  array(
 112                      'name'  => __( 'White', 'twentyten' ),
 113                      'slug'  => 'white',
 114                      'color' => '#fff',
 115                  ),
 116              )
 117          );
 118  
 119          // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
 120          add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
 121  
 122          // This theme uses post thumbnails.
 123          add_theme_support( 'post-thumbnails' );
 124  
 125          // Add default posts and comments RSS feed links to head.
 126          add_theme_support( 'automatic-feed-links' );
 127  
 128          /*
 129           * Make theme available for translation.
 130           * Translations can be filed in the /languages/ directory.
 131           *
 132           * Manual loading of text domain is not required after the introduction of
 133           * just in time translation loading in WordPress version 4.6.
 134           *
 135           * @ticket 58318
 136           */
 137          if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) {
 138              load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' );
 139          }
 140  
 141          // This theme uses wp_nav_menu() in one location.
 142          register_nav_menus(
 143              array(
 144                  'primary' => __( 'Primary Navigation', 'twentyten' ),
 145              )
 146          );
 147  
 148          // This theme allows users to set a custom background.
 149          add_theme_support(
 150              'custom-background',
 151              array(
 152                  // Let WordPress know what our default background color is.
 153                  'default-color' => 'f1f1f1',
 154              )
 155          );
 156  
 157          // The custom header business starts here.
 158  
 159          $custom_header_support = array(
 160              /*
 161               * The default image to use.
 162               * The %s is a placeholder for the theme template directory URI.
 163               */
 164              'default-image'       => '%s/images/headers/path.jpg',
 165              // The height and width of our custom header.
 166              /**
 167               * Filters the Twenty Ten default header image width.
 168               *
 169               * @since Twenty Ten 1.0
 170               *
 171               * @param int The default header image width in pixels. Default 940.
 172               */
 173              'width'               => apply_filters( 'twentyten_header_image_width', 940 ),
 174              /**
 175               * Filters the Twenty Ten default header image height.
 176               *
 177               * @since Twenty Ten 1.0
 178               *
 179               * @param int The default header image height in pixels. Default 198.
 180               */
 181              'height'              => apply_filters( 'twentyten_header_image_height', 198 ),
 182              // Support flexible heights.
 183              'flex-height'         => true,
 184              // Don't support text inside the header image.
 185              'header-text'         => false,
 186              // Callback for styling the header preview in the admin.
 187              'admin-head-callback' => 'twentyten_admin_header_style',
 188          );
 189  
 190          add_theme_support( 'custom-header', $custom_header_support );
 191  
 192          if ( ! function_exists( 'get_custom_header' ) ) {
 193              // This is all for compatibility with versions of WordPress prior to 3.4.
 194              define( 'HEADER_TEXTCOLOR', '' );
 195              define( 'NO_HEADER_TEXT', true );
 196              define( 'HEADER_IMAGE', $custom_header_support['default-image'] );
 197              define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
 198              define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
 199              add_custom_image_header( '', $custom_header_support['admin-head-callback'] );
 200              add_custom_background();
 201          }
 202  
 203          /*
 204           * We'll be using post thumbnails for custom header images on posts and pages.
 205           * We want them to be 940 pixels wide by 198 pixels tall.
 206           * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
 207           */
 208          set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
 209  
 210          // ...and thus ends the custom header business.
 211  
 212          // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
 213          register_default_headers(
 214              array(
 215                  'berries'       => array(
 216                      'url'           => '%s/images/headers/berries.jpg',
 217                      'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
 218                      /* translators: Header image description. */
 219                      'description'   => __( 'Berries', 'twentyten' ),
 220                  ),
 221                  'cherryblossom' => array(
 222                      'url'           => '%s/images/headers/cherryblossoms.jpg',
 223                      'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
 224                      /* translators: Header image description. */
 225                      'description'   => __( 'Cherry Blossoms', 'twentyten' ),
 226                  ),
 227                  'concave'       => array(
 228                      'url'           => '%s/images/headers/concave.jpg',
 229                      'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
 230                      /* translators: Header image description. */
 231                      'description'   => __( 'Concave', 'twentyten' ),
 232                  ),
 233                  'fern'          => array(
 234                      'url'           => '%s/images/headers/fern.jpg',
 235                      'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
 236                      /* translators: Header image description. */
 237                      'description'   => __( 'Fern', 'twentyten' ),
 238                  ),
 239                  'forestfloor'   => array(
 240                      'url'           => '%s/images/headers/forestfloor.jpg',
 241                      'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
 242                      /* translators: Header image description. */
 243                      'description'   => __( 'Forest Floor', 'twentyten' ),
 244                  ),
 245                  'inkwell'       => array(
 246                      'url'           => '%s/images/headers/inkwell.jpg',
 247                      'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
 248                      /* translators: Header image description. */
 249                      'description'   => __( 'Inkwell', 'twentyten' ),
 250                  ),
 251                  'path'          => array(
 252                      'url'           => '%s/images/headers/path.jpg',
 253                      'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
 254                      /* translators: Header image description. */
 255                      'description'   => __( 'Path', 'twentyten' ),
 256                  ),
 257                  'sunset'        => array(
 258                      'url'           => '%s/images/headers/sunset.jpg',
 259                      'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
 260                      /* translators: Header image description. */
 261                      'description'   => __( 'Sunset', 'twentyten' ),
 262                  ),
 263              )
 264          );
 265      }
 266  endif;
 267  
 268  if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
 269      /**
 270       * Style the header image displayed on the Appearance > Header admin panel.
 271       *
 272       * Referenced via add_custom_image_header() in twentyten_setup().
 273       *
 274       * @since Twenty Ten 1.0
 275       */
 276  	function twentyten_admin_header_style() {
 277          ?>
 278      <style type="text/css" id="twentyten-admin-header-css">
 279      /* Shows the same border as on front end */
 280      #headimg {
 281      border-bottom: 1px solid #000;
 282      border-top: 4px solid #000;
 283      }
 284      /* If header-text was supported, you would style the text with these selectors:
 285      #headimg #name { }
 286      #headimg #desc { }
 287      */
 288      </style>
 289          <?php
 290      }
 291  endif;
 292  
 293  
 294  if ( ! function_exists( 'twentyten_header_image' ) ) :
 295      /**
 296       * Custom header image markup displayed.
 297       *
 298       * @since Twenty Ten 4.0
 299       */
 300  	function twentyten_header_image() {
 301          $attrs = array(
 302              'alt' => get_bloginfo( 'name', 'display' ),
 303          );
 304  
 305          // Compatibility with versions of WordPress prior to 3.4.
 306          if ( function_exists( 'get_custom_header' ) ) {
 307              $custom_header   = get_custom_header();
 308              $attrs['width']  = $custom_header->width;
 309              $attrs['height'] = $custom_header->height;
 310          } else {
 311              $attrs['width']  = HEADER_IMAGE_WIDTH;
 312              $attrs['height'] = HEADER_IMAGE_HEIGHT;
 313          }
 314  
 315          if ( function_exists( 'the_header_image_tag' ) ) {
 316              the_header_image_tag( $attrs );
 317              return;
 318          }
 319  
 320          ?>
 321          <img src="<?php header_image(); ?>" width="<?php echo esc_attr( $attrs['width'] ); ?>" height="<?php echo esc_attr( $attrs['height'] ); ?>" alt="<?php echo esc_attr( $attrs['alt'] ); ?>" />
 322          <?php
 323      }
 324  endif; // twentyten_header_image()
 325  
 326  /**
 327   * Show a home link for our wp_nav_menu() fallback, wp_page_menu().
 328   *
 329   * To override this in a child theme, remove the filter and optionally add
 330   * your own function tied to the wp_page_menu_args filter hook.
 331   *
 332   * @since Twenty Ten 1.0
 333   *
 334   * @param array $args An optional array of arguments. @see wp_page_menu()
 335   */
 336  function twentyten_page_menu_args( $args ) {
 337      if ( ! isset( $args['show_home'] ) ) {
 338          $args['show_home'] = true;
 339      }
 340      return $args;
 341  }
 342  add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
 343  
 344  /**
 345   * Set the post excerpt length to 40 characters.
 346   *
 347   * To override this length in a child theme, remove the filter and add your own
 348   * function tied to the excerpt_length filter hook.
 349   *
 350   * @since Twenty Ten 1.0
 351   *
 352   * @param int $length The number of excerpt characters.
 353   * @return int The filtered number of excerpt characters.
 354   */
 355  function twentyten_excerpt_length( $length ) {
 356      return 40;
 357  }
 358  add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
 359  
 360  if ( ! function_exists( 'twentyten_continue_reading_link' ) ) :
 361      /**
 362       * Return a "Continue Reading" link for excerpts.
 363       *
 364       * @since Twenty Ten 1.0
 365       *
 366       * @return string "Continue Reading" link.
 367       */
 368  	function twentyten_continue_reading_link() {
 369          return ' <a href="' . esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
 370      }
 371  endif;
 372  
 373  /**
 374   * Replace "[...]" with an ellipsis and twentyten_continue_reading_link().
 375   *
 376   * "[...]" is appended to automatically generated excerpts.
 377   *
 378   * To override this in a child theme, remove the filter and add your own
 379   * function tied to the excerpt_more filter hook.
 380   *
 381   * @since Twenty Ten 1.0
 382   *
 383   * @param string $more The Read More text.
 384   * @return string The filtered Read More text.
 385   */
 386  function twentyten_auto_excerpt_more( $more ) {
 387      if ( ! is_admin() ) {
 388          return ' &hellip;' . twentyten_continue_reading_link();
 389      }
 390      return $more;
 391  }
 392  add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
 393  
 394  /**
 395   * Add a pretty "Continue Reading" link to custom post excerpts.
 396   *
 397   * To override this link in a child theme, remove the filter and add your own
 398   * function tied to the get_the_excerpt filter hook.
 399   *
 400   * @since Twenty Ten 1.0
 401   *
 402   * @param string $output The "Continue Reading" link.
 403   * @return string Excerpt with a pretty "Continue Reading" link.
 404   */
 405  function twentyten_custom_excerpt_more( $output ) {
 406      if ( has_excerpt() && ! is_attachment() && ! is_admin() ) {
 407          $output .= twentyten_continue_reading_link();
 408      }
 409      return $output;
 410  }
 411  add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
 412  
 413  /**
 414   * Remove inline styles printed when the gallery shortcode is used.
 415   *
 416   * Galleries are styled by the theme in Twenty Ten's style.css. This is just
 417   * a simple filter call that tells WordPress to not use the default styles.
 418   *
 419   * @since Twenty Ten 1.2
 420   */
 421  add_filter( 'use_default_gallery_style', '__return_false' );
 422  
 423  /**
 424   * Deprecated way to remove inline styles printed when the gallery shortcode is used.
 425   *
 426   * This function is no longer needed or used. Use the use_default_gallery_style
 427   * filter instead, as seen above.
 428   *
 429   * @since Twenty Ten 1.0
 430   * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
 431   *
 432   * @param string $css Default CSS styles and opening HTML div container
 433   *                    for the gallery shortcode output.
 434   * @return string The gallery style filter, with the styles themselves removed.
 435   */
 436  function twentyten_remove_gallery_css( $css ) {
 437      return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
 438  }
 439  // Backward compatibility with WordPress 3.0.
 440  if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) {
 441      add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
 442  }
 443  
 444  if ( ! function_exists( 'twentyten_comment' ) ) :
 445      /**
 446       * Template for comments and pingbacks.
 447       *
 448       * To override this walker in a child theme without modifying the comments template
 449       * simply create your own twentyten_comment(), and that function will be used instead.
 450       *
 451       * Used as a callback by wp_list_comments() for displaying the comments.
 452       *
 453       * @since Twenty Ten 1.0
 454       *
 455       * @param WP_Comment $comment The comment object.
 456       * @param array      $args    An array of arguments. @see get_comment_reply_link()
 457       * @param int        $depth   The depth of the comment.
 458       */
 459  	function twentyten_comment( $comment, $args, $depth ) {
 460          $GLOBALS['comment'] = $comment;
 461          switch ( $comment->comment_type ) :
 462              case '':
 463              case 'comment':
 464                  ?>
 465          <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 466          <div id="comment-<?php comment_ID(); ?>">
 467              <div class="comment-author vcard">
 468                  <?php echo get_avatar( $comment, 40 ); ?>
 469                  <?php
 470                  /* translators: %s: Author display name. */
 471                  printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) );
 472                  ?>
 473              </div><!-- .comment-author .vcard -->
 474  
 475                  <?php
 476                  $commenter = wp_get_current_commenter();
 477                  if ( $commenter['comment_author_email'] ) {
 478                      $moderation_note = __( 'Your comment is awaiting moderation.', 'twentyten' );
 479                  } else {
 480                      $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentyten' );
 481                  }
 482                  ?>
 483  
 484                  <?php if ( '0' === $comment->comment_approved ) : ?>
 485              <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
 486              <br />
 487              <?php endif; ?>
 488  
 489              <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
 490                  <?php
 491                      /* translators: 1: Date, 2: Time. */
 492                      printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() );
 493                  ?>
 494                      </a>
 495                      <?php
 496                      edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
 497                      ?>
 498                  </div><!-- .comment-meta .commentmetadata -->
 499  
 500                  <div class="comment-body"><?php comment_text(); ?></div>
 501  
 502                  <div class="reply">
 503                  <?php
 504                  comment_reply_link(
 505                      array_merge(
 506                          $args,
 507                          array(
 508                              'depth'     => $depth,
 509                              'max_depth' => $args['max_depth'],
 510                          )
 511                      )
 512                  );
 513                  ?>
 514                  </div><!-- .reply -->
 515              </div><!-- #comment-##  -->
 516  
 517                  <?php
 518                  break;
 519              case 'pingback':
 520              case 'trackback':
 521                  ?>
 522          <li class="post pingback">
 523          <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
 524                  <?php
 525                  break;
 526          endswitch;
 527      }
 528  endif;
 529  
 530  /**
 531   * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
 532   *
 533   * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
 534   * function tied to the init hook.
 535   *
 536   * @since Twenty Ten 1.0
 537   *
 538   * @uses register_sidebar()
 539   */
 540  function twentyten_widgets_init() {
 541      // Area 1, located at the top of the sidebar.
 542      register_sidebar(
 543          array(
 544              'name'          => __( 'Primary Widget Area', 'twentyten' ),
 545              'id'            => 'primary-widget-area',
 546              'description'   => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ),
 547              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 548              'after_widget'  => '</li>',
 549              'before_title'  => '<h3 class="widget-title">',
 550              'after_title'   => '</h3>',
 551          )
 552      );
 553  
 554      // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
 555      register_sidebar(
 556          array(
 557              'name'          => __( 'Secondary Widget Area', 'twentyten' ),
 558              'id'            => 'secondary-widget-area',
 559              'description'   => __( 'An optional secondary widget area, displays below the primary widget area in your sidebar.', 'twentyten' ),
 560              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 561              'after_widget'  => '</li>',
 562              'before_title'  => '<h3 class="widget-title">',
 563              'after_title'   => '</h3>',
 564          )
 565      );
 566  
 567      // Area 3, located in the footer. Empty by default.
 568      register_sidebar(
 569          array(
 570              'name'          => __( 'First Footer Widget Area', 'twentyten' ),
 571              'id'            => 'first-footer-widget-area',
 572              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 573              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 574              'after_widget'  => '</li>',
 575              'before_title'  => '<h3 class="widget-title">',
 576              'after_title'   => '</h3>',
 577          )
 578      );
 579  
 580      // Area 4, located in the footer. Empty by default.
 581      register_sidebar(
 582          array(
 583              'name'          => __( 'Second Footer Widget Area', 'twentyten' ),
 584              'id'            => 'second-footer-widget-area',
 585              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 586              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 587              'after_widget'  => '</li>',
 588              'before_title'  => '<h3 class="widget-title">',
 589              'after_title'   => '</h3>',
 590          )
 591      );
 592  
 593      // Area 5, located in the footer. Empty by default.
 594      register_sidebar(
 595          array(
 596              'name'          => __( 'Third Footer Widget Area', 'twentyten' ),
 597              'id'            => 'third-footer-widget-area',
 598              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 599              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 600              'after_widget'  => '</li>',
 601              'before_title'  => '<h3 class="widget-title">',
 602              'after_title'   => '</h3>',
 603          )
 604      );
 605  
 606      // Area 6, located in the footer. Empty by default.
 607      register_sidebar(
 608          array(
 609              'name'          => __( 'Fourth Footer Widget Area', 'twentyten' ),
 610              'id'            => 'fourth-footer-widget-area',
 611              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 612              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 613              'after_widget'  => '</li>',
 614              'before_title'  => '<h3 class="widget-title">',
 615              'after_title'   => '</h3>',
 616          )
 617      );
 618  }
 619  /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
 620  add_action( 'widgets_init', 'twentyten_widgets_init' );
 621  
 622  /**
 623   * Remove the default styles that are packaged with the Recent Comments widget.
 624   *
 625   * To override this in a child theme, remove the filter and optionally add your own
 626   * function tied to the widgets_init action hook.
 627   *
 628   * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
 629   * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
 630   * but they won't have any effect on the widget in default Twenty Ten styling.
 631   *
 632   * @since Twenty Ten 1.0
 633   */
 634  function twentyten_remove_recent_comments_style() {
 635      add_filter( 'show_recent_comments_widget_style', '__return_false' );
 636  }
 637  add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
 638  
 639  if ( ! function_exists( 'twentyten_posted_on' ) ) :
 640      /**
 641       * Print HTML with meta information for the current post-date/time and author.
 642       *
 643       * @since Twenty Ten 1.0
 644       */
 645  	function twentyten_posted_on() {
 646          printf(
 647              /* translators: 1: CSS classes, 2: Date, 3: Author display name. */
 648              __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
 649              'meta-prep meta-prep-author',
 650              sprintf(
 651                  '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
 652                  esc_url( get_permalink() ),
 653                  esc_attr( get_the_time() ),
 654                  get_the_date()
 655              ),
 656              sprintf(
 657                  '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
 658                  esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 659                  /* translators: %s: Author display name. */
 660                  esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
 661                  get_the_author()
 662              )
 663          );
 664      }
 665  endif;
 666  
 667  if ( ! function_exists( 'twentyten_posted_in' ) ) :
 668      /**
 669       * Print HTML with meta information for the current post (category, tags and permalink).
 670       *
 671       * @since Twenty Ten 1.0
 672       */
 673  	function twentyten_posted_in() {
 674          // Retrieves tag list of current post, separated by commas.
 675          $tags_list = get_the_tag_list( '', ', ' );
 676  
 677          if ( $tags_list && ! is_wp_error( $tags_list ) ) {
 678              /* translators: 1: Category name, 2: Tag name, 3: Post permalink, 4: Post title. */
 679              $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
 680          } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
 681              /* translators: 1: Category name, 3: Post permalink, 4: Post title. */
 682              $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
 683          } else {
 684              /* translators: 3: Post permalink, 4: Post title. */
 685              $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
 686          }
 687  
 688          // Prints the string, replacing the placeholders.
 689          printf(
 690              $posted_in,
 691              get_the_category_list( ', ' ),
 692              $tags_list,
 693              esc_url( get_permalink() ),
 694              the_title_attribute( 'echo=0' )
 695          );
 696      }
 697  endif;
 698  
 699  /**
 700   * Retrieve the IDs for images in a gallery.
 701   *
 702   * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
 703   *                            then as last option uses a get_posts() call.
 704   *
 705   * @since Twenty Ten 1.6.
 706   *
 707   * @return array List of image IDs from the post gallery.
 708   */
 709  function twentyten_get_gallery_images() {
 710      $images = array();
 711  
 712      if ( function_exists( 'get_post_galleries' ) ) {
 713          $galleries = get_post_galleries( get_the_ID(), false );
 714          if ( isset( $galleries[0]['ids'] ) ) {
 715              $images = explode( ',', $galleries[0]['ids'] );
 716          }
 717      } else {
 718          $pattern = get_shortcode_regex();
 719          preg_match( "/$pattern/s", get_the_content(), $match );
 720          $atts = shortcode_parse_atts( $match[3] );
 721          if ( isset( $atts['ids'] ) ) {
 722              $images = explode( ',', $atts['ids'] );
 723          }
 724      }
 725  
 726      if ( ! $images ) {
 727          $images = get_posts(
 728              array(
 729                  'fields'         => 'ids',
 730                  'numberposts'    => 999,
 731                  'order'          => 'ASC',
 732                  'orderby'        => 'menu_order',
 733                  'post_mime_type' => 'image',
 734                  'post_parent'    => get_the_ID(),
 735                  'post_type'      => 'attachment',
 736              )
 737          );
 738      }
 739  
 740      return $images;
 741  }
 742  
 743  /**
 744   * Modifies tag cloud widget arguments to display all tags in the same font size
 745   * and use list format for better accessibility.
 746   *
 747   * @since Twenty Ten 2.4
 748   *
 749   * @param array $args Arguments for tag cloud widget.
 750   * @return array The filtered arguments for tag cloud widget.
 751   */
 752  function twentyten_widget_tag_cloud_args( $args ) {
 753      $args['largest']  = 22;
 754      $args['smallest'] = 8;
 755      $args['unit']     = 'pt';
 756      $args['format']   = 'list';
 757  
 758      return $args;
 759  }
 760  add_filter( 'widget_tag_cloud_args', 'twentyten_widget_tag_cloud_args' );
 761  
 762  /**
 763   * Enqueue scripts and styles for front end.
 764   *
 765   * @since Twenty Ten 2.6
 766   */
 767  function twentyten_scripts_styles() {
 768      // Theme block stylesheet.
 769      wp_enqueue_style( 'twentyten-block-style', get_template_directory_uri() . '/blocks.css', array(), '20240703' );
 770  }
 771  add_action( 'wp_enqueue_scripts', 'twentyten_scripts_styles' );
 772  
 773  /**
 774   * Enqueue styles for the block-based editor.
 775   *
 776   * @since Twenty Ten 2.6
 777   */
 778  function twentyten_block_editor_styles() {
 779      // Block styles.
 780      wp_enqueue_style( 'twentyten-block-editor-style', get_template_directory_uri() . '/editor-blocks.css', array(), '20240703' );
 781  }
 782  add_action( 'enqueue_block_editor_assets', 'twentyten_block_editor_styles' );
 783  
 784  /**
 785   * Register block patterns and pattern categories.
 786   *
 787   * @since Twenty Ten 4.3
 788   */
 789  function twentyten_register_block_patterns() {
 790      require get_template_directory() . '/block-patterns.php';
 791  }
 792  
 793  add_action( 'init', 'twentyten_register_block_patterns' );
 794  
 795  if ( ! function_exists( 'wp_body_open' ) ) :
 796      /**
 797       * Fire the wp_body_open action.
 798       *
 799       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 800       *
 801       * @since Twenty Ten 2.9
 802       */
 803  	function wp_body_open() {
 804          /**
 805           * Triggered after the opening <body> tag.
 806           *
 807           * @since Twenty Ten 2.9
 808           */
 809          do_action( 'wp_body_open' );
 810      }
 811  endif;


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref