@@ -12,19 +12,19 @@ |
||
12 | 12 | */ |
13 | 13 | class CMB2_Type_Text_Date extends CMB2_Type_Picker_Base { |
14 | 14 | |
15 | - public function render( $args = array() ) { |
|
16 | - $args = $this->parse_args( 'text_date', array( |
|
15 | + public function render($args = array()) { |
|
16 | + $args = $this->parse_args('text_date', array( |
|
17 | 17 | 'class' => 'cmb2-text-small cmb2-datepicker', |
18 | 18 | 'value' => $this->field->get_timestamp_format(), |
19 | 19 | 'desc' => $this->_desc(), |
20 | - 'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ), |
|
21 | - ) ); |
|
20 | + 'js_dependencies' => array('jquery-ui-core', 'jquery-ui-datepicker'), |
|
21 | + )); |
|
22 | 22 | |
23 | - if ( false === strpos( $args['class'], 'timepicker' ) ) { |
|
24 | - $this->parse_picker_options( 'date' ); |
|
23 | + if (false === strpos($args['class'], 'timepicker')) { |
|
24 | + $this->parse_picker_options('date'); |
|
25 | 25 | } |
26 | 26 | |
27 | - return parent::render( $args ); |
|
27 | + return parent::render($args); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param array $args Array of arguments for the type. |
29 | 29 | * @param mixed $is_checked Whether or not the field is checked, or default value. |
30 | 30 | */ |
31 | - public function __construct( CMB2_Types $types, $args = array(), $is_checked = null ) { |
|
32 | - parent::__construct( $types, $args ); |
|
31 | + public function __construct(CMB2_Types $types, $args = array(), $is_checked = null) { |
|
32 | + parent::__construct($types, $args); |
|
33 | 33 | $this->is_checked = $is_checked; |
34 | 34 | } |
35 | 35 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param array $args Array of arguments for the rendering. |
42 | 42 | * @return CMB2_Type_Base|string |
43 | 43 | */ |
44 | - public function render( $args = array() ) { |
|
44 | + public function render($args = array()) { |
|
45 | 45 | $defaults = array( |
46 | 46 | 'type' => 'checkbox', |
47 | 47 | 'class' => 'cmb2-option cmb2-list', |
@@ -52,20 +52,20 @@ discard block |
||
52 | 52 | $meta_value = $this->field->escaped_value(); |
53 | 53 | |
54 | 54 | $is_checked = null === $this->is_checked |
55 | - ? ! empty( $meta_value ) |
|
55 | + ? ! empty($meta_value) |
|
56 | 56 | : $this->is_checked; |
57 | 57 | |
58 | - if ( $is_checked ) { |
|
58 | + if ($is_checked) { |
|
59 | 59 | $defaults['checked'] = 'checked'; |
60 | 60 | } |
61 | 61 | |
62 | - $args = $this->parse_args( 'checkbox', $defaults ); |
|
62 | + $args = $this->parse_args('checkbox', $defaults); |
|
63 | 63 | |
64 | 64 | return $this->rendered( |
65 | 65 | sprintf( |
66 | 66 | '%s <label for="%s">%s</label>', |
67 | - parent::render( $args ), |
|
68 | - $this->_id( '', false ), |
|
67 | + parent::render($args), |
|
68 | + $this->_id('', false), |
|
69 | 69 | $this->_desc() |
70 | 70 | ) |
71 | 71 | ); |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * @param CMB2_Types $types Object for the field type. |
41 | 41 | * @param array $args Array of arguments for the type. |
42 | 42 | */ |
43 | - public function __construct( CMB2_Types $types, $args = array() ) { |
|
43 | + public function __construct(CMB2_Types $types, $args = array()) { |
|
44 | 44 | $this->types = $types; |
45 | - $args['rendered'] = isset( $args['rendered'] ) ? (bool) $args['rendered'] : true; |
|
45 | + $args['rendered'] = isset($args['rendered']) ? (bool) $args['rendered'] : true; |
|
46 | 46 | $this->args = $args; |
47 | 47 | } |
48 | 48 | |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | * @param string|CMB2_Type_Base $rendered Rendered output. |
62 | 62 | * @return string|CMB2_Type_Base Rendered output or this object. |
63 | 63 | */ |
64 | - public function rendered( $rendered ) { |
|
64 | + public function rendered($rendered) { |
|
65 | 65 | $this->field->register_js_data(); |
66 | 66 | |
67 | - if ( $this->args['rendered'] ) { |
|
68 | - return is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered; |
|
67 | + if ($this->args['rendered']) { |
|
68 | + return is_a($rendered, __CLASS__) ? $rendered->rendered : $rendered; |
|
69 | 69 | } |
70 | 70 | |
71 | - $this->rendered = is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered; |
|
71 | + $this->rendered = is_a($rendered, __CLASS__) ? $rendered->rendered : $rendered; |
|
72 | 72 | |
73 | 73 | return $this; |
74 | 74 | } |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * @param array $type_overrides Type override arguments. |
93 | 93 | * @return array Parsed and filtered arguments. |
94 | 94 | */ |
95 | - public function parse_args( $element, $type_defaults, $type_overrides = array() ) { |
|
96 | - $args = $this->parse_args_from_overrides( $type_overrides ); |
|
95 | + public function parse_args($element, $type_defaults, $type_overrides = array()) { |
|
96 | + $args = $this->parse_args_from_overrides($type_overrides); |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * Filter attributes for a field type. |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | * @param array $field The `CMB2_Field` object. |
106 | 106 | * @param object $field_type_object This `CMB2_Types` object. |
107 | 107 | */ |
108 | - $args = apply_filters( "cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types ); |
|
108 | + $args = apply_filters("cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types); |
|
109 | 109 | |
110 | - $args = wp_parse_args( $args, $type_defaults ); |
|
110 | + $args = wp_parse_args($args, $type_defaults); |
|
111 | 111 | |
112 | - if ( ! empty( $args['js_dependencies'] ) ) { |
|
113 | - $this->field->add_js_dependencies( $args['js_dependencies'] ); |
|
112 | + if ( ! empty($args['js_dependencies'])) { |
|
113 | + $this->field->add_js_dependencies($args['js_dependencies']); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | return $args; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | * @param array $type_overrides Type override arguments. |
124 | 124 | * @return array Parsed arguments |
125 | 125 | */ |
126 | - protected function parse_args_from_overrides( $type_overrides = array() ) { |
|
127 | - $type_overrides = empty( $type_overrides ) ? $this->args : $type_overrides; |
|
126 | + protected function parse_args_from_overrides($type_overrides = array()) { |
|
127 | + $type_overrides = empty($type_overrides) ? $this->args : $type_overrides; |
|
128 | 128 | |
129 | - if ( true !== $this->field->args( 'disable_hash_data_attribute' ) ) { |
|
129 | + if (true !== $this->field->args('disable_hash_data_attribute')) { |
|
130 | 130 | $type_overrides['data-hash'] = $this->field->hash_id(); |
131 | 131 | } |
132 | 132 | |
133 | - $field_overrides = $this->field->args( 'attributes' ); |
|
133 | + $field_overrides = $this->field->args('attributes'); |
|
134 | 134 | |
135 | - return ! empty( $field_overrides ) |
|
136 | - ? wp_parse_args( $field_overrides, $type_overrides ) |
|
135 | + return ! empty($field_overrides) |
|
136 | + ? wp_parse_args($field_overrides, $type_overrides) |
|
137 | 137 | : $type_overrides; |
138 | 138 | } |
139 | 139 | |
@@ -145,16 +145,16 @@ discard block |
||
145 | 145 | * @throws Exception Throws an exception if the field is invalid. |
146 | 146 | * @return mixed |
147 | 147 | */ |
148 | - public function __call( $method, $arguments ) { |
|
149 | - switch ( $method ) { |
|
148 | + public function __call($method, $arguments) { |
|
149 | + switch ($method) { |
|
150 | 150 | case '_id': |
151 | 151 | case '_name': |
152 | 152 | case '_desc': |
153 | 153 | case '_text': |
154 | 154 | case 'concat_attrs': |
155 | - return call_user_func_array( array( $this->types, $method ), $arguments ); |
|
155 | + return call_user_func_array(array($this->types, $method), $arguments); |
|
156 | 156 | default: |
157 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), __CLASS__, $method ) ); |
|
157 | + throw new Exception(sprintf(esc_html__('Invalid %1$s method: %2$s', 'cmb2'), __CLASS__, $method)); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -165,12 +165,12 @@ discard block |
||
165 | 165 | * @throws Exception Throws an exception if the field is invalid. |
166 | 166 | * @return mixed |
167 | 167 | */ |
168 | - public function __get( $field ) { |
|
169 | - switch ( $field ) { |
|
168 | + public function __get($field) { |
|
169 | + switch ($field) { |
|
170 | 170 | case 'field': |
171 | 171 | return $this->types->field; |
172 | 172 | default: |
173 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) ); |
|
173 | + throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field)); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 |
@@ -18,28 +18,28 @@ discard block |
||
18 | 18 | * @param array $args Override arguments. |
19 | 19 | * @return string Form input element |
20 | 20 | */ |
21 | - public function render( $args = array() ) { |
|
22 | - $args = empty( $args ) ? $this->args : $args; |
|
21 | + public function render($args = array()) { |
|
22 | + $args = empty($args) ? $this->args : $args; |
|
23 | 23 | $field = $this->field; |
24 | 24 | $options = (array) $field->options(); |
25 | 25 | |
26 | - $a = $this->args = $this->parse_args( 'file', array( |
|
26 | + $a = $this->args = $this->parse_args('file', array( |
|
27 | 27 | 'class' => 'cmb2-upload-file regular-text', |
28 | 28 | 'id' => $this->_id(), |
29 | 29 | 'name' => $this->_name(), |
30 | 30 | 'value' => $field->escaped_value(), |
31 | 31 | 'id_value' => null, |
32 | - 'desc' => $this->_desc( true ), |
|
32 | + 'desc' => $this->_desc(true), |
|
33 | 33 | 'size' => 45, |
34 | 34 | 'js_dependencies' => 'media-editor', |
35 | - 'preview_size' => $field->args( 'preview_size' ), |
|
36 | - 'query_args' => $field->args( 'query_args' ), |
|
35 | + 'preview_size' => $field->args('preview_size'), |
|
36 | + 'query_args' => $field->args('query_args'), |
|
37 | 37 | |
38 | 38 | // if options array and 'url' => false, then hide the url field. |
39 | - 'type' => array_key_exists( 'url', $options ) && false === $options['url'] |
|
39 | + 'type' => array_key_exists('url', $options) && false === $options['url'] |
|
40 | 40 | ? 'hidden' |
41 | 41 | : 'text', |
42 | - ), $args ); |
|
42 | + ), $args); |
|
43 | 43 | |
44 | 44 | // get an array of image size meta data, fallback to 'large'. |
45 | 45 | $this->args['img_size_data'] = $img_size_data = parent::get_image_size_data( |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | $output = ''; |
51 | 51 | |
52 | - $output .= parent::render( array( |
|
52 | + $output .= parent::render(array( |
|
53 | 53 | 'type' => $a['type'], |
54 | 54 | 'class' => $a['class'], |
55 | 55 | 'value' => $a['value'], |
@@ -57,35 +57,35 @@ discard block |
||
57 | 57 | 'name' => $a['name'], |
58 | 58 | 'size' => $a['size'], |
59 | 59 | 'desc' => '', |
60 | - 'data-previewsize' => sprintf( '[%d,%d]', $img_size_data['width'], $img_size_data['height'] ), |
|
60 | + 'data-previewsize' => sprintf('[%d,%d]', $img_size_data['width'], $img_size_data['height']), |
|
61 | 61 | 'data-sizename' => $img_size_data['name'], |
62 | - 'data-queryargs' => ! empty( $a['query_args'] ) ? json_encode( $a['query_args'] ) : '', |
|
62 | + 'data-queryargs' => ! empty($a['query_args']) ? json_encode($a['query_args']) : '', |
|
63 | 63 | 'js_dependencies' => $a['js_dependencies'], |
64 | - ) ); |
|
64 | + )); |
|
65 | 65 | |
66 | 66 | // Now remove the data-iterator attribute if it exists. |
67 | 67 | // (Possible if being used within a custom field) |
68 | 68 | // This is not elegant, but compensates for CMB2_Types::_id |
69 | 69 | // automagically & inelegantly adding the data-iterator attribute. |
70 | 70 | // Single responsibility principle? pffft. |
71 | - $parts = explode( '"', $this->args['id'] ); |
|
71 | + $parts = explode('"', $this->args['id']); |
|
72 | 72 | $this->args['id'] = $parts[0]; |
73 | 73 | |
74 | 74 | $output .= sprintf( |
75 | 75 | '<input class="cmb2-upload-button button-secondary" type="button" value="%1$s" />', |
76 | - esc_attr( $this->_text( 'add_upload_file_text', esc_html__( 'Add or Upload File', 'cmb2' ) ) ) |
|
76 | + esc_attr($this->_text('add_upload_file_text', esc_html__('Add or Upload File', 'cmb2'))) |
|
77 | 77 | ); |
78 | 78 | |
79 | 79 | $output .= $a['desc']; |
80 | 80 | $output .= $this->get_id_field_output(); |
81 | 81 | |
82 | - $output .= '<div id="' . esc_attr( $field->id() ) . '-status" class="cmb2-media-status">'; |
|
83 | - if ( ! empty( $a['value'] ) ) { |
|
82 | + $output .= '<div id="' . esc_attr($field->id()) . '-status" class="cmb2-media-status">'; |
|
83 | + if ( ! empty($a['value'])) { |
|
84 | 84 | $output .= $this->get_file_preview_output(); |
85 | 85 | } |
86 | 86 | $output .= '</div>'; |
87 | 87 | |
88 | - return $this->rendered( $output ); |
|
88 | + return $this->rendered($output); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -96,28 +96,28 @@ discard block |
||
96 | 96 | * @return string |
97 | 97 | */ |
98 | 98 | public function get_file_preview_output() { |
99 | - if ( ! $this->is_valid_img_ext( $this->args['value'] ) ) { |
|
99 | + if ( ! $this->is_valid_img_ext($this->args['value'])) { |
|
100 | 100 | |
101 | - return $this->file_status_output( array( |
|
101 | + return $this->file_status_output(array( |
|
102 | 102 | 'value' => $this->args['value'], |
103 | 103 | 'tag' => 'div', |
104 | 104 | 'cached_id' => $this->args['id'], |
105 | - ) ); |
|
105 | + )); |
|
106 | 106 | } |
107 | 107 | |
108 | - if ( $this->args['id_value'] ) { |
|
109 | - $image = wp_get_attachment_image( $this->args['id_value'], $this->args['preview_size'], null, array( |
|
108 | + if ($this->args['id_value']) { |
|
109 | + $image = wp_get_attachment_image($this->args['id_value'], $this->args['preview_size'], null, array( |
|
110 | 110 | 'class' => 'cmb-file-field-image', |
111 | - ) ); |
|
111 | + )); |
|
112 | 112 | } else { |
113 | - $image = '<img style="max-width: ' . absint( $this->args['img_size_data']['width'] ) . 'px; width: 100%;" src="' . esc_url( $this->args['value'] ) . '" class="cmb-file-field-image" alt="" />'; |
|
113 | + $image = '<img style="max-width: ' . absint($this->args['img_size_data']['width']) . 'px; width: 100%;" src="' . esc_url($this->args['value']) . '" class="cmb-file-field-image" alt="" />'; |
|
114 | 114 | } |
115 | 115 | |
116 | - return $this->img_status_output( array( |
|
116 | + return $this->img_status_output(array( |
|
117 | 117 | 'image' => $image, |
118 | 118 | 'tag' => 'div', |
119 | 119 | 'cached_id' => $this->args['id'], |
120 | - ) ); |
|
120 | + )); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | */ |
137 | 137 | $this->types->field = $this->get_id_field(); |
138 | 138 | |
139 | - $output = parent::render( array( |
|
139 | + $output = parent::render(array( |
|
140 | 140 | 'type' => 'hidden', |
141 | 141 | 'class' => 'cmb2-upload-file-id', |
142 | 142 | 'value' => $this->types->field->value, |
143 | 143 | 'desc' => '', |
144 | - ) ); |
|
144 | + )); |
|
145 | 145 | |
146 | 146 | // We need to put the original field object back |
147 | 147 | // or other fields in a custom field will be broken. |
@@ -162,24 +162,24 @@ discard block |
||
162 | 162 | // reset field args for attachment id. |
163 | 163 | $args = array( |
164 | 164 | // if we're looking at a file in a group, we need to get the non-prefixed id. |
165 | - 'id' => ( $this->field->group ? $this->field->args( '_id' ) : $this->args['id'] ) . '_id', |
|
165 | + 'id' => ($this->field->group ? $this->field->args('_id') : $this->args['id']) . '_id', |
|
166 | 166 | 'disable_hash_data_attribute' => true, |
167 | 167 | ); |
168 | 168 | |
169 | 169 | // and get new field object |
170 | 170 | // (need to set it to the types field property). |
171 | - $id_field = $this->field->get_field_clone( $args ); |
|
171 | + $id_field = $this->field->get_field_clone($args); |
|
172 | 172 | |
173 | - $id_value = absint( null !== $this->args['id_value'] ? $this->args['id_value'] : $id_field->escaped_value() ); |
|
173 | + $id_value = absint(null !== $this->args['id_value'] ? $this->args['id_value'] : $id_field->escaped_value()); |
|
174 | 174 | |
175 | 175 | // we don't want to output "0" as a value. |
176 | - if ( ! $id_value ) { |
|
176 | + if ( ! $id_value) { |
|
177 | 177 | $id_value = ''; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // if there is no id saved yet, try to get it from the url. |
181 | - if ( $this->args['value'] && ! $id_value ) { |
|
182 | - $id_value = CMB2_Utils::image_id_from_url( esc_url_raw( $this->args['value'] ) ); |
|
181 | + if ($this->args['value'] && ! $id_value) { |
|
182 | + $id_value = CMB2_Utils::image_id_from_url(esc_url_raw($this->args['value'])); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | $id_field->value = $id_value; |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | * @return mixed Array of terms on success |
27 | 27 | */ |
28 | 28 | public function get_object_terms() { |
29 | - switch ( $this->field->object_type ) { |
|
29 | + switch ($this->field->object_type) { |
|
30 | 30 | case 'options-page': |
31 | 31 | case 'term': |
32 | 32 | return $this->options_terms(); |
33 | 33 | case 'post': |
34 | 34 | // WP caches internally so it's better to use |
35 | - return get_the_terms( $this->field->object_id, $this->field->args( 'taxonomy' ) ); |
|
35 | + return get_the_terms($this->field->object_id, $this->field->args('taxonomy')); |
|
36 | 36 | |
37 | 37 | default: |
38 | 38 | return $this->non_post_object_terms(); |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * @return mixed Array of terms on success |
47 | 47 | */ |
48 | 48 | public function options_terms() { |
49 | - if ( empty( $this->field->value ) ) { |
|
49 | + if (empty($this->field->value)) { |
|
50 | 50 | return array(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | $terms = (array) $this->field->value; |
54 | 54 | |
55 | - foreach ( $terms as $index => $term ) { |
|
56 | - $terms[ $index ] = get_term_by( 'slug', $term, $this->field->args( 'taxonomy' ) ); |
|
55 | + foreach ($terms as $index => $term) { |
|
56 | + $terms[$index] = get_term_by('slug', $term, $this->field->args('taxonomy')); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | return $terms; |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function non_post_object_terms() { |
69 | 69 | $object_id = $this->field->object_id; |
70 | - $taxonomy = $this->field->args( 'taxonomy' ); |
|
70 | + $taxonomy = $this->field->args('taxonomy'); |
|
71 | 71 | |
72 | 72 | $cache_key = "cmb-cache-{$taxonomy}-{$object_id}"; |
73 | 73 | |
74 | 74 | // Check cache |
75 | - $cached = get_transient( $cache_key ); |
|
75 | + $cached = get_transient($cache_key); |
|
76 | 76 | |
77 | - if ( ! $cached ) { |
|
78 | - $cached = wp_get_object_terms( $object_id, $taxonomy ); |
|
77 | + if ( ! $cached) { |
|
78 | + $cached = wp_get_object_terms($object_id, $taxonomy); |
|
79 | 79 | // Do our own (minimal) caching. Long enough for a page-load. |
80 | - set_transient( $cache_key, $cached, 60 ); |
|
80 | + set_transient($cache_key, $cached, 60); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | return $cached; |
@@ -92,41 +92,41 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function get_terms() { |
94 | 94 | $args = array( |
95 | - 'taxonomy' => $this->field->args( 'taxonomy' ), |
|
95 | + 'taxonomy' => $this->field->args('taxonomy'), |
|
96 | 96 | 'hide_empty' => false, |
97 | 97 | ); |
98 | 98 | |
99 | - if ( null !== $this->parent ) { |
|
99 | + if (null !== $this->parent) { |
|
100 | 100 | $args['parent'] = $this->parent; |
101 | 101 | } |
102 | 102 | |
103 | - $args = wp_parse_args( $this->field->prop( 'query_args', array() ), $args ); |
|
103 | + $args = wp_parse_args($this->field->prop('query_args', array()), $args); |
|
104 | 104 | |
105 | - return CMB2_Utils::wp_at_least( '4.5.0' ) |
|
106 | - ? get_terms( $args ) |
|
107 | - : get_terms( $this->field->args( 'taxonomy' ), http_build_query( $args ) ); |
|
105 | + return CMB2_Utils::wp_at_least('4.5.0') |
|
106 | + ? get_terms($args) |
|
107 | + : get_terms($this->field->args('taxonomy'), http_build_query($args)); |
|
108 | 108 | } |
109 | 109 | |
110 | - protected function no_terms_result( $error, $tag = 'li' ) { |
|
111 | - if ( is_wp_error( $error ) ) { |
|
110 | + protected function no_terms_result($error, $tag = 'li') { |
|
111 | + if (is_wp_error($error)) { |
|
112 | 112 | $message = $error->get_error_message(); |
113 | - $data = 'data-error="' . esc_attr( $error->get_error_code() ) . '"'; |
|
113 | + $data = 'data-error="' . esc_attr($error->get_error_code()) . '"'; |
|
114 | 114 | } else { |
115 | - $message = $this->_text( 'no_terms_text', esc_html__( 'No terms', 'cmb2' ) ); |
|
115 | + $message = $this->_text('no_terms_text', esc_html__('No terms', 'cmb2')); |
|
116 | 116 | $data = ''; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $this->field->args['select_all_button'] = false; |
120 | 120 | |
121 | - return sprintf( '<%3$s><label %1$s>%2$s</label></%3$s>', $data, esc_html( $message ), $tag ); |
|
121 | + return sprintf('<%3$s><label %1$s>%2$s</label></%3$s>', $data, esc_html($message), $tag); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function get_object_term_or_default() { |
125 | 125 | $saved_terms = $this->get_object_terms(); |
126 | 126 | |
127 | - return is_wp_error( $saved_terms ) || empty( $saved_terms ) |
|
127 | + return is_wp_error($saved_terms) || empty($saved_terms) |
|
128 | 128 | ? $this->field->get_default() |
129 | - : array_shift( $saved_terms )->slug; |
|
129 | + : array_shift($saved_terms)->slug; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return string List of terms. |
141 | 141 | */ |
142 | - protected function loop_terms( $all_terms, $saved_terms ) { |
|
142 | + protected function loop_terms($all_terms, $saved_terms) { |
|
143 | 143 | return ''; |
144 | 144 | } |
145 | 145 | |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return string List of terms. |
153 | 153 | */ |
154 | - protected function build_children( $parent_term, $saved ) { |
|
155 | - if ( empty( $parent_term->term_id ) ) { |
|
154 | + protected function build_children($parent_term, $saved) { |
|
155 | + if (empty($parent_term->term_id)) { |
|
156 | 156 | return ''; |
157 | 157 | } |
158 | 158 | |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | $terms = $this->get_terms(); |
162 | 162 | $options = ''; |
163 | 163 | |
164 | - if ( ! empty( $terms ) && is_array( $terms ) ) { |
|
165 | - $options .= $this->child_option_output( $terms, $saved ); |
|
164 | + if ( ! empty($terms) && is_array($terms)) { |
|
165 | + $options .= $this->child_option_output($terms, $saved); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | return $options; |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return string Child option output. |
180 | 180 | */ |
181 | - public function child_option_output( $terms, $saved ) { |
|
181 | + public function child_option_output($terms, $saved) { |
|
182 | 182 | $output = '<li class="cmb2-indented-hierarchy"><ul>'; |
183 | - $output .= $this->loop_terms( $terms, $saved ); |
|
183 | + $output .= $this->loop_terms($terms, $saved); |
|
184 | 184 | $output .= '</ul></li>'; |
185 | 185 | |
186 | 186 | return $output; |
@@ -13,18 +13,18 @@ |
||
13 | 13 | class CMB2_Type_Select extends CMB2_Type_Multi_Base { |
14 | 14 | |
15 | 15 | public function render() { |
16 | - $a = $this->parse_args( 'select', array( |
|
16 | + $a = $this->parse_args('select', array( |
|
17 | 17 | 'class' => 'cmb2_select', |
18 | 18 | 'name' => $this->_name(), |
19 | 19 | 'id' => $this->_id(), |
20 | - 'desc' => $this->_desc( true ), |
|
20 | + 'desc' => $this->_desc(true), |
|
21 | 21 | 'options' => $this->concat_items(), |
22 | - ) ); |
|
22 | + )); |
|
23 | 23 | |
24 | - $attrs = $this->concat_attrs( $a, array( 'desc', 'options' ) ); |
|
24 | + $attrs = $this->concat_attrs($a, array('desc', 'options')); |
|
25 | 25 | |
26 | 26 | return $this->rendered( |
27 | - sprintf( '<select%s>%s</select>%s', $attrs, $a['options'], $a['desc'] ) |
|
27 | + sprintf('<select%s>%s</select>%s', $attrs, $a['options'], $a['desc']) |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | } |
@@ -20,37 +20,37 @@ |
||
20 | 20 | * @param array $args Optional arguments to modify (else use $this->field->args['attributes']) |
21 | 21 | * @return array Array of field attributes |
22 | 22 | */ |
23 | - public function parse_picker_options( $arg = 'date', $args = array() ) { |
|
23 | + public function parse_picker_options($arg = 'date', $args = array()) { |
|
24 | 24 | $att = 'data-' . $arg . 'picker'; |
25 | - $update = empty( $args ); |
|
25 | + $update = empty($args); |
|
26 | 26 | $atts = array(); |
27 | - $format = $this->field->args( $arg . '_format' ); |
|
27 | + $format = $this->field->args($arg . '_format'); |
|
28 | 28 | |
29 | - if ( $js_format = CMB2_Utils::php_to_js_dateformat( $format ) ) { |
|
29 | + if ($js_format = CMB2_Utils::php_to_js_dateformat($format)) { |
|
30 | 30 | |
31 | - if ( $update ) { |
|
32 | - $atts = $this->field->args( 'attributes' ); |
|
31 | + if ($update) { |
|
32 | + $atts = $this->field->args('attributes'); |
|
33 | 33 | } else { |
34 | - $atts = isset( $args['attributes'] ) |
|
34 | + $atts = isset($args['attributes']) |
|
35 | 35 | ? $args['attributes'] |
36 | 36 | : $atts; |
37 | 37 | } |
38 | 38 | |
39 | 39 | // Don't override user-provided datepicker values |
40 | - $data = isset( $atts[ $att ] ) |
|
41 | - ? json_decode( $atts[ $att ], true ) |
|
40 | + $data = isset($atts[$att]) |
|
41 | + ? json_decode($atts[$att], true) |
|
42 | 42 | : array(); |
43 | 43 | |
44 | - $data[ $arg . 'Format' ] = $js_format; |
|
45 | - $atts[ $att ] = function_exists( 'wp_json_encode' ) |
|
46 | - ? wp_json_encode( $data ) |
|
47 | - : json_encode( $data ); |
|
44 | + $data[$arg . 'Format'] = $js_format; |
|
45 | + $atts[$att] = function_exists('wp_json_encode') |
|
46 | + ? wp_json_encode($data) |
|
47 | + : json_encode($data); |
|
48 | 48 | } |
49 | 49 | |
50 | - if ( $update ) { |
|
50 | + if ($update) { |
|
51 | 51 | $this->field->args['attributes'] = $atts; |
52 | 52 | } |
53 | 53 | |
54 | - return array_merge( $args, $atts ); |
|
54 | + return array_merge($args, $atts); |
|
55 | 55 | } |
56 | 56 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param array $args Array of arguments for the type. |
29 | 29 | * @param string $value Value that the field type is currently set to, or default value. |
30 | 30 | */ |
31 | - public function __construct( CMB2_Types $types, $args = array(), $value = '' ) { |
|
32 | - parent::__construct( $types, $args ); |
|
31 | + public function __construct(CMB2_Types $types, $args = array(), $value = '') { |
|
32 | + parent::__construct($types, $args); |
|
33 | 33 | $this->value = $value ? $value : $this->value; |
34 | 34 | } |
35 | 35 | |
@@ -42,41 +42,41 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return CMB2_Type_Base|string |
44 | 44 | */ |
45 | - public function render( $args = array() ) { |
|
45 | + public function render($args = array()) { |
|
46 | 46 | $meta_value = $this->value ? $this->value : $this->field->escaped_value(); |
47 | 47 | |
48 | 48 | $hex_color = '(([a-fA-F0-9]){3}){1,2}$'; |
49 | - if ( preg_match( '/^' . $hex_color . '/i', $meta_value ) ) { |
|
49 | + if (preg_match('/^' . $hex_color . '/i', $meta_value)) { |
|
50 | 50 | // Value is just 123abc, so prepend #. |
51 | 51 | $meta_value = '#' . $meta_value; |
52 | 52 | } elseif ( |
53 | 53 | // If value doesn't match #123abc... |
54 | - ! preg_match( '/^#' . $hex_color . '/i', $meta_value ) |
|
54 | + ! preg_match('/^#' . $hex_color . '/i', $meta_value) |
|
55 | 55 | // And value doesn't match rgba()... |
56 | - && 0 !== strpos( trim( $meta_value ), 'rgba' ) |
|
56 | + && 0 !== strpos(trim($meta_value), 'rgba') |
|
57 | 57 | ) { |
58 | 58 | // Then sanitize to just #. |
59 | 59 | $meta_value = '#'; |
60 | 60 | } |
61 | 61 | |
62 | - wp_enqueue_style( 'wp-color-picker' ); |
|
62 | + wp_enqueue_style('wp-color-picker'); |
|
63 | 63 | |
64 | - $args = wp_parse_args( $args, array( |
|
64 | + $args = wp_parse_args($args, array( |
|
65 | 65 | 'class' => 'cmb2-text-small', |
66 | - ) ); |
|
66 | + )); |
|
67 | 67 | |
68 | 68 | $args['class'] .= ' cmb2-colorpicker'; |
69 | 69 | $args['value'] = $meta_value; |
70 | - $args['js_dependencies'] = array( 'wp-color-picker' ); |
|
70 | + $args['js_dependencies'] = array('wp-color-picker'); |
|
71 | 71 | |
72 | - if ( $this->field->options( 'alpha' ) ) { |
|
72 | + if ($this->field->options('alpha')) { |
|
73 | 73 | $args['js_dependencies'][] = 'wp-color-picker-alpha'; |
74 | 74 | $args['data-alpha'] = 'true'; |
75 | 75 | } |
76 | 76 | |
77 | - $args = wp_parse_args( $this->args, $args ); |
|
77 | + $args = wp_parse_args($this->args, $args); |
|
78 | 78 | |
79 | - return parent::render( $args ); |
|
79 | + return parent::render($args); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * @since 2.2.6.2 |
86 | 86 | */ |
87 | 87 | public static function dequeue_rgba_colorpicker_script() { |
88 | - if ( wp_script_is( 'jw-cmb2-rgba-picker-js', 'enqueued' ) ) { |
|
89 | - wp_dequeue_script( 'jw-cmb2-rgba-picker-js' ); |
|
90 | - CMB2_JS::register_colorpicker_alpha( true ); |
|
88 | + if (wp_script_is('jw-cmb2-rgba-picker-js', 'enqueued')) { |
|
89 | + wp_dequeue_script('jw-cmb2-rgba-picker-js'); |
|
90 | + CMB2_JS::register_colorpicker_alpha(true); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 |
@@ -15,26 +15,26 @@ discard block |
||
15 | 15 | |
16 | 16 | public function render() { |
17 | 17 | return $this->rendered( |
18 | - $this->types->radio( array( |
|
18 | + $this->types->radio(array( |
|
19 | 19 | 'options' => $this->get_term_options(), |
20 | - ), 'taxonomy_radio' ) |
|
20 | + ), 'taxonomy_radio') |
|
21 | 21 | ); |
22 | 22 | } |
23 | 23 | |
24 | 24 | protected function get_term_options() { |
25 | 25 | $all_terms = $this->get_terms(); |
26 | 26 | |
27 | - if ( ! $all_terms || is_wp_error( $all_terms ) ) { |
|
28 | - return $this->no_terms_result( $all_terms ); |
|
27 | + if ( ! $all_terms || is_wp_error($all_terms)) { |
|
28 | + return $this->no_terms_result($all_terms); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $saved_term = $this->get_object_term_or_default(); |
32 | - $option_none = $this->field->args( 'show_option_none' ); |
|
32 | + $option_none = $this->field->args('show_option_none'); |
|
33 | 33 | $options = ''; |
34 | 34 | |
35 | - if ( ! empty( $option_none ) ) { |
|
35 | + if ( ! empty($option_none)) { |
|
36 | 36 | |
37 | - $field_id = $this->_id( '', false ); |
|
37 | + $field_id = $this->_id('', false); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Default (option-none) taxonomy-radio value. |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param string $option_none_value Default (option-none) taxonomy-radio value. |
45 | 45 | */ |
46 | - $option_none_value = apply_filters( 'cmb2_taxonomy_radio_default_value', '' ); |
|
46 | + $option_none_value = apply_filters('cmb2_taxonomy_radio_default_value', ''); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Default (option-none) taxonomy-radio value. |
@@ -54,39 +54,39 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @param string $option_none_value Default (option-none) taxonomy-radio value. |
56 | 56 | */ |
57 | - $option_none_value = apply_filters( "cmb2_taxonomy_radio_{$field_id}_default_value", $option_none_value ); |
|
57 | + $option_none_value = apply_filters("cmb2_taxonomy_radio_{$field_id}_default_value", $option_none_value); |
|
58 | 58 | |
59 | - $options .= $this->list_term_input( (object) array( |
|
59 | + $options .= $this->list_term_input((object) array( |
|
60 | 60 | 'slug' => $option_none_value, |
61 | 61 | 'name' => $option_none, |
62 | - ), $saved_term ); |
|
62 | + ), $saved_term); |
|
63 | 63 | } |
64 | 64 | |
65 | - $options .= $this->loop_terms( $all_terms, $saved_term ); |
|
65 | + $options .= $this->loop_terms($all_terms, $saved_term); |
|
66 | 66 | |
67 | 67 | return $options; |
68 | 68 | } |
69 | 69 | |
70 | - protected function loop_terms( $all_terms, $saved_term ) { |
|
70 | + protected function loop_terms($all_terms, $saved_term) { |
|
71 | 71 | $options = ''; |
72 | - foreach ( $all_terms as $term ) { |
|
73 | - $options .= $this->list_term_input( $term, $saved_term ); |
|
72 | + foreach ($all_terms as $term) { |
|
73 | + $options .= $this->list_term_input($term, $saved_term); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return $options; |
77 | 77 | } |
78 | 78 | |
79 | - protected function list_term_input( $term, $saved_term ) { |
|
79 | + protected function list_term_input($term, $saved_term) { |
|
80 | 80 | $args = array( |
81 | 81 | 'value' => $term->slug, |
82 | 82 | 'label' => $term->name, |
83 | 83 | ); |
84 | 84 | |
85 | - if ( $saved_term == $term->slug ) { |
|
85 | + if ($saved_term == $term->slug) { |
|
86 | 86 | $args['checked'] = 'checked'; |
87 | 87 | } |
88 | 88 | |
89 | - return $this->list_input( $args, ++$this->counter ); |
|
89 | + return $this->list_input($args, ++$this->counter); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | } |