[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Thu Apr 23 08:20:11 2026 Cross-referenced by PHPXref