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


Generated: Tue Mar 19 01:00:02 2024 Cross-referenced by PHPXref 0.7.1