PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.9
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.9
2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 2.7.1 All 27 releases
insert-php / includes / controls / class.dropdown.php

class.dropdown.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.4.9, at includes/controls/class.dropdown.php

87 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Woody Dropdown List Control
5 *
6 * Main options:
7 * name => a name of the control
8 * value => a value to show in the control
9 * default => a default value of the control if the "value" option is not specified
10 * items => a callback to return items or an array of items to select
11 *
12 * @author Artem Prihodko <webtemyk@ya.ru>
13 * @copyright (c) 2021, CreativeMotion
14 *
15 * @package factory-forms
16 * @since 1.0.0
17 */
18
19 // Exit if accessed directly
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 if ( ! class_exists( 'WINP_FactoryForms_Dropdown' ) ) {
25
26 class WINP_FactoryForms_Dropdown extends Wbcr_FactoryForms460_DropdownControl {
27
28 public $type = 'winp-dropdown';
29
30 /**
31 * @param array $items
32 * @param null $selected
33 */
34 protected function printItems( $items, $selected = null ) {
35 foreach ( (array) $items as $item ) {
36 $subitems = array();
37 $data = null;
38
39 // this item is an associative array
40 if ( isset( $item['type'] ) || isset( $item['value'] ) ) {
41 $type = isset( $item['type'] ) ? $item['type'] : 'option';
42 $disabled = isset( $item['disabled'] ) && $item['disabled'] == 'disabled' ? 'disabled' : '';
43
44 if ( 'group' === $type ) {
45 $subitems = isset( $item['items'] ) ? $item['items'] : array();
46 }
47
48 $value = isset( $item['value'] ) ? $item['value'] : '';
49 $title = isset( $item['title'] ) ? $item['title'] : __( '- empty -', 'wbcr_factory_forms_460' );
50
51 $data = isset( $item['data'] ) ? $item['data'] : null;
52 } else {
53 $type = ( count( $item ) == 3 && $item[0] === 'group' ) ? 'group' : 'option';
54 if ( 'group' === $type ) {
55 $subitems = $item[2];
56 }
57
58 $title = $item[1];
59 $value = esc_attr( $item[0] );
60 }
61
62 if ( 'group' === $type ) {
63 ?>
64 <optgroup label="<?php echo $title ?>" <?php echo $disabled; ?>>
65 <?php $this->printItems( $subitems, $selected ); ?>
66 </optgroup>
67 <?php
68 } else {
69 $attr = ( $selected == $value ) ? 'selected="selected"' : '';
70 $strData = '';
71
72 if ( ! empty( $data ) ) {
73 foreach ( $data as $key => $values ) {
74 $strData = $strData . ' data-' . $key . '="' . ( is_array( $values ) ? implode( ',', $values ) : $values ) . '"';
75 }
76 }
77
78 ?>
79 <option value='<?php echo $value ?>' <?php echo $attr ?> <?php echo $strData ?>>
80 <?php echo $title ?>
81 </option>
82 <?php
83 }
84 }
85 }
86 }
87 }