[ 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   * @return string The gallery style filter, with the styles themselves removed.
 433   */
 434  function twentyten_remove_gallery_css( $css ) {
 435      return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
 436  }
 437  // Backward compatibility with WordPress 3.0.
 438  if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) {
 439      add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
 440  }
 441  
 442  if ( ! function_exists( 'twentyten_comment' ) ) :
 443      /**
 444       * Template for comments and pingbacks.
 445       *
 446       * To override this walker in a child theme without modifying the comments template
 447       * simply create your own twentyten_comment(), and that function will be used instead.
 448       *
 449       * Used as a callback by wp_list_comments() for displaying the comments.
 450       *
 451       * @since Twenty Ten 1.0
 452       *
 453       * @param WP_Comment $comment The comment object.
 454       * @param array      $args    An array of arguments. @see get_comment_reply_link()
 455       * @param int        $depth   The depth of the comment.
 456       */
 457  	function twentyten_comment( $comment, $args, $depth ) {
 458          $GLOBALS['comment'] = $comment;
 459          switch ( $comment->comment_type ) :
 460              case '':
 461              case 'comment':
 462                  ?>
 463          <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 464          <div id="comment-<?php comment_ID(); ?>">
 465              <div class="comment-author vcard">
 466                  <?php echo get_avatar( $comment, 40 ); ?>
 467                  <?php
 468                  /* translators: %s: Author display name. */
 469                  printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) );
 470                  ?>
 471              </div><!-- .comment-author .vcard -->
 472  
 473                  <?php
 474                  $commenter = wp_get_current_commenter();
 475                  if ( $commenter['comment_author_email'] ) {
 476                      $moderation_note = __( 'Your comment is awaiting moderation.', 'twentyten' );
 477                  } else {
 478                      $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentyten' );
 479                  }
 480                  ?>
 481  
 482                  <?php if ( '0' === $comment->comment_approved ) : ?>
 483              <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
 484              <br />
 485              <?php endif; ?>
 486  
 487              <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
 488                  <?php
 489                      /* translators: 1: Date, 2: Time. */
 490                      printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() );
 491                  ?>
 492                      </a>
 493                      <?php
 494                      edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
 495                      ?>
 496                  </div><!-- .comment-meta .commentmetadata -->
 497  
 498                  <div class="comment-body"><?php comment_text(); ?></div>
 499  
 500                  <div class="reply">
 501                  <?php
 502                  comment_reply_link(
 503                      array_merge(
 504                          $args,
 505                          array(
 506                              'depth'     => $depth,
 507                              'max_depth' => $args['max_depth'],
 508                          )
 509                      )
 510                  );
 511                  ?>
 512                  </div><!-- .reply -->
 513              </div><!-- #comment-##  -->
 514  
 515                  <?php
 516                  break;
 517              case 'pingback':
 518              case 'trackback':
 519                  ?>
 520          <li class="post pingback">
 521          <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
 522                  <?php
 523                  break;
 524          endswitch;
 525      }
 526  endif;
 527  
 528  /**
 529   * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
 530   *
 531   * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
 532   * function tied to the init hook.
 533   *
 534   * @since Twenty Ten 1.0
 535   *
 536   * @uses register_sidebar()
 537   */
 538  function twentyten_widgets_init() {
 539      // Area 1, located at the top of the sidebar.
 540      register_sidebar(
 541          array(
 542              'name'          => __( 'Primary Widget Area', 'twentyten' ),
 543              'id'            => 'primary-widget-area',
 544              'description'   => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ),
 545              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 546              'after_widget'  => '</li>',
 547              'before_title'  => '<h3 class="widget-title">',
 548              'after_title'   => '</h3>',
 549          )
 550      );
 551  
 552      // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
 553      register_sidebar(
 554          array(
 555              'name'          => __( 'Secondary Widget Area', 'twentyten' ),
 556              'id'            => 'secondary-widget-area',
 557              'description'   => __( 'An optional secondary widget area, displays below the primary widget area in your sidebar.', 'twentyten' ),
 558              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 559              'after_widget'  => '</li>',
 560              'before_title'  => '<h3 class="widget-title">',
 561              'after_title'   => '</h3>',
 562          )
 563      );
 564  
 565      // Area 3, located in the footer. Empty by default.
 566      register_sidebar(
 567          array(
 568              'name'          => __( 'First Footer Widget Area', 'twentyten' ),
 569              'id'            => 'first-footer-widget-area',
 570              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 571              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 572              'after_widget'  => '</li>',
 573              'before_title'  => '<h3 class="widget-title">',
 574              'after_title'   => '</h3>',
 575          )
 576      );
 577  
 578      // Area 4, located in the footer. Empty by default.
 579      register_sidebar(
 580          array(
 581              'name'          => __( 'Second Footer Widget Area', 'twentyten' ),
 582              'id'            => 'second-footer-widget-area',
 583              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 584              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 585              'after_widget'  => '</li>',
 586              'before_title'  => '<h3 class="widget-title">',
 587              'after_title'   => '</h3>',
 588          )
 589      );
 590  
 591      // Area 5, located in the footer. Empty by default.
 592      register_sidebar(
 593          array(
 594              'name'          => __( 'Third Footer Widget Area', 'twentyten' ),
 595              'id'            => 'third-footer-widget-area',
 596              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 597              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 598              'after_widget'  => '</li>',
 599              'before_title'  => '<h3 class="widget-title">',
 600              'after_title'   => '</h3>',
 601          )
 602      );
 603  
 604      // Area 6, located in the footer. Empty by default.
 605      register_sidebar(
 606          array(
 607              'name'          => __( 'Fourth Footer Widget Area', 'twentyten' ),
 608              'id'            => 'fourth-footer-widget-area',
 609              'description'   => __( 'An optional widget area for your site footer.', 'twentyten' ),
 610              'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
 611              'after_widget'  => '</li>',
 612              'before_title'  => '<h3 class="widget-title">',
 613              'after_title'   => '</h3>',
 614          )
 615      );
 616  }
 617  /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
 618  add_action( 'widgets_init', 'twentyten_widgets_init' );
 619  
 620  /**
 621   * Remove the default styles that are packaged with the Recent Comments widget.
 622   *
 623   * To override this in a child theme, remove the filter and optionally add your own
 624   * function tied to the widgets_init action hook.
 625   *
 626   * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
 627   * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
 628   * but they won't have any effect on the widget in default Twenty Ten styling.
 629   *
 630   * @since Twenty Ten 1.0
 631   */
 632  function twentyten_remove_recent_comments_style() {
 633      add_filter( 'show_recent_comments_widget_style', '__return_false' );
 634  }
 635  add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
 636  
 637  if ( ! function_exists( 'twentyten_posted_on' ) ) :
 638      /**
 639       * Print HTML with meta information for the current post-date/time and author.
 640       *
 641       * @since Twenty Ten 1.0
 642       */
 643  	function twentyten_posted_on() {
 644          printf(
 645              /* translators: 1: CSS classes, 2: Date, 3: Author display name. */
 646              __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
 647              'meta-prep meta-prep-author',
 648              sprintf(
 649                  '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
 650                  esc_url( get_permalink() ),
 651                  esc_attr( get_the_time() ),
 652                  get_the_date()
 653              ),
 654              sprintf(
 655                  '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
 656                  esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 657                  /* translators: %s: Author display name. */
 658                  esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
 659                  get_the_author()
 660              )
 661          );
 662      }
 663  endif;
 664  
 665  if ( ! function_exists( 'twentyten_posted_in' ) ) :
 666      /**
 667       * Print HTML with meta information for the current post (category, tags and permalink).
 668       *
 669       * @since Twenty Ten 1.0
 670       */
 671  	function twentyten_posted_in() {
 672          // Retrieves tag list of current post, separated by commas.
 673          $tags_list = get_the_tag_list( '', ', ' );
 674  
 675          if ( $tags_list && ! is_wp_error( $tags_list ) ) {
 676              /* translators: 1: Category name, 2: Tag name, 3: Post permalink, 4: Post title. */
 677              $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' );
 678          } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
 679              /* translators: 1: Category name, 3: Post permalink, 4: Post title. */
 680              $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' );
 681          } else {
 682              /* translators: 3: Post permalink, 4: Post title. */
 683              $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
 684          }
 685  
 686          // Prints the string, replacing the placeholders.
 687          printf(
 688              $posted_in,
 689              get_the_category_list( ', ' ),
 690              $tags_list,
 691              esc_url( get_permalink() ),
 692              the_title_attribute( 'echo=0' )
 693          );
 694      }
 695  endif;
 696  
 697  /**
 698   * Retrieve the IDs for images in a gallery.
 699   *
 700   * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
 701   *                            then as last option uses a get_posts() call.
 702   *
 703   * @since Twenty Ten 1.6.
 704   *
 705   * @return array List of image IDs from the post gallery.
 706   */
 707  function twentyten_get_gallery_images() {
 708      $images = array();
 709  
 710      if ( function_exists( 'get_post_galleries' ) ) {
 711          $galleries = get_post_galleries( get_the_ID(), false );
 712          if ( isset( $galleries[0]['ids'] ) ) {
 713              $images = explode( ',', $galleries[0]['ids'] );
 714          }
 715      } else {
 716          $pattern = get_shortcode_regex();
 717          preg_match( "/$pattern/s", get_the_content(), $match );
 718          $atts = shortcode_parse_atts( $match[3] );
 719          if ( isset( $atts['ids'] ) ) {
 720              $images = explode( ',', $atts['ids'] );
 721          }
 722      }
 723  
 724      if ( ! $images ) {
 725          $images = get_posts(
 726              array(
 727                  'fields'         => 'ids',
 728                  'numberposts'    => 999,
 729                  'order'          => 'ASC',
 730                  'orderby'        => 'menu_order',
 731                  'post_mime_type' => 'image',
 732                  'post_parent'    => get_the_ID(),
 733                  'post_type'      => 'attachment',
 734              )
 735          );
 736      }
 737  
 738      return $images;
 739  }
 740  
 741  /**
 742   * Modifies tag cloud widget arguments to display all tags in the same font size
 743   * and use list format for better accessibility.
 744   *
 745   * @since Twenty Ten 2.4
 746   *
 747   * @param array $args Arguments for tag cloud widget.
 748   * @return array The filtered arguments for tag cloud widget.
 749   */
 750  function twentyten_widget_tag_cloud_args( $args ) {
 751      $args['largest']  = 22;
 752      $args['smallest'] = 8;
 753      $args['unit']     = 'pt';
 754      $args['format']   = 'list';
 755  
 756      return $args;
 757  }
 758  add_filter( 'widget_tag_cloud_args', 'twentyten_widget_tag_cloud_args' );
 759  
 760  /**
 761   * Enqueue scripts and styles for front end.
 762   *
 763   * @since Twenty Ten 2.6
 764   */
 765  function twentyten_scripts_styles() {
 766      // Theme block stylesheet.
 767      wp_enqueue_style( 'twentyten-block-style', get_template_directory_uri() . '/blocks.css', array(), '20230627' );
 768  }
 769  add_action( 'wp_enqueue_scripts', 'twentyten_scripts_styles' );
 770  
 771  /**
 772   * Enqueue styles for the block-based editor.
 773   *
 774   * @since Twenty Ten 2.6
 775   */
 776  function twentyten_block_editor_styles() {
 777      // Block styles.
 778      wp_enqueue_style( 'twentyten-block-editor-style', get_template_directory_uri() . '/editor-blocks.css', array(), '20230627' );
 779  }
 780  add_action( 'enqueue_block_editor_assets', 'twentyten_block_editor_styles' );
 781  
 782  // Block Patterns.
 783  require get_template_directory() . '/block-patterns.php';
 784  
 785  if ( ! function_exists( 'wp_body_open' ) ) :
 786      /**
 787       * Fire the wp_body_open action.
 788       *
 789       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 790       *
 791       * @since Twenty Ten 2.9
 792       */
 793  	function wp_body_open() {
 794          /**
 795           * Triggered after the opening <body> tag.
 796           *
 797           * @since Twenty Ten 2.9
 798           */
 799          do_action( 'wp_body_open' );
 800      }
 801  endif;


Generated : Mon Mar 18 08:20:01 2024 Cross-referenced by PHPXref