[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7