Guest User

class-wf-fields.php

a guest
Dec 24th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.15 KB | None | 0 0
  1. <?php
  2. // File Security Check.
  3. if ( ! defined( 'ABSPATH' ) ) exit;
  4.  
  5. class WF_Fields {
  6. protected $_token;
  7. protected $_settings;
  8. protected $_sections;
  9. protected $_fields;
  10.  
  11. protected $_assets_url;
  12.  
  13. protected $_has_range;
  14. protected $_has_imageselector;
  15. protected $_has_colourpicker;
  16. protected $_has_calendar;
  17. protected $_has_masked_input;
  18. protected $_has_typography;
  19. protected $_has_upload;
  20. protected $_has_select;
  21.  
  22. protected $_processed_sections;
  23.  
  24. protected $_extra_hidden_fields;
  25.  
  26. protected $_render_submit_button;
  27.  
  28. protected $_tabs;
  29.  
  30. protected $_wrappers;
  31.  
  32. /**
  33. * Constructor function.
  34. * @access public
  35. * @since 6.0.0
  36. * @return void
  37. */
  38. public function __construct () {
  39. $this->_token = 'woothemes';
  40. $this->_sections = array();
  41. $this->_fields = array();
  42.  
  43. $this->_has_range = false;
  44. $this->_has_imageselector = false;
  45. $this->_has_colourpicker = false;
  46. $this->_has_calendar = false;
  47. $this->_has_masked_input = false;
  48. $this->_has_typography = false;
  49. $this->_has_upload = false;
  50. $this->_has_select = false;
  51.  
  52. $this->_processed_sections = array();
  53.  
  54. $this->_extra_hidden_fields = array();
  55.  
  56. $this->_render_submit_button = true;
  57.  
  58. $this->_assets_url = WF()->get_assets_url();
  59.  
  60. $this->_wrappers = array();
  61.  
  62. // Set default field wrappers.
  63. $this->__set( 'wrapper_start', '<table class="form-table">' );
  64. $this->__set( 'wrapper_end', '</table>' );
  65. } // End __construct()
  66.  
  67. /**
  68. * Initialise the settings sections and fields.
  69. * @access public
  70. * @since 6.0.0
  71. * @param array $data Array of settings data to be parsed.
  72. * @return boolean/object true if successful, WP_Error object if failed.
  73. */
  74. public function init ( $data = array() ) {
  75. if ( 0 >= count( $data ) ) return new WP_Error( 'bad_settings_data', __( 'The settings data provided is malformed. Please try again.', 'woothemes' ) );
  76.  
  77. $this->init_sections( $data );
  78. $this->init_fields( $data );
  79. } // End init()
  80.  
  81. /**
  82. * Generic setter for protected properties.
  83. * @access public
  84. * @since 6.0.0
  85. * @param string $key The key to denote which property is to be set.
  86. * @param mixed $value The value to which to set the property (casting should happen on a per-case basis).
  87. * @return mixed
  88. */
  89. public function __set ( $key, $value ) {
  90. switch ( $key ) {
  91. case 'has_tabs':
  92. $this->_has_tabs = (bool)$value;
  93. break;
  94. case 'token':
  95. $this->_token = $value;
  96. break;
  97. case 'wrapper_start':
  98. $this->_wrappers['wrapper_start'] = $value;
  99. break;
  100. case 'wrapper_end':
  101. $this->_wrappers['wrapper_end'] = $value;
  102. break;
  103. case 'assets_url':
  104. $this->_assets_url = esc_url( $value );
  105. break;
  106. case 'extra_hidden_fields':
  107. $this->_extra_hidden_fields = (array)$value;
  108. break;
  109. case 'fields':
  110. $this->_fields = (array)$value;
  111. break;
  112. case 'sections':
  113. $this->_sections = (array)$value;
  114. break;
  115. case 'render_submit_button':
  116. $this->_render_submit_button = (bool)$value;
  117. break;
  118. default:
  119. break;
  120. }
  121. } // End __set()
  122.  
  123. /**
  124. * Generic getter for protected properties.
  125. * @access public
  126. * @since 6.0.0
  127. * @param string $key The key to denote which property is to be set.
  128. * @return mixed
  129. */
  130. public function __get ( $key ) {
  131. switch ( $key ) {
  132. case 'has_tabs':
  133. $value = (bool)$this->_has_tabs;
  134. break;
  135. case 'token':
  136. $value = $this->_token;
  137. break;
  138. case 'wrapper_start':
  139. $value = $this->_wrappers['wrapper_start'];
  140. break;
  141. case 'wrapper_end':
  142. $value = $this->_wrappers['wrapper_end'];
  143. break;
  144. case 'assets_url':
  145. $value = $this->_assets_url;
  146. break;
  147. case 'extra_hidden_fields':
  148. $value = (array)$this->_extra_hidden_fields;
  149. break;
  150. case 'fields':
  151. $value = (array)$this->_fields;
  152. break;
  153. case 'sections':
  154. $value = (array)$this->_sections;
  155. break;
  156. case 'render_submit_button':
  157. $value = (bool)$this->_render_submit_button;
  158. break;
  159. default:
  160. break;
  161. }
  162. return $value;
  163. } // End __get()
  164.  
  165. /**
  166. * Prepare the given data to be validated.
  167. * @access public
  168. * @since 6.0.0
  169. * @return void
  170. */
  171. public function prepare_data_for_validation ( $data ) {
  172. $fields = $this->_fields;
  173.  
  174. $prepared_data = array();
  175.  
  176. // Bring the fields in a "multi_field" up to the top of the array, for validation.
  177. $fields = $this->maybe_bubble_up_multi_fields( $fields );
  178.  
  179. $accepted_keys = array_keys( $fields );
  180.  
  181. if ( 0 < count( $accepted_keys ) ) {
  182. foreach ( $accepted_keys as $k ) {
  183. // Last minute preservation of the *-id keys for upload fields.
  184. if ( in_array( $fields[$k]['type'], array( 'upload', 'upload_min' ) ) ) {
  185. $accepted_keys[] = $k . '-id';
  186. $field_data = $fields[$k];
  187. $field_data['type'] = 'upload_field_id';
  188. $fields[$k . '-id'] = $field_data;
  189. $this->_fields[$k . '-id'] = $field_data;
  190. }
  191. }
  192. }
  193.  
  194. if ( is_array( $data ) && 0 < count( $data ) ) {
  195. foreach ( $data as $k => $v ) {
  196. // Remove any keys which aren't meant to be validated and stored.
  197. if ( ! isset( $fields[$k] ) ) {
  198. continue;
  199. }
  200. // If the current field type isn't supported, don't validate or store it.
  201. if ( ! in_array( $fields[$k]['type'], $this->get_supported_fields() ) ) {
  202. continue;
  203. }
  204.  
  205. if ( in_array( $k, $accepted_keys ) ) {
  206. $prepared_data[$k] = $v;
  207. }
  208. }
  209. }
  210.  
  211. return $prepared_data;
  212. } // End prepare_data_for_validation()
  213.  
  214. /**
  215. * Move multi_field fields in the given array, into the top index, to prepare for validation.
  216. * @access public
  217. * @since 6.0.0
  218. * @return void
  219. */
  220. public function maybe_bubble_up_multi_fields ( $fields ) {
  221. if ( 0 < count( $fields ) ) {
  222. foreach ( $fields as $k => $v ) {
  223. if ( isset( $v['type'] ) && 'multi_field' == $v['type'] && isset( $v['multi_fields'] ) ) {
  224. foreach ( $v['multi_fields'] as $i => $j ) {
  225. if ( ! isset( $fields[$i] ) ) {
  226. $fields[$i] = $j;
  227. unset( $fields[$k] );
  228. }
  229. }
  230. }
  231. }
  232. }
  233. return $fields;
  234. } // End maybe_bubble_up_multi_fields()
  235.  
  236. /**
  237. * Validate the given field data.
  238. * @access public
  239. * @since 6.0.0
  240. * @return void
  241. */
  242. public function validate_fields ( $data, $section = '' ) {
  243. if ( ! is_array( $data ) || 0 >= count( $data ) ) return new WP_Error( 'bad_field_data', __( 'The provided field data is invalid and cannot be validated.', 'woothemes' ) );
  244.  
  245. $sections_to_scan = array();
  246.  
  247. // No section has been applied. Assume it's the first.
  248. if ( '' == $section && 'all_fields' != $section ) {
  249. $all_sections = $this->_sections;
  250. if ( is_array( $all_sections ) && 0 < count( $all_sections ) ) {
  251. foreach ( $all_sections as $k => $v ) {
  252. $section = $k;
  253. break;
  254. }
  255. }
  256. }
  257.  
  258. // Store the current top section.
  259. $sections_to_scan[] = $section;
  260. // Check if we have sub-sections.
  261. if ( isset( $this->_sections[$section]['children'] ) && 0 < count( (array)$this->_sections[$section]['children'] ) ) {
  262. foreach ( $this->_sections[$section]['children'] as $k => $v ) {
  263. $sections_to_scan[] = $v['token'];
  264. }
  265. }
  266.  
  267. // Retrieve all fields in this current screen (main and sub-sections).
  268. $fields_by_section = array();
  269.  
  270. foreach ( $sections_to_scan as $k => $v ) {
  271. $field_data = $this->_get_fields_by_section( $v );
  272. $fields_by_section = array_merge( $fields_by_section, $field_data );
  273. }
  274.  
  275. // Make sure checkboxes are taken care of.
  276. // As well as multicheck fields.
  277. if ( 0 < count( $fields_by_section ) ) {
  278. foreach ( $fields_by_section as $k => $v ) {
  279. if ( ! in_array( $v['type'], array( 'checkbox', 'multicheck', 'multicheck2' ) ) ) {
  280. unset( $fields_by_section[$k] );
  281. }
  282. }
  283. }
  284.  
  285. // If we have fields left, merge them in.
  286. if ( 0 < count( $fields_by_section ) ) {
  287. foreach ( $fields_by_section as $k => $v ) {
  288. if ( ! isset( $data[$k] ) ) {
  289. $data[$k] = '';
  290. }
  291. }
  292. }
  293.  
  294. $data = $this->prepare_data_for_validation( $data );
  295.  
  296. $fields = $this->_fields;
  297.  
  298. // Bring the fields in a "multi_field" up to the top of the array, for validation.
  299. $fields = $this->maybe_bubble_up_multi_fields( $fields );
  300.  
  301. if ( 0 < count( $data ) ) {
  302. foreach ( $data as $k => $v ) {
  303. if ( ! isset( $fields[$k] ) ) continue;
  304.  
  305. // Determine if a method is available for validating this field.
  306. $method = 'validate_field_' . $fields[$k]['type'];
  307. if ( ! method_exists( $this, $method ) ) {
  308. if ( true == (bool)apply_filters( 'wf_validate_field_' . $fields[$k]['type'] . '_use_default', true ) ) {
  309. $method = 'validate_field_text';
  310. } else {
  311. $method = '';
  312. }
  313. }
  314.  
  315. // If we have an internal method for validation, filter and apply it.
  316. if ( '' != $method ) {
  317. add_filter( 'wf_validate_field_' . $fields[$k]['type'], array( $this, $method ), 10, 2 );
  318. }
  319.  
  320. $method_output = apply_filters( 'wf_validate_field_' . $fields[$k]['type'], $v, $fields[$k] );
  321. // $method_output = apply_filters( 'wf_validate_field_' . $k, $v, $fields[$k] );
  322.  
  323. if ( is_wp_error( $method_output ) ) {
  324. // if ( defined( 'WP_DEBUG' ) || true == constant( 'WP_DEBUG' ) ) print_r( $method_output ); // Add better error display.
  325. } else {
  326. $data[$k] = $method_output;
  327. }
  328. }
  329. }
  330.  
  331. return $data;
  332. } // End validate_fields()
  333.  
  334. /**
  335. * Validate the given data, assuming it is from a text input field.
  336. * @access public
  337. * @since 6.0.0
  338. * @return void
  339. */
  340. public function validate_field_text ( $v ) {
  341. return (string)wp_kses_post( $v );
  342. } // End validate_field_text()
  343.  
  344. /**
  345. * Validate the given data, assuming it is from a textarea field.
  346. * @access public
  347. * @since 6.0.0
  348. * @return void
  349. */
  350. public function validate_field_textarea ( $v, $k ) {
  351. // Allow iframe, object and embed tags in textarea fields.
  352. $allowed = wp_kses_allowed_html( 'post' );
  353. $allowed['iframe'] = array( 'src' => true, 'width' => true, 'height' => true, 'id' => true, 'class' => true, 'name' => true );
  354. $allowed['object'] = array( 'src' => true, 'width' => true, 'height' => true, 'id' => true, 'class' => true, 'name' => true );
  355. $allowed['embed'] = array( 'src' => true, 'width' => true, 'height' => true, 'id' => true, 'class' => true, 'name' => true );
  356.  
  357. return wp_kses( $v, $allowed );
  358. } // End validate_field_textarea()
  359.  
  360. /**
  361. * Validate the given data, assuming it is from a checkbox input field.
  362. * @access public
  363. * @since 6.0.0
  364. * @param string $v
  365. * @return string
  366. */
  367. public function validate_field_checkbox ( $v ) {
  368. if ( 'true' != $v ) {
  369. return 'false';
  370. } else {
  371. return 'true';
  372. }
  373. } // End validate_field_checkbox()
  374.  
  375. /**
  376. * Validate the given data, assuming it is from a multicheck field.
  377. * @access public
  378. * @since 6.0.0
  379. * @param string $v
  380. * @return string
  381. */
  382. public function validate_field_multicheck ( $v ) {
  383. $v = (array) $v;
  384.  
  385. $v = array_map( 'esc_attr', $v );
  386.  
  387. return $v;
  388. } // End validate_field_multicheck()
  389.  
  390. /**
  391. * Validate the given data, assuming it is from a multicheck2 field.
  392. * @access public
  393. * @since 6.0.0
  394. * @param string $v
  395. * @return string
  396. */
  397. public function validate_field_multicheck2 ( $v ) {
  398. $v = (array) $v;
  399.  
  400. $v = array_map( 'esc_attr', $v );
  401.  
  402. return $v;
  403. } // End validate_field_multicheck2()
  404.  
  405. /**
  406. * Validate the given data, assuming it is from a slider field.
  407. * @access public
  408. * @since 6.0.0
  409. * @param string $v
  410. * @return string
  411. */
  412. public function validate_field_slider ( $v ) {
  413. $v = floatval( $v );
  414.  
  415. return $v;
  416. } // End validate_field_slider()
  417.  
  418. /**
  419. * Validate the given data, assuming it is from a URL field.
  420. * @access public
  421. * @since 6.0.0
  422. * @param string $v
  423. * @return string
  424. */
  425. public function validate_field_url ( $v ) {
  426. return trim( esc_url( $v ) );
  427. } // End validate_field_url()
  428.  
  429. /**
  430. * Validate the given data, assuming it is from a upload field.
  431. * @access public
  432. * @since 6.0.0
  433. * @param string $v
  434. * @return string
  435. */
  436. public function validate_field_upload ( $v ) {
  437. return trim( esc_url( $v ) );
  438. } // End validate_field_upload()
  439.  
  440. /**
  441. * Validate the given data, assuming it is from a upload_min field.
  442. * @access public
  443. * @since 6.0.0
  444. * @param string $v
  445. * @return string
  446. */
  447. public function validate_field_upload_min ( $v ) {
  448. return trim( esc_url( $v ) );
  449. } // End validate_field_upload()
  450.  
  451. /**
  452. * Validate the given data, assuming it is from a upload_field_id field.
  453. * @access public
  454. * @since 6.0.0
  455. * @param string $v
  456. * @return string
  457. */
  458. public function validate_field_upload_field_id ( $v ) {
  459. return intval( $v );
  460. } // End validate_field_upload_field_id()
  461.  
  462. /**
  463. * Validate the given data, assuming it is from a typography field.
  464. * @access public
  465. * @since 6.0.0
  466. * @param string $v
  467. * @return string
  468. */
  469. public function validate_field_typography ( $v ) {
  470. $defaults = array( 'size' => '', 'unit' => '', 'face' => '', 'style' => '', 'color' => '' );
  471. $v = wp_parse_args( $v, $defaults );
  472.  
  473. if ( isset( $v['size_' . $v['unit']] ) ) {
  474. $v['size'] = $v['size_' . $v['unit']];
  475. }
  476.  
  477. foreach ( $v as $i => $j ) {
  478. if ( ! in_array( $i, array_keys( $defaults ) ) ) {
  479. unset( $v[$i] );
  480. }
  481. }
  482.  
  483. $v = array_map( 'strip_tags', $v );
  484. $v = array_map( 'stripslashes', $v );
  485.  
  486. return $v;
  487. } // End validate_field_typography()
  488.  
  489. /**
  490. * Validate the given data, assuming it is from a border field.
  491. * @access public
  492. * @since 6.0.0
  493. * @param string $v
  494. * @return string
  495. */
  496. public function validate_field_border ( $v ) {
  497. $defaults = array( 'width' => '', 'style' => '', 'color' => '' );
  498. $v = wp_parse_args( $v, $defaults );
  499.  
  500. foreach ( $v as $i => $j ) {
  501. if ( ! in_array( $i, array_keys( $defaults ) ) ) {
  502. unset( $v[$i] );
  503. }
  504. }
  505.  
  506. $v = array_map( 'esc_html', $v );
  507.  
  508. return $v;
  509. } // End validate_field_border()
  510.  
  511. /**
  512. * Validate the given data, assuming it is from a timestamp field.
  513. * @access public
  514. * @since 6.0.0
  515. * @param string $v
  516. * @return string
  517. */
  518. public function validate_field_timestamp ( $v ) {
  519. $defaults = array( 'date' => '', 'hour' => '', 'minute' => '' );
  520. $v = wp_parse_args( $v, $defaults );
  521.  
  522. foreach ( $v as $i => $j ) {
  523. if ( ! in_array( $i, array_keys( $defaults ) ) ) {
  524. unset( $v[$i] );
  525. }
  526. }
  527.  
  528. $date = $v['date'];
  529.  
  530. $hour = $v['hour'];
  531. $minute = $v['minute'];
  532. // $second = $output[$option_array['id']]['second'];
  533. $second = '00';
  534.  
  535. $day = substr( $date, 3, 2 );
  536. $month = substr( $date, 0, 2 );
  537. $year = substr( $date, 6, 4 );
  538.  
  539. $timestamp = mktime( $hour, $minute, $second, $month, $day, $year );
  540.  
  541. return esc_attr( $timestamp );
  542. } // End validate_field_timestamp()
  543.  
  544. /**
  545. * Render the various sections and their corresponding fields.
  546. * @access public
  547. * @since 6.0.0
  548. * @return void
  549. */
  550. public function render_sections () {
  551. if ( 0 >= count( $this->_sections ) ) return;
  552. $html = '';
  553. $current_section = '';
  554. if ( isset( $_GET['tab'] ) && '' != $_GET['tab'] ) {
  555. $current_section = sanitize_title_with_dashes( $_GET['tab'] );
  556. } else {
  557. // Grab the key for the first section, using a short loop.
  558. if ( 0 < count( $this->_sections ) ) {
  559. foreach ( $this->_sections as $k => $v ) {
  560. $current_section = $k;
  561. break;
  562. }
  563. }
  564. }
  565.  
  566. if ( isset( $this->_sections[$current_section] ) ) {
  567. $html .= $this->render_single_section( $current_section, $this->_sections[$current_section] );
  568. }
  569.  
  570. echo $html;
  571. } // End render_sections()
  572.  
  573. /**
  574. * Render a single section if fields.
  575. * @access public
  576. * @since 6.0.0
  577. * @param string $key The key/token.
  578. * @param array $args Arguments pertaining to this section.
  579. * @return string Rendered HTML markup for the section.
  580. */
  581. public function render_single_section ( $key, $args, $heading_level = 2 ) {
  582. if ( in_array( $key, $this->_processed_sections ) ) return; // Don't process a section more than once.
  583. if ( 6 < intval( $heading_level ) ) $heading_level = 2; // Set a default heading level.
  584.  
  585. $fields = $this->_get_fields_by_section( $key );
  586. $html = '';
  587. $html .= '<div id="' . esc_attr( $key ) . '" class="settings-section">' . "\n";
  588. if ( isset( $args['name'] ) ) {
  589. $html .= '<h' . intval( $heading_level ) . ' class="section-title">' . $args['name'] . '</h' . intval( $heading_level ) . '>' . "\n";
  590. }
  591. $html .= $this->__get( 'wrapper_start' );
  592. if ( 0 < count( $fields ) ) {
  593. $html .= $this->render_fields( $fields );
  594. }
  595. $html .= $this->__get( 'wrapper_end' );
  596.  
  597. // Cater for child sections.
  598. if ( isset( $args['children'] ) && is_array( $args['children'] ) && 0 < count( $args['children'] ) ) {
  599. foreach ( $args['children'] as $k => $v ) {
  600. $html .= $this->render_single_section( $k, $v, 3 );
  601. }
  602. }
  603. $html .= '</div><!--/#' . esc_attr( $key ) . ' .settings-section-->' . "\n";
  604. return $html;
  605. } // End render_single_section()
  606.  
  607. /**
  608. * Render the various fields based on the given field data.
  609. * @access public
  610. * @since 6.0.0
  611. * @param array $data Provided field data.
  612. * @return void
  613. */
  614. public function render_fields ( $data, $mode = 'table' ) {
  615. if ( 0 >= count( $data ) ) return;
  616. $html = '';
  617. $no_header = $this->get_no_label_field_types();
  618. $this->enqueue_media_setup(); // Make sure wp_enqueue_media() is being loaded well before the footer, so our underscore.js templates get loaded.
  619. foreach ( $data as $k => $v ) {
  620. $colspan = '';
  621. if ( in_array( $v['type'], $no_header ) ) $colspan = ' colspan="2"'; // If we're not displaying a header, span the table cell by two columns.
  622. $field = $this->render_single_field( $k, $v );
  623. $html .= '<tr>' . "\n";
  624. if ( '' == $colspan ) $html .= '<th>' . $v['name'] . '</th>' . "\n";
  625. $html .= '<td' . $colspan . '><span class="wf-field wf-field-' . esc_attr( $v['type'] ) . '">' . $field . '</span></td>' . "\n";
  626. $html .= '</tr>' . "\n";
  627. }
  628. return $html;
  629. } // End render_fields()
  630.  
  631. /**
  632. * Render the HTML markup for a single field.
  633. * @access public
  634. * @since 6.0.0
  635. * @param string $key The key to be used for the field.
  636. * @param array $args Arguments pertaining to the field.
  637. * @return string
  638. */
  639. public function render_single_field ( $key, $args ) {
  640. $html = '';
  641. if ( ! in_array( $args['type'], $this->get_supported_fields() ) ) return ''; // Supported field type sanity check.
  642.  
  643. // Make sure we have some kind of default, if the key isn't set.
  644. if ( ! isset( $args['std'] ) ) $args['std'] = '';
  645.  
  646. $method = 'render_field_' . $args['type'];
  647. if ( ! method_exists( $this, $method ) ) $method = 'render_field_text';
  648.  
  649. $method_output = $this->$method( $key, $args );
  650. if ( is_wp_error( $method_output ) ) {
  651. // if ( defined( 'WP_DEBUG' ) || true == constant( 'WP_DEBUG' ) ) print_r( $method_output ); // Add better error display.
  652. } else {
  653. $html .= $method_output;
  654. }
  655.  
  656. // Output the description, if the current field allows it.
  657. if ( isset( $args['type'] ) && ! in_array( $args['type'], (array)apply_filters( 'wf_no_description_fields', array( 'checkbox', 'info' ) ) ) ) {
  658. if ( isset( $args['desc'] ) ) {
  659. $description = '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>' . "\n";
  660. if ( in_array( $args['type'], (array)apply_filters( 'wf_newline_description_fields', array( 'textarea', 'select', 'select2', 'slider', 'images', 'info', 'border', 'typography', 'color', 'upload', 'calendar', 'timestamp', 'select_taxonomy', 'multi_field' ) ) ) ) {
  661. $description = wpautop( $description );
  662. }
  663. $html .= $description;
  664. }
  665. }
  666.  
  667. return $html;
  668. } // End render_single_field()
  669.  
  670. /**
  671. * Render HTML markup for the "text" field type.
  672. * @access protected
  673. * @since 6.0.0
  674. * @param string $key The unique ID of this field.
  675. * @param array $args Arguments used to construct this field.
  676. * @return string HTML markup for the field.
  677. */
  678. protected function render_field_text ( $key, $args ) {
  679. $html = '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="40" type="text" value="' . esc_attr( $this->get_value( $key, $args['std'] ) ) . '" />' . "\n";
  680. return $html;
  681. } // End render_field_text()
  682.  
  683. /**
  684. * Render HTML markup for the "multi_field" field type.
  685. * @access protected
  686. * @since 6.0.0
  687. * @param string $key The unique ID of this field.
  688. * @param array $args Arguments used to construct this field.
  689. * @return string HTML markup for the field.
  690. */
  691. protected function render_field_multi_field ( $key, $args ) {
  692. $html = '';
  693. if ( isset( $args['multi_fields'] ) && 0 < count( $args['multi_fields'] ) ) {
  694. foreach ( $args['multi_fields'] as $k => $v ) {
  695. $html .= '<label for="' . esc_attr( $k ) . '">' . esc_html( $v['name'] ) . '</label>' . "\n";
  696. $html .= $this->render_single_field( $k, $v );
  697. }
  698. }
  699. return $html;
  700. } // End render_field_multi_field()
  701.  
  702. /**
  703. * Render HTML markup for the "typography" field type.
  704. * @access protected
  705. * @since 6.0.0
  706. * @param string $key The unique ID of this field.
  707. * @param array $args Arguments used to construct this field.
  708. * @return string HTML markup for the field.
  709. */
  710. protected function render_field_typography ( $key, $args ) {
  711. $this->_has_colourpicker = true;
  712. $this->_has_typography = true;
  713. $this->_has_select = true;
  714.  
  715. $html = '';
  716.  
  717. $defaults = array(
  718. 'size' => get_option( $key . '_size', '' ),
  719. 'unit' => get_option( $key . '_unit', '' ),
  720. 'face' => get_option( $key . '_face', '' ),
  721. 'style' => get_option( $key . '_style', '' ),
  722. 'color' => get_option( $key . '_color', '' )
  723. );
  724.  
  725. if ( 0 < count( $defaults ) && isset( $args['std'] ) && is_array( $args['std'] ) ) {
  726. foreach ( $defaults as $k => $v ) {
  727. if ( '' == $v && isset( $args['std'][$k] ) ) {
  728. $defaults[$k] = $args['std'][$k];
  729. }
  730. }
  731. }
  732.  
  733. $value = $this->get_value( $key, $defaults );
  734.  
  735. // Make sure we place our default values in if the key is empty. wp_parse_args() didn't seem to work for this.
  736. foreach ( $defaults as $k => $v ) {
  737. if ( ! isset( $value[$k] ) ) {
  738. $value[$k] = $defaults[$k];
  739. } else {
  740. if ( '' == $value[$k] ) {
  741. $value[$k] = $defaults[$k];
  742. }
  743. }
  744. }
  745.  
  746. // Make sure the size fields are set correctly.
  747. if ( ! isset( $value['size'] ) ) {
  748. $value['size'] = $value['size_' . $value['unit']];
  749. }
  750.  
  751. $unit = $value['unit'];
  752.  
  753. $html .= '<span class="unit-container ' . esc_attr( 'unit-' . sanitize_title_with_dashes( $unit ) ) . '">' . "\n";
  754.  
  755. /* Size in Pixels */
  756. $html .= '<select class="woo-typography woo-typography-size woo-typography-size-px hide-if-em" name="'. esc_attr( $key . '[size_px]' ) . '" id="'. esc_attr( $key . '_size' ) . '">' . "\n";
  757. for ( $i = 9; $i < floatval( apply_filters( 'wf_fields_typography_font_size_px_upper_limit', 71 ) ); $i++ ) {
  758. $html .= '<option value="'. esc_attr( $i ) .'" ' . selected( floatval( $value['size'] ), $i, false ) . '>'. esc_html( $i ) . '</option>' . "\n";
  759. }
  760. $html .= '</select>' . "\n";
  761.  
  762. /* Size in EMs */
  763. $html .= '<select class="woo-typography woo-typography-size woo-typography-size-em hide-if-px" name="'. esc_attr( $key . '[size_em]' ) . '" id="'. esc_attr( $key . '_size' ) . '">' . "\n";
  764. $em = 0;
  765. for ( $i = 0; $i < 39; $i++ ) {
  766. if ( $i <= 24 ) // up to 2.0em in 0.1 increments
  767. $em = $em + 0.1;
  768. elseif ( $i >= 14 && $i <= 24 ) // Above 2.0em to 3.0em in 0.2 increments
  769. $em = $em + 0.2;
  770. elseif ( $i >= 24 ) // Above 3.0em in 0.5 increments
  771. $em = $em + 0.5;
  772.  
  773. $active = '';
  774. if( strval( $em ) == $value['size'] ) {
  775. $active = 'selected="selected"';
  776. }
  777. $html .= '<option value="' . esc_attr( floatval( $em ) ) . '" ' . $active . '>' . esc_html( $em ) . '</option>';
  778. }
  779. $html .= '</select>' . "\n";
  780.  
  781. /* Font Unit */
  782. $unit = $value['unit'];
  783. $em = ''; $px = '';
  784. if ( 'em' == $unit ) { $em = 'selected="selected"'; }
  785. if ( 'px' == $unit ) { $px = 'selected="selected"'; }
  786. $html .= '<select class="woo-typography woo-typography-unit" name="'. esc_attr( $key .'[unit]' ) . '" id="'. esc_attr( $key . '_unit' ) . '">' . "\n";
  787. $html .= '<option value="px" ' . $px . '">px</option>' . "\n";
  788. $html .= '<option value="em" ' . $em . '>em</option>' . "\n";
  789. $html .= '</select>' . "\n";
  790.  
  791. /* Weights */
  792. $font_weights = (array) apply_filters( 'wf_fields_typography_font_weights', array( '300' => __( 'Thin', 'woothemes' ), '300 italic' => __( 'Thin Italic', 'woothemes' ), 'normal' => __( 'Normal', 'woothemes' ), 'italic' => __( 'Italic', 'woothemes' ), 'bold' => __( 'Bold', 'woothemes' ), 'bold italic' => __( 'Bold/Italic', 'woothemes' ) ) );
  793.  
  794. if ( 0 < count( $font_weights ) ) {
  795. $html .= '<select class="woo-typography woo-typography-font-weight woo-typography-style" name="'. esc_attr( $key . '[style]' ) . '" id="'. esc_attr( $key . '_style' ) . '">' . "\n";
  796. foreach ( $font_weights as $k => $v ) {
  797. $html .= '<option value="' . esc_attr( $k ) . '" ' . selected( $value['style'], $k, false ) . '>' . esc_html( $v ) . '</option>' . "\n";
  798. }
  799. $html .= '</select>' . "\n";
  800. }
  801.  
  802. /* Font Face */
  803. $font_faces = wf_get_system_fonts();
  804. $google_fonts = wf_get_google_fonts();
  805. if ( 0 < count( $google_fonts ) ) {
  806. $font_faces[''] = __( '-- Google WebFonts --', 'woothemes' );
  807. $google_fonts_array = array();
  808. foreach ( $google_fonts as $k => $v ) {
  809. $google_fonts_array[$v['name']] = $v['name'];
  810. }
  811. asort( $google_fonts_array );
  812. $font_faces = array_merge( $font_faces, $google_fonts_array );
  813. }
  814.  
  815. if ( 0 < count( $font_faces ) ) {
  816. $test_cases = wf_get_system_fonts_test_cases();
  817.  
  818. $html .= '<select class="woo-typography woo-typography-font-face woo-typography-face" name="'. esc_attr( $key . '[face]' ) . '" id="'. esc_attr( $key . '_face' ) . '">' . "\n";
  819. foreach ( $font_faces as $k => $v ) {
  820. $selected = '';
  821. // If one of the fonts requires a test case, use that value. Otherwise, use the key as the test case.
  822. if ( in_array( $k, array_keys( $test_cases ) ) ) {
  823. $value_to_test = $test_cases[$k];
  824. } else {
  825. $value_to_test = $k;
  826. }
  827. if ( $this->_test_typeface_against_test_case( $value['face'], $value_to_test ) ) $selected = ' selected="selected"';
  828. $html .= '<option value="' . esc_attr( $k ) . '" ' . $selected . '>' . esc_html( $v ) . '</option>' . "\n";
  829. }
  830. $html .= '</select>' . "\n";
  831. }
  832.  
  833. /* Border Color */
  834. $html .= '<input id="' . esc_attr( $key . '_color' ) . '" name="' . esc_attr( $key . '[color]' ) . '" size="40" type="text" class="woo-typography-color colour" value="' . esc_attr( $value['color'] ) . '" />' . "\n";
  835.  
  836. $html .= '</span>' . "\n";
  837. return $html;
  838. } // End render_field_typography()
  839.  
  840. /**
  841. * Test whether or not a typeface has been selected for a "typography" field.
  842. * @access protected
  843. * @since 6.0.2
  844. * @param string $face The noble warrior (typeface) to be tested.
  845. * @param string $test_case The test case. Does the warrior pass the ultimate test and reep eternal glory?
  846. * @return bool Whether or not eternal glory shall be achieved by the warrior.
  847. */
  848. protected function _test_typeface_against_test_case ( $face, $test_case ) {
  849. $response = false;
  850.  
  851. $face = stripslashes( str_replace( '"', '', str_replace( '&quot;', '', $face ) ) );
  852.  
  853. $parts = explode( ',', $face );
  854.  
  855. if ( $test_case == $parts[0] ) {
  856. $response = true;
  857. }
  858.  
  859. return $response;
  860. } // End _test_typeface_against_test_case()
  861.  
  862. /**
  863. * Render HTML markup for the "border" field type.
  864. * @access protected
  865. * @since 6.0.0
  866. * @param string $key The unique ID of this field.
  867. * @param array $args Arguments used to construct this field.
  868. * @return string HTML markup for the field.
  869. */
  870. protected function render_field_border ( $key, $args ) {
  871. $this->_has_colourpicker = true;
  872.  
  873. $html = '';
  874. $defaults = array(
  875. 'width' => get_option( $key . '_width', '' ),
  876. 'style' => get_option( $key . '_style', '' ),
  877. 'color' => get_option( $key . '_color', '' )
  878. );
  879.  
  880. if ( 0 < count( $defaults ) && isset( $args['std'] ) && is_array( $args['std'] ) ) {
  881. foreach ( $defaults as $k => $v ) {
  882. if ( '' == $v && isset( $args['std'][$k] ) ) {
  883. $defaults[$k] = $args['std'][$k];
  884. }
  885. }
  886. }
  887.  
  888. $value = $this->get_value( $key, $defaults );
  889.  
  890. // Make sure we place our default values in if the key is empty. wp_parse_args() didn't seem to work for this.
  891. foreach ( $defaults as $k => $v ) {
  892. if ( ! isset( $value[$k] ) ) {
  893. $value[$k] = $defaults[$k];
  894. } else {
  895. if ( '' == $value[$k] ) {
  896. $value[$k] = $defaults[$k];
  897. }
  898. }
  899. }
  900.  
  901. /* Border Width */
  902. $html .= '<select class="woo-border woo-border-width" name="'. esc_attr( $key . '[width]' ) . '" id="'. esc_attr( $key . '_width' ) . '">' . "\n";
  903. for ( $i = 0; $i < intval( apply_filters( 'wf_fields_border_width_upper_limit', 21 ) ); $i++ ) {
  904. $html .= '<option value="' . esc_attr( $i ) . '" ' . selected( intval( $value['width'] ), $i, false ) . '>'. esc_html( $i ) . 'px</option>' . "\n";
  905. }
  906. $html .= '</select>' . "\n";
  907.  
  908. /* Border Style */
  909. $border_styles = (array) apply_filters( 'wf_fields_border_styles', array( 'solid' => __( 'Solid', 'woothemes' ), 'dashed' => __( 'Dashed', 'woothemes' ), 'dotted' => __( 'Dotted', 'woothemes' ) ) );
  910.  
  911. if ( 0 < count( $border_styles ) ) {
  912. $html .= '<select class="woo-border woo-border-style" name="'. esc_attr( $key . '[style]' ) . '" id="'. esc_attr( $key . '_style' ) . '">' . "\n";
  913. foreach ( $border_styles as $k => $v ) {
  914. $html .= '<option value="' . esc_attr( $k ) . '" ' . selected( $value['style'], $k, false ) . '>' . esc_html( $v ) . '</option>' . "\n";
  915. }
  916. $html .= '</select>' . "\n";
  917. }
  918.  
  919. /* Border Color */
  920. $html .= '<input id="' . esc_attr( $key .'_color' ) . '" name="' . esc_attr( $key . '[color]' ) . '" size="40" type="text" class="colour" value="' . esc_attr( $value['color'] ) . '" />' . "\n";
  921. return $html;
  922. } // End render_field_border()
  923.  
  924. /**
  925. * Render HTML markup for the "radio" field type.
  926. * @access protected
  927. * @since 6.0.0
  928. * @param string $key The unique ID of this field.
  929. * @param array $args Arguments used to construct this field.
  930. * @return string HTML markup for the field.
  931. */
  932. protected function render_field_radio ( $key, $args ) {
  933. $html = '';
  934. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  935. $html = '';
  936. foreach ( $args['options'] as $k => $v ) {
  937. $html .= '<input type="radio" name="' . esc_attr( $key ) . '" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $this->get_value( $key, $args['std'] ) ), $k, false ) . ' /> ' . esc_html( $v ) . '<br />' . "\n";
  938. }
  939. }
  940. return $html;
  941. } // End render_field_radio()
  942.  
  943. /**
  944. * Render HTML markup for the "textarea" field type.
  945. * @access protected
  946. * @since 6.0.0
  947. * @param string $key The unique ID of this field.
  948. * @param array $args Arguments used to construct this field.
  949. * @return string HTML markup for the field.
  950. */
  951. protected function render_field_textarea ( $key, $args ) {
  952. // Explore how best to escape this data, as esc_textarea() strips HTML tags, it seems.
  953. $html = '<textarea id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" cols="42" rows="5">' . esc_textarea( $this->get_value( $key, $args['std'] ) ) . '</textarea>' . "\n";
  954. return $html;
  955. } // End render_field_textarea()
  956.  
  957. /**
  958. * Render HTML markup for the "multicheck" field type.
  959. * @access protected
  960. * @since 6.0.0
  961. * @param string $key The unique ID of this field.
  962. * @param array $args Arguments used to construct this field.
  963. * @return string HTML markup for the field.
  964. */
  965. protected function render_field_multicheck ( $key, $args ) {
  966. $html = '';
  967. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  968. // Attempt to preserve legacy "multicheck" field data, which was stored in an unorthodox manner. Retrieve it in our new format.
  969. $multicheck_legacy_defaults = $this->maybe_create_multicheck_legacy_defaults( $key, $args['options'] );
  970.  
  971. $value = $this->get_value( $key, $multicheck_legacy_defaults );
  972.  
  973. $html = '<div class="multicheck-container" style="height: 100px; overflow-y: auto;">' . "\n";
  974. foreach ( $args['options'] as $k => $v ) {
  975. $checked = '';
  976.  
  977. if ( in_array( $v, (array)$value ) ) { $checked = ' checked="checked"'; }
  978. $html .= '<input type="checkbox" name="' . esc_attr( $key ) . '[]" class="multicheck multicheck-' . esc_attr( $key ) . '" value="' . esc_attr( $v ) . '"' . $checked . ' /> ' . esc_html( $v ) . '<br />' . "\n";
  979. }
  980. $html .= '</div>' . "\n";
  981. }
  982. return $html;
  983. } // End render_field_multicheck()
  984.  
  985. /**
  986. * Render HTML markup for the "multicheck2" field type.
  987. * @access protected
  988. * @since 6.0.0
  989. * @param string $key The unique ID of this field.
  990. * @param array $args Arguments used to construct this field.
  991. * @return string HTML markup for the field.
  992. */
  993. protected function render_field_multicheck2 ( $key, $args ) {
  994. $html = '';
  995. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  996. $value = $this->get_value( $key, array() );
  997.  
  998. $html = '<div class="multicheck-container" style="height: 100px; overflow-y: auto;">' . "\n";
  999. foreach ( $args['options'] as $k => $v ) {
  1000. $checked = '';
  1001.  
  1002. if ( in_array( $k, (array)$value ) ) { $checked = ' checked="checked"'; }
  1003. $html .= '<input type="checkbox" name="' . esc_attr( $key ) . '[]" class="multicheck multicheck-' . esc_attr( $key ) . '" value="' . esc_attr( $k ) . '"' . $checked . ' /> ' . esc_html( $v ) . '<br />' . "\n";
  1004. }
  1005. $html .= '</div>' . "\n";
  1006. }
  1007. return $html;
  1008. } // End render_field_multicheck2()
  1009.  
  1010. /**
  1011. * Render HTML markup for the "checkbox" field type.
  1012. * @access protected
  1013. * @since 6.0.0
  1014. * @param string $key The unique ID of this field.
  1015. * @param array $args Arguments used to construct this field.
  1016. * @return string HTML markup for the field.
  1017. */
  1018. protected function render_field_checkbox ( $key, $args ) {
  1019. $has_description = false;
  1020. $html = '';
  1021. if ( isset( $args['desc'] ) ) {
  1022. $has_description = true;
  1023. $html .= '<label for="' . esc_attr( $key ) . '">' . "\n";
  1024. }
  1025. $html .= '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="checkbox" value="true"' . checked( esc_attr( $this->get_value( $key, $args['std'] ) ), 'true', false ) . ' />' . "\n";
  1026. if ( $has_description ) {
  1027. $html .= wp_kses_post( $args['desc'] ) . '</label>' . "\n";
  1028. }
  1029. return $html;
  1030. } // End render_field_checkbox()
  1031.  
  1032. /**
  1033. * Render HTML markup for the "info" field type.
  1034. * @access protected
  1035. * @since 6.0.0
  1036. * @param string $key The unique ID of this field.
  1037. * @param array $args Arguments used to construct this field.
  1038. * @return string HTML markup for the field.
  1039. */
  1040. protected function render_field_info ( $key, $args ) {
  1041. $html = '<div id="' . esc_attr( $key ) . '" class="woo-notice">' . "\n";
  1042. if ( '' != $args['desc'] ) $html .= '<p>' . wp_kses_post( $args['desc'] ) . '</p>' . "\n";
  1043. $html .= '</div>' . "\n";
  1044. return $html;
  1045. } // End render_field_info()
  1046.  
  1047. /**
  1048. * Render HTML markup for the "select" field type.
  1049. * @access protected
  1050. * @since 6.0.0
  1051. * @param string $key The unique ID of this field.
  1052. * @param array $args Arguments used to construct this field.
  1053. * @return string HTML markup for the field.
  1054. */
  1055. protected function render_field_select ( $key, $args ) {
  1056. $this->_has_select = true;
  1057.  
  1058. $html = '';
  1059. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  1060. $html .= '<select id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '">' . "\n";
  1061. foreach ( $args['options'] as $k => $v ) {
  1062. $html .= '<option value="' . esc_attr( $v ) . '"' . selected( esc_attr( $this->get_value( $key, $args['std'] ) ), $v, false ) . '>' . esc_html( $v ) . '</option>' . "\n";
  1063. }
  1064. $html .= '</select>' . "\n";
  1065. }
  1066. return $html;
  1067. } // End render_field_select()
  1068.  
  1069. /**
  1070. * Render HTML markup for the "select2" field type.
  1071. * @access protected
  1072. * @since 6.0.0
  1073. * @param string $key The unique ID of this field.
  1074. * @param array $args Arguments used to construct this field.
  1075. * @return string HTML markup for the field.
  1076. */
  1077. protected function render_field_select2 ( $key, $args ) {
  1078. $this->_has_select = true;
  1079.  
  1080. $html = '';
  1081. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  1082. $html .= '<select id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '">' . "\n";
  1083. foreach ( $args['options'] as $k => $v ) {
  1084. $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $this->get_value( $key, $args['std'] ) ), $k, false ) . '>' . esc_html( $v ) . '</option>' . "\n";
  1085. }
  1086. $html .= '</select>' . "\n";
  1087. }
  1088. return $html;
  1089. } // End render_field_select2()
  1090.  
  1091. /**
  1092. * Render HTML markup for the "select_taxonomy" field type.
  1093. * @access protected
  1094. * @since 6.0.0
  1095. * @param string $key The unique ID of this field.
  1096. * @param array $args Arguments used to construct this field.
  1097. * @return string HTML markup for the field.
  1098. */
  1099. protected function render_field_select_taxonomy ( $key, $args ) {
  1100. $this->_has_select = true;
  1101.  
  1102. $defaults = array(
  1103. 'show_option_all' => '',
  1104. 'show_option_none' => '',
  1105. 'orderby' => 'ID',
  1106. 'order' => 'ASC',
  1107. 'show_count' => 0,
  1108. 'hide_empty' => 1,
  1109. 'child_of' => 0,
  1110. 'exclude' => '',
  1111. 'selected' => $this->get_value( $key, $args['std'] ),
  1112. 'hierarchical' => 1,
  1113. 'class' => 'postform',
  1114. 'depth' => 0,
  1115. 'tab_index' => 0,
  1116. 'taxonomy' => 'category',
  1117. 'hide_if_empty' => false,
  1118. 'walker' => ''
  1119. );
  1120.  
  1121. if ( ! isset( $args['options'] ) ) {
  1122. $args['options'] = array();
  1123. }
  1124.  
  1125. $args['options'] = wp_parse_args( $args['options'], $defaults );
  1126.  
  1127. $args['options']['echo'] = false;
  1128. $args['options']['name'] = esc_attr( $key );
  1129. $args['options']['id'] = esc_attr( $key );
  1130.  
  1131. $html = '';
  1132. $html .= wp_dropdown_categories( $args['options'] );
  1133. return $html;
  1134. } // End render_field_select_taxonomy()
  1135.  
  1136. /**
  1137. * Render HTML markup for the "slider" field type.
  1138. * @access protected
  1139. * @since 6.0.0
  1140. * @param string $key The unique ID of this field.
  1141. * @param array $args Arguments used to construct this field.
  1142. * @return string HTML markup for the field.
  1143. */
  1144. protected function render_field_slider ( $key, $args ) {
  1145. $this->_has_range = true;
  1146.  
  1147. $html = '';
  1148. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  1149. $html .= '<select id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" class="range-input">' . "\n";
  1150. foreach ( $args['options'] as $k => $v ) {
  1151. $html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $this->get_value( $key, $args['std'] ) ), $k, false ) . '>' . esc_html( $v ) . '</option>' . "\n";
  1152. }
  1153. $html .= '</select>' . "\n";
  1154. }
  1155. return $html;
  1156. } // End render_field_slider()
  1157.  
  1158. /**
  1159. * Render HTML markup for the "masked_input" field type.
  1160. * @access protected
  1161. * @since 6.0.0
  1162. * @param string $key The unique ID of this field.
  1163. * @param array $args Arguments used to construct this field.
  1164. * @return string HTML markup for the field.
  1165. */
  1166. protected function render_field_masked_input ( $key, $args ) {
  1167. $this->_has_masked_input = true;
  1168.  
  1169. $placeholder = '99:99';
  1170. if ( isset( $args['options']['placeholder'] ) ) $placeholder = $args['options']['placeholder'];
  1171.  
  1172. $html = '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="40" type="text" value="' . esc_attr( $this->get_value( $key, $args['std'] ) ) . '" class="woo-input-masked" data-placeholder="' . esc_attr( $placeholder ) . '" />' . "\n";
  1173. return $html;
  1174. } // End render_field_masked_input()
  1175.  
  1176. /**
  1177. * Render HTML markup for the "time_masked" field type.
  1178. * @access protected
  1179. * @since 6.0.0
  1180. * @param string $key The unique ID of this field.
  1181. * @param array $args Arguments used to construct this field.
  1182. * @return string HTML markup for the field.
  1183. */
  1184. protected function render_field_time_masked ( $key, $args ) {
  1185. $this->_has_masked_input = true;
  1186.  
  1187. $placeholder = '99:99';
  1188. if ( isset( $args['options']['placeholder'] ) ) $placeholder = $args['options']['placeholder'];
  1189.  
  1190. $html = '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="40" type="text" value="' . esc_attr( $this->get_value( $key, $args['std'] ) ) . '" class="woo-input-masked" data-placeholder="' . esc_attr( $placeholder ) . '" />' . "\n";
  1191. return $html;
  1192. } // End render_field_time_masked()
  1193.  
  1194. /**
  1195. * Render HTML markup for the "time" field type.
  1196. * @access protected
  1197. * @since 6.0.0
  1198. * @param string $key The unique ID of this field.
  1199. * @param array $args Arguments used to construct this field.
  1200. * @return string HTML markup for the field.
  1201. */
  1202. protected function render_field_time ( $key, $args ) {
  1203. $this->_has_masked_input = true;
  1204.  
  1205. $placeholder = '99:99';
  1206. if ( isset( $args['options']['placeholder'] ) ) $placeholder = $args['options']['placeholder'];
  1207.  
  1208. $html = '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="40" type="text" value="' . esc_attr( $this->get_value( $key, $args['std'] ) ) . '" class="woo-input-masked" data-placeholder="' . esc_attr( $placeholder ) . '" />' . "\n";
  1209. return $html;
  1210. } // End render_field_time()
  1211.  
  1212. /**
  1213. * Render HTML markup for the "calendar" field type.
  1214. * @access protected
  1215. * @since 6.0.0
  1216. * @param string $key The unique ID of this field.
  1217. * @param array $args Arguments used to construct this field.
  1218. * @return string HTML markup for the field.
  1219. */
  1220. protected function render_field_calendar ( $key, $args ) {
  1221. $this->_has_calendar = true;
  1222.  
  1223. $val = $this->get_value( $key );
  1224. if ( '' == $val ) $val = time();
  1225.  
  1226. $html = '<input type="hidden" name="datepicker-image" value="' . esc_url( admin_url( 'images/date-button.gif' ) ) . '" />' . "\n";
  1227. $html .= '<input class="woo-input-calendar" type="text" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="' . esc_attr( date( 'm/d/Y', strtotime( $val ) ) ) . '">';
  1228. return $html;
  1229. } // End render_field_calendar()
  1230.  
  1231. /**
  1232. * Render HTML markup for the "color" field type.
  1233. * @access protected
  1234. * @since 6.0.0
  1235. * @param string $key The unique ID of this field.
  1236. * @param array $args Arguments used to construct this field.
  1237. * @return string HTML markup for the field.
  1238. */
  1239. protected function render_field_color ( $key, $args ) {
  1240. $this->_has_colourpicker = true;
  1241. $value = $this->get_value( $key, $args['std'] );
  1242. $html = '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="40" type="text" class="colour" value="' . esc_attr( $value ) . '" />' . "\n";
  1243. return $html;
  1244. } // End render_field_color()
  1245.  
  1246. /**
  1247. * Render HTML markup for the "images" field type.
  1248. * @access protected
  1249. * @since 6.0.0
  1250. * @param string $key The unique ID of this field.
  1251. * @param array $args Arguments used to construct this field.
  1252. * @return string HTML markup for the field.
  1253. */
  1254. protected function render_field_images ( $key, $args ) {
  1255. $this->_has_imageselector = true;
  1256.  
  1257. if ( isset( $args['options'] ) && ( 0 < count( (array)$args['options'] ) ) ) {
  1258. $html = '';
  1259. foreach ( $args['options'] as $k => $v ) {
  1260. $image = '<img src="' . esc_url( $v ) . '" alt="' . esc_attr( $k ) . '" title="' . esc_attr( $k ) . '" class="radio-image-thumb" />';
  1261. $html .= '<input type="radio" name="' . esc_attr( $key ) . '" value="' . esc_attr( $k ) . '" class="radio-images"' . checked( esc_attr( $this->get_value( $key, $args['std'] ) ), $k, false ) . ' /> ' . $image . "\n";
  1262. }
  1263. }
  1264. return $html;
  1265. } // End render_field_images()
  1266.  
  1267. /**
  1268. * Render HTML markup for the "upload" field type.
  1269. * @access protected
  1270. * @since 6.0.0
  1271. * @param string $key The unique ID of this field.
  1272. * @param array $args Arguments used to construct this field.
  1273. * @return string HTML markup for the field.
  1274. */
  1275. protected function render_field_upload ( $key, $args ) {
  1276. $this->_has_upload = true;
  1277.  
  1278. $url = $this->get_value( $key, $args['std'] );
  1279. $id = $this->get_value( $key . '-id', 0 );
  1280. $placeholder = apply_filters( 'wf_placeholder_image_url', get_template_directory_uri() . '/functions/assets/images/placeholder.png' );
  1281. $class = ' no-image';
  1282. if ( '' != $url || 0 < intval( $id ) ) $class = ' has-image';
  1283.  
  1284. $html = '<span class="upload-field">' . "\n";
  1285. $html .= '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" size="34" type="text" class="input-upload" value="' . esc_attr( $url ) . '" /> <a href="#" class="button" data-uploader-title="' . esc_attr( sprintf( __( 'Select %s', 'woothemes' ), $args['name'] ) ) . '" data-uploader-button-text="' . esc_attr( sprintf( __( 'Use image as %s', 'woothemes' ), $args['name'] ) ) . '">' . __( 'Upload', 'woothemes' ) . '</a>' . "\n";
  1286. $html .= '<input id="' . esc_attr( $key ) . '-id" name="' . esc_attr( $key ) . '-id" type="hidden" class="input-upload-id" value="' . esc_attr( $id ) . '" /> ' . "\n";
  1287. $html .= '</span>' . "\n";
  1288.  
  1289. $html .= '<div class="image-preview' . esc_attr( $class ) . '">' . "\n";
  1290. $html .= '<img src="' . esc_url( $url ) . '" data-placeholder="' . esc_url( $placeholder ) . '" />' . "\n";
  1291. $html .= '<a href="#" class="remove">' . sprintf( __( 'Remove %s', 'woothemes' ), $args['name'] ) . '</a>' . "\n";
  1292. $html .= '</div><!--/.image-preview-->' . "\n";
  1293.  
  1294. return $html;
  1295. } // End render_field_upload()
  1296.  
  1297. /**
  1298. * Render HTML markup for the "upload_min" field type.
  1299. * @access protected
  1300. * @since 6.0.0
  1301. * @param string $key The unique ID of this field.
  1302. * @param array $args Arguments used to construct this field.
  1303. * @return string HTML markup for the field.
  1304. */
  1305. protected function render_field_upload_min ( $key, $args ) {
  1306. $this->_has_upload = true;
  1307.  
  1308. $url = $this->get_value( $key, $args['std'] );
  1309. $id = $this->get_value( $key . '-id', 0 );
  1310. $placeholder = WF()->get_placeholder_image_url();
  1311. $class = ' no-image';
  1312. if ( '' != $url || 0 < intval( $id ) ) $class = ' has-image';
  1313.  
  1314. $html = '<span class="upload-field">' . "\n";
  1315. $html .= '<input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="hidden" class="input-upload" value="' . esc_attr( $url ) . '" /> <a href="#" class="button" data-uploader-title="' . esc_attr( sprintf( __( 'Select %s', 'woothemes' ), $args['name'] ) ) . '" data-uploader-button-text="' . esc_attr( sprintf( __( 'Use image as %s', 'woothemes' ), $args['name'] ) ) . '">' . __( 'Upload', 'woothemes' ) . '</a>' . "\n";
  1316. $html .= '<input id="' . esc_attr( $key ) . '-id" name="' . esc_attr( $key ) . '-id" type="hidden" class="input-upload-id" value="' . esc_attr( $id ) . '" /> ' . "\n";
  1317. $html .= '</span>' . "\n";
  1318.  
  1319. $html .= '<div class="image-preview' . esc_attr( $class ) . '">' . "\n";
  1320. $html .= '<img src="' . esc_url( $url ) . '" data-placeholder="' . esc_url( $placeholder ) . '" />' . "\n";
  1321. $html .= '<a href="#" class="remove">' . sprintf( __( 'Remove %s', 'woothemes' ), $args['name'] ) . '</a>' . "\n";
  1322. $html .= '</div><!--/.image-preview-->' . "\n";
  1323.  
  1324. return $html;
  1325. } // End render_field_upload_min()
  1326.  
  1327. /**
  1328. * Render HTML markup for the "timestamp" field type.
  1329. * @access protected
  1330. * @since 6.0.0
  1331. * @param string $key The unique ID of this field.
  1332. * @param array $args Arguments used to construct this field.
  1333. * @return string HTML markup for the field.
  1334. */
  1335. protected function render_field_timestamp ( $key, $args ) {
  1336. $this->_has_calendar = true;
  1337.  
  1338. $val = $this->get_value( $key );
  1339. if ( '' == $val ) $val = time();
  1340.  
  1341. $html = '<input type="hidden" name="datepicker-image" value="' . esc_url( admin_url( 'images/date-button.gif' ) ) . '" />' . "\n";
  1342. $html .= '<input class="woo-input-calendar" type="text" name="' . esc_attr( $key . '[date]' ) . '" id="' . esc_attr( $key ) . '" value="' . esc_attr( date( 'm/d/Y', $val ) ) . '">';
  1343. $html .= '<span class="time-selectors">' . "\n";
  1344. $html .= ' <span class="woo-timestamp-at">' . __( '@', 'woothemes' ) . '</span> ';
  1345.  
  1346. $html .= '<select name="' . esc_attr( $key . '[hour]' ) . '" class="woo-select-timestamp">' . "\n";
  1347. for ( $i = 0; $i <= 23; $i++ ) {
  1348.  
  1349. $j = $i;
  1350. if ( $i < 10 ) {
  1351. $j = '0' . $i;
  1352. }
  1353.  
  1354. $html .= '<option value="' . esc_attr( $i ) . '"' . selected( date( 'H', $val ), $j, false ) . '>' . esc_html( $j ) . '</option>' . "\n";
  1355. }
  1356. $html .= '</select>' . "\n";
  1357.  
  1358. $html .= '<select name="' . $key . '[minute]" class="woo-select-timestamp">' . "\n";
  1359. for ( $i = 0; $i <= 59; $i++ ) {
  1360.  
  1361. $j = $i;
  1362. if ( $i < 10 ) {
  1363. $j = '0' . $i;
  1364. }
  1365.  
  1366. $html .= '<option value="' . esc_attr( $i ) . '"' . selected( date( 'i', $val ), $j, false ) .'>' . esc_html( $j ) . '</option>' . "\n";
  1367. }
  1368. $html .= '</select>' . "\n";
  1369. $html .= '</span><!--/.time-selectors-->' . "\n";
  1370. return $html;
  1371. } // End render_field_timestamp()
  1372.  
  1373. /**
  1374. * Render the current fields state. This is the main function used for HTML output.
  1375. * @access public
  1376. * @since 6.0.0
  1377. * @return void
  1378. */
  1379. public function render () {
  1380. echo '<form name="' . esc_attr( $this->_token ) . '-form" method="post" enctype="multipart/form-data">' . "\n";
  1381. wp_nonce_field( $this->_token . '_nonce', $this->_token . '_nonce' );
  1382. $this->maybe_render_extra_hidden_fields();
  1383. $this->render_sections();
  1384. if ( true == $this->__get( 'render_submit_button' ) ) {
  1385. submit_button();
  1386. }
  1387. echo '</form>' . "\n";
  1388. } // End render()
  1389.  
  1390. /**
  1391. * Render any extra hidden fields, if any are specified.
  1392. * @access public
  1393. * @since 6.0.0
  1394. * @return void
  1395. */
  1396. public function maybe_render_extra_hidden_fields () {
  1397. $fields = $this->__get( 'extra_hidden_fields' );
  1398.  
  1399. $html = '';
  1400. if ( is_array( $fields ) && 0 < count( $fields ) ) {
  1401. foreach ( $fields as $k => $v ) {
  1402. $html .= '<input type="hidden" name="' . esc_attr( $k ) . '" value="' . esc_attr( $v ) . '" />' . "\n";
  1403. }
  1404. }
  1405. echo $html;
  1406. } // End maybe_render_extra_hidden_fields()
  1407.  
  1408. /**
  1409. * Attempt to create an array of the selected data from a legacy "multicheck" field.
  1410. * Previously, each field was saved in a separate entry in the database, as either "true" or "false". Clearly, that is no longer the case. :)
  1411. * @access public
  1412. * @since 6.0.0
  1413. * @return void
  1414. */
  1415. public function maybe_create_multicheck_legacy_defaults ( $key, $options ) {
  1416. $response = array();
  1417. if ( is_array( $options ) && 0 < count( $options ) ) {
  1418. foreach ( $options as $k => $v ) {
  1419. $check = get_option( $key . '_' . $k, 'false' );
  1420. if ( 'true' == $check ) {
  1421. $response[$k] = $v;
  1422. }
  1423. }
  1424. }
  1425. return $response;
  1426. } // End maybe_create_multicheck_legacy_defaults()
  1427.  
  1428. /**
  1429. * Load in CSS where necessary.
  1430. * @access public
  1431. * @since 6.0.0
  1432. * @return void
  1433. */
  1434. public function enqueue_styles () {
  1435. // General fields-related CSS.
  1436. wp_enqueue_style( $this->_token . '-fields', esc_url( $this->_assets_url . 'css/fields.css' ) );
  1437.  
  1438. // Stylesheet for "Chosen".
  1439. wp_register_style( $this->_token . '-chosen', esc_url( $this->_assets_url . 'css/lib/chosen.css' ) );
  1440.  
  1441. if ( $this->_has_colourpicker ) {
  1442. wp_enqueue_style( 'wp-color-picker' );
  1443. }
  1444. if ( $this->_has_select ) {
  1445. wp_enqueue_style( $this->_token . '-chosen' );
  1446. }
  1447. } // End enqueue_styles()
  1448.  
  1449. /**
  1450. * Load in JavaScripts where necessary.
  1451. * @access public
  1452. * @since 6.0.0
  1453. * @return void
  1454. */
  1455. public function enqueue_scripts () {
  1456. wp_register_script( $this->_token . '-upload', esc_url( $this->_assets_url . 'js/uploaders.js' ), array( 'jquery' ) );
  1457. wp_register_script( $this->_token . '-datepicker', esc_url( $this->_assets_url . 'js/datepickers.js' ), array( 'jquery', 'jquery-ui-datepicker' ) );
  1458. wp_register_script( $this->_token . '-colourpicker', esc_url( $this->_assets_url . 'js/colourpickers.js' ), array( 'jquery', 'wp-color-picker' ) );
  1459. wp_register_script( $this->_token . '-typography', esc_url( $this->_assets_url . 'js/typography.js' ), array( 'jquery' ) );
  1460.  
  1461. wp_register_script( 'jquery-masked-input', esc_url( $this->_assets_url . 'js/lib/jquery-masked-input.js' ), array( 'jquery' ) );
  1462. wp_register_script( $this->_token . '-masked-input', esc_url( $this->_assets_url . 'js/masked-inputs.js' ), array( 'jquery', 'jquery-masked-input' ) );
  1463.  
  1464. wp_register_script( $this->_token . '-chosen', esc_url( $this->_assets_url . 'js/lib/jquery-chosen.js' ), array( 'jquery' ) );
  1465. wp_register_script( $this->_token . '-chosen-rtl', esc_url( $this->_assets_url . 'js/lib/jquery-chosen-rtl.js' ), array( $this->_token . '-chosen' ) );
  1466. wp_register_script( $this->_token . '-chosen-loader', esc_url( $this->_assets_url . 'js/chosen-selectors.js' ), array( 'jquery', $this->_token . '-chosen' ) );
  1467.  
  1468. wp_register_script( $this->_token . '-image-selector', esc_url( $this->_assets_url . 'js/image-selectors.js' ), array( 'jquery' ) );
  1469. wp_register_script( $this->_token . '-range-selector', esc_url( $this->_assets_url . 'js/range-selectors.js' ), array( 'jquery' ) );
  1470.  
  1471. if ( $this->_has_upload ) {
  1472. wp_enqueue_script( $this->_token . '-upload' );
  1473. }
  1474. if ( $this->_has_colourpicker ) {
  1475. wp_enqueue_script( $this->_token . '-colourpicker' );
  1476. }
  1477. if ( $this->_has_typography ) {
  1478. wp_enqueue_script( $this->_token . '-typography' );
  1479. }
  1480. if ( $this->_has_masked_input ) {
  1481. wp_enqueue_script( $this->_token . '-masked-input' );
  1482. }
  1483. if ( $this->_has_calendar ) {
  1484. wp_enqueue_script( $this->_token . '-datepicker' );
  1485. }
  1486. if ( $this->_has_imageselector ) {
  1487. wp_enqueue_script( $this->_token . '-image-selector' );
  1488. }
  1489. if ( $this->_has_range ) {
  1490. wp_enqueue_script( $this->_token . '-range-selector' );
  1491. }
  1492. if ( $this->_has_select ) {
  1493. if ( is_rtl() ) {
  1494. wp_enqueue_script( $this->_token . '-chosen-rtl' );
  1495. }
  1496. wp_enqueue_script( $this->_token . '-chosen-loader' );
  1497. }
  1498. } // End enqueue_scripts()
  1499.  
  1500. /**
  1501. * Load wp_enqueue_media() separately from the JavaScripts, to ensure the underscore.js templates are correctly loaded.
  1502. * @access public
  1503. * @since 6.0.0
  1504. * @return void
  1505. */
  1506. public function enqueue_media_setup () {
  1507. wp_enqueue_media();
  1508. } // End enqueue_media_setup()
  1509.  
  1510. /**
  1511. * Enqueue the styles and scripts for use with the fields.
  1512. * @access public
  1513. * @since 6.0.0
  1514. * @return void
  1515. */
  1516. public function maybe_enqueue_field_assets () {
  1517. $this->enqueue_styles();
  1518. $this->enqueue_scripts();
  1519. } // End maybe_enqueue_field_assets()
  1520.  
  1521. /**
  1522. * Retrieve the fields for a specified section.
  1523. * @access protected
  1524. * @since 6.0.0
  1525. * @param string $section The section to search for fields in.
  1526. * @return array An array of the detected fields.
  1527. */
  1528. protected function _get_fields_by_section ( $section ) {
  1529. $fields = array();
  1530. foreach ( $this->_fields as $k => $v ) {
  1531. if ( $section == $v['section'] ) $fields[$k] = $v;
  1532. }
  1533. return $fields;
  1534. } // End _get_fields_by_section()
  1535.  
  1536. /**
  1537. * Detect the various sections of the provided data.
  1538. * @access public
  1539. * @since 6.0.0
  1540. * @param array $data Data array of various sections and fields.
  1541. * @return array Detected sections.
  1542. */
  1543. public function init_sections ( $data ) {
  1544. if ( 0 >= count( $data ) ) return new WP_Error( 'bad_settings_data', __( 'The settings data provided is malformed. Please try again.', 'woothemes' ) );
  1545.  
  1546. // Create an array of menu items - multi-dimensional, to accommodate sub-headings.
  1547. $sections = array();
  1548. $headings = array();
  1549.  
  1550. foreach ( $data as $k => $v ) {
  1551. if ( $v['type'] == 'heading' || $v['type'] == 'subheading' ) {
  1552. $headings[] = $v;
  1553. }
  1554. }
  1555.  
  1556. $prev_heading_key = 0;
  1557.  
  1558. foreach ( $headings as $k => $v ) {
  1559. $token = $this->_generate_section_token( $v['name'] );
  1560. // Capture the token.
  1561. $v['token'] = $token;
  1562.  
  1563. if ( 'heading' == $v['type'] ) {
  1564. $sections[$token] = $v;
  1565. $prev_heading_key = $token;
  1566. }
  1567.  
  1568. if ( 'subheading' == $v['type'] ) {
  1569. $sections[$prev_heading_key]['children'][$v['token']] = $v;
  1570. }
  1571. }
  1572.  
  1573. $this->_sections = $sections;
  1574.  
  1575. return $this->_sections;
  1576. } // End init_sections()
  1577.  
  1578. /**
  1579. * Detect the various fields within the provided data.
  1580. * @access public
  1581. * @since 6.0.0
  1582. * @param array $data Data array of various sections and fields.
  1583. * @return array Detected fields.
  1584. */
  1585. public function init_fields ( $data ) {
  1586. if ( 0 >= count( $data ) ) return new WP_Error( 'bad_settings_data', __( 'The settings data provided is malformed. Please try again.', 'woothemes' ) );
  1587.  
  1588. $current_section = '';
  1589. foreach ( $data as $k => $v ) {
  1590. $field_counter = 0;
  1591. $field_counter++;
  1592.  
  1593. if ( in_array( $v['type'], array( 'heading', 'subheading' ) ) ) {
  1594. $current_section = $this->_generate_section_token( $v['name'] );
  1595. continue; // Ignore headings and sub-headings.
  1596. }
  1597.  
  1598. // Cater for the "std" field in "info" field types. We prefer to use "desc" as it is more logical.
  1599. if ( ! isset( $v['desc'] ) ) {
  1600. $v['desc'] = '';
  1601. }
  1602.  
  1603. if ( 'info' == $v['type'] && '' == $v['desc'] ) {
  1604. $v['desc'] = $v['std'];
  1605. }
  1606.  
  1607. // Process fields with an array as the type.
  1608. if ( is_array( $v['type'] ) ) {
  1609. foreach ( $v['type'] as $i => $j ) {
  1610. $v['multi_fields'] = $v['type'];
  1611. }
  1612. foreach ( $v['multi_fields'] as $i => $j ) {
  1613. unset( $v['multi_fields'][$i] );
  1614. // Change "meta" to "name".
  1615. if ( isset( $j['meta'] ) ) {
  1616. $j['name'] = $j['meta'];
  1617. unset( $j['meta'] );
  1618. }
  1619. $v['multi_fields'][$j['id']] = $j;
  1620. }
  1621. $v['type'] = 'multi_field';
  1622. }
  1623.  
  1624. // Add the field to the fields property.
  1625. $v['section'] = $current_section;
  1626.  
  1627. $key = '';
  1628. if ( isset( $v['id'] ) ) {
  1629. $key = $v['id'];
  1630. } else {
  1631. if ( isset( $v['name'] ) ) {
  1632. $key = sanitize_title_with_dashes( $v['name'] );
  1633. }
  1634. }
  1635.  
  1636. // Make sure we always have a key.
  1637. if ( '' == $key ) {
  1638. $key = 'field-' . $field_counter;
  1639. }
  1640.  
  1641. // Avoid duplicate keys by creating an adjusted key.
  1642. if ( isset( $this->_fields[$key] ) ) {
  1643. $counter = 0;
  1644. $new_key = '';
  1645.  
  1646. do {
  1647. $counter++;
  1648. $new_key = $key . '-' . $counter;
  1649. } while ( isset( $this->_fields[$key . '-' . $counter] ) );
  1650.  
  1651. $key = $new_key;
  1652. }
  1653.  
  1654. // Cater for slider fields and create the necessary options, if none are present.
  1655. if ( 'slider' == $v['type'] && ! isset( $v['options'] ) ) {
  1656. if ( isset( $v['min'] ) && isset( $v['max'] ) ) {
  1657. $increment = 1;
  1658. $min = intval( $v['min'] );
  1659. $max = intval( $v['max'] );
  1660. if ( isset( $v['increment'] ) ) {
  1661. $increment = intval( $v['increment'] );
  1662. }
  1663.  
  1664. if ( $max > $min ) {
  1665. $options = array();
  1666. for ( $i = $min; $i <= $max; $i+=$increment ) {
  1667. $options[$i] = $i;
  1668. }
  1669. $v['options'] = $options;
  1670. }
  1671. }
  1672. }
  1673.  
  1674. $this->_fields[$key] = $v;
  1675. }
  1676. $this->_fields = (array)apply_filters( 'wf_fields_init_fields', $this->_fields, $this->_fields );
  1677. return $this->_fields;
  1678. } // End init_fields()
  1679.  
  1680. /**
  1681. * Generate a section token based on a specified key.
  1682. * @access public
  1683. * @since 6.0.0
  1684. * @param string $key Specified key for the section.
  1685. * @return string Generated token for the section.
  1686. */
  1687. public function _generate_section_token ( $key ) {
  1688. return sanitize_title_with_dashes( $key );
  1689. } // End _generate_section_token()
  1690.  
  1691. /**
  1692. * Return an array of field types expecting an array value returned.
  1693. * @access public
  1694. * @since 6.0.0
  1695. * @return array
  1696. */
  1697. public function get_array_field_types () {
  1698. return array( 'multicheck', 'multicheck2', 'typography', 'border', 'timestamp' );
  1699. } // End get_array_field_types()
  1700.  
  1701. /**
  1702. * Return an array of field types where no label/header is to be displayed.
  1703. * @access protected
  1704. * @since 6.0.0
  1705. * @return array
  1706. */
  1707. protected function get_no_label_field_types () {
  1708. return array( 'info' );
  1709. } // End get_no_label_field_types()
  1710.  
  1711. /**
  1712. * Return a filtered array of supported field types.
  1713. * @access public
  1714. * @since 6.0.0
  1715. * @return array Supported field type keys.
  1716. */
  1717. public function get_supported_fields () {
  1718. return (array)apply_filters( 'wf_fields_supported_fields', array( 'text', 'checkbox', 'radio', 'textarea', 'multicheck', 'multicheck2', 'select', 'select2', 'upload', 'upload_min', 'upload_field_id', 'calendar', 'time', 'time_masked', 'timestamp', 'color', 'typography', 'border', 'images', 'info', 'slider', 'masked_input' , 'select_taxonomy', 'multi_field' ) );
  1719. } // End get_supported_fields()
  1720.  
  1721. /**
  1722. * Return a value, using a desired retrieval method.
  1723. * @access public
  1724. * @since 6.0.0
  1725. * @return mixed Returned value.
  1726. */
  1727. public function get_value ( $key, $default ) {
  1728. $response = false;
  1729.  
  1730. if ( true == apply_filters( 'wf_use_theme_mods', false ) ) {
  1731. $response = get_theme_mod( esc_attr( $key ), $default );
  1732. } else {
  1733. $response = get_option( esc_attr( $key ), $default );
  1734. }
  1735.  
  1736. return $response;
  1737. } // End get_value()
  1738. } // End Class
  1739. ?>
Advertisement
Add Comment
Please, Sign In to add comment