[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentyeleven/inc/ -> theme-options.php (source)

   1  <?php
   2  /**
   3   * Twenty Eleven Theme Options
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Eleven
   7   * @since Twenty Eleven 1.0
   8   */
   9  
  10  /**
  11   * Enqueues styles and scripts for the theme options page.
  12   *
  13   * This function is attached to the admin_enqueue_scripts action hook.
  14   *
  15   * @since Twenty Eleven 1.0
  16   *
  17   * @param string $hook_suffix An admin page's hook suffix.
  18   */
  19  function twentyeleven_admin_enqueue_scripts( $hook_suffix ) {
  20      wp_enqueue_style( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options.css', false, '20110602' );
  21      wp_enqueue_script( 'twentyeleven-theme-options', get_template_directory_uri() . '/inc/theme-options.js', array( 'farbtastic' ), '20110610' );
  22      wp_enqueue_style( 'farbtastic' );
  23  }
  24  add_action( 'admin_print_styles-appearance_page_theme_options', 'twentyeleven_admin_enqueue_scripts' );
  25  
  26  /**
  27   * Registers the form setting for our twentyeleven_options array.
  28   *
  29   * This function is attached to the admin_init action hook.
  30   *
  31   * This call to register_setting() registers a validation callback, twentyeleven_theme_options_validate(),
  32   * which is used when the option is saved, to ensure that our option values are complete, properly
  33   * formatted, and safe.
  34   *
  35   * @since Twenty Eleven 1.0
  36   */
  37  function twentyeleven_theme_options_init() {
  38  
  39      register_setting(
  40          'twentyeleven_options',               // Options group, see settings_fields() call in twentyeleven_theme_options_render_page().
  41          'twentyeleven_theme_options',         // Database option, see twentyeleven_get_theme_options().
  42          'twentyeleven_theme_options_validate' // The sanitization callback, see twentyeleven_theme_options_validate().
  43      );
  44  
  45      // Register our settings field group.
  46      add_settings_section(
  47          'general',        // Unique identifier for the settings section.
  48          '',               // Section title (we don't want one).
  49          '__return_false', // Section callback (we don't want anything).
  50          'theme_options'   // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page().
  51      );
  52  
  53      // Register our individual settings fields.
  54      add_settings_field(
  55          'color_scheme',                             // Unique identifier for the field for this section.
  56          __( 'Color Scheme', 'twentyeleven' ),       // Setting field label.
  57          'twentyeleven_settings_field_color_scheme', // Function that renders the settings field.
  58          'theme_options',                            // Menu slug, used to uniquely identify the page; see twentyeleven_theme_options_add_page().
  59          'general'                                   // Settings section. Same as the first argument in the add_settings_section() above.
  60      );
  61  
  62      add_settings_field( 'link_color', __( 'Link Color', 'twentyeleven' ), 'twentyeleven_settings_field_link_color', 'theme_options', 'general' );
  63      add_settings_field( 'layout', __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout', 'theme_options', 'general' );
  64  }
  65  add_action( 'admin_init', 'twentyeleven_theme_options_init' );
  66  
  67  /**
  68   * Changes the capability required to save the 'twentyeleven_options' options group.
  69   *
  70   * @see twentyeleven_theme_options_init()     First parameter to register_setting() is the name of the options group.
  71   * @see twentyeleven_theme_options_add_page() The edit_theme_options capability is used for viewing the page.
  72   *
  73   * By default, the options groups for all registered settings require the manage_options capability.
  74   * This filter is required to change our theme options page to edit_theme_options instead.
  75   * By default, only administrators have either of these capabilities, but the desire here is
  76   * to allow for finer-grained control for roles and users.
  77   *
  78   * @since Twenty Eleven 1.1
  79   *
  80   * @param string $capability The capability used for the page, which is manage_options by default.
  81   * @return string The capability to actually use.
  82   */
  83  function twentyeleven_option_page_capability( $capability ) {
  84      return 'edit_theme_options';
  85  }
  86  add_filter( 'option_page_capability_twentyeleven_options', 'twentyeleven_option_page_capability' );
  87  
  88  /**
  89   * Adds the theme options page to the admin menu, including help documentation.
  90   *
  91   * This function is attached to the admin_menu action hook.
  92   *
  93   * @since Twenty Eleven 1.0
  94   */
  95  function twentyeleven_theme_options_add_page() {
  96      $theme_page = add_theme_page(
  97          __( 'Theme Options', 'twentyeleven' ),   // Name of page.
  98          __( 'Theme Options', 'twentyeleven' ),   // Label in menu.
  99          'edit_theme_options',                    // Capability required.
 100          'theme_options',                         // Menu slug, used to uniquely identify the page.
 101          'twentyeleven_theme_options_render_page' // Function that renders the options page.
 102      );
 103  
 104      if ( ! $theme_page ) {
 105          return;
 106      }
 107  
 108      add_action( "load-{$theme_page}", 'twentyeleven_theme_options_help' );
 109  }
 110  add_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );
 111  
 112  /**
 113   * Adds help documentation to the theme options page.
 114   *
 115   * @since Twenty Eleven 1.3
 116   */
 117  function twentyeleven_theme_options_help() {
 118  
 119      $help = '<p>' . __( 'Some themes provide customization options that are grouped together on a Theme Options screen. If you change themes, options may change or disappear, as they are theme-specific. Your current theme, Twenty Eleven, provides the following Theme Options:', 'twentyeleven' ) . '</p>' .
 120              '<ol>' .
 121                  '<li>' . __( '<strong>Color Scheme</strong>: You can choose a color palette of "Light" (light background with dark text) or "Dark" (dark background with light text) for your site.', 'twentyeleven' ) . '</li>' .
 122                  '<li>' . __( '<strong>Link Color</strong>: You can choose the color used for text links on your site. You can enter the HTML color or hex code, or you can choose visually by clicking the "Select a Color" button to pick from a color wheel.', 'twentyeleven' ) . '</li>' .
 123                  '<li>' . __( '<strong>Default Layout</strong>: You can choose if you want your site&#8217;s default layout to have a sidebar on the left, the right, or not at all.', 'twentyeleven' ) . '</li>' .
 124              '</ol>' .
 125              '<p>' . __( 'Remember to click "Save Changes" to save any changes you have made to the theme options.', 'twentyeleven' ) . '</p>';
 126  
 127      $sidebar = '<p><strong>' . __( 'For more information:', 'twentyeleven' ) . '</strong></p>' .
 128          '<p>' . __( '<a href="https://wordpress.org/documentation/article/customizer/" target="_blank">Documentation on Theme Customization</a>', 'twentyeleven' ) . '</p>' .
 129          '<p>' . __( '<a href="https://wordpress.org/support/forums/" target="_blank">Support forums</a>', 'twentyeleven' ) . '</p>';
 130  
 131      $screen = get_current_screen();
 132  
 133      if ( method_exists( $screen, 'add_help_tab' ) ) {
 134          // WordPress 3.3.0.
 135          $screen->add_help_tab(
 136              array(
 137                  'title'   => __( 'Overview', 'twentyeleven' ),
 138                  'id'      => 'theme-options-help',
 139                  'content' => $help,
 140              )
 141          );
 142  
 143          $screen->set_help_sidebar( $sidebar );
 144      } else {
 145          // WordPress 3.2.0.
 146          add_contextual_help( $screen, $help . $sidebar );
 147      }
 148  }
 149  
 150  /**
 151   * Returns an array of color schemes registered for Twenty Eleven.
 152   *
 153   * @since Twenty Eleven 1.0
 154   *
 155   * @return array<string, array<string, string>> An associative array of color scheme options.
 156   */
 157  function twentyeleven_color_schemes() {
 158      $color_scheme_options = array(
 159          'light' => array(
 160              'value'              => 'light',
 161              'label'              => __( 'Light', 'twentyeleven' ),
 162              'thumbnail'          => get_template_directory_uri() . '/inc/images/light.png',
 163              'default_link_color' => '#1b8be0',
 164          ),
 165          'dark'  => array(
 166              'value'              => 'dark',
 167              'label'              => __( 'Dark', 'twentyeleven' ),
 168              'thumbnail'          => get_template_directory_uri() . '/inc/images/dark.png',
 169              'default_link_color' => '#e4741f',
 170          ),
 171      );
 172  
 173      /**
 174       * Filters the Twenty Eleven color scheme options.
 175       *
 176       * @since Twenty Eleven 1.0
 177       *
 178       * @param array<string, array<string, string>> $color_scheme_options An associative array of color scheme options.
 179       */
 180      return apply_filters( 'twentyeleven_color_schemes', $color_scheme_options );
 181  }
 182  
 183  /**
 184   * Returns an array of layout options registered for Twenty Eleven.
 185   *
 186   * @since Twenty Eleven 1.0
 187   *
 188   * @return array<string, array<string, string>> An associative array of layout options.
 189   */
 190  function twentyeleven_layouts() {
 191      $layout_options = array(
 192          'content-sidebar' => array(
 193              'value'     => 'content-sidebar',
 194              'label'     => __( 'Content on left', 'twentyeleven' ),
 195              'thumbnail' => get_template_directory_uri() . '/inc/images/content-sidebar.png',
 196          ),
 197          'sidebar-content' => array(
 198              'value'     => 'sidebar-content',
 199              'label'     => __( 'Content on right', 'twentyeleven' ),
 200              'thumbnail' => get_template_directory_uri() . '/inc/images/sidebar-content.png',
 201          ),
 202          'content'         => array(
 203              'value'     => 'content',
 204              'label'     => __( 'One-column, no sidebar', 'twentyeleven' ),
 205              'thumbnail' => get_template_directory_uri() . '/inc/images/content.png',
 206          ),
 207      );
 208  
 209      /**
 210       * Filters the Twenty Eleven layout options.
 211       *
 212       * @since Twenty Eleven 1.0
 213       *
 214       * @param array<string, array<string, string>> $layout_options An associative array of layout options.
 215       */
 216      return apply_filters( 'twentyeleven_layouts', $layout_options );
 217  }
 218  
 219  /**
 220   * Returns the default options for Twenty Eleven.
 221   *
 222   * @since Twenty Eleven 1.0
 223   *
 224   * @return array<string, string> An array of default theme options.
 225   */
 226  function twentyeleven_get_default_theme_options() {
 227      $default_theme_options = array(
 228          'color_scheme' => 'light',
 229          'link_color'   => twentyeleven_get_default_link_color( 'light' ),
 230          'theme_layout' => 'content-sidebar',
 231      );
 232  
 233      if ( is_rtl() ) {
 234          $default_theme_options['theme_layout'] = 'sidebar-content';
 235      }
 236  
 237      /**
 238       * Filters the Twenty Eleven default options.
 239       *
 240       * @since Twenty Eleven 1.0
 241       *
 242       * @param array<string, string> $default_theme_options An array of default theme options.
 243       */
 244      return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );
 245  }
 246  
 247  /**
 248   * Returns the default link color for Twenty Eleven, based on color scheme.
 249   *
 250   * @since Twenty Eleven 1.0
 251   *
 252   * @param string $color_scheme Optional. Color scheme.
 253   *                             Default null (or the active color scheme).
 254   * @return string|false The default link color, or false if not set.
 255   */
 256  function twentyeleven_get_default_link_color( $color_scheme = null ) {
 257      if ( null === $color_scheme ) {
 258          $options      = twentyeleven_get_theme_options();
 259          $color_scheme = $options['color_scheme'];
 260      }
 261  
 262      $color_schemes = twentyeleven_color_schemes();
 263      if ( ! isset( $color_schemes[ $color_scheme ] ) ) {
 264          return false;
 265      }
 266  
 267      return $color_schemes[ $color_scheme ]['default_link_color'];
 268  }
 269  
 270  /**
 271   * Returns the options array for Twenty Eleven.
 272   *
 273   * @since Twenty Eleven 1.0
 274   *
 275   * @return array<string, string> The theme options array.
 276   */
 277  function twentyeleven_get_theme_options() {
 278      return get_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() );
 279  }
 280  
 281  /**
 282   * Renders the Color Scheme setting field.
 283   *
 284   * @since Twenty Eleven 1.3
 285   */
 286  function twentyeleven_settings_field_color_scheme() {
 287      $options = twentyeleven_get_theme_options();
 288  
 289      foreach ( twentyeleven_color_schemes() as $scheme ) {
 290          ?>
 291      <div class="layout image-radio-option color-scheme">
 292      <label class="description">
 293          <input type="radio" name="twentyeleven_theme_options[color_scheme]" value="<?php echo esc_attr( $scheme['value'] ); ?>" <?php checked( $options['color_scheme'], $scheme['value'] ); ?> />
 294          <input type="hidden" id="default-color-<?php echo esc_attr( $scheme['value'] ); ?>" value="<?php echo esc_attr( $scheme['default_link_color'] ); ?>" />
 295          <span>
 296              <img src="<?php echo esc_url( $scheme['thumbnail'] ); ?>" width="136" height="122" alt="" />
 297              <?php echo esc_html( $scheme['label'] ); ?>
 298          </span>
 299      </label>
 300      </div>
 301          <?php
 302      }
 303  }
 304  
 305  /**
 306   * Renders the Link Color setting field.
 307   *
 308   * @since Twenty Eleven 1.3
 309   */
 310  function twentyeleven_settings_field_link_color() {
 311      $options = twentyeleven_get_theme_options();
 312      ?>
 313      <input type="text" name="twentyeleven_theme_options[link_color]" id="link-color" value="<?php echo esc_attr( $options['link_color'] ); ?>" />
 314      <a href="#" class="pickcolor hide-if-no-js" id="link-color-example"></a>
 315      <input type="button" class="pickcolor button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color', 'twentyeleven' ); ?>" />
 316      <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
 317      <br />
 318      <span>
 319      <?php
 320      /* translators: %s: Link color. */
 321      printf( __( 'Default color: %s', 'twentyeleven' ), '<span id="default-color">' . twentyeleven_get_default_link_color( $options['color_scheme'] ) . '</span>' );
 322      ?>
 323      </span>
 324      <?php
 325  }
 326  
 327  /**
 328   * Renders the Layout setting field.
 329   *
 330   * @since Twenty Eleven 1.3
 331   */
 332  function twentyeleven_settings_field_layout() {
 333      $options = twentyeleven_get_theme_options();
 334      foreach ( twentyeleven_layouts() as $layout ) {
 335          ?>
 336          <div class="layout image-radio-option theme-layout">
 337          <label class="description">
 338              <input type="radio" name="twentyeleven_theme_options[theme_layout]" value="<?php echo esc_attr( $layout['value'] ); ?>" <?php checked( $options['theme_layout'], $layout['value'] ); ?> />
 339              <span>
 340                  <img src="<?php echo esc_url( $layout['thumbnail'] ); ?>" width="136" height="122" alt="" />
 341                  <?php echo esc_html( $layout['label'] ); ?>
 342              </span>
 343          </label>
 344          </div>
 345          <?php
 346      }
 347  }
 348  
 349  /**
 350   * Renders the theme options page for Twenty Eleven.
 351   *
 352   * @since Twenty Eleven 1.2
 353   */
 354  function twentyeleven_theme_options_render_page() {
 355      $theme_name = function_exists( 'wp_get_theme' ) ? wp_get_theme()->display( 'Name' ) : get_option( 'current_theme' );
 356      ?>
 357      <div class="wrap">
 358          <h2>
 359          <?php
 360          /* translators: %s: Theme name. */
 361          printf( __( '%s Theme Options', 'twentyeleven' ), $theme_name );
 362          ?>
 363          </h2>
 364          <?php settings_errors(); ?>
 365  
 366          <form method="post" action="options.php">
 367              <?php
 368                  settings_fields( 'twentyeleven_options' );
 369                  do_settings_sections( 'theme_options' );
 370                  submit_button();
 371              ?>
 372          </form>
 373      </div>
 374      <?php
 375  }
 376  
 377  /**
 378   * Sanitizes and validates form input.
 379   *
 380   * Accepts an array, return a sanitized array.
 381   *
 382   * @see twentyeleven_theme_options_init()
 383   * @todo set up Reset Options action
 384   *
 385   * @since Twenty Eleven 1.0
 386   *
 387   * @param array $input An array of form input.
 388   * @return array<string, string> An array of sanitized and validated form output.
 389   */
 390  function twentyeleven_theme_options_validate( $input ) {
 391      $defaults = twentyeleven_get_default_theme_options();
 392      $output   = $defaults;
 393  
 394      // Color scheme must be in our array of color scheme options.
 395      if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) {
 396          $output['color_scheme'] = $input['color_scheme'];
 397      }
 398  
 399      // Our defaults for the link color may have changed, based on the color scheme.
 400      $defaults['link_color'] = twentyeleven_get_default_link_color( $output['color_scheme'] );
 401      $output['link_color']   = $defaults['link_color'];
 402  
 403      // Link color must be 3 or 6 hexadecimal characters.
 404      if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) {
 405          $output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) );
 406      }
 407  
 408      // Theme layout must be in our array of theme layout options.
 409      if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) {
 410          $output['theme_layout'] = $input['theme_layout'];
 411      }
 412  
 413      /**
 414       * Filters the Twenty Eleven sanitized form input array.
 415       *
 416       * @since Twenty Eleven 1.0
 417       *
 418       * @param array<string, string> $output   An array of sanitized form output.
 419       * @param array                 $input    An array of un-sanitized form input.
 420       * @param array<string, string> $defaults An array of default theme options.
 421       */
 422      return apply_filters( 'twentyeleven_theme_options_validate', $output, $input, $defaults );
 423  }
 424  
 425  /**
 426   * Enqueues the styles for the current color scheme.
 427   *
 428   * @since Twenty Eleven 1.0
 429   */
 430  function twentyeleven_enqueue_color_scheme() {
 431      $options      = twentyeleven_get_theme_options();
 432      $color_scheme = $options['color_scheme'];
 433  
 434      if ( 'dark' === $color_scheme ) {
 435          wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), '20251017' );
 436      }
 437  
 438      /**
 439       * Fires after the styles for the Twenty Eleven color scheme are enqueued.
 440       *
 441       * @since Twenty Eleven 1.0
 442       *
 443       * @param string $color_scheme The color scheme.
 444       */
 445      do_action( 'twentyeleven_enqueue_color_scheme', $color_scheme );
 446  }
 447  add_action( 'wp_enqueue_scripts', 'twentyeleven_enqueue_color_scheme' );
 448  
 449  /**
 450   * Adds a style block to the theme for the current link color.
 451   *
 452   * This function is attached to the wp_head action hook.
 453   *
 454   * @since Twenty Eleven 1.0
 455   */
 456  function twentyeleven_print_link_color_style() {
 457      $options    = twentyeleven_get_theme_options();
 458      $link_color = $options['link_color'];
 459  
 460      $default_options = twentyeleven_get_default_theme_options();
 461  
 462      // Don't do anything if the current link color is the default.
 463      if ( $default_options['link_color'] === $link_color ) {
 464          return;
 465      }
 466      ?>
 467      <style>
 468          /* Link color */
 469          a,
 470          #site-title a:focus,
 471          #site-title a:hover,
 472          #site-title a:active,
 473          .entry-title a:hover,
 474          .entry-title a:focus,
 475          .entry-title a:active,
 476          .widget_twentyeleven_ephemera .comments-link a:hover,
 477          section.recent-posts .other-recent-posts a[rel="bookmark"]:hover,
 478          section.recent-posts .other-recent-posts .comments-link a:hover,
 479          .format-image footer.entry-meta a:hover,
 480          #site-generator a:hover {
 481              color: <?php echo $link_color; ?>;
 482          }
 483          section.recent-posts .other-recent-posts .comments-link a:hover {
 484              border-color: <?php echo $link_color; ?>;
 485          }
 486          article.feature-image.small .entry-summary p a:hover,
 487          .entry-header .comments-link a:hover,
 488          .entry-header .comments-link a:focus,
 489          .entry-header .comments-link a:active,
 490          .feature-slider a.active {
 491              background-color: <?php echo $link_color; ?>;
 492          }
 493      </style>
 494      <?php
 495  }
 496  add_action( 'wp_head', 'twentyeleven_print_link_color_style' );
 497  
 498  /**
 499   * Adds Twenty Eleven layout classes to the array of body classes.
 500   *
 501   * @since Twenty Eleven 1.0
 502   *
 503   * @param string[] $existing_classes An array of existing body classes.
 504   * @return string[] The filtered array of body classes.
 505   */
 506  function twentyeleven_layout_classes( $existing_classes ) {
 507      $options        = twentyeleven_get_theme_options();
 508      $current_layout = $options['theme_layout'];
 509  
 510      if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ), true ) ) {
 511          $classes = array( 'two-column' );
 512      } else {
 513          $classes = array( 'one-column' );
 514      }
 515  
 516      if ( 'content-sidebar' === $current_layout ) {
 517          $classes[] = 'right-sidebar';
 518      } elseif ( 'sidebar-content' === $current_layout ) {
 519          $classes[] = 'left-sidebar';
 520      } else {
 521          $classes[] = $current_layout;
 522      }
 523  
 524      /**
 525       * Filters the Twenty Eleven layout body classes.
 526       *
 527       * @since Twenty Eleven 1.0
 528       *
 529       * @param string[] $classes        An array of body classes.
 530       * @param string   $current_layout The current theme layout.
 531       */
 532      $classes = apply_filters( 'twentyeleven_layout_classes', $classes, $current_layout );
 533  
 534      return array_merge( $existing_classes, $classes );
 535  }
 536  add_filter( 'body_class', 'twentyeleven_layout_classes' );
 537  
 538  /**
 539   * Implements Twenty Eleven theme options into Customizer.
 540   *
 541   * @since Twenty Eleven 1.3
 542   *
 543   * @param WP_Customize_Manager $wp_customize Customizer object.
 544   */
 545  function twentyeleven_customize_register( $wp_customize ) {
 546      $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
 547      $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
 548      $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
 549  
 550      if ( isset( $wp_customize->selective_refresh ) ) {
 551          $wp_customize->selective_refresh->add_partial(
 552              'blogname',
 553              array(
 554                  'selector'            => '#site-title a',
 555                  'container_inclusive' => false,
 556                  'render_callback'     => 'twentyeleven_customize_partial_blogname',
 557              )
 558          );
 559          $wp_customize->selective_refresh->add_partial(
 560              'blogdescription',
 561              array(
 562                  'selector'            => '#site-description',
 563                  'container_inclusive' => false,
 564                  'render_callback'     => 'twentyeleven_customize_partial_blogdescription',
 565              )
 566          );
 567      }
 568  
 569      $options  = twentyeleven_get_theme_options();
 570      $defaults = twentyeleven_get_default_theme_options();
 571  
 572      $wp_customize->add_setting(
 573          'twentyeleven_theme_options[color_scheme]',
 574          array(
 575              'default'    => $defaults['color_scheme'],
 576              'type'       => 'option',
 577              'capability' => 'edit_theme_options',
 578          )
 579      );
 580  
 581      $schemes = twentyeleven_color_schemes();
 582      $choices = array();
 583      foreach ( $schemes as $scheme ) {
 584          $choices[ $scheme['value'] ] = $scheme['label'];
 585      }
 586  
 587      $wp_customize->add_control(
 588          'twentyeleven_color_scheme',
 589          array(
 590              'label'    => __( 'Color Scheme', 'twentyeleven' ),
 591              'section'  => 'colors',
 592              'settings' => 'twentyeleven_theme_options[color_scheme]',
 593              'type'     => 'radio',
 594              'choices'  => $choices,
 595              'priority' => 5,
 596          )
 597      );
 598  
 599      // Link Color (added to Color Scheme section in Customizer).
 600      $wp_customize->add_setting(
 601          'twentyeleven_theme_options[link_color]',
 602          array(
 603              'default'           => twentyeleven_get_default_link_color( $options['color_scheme'] ),
 604              'type'              => 'option',
 605              'sanitize_callback' => 'sanitize_hex_color',
 606              'capability'        => 'edit_theme_options',
 607          )
 608      );
 609  
 610      $wp_customize->add_control(
 611          new WP_Customize_Color_Control(
 612              $wp_customize,
 613              'link_color',
 614              array(
 615                  'label'    => __( 'Link Color', 'twentyeleven' ),
 616                  'section'  => 'colors',
 617                  'settings' => 'twentyeleven_theme_options[link_color]',
 618              )
 619          )
 620      );
 621  
 622      // Default Layout.
 623      $wp_customize->add_section(
 624          'twentyeleven_layout',
 625          array(
 626              'title'    => __( 'Layout', 'twentyeleven' ),
 627              'priority' => 50,
 628          )
 629      );
 630  
 631      $wp_customize->add_setting(
 632          'twentyeleven_theme_options[theme_layout]',
 633          array(
 634              'type'              => 'option',
 635              'default'           => $defaults['theme_layout'],
 636              'sanitize_callback' => 'sanitize_key',
 637          )
 638      );
 639  
 640      $layouts = twentyeleven_layouts();
 641      $choices = array();
 642      foreach ( $layouts as $layout ) {
 643          $choices[ $layout['value'] ] = $layout['label'];
 644      }
 645  
 646      $wp_customize->add_control(
 647          'twentyeleven_theme_options[theme_layout]',
 648          array(
 649              'section' => 'twentyeleven_layout',
 650              'type'    => 'radio',
 651              'choices' => $choices,
 652          )
 653      );
 654  }
 655  add_action( 'customize_register', 'twentyeleven_customize_register' );
 656  
 657  /**
 658   * Renders the site title for the selective refresh partial.
 659   *
 660   * @since Twenty Eleven 2.4
 661   *
 662   * @see twentyeleven_customize_register()
 663   *
 664   * @return void
 665   */
 666  function twentyeleven_customize_partial_blogname() {
 667      bloginfo( 'name' );
 668  }
 669  
 670  /**
 671   * Renders the site tagline for the selective refresh partial.
 672   *
 673   * @since Twenty Eleven 2.4
 674   *
 675   * @see twentyeleven_customize_register()
 676   *
 677   * @return void
 678   */
 679  function twentyeleven_customize_partial_blogdescription() {
 680      bloginfo( 'description' );
 681  }
 682  
 683  /**
 684   * Binds JS handlers to make Customizer preview reload changes asynchronously.
 685   *
 686   * Used with blogname and blogdescription.
 687   *
 688   * @since Twenty Eleven 1.3
 689   */
 690  function twentyeleven_customize_preview_js() {
 691      wp_enqueue_script( 'twentyeleven-customizer', get_template_directory_uri() . '/inc/theme-customizer.js', array( 'customize-preview' ), '20250217', array( 'in_footer' => true ) );
 692  }
 693  add_action( 'customize_preview_init', 'twentyeleven_customize_preview_js' );


Generated : Thu May 14 08:20:03 2026 Cross-referenced by PHPXref