[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Twenty Twelve functions and definitions
   4   *
   5   * Sets up the theme and provides some helper functions, which are used
   6   * in the theme as custom template tags. Others are attached to action and
   7   * filter hooks in WordPress to change core functionality.
   8   *
   9   * When using a child theme you can override certain functions (those wrapped
  10   * in a function_exists() call) by defining them first in your child theme's
  11   * functions.php file. The child theme's functions.php file is included before
  12   * the parent theme's file, so the child theme functions would be used.
  13   *
  14   * @link https://developer.wordpress.org/themes/basics/theme-functions/
  15   * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
  16   *
  17   * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  18   * to a filter or action hook.
  19   *
  20   * For more information on hooks, actions, and filters, @link https://developer.wordpress.org/plugins/
  21   *
  22   * @package WordPress
  23   * @subpackage Twenty_Twelve
  24   * @since Twenty Twelve 1.0
  25   */
  26  
  27  // Set up the content width value based on the theme's design and stylesheet.
  28  if ( ! isset( $content_width ) ) {
  29      $content_width = 625;
  30  }
  31  
  32  /**
  33   * Twenty Twelve setup.
  34   *
  35   * Sets up theme defaults and registers the various WordPress features that
  36   * Twenty Twelve supports.
  37   *
  38   * @uses load_theme_textdomain() For translation/localization support.
  39   * @uses add_editor_style() To add a Visual Editor stylesheet.
  40   * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
  41   *  custom background, and post formats.
  42   * @uses register_nav_menu() To add support for navigation menus.
  43   * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  44   *
  45   * @since Twenty Twelve 1.0
  46   */
  47  function twentytwelve_setup() {
  48      /*
  49       * Makes Twenty Twelve available for translation.
  50       *
  51       * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentytwelve
  52       * If you're building a theme based on Twenty Twelve, use a find and replace
  53       * to change 'twentytwelve' to the name of your theme in all the template files.
  54       */
  55      load_theme_textdomain( 'twentytwelve' );
  56  
  57      // This theme styles the visual editor with editor-style.css to match the theme style.
  58      add_editor_style();
  59  
  60      // Load regular editor styles into the new block-based editor.
  61      add_theme_support( 'editor-styles' );
  62  
  63      // Load default block styles.
  64      add_theme_support( 'wp-block-styles' );
  65  
  66      // Add support for responsive embeds.
  67      add_theme_support( 'responsive-embeds' );
  68  
  69      // Add support for custom color scheme.
  70      add_theme_support(
  71          'editor-color-palette',
  72          array(
  73              array(
  74                  'name'  => __( 'Blue', 'twentytwelve' ),
  75                  'slug'  => 'blue',
  76                  'color' => '#21759b',
  77              ),
  78              array(
  79                  'name'  => __( 'Dark Gray', 'twentytwelve' ),
  80                  'slug'  => 'dark-gray',
  81                  'color' => '#444',
  82              ),
  83              array(
  84                  'name'  => __( 'Medium Gray', 'twentytwelve' ),
  85                  'slug'  => 'medium-gray',
  86                  'color' => '#9f9f9f',
  87              ),
  88              array(
  89                  'name'  => __( 'Light Gray', 'twentytwelve' ),
  90                  'slug'  => 'light-gray',
  91                  'color' => '#e6e6e6',
  92              ),
  93              array(
  94                  'name'  => __( 'White', 'twentytwelve' ),
  95                  'slug'  => 'white',
  96                  'color' => '#fff',
  97              ),
  98          )
  99      );
 100  
 101      // Adds RSS feed links to <head> for posts and comments.
 102      add_theme_support( 'automatic-feed-links' );
 103  
 104      // This theme supports a variety of post formats.
 105      add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
 106  
 107      // This theme uses wp_nav_menu() in one location.
 108      register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
 109  
 110      /*
 111       * This theme supports custom background color and image,
 112       * and here we also set up the default background color.
 113       */
 114      add_theme_support(
 115          'custom-background',
 116          array(
 117              'default-color' => 'e6e6e6',
 118          )
 119      );
 120  
 121      // This theme uses a custom image size for featured images, displayed on "standard" posts.
 122      add_theme_support( 'post-thumbnails' );
 123      set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop
 124  
 125      // Indicate widget sidebars can use selective refresh in the Customizer.
 126      add_theme_support( 'customize-selective-refresh-widgets' );
 127  }
 128  add_action( 'after_setup_theme', 'twentytwelve_setup' );
 129  
 130  /**
 131   * Add support for a custom header image.
 132   */
 133  require( get_template_directory() . '/inc/custom-header.php' );
 134  
 135  /**
 136   * Return the Google font stylesheet URL if available.
 137   *
 138   * The use of Open Sans by default is localized. For languages that use
 139   * characters not supported by the font, the font can be disabled.
 140   *
 141   * @since Twenty Twelve 1.2
 142   *
 143   * @return string Font stylesheet or empty string if disabled.
 144   */
 145  function twentytwelve_get_font_url() {
 146      $font_url = '';
 147  
 148      /*
 149       * translators: If there are characters in your language that are not supported
 150       * by Open Sans, translate this to 'off'. Do not translate into your own language.
 151       */
 152      if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
 153          $subsets = 'latin,latin-ext';
 154  
 155          /*
 156           * translators: To add an additional Open Sans character subset specific to your language,
 157           * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
 158           */
 159          $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
 160  
 161          if ( 'cyrillic' == $subset ) {
 162              $subsets .= ',cyrillic,cyrillic-ext';
 163          } elseif ( 'greek' == $subset ) {
 164              $subsets .= ',greek,greek-ext';
 165          } elseif ( 'vietnamese' == $subset ) {
 166              $subsets .= ',vietnamese';
 167          }
 168  
 169          $query_args = array(
 170              'family'  => urlencode( 'Open Sans:400italic,700italic,400,700' ),
 171              'subset'  => urlencode( $subsets ),
 172              'display' => urlencode( 'fallback' ),
 173          );
 174          $font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
 175      }
 176  
 177      return $font_url;
 178  }
 179  
 180  /**
 181   * Enqueue scripts and styles for front end.
 182   *
 183   * @since Twenty Twelve 1.0
 184   */
 185  function twentytwelve_scripts_styles() {
 186      global $wp_styles;
 187  
 188      /*
 189       * Adds JavaScript to pages with the comment form to support
 190       * sites with threaded comments (when in use).
 191       */
 192      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 193          wp_enqueue_script( 'comment-reply' );
 194      }
 195  
 196      // Adds JavaScript for handling the navigation menu hide-and-show behavior.
 197      wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20141205', true );
 198  
 199      $font_url = twentytwelve_get_font_url();
 200      if ( ! empty( $font_url ) ) {
 201          wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
 202      }
 203  
 204      // Loads our main stylesheet.
 205      wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri(), array(), '20190507' );
 206  
 207      // Theme block stylesheet.
 208      wp_enqueue_style( 'twentytwelve-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentytwelve-style' ), '20190406' );
 209  
 210      // Loads the Internet Explorer specific stylesheet.
 211      wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20150214' );
 212      $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
 213  }
 214  add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
 215  
 216  /**
 217   * Enqueue styles for the block-based editor.
 218   *
 219   * @since Twenty Twelve 2.6
 220   */
 221  function twentytwelve_block_editor_styles() {
 222      // Block styles.
 223      wp_enqueue_style( 'twentytwelve-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20190406' );
 224      // Add custom fonts.
 225      wp_enqueue_style( 'twentytwelve-fonts', twentytwelve_get_font_url(), array(), null );
 226  }
 227  add_action( 'enqueue_block_editor_assets', 'twentytwelve_block_editor_styles' );
 228  
 229  /**
 230   * Add preconnect for Google Fonts.
 231   *
 232   * @since Twenty Twelve 2.2
 233   *
 234   * @param array   $urls          URLs to print for resource hints.
 235   * @param string  $relation_type The relation type the URLs are printed.
 236   * @return array URLs to print for resource hints.
 237   */
 238  function twentytwelve_resource_hints( $urls, $relation_type ) {
 239      if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
 240          if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
 241              $urls[] = array(
 242                  'href' => 'https://fonts.gstatic.com',
 243                  'crossorigin',
 244              );
 245          } else {
 246              $urls[] = 'https://fonts.gstatic.com';
 247          }
 248      }
 249  
 250      return $urls;
 251  }
 252  add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 );
 253  
 254  /**
 255   * Filter TinyMCE CSS path to include Google Fonts.
 256   *
 257   * Adds additional stylesheets to the TinyMCE editor if needed.
 258   *
 259   * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
 260   *
 261   * @since Twenty Twelve 1.2
 262   *
 263   * @param string $mce_css CSS path to load in TinyMCE.
 264   * @return string Filtered CSS path.
 265   */
 266  function twentytwelve_mce_css( $mce_css ) {
 267      $font_url = twentytwelve_get_font_url();
 268  
 269      if ( empty( $font_url ) ) {
 270          return $mce_css;
 271      }
 272  
 273      if ( ! empty( $mce_css ) ) {
 274          $mce_css .= ',';
 275      }
 276  
 277      $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
 278  
 279      return $mce_css;
 280  }
 281  add_filter( 'mce_css', 'twentytwelve_mce_css' );
 282  
 283  /**
 284   * Filter the page title.
 285   *
 286   * Creates a nicely formatted and more specific title element text
 287   * for output in head of document, based on current view.
 288   *
 289   * @since Twenty Twelve 1.0
 290   *
 291   * @param string $title Default title text for current view.
 292   * @param string $sep Optional separator.
 293   * @return string Filtered title.
 294   */
 295  function twentytwelve_wp_title( $title, $sep ) {
 296      global $paged, $page;
 297  
 298      if ( is_feed() ) {
 299          return $title;
 300      }
 301  
 302      // Add the site name.
 303      $title .= get_bloginfo( 'name', 'display' );
 304  
 305      // Add the site description for the home/front page.
 306      $site_description = get_bloginfo( 'description', 'display' );
 307      if ( $site_description && ( is_home() || is_front_page() ) ) {
 308          $title = "$title $sep $site_description";
 309      }
 310  
 311      // Add a page number if necessary.
 312      if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
 313          /* translators: %s: Page number. */
 314          $title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
 315      }
 316  
 317      return $title;
 318  }
 319  add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
 320  
 321  /**
 322   * Filter the page menu arguments.
 323   *
 324   * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
 325   *
 326   * @since Twenty Twelve 1.0
 327   */
 328  function twentytwelve_page_menu_args( $args ) {
 329      if ( ! isset( $args['show_home'] ) ) {
 330          $args['show_home'] = true;
 331      }
 332      return $args;
 333  }
 334  add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' );
 335  
 336  /**
 337   * Register sidebars.
 338   *
 339   * Registers our main widget area and the front page widget areas.
 340   *
 341   * @since Twenty Twelve 1.0
 342   */
 343  function twentytwelve_widgets_init() {
 344      register_sidebar(
 345          array(
 346              'name'          => __( 'Main Sidebar', 'twentytwelve' ),
 347              'id'            => 'sidebar-1',
 348              'description'   => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
 349              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 350              'after_widget'  => '</aside>',
 351              'before_title'  => '<h3 class="widget-title">',
 352              'after_title'   => '</h3>',
 353          )
 354      );
 355  
 356      register_sidebar(
 357          array(
 358              'name'          => __( 'First Front Page Widget Area', 'twentytwelve' ),
 359              'id'            => 'sidebar-2',
 360              'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
 361              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 362              'after_widget'  => '</aside>',
 363              'before_title'  => '<h3 class="widget-title">',
 364              'after_title'   => '</h3>',
 365          )
 366      );
 367  
 368      register_sidebar(
 369          array(
 370              'name'          => __( 'Second Front Page Widget Area', 'twentytwelve' ),
 371              'id'            => 'sidebar-3',
 372              'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
 373              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 374              'after_widget'  => '</aside>',
 375              'before_title'  => '<h3 class="widget-title">',
 376              'after_title'   => '</h3>',
 377          )
 378      );
 379  }
 380  add_action( 'widgets_init', 'twentytwelve_widgets_init' );
 381  
 382  if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
 383      /**
 384       * Displays navigation to next/previous pages when applicable.
 385       *
 386       * @since Twenty Twelve 1.0
 387       */
 388  	function twentytwelve_content_nav( $html_id ) {
 389          global $wp_query;
 390  
 391          if ( $wp_query->max_num_pages > 1 ) : ?>
 392              <nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
 393                  <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
 394                  <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
 395                  <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
 396              </nav><!-- .navigation -->
 397              <?php
 398      endif;
 399      }
 400  endif;
 401  
 402  if ( ! function_exists( 'twentytwelve_comment' ) ) :
 403      /**
 404       * Template for comments and pingbacks.
 405       *
 406       * To override this walker in a child theme without modifying the comments template
 407       * simply create your own twentytwelve_comment(), and that function will be used instead.
 408       *
 409       * Used as a callback by wp_list_comments() for displaying the comments.
 410       *
 411       * @since Twenty Twelve 1.0
 412       */
 413  	function twentytwelve_comment( $comment, $args, $depth ) {
 414          $GLOBALS['comment'] = $comment;
 415          switch ( $comment->comment_type ) :
 416              case 'pingback':
 417              case 'trackback':
 418                  // Display trackbacks differently than normal comments.
 419                  ?>
 420          <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
 421          <p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
 422                  <?php
 423                  break;
 424              default:
 425                  // Proceed with normal comments.
 426                  global $post;
 427                  ?>
 428          <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 429          <article id="comment-<?php comment_ID(); ?>" class="comment">
 430              <header class="comment-meta comment-author vcard">
 431                  <?php
 432                      echo get_avatar( $comment, 44 );
 433                      printf(
 434                          '<cite><b class="fn">%1$s</b> %2$s</cite>',
 435                          get_comment_author_link(),
 436                          // If current post author is also comment author, make it known visually.
 437                          ( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
 438                      );
 439                      printf(
 440                          '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
 441                          esc_url( get_comment_link( $comment->comment_ID ) ),
 442                          get_comment_time( 'c' ),
 443                          /* translators: 1: Date, 2: Time. */
 444                          sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
 445                      );
 446                  ?>
 447                  </header><!-- .comment-meta -->
 448  
 449                  <?php
 450                  $commenter = wp_get_current_commenter();
 451                  if ( $commenter['comment_author_email'] ) {
 452                      $moderation_note = __( 'Your comment is awaiting moderation.', 'twentytwelve' );
 453                  } else {
 454                      $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.', 'twentytwelve' );
 455                  }
 456                  ?>
 457  
 458                  <?php if ( '0' == $comment->comment_approved ) : ?>
 459                  <p class="comment-awaiting-moderation"><?php echo $moderation_note; ?></p>
 460                  <?php endif; ?>
 461  
 462                  <section class="comment-content comment">
 463                  <?php comment_text(); ?>
 464                  <?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
 465                  </section><!-- .comment-content -->
 466  
 467                  <div class="reply">
 468                  <?php
 469                  comment_reply_link(
 470                      array_merge(
 471                          $args,
 472                          array(
 473                              'reply_text' => __( 'Reply', 'twentytwelve' ),
 474                              'after'      => ' <span>&darr;</span>',
 475                              'depth'      => $depth,
 476                              'max_depth'  => $args['max_depth'],
 477                          )
 478                      )
 479                  );
 480                  ?>
 481                  </div><!-- .reply -->
 482              </article><!-- #comment-## -->
 483                  <?php
 484                  break;
 485          endswitch; // end comment_type check
 486      }
 487  endif;
 488  
 489  if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
 490      /**
 491       * Set up post entry meta.
 492       *
 493       * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
 494       *
 495       * Create your own twentytwelve_entry_meta() to override in a child theme.
 496       *
 497       * @since Twenty Twelve 1.0
 498       */
 499  	function twentytwelve_entry_meta() {
 500          /* translators: Used between list items, there is a space after the comma. */
 501          $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
 502  
 503          /* translators: Used between list items, there is a space after the comma. */
 504          $tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
 505  
 506          $date = sprintf(
 507              '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
 508              esc_url( get_permalink() ),
 509              esc_attr( get_the_time() ),
 510              esc_attr( get_the_date( 'c' ) ),
 511              esc_html( get_the_date() )
 512          );
 513  
 514          $author = sprintf(
 515              '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
 516              esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 517              /* translators: %s: Author display name. */
 518              esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
 519              get_the_author()
 520          );
 521  
 522          if ( $tag_list ) {
 523              /* translators: 1: Category name, 2: Tag name, 3: Date, 4: Author display name. */
 524              $utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
 525          } elseif ( $categories_list ) {
 526              /* translators: 1: Category name, 3: Date, 4: Author display name. */
 527              $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
 528          } else {
 529              /* translators: 3: Date, 4: Author display name. */
 530              $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
 531          }
 532  
 533          printf(
 534              $utility_text,
 535              $categories_list,
 536              $tag_list,
 537              $date,
 538              $author
 539          );
 540      }
 541  endif;
 542  
 543  /**
 544   * Extend the default WordPress body classes.
 545   *
 546   * Extends the default WordPress body class to denote:
 547   * 1. Using a full-width layout, when no active widgets in the sidebar
 548   *    or full-width template.
 549   * 2. Front Page template: thumbnail in use and number of sidebars for
 550   *    widget areas.
 551   * 3. White or empty background color to change the layout and spacing.
 552   * 4. Custom fonts enabled.
 553   * 5. Single or multiple authors.
 554   *
 555   * @since Twenty Twelve 1.0
 556   *
 557   * @param array $classes Existing class values.
 558   * @return array Filtered class values.
 559   */
 560  function twentytwelve_body_class( $classes ) {
 561      $background_color = get_background_color();
 562      $background_image = get_background_image();
 563  
 564      if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) {
 565          $classes[] = 'full-width';
 566      }
 567  
 568      if ( is_page_template( 'page-templates/front-page.php' ) ) {
 569          $classes[] = 'template-front-page';
 570          if ( has_post_thumbnail() ) {
 571              $classes[] = 'has-post-thumbnail';
 572          }
 573          if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) {
 574              $classes[] = 'two-sidebars';
 575          }
 576      }
 577  
 578      if ( empty( $background_image ) ) {
 579          if ( empty( $background_color ) ) {
 580              $classes[] = 'custom-background-empty';
 581          } elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) {
 582              $classes[] = 'custom-background-white';
 583          }
 584      }
 585  
 586      // Enable custom font class only if the font CSS is queued to load.
 587      if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) {
 588          $classes[] = 'custom-font-enabled';
 589      }
 590  
 591      if ( ! is_multi_author() ) {
 592          $classes[] = 'single-author';
 593      }
 594  
 595      return $classes;
 596  }
 597  add_filter( 'body_class', 'twentytwelve_body_class' );
 598  
 599  /**
 600   * Adjust content width in certain contexts.
 601   *
 602   * Adjusts content_width value for full-width and single image attachment
 603   * templates, and when there are no active widgets in the sidebar.
 604   *
 605   * @since Twenty Twelve 1.0
 606   */
 607  function twentytwelve_content_width() {
 608      if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
 609          global $content_width;
 610          $content_width = 960;
 611      }
 612  }
 613  add_action( 'template_redirect', 'twentytwelve_content_width' );
 614  
 615  /**
 616   * Register postMessage support.
 617   *
 618   * Add postMessage support for site title and description for the Customizer.
 619   *
 620   * @since Twenty Twelve 1.0
 621   *
 622   * @param WP_Customize_Manager $wp_customize Customizer object.
 623   */
 624  function twentytwelve_customize_register( $wp_customize ) {
 625      $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
 626      $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
 627      $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
 628  
 629      if ( isset( $wp_customize->selective_refresh ) ) {
 630          $wp_customize->selective_refresh->add_partial(
 631              'blogname',
 632              array(
 633                  'selector'            => '.site-title > a',
 634                  'container_inclusive' => false,
 635                  'render_callback'     => 'twentytwelve_customize_partial_blogname',
 636              )
 637          );
 638          $wp_customize->selective_refresh->add_partial(
 639              'blogdescription',
 640              array(
 641                  'selector'            => '.site-description',
 642                  'container_inclusive' => false,
 643                  'render_callback'     => 'twentytwelve_customize_partial_blogdescription',
 644              )
 645          );
 646      }
 647  }
 648  add_action( 'customize_register', 'twentytwelve_customize_register' );
 649  
 650  /**
 651   * Render the site title for the selective refresh partial.
 652   *
 653   * @since Twenty Twelve 2.0
 654   * @see twentytwelve_customize_register()
 655   *
 656   * @return void
 657   */
 658  function twentytwelve_customize_partial_blogname() {
 659      bloginfo( 'name' );
 660  }
 661  
 662  /**
 663   * Render the site tagline for the selective refresh partial.
 664   *
 665   * @since Twenty Twelve 2.0
 666   * @see twentytwelve_customize_register()
 667   *
 668   * @return void
 669   */
 670  function twentytwelve_customize_partial_blogdescription() {
 671      bloginfo( 'description' );
 672  }
 673  
 674  /**
 675   * Enqueue Javascript postMessage handlers for the Customizer.
 676   *
 677   * Binds JS handlers to make the Customizer preview reload changes asynchronously.
 678   *
 679   * @since Twenty Twelve 1.0
 680   */
 681  function twentytwelve_customize_preview_js() {
 682      wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
 683  }
 684  add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
 685  
 686  /**
 687   * Modifies tag cloud widget arguments to display all tags in the same font size
 688   * and use list format for better accessibility.
 689   *
 690   * @since Twenty Twelve 2.4
 691   *
 692   * @param array $args Arguments for tag cloud widget.
 693   * @return array The filtered arguments for tag cloud widget.
 694   */
 695  function twentytwelve_widget_tag_cloud_args( $args ) {
 696      $args['largest']  = 22;
 697      $args['smallest'] = 8;
 698      $args['unit']     = 'pt';
 699      $args['format']   = 'list';
 700  
 701      return $args;
 702  }
 703  add_filter( 'widget_tag_cloud_args', 'twentytwelve_widget_tag_cloud_args' );
 704  
 705  if ( ! function_exists( 'wp_body_open' ) ) :
 706      /**
 707       * Fire the wp_body_open action.
 708       *
 709       * Added for backwards compatibility to support pre 5.2.0 WordPress versions.
 710       *
 711       * @since Twenty Twelve 3.0
 712       */
 713  	function wp_body_open() {
 714          /**
 715           * Triggered after the opening <body> tag.
 716           *
 717           * @since Twenty Twelve 3.0
 718           */
 719          do_action( 'wp_body_open' );
 720      }
 721  endif;


Generated: Mon Nov 18 01:00:04 2019 Cross-referenced by PHPXref 0.7.1