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


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref