[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Twenty Eleven 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, twentyeleven_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', 'twentyeleven_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_Eleven
  40   * @since Twenty Eleven 1.0
  41   */
  42  
  43  // Set the content width based on the theme's design and stylesheet.
  44  if ( ! isset( $content_width ) ) {
  45      $content_width = 584;
  46  }
  47  
  48  /*
  49   * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run.
  50   */
  51  add_action( 'after_setup_theme', 'twentyeleven_setup' );
  52  
  53  if ( ! function_exists( 'twentyeleven_setup' ) ) :
  54      /**
  55       * Set up theme defaults and registers support for various WordPress features.
  56       *
  57       * Note that this function is hooked into the after_setup_theme hook, which runs
  58       * before the init hook. The init hook is too late for some features, such as indicating
  59       * support post thumbnails.
  60       *
  61       * To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's
  62       * functions.php file.
  63       *
  64       * @uses load_theme_textdomain()    For translation/localization support.
  65       * @uses add_editor_style()         To style the visual editor.
  66       * @uses add_theme_support()        To add support for post thumbnails, automatic feed links, custom headers
  67       *                                  and backgrounds, and post formats.
  68       * @uses register_nav_menus()       To add support for navigation menus.
  69       * @uses register_default_headers() To register the default custom header images provided with the theme.
  70       * @uses set_post_thumbnail_size()  To set a custom post thumbnail size.
  71       *
  72       * @since Twenty Eleven 1.0
  73       */
  74  	function twentyeleven_setup() {
  75  
  76          /*
  77           * Make Twenty Eleven available for translation.
  78           * Translations can be added to the /languages/ directory.
  79           * If you're building a theme based on Twenty Eleven, use
  80           * a find and replace to change 'twentyeleven' to the name
  81           * of your theme in all the template files.
  82           *
  83           * Manual loading of text domain is not required after the introduction of
  84           * just in time translation loading in WordPress version 4.6.
  85           *
  86           * @ticket 58318
  87           */
  88          if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) {
  89              load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' );
  90          }
  91  
  92          // This theme styles the visual editor with editor-style.css to match the theme style.
  93          add_editor_style();
  94  
  95          // Load regular editor styles into the new block-based editor.
  96          add_theme_support( 'editor-styles' );
  97  
  98          // Load default block styles.
  99          add_theme_support( 'wp-block-styles' );
 100  
 101          // Add support for responsive embeds.
 102          add_theme_support( 'responsive-embeds' );
 103  
 104          // Add support for custom color scheme.
 105          add_theme_support(
 106              'editor-color-palette',
 107              array(
 108                  array(
 109                      'name'  => __( 'Blue', 'twentyeleven' ),
 110                      'slug'  => 'blue',
 111                      'color' => '#1982d1',
 112                  ),
 113                  array(
 114                      'name'  => __( 'Black', 'twentyeleven' ),
 115                      'slug'  => 'black',
 116                      'color' => '#000',
 117                  ),
 118                  array(
 119                      'name'  => __( 'Dark Gray', 'twentyeleven' ),
 120                      'slug'  => 'dark-gray',
 121                      'color' => '#373737',
 122                  ),
 123                  array(
 124                      'name'  => __( 'Medium Gray', 'twentyeleven' ),
 125                      'slug'  => 'medium-gray',
 126                      'color' => '#666',
 127                  ),
 128                  array(
 129                      'name'  => __( 'Light Gray', 'twentyeleven' ),
 130                      'slug'  => 'light-gray',
 131                      'color' => '#e2e2e2',
 132                  ),
 133                  array(
 134                      'name'  => __( 'White', 'twentyeleven' ),
 135                      'slug'  => 'white',
 136                      'color' => '#fff',
 137                  ),
 138              )
 139          );
 140  
 141          // Load up our theme options page and related code.
 142          require get_template_directory() . '/inc/theme-options.php';
 143  
 144          // Grab Twenty Eleven's Ephemera widget.
 145          require get_template_directory() . '/inc/widgets.php';
 146  
 147          // Load block patterns.
 148          require get_template_directory() . '/inc/block-patterns.php';
 149  
 150          // Add default posts and comments RSS feed links to <head>.
 151          add_theme_support( 'automatic-feed-links' );
 152  
 153          // This theme uses wp_nav_menu() in one location.
 154          register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );
 155  
 156          // Add support for a variety of post formats.
 157          add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
 158  
 159          $theme_options = twentyeleven_get_theme_options();
 160          if ( 'dark' === $theme_options['color_scheme'] ) {
 161              $default_background_color = '1d1d1d';
 162          } else {
 163              $default_background_color = 'e2e2e2';
 164          }
 165  
 166          // Add support for custom backgrounds.
 167          add_theme_support(
 168              'custom-background',
 169              array(
 170                  /*
 171                  * Let WordPress know what our default background color is.
 172                  * This is dependent on our current color scheme.
 173                  */
 174                  'default-color' => $default_background_color,
 175              )
 176          );
 177  
 178          // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images.
 179          add_theme_support( 'post-thumbnails' );
 180  
 181          // Add support for custom headers.
 182          $custom_header_support = array(
 183              // The default header text color.
 184              'default-text-color'     => '000',
 185              // The height and width of our custom header.
 186              /**
 187               * Filters the Twenty Eleven default header image width.
 188               *
 189               * @since Twenty Eleven 1.0
 190               *
 191               * @param int The default header image width in pixels. Default 1000.
 192               */
 193              'width'                  => apply_filters( 'twentyeleven_header_image_width', 1000 ),
 194              /**
 195               * Filters the Twenty Eleven default header image height.
 196               *
 197               * @since Twenty Eleven 1.0
 198               *
 199               * @param int The default header image height in pixels. Default 288.
 200               */
 201              'height'                 => apply_filters( 'twentyeleven_header_image_height', 288 ),
 202              // Support flexible heights.
 203              'flex-height'            => true,
 204              // Random image rotation by default.
 205              'random-default'         => true,
 206              // Callback for styling the header.
 207              'wp-head-callback'       => 'twentyeleven_header_style',
 208              // Callback for styling the header preview in the admin.
 209              'admin-head-callback'    => 'twentyeleven_admin_header_style',
 210              // Callback used to display the header preview in the admin.
 211              'admin-preview-callback' => 'twentyeleven_admin_header_image',
 212          );
 213  
 214          add_theme_support( 'custom-header', $custom_header_support );
 215  
 216          if ( ! function_exists( 'get_custom_header' ) ) {
 217              // This is all for compatibility with versions of WordPress prior to 3.4.
 218              define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] );
 219              define( 'HEADER_IMAGE', '' );
 220              define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
 221              define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
 222              add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] );
 223              add_custom_background();
 224          }
 225  
 226          /*
 227           * We'll be using post thumbnails for custom header images on posts and pages.
 228           * We want them to be the size of the header image that we just defined.
 229           * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
 230           */
 231          set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
 232  
 233          /*
 234           * Add Twenty Eleven's custom image sizes.
 235           * Used for large feature (header) images.
 236           */
 237          add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
 238          // Used for featured posts if a large-feature doesn't exist.
 239          add_image_size( 'small-feature', 500, 300 );
 240  
 241          // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
 242          register_default_headers(
 243              array(
 244                  'wheel'      => array(
 245                      'url'           => '%s/images/headers/wheel.jpg',
 246                      'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',
 247                      /* translators: Header image description. */
 248                      'description'   => __( 'Wheel', 'twentyeleven' ),
 249                  ),
 250                  'shore'      => array(
 251                      'url'           => '%s/images/headers/shore.jpg',
 252                      'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',
 253                      /* translators: Header image description. */
 254                      'description'   => __( 'Shore', 'twentyeleven' ),
 255                  ),
 256                  'trolley'    => array(
 257                      'url'           => '%s/images/headers/trolley.jpg',
 258                      'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',
 259                      /* translators: Header image description. */
 260                      'description'   => __( 'Trolley', 'twentyeleven' ),
 261                  ),
 262                  'pine-cone'  => array(
 263                      'url'           => '%s/images/headers/pine-cone.jpg',
 264                      'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',
 265                      /* translators: Header image description. */
 266                      'description'   => __( 'Pine Cone', 'twentyeleven' ),
 267                  ),
 268                  'chessboard' => array(
 269                      'url'           => '%s/images/headers/chessboard.jpg',
 270                      'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',
 271                      /* translators: Header image description. */
 272                      'description'   => __( 'Chessboard', 'twentyeleven' ),
 273                  ),
 274                  'lanterns'   => array(
 275                      'url'           => '%s/images/headers/lanterns.jpg',
 276                      'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',
 277                      /* translators: Header image description. */
 278                      'description'   => __( 'Lanterns', 'twentyeleven' ),
 279                  ),
 280                  'willow'     => array(
 281                      'url'           => '%s/images/headers/willow.jpg',
 282                      'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',
 283                      /* translators: Header image description. */
 284                      'description'   => __( 'Willow', 'twentyeleven' ),
 285                  ),
 286                  'hanoi'      => array(
 287                      'url'           => '%s/images/headers/hanoi.jpg',
 288                      'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',
 289                      /* translators: Header image description. */
 290                      'description'   => __( 'Hanoi Plant', 'twentyeleven' ),
 291                  ),
 292              )
 293          );
 294  
 295          // Indicate widget sidebars can use selective refresh in the Customizer.
 296          add_theme_support( 'customize-selective-refresh-widgets' );
 297      }
 298  endif; // twentyeleven_setup()
 299  
 300  /**
 301   * Enqueue scripts and styles for front end.
 302   *
 303   * @since Twenty Eleven 2.9
 304   */
 305  function twentyeleven_scripts_styles() {
 306      // Theme block stylesheet.
 307      wp_enqueue_style( 'twentyeleven-block-style', get_template_directory_uri() . '/blocks.css', array(), '20240703' );
 308  }
 309  add_action( 'wp_enqueue_scripts', 'twentyeleven_scripts_styles' );
 310  
 311  /**
 312   * Enqueue styles for the block-based editor.
 313   *
 314   * @since Twenty Eleven 2.9
 315   */
 316  function twentyeleven_block_editor_styles() {
 317      // Block styles.
 318      wp_enqueue_style( 'twentyeleven-block-editor-style', get_template_directory_uri() . '/editor-blocks.css', array(), '20240716' );
 319  }
 320  add_action( 'enqueue_block_editor_assets', 'twentyeleven_block_editor_styles' );
 321  
 322  if ( ! function_exists( 'twentyeleven_header_style' ) ) :
 323      /**
 324       * Styles the header image and text displayed on the blog.
 325       *
 326       * @since Twenty Eleven 1.0
 327       */
 328  	function twentyeleven_header_style() {
 329          $text_color = get_header_textcolor();
 330  
 331          // If no custom options for text are set, let's bail.
 332          if ( HEADER_TEXTCOLOR === $text_color ) {
 333              return;
 334          }
 335  
 336          // If we get this far, we have custom styles. Let's do this.
 337          ?>
 338          <style type="text/css" id="twentyeleven-header-css">
 339          <?php
 340          // Has the text been hidden?
 341          if ( 'blank' === $text_color ) :
 342              ?>
 343          #site-title,
 344          #site-description {
 345              position: absolute;
 346              clip-path: inset(50%);
 347          }
 348              <?php
 349              // If the user has set a custom color for the text, use that.
 350          else :
 351              ?>
 352          #site-title a,
 353          #site-description {
 354              color: #<?php echo $text_color; ?>;
 355          }
 356      <?php endif; ?>
 357      </style>
 358          <?php
 359      }
 360  endif; // twentyeleven_header_style()
 361  
 362  if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) :
 363      /**
 364       * Styles the header image displayed on the Appearance > Header admin panel.
 365       *
 366       * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
 367       *
 368       * @since Twenty Eleven 1.0
 369       */
 370  	function twentyeleven_admin_header_style() {
 371          ?>
 372      <style type="text/css" id="twentyeleven-admin-header-css">
 373      .appearance_page_custom-header #headimg {
 374          border: none;
 375      }
 376      #headimg h1,
 377      #desc {
 378          font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
 379      }
 380      #headimg h1 {
 381          margin: 0;
 382      }
 383      #headimg h1 a {
 384          font-size: 32px;
 385          line-height: 36px;
 386          text-decoration: none;
 387      }
 388      #desc {
 389          font-size: 14px;
 390          line-height: 23px;
 391          padding: 0 0 3em;
 392      }
 393          <?php
 394          // If the user has set a custom color for the text, use that.
 395          if ( get_header_textcolor() !== HEADER_TEXTCOLOR ) :
 396              ?>
 397      #site-title a,
 398      #site-description {
 399          color: #<?php echo get_header_textcolor(); ?>;
 400      }
 401      <?php endif; ?>
 402      #headimg img {
 403          max-width: 1000px;
 404          height: auto;
 405          width: 100%;
 406      }
 407      </style>
 408          <?php
 409      }
 410  endif; // twentyeleven_admin_header_style()
 411  
 412  if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) :
 413      /**
 414       * Custom header image markup displayed on the Appearance > Header admin panel.
 415       *
 416       * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
 417       *
 418       * @since Twenty Eleven 1.0
 419       */
 420  	function twentyeleven_admin_header_image() {
 421  
 422          ?>
 423          <div id="headimg">
 424              <?php
 425              $color = get_header_textcolor();
 426              $image = get_header_image();
 427              $style = 'display: none;';
 428              if ( $color && 'blank' !== $color ) {
 429                  $style = 'color: #' . $color . ';';
 430              }
 431              ?>
 432              <h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr( $style ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
 433          <div id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></div>
 434          <?php if ( $image ) : ?>
 435              <img src="<?php echo esc_url( $image ); ?>" alt="" />
 436          <?php endif; ?>
 437          </div>
 438          <?php
 439      }
 440  endif; // twentyeleven_admin_header_image()
 441  
 442  
 443  if ( ! function_exists( 'twentyeleven_header_image' ) ) :
 444      /**
 445       * Custom header image markup displayed.
 446       *
 447       * @since Twenty Eleven 4.5
 448       */
 449  	function twentyeleven_header_image() {
 450          $attrs = array(
 451              'alt' => get_bloginfo( 'name', 'display' ),
 452          );
 453  
 454          // Compatibility with versions of WordPress prior to 3.4.
 455          if ( function_exists( 'get_custom_header' ) ) {
 456              $custom_header   = get_custom_header();
 457              $attrs['width']  = $custom_header->width;
 458              $attrs['height'] = $custom_header->height;
 459          } else {
 460              $attrs['width']  = HEADER_IMAGE_WIDTH;
 461              $attrs['height'] = HEADER_IMAGE_HEIGHT;
 462          }
 463  
 464          if ( function_exists( 'the_header_image_tag' ) ) {
 465              the_header_image_tag( $attrs );
 466              return;
 467          }
 468  
 469          ?>
 470          <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'] ); ?>" />
 471          <?php
 472      }
 473  endif; // twentyeleven_header_image()
 474  
 475  /**
 476   * Set the post excerpt length to 40 words.
 477   *
 478   * To override this length in a child theme, remove
 479   * the filter and add your own function tied to
 480   * the excerpt_length filter hook.
 481   *
 482   * @since Twenty Eleven 1.0
 483   *
 484   * @param int $length The number of excerpt characters.
 485   * @return int The filtered number of characters.
 486   */
 487  function twentyeleven_excerpt_length( $length ) {
 488      return 40;
 489  }
 490  add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
 491  
 492  if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) :
 493      /**
 494       * Return a "Continue Reading" link for excerpts
 495       *
 496       * @since Twenty Eleven 1.0
 497       *
 498       * @return string The "Continue Reading" HTML link.
 499       */
 500  	function twentyeleven_continue_reading_link() {
 501          return ' <a href="' . esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) . '</a>';
 502      }
 503  endif; // twentyeleven_continue_reading_link()
 504  
 505  /**
 506   * Replace "[...]" in the Read More link with an ellipsis.
 507   *
 508   * The "[...]" is appended to automatically generated excerpts.
 509   *
 510   * To override this in a child theme, remove the filter and add your own
 511   * function tied to the excerpt_more filter hook.
 512   *
 513   * @since Twenty Eleven 1.0
 514   *
 515   * @param string $more The Read More text.
 516   * @return string The filtered Read More text.
 517   */
 518  function twentyeleven_auto_excerpt_more( $more ) {
 519      if ( ! is_admin() ) {
 520          return ' &hellip;' . twentyeleven_continue_reading_link();
 521      }
 522      return $more;
 523  }
 524  add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
 525  
 526  /**
 527   * Add a pretty "Continue Reading" link to custom post excerpts.
 528   *
 529   * To override this link in a child theme, remove the filter and add your own
 530   * function tied to the get_the_excerpt filter hook.
 531   *
 532   * @since Twenty Eleven 1.0
 533   *
 534   * @param string $output The "Continue Reading" link.
 535   * @return string The filtered "Continue Reading" link.
 536   */
 537  function twentyeleven_custom_excerpt_more( $output ) {
 538      if ( has_excerpt() && ! is_attachment() && ! is_admin() ) {
 539          $output .= twentyeleven_continue_reading_link();
 540      }
 541      return $output;
 542  }
 543  add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
 544  
 545  /**
 546   * Show a home link for the wp_nav_menu() fallback, wp_page_menu().
 547   *
 548   * @since Twenty Eleven 1.0
 549   *
 550   * @param array $args The page menu arguments. @see wp_page_menu()
 551   * @return array The filtered page menu arguments.
 552   */
 553  function twentyeleven_page_menu_args( $args ) {
 554      if ( ! isset( $args['show_home'] ) ) {
 555          $args['show_home'] = true;
 556      }
 557      return $args;
 558  }
 559  add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
 560  
 561  /**
 562   * Register sidebars and widgetized areas.
 563   *
 564   * Also register the default Ephemera widget.
 565   *
 566   * @since Twenty Eleven 1.0
 567   */
 568  function twentyeleven_widgets_init() {
 569  
 570      register_widget( 'Twenty_Eleven_Ephemera_Widget' );
 571  
 572      register_sidebar(
 573          array(
 574              'name'          => __( 'Main Sidebar', 'twentyeleven' ),
 575              'id'            => 'sidebar-1',
 576              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 577              'after_widget'  => '</aside>',
 578              'before_title'  => '<h3 class="widget-title">',
 579              'after_title'   => '</h3>',
 580          )
 581      );
 582  
 583      register_sidebar(
 584          array(
 585              'name'          => __( 'Showcase Sidebar', 'twentyeleven' ),
 586              'id'            => 'sidebar-2',
 587              'description'   => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ),
 588              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 589              'after_widget'  => '</aside>',
 590              'before_title'  => '<h3 class="widget-title">',
 591              'after_title'   => '</h3>',
 592          )
 593      );
 594  
 595      register_sidebar(
 596          array(
 597              'name'          => __( 'Footer Area One', 'twentyeleven' ),
 598              'id'            => 'sidebar-3',
 599              'description'   => __( 'An optional widget area for your site footer', 'twentyeleven' ),
 600              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 601              'after_widget'  => '</aside>',
 602              'before_title'  => '<h3 class="widget-title">',
 603              'after_title'   => '</h3>',
 604          )
 605      );
 606  
 607      register_sidebar(
 608          array(
 609              'name'          => __( 'Footer Area Two', 'twentyeleven' ),
 610              'id'            => 'sidebar-4',
 611              'description'   => __( 'An optional widget area for your site footer', 'twentyeleven' ),
 612              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 613              'after_widget'  => '</aside>',
 614              'before_title'  => '<h3 class="widget-title">',
 615              'after_title'   => '</h3>',
 616          )
 617      );
 618  
 619      register_sidebar(
 620          array(
 621              'name'          => __( 'Footer Area Three', 'twentyeleven' ),
 622              'id'            => 'sidebar-5',
 623              'description'   => __( 'An optional widget area for your site footer', 'twentyeleven' ),
 624              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 625              'after_widget'  => '</aside>',
 626              'before_title'  => '<h3 class="widget-title">',
 627              'after_title'   => '</h3>',
 628          )
 629      );
 630  }
 631  add_action( 'widgets_init', 'twentyeleven_widgets_init' );
 632  
 633  if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
 634      /**
 635       * Display navigation to next/previous pages when applicable.
 636       *
 637       * @since Twenty Eleven 1.0
 638       *
 639       * @param string $html_id The HTML id attribute.
 640       */
 641  	function twentyeleven_content_nav( $html_id ) {
 642          global $wp_query;
 643  
 644          if ( $wp_query->max_num_pages > 1 ) :
 645              ?>
 646              <nav id="<?php echo esc_attr( $html_id ); ?>">
 647                  <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
 648                  <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
 649                  <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>
 650              </nav><!-- #nav-above -->
 651              <?php
 652      endif;
 653      }
 654  endif; // twentyeleven_content_nav()
 655  
 656  /**
 657   * Return the first link from the post content. If none found, the
 658   * post permalink is used as a fallback.
 659   *
 660   * @since Twenty Eleven 1.0
 661   *
 662   * @uses get_url_in_content() to get the first URL from the post content.
 663   *
 664   * @return string The first link.
 665   */
 666  function twentyeleven_get_first_url() {
 667      $content = get_the_content();
 668      $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false;
 669  
 670      if ( ! $has_url ) {
 671          $has_url = twentyeleven_url_grabber();
 672      }
 673  
 674      /** This filter is documented in wp-includes/link-template.php */
 675      return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
 676  }
 677  
 678  /**
 679   * Return the URL for the first link found in the post content.
 680   *
 681   * @since Twenty Eleven 1.0
 682   *
 683   * @return string|bool URL or false when no link is present.
 684   */
 685  function twentyeleven_url_grabber() {
 686      if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) {
 687          return false;
 688      }
 689  
 690      return esc_url_raw( $matches[1] );
 691  }
 692  
 693  /**
 694   * Count the number of footer sidebars to enable dynamic classes for the footer.
 695   *
 696   * @since Twenty Eleven 1.0
 697   */
 698  function twentyeleven_footer_sidebar_class() {
 699      $count = 0;
 700  
 701      if ( is_active_sidebar( 'sidebar-3' ) ) {
 702          ++$count;
 703      }
 704  
 705      if ( is_active_sidebar( 'sidebar-4' ) ) {
 706          ++$count;
 707      }
 708  
 709      if ( is_active_sidebar( 'sidebar-5' ) ) {
 710          ++$count;
 711      }
 712  
 713      $class = '';
 714  
 715      switch ( $count ) {
 716          case '1':
 717              $class = 'one';
 718              break;
 719          case '2':
 720              $class = 'two';
 721              break;
 722          case '3':
 723              $class = 'three';
 724              break;
 725      }
 726  
 727      if ( $class ) {
 728          echo 'class="' . esc_attr( $class ) . '"';
 729      }
 730  }
 731  
 732  if ( ! function_exists( 'twentyeleven_comment' ) ) :
 733      /**
 734       * Template for comments and pingbacks.
 735       *
 736       * To override this walker in a child theme without modifying the comments template
 737       * simply create your own twentyeleven_comment(), and that function will be used instead.
 738       *
 739       * Used as a callback by wp_list_comments() for displaying the comments.
 740       *
 741       * @since Twenty Eleven 1.0
 742       *
 743       * @param WP_Comment $comment The comment object.
 744       * @param array      $args    An array of comment arguments. @see get_comment_reply_link()
 745       * @param int        $depth   The depth of the comment.
 746       */
 747  	function twentyeleven_comment( $comment, $args, $depth ) {
 748          $GLOBALS['comment'] = $comment;
 749          switch ( $comment->comment_type ) :
 750              case 'pingback':
 751              case 'trackback':
 752                  ?>
 753          <li class="post pingback">
 754          <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
 755                  <?php
 756                  break;
 757              default:
 758                  ?>
 759          <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 760          <article id="comment-<?php comment_ID(); ?>" class="comment">
 761              <footer class="comment-meta">
 762                  <div class="comment-author vcard">
 763                      <?php
 764                      $avatar_size = 68;
 765  
 766                      if ( '0' !== $comment->comment_parent ) {
 767                          $avatar_size = 39;
 768                      }
 769  
 770                      echo get_avatar( $comment, $avatar_size );
 771  
 772                      printf(
 773                          /* translators: 1: Comment author, 2: Date and time. */
 774                          __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
 775                          sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
 776                          sprintf(
 777                              '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
 778                              esc_url( get_comment_link( $comment->comment_ID ) ),
 779                              get_comment_time( 'c' ),
 780                              /* translators: 1: Date, 2: Time. */
 781                              sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() )
 782                          )
 783                      );
 784                      ?>
 785  
 786                      <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
 787                      </div><!-- .comment-author .vcard -->
 788  
 789                      <?php
 790                      $commenter = wp_get_current_commenter();
 791                      if ( $commenter['comment_author_email'] ) {
 792                          $moderation_note = __( 'Your comment is awaiting moderation.', 'twentyeleven' );
 793                      } else {
 794                          $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentyeleven' );
 795                      }
 796                      ?>
 797  
 798                      <?php if ( '0' === $comment->comment_approved ) : ?>
 799                      <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
 800                      <br />
 801                      <?php endif; ?>
 802  
 803                  </footer>
 804  
 805                  <div class="comment-content"><?php comment_text(); ?></div>
 806  
 807                  <div class="reply">
 808                      <?php
 809                      comment_reply_link(
 810                          array_merge(
 811                              $args,
 812                              array(
 813                                  'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ),
 814                                  'depth'      => $depth,
 815                                  'max_depth'  => $args['max_depth'],
 816                              )
 817                          )
 818                      );
 819                      ?>
 820                  </div><!-- .reply -->
 821              </article><!-- #comment-## -->
 822  
 823                  <?php
 824                  break;
 825          endswitch;
 826      }
 827  endif; // twentyeleven_comment()
 828  
 829  if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
 830      /**
 831       * Print HTML with meta information for the current post-date/time and author.
 832       *
 833       * Create your own twentyeleven_posted_on to override in a child theme
 834       *
 835       * @since Twenty Eleven 1.0
 836       */
 837  	function twentyeleven_posted_on() {
 838          printf(
 839              /* translators: 1: The permalink, 2: Time, 3: Date and time, 4: Date and time, 5: Author posts, 6: Author post link text, 7: Author display name. */
 840              __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
 841              esc_url( get_permalink() ),
 842              esc_attr( get_the_time() ),
 843              esc_attr( get_the_date( 'c' ) ),
 844              esc_html( get_the_date() ),
 845              esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 846              /* translators: %s: Author display name. */
 847              esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
 848              get_the_author()
 849          );
 850      }
 851  endif;
 852  
 853  /**
 854   * Add two classes to the array of body classes.
 855   *
 856   * The first is if the site has only had one author with published posts.
 857   * The second is if a singular post being displayed
 858   *
 859   * @since Twenty Eleven 1.0
 860   *
 861   * @param array $classes Existing body classes.
 862   * @return array The filtered array of body classes.
 863   */
 864  function twentyeleven_body_classes( $classes ) {
 865  
 866      if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) {
 867          $classes[] = 'single-author';
 868      }
 869  
 870      if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) {
 871          $classes[] = 'singular';
 872      }
 873  
 874      return $classes;
 875  }
 876  add_filter( 'body_class', 'twentyeleven_body_classes' );
 877  
 878  /**
 879   * Retrieve the IDs for images in a gallery.
 880   *
 881   * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
 882   *                            then as last option uses a get_posts() call.
 883   *
 884   * @since Twenty Eleven 1.6
 885   *
 886   * @return array List of image IDs from the post gallery.
 887   */
 888  function twentyeleven_get_gallery_images() {
 889      $images = array();
 890  
 891      if ( function_exists( 'get_post_galleries' ) ) {
 892          $galleries = get_post_galleries( get_the_ID(), false );
 893          if ( isset( $galleries[0]['ids'] ) ) {
 894              $images = explode( ',', $galleries[0]['ids'] );
 895          }
 896      } else {
 897          $pattern = get_shortcode_regex();
 898          preg_match( "/$pattern/s", get_the_content(), $match );
 899          $atts = shortcode_parse_atts( $match[3] );
 900          if ( isset( $atts['ids'] ) ) {
 901              $images = explode( ',', $atts['ids'] );
 902          }
 903      }
 904  
 905      if ( ! $images ) {
 906          $images = get_posts(
 907              array(
 908                  'fields'         => 'ids',
 909                  'numberposts'    => 999,
 910                  'order'          => 'ASC',
 911                  'orderby'        => 'menu_order',
 912                  'post_mime_type' => 'image',
 913                  'post_parent'    => get_the_ID(),
 914                  'post_type'      => 'attachment',
 915              )
 916          );
 917      }
 918  
 919      return $images;
 920  }
 921  
 922  /**
 923   * Modifies tag cloud widget arguments to display all tags in the same font size
 924   * and use list format for better accessibility.
 925   *
 926   * @since Twenty Eleven 2.7
 927   *
 928   * @param array $args Arguments for tag cloud widget.
 929   * @return array The filtered arguments for tag cloud widget.
 930   */
 931  function twentyeleven_widget_tag_cloud_args( $args ) {
 932      $args['largest']  = 22;
 933      $args['smallest'] = 8;
 934      $args['unit']     = 'pt';
 935      $args['format']   = 'list';
 936  
 937      return $args;
 938  }
 939  add_filter( 'widget_tag_cloud_args', 'twentyeleven_widget_tag_cloud_args' );
 940  
 941  if ( ! function_exists( 'wp_body_open' ) ) :
 942      /**
 943       * Fire the wp_body_open action.
 944       *
 945       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 946       *
 947       * @since Twenty Eleven 3.3
 948       */
 949  	function wp_body_open() {
 950          /**
 951           * Triggered after the opening <body> tag.
 952           *
 953           * @since Twenty Eleven 3.3
 954           */
 955          do_action( 'wp_body_open' );
 956      }
 957  endif;
 958  
 959  /**
 960   * Include a skip to content link at the top of the page so that users can bypass the menu.
 961   *
 962   * @since Twenty Eleven 3.4
 963   */
 964  function twentyeleven_skip_link() {
 965      echo '<div class="skip-link"><a class="assistive-text" href="#content">' . esc_html__( 'Skip to primary content', 'twentyeleven' ) . '</a></div>';
 966      if ( ! is_singular() ) {
 967          echo '<div class="skip-link"><a class="assistive-text" href="#secondary">' . esc_html__( 'Skip to secondary content', 'twentyeleven' ) . '</a></div>';
 968      }
 969  }
 970  add_action( 'wp_body_open', 'twentyeleven_skip_link', 5 );
 971  
 972  if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
 973      /**
 974       * Retrieves the list item separator based on the locale.
 975       *
 976       * Added for backward compatibility to support pre-6.0.0 WordPress versions.
 977       *
 978       * @since 6.0.0
 979       */
 980  	function wp_get_list_item_separator() {
 981          /* translators: Used between list items, there is a space after the comma. */
 982          return __( ', ', 'twentyeleven' );
 983      }
 984  endif;


Generated : Sun Mar 9 08:20:01 2025 Cross-referenced by PHPXref