/inc/theme-options.php

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