PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/public_html/wp-content/themes/genesis/lib/admin/customizer.php

https://gitlab.com/hop23typhu/list-theme
PHP | 357 lines | 263 code | 60 blank | 34 comment | 5 complexity | 999f4e442e236a2209edb1d3485f692c MD5 | raw file
  1. <?php
  2. /**
  3. * Genesis Framework.
  4. *
  5. * WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
  6. * Please do all modifications in the form of a child theme.
  7. *
  8. * @package Genesis\Admin
  9. * @author StudioPress
  10. * @license GPL-2.0+
  11. * @link http://my.studiopress.com/themes/genesis/
  12. */
  13. /**
  14. *
  15. */
  16. abstract class Genesis_Customizer_Base {
  17. /**
  18. * Define defaults, call the `register` method, add css to head.
  19. */
  20. public function __construct() {
  21. //** Register new customizer elements
  22. if ( method_exists( $this, 'register' ) ) {
  23. add_action( 'customize_register', array( $this, 'register'), 15 );
  24. } else {
  25. _doing_it_wrong( 'Genesis_Customizer_Base', __( 'When extending Genesis_Customizer_Base, you must create a register method.', 'genesis' ) );
  26. }
  27. //* Customizer scripts
  28. if ( method_exists( $this, 'scripts' ) ) {
  29. add_action( 'customize_preview_init', 'scripts' );
  30. }
  31. }
  32. protected function get_field_name( $name ) {
  33. return sprintf( '%s[%s]', $this->settings_field, $name );
  34. }
  35. protected function get_field_id( $id ) {
  36. return sprintf( '%s[%s]', $this->settings_field, $id );
  37. }
  38. protected function get_field_value( $key ) {
  39. return genesis_get_option( $key, $this->settings_field );
  40. }
  41. }
  42. /**
  43. *
  44. */
  45. class Genesis_Customizer extends Genesis_Customizer_Base {
  46. /**
  47. * Settings field.
  48. */
  49. public $settings_field = 'genesis-settings';
  50. /**
  51. *
  52. */
  53. public function register( $wp_customize ) {
  54. $this->color_scheme( $wp_customize );
  55. $this->layout( $wp_customize );
  56. if ( current_theme_supports( 'genesis-breadcrumbs' ) ) {
  57. $this->breadcrumbs( $wp_customize );
  58. }
  59. $this->comments( $wp_customize );
  60. $this->archives( $wp_customize );
  61. }
  62. private function color_scheme( $wp_customize ) {
  63. //** Color Selector
  64. if ( ! current_theme_supports( 'genesis-style-selector' ) )
  65. return;
  66. //** Add Section
  67. $wp_customize->add_section(
  68. 'genesis_color_scheme',
  69. array(
  70. 'title' => __( 'Color Scheme', 'genesis' ),
  71. 'priority' => 150,
  72. )
  73. );
  74. $wp_customize->add_setting(
  75. $this->get_field_name( 'style_selection' ),
  76. array(
  77. 'default' => '',
  78. 'type' => 'option',
  79. )
  80. );
  81. $wp_customize->add_control(
  82. 'genesis_color_scheme',
  83. array(
  84. 'label' => __( 'Select Color Style', 'genesis'),
  85. 'section' => 'genesis_color_scheme',
  86. 'settings' => $this->get_field_name( 'style_selection' ),
  87. 'type' => 'select',
  88. 'choices' => array_merge(
  89. array( '' => __( 'Default', 'genesis' ) ),
  90. array_shift( get_theme_support( 'genesis-style-selector' ) )
  91. ),
  92. )
  93. );
  94. }
  95. private function layout( $wp_customize ) {
  96. $wp_customize->add_section(
  97. 'genesis_layout',
  98. array(
  99. 'title' => __( 'Site Layout', 'genesis' ),
  100. 'priority' => 150,
  101. )
  102. );
  103. $wp_customize->add_setting(
  104. $this->get_field_name( 'site_layout' ),
  105. array(
  106. 'default' => genesis_get_default_layout(),
  107. 'type' => 'option',
  108. )
  109. );
  110. $wp_customize->add_control(
  111. 'genesis_layout',
  112. array(
  113. 'label' => __( 'Select Default Layout', 'genesis' ),
  114. 'section' => 'genesis_layout',
  115. 'settings' => $this->get_field_name( 'site_layout' ),
  116. 'type' => 'select',
  117. 'choices' => genesis_get_layouts_for_customizer(),
  118. )
  119. );
  120. }
  121. private function breadcrumbs( $wp_customize ) {
  122. $wp_customize->add_section(
  123. 'genesis_breadcrumbs',
  124. array(
  125. 'title' => __( 'Breadcrumbs', 'genesis' ),
  126. 'priority' => 150,
  127. )
  128. );
  129. $settings = array(
  130. 'breadcrumb_home' => __( 'Homepage', 'genesis' ),
  131. 'breadcrumb_front_page' => __( 'Front Page', 'genesis' ),
  132. 'breadcrumb_posts_page' => __( 'Posts Page', 'genesis' ),
  133. 'breadcrumb_single' => __( 'Single', 'genesis' ),
  134. 'breadcrumb_page' => __( 'Page', 'genesis' ),
  135. 'breadcrumb_archive' => __( 'Archive', 'genesis' ),
  136. 'breadcrumb_404' => __( '404', 'genesis' ),
  137. 'breadcrumb_attachment' => __( 'Attachment/Media', 'genesis' ),
  138. );
  139. $priority = 1;
  140. foreach ( $settings as $setting => $label ) {
  141. $wp_customize->add_setting(
  142. $this->get_field_name( $setting ),
  143. array(
  144. 'default' => 0,
  145. 'type' => 'option',
  146. )
  147. );
  148. $wp_customize->add_control(
  149. 'genesis_' . $setting,
  150. array(
  151. 'priority' => $priority,
  152. 'label' => $label,
  153. 'section' => 'genesis_breadcrumbs',
  154. 'settings' => $this->get_field_name( $setting ),
  155. 'type' => 'checkbox',
  156. )
  157. );
  158. $priority++;
  159. }
  160. }
  161. private function comments( $wp_customize ) {
  162. $wp_customize->add_section(
  163. 'genesis_comments',
  164. array(
  165. 'title' => __( 'Comments and Trackbacks', 'genesis' ),
  166. 'priority' => 150,
  167. )
  168. );
  169. $settings = array(
  170. 'comments_posts' => __( 'Enable Comments on Posts?', 'genesis' ),
  171. 'comments_pages' => __( 'Enable Comments on Pages?', 'genesis' ),
  172. 'trackbacks_posts' => __( 'Enable Trackbacks on Posts?', 'genesis' ),
  173. 'trackbacks_pages' => __( 'Enable Trackbacks on Pages?', 'genesis' ),
  174. );
  175. foreach ( $settings as $setting => $label ) {
  176. $wp_customize->add_setting(
  177. $this->get_field_name( $setting ),
  178. array(
  179. 'default' => 0,
  180. 'type' => 'option',
  181. )
  182. );
  183. $wp_customize->add_control(
  184. 'genesis_' . $setting,
  185. array(
  186. 'label' => $label,
  187. 'section' => 'genesis_comments',
  188. 'settings' => $this->get_field_name( $setting ),
  189. 'type' => 'checkbox',
  190. )
  191. );
  192. }
  193. }
  194. private function archives( $wp_customize ) {
  195. $wp_customize->add_section(
  196. 'genesis_archives',
  197. array(
  198. 'title' => __( 'Content Archives', 'genesis' ),
  199. 'description' => __( 'These options will affect any blog listings page, including archive, author, blog, category, search, and tag pages.', 'genesis' ),
  200. 'priority' => 150,
  201. )
  202. );
  203. //* Setting key and default value array
  204. $settings = array(
  205. 'content_archive' => 'full',
  206. 'content_archive_limit' => '',
  207. 'content_archive_thumbnail' => 0,
  208. 'image_size' => '',
  209. 'image_alignment' => 'alignleft',
  210. 'posts_nav' => 'numeric',
  211. );
  212. foreach ( $settings as $setting => $default ) {
  213. $wp_customize->add_setting(
  214. $this->get_field_name( $setting ),
  215. array(
  216. 'default' => $default,
  217. 'type' => 'option',
  218. )
  219. );
  220. }
  221. $wp_customize->add_control(
  222. 'genesis_content_archive',
  223. array(
  224. 'priority' => 1,
  225. 'label' => __( 'Select one of the following', 'genesis' ),
  226. 'section' => 'genesis_archives',
  227. 'settings' => $this->get_field_name( 'content_archive' ),
  228. 'type' => 'select',
  229. 'choices' => array(
  230. 'full' => __( 'Display post content', 'genesis' ),
  231. 'excerpts' => __( 'Display post excerpts', 'genesis' ),
  232. ),
  233. )
  234. );
  235. $wp_customize->add_control(
  236. 'genesis_content_archive_limit',
  237. array(
  238. 'label' => __( 'Limit content to how many characters? (0 for no limit)', 'genesis' ),
  239. 'section' => 'genesis_archives',
  240. 'settings' => $this->get_field_name( 'content_archive_limit' ),
  241. )
  242. );
  243. $wp_customize->add_control(
  244. 'genesis_content_archive_thumbnail',
  245. array(
  246. 'label' => __( 'Display the featured image?', 'genesis' ),
  247. 'section' => 'genesis_archives',
  248. 'settings' => $this->get_field_name( 'content_archive_thumbnail' ),
  249. 'type' => 'checkbox',
  250. )
  251. );
  252. $wp_customize->add_control(
  253. 'genesis_image_size',
  254. array(
  255. 'label' => __( 'Featured image size', 'genesis' ),
  256. 'section' => 'genesis_archives',
  257. 'settings' => $this->get_field_name( 'image_size' ),
  258. 'type' => 'select',
  259. 'choices' => genesis_get_image_sizes_for_customizer(),
  260. )
  261. );
  262. $wp_customize->add_control(
  263. 'genesis_image_alignment',
  264. array(
  265. 'label' => __( 'Featured image alignment', 'genesis' ),
  266. 'section' => 'genesis_archives',
  267. 'settings' => $this->get_field_name( 'image_alignment' ),
  268. 'type' => 'select',
  269. 'choices' => array(
  270. '' => __( '- None -', 'genesis' ),
  271. 'alignleft' => __( 'Left', 'genesis' ),
  272. 'alignright' => __( 'Right', 'genesis' ),
  273. ),
  274. )
  275. );
  276. $wp_customize->add_control(
  277. 'genesis_posts_nav',
  278. array(
  279. 'label' => __( 'Post Navigation Type', 'genesis' ),
  280. 'section' => 'genesis_archives',
  281. 'settings' => $this->get_field_name( 'posts_nav' ),
  282. 'type' => 'select',
  283. 'choices' => array(
  284. 'prev-next' => __( 'Previous / Next', 'genesis' ),
  285. 'numeric' => __( 'Numeric', 'genesis' ),
  286. ),
  287. )
  288. );
  289. }
  290. }
  291. add_action( 'init', 'genesis_customizer_init' );
  292. /**
  293. *
  294. */
  295. function genesis_customizer_init() {
  296. new Genesis_Customizer;
  297. }