No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

207 líneas
6.4 KiB

  1. <?php
  2. /**
  3. * Twenty Seventeen: Customizer
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Seventeen
  7. * @since 1.0
  8. */
  9. /**
  10. * Add postMessage support for site title and description for the Theme Customizer.
  11. *
  12. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  13. */
  14. function twentyseventeen_customize_register( $wp_customize ) {
  15. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  16. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  17. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  18. $wp_customize->selective_refresh->add_partial( 'blogname', array(
  19. 'selector' => '.site-title a',
  20. 'render_callback' => 'twentyseventeen_customize_partial_blogname',
  21. ) );
  22. $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
  23. 'selector' => '.site-description',
  24. 'render_callback' => 'twentyseventeen_customize_partial_blogdescription',
  25. ) );
  26. /**
  27. * Custom colors.
  28. */
  29. $wp_customize->add_setting( 'colorscheme', array(
  30. 'default' => 'light',
  31. 'transport' => 'postMessage',
  32. 'sanitize_callback' => 'twentyseventeen_sanitize_colorscheme',
  33. ) );
  34. $wp_customize->add_setting( 'colorscheme_hue', array(
  35. 'default' => 250,
  36. 'transport' => 'postMessage',
  37. 'sanitize_callback' => 'absint', // The hue is stored as a positive integer.
  38. ) );
  39. $wp_customize->add_control( 'colorscheme', array(
  40. 'type' => 'radio',
  41. 'label' => __( 'Color Scheme', 'twentyseventeen' ),
  42. 'choices' => array(
  43. 'light' => __( 'Light', 'twentyseventeen' ),
  44. 'dark' => __( 'Dark', 'twentyseventeen' ),
  45. 'custom' => __( 'Custom', 'twentyseventeen' ),
  46. ),
  47. 'section' => 'colors',
  48. 'priority' => 5,
  49. ) );
  50. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'colorscheme_hue', array(
  51. 'mode' => 'hue',
  52. 'section' => 'colors',
  53. 'priority' => 6,
  54. ) ) );
  55. /**
  56. * Theme options.
  57. */
  58. $wp_customize->add_section( 'theme_options', array(
  59. 'title' => __( 'Theme Options', 'twentyseventeen' ),
  60. 'priority' => 130, // Before Additional CSS.
  61. ) );
  62. $wp_customize->add_setting( 'page_layout', array(
  63. 'default' => 'two-column',
  64. 'sanitize_callback' => 'twentyseventeen_sanitize_page_layout',
  65. 'transport' => 'postMessage',
  66. ) );
  67. $wp_customize->add_control( 'page_layout', array(
  68. 'label' => __( 'Page Layout', 'twentyseventeen' ),
  69. 'section' => 'theme_options',
  70. 'type' => 'radio',
  71. 'description' => __( 'When the two column layout is assigned, the page title is in one column and content is in the other.', 'twentyseventeen' ),
  72. 'choices' => array(
  73. 'one-column' => __( 'One Column', 'twentyseventeen' ),
  74. 'two-column' => __( 'Two Column', 'twentyseventeen' ),
  75. ),
  76. 'active_callback' => 'twentyseventeen_is_view_with_layout_option',
  77. ) );
  78. /**
  79. * Filter number of front page sections in Twenty Seventeen.
  80. *
  81. * @since Twenty Seventeen 1.0
  82. *
  83. * @param $num_sections integer
  84. */
  85. $num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
  86. // Create a setting and control for each of the sections available in the theme.
  87. for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
  88. $wp_customize->add_setting( 'panel_' . $i, array(
  89. 'default' => false,
  90. 'sanitize_callback' => 'absint',
  91. 'transport' => 'postMessage',
  92. ) );
  93. $wp_customize->add_control( 'panel_' . $i, array(
  94. /* translators: %d is the front page section number */
  95. 'label' => sprintf( __( 'Front Page Section %d Content', 'twentyseventeen' ), $i ),
  96. 'description' => ( 1 !== $i ? '' : __( 'Select pages to feature in each area from the dropdowns. Add an image to a section by setting a featured image in the page editor. Empty sections will not be displayed.', 'twentyseventeen' ) ),
  97. 'section' => 'theme_options',
  98. 'type' => 'dropdown-pages',
  99. 'allow_addition' => true,
  100. 'active_callback' => 'twentyseventeen_is_static_front_page',
  101. ) );
  102. $wp_customize->selective_refresh->add_partial( 'panel_' . $i, array(
  103. 'selector' => '#panel' . $i,
  104. 'render_callback' => 'twentyseventeen_front_page_section',
  105. 'container_inclusive' => true,
  106. ) );
  107. }
  108. }
  109. add_action( 'customize_register', 'twentyseventeen_customize_register' );
  110. /**
  111. * Sanitize the page layout options.
  112. */
  113. function twentyseventeen_sanitize_page_layout( $input ) {
  114. $valid = array(
  115. 'one-column' => __( 'One Column', 'twentyseventeen' ),
  116. 'two-column' => __( 'Two Column', 'twentyseventeen' ),
  117. );
  118. if ( array_key_exists( $input, $valid ) ) {
  119. return $input;
  120. }
  121. return '';
  122. }
  123. /**
  124. * Sanitize the colorscheme.
  125. */
  126. function twentyseventeen_sanitize_colorscheme( $input ) {
  127. $valid = array( 'light', 'dark', 'custom' );
  128. if ( in_array( $input, $valid ) ) {
  129. return $input;
  130. }
  131. return 'light';
  132. }
  133. /**
  134. * Render the site title for the selective refresh partial.
  135. *
  136. * @since Twenty Seventeen 1.0
  137. * @see twentyseventeen_customize_register()
  138. *
  139. * @return void
  140. */
  141. function twentyseventeen_customize_partial_blogname() {
  142. bloginfo( 'name' );
  143. }
  144. /**
  145. * Render the site tagline for the selective refresh partial.
  146. *
  147. * @since Twenty Seventeen 1.0
  148. * @see twentyseventeen_customize_register()
  149. *
  150. * @return void
  151. */
  152. function twentyseventeen_customize_partial_blogdescription() {
  153. bloginfo( 'description' );
  154. }
  155. /**
  156. * Return whether we're previewing the front page and it's a static page.
  157. */
  158. function twentyseventeen_is_static_front_page() {
  159. return ( is_front_page() && ! is_home() );
  160. }
  161. /**
  162. * Return whether we're on a view that supports a one or two column layout.
  163. */
  164. function twentyseventeen_is_view_with_layout_option() {
  165. // This option is available on all pages. It's also available on archives when there isn't a sidebar.
  166. return ( is_page() || ( is_archive() && ! is_active_sidebar( 'sidebar-1' ) ) );
  167. }
  168. /**
  169. * Bind JS handlers to instantly live-preview changes.
  170. */
  171. function twentyseventeen_customize_preview_js() {
  172. wp_enqueue_script( 'twentyseventeen-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array( 'customize-preview' ), '1.0', true );
  173. }
  174. add_action( 'customize_preview_init', 'twentyseventeen_customize_preview_js' );
  175. /**
  176. * Load dynamic logic for the customizer controls area.
  177. */
  178. function twentyseventeen_panels_js() {
  179. wp_enqueue_script( 'twentyseventeen-customize-controls', get_theme_file_uri( '/assets/js/customize-controls.js' ), array(), '1.0', true );
  180. }
  181. add_action( 'customize_controls_enqueue_scripts', 'twentyseventeen_panels_js' );