/wp-content/themes/eportfolio/inc/customize/core/control.php

https://github.com/livinglab/openlab · PHP · 212 lines · 88 code · 27 blank · 97 comment · 6 complexity · 5ee2ef71198701930a3e0e4c17dcc092 MD5 · raw file

  1. <?php
  2. /**
  3. * Custom Customizer Controls.
  4. *
  5. * @package ePortfolio
  6. */
  7. /**
  8. * Customize Control for Taxonomy Select.
  9. *
  10. * @since 1.0.0
  11. *
  12. * @see WP_Customize_Control
  13. */
  14. class eportfolio_Dropdown_Taxonomies_Control extends WP_Customize_Control {
  15. /**
  16. * Control type.
  17. *
  18. * @access public
  19. * @var string
  20. */
  21. public $type = 'dropdown-taxonomies';
  22. /**
  23. * Taxonomy.
  24. *
  25. * @access public
  26. * @var string
  27. */
  28. public $taxonomy = '';
  29. /**
  30. * Constructor.
  31. *
  32. * @since 1.0.0
  33. *
  34. * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  35. * @param string $id Control ID.
  36. * @param array $args Optional. Arguments to override class property defaults.
  37. */
  38. public function __construct( $manager, $id, $args = array() ) {
  39. $our_taxonomy = 'category';
  40. if ( isset( $args['taxonomy'] ) ) {
  41. $taxonomy_exist = taxonomy_exists( esc_attr( $args['taxonomy'] ) );
  42. if ( true === $taxonomy_exist ) {
  43. $our_taxonomy = esc_attr( $args['taxonomy'] );
  44. }
  45. }
  46. $args['taxonomy'] = $our_taxonomy;
  47. $this->taxonomy = esc_attr( $our_taxonomy );
  48. parent::__construct( $manager, $id, $args );
  49. }
  50. /**
  51. * Render content.
  52. *
  53. * @since 1.0.0
  54. */
  55. public function render_content() {
  56. $tax_args = array(
  57. 'hierarchical' => 0,
  58. 'taxonomy' => $this->taxonomy,
  59. );
  60. $all_taxonomies = get_categories( $tax_args );
  61. ?>
  62. <label>
  63. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  64. <select <?php $this->link(); ?>>
  65. <?php
  66. printf( '<option value="%s" %s>%s</option>', '', selected( $this->value(), '', false ), ' ' );
  67. ?>
  68. <?php if ( ! empty( $all_taxonomies ) ) : ?>
  69. <?php foreach ( $all_taxonomies as $key => $tax ) : ?>
  70. <?php
  71. printf( '<option value="%s" %s>%s</option>', esc_attr( $tax->term_id ), selected( $this->value(), $tax->term_id, false ), esc_html( $tax->name ) );
  72. ?>
  73. <?php endforeach ?>
  74. <?php endif ?>
  75. </select>
  76. </label>
  77. <?php
  78. }
  79. }
  80. /**
  81. * Customize Control for Radio Image.
  82. *
  83. * @since 1.0.0
  84. *
  85. * @see WP_Customize_Control
  86. */
  87. class eportfolio_Radio_Image_Control extends WP_Customize_Control {
  88. /**
  89. * Control type.
  90. *
  91. * @access public
  92. * @var string
  93. */
  94. public $type = 'radio-image';
  95. /**
  96. * Render content.
  97. *
  98. * @since 1.0.0
  99. */
  100. public function render_content() {
  101. if ( empty( $this->choices ) ) {
  102. return;
  103. }
  104. $name = '_customize-radio-' . $this->id;
  105. ?>
  106. <label>
  107. <?php if ( ! empty( $this->label ) ) : ?>
  108. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  109. <?php endif; ?>
  110. <?php if ( ! empty( $this->description ) ) : ?>
  111. <span class="description customize-control-description"><?php echo $this->description; ?></span>
  112. <?php endif; ?>
  113. <?php foreach ( $this->choices as $value => $label ) : ?>
  114. <label>
  115. <input type="radio" value="<?php echo esc_attr( $value ); ?>" <?php $this->link();
  116. checked( $this->value(), $value ); ?> class="np-radio-image" name="<?php echo esc_attr( $name ); ?>"/>
  117. <span><img src="<?php echo esc_url( $label ); ?>" alt="<?php echo esc_attr( $value ); ?>" /></span>
  118. </label>
  119. <?php endforeach; ?>
  120. </label>
  121. <?php
  122. }
  123. }
  124. /**
  125. * Upsell customizer section.
  126. *
  127. * @since 1.0.0
  128. * @access public
  129. */
  130. class eportfolio_Customize_Section_Upsell extends WP_Customize_Section {
  131. /**
  132. * The type of customize section being rendered.
  133. *
  134. * @since 1.0.0
  135. * @access public
  136. * @var string
  137. */
  138. public $type = 'upsell';
  139. /**
  140. * Custom button text to output.
  141. *
  142. * @since 1.0.0
  143. * @access public
  144. * @var string
  145. */
  146. public $pro_text = '';
  147. /**
  148. * Custom pro button URL.
  149. *
  150. * @since 1.0.0
  151. * @access public
  152. * @var string
  153. */
  154. public $pro_url = '';
  155. /**
  156. * Add custom parameters to pass to the JS via JSON.
  157. *
  158. * @since 1.0.0
  159. * @access public
  160. * @return void
  161. */
  162. public function json() {
  163. $json = parent::json();
  164. $json['pro_text'] = $this->pro_text;
  165. $json['pro_url'] = esc_url( $this->pro_url );
  166. return $json;
  167. }
  168. /**
  169. * Outputs the Underscore.js template.
  170. *
  171. * @since 1.0.0
  172. * @access public
  173. * @return void
  174. */
  175. protected function render_template() { ?>
  176. <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
  177. <h3 class="accordion-section-title">
  178. {{ data.title }}
  179. <# if ( data.pro_text && data.pro_url ) { #>
  180. <a href="{{ data.pro_url }}" class="button button-secondary alignright" target="_blank">{{ data.pro_text }}</a>
  181. <# } #>
  182. </h3>
  183. </li>
  184. <?php }
  185. }