暂无描述

class-pum-fields.php 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. <?php
  2. /**
  3. * Fields
  4. *
  5. * @package PUM
  6. * @subpackage Classes/PUM_Fields
  7. * @copyright Copyright (c) 2019, Code Atlantic LLC
  8. * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
  9. * @since 1.4
  10. */
  11. // Exit if accessed directly
  12. if ( ! defined( 'ABSPATH' ) ) {
  13. exit;
  14. }
  15. class PUM_Fields extends Popmake_Fields {
  16. #region Non Fields
  17. /**
  18. * Hook Callback
  19. *
  20. * Renders the heading.
  21. *
  22. * @param array $args Arguments passed by the setting
  23. *
  24. * @return void
  25. */
  26. public function hook_callback( $args ) {
  27. do_action( $args['hook'], $args );
  28. }
  29. /**
  30. * Heading Callback
  31. *
  32. * Renders the heading.
  33. *
  34. * @param array $args Arguments passed by the setting
  35. *
  36. * @return void
  37. */
  38. public function heading_callback( $args ) { ?>
  39. </td></tr></tbody></table>
  40. <h2 class="pum-setting-heading"><?php echo esc_html( $args['desc'] ); ?></h2>
  41. <hr/>
  42. <table class="form-table"><tbody><tr style="display:none;"><td colspan="2"><?php
  43. }
  44. #endregion Non Fields
  45. #region Standard Fields
  46. /**
  47. * Button Callback
  48. *
  49. * Renders buttons.
  50. *
  51. * @param array $args Arguments passed by the setting
  52. *
  53. * @return void
  54. */
  55. public function button_callback( $args ) {
  56. $this->field_before( $args ); ?>
  57. <button type="<?php echo esc_attr( $args['button_type'] ); ?>" class="pum-button-<?php echo esc_attr( $args['size'] ); ?>" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>"><?php echo esc_html( $args['label'] ); ?></button><?php
  58. $this->field_description( $args );
  59. $this->field_after();
  60. }
  61. /**
  62. * Text Callback
  63. *
  64. * Renders text fields.
  65. *
  66. * @param array $args Arguments passed by the setting
  67. *
  68. * @param string $value
  69. */
  70. public function text_callback( $args, $value = null ) {
  71. if ( $args['type'] != 'text' ) {
  72. $args['class'].= ' pum-field-text';
  73. }
  74. $this->field_before( $args );
  75. if ( ! $value ) {
  76. $value = isset( $args['std'] ) ? $args['std'] : '';
  77. }
  78. $this->field_label( $args ); ?>
  79. <input type="<?php echo esc_attr( $args['type'] ); ?>" placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" class="<?php echo esc_attr( $args['size'] ); ?>-text" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="<?php echo esc_attr( stripslashes( $value ) ); ?>" <?php if ( $args['required'] ) { echo 'required'; } ?>/><?php
  80. $this->field_description( $args );
  81. $this->field_after();
  82. }
  83. /**
  84. * Textarea Callback
  85. *
  86. * Renders textarea fields.
  87. *
  88. * @param array $args Arguments passed by the setting
  89. *
  90. * @param string $value
  91. */
  92. public function textarea_callback( $args, $value = null ) {
  93. $this->field_before( $args );
  94. if ( ! $value ) {
  95. $value = isset( $args['std'] ) ? $args['std'] : '';
  96. }
  97. $this->field_label( $args ); ?>
  98. <textarea placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" class="<?php echo esc_attr( $args['size'] ); ?>-text" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" cols="<?php echo esc_attr( $args['cols'] ); ?>" rows="<?php echo esc_attr( $args['rows'] ); ?>" <?php if ( $args['required'] ) { echo 'required'; } ?>><?php echo esc_textarea( stripslashes( $value ) ); ?></textarea><?php
  99. $this->field_description( $args );
  100. $this->field_after();
  101. }
  102. /**
  103. * Hidden Callback
  104. *
  105. * Renders hidden fields.
  106. *
  107. * @param array $args Arguments passed by the setting
  108. *
  109. * @param $value
  110. */
  111. public function hidden_callback( $args, $value = null ) {
  112. $class = $this->field_classes( $args );
  113. if ( ! $value ) {
  114. $value = isset( $args['std'] ) ? $args['std'] : '';
  115. } ?>
  116. <input type="hidden" class="<?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="<?php echo esc_attr( stripslashes( $value ) ); ?>"/><?php
  117. }
  118. /**
  119. * Select Callback
  120. *
  121. * Renders select fields.
  122. *
  123. * @param array $args Arguments passed by the setting
  124. *
  125. * @param $value
  126. */
  127. public function select_callback( $args, $value = null ) {
  128. if ( isset ( $args['select2'] ) ) {
  129. $args['class'] .= ' pum-field-select2';
  130. }
  131. if ( ! $value ) {
  132. $value = isset( $args['std'] ) ? $args['std'] : '';
  133. }
  134. $multiple = null;
  135. if ( $args['multiple'] ) {
  136. $multiple = 'multiple';
  137. $args['class'] .= ' pum-field-select--multiple';
  138. $args['name'] .= $args['as_array'] ? '[]' : '';
  139. $value = ! is_array( $value ) ? array( $value ) : $value;
  140. }
  141. $this->field_before( $args );
  142. $this->field_label( $args ); ?>
  143. <select id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" data-placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" data-allow-clear="true" <?php echo $multiple; ?> <?php if ( $args['required'] ) { echo 'required'; } ?>>
  144. <?php if ( ! empty( $args['options'] ) ) {
  145. foreach ( $args['options'] as $label => $option ) {
  146. $selected = ( ! $multiple && $option == $value ) || ( $multiple && in_array( $option, $value ) ); ?>
  147. <option value="<?php echo esc_attr( $option ); ?>" <?php selected( 1, $selected ); ?>><?php echo esc_html( $label ); ?></option><?php
  148. }
  149. } ?>
  150. </select><?php
  151. $this->field_description( $args );
  152. $this->field_after();
  153. }
  154. /**
  155. * Checkbox Callback
  156. *
  157. * Renders checkboxes.
  158. *
  159. * @param array $args Arguments passed by the setting
  160. *
  161. * @param $value
  162. */
  163. public function checkbox_callback( $args, $value ) {
  164. $this->field_before( $args );
  165. $this->field_label( $args ); ?>
  166. <input type="checkbox" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="<?php echo esc_attr( $args['checkbox_val'] ); ?>" <?php checked( 1, $value ); ?> /><?php
  167. $this->field_description( $args );
  168. $this->field_after();
  169. }
  170. /**
  171. * Multicheck Callback
  172. *
  173. * Renders multiple checkboxes.
  174. *
  175. * @param array $args Arguments passed by the setting
  176. *
  177. * @param array $values
  178. */
  179. public function multicheck_callback( $args, $values = array() ) {
  180. $this->field_before( $args );
  181. $this->field_label( $args );
  182. if ( ! empty( $args['options'] ) ) {
  183. foreach ( $args['options'] as $key => $option ) {
  184. if ( ! is_array( $option ) ) {
  185. $option = array(
  186. 'label' => $option,
  187. );
  188. }
  189. $option = wp_parse_args( $option, array(
  190. 'label' => '',
  191. 'required' => false,
  192. 'disabled' => false,
  193. ) );
  194. $checked = isset( $values[ $key ] ); ?>
  195. <input name="<?php echo esc_attr( $args['name'] ); ?>[<?php echo esc_attr( $key ); ?>]" id="<?php echo esc_attr( $args['id'] . '_' . $key ); ?>" type="checkbox" value="<?php echo esc_html( $option ); ?>" <?php checked( true, $checked ); ?> <?php if ( $option['disabled'] ) { echo 'disabled="disabled"'; } ?> <?php if ( $option['required'] ) { echo 'required'; } ?> />&nbsp;
  196. <label for="<?php echo esc_attr( $args['id']. '_' . $key ); ?>"><?php echo esc_html( $option['label'] ); ?></label><br/><?php
  197. }
  198. }
  199. $this->field_description( $args );
  200. $this->field_after();
  201. }
  202. #endregion Standard Fields
  203. #region HTML5 Text Fields
  204. /**
  205. * Password Callback
  206. *
  207. * Renders password fields.
  208. *
  209. * @param array $args Arguments passed by the setting
  210. *
  211. * @param string $value
  212. */
  213. public function password_callback( $args, $value = null ) {
  214. $args['type'] = 'password';
  215. $this->text_callback( $args, $value );
  216. }
  217. /**
  218. * Email Callback
  219. *
  220. * Renders email fields.
  221. *
  222. * @param array $args Arguments passed by the setting
  223. *
  224. * @param string $value
  225. */
  226. public function email_callback( $args, $value = null ) {
  227. $args['type'] = 'email';
  228. $this->text_callback( $args, $value );
  229. }
  230. /**
  231. * Search Callback
  232. *
  233. * Renders search fields.
  234. *
  235. * @param array $args Arguments passed by the setting
  236. *
  237. * @param string $value
  238. */
  239. public function search_callback( $args, $value = null ) {
  240. $args['type'] = 'search';
  241. $this->text_callback( $args, $value );
  242. }
  243. /**
  244. * URL Callback
  245. *
  246. * Renders url fields.
  247. *
  248. * @param array $args Arguments passed by the setting
  249. *
  250. * @param string $value
  251. */
  252. public function url_callback( $args, $value = null ) {
  253. $args['type'] = 'url';
  254. $this->text_callback( $args, $value );
  255. }
  256. /**
  257. * Telephone Callback
  258. *
  259. * Renders telelphone number fields.
  260. *
  261. * @param array $args Arguments passed by the setting
  262. *
  263. * @param string $value
  264. */
  265. public function tel_callback( $args, $value = null ) {
  266. $args['type'] = 'tel';
  267. $this->text_callback( $args, $value );
  268. }
  269. /**
  270. * Number Callback
  271. *
  272. * Renders number fields.
  273. *
  274. * @param array $args Arguments passed by the setting
  275. *
  276. * @param string $value
  277. */
  278. public function number_callback( $args, $value = null ) {
  279. $args['type'] = 'number';
  280. $this->text_callback( $args, $value );
  281. }
  282. /**
  283. * Range Callback
  284. *
  285. * Renders range fields.
  286. *
  287. * @param array $args Arguments passed by the setting
  288. *
  289. * @param string $value
  290. */
  291. public function range_callback( $args, $value = null ) {
  292. $args['type'] = 'range';
  293. $this->text_callback( $args, $value );
  294. }
  295. #endregion HTML5 Text Fields
  296. #region Custom Fields (post_type, taxonomy, object, rangeslider)
  297. /**
  298. * Object Select Callback
  299. *
  300. * Renders select fields.
  301. *
  302. * @param array $args Arguments passed by the setting
  303. *
  304. * @param null $value
  305. */
  306. public function objectselect_callback( $args, $value = null ) {
  307. if ( $args['type'] != 'objectselect' ) {
  308. $args['class'] .= ' pum-field-objectselect';
  309. }
  310. $args['class'] .= ' pum-field-select pum-field-select2';
  311. if ( ! $value ) {
  312. $value = isset( $args['std'] ) ? $args['std'] : '';
  313. }
  314. $multiple = null;
  315. if ( $args['multiple'] ) {
  316. $multiple = 'multiple';
  317. $args['class'] .= ' pum-field-select--multiple';
  318. $args['name'] .= $args['as_array'] ? '[]' : '';
  319. $value = ! is_array( $value ) ? array( $value ) : $value;
  320. $value = wp_parse_id_list( $value );
  321. }
  322. $this->field_before( $args );
  323. $this->field_label( $args ); ?>
  324. <select id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" data-placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" data-allow-clear="true" <?php echo $multiple; ?> data-objecttype="<?php echo esc_attr( $args['object_type'] ); ?>" data-objectkey="<?php echo esc_attr( $args['object_key'] ); ?>" data-current="<?php echo maybe_json_attr( $value, true ); ?>" <?php if ( $args['required'] ) { echo 'required'; } ?>>
  325. <?php if ( ! empty( $args['options'] ) ) {
  326. foreach ( $args['options'] as $label => $option ) {
  327. $selected = ( $multiple && in_array( $option, $value ) ) || ( ! $multiple && $option == $value ); ?>
  328. <option value="<?php echo esc_attr( $option ); ?>" <?php selected( 1, $selected ); ?>><?php echo esc_html( $label ); ?></option><?php
  329. }
  330. } ?>
  331. </select><?php
  332. $this->field_description( $args );
  333. $this->field_after();
  334. }
  335. /**
  336. * Taxonomy Select Callback
  337. *
  338. * Renders select fields.
  339. *
  340. * @param array $args Arguments passed by the setting
  341. *
  342. * @param $value
  343. */
  344. public function taxonomyselect_callback( $args, $value ) {
  345. $args['object_type'] = 'taxonomy';
  346. $args['object_key'] = $args['taxonomy'];
  347. $args['class'] = ! empty( $args['class'] ) ? $args['class'] : '' . ' pum-taxonomyselect';
  348. $this->objectselect_callback( $args, $value );
  349. }
  350. /**
  351. * Select Callback
  352. *
  353. * Renders select fields.
  354. *
  355. * @param array $args Arguments passed by the setting
  356. *
  357. * @param $value
  358. */
  359. public function postselect_callback( $args, $value = null ) {
  360. $args['object_type'] = 'post_type';
  361. $args['object_key'] = $args['post_type'];
  362. $args['class'] = ! empty( $args['class'] ) ? $args['class'] : '' . ' pum-postselect';
  363. $this->objectselect_callback( $args, $value );
  364. }
  365. /**
  366. * Rangeslider Callback
  367. *
  368. * Renders the rangeslider.
  369. *
  370. * @param array $args Arguments passed by the setting
  371. *
  372. * @param $value
  373. */
  374. public function rangeslider_callback( $args, $value = null ) {
  375. $this->field_before( $args );
  376. if ( ! $value ) {
  377. $value = isset( $args['std'] ) ? $args['std'] : '';
  378. }
  379. $this->field_label( $args ); ?>
  380. <input type="text"
  381. value="<?php echo $value; ?>"
  382. name="<?php echo esc_attr( $args['name'] ); ?>"
  383. id="<?php echo esc_attr( $args['id'] ); ?>"
  384. class="pum-range-manual popmake-range-manual"
  385. step="<?php echo esc_attr( $args['step'] ); ?>"
  386. min="<?php echo esc_attr( $args['min'] ); ?>"
  387. max="<?php echo esc_attr( $args['max'] ); ?>"
  388. <?php if ( $args['required'] ) { echo 'required'; } ?>
  389. data-force-minmax="<?php echo esc_attr( $args['force_minmax'] ); ?>"
  390. />
  391. <span class="range-value-unit regular-text"><?php echo esc_html( $args['unit'] ); ?></span><?php
  392. $this->field_description( $args );
  393. $this->field_after();
  394. }
  395. #endregion Custom Fields (post_type, taxonomy, object, rangeslider)
  396. #region Templ Non Fields
  397. public function heading_templ_callback( $args ) {
  398. $this->heading_callback( $args );
  399. }
  400. #endregion Non Fields
  401. public function text_templ_callback( $args ) {
  402. if ( $args['type'] != 'text' ) {
  403. $args['class'] .= ' pum-field-text';
  404. }
  405. $this->field_before( $args );
  406. $this->field_label( $args ); ?>
  407. <input type="<?php echo esc_attr( $args['type'] ); ?>" placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" class="<?php echo esc_attr( $args['size'] ); ?>-text" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="{{data.<?php echo $args['templ_name']; ?>}}" /><?php
  408. $this->field_description( $args );
  409. $this->field_after();
  410. }
  411. /**
  412. * Password Callback
  413. *
  414. * Renders password fields.
  415. *
  416. * @param array $args Arguments passed by the setting
  417. */
  418. public function password_templ_callback( $args ) {
  419. $args['type'] = 'password';
  420. $this->text_templ_callback( $args );
  421. }
  422. /**
  423. * Email Callback
  424. *
  425. * Renders email fields.
  426. *
  427. * @param array $args Arguments passed by the setting
  428. *
  429. * @return void
  430. */
  431. public function email_templ_callback( $args ) {
  432. $args['type'] = 'email';
  433. $this->text_templ_callback( $args );
  434. }
  435. /**
  436. * Search Callback
  437. *
  438. * Renders search fields.
  439. *
  440. * @param array $args Arguments passed by the setting
  441. *
  442. * @return void
  443. */
  444. public function search_templ_callback( $args ) {
  445. $args['type'] = 'search';
  446. $this->text_templ_callback( $args );
  447. }
  448. /**
  449. * URL Callback
  450. *
  451. * Renders url fields.
  452. *
  453. * @param array $args Arguments passed by the setting
  454. *
  455. * @return void
  456. */
  457. public function url_templ_callback( $args ) {
  458. $args['type'] = 'url';
  459. $this->text_templ_callback( $args );
  460. }
  461. /**
  462. * Telephone Callback
  463. *
  464. * Renders telelphone number fields.
  465. *
  466. * @param array $args Arguments passed by the setting
  467. *
  468. * @return void
  469. */
  470. public function tel_templ_callback( $args ) {
  471. $args['type'] = 'tel';
  472. $this->text_templ_callback( $args );
  473. }
  474. /**
  475. * Number Callback
  476. *
  477. * Renders number fields.
  478. *
  479. * @param array $args Arguments passed by the setting
  480. *
  481. * @return void
  482. */
  483. public function number_templ_callback( $args ) {
  484. $args['type'] = 'number';
  485. $this->text_templ_callback( $args );
  486. }
  487. /**
  488. * Range Callback
  489. *
  490. * Renders range fields.
  491. *
  492. * @param array $args Arguments passed by the setting
  493. *
  494. * @return void
  495. */
  496. public function range_templ_callback( $args ) {
  497. $args['type'] = 'range';
  498. $this->text_templ_callback( $args );
  499. }
  500. /**
  501. * Hidden Callback
  502. *
  503. * Renders hidden fields.
  504. *
  505. * @param array $args Arguments passed by the setting
  506. */
  507. public function hidden_templ_callback( $args ) {
  508. $class = $this->field_classes( $args ); ?>
  509. <input type="hidden" class="<?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="{{data.<?php echo $args['templ_name']; ?>}}"/><?php
  510. }
  511. public function select_templ_callback( $args ) {
  512. if ( $args['select2'] ) {
  513. $args['class'] .= ' pum-field-select2';
  514. }
  515. $multiple = null;
  516. if ( $args['multiple'] ) {
  517. $multiple = 'multiple';
  518. $args['class'] .= ' pum-field-select--multiple';
  519. $args['name'] .= $args['as_array'] ? '[]' : '';
  520. }
  521. $this->field_before( $args );
  522. $this->field_label( $args ); ?>
  523. <select id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" data-placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" data-allow-clear="true" <?php echo $multiple; ?>>
  524. <?php if ( ! empty( $args['options'] ) ) {
  525. foreach ( $args['options'] as $label => $option ) { ?>
  526. <option value="<?php echo esc_attr( $option ); ?>" {{pumSelected(data.<?php echo esc_attr( $args['templ_name'] ); ?>, '<?php echo $option; ?>', true)}}>
  527. <?php echo esc_html( $label ); ?>
  528. </option><?php
  529. }
  530. } ?>
  531. </select><?php
  532. $this->field_description( $args );
  533. $this->field_after();
  534. }
  535. /**
  536. * Posttype Select Callback
  537. *
  538. * Renders select fields.
  539. *
  540. * @param array $args Arguments passed by the setting
  541. */
  542. public function postselect_templ_callback( $args ) {
  543. $args['object_type'] = 'post_type';
  544. $args['object_key'] = $args['post_type'];
  545. $args['class'] .= ' pum-postselect';
  546. $this->objectselect_templ_callback( $args );
  547. }
  548. public function objectselect_templ_callback( $args ) {
  549. if ( $args['type'] != 'objectselect' ) {
  550. $args['class'] .= ' pum-field-objectselect';
  551. }
  552. $args['class'] .= ' pum-field-select pum-field-select2';
  553. $multiple = null;
  554. if ( $args['multiple'] ) {
  555. $multiple = 'multiple';
  556. $args['class'] .= ' pum-field-select--multiple';
  557. $args['name'] .= $args['as_array'] ? '[]' : '';
  558. }
  559. $this->field_before( $args );
  560. $this->field_label( $args ); ?>
  561. <# var templ_name = '<?php echo esc_attr( $args['templ_name'] ); ?>'; #>
  562. <# if (typeof data[templ_name] === 'undefined') {
  563. data[templ_name] = '';
  564. } #>
  565. <select id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" data-placeholder="<?php echo esc_attr( $args['placeholder'] ); ?>" data-allow-clear="true" <?php echo $multiple; ?> data-objecttype="<?php echo esc_attr( $args['object_type'] ); ?>" data-objectkey="<?php echo esc_attr( $args['object_key'] ); ?>">
  566. <?php if ( ! empty( $args['options'] ) ) {
  567. foreach ( $args['options'] as $label => $option ) { ?>
  568. <option value="<?php echo esc_attr( $option ); ?>" {{pumSelected(data[templ_name], '<?php echo $option; ?>', true)}}>
  569. <?php echo esc_html( $label ); ?>
  570. </option><?php
  571. }
  572. } ?>
  573. </select><?php
  574. $this->field_description( $args );
  575. $this->field_after();
  576. }
  577. /**
  578. * Select Callback
  579. *
  580. * Renders select fields.
  581. *
  582. * @param array $args Arguments passed by the setting
  583. */
  584. public function taxonomyselect_templ_callback( $args ) {
  585. $args['object_type'] = 'taxonomy';
  586. $args['object_key'] = $args['taxonomy'];
  587. $args['class'] .= ' pum-field-taxonomyselect';
  588. $this->objectselect_templ_callback( $args );
  589. }
  590. public function checkbox_templ_callback( $args ) {
  591. $this->field_before( $args );
  592. $this->field_label( $args ); ?>
  593. <# var checked = data.<?php echo esc_attr( $args['templ_name'] ); ?> !== undefined && data.<?php echo esc_attr( $args['templ_name'] ); ?> ? true : false; #>
  594. <input type="checkbox" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="<?php echo esc_attr( $args['checkbox_val'] ); ?>" {{pumChecked(checked, true, true)}} /><?php
  595. $this->field_description( $args );
  596. $this->field_after();
  597. }
  598. public function multicheck_templ_callback( $args ) {
  599. $this->field_before( $args );
  600. $this->field_label( $args );
  601. $this->field_description( $args ); ?>
  602. <# var checked = data.<?php echo esc_attr( $args['templ_name'] ); ?> !== undefined && data.<?php echo esc_attr( $args['templ_name'] ); ?> && typeof data.<?php echo esc_attr( $args['templ_name'] ); ?> === 'object' ? data.<?php echo esc_attr( $args['templ_name'] ); ?> : {}; #>
  603. <?php
  604. if ( ! empty( $args['options'] ) ) {
  605. foreach ( $args['options'] as $option => $label ) { ?>
  606. <# if (checked.<?php echo esc_attr( $option ); ?> === undefined) {
  607. checked.<?php echo esc_attr( $option ); ?> = false;
  608. } #>
  609. <input name="<?php echo esc_attr( $args['name'] ); ?>[<?php echo esc_attr( $option ); ?>]" id="<?php echo esc_attr( $args['id'] ); ?>_<?php echo esc_attr( $option ); ?>" type="checkbox" value="<?php echo esc_html( $option ); ?>" {{pumChecked(checked.<?php echo esc_attr( $option ); ?>, '<?php echo $option; ?>', true)}} />&nbsp;
  610. <label for="<?php echo esc_attr( $args['id'] ); ?>_<?php echo esc_attr( $option ); ?>"><?php echo esc_html( $label ); ?></label><br/><?php
  611. }
  612. }
  613. $this->field_after();
  614. }
  615. public function rangeslider_templ_callback( $args ) {
  616. $value = '{{data.' . $args['templ_name'] . '}}';
  617. $this->rangeslider_callback( $args, $value );
  618. }
  619. public function postselect_sanitize( $value = array(), $args = array() ) {
  620. return $this->objectselect_sanitize( $value, $args );
  621. }
  622. public function objectselect_sanitize( $value = array(), $args = array() ) {
  623. return wp_parse_id_list( $value );
  624. }
  625. public function taxonomyselect_sanitize( $value = array(), $args = array() ) {
  626. return $this->objectselect_sanitize( $value, $args );
  627. }
  628. /**
  629. * TODO: Finish adding the following field types for HTML & underscore.js
  630. */
  631. /*
  632. * Radio Callback
  633. *
  634. * Renders radio boxes.
  635. *
  636. * @param array $args Arguments passed by the setting
  637. *
  638. * @return void
  639. *
  640. * public function radio_callback( $args, $value ) {
  641. * if ( ! empty( $args['options'] ) ) {
  642. *
  643. * foreach ( $args['options'] as $key => $option ) {
  644. * $checked = false;
  645. *
  646. * $value = $this->get_option( $args['id'] );
  647. *
  648. * if ( $value == $key || ( ! $value && isset( $args['std'] ) && $args['std'] == $key ) ) {
  649. * $checked = true;
  650. * }
  651. *
  652. * echo '<input name="<?php echo esc_attr( $args['name'] ); ?>"" id="<?php echo esc_attr( $args['id'] ); ?>[<?php echo esc_attr( $key ); ?>]" type="radio" value="<?php echo esc_attr( $key ); ?>" ' . checked( true, $checked, false ) . '/>&nbsp;';
  653. * echo '<label for="<?php echo esc_attr( $args['id'] ); ?>[<?php echo esc_attr( $key ); ?>]">' . $option . '</label><br/>';
  654. * }
  655. *
  656. * echo '<p class="pum-desc">' . $args['desc'] . '</p>';
  657. *
  658. * }
  659. * }
  660. *
  661. *
  662. *
  663. *
  664. *
  665. *
  666. *
  667. * /**
  668. * Color select Callback
  669. *
  670. * Renders color select fields.
  671. *
  672. * @param array $args Arguments passed by the setting
  673. *
  674. * @return void
  675. *
  676. * public function color_select_callback( $args ) {
  677. *
  678. * $value = $this->get_option( $args['id'] );
  679. *
  680. * if ( ! $value ) {
  681. * $value = isset( $args['std'] ) ? $args['std'] : '';
  682. * }
  683. *
  684. * $html = '<select id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>"/>';
  685. *
  686. * if ( ! empty( $args['options'] ) ) {
  687. * foreach ( $args['options'] as $option => $color ) {
  688. * $selected = selected( $option, $value, false );
  689. * $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>';
  690. * }
  691. * }
  692. *
  693. * $html .= '</select>';
  694. * $html .= '<label for="<?php echo esc_attr( $args['id'] ); ?>"> ' . $args['desc'] . '</label>';
  695. *
  696. * echo $html;
  697. * }
  698. *
  699. * /**
  700. * Rich Editor Callback
  701. *
  702. * Renders rich editor fields.
  703. *
  704. * @param array $args Arguments passed by the setting
  705. *
  706. * @global $wp_version WordPress Version
  707. *
  708. * public function rich_editor_callback( $args ) {
  709. * global $wp_version;
  710. * $value = $this->get_option( $args['id'] );
  711. *
  712. * if ( ! $value ) {
  713. * $value = isset( $args['std'] ) ? $args['std'] : '';
  714. * }
  715. *
  716. * $rows = isset( $args['size'] ) ? $args['size'] : 20;
  717. *
  718. * if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
  719. * ob_start();
  720. * wp_editor( stripslashes( $value ), $this->options_key . '_' . $args['id'], array(
  721. * 'textarea_name' => '' . $this->options_key . '[' . $args['id'] . ']',
  722. * 'textarea_rows' => $rows
  723. * ) );
  724. * $html = ob_get_clean();
  725. * } else {
  726. * $html = '<textarea class="large-text" rows="10" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
  727. * }
  728. *
  729. * $html .= '<br/><label for="<?php echo esc_attr( $args['id'] ); ?>"> ' . $args['desc'] . '</label>';
  730. *
  731. * echo $html;
  732. * }
  733. *
  734. * /**
  735. * Upload Callback
  736. *
  737. * Renders upload fields.
  738. *
  739. * @param array $args Arguments passed by the setting
  740. *
  741. * @return void
  742. *
  743. * public function upload_callback( $args ) {
  744. * $value = $this->get_option( $args['id'] );
  745. *
  746. * if ( ! $value ) {
  747. * $value = isset( $args['std'] ) ? $args['std'] : '';
  748. * }
  749. *
  750. * $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
  751. * $html = '<input type="text" class="' . $size . '-text" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="' . echo esc_attr( stripslashes( $value ) ) . '"/>';
  752. * $html .= '<span>&nbsp;<input type="button" class="' . $this->options_key . '_upload_button button-secondary" value="' . __( 'Upload File' ) . '"/></span>';
  753. * $html .= '<label for="<?php echo esc_attr( $args['id'] ); ?>"> ' . $args['desc'] . '</label>';
  754. *
  755. * echo $html;
  756. * }
  757. *
  758. * /**
  759. * Color picker Callback
  760. *
  761. * Renders color picker fields.
  762. *
  763. * @param array $args Arguments passed by the setting
  764. *
  765. * @return void
  766. *
  767. * public function color_callback( $args ) {
  768. * $value = $this->get_option( $args['id'] );
  769. *
  770. * if ( ! $value ) {
  771. * $value = isset( $args['std'] ) ? $args['std'] : '';
  772. * }
  773. *
  774. * $default = isset( $args['std'] ) ? $args['std'] : '';
  775. *
  776. * $html = '<input type="text" class="di-color-picker" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="' . echo esc_attr( $value ) . '" data-default-color="' . echo esc_attr( $default ) . '" />';
  777. * $html .= '<label for="<?php echo esc_attr( $args['id'] ); ?>"> ' . $args['desc'] . '</label>';
  778. *
  779. * echo $html;
  780. * }
  781. *
  782. * /**
  783. * Descriptive text callback.
  784. *
  785. * Renders descriptive text onto the settings field.
  786. *
  787. * @param array $args Arguments passed by the setting
  788. *
  789. * @return void
  790. *
  791. * public function descriptive_text_callback( $args ) {
  792. * echo esc_html( $args['desc'] );
  793. * }
  794. *
  795. * /**
  796. * Registers the license field callback for Software Licensing
  797. *
  798. * @param array $args Arguments passed by the setting
  799. *
  800. * @return void
  801. *
  802. * public function license_key_callback( $args ) {
  803. * $value = $this->get_option( $args['id'] );
  804. *
  805. * if ( ! $value ) {
  806. * $value = isset( $args['std'] ) ? $args['std'] : '';
  807. * }
  808. *
  809. * $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
  810. *
  811. * $html = '<input type="' . ( $value == '' ? 'text' : 'password' ) . '" class="' . $size . '-text" id="<?php echo esc_attr( $args['id'] ); ?>" name="<?php echo esc_attr( $args['name'] ); ?>" value="' . echo esc_attr( $value ) . '"/>';
  812. *
  813. * if ( 'valid' == get_option( $args['options']['is_valid_license_option'] ) ) {
  814. * $html .= '<input type="submit" class="button-secondary" name="' . $args['id'] . '_deactivate" value="' . __( 'Deactivate License' ) . '"/>';
  815. * }
  816. * $html .= '<label for="<?php echo esc_attr( $args['id'] ); ?>"> ' . $args['desc'] . '</label>';
  817. *
  818. * echo $html;
  819. * }
  820. *
  821. * */
  822. }