Diff Checker

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