[ 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( 'twentytwelve_content_nav' ) ) :
 388      /**
 389       * Displays navigation to next/previous pages when applicable.
 390       *
 391       * @since Twenty Twelve 1.0
 392       */
 393  	function twentytwelve_content_nav( $html_id ) {
 394          global $wp_query;
 395  
 396          if ( $wp_query->max_num_pages > 1 ) : ?>
 397              <nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
 398                  <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
 399                  <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
 400                  <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
 401              </nav><!-- .navigation -->
 402              <?php
 403      endif;
 404      }
 405  endif;
 406  
 407  if ( ! function_exists( 'twentytwelve_comment' ) ) :
 408      /**
 409       * Template for comments and pingbacks.
 410       *
 411       * To override this walker in a child theme without modifying the comments template
 412       * simply create your own twentytwelve_comment(), and that function will be used instead.
 413       *
 414       * Used as a callback by wp_list_comments() for displaying the comments.
 415       *
 416       * @since Twenty Twelve 1.0
 417       */
 418  	function twentytwelve_comment( $comment, $args, $depth ) {
 419          $GLOBALS['comment'] = $comment;
 420          switch ( $comment->comment_type ) :
 421              case 'pingback':
 422              case 'trackback':
 423                  // Display trackbacks differently than normal comments.
 424                  ?>
 425          <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
 426          <p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
 427                  <?php
 428                  break;
 429              default:
 430                  // Proceed with normal comments.
 431                  global $post;
 432                  ?>
 433          <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 434          <article id="comment-<?php comment_ID(); ?>" class="comment">
 435              <header class="comment-meta comment-author vcard">
 436                  <?php
 437                      echo get_avatar( $comment, 44 );
 438                      printf(
 439                          '<cite><b class="fn">%1$s</b> %2$s</cite>',
 440                          get_comment_author_link(),
 441                          // If current post author is also comment author, make it known visually.
 442                          ( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
 443                      );
 444                      printf(
 445                          '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
 446                          esc_url( get_comment_link( $comment->comment_ID ) ),
 447                          get_comment_time( 'c' ),
 448                          /* translators: 1: Date, 2: Time. */
 449                          sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
 450                      );
 451                  ?>
 452                  </header><!-- .comment-meta -->
 453  
 454                  <?php
 455                  $commenter = wp_get_current_commenter();
 456                  if ( $commenter['comment_author_email'] ) {
 457                      $moderation_note = __( 'Your comment is awaiting moderation.', 'twentytwelve' );
 458                  } else {
 459                      $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentytwelve' );
 460                  }
 461                  ?>
 462  
 463                  <?php if ( '0' == $comment->comment_approved ) : ?>
 464                  <p class="comment-awaiting-moderation"><?php echo $moderation_note; ?></p>
 465                  <?php endif; ?>
 466  
 467                  <section class="comment-content comment">
 468                  <?php comment_text(); ?>
 469                  <?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
 470                  </section><!-- .comment-content -->
 471  
 472                  <div class="reply">
 473                  <?php
 474                  comment_reply_link(
 475                      array_merge(
 476                          $args,
 477                          array(
 478                              'reply_text' => __( 'Reply', 'twentytwelve' ),
 479                              'after'      => ' <span>&darr;</span>',
 480                              'depth'      => $depth,
 481                              'max_depth'  => $args['max_depth'],
 482                          )
 483                      )
 484                  );
 485                  ?>
 486                  </div><!-- .reply -->
 487              </article><!-- #comment-## -->
 488                  <?php
 489                  break;
 490          endswitch; // End comment_type check.
 491      }
 492  endif;
 493  
 494  if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
 495      /**
 496       * Set up post entry meta.
 497       *
 498       * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
 499       *
 500       * Create your own twentytwelve_entry_meta() to override in a child theme.
 501       *
 502       * @since Twenty Twelve 1.0
 503       */
 504  	function twentytwelve_entry_meta() {
 505          /* translators: Used between list items, there is a space after the comma. */
 506          $categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
 507  
 508          /* translators: Used between list items, there is a space after the comma. */
 509          $tags_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
 510  
 511          $date = sprintf(
 512              '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
 513              esc_url( get_permalink() ),
 514              esc_attr( get_the_time() ),
 515              esc_attr( get_the_date( 'c' ) ),
 516              esc_html( get_the_date() )
 517          );
 518  
 519          $author = sprintf(
 520              '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
 521              esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 522              /* translators: %s: Author display name. */
 523              esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
 524              get_the_author()
 525          );
 526  
 527          if ( $tags_list && ! is_wp_error( $tags_list ) ) {
 528              /* translators: 1: Category name, 2: Tag name, 3: Date, 4: Author display name. */
 529              $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' );
 530          } elseif ( $categories_list ) {
 531              /* translators: 1: Category name, 3: Date, 4: Author display name. */
 532              $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
 533          } else {
 534              /* translators: 3: Date, 4: Author display name. */
 535              $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
 536          }
 537  
 538          printf(
 539              $utility_text,
 540              $categories_list,
 541              $tags_list,
 542              $date,
 543              $author
 544          );
 545      }
 546  endif;
 547  
 548  /**
 549   * Extend the default WordPress body classes.
 550   *
 551   * Extends the default WordPress body class to denote:
 552   * 1. Using a full-width layout, when no active widgets in the sidebar
 553   *    or full-width template.
 554   * 2. Front Page template: thumbnail in use and number of sidebars for
 555   *    widget areas.
 556   * 3. White or empty background color to change the layout and spacing.
 557   * 4. Custom fonts enabled.
 558   * 5. Single or multiple authors.
 559   *
 560   * @since Twenty Twelve 1.0
 561   *
 562   * @param array $classes Existing class values.
 563   * @return array Filtered class values.
 564   */
 565  function twentytwelve_body_class( $classes ) {
 566      $background_color = get_background_color();
 567      $background_image = get_background_image();
 568  
 569      if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) {
 570          $classes[] = 'full-width';
 571      }
 572  
 573      if ( is_page_template( 'page-templates/front-page.php' ) ) {
 574          $classes[] = 'template-front-page';
 575          if ( has_post_thumbnail() ) {
 576              $classes[] = 'has-post-thumbnail';
 577          }
 578          if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) {
 579              $classes[] = 'two-sidebars';
 580          }
 581      }
 582  
 583      if ( empty( $background_image ) ) {
 584          if ( empty( $background_color ) ) {
 585              $classes[] = 'custom-background-empty';
 586          } elseif ( in_array( $background_color, array( 'fff', 'ffffff' ), true ) ) {
 587              $classes[] = 'custom-background-white';
 588          }
 589      }
 590  
 591      // Enable custom font class only if the font CSS is queued to load.
 592      if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) {
 593          $classes[] = 'custom-font-enabled';
 594      }
 595  
 596      if ( ! is_multi_author() ) {
 597          $classes[] = 'single-author';
 598      }
 599  
 600      return $classes;
 601  }
 602  add_filter( 'body_class', 'twentytwelve_body_class' );
 603  
 604  /**
 605   * Adjust content width in certain contexts.
 606   *
 607   * Adjusts content_width value for full-width and single image attachment
 608   * templates, and when there are no active widgets in the sidebar.
 609   *
 610   * @since Twenty Twelve 1.0
 611   */
 612  function twentytwelve_content_width() {
 613      if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
 614          global $content_width;
 615          $content_width = 960;
 616      }
 617  }
 618  add_action( 'template_redirect', 'twentytwelve_content_width' );
 619  
 620  /**
 621   * Register postMessage support.
 622   *
 623   * Add postMessage support for site title and description for the Customizer.
 624   *
 625   * @since Twenty Twelve 1.0
 626   *
 627   * @param WP_Customize_Manager $wp_customize Customizer object.
 628   */
 629  function twentytwelve_customize_register( $wp_customize ) {
 630      $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
 631      $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
 632      $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
 633  
 634      if ( isset( $wp_customize->selective_refresh ) ) {
 635          $wp_customize->selective_refresh->add_partial(
 636              'blogname',
 637              array(
 638                  'selector'            => '.site-title > a',
 639                  'container_inclusive' => false,
 640                  'render_callback'     => 'twentytwelve_customize_partial_blogname',
 641              )
 642          );
 643          $wp_customize->selective_refresh->add_partial(
 644              'blogdescription',
 645              array(
 646                  'selector'            => '.site-description',
 647                  'container_inclusive' => false,
 648                  'render_callback'     => 'twentytwelve_customize_partial_blogdescription',
 649              )
 650          );
 651      }
 652  }
 653  add_action( 'customize_register', 'twentytwelve_customize_register' );
 654  
 655  /**
 656   * Render the site title for the selective refresh partial.
 657   *
 658   * @since Twenty Twelve 2.0
 659   *
 660   * @see twentytwelve_customize_register()
 661   *
 662   * @return void
 663   */
 664  function twentytwelve_customize_partial_blogname() {
 665      bloginfo( 'name' );
 666  }
 667  
 668  /**
 669   * Render the site tagline for the selective refresh partial.
 670   *
 671   * @since Twenty Twelve 2.0
 672   *
 673   * @see twentytwelve_customize_register()
 674   *
 675   * @return void
 676   */
 677  function twentytwelve_customize_partial_blogdescription() {
 678      bloginfo( 'description' );
 679  }
 680  
 681  /**
 682   * Enqueue JavaScript postMessage handlers for the Customizer.
 683   *
 684   * Binds JS handlers to make the Customizer preview reload changes asynchronously.
 685   *
 686   * @since Twenty Twelve 1.0
 687   */
 688  function twentytwelve_customize_preview_js() {
 689      wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
 690  }
 691  add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
 692  
 693  /**
 694   * Modifies tag cloud widget arguments to display all tags in the same font size
 695   * and use list format for better accessibility.
 696   *
 697   * @since Twenty Twelve 2.4
 698   *
 699   * @param array $args Arguments for tag cloud widget.
 700   * @return array The filtered arguments for tag cloud widget.
 701   */
 702  function twentytwelve_widget_tag_cloud_args( $args ) {
 703      $args['largest']  = 22;
 704      $args['smallest'] = 8;
 705      $args['unit']     = 'pt';
 706      $args['format']   = 'list';
 707  
 708      return $args;
 709  }
 710  add_filter( 'widget_tag_cloud_args', 'twentytwelve_widget_tag_cloud_args' );
 711  
 712  if ( ! function_exists( 'wp_body_open' ) ) :
 713      /**
 714       * Fire the wp_body_open action.
 715       *
 716       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 717       *
 718       * @since Twenty Twelve 3.0
 719       */
 720  	function wp_body_open() {
 721          /**
 722           * Triggered after the opening <body> tag.
 723           *
 724           * @since Twenty Twelve 3.0
 725           */
 726          do_action( 'wp_body_open' );
 727      }
 728  endif;


Generated: Mon Aug 2 01:00:04 2021 Cross-referenced by PHPXref 0.7.1