@@ -20,70 +20,70 @@ discard block |
||
20 | 20 | * @since 1.1.0 |
21 | 21 | * @return string Form wysiwyg element |
22 | 22 | */ |
23 | - public function render( $args = array() ) { |
|
23 | + public function render($args = array()) { |
|
24 | 24 | $field = $this->field; |
25 | - $a = $this->parse_args( 'wysiwyg', array( |
|
26 | - 'id' => $this->_id( '', false ), |
|
27 | - 'value' => $field->escaped_value( 'stripslashes' ), |
|
28 | - 'desc' => $this->_desc( true ), |
|
25 | + $a = $this->parse_args('wysiwyg', array( |
|
26 | + 'id' => $this->_id('', false), |
|
27 | + 'value' => $field->escaped_value('stripslashes'), |
|
28 | + 'desc' => $this->_desc(true), |
|
29 | 29 | 'options' => $field->options(), |
30 | - ) ); |
|
30 | + )); |
|
31 | 31 | |
32 | - if ( ! $field->group ) { |
|
32 | + if ( ! $field->group) { |
|
33 | 33 | |
34 | - $a = $this->maybe_update_attributes_for_char_counter( $a ); |
|
34 | + $a = $this->maybe_update_attributes_for_char_counter($a); |
|
35 | 35 | |
36 | - if ( $this->has_counter ) { |
|
37 | - $a['options']['editor_class'] = ! empty( $a['options']['editor_class'] ) |
|
36 | + if ($this->has_counter) { |
|
37 | + $a['options']['editor_class'] = ! empty($a['options']['editor_class']) |
|
38 | 38 | ? $a['options']['editor_class'] . ' cmb2-count-chars' |
39 | 39 | : 'cmb2-count-chars'; |
40 | 40 | } |
41 | 41 | |
42 | - return $this->rendered( $this->get_wp_editor( $a ) . $a['desc'] ); |
|
42 | + return $this->rendered($this->get_wp_editor($a) . $a['desc']); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Character counter not currently working for grouped WYSIWYG |
46 | 46 | $this->field->args['char_counter'] = false; |
47 | 47 | |
48 | 48 | // wysiwyg fields in a group need some special handling. |
49 | - $field->add_js_dependencies( 'wp-util', 'cmb2-wysiwyg' ); |
|
49 | + $field->add_js_dependencies('wp-util', 'cmb2-wysiwyg'); |
|
50 | 50 | |
51 | 51 | // Hook in our template-output to the footer. |
52 | - add_action( is_admin() ? 'admin_footer' : 'wp_footer', array( $this, 'add_wysiwyg_template_for_group' ) ); |
|
52 | + add_action(is_admin() ? 'admin_footer' : 'wp_footer', array($this, 'add_wysiwyg_template_for_group')); |
|
53 | 53 | |
54 | 54 | return $this->rendered( |
55 | - sprintf( '<div class="cmb2-wysiwyg-wrap">%s', parent::render( array( |
|
55 | + sprintf('<div class="cmb2-wysiwyg-wrap">%s', parent::render(array( |
|
56 | 56 | 'class' => 'cmb2_textarea cmb2-wysiwyg-placeholder', |
57 | 57 | 'data-groupid' => $field->group->id(), |
58 | 58 | 'data-iterator' => $field->group->index, |
59 | - 'data-fieldid' => $field->id( true ), |
|
60 | - 'desc' => '</div>' . $this->_desc( true ), |
|
61 | - ) ) ) |
|
59 | + 'data-fieldid' => $field->id(true), |
|
60 | + 'desc' => '</div>' . $this->_desc(true), |
|
61 | + ))) |
|
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
65 | - protected function get_wp_editor( $args ) { |
|
65 | + protected function get_wp_editor($args) { |
|
66 | 66 | ob_start(); |
67 | - wp_editor( $args['value'], $args['id'], $args['options'] ); |
|
67 | + wp_editor($args['value'], $args['id'], $args['options']); |
|
68 | 68 | return ob_get_clean(); |
69 | 69 | } |
70 | 70 | |
71 | 71 | public function add_wysiwyg_template_for_group() { |
72 | 72 | $group_id = $this->field->group->id(); |
73 | - $field_id = $this->field->id( true ); |
|
73 | + $field_id = $this->field->id(true); |
|
74 | 74 | $hash = $this->field->hash_id(); |
75 | 75 | $options = $this->field->options(); |
76 | 76 | $options['textarea_name'] = 'cmb2_n_' . $group_id . $field_id; |
77 | 77 | |
78 | 78 | // Initate the editor with special id/value/name so we can retrieve the options in JS. |
79 | - $editor = $this->get_wp_editor( array( |
|
79 | + $editor = $this->get_wp_editor(array( |
|
80 | 80 | 'value' => 'cmb2_v_' . $group_id . $field_id, |
81 | 81 | 'id' => 'cmb2_i_' . $group_id . $field_id, |
82 | 82 | 'options' => $options, |
83 | - ) ); |
|
83 | + )); |
|
84 | 84 | |
85 | 85 | // Then replace the special id/value/name with underscore placeholders. |
86 | - $editor = str_replace( array( |
|
86 | + $editor = str_replace(array( |
|
87 | 87 | 'cmb2_n_' . $group_id . $field_id, |
88 | 88 | 'cmb2_v_' . $group_id . $field_id, |
89 | 89 | 'cmb2_i_' . $group_id . $field_id, |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | '{{ data.name }}', |
92 | 92 | '{{{ data.value }}}', |
93 | 93 | '{{ data.id }}', |
94 | - ), $editor ); |
|
94 | + ), $editor); |
|
95 | 95 | |
96 | 96 | // And put the editor instance in a JS template wrapper. |
97 | 97 | echo '<script type="text/template" id="tmpl-cmb2-wysiwyg-' . $group_id . '-' . $field_id . '">'; |
@@ -18,11 +18,11 @@ |
||
18 | 18 | ? $this->field->get_default() |
19 | 19 | : CMB2_Utils::timezone_string(); |
20 | 20 | |
21 | - $this->args = wp_parse_args( $this->args, array( |
|
21 | + $this->args = wp_parse_args($this->args, array( |
|
22 | 22 | 'class' => 'cmb2_select cmb2-select-timezone', |
23 | - 'options' => wp_timezone_choice( $this->field->escaped_value() ), |
|
23 | + 'options' => wp_timezone_choice($this->field->escaped_value()), |
|
24 | 24 | 'desc' => $this->_desc(), |
25 | - ) ); |
|
25 | + )); |
|
26 | 26 | |
27 | 27 | return parent::render(); |
28 | 28 | } |
@@ -19,23 +19,23 @@ |
||
19 | 19 | * @param array $args Override arguments |
20 | 20 | * @return string Form textarea element |
21 | 21 | */ |
22 | - public function render( $args = array() ) { |
|
23 | - $args = empty( $args ) ? $this->args : $args; |
|
24 | - $a = $this->parse_args( 'textarea', array( |
|
22 | + public function render($args = array()) { |
|
23 | + $args = empty($args) ? $this->args : $args; |
|
24 | + $a = $this->parse_args('textarea', array( |
|
25 | 25 | 'class' => 'cmb2_textarea', |
26 | 26 | 'name' => $this->_name(), |
27 | 27 | 'id' => $this->_id(), |
28 | 28 | 'cols' => 60, |
29 | 29 | 'rows' => 10, |
30 | - 'value' => $this->field->escaped_value( 'esc_textarea' ), |
|
31 | - 'desc' => $this->_desc( true ), |
|
32 | - ), $args ); |
|
30 | + 'value' => $this->field->escaped_value('esc_textarea'), |
|
31 | + 'desc' => $this->_desc(true), |
|
32 | + ), $args); |
|
33 | 33 | |
34 | 34 | // Add character counter? |
35 | - $a = $this->maybe_update_attributes_for_char_counter( $a ); |
|
35 | + $a = $this->maybe_update_attributes_for_char_counter($a); |
|
36 | 36 | |
37 | 37 | return $this->rendered( |
38 | - sprintf( '<textarea%s>%s</textarea>%s', $this->concat_attrs( $a, array( 'desc', 'value' ) ), $a['value'], $a['desc'] ) |
|
38 | + sprintf('<textarea%s>%s</textarea>%s', $this->concat_attrs($a, array('desc', 'value')), $a['value'], $a['desc']) |
|
39 | 39 | ); |
40 | 40 | } |
41 | 41 | } |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | * @param string $file File url |
20 | 20 | * @return bool Whether file has a valid image extension |
21 | 21 | */ |
22 | - public function is_valid_img_ext( $file, $blah = false ) { |
|
23 | - $file_ext = CMB2_Utils::get_file_ext( $file ); |
|
22 | + public function is_valid_img_ext($file, $blah = false) { |
|
23 | + $file_ext = CMB2_Utils::get_file_ext($file); |
|
24 | 24 | |
25 | - $valid_types = array( 'jpg', 'jpeg', 'png', 'gif', 'ico', 'icon' ); |
|
25 | + $valid_types = array('jpg', 'jpeg', 'png', 'gif', 'ico', 'icon'); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Which image types are considered valid image file extensions. |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param array $valid_types The valid image file extensions. |
33 | 33 | */ |
34 | - $is_valid_types = apply_filters( 'cmb2_valid_img_types', $valid_types ); |
|
35 | - $is_valid = $file_ext && in_array( $file_ext, (array) $is_valid_types ); |
|
34 | + $is_valid_types = apply_filters('cmb2_valid_img_types', $valid_types); |
|
35 | + $is_valid = $file_ext && in_array($file_ext, (array) $is_valid_types); |
|
36 | 36 | $field_id = $this->field->id(); |
37 | 37 | |
38 | 38 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param string $file File url. |
47 | 47 | * @param string $file_ext File extension. |
48 | 48 | */ |
49 | - return (bool) apply_filters( "cmb2_{$field_id}_is_valid_img_ext", $is_valid, $file, $file_ext ); |
|
49 | + return (bool) apply_filters("cmb2_{$field_id}_is_valid_img_ext", $is_valid, $file, $file_ext); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | * @param array $args Array of arguments for output |
57 | 57 | * @return string Image wrap output |
58 | 58 | */ |
59 | - public function img_status_output( $args ) { |
|
60 | - return sprintf( '<%1$s class="img-status cmb2-media-item">%2$s<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button"%3$s>%4$s</a></p>%5$s</%1$s>', |
|
59 | + public function img_status_output($args) { |
|
60 | + return sprintf('<%1$s class="img-status cmb2-media-item">%2$s<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button"%3$s>%4$s</a></p>%5$s</%1$s>', |
|
61 | 61 | $args['tag'], |
62 | 62 | $args['image'], |
63 | - isset( $args['cached_id'] ) ? ' rel="' . esc_attr( $args['cached_id'] ) . '"' : '', |
|
64 | - esc_html( $this->_text( 'remove_image_text', esc_html__( 'Remove Image', 'cmb2' ) ) ), |
|
65 | - isset( $args['id_input'] ) ? $args['id_input'] : '' |
|
63 | + isset($args['cached_id']) ? ' rel="' . esc_attr($args['cached_id']) . '"' : '', |
|
64 | + esc_html($this->_text('remove_image_text', esc_html__('Remove Image', 'cmb2'))), |
|
65 | + isset($args['id_input']) ? $args['id_input'] : '' |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | * @param array $args Array of arguments for output |
74 | 74 | * @return string File wrap output |
75 | 75 | */ |
76 | - public function file_status_output( $args ) { |
|
77 | - return sprintf( '<%1$s class="file-status cmb2-media-item"><span>%2$s <strong>%3$s</strong></span> (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>', |
|
76 | + public function file_status_output($args) { |
|
77 | + return sprintf('<%1$s class="file-status cmb2-media-item"><span>%2$s <strong>%3$s</strong></span> (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>', |
|
78 | 78 | $args['tag'], |
79 | - esc_html( $this->_text( 'file_text', esc_html__( 'File:', 'cmb2' ) ) ), |
|
80 | - esc_html( CMB2_Utils::get_file_name_from_path( $args['value'] ) ), |
|
81 | - esc_url( $args['value'] ), |
|
82 | - esc_html( $this->_text( 'file_download_text', esc_html__( 'Download', 'cmb2' ) ) ), |
|
83 | - isset( $args['cached_id'] ) ? ' rel="' . esc_attr( $args['cached_id'] ) . '"' : '', |
|
84 | - esc_html( $this->_text( 'remove_text', esc_html__( 'Remove', 'cmb2' ) ) ), |
|
85 | - isset( $args['id_input'] ) ? $args['id_input'] : '' |
|
79 | + esc_html($this->_text('file_text', esc_html__('File:', 'cmb2'))), |
|
80 | + esc_html(CMB2_Utils::get_file_name_from_path($args['value'])), |
|
81 | + esc_url($args['value']), |
|
82 | + esc_html($this->_text('file_download_text', esc_html__('Download', 'cmb2'))), |
|
83 | + isset($args['cached_id']) ? ' rel="' . esc_attr($args['cached_id']) . '"' : '', |
|
84 | + esc_html($this->_text('remove_text', esc_html__('Remove', 'cmb2'))), |
|
85 | + isset($args['id_input']) ? $args['id_input'] : '' |
|
86 | 86 | ); |
87 | 87 | } |
88 | 88 | |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | * 'name' => (string) e.g. 'thumbnail' |
139 | 139 | * ) |
140 | 140 | */ |
141 | - static function get_image_size_data( $img_size = '', $fallback = 'thumbnail' ) { |
|
141 | + static function get_image_size_data($img_size = '', $fallback = 'thumbnail') { |
|
142 | 142 | $data = array(); |
143 | 143 | |
144 | - if ( is_array( $img_size ) ) { |
|
145 | - $data['width'] = intval( $img_size[0] ); |
|
146 | - $data['height'] = intval( $img_size[1] ); |
|
144 | + if (is_array($img_size)) { |
|
145 | + $data['width'] = intval($img_size[0]); |
|
146 | + $data['height'] = intval($img_size[1]); |
|
147 | 147 | $data['name'] = ''; |
148 | 148 | |
149 | 149 | // Try and get the closest named size from our array of dimensions |
150 | - if ( $named_size = CMB2_Utils::get_named_size( $img_size ) ) { |
|
150 | + if ($named_size = CMB2_Utils::get_named_size($img_size)) { |
|
151 | 151 | $data['name'] = $named_size; |
152 | 152 | } |
153 | 153 | } else { |
@@ -155,18 +155,18 @@ discard block |
||
155 | 155 | $image_sizes = CMB2_Utils::get_available_image_sizes(); |
156 | 156 | |
157 | 157 | // The 'thumb' alias, which works elsewhere, doesn't work in the wp.media uploader |
158 | - if ( 'thumb' == $img_size ) { |
|
158 | + if ('thumb' == $img_size) { |
|
159 | 159 | $img_size = 'thumbnail'; |
160 | 160 | } |
161 | 161 | |
162 | 162 | // Named size doesn't exist, use $fallback |
163 | - if ( ! array_key_exists( $img_size, $image_sizes ) ) { |
|
163 | + if ( ! array_key_exists($img_size, $image_sizes)) { |
|
164 | 164 | $img_size = $fallback; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Get image dimensions from named sizes |
168 | - $data['width'] = intval( $image_sizes[ $img_size ]['width'] ); |
|
169 | - $data['height'] = intval( $image_sizes[ $img_size ]['height'] ); |
|
168 | + $data['width'] = intval($image_sizes[$img_size]['width']); |
|
169 | + $data['height'] = intval($image_sizes[$img_size]['height']); |
|
170 | 170 | $data['name'] = $img_size; |
171 | 171 | } |
172 | 172 | |
@@ -185,17 +185,17 @@ discard block |
||
185 | 185 | * @param array $meta Array of attachment meta data ( from wp_get_attachment_metadata() ) |
186 | 186 | * @return array filtered $response array |
187 | 187 | */ |
188 | - public static function prepare_image_sizes_for_js( $response, $attachment, $meta ) { |
|
189 | - foreach ( CMB2_Utils::get_available_image_sizes() as $size => $info ) { |
|
188 | + public static function prepare_image_sizes_for_js($response, $attachment, $meta) { |
|
189 | + foreach (CMB2_Utils::get_available_image_sizes() as $size => $info) { |
|
190 | 190 | |
191 | 191 | // registered image size exists for this attachment |
192 | - if ( isset( $meta['sizes'][ $size ] ) ) { |
|
192 | + if (isset($meta['sizes'][$size])) { |
|
193 | 193 | |
194 | - $attachment_url = wp_get_attachment_url( $attachment->ID ); |
|
195 | - $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
|
196 | - $size_meta = $meta['sizes'][ $size ]; |
|
194 | + $attachment_url = wp_get_attachment_url($attachment->ID); |
|
195 | + $base_url = str_replace(wp_basename($attachment_url), '', $attachment_url); |
|
196 | + $size_meta = $meta['sizes'][$size]; |
|
197 | 197 | |
198 | - $response['sizes'][ $size ] = array( |
|
198 | + $response['sizes'][$size] = array( |
|
199 | 199 | 'url' => $base_url . $size_meta['file'], |
200 | 200 | 'height' => $size_meta['height'], |
201 | 201 | 'width' => $size_meta['width'], |
@@ -12,51 +12,51 @@ |
||
12 | 12 | */ |
13 | 13 | class CMB2_Type_Text_Datetime_Timestamp_Timezone extends CMB2_Type_Base { |
14 | 14 | |
15 | - public function render( $args = array() ) { |
|
15 | + public function render($args = array()) { |
|
16 | 16 | $field = $this->field; |
17 | 17 | |
18 | 18 | $value = $field->escaped_value(); |
19 | - if ( empty( $value ) ) { |
|
19 | + if (empty($value)) { |
|
20 | 20 | $value = $field->get_default(); |
21 | 21 | } |
22 | 22 | |
23 | - $args = wp_parse_args( $this->args, array( |
|
23 | + $args = wp_parse_args($this->args, array( |
|
24 | 24 | 'value' => $value, |
25 | - 'desc' => $this->_desc( true ), |
|
25 | + 'desc' => $this->_desc(true), |
|
26 | 26 | 'text_datetime_timestamp' => array(), |
27 | 27 | 'select_timezone' => array(), |
28 | - ) ); |
|
28 | + )); |
|
29 | 29 | |
30 | 30 | $args['value'] = $value; |
31 | - if ( is_array( $args['value'] ) ) { |
|
31 | + if (is_array($args['value'])) { |
|
32 | 32 | $args['value'] = ''; |
33 | 33 | } |
34 | 34 | |
35 | - $datetime = maybe_unserialize( $args['value'] ); |
|
35 | + $datetime = maybe_unserialize($args['value']); |
|
36 | 36 | $value = $tzstring = ''; |
37 | 37 | |
38 | - if ( $datetime && $datetime instanceof DateTime ) { |
|
38 | + if ($datetime && $datetime instanceof DateTime) { |
|
39 | 39 | $tz = $datetime->getTimezone(); |
40 | 40 | $tzstring = $tz->getName(); |
41 | 41 | $value = $datetime->getTimestamp(); |
42 | 42 | } |
43 | 43 | |
44 | - $timestamp_args = wp_parse_args( $args['text_datetime_timestamp'], array( |
|
44 | + $timestamp_args = wp_parse_args($args['text_datetime_timestamp'], array( |
|
45 | 45 | 'desc' => '', |
46 | 46 | 'value' => $value, |
47 | 47 | 'rendered' => true, |
48 | - ) ); |
|
49 | - $datetime_timestamp = $this->types->text_datetime_timestamp( $timestamp_args ); |
|
48 | + )); |
|
49 | + $datetime_timestamp = $this->types->text_datetime_timestamp($timestamp_args); |
|
50 | 50 | |
51 | - $timezone_select_args = wp_parse_args( $args['select_timezone'], array( |
|
51 | + $timezone_select_args = wp_parse_args($args['select_timezone'], array( |
|
52 | 52 | 'class' => 'cmb2_select cmb2-select-timezone', |
53 | - 'name' => $this->_name( '[timezone]' ), |
|
54 | - 'id' => $this->_id( '_timezone' ), |
|
55 | - 'options' => wp_timezone_choice( $tzstring ), |
|
53 | + 'name' => $this->_name('[timezone]'), |
|
54 | + 'id' => $this->_id('_timezone'), |
|
55 | + 'options' => wp_timezone_choice($tzstring), |
|
56 | 56 | 'desc' => $args['desc'], |
57 | 57 | 'rendered' => true, |
58 | - ) ); |
|
59 | - $select = $this->types->select( $timezone_select_args ); |
|
58 | + )); |
|
59 | + $select = $this->types->select($timezone_select_args); |
|
60 | 60 | |
61 | 61 | return $this->rendered( |
62 | 62 | $datetime_timestamp . "\n" . $select |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @return CMB2_Ajax |
36 | 36 | */ |
37 | 37 | public static function get_instance() { |
38 | - if ( ! ( self::$instance instanceof self ) ) { |
|
38 | + if ( ! (self::$instance instanceof self)) { |
|
39 | 39 | self::$instance = new self(); |
40 | 40 | } |
41 | 41 | |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * @since 2.2.0 |
49 | 49 | */ |
50 | 50 | protected function __construct() { |
51 | - add_action( 'wp_ajax_cmb2_oembed_handler', array( $this, 'oembed_handler' ) ); |
|
52 | - add_action( 'wp_ajax_nopriv_cmb2_oembed_handler', array( $this, 'oembed_handler' ) ); |
|
51 | + add_action('wp_ajax_cmb2_oembed_handler', array($this, 'oembed_handler')); |
|
52 | + add_action('wp_ajax_nopriv_cmb2_oembed_handler', array($this, 'oembed_handler')); |
|
53 | 53 | // Need to occasionally clean stale oembed cache data from the option value. |
54 | - add_action( 'cmb2_save_options-page_fields', array( __CLASS__, 'clean_stale_options_page_oembeds' ) ); |
|
54 | + add_action('cmb2_save_options-page_fields', array(__CLASS__, 'clean_stale_options_page_oembeds')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -63,23 +63,23 @@ discard block |
||
63 | 63 | public function oembed_handler() { |
64 | 64 | |
65 | 65 | // Verify our nonce. |
66 | - if ( ! ( isset( $_REQUEST['cmb2_ajax_nonce'], $_REQUEST['oembed_url'] ) && wp_verify_nonce( $_REQUEST['cmb2_ajax_nonce'], 'ajax_nonce' ) ) ) { |
|
66 | + if ( ! (isset($_REQUEST['cmb2_ajax_nonce'], $_REQUEST['oembed_url']) && wp_verify_nonce($_REQUEST['cmb2_ajax_nonce'], 'ajax_nonce'))) { |
|
67 | 67 | die(); |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Sanitize our search string. |
71 | - $oembed_string = sanitize_text_field( $_REQUEST['oembed_url'] ); |
|
71 | + $oembed_string = sanitize_text_field($_REQUEST['oembed_url']); |
|
72 | 72 | |
73 | 73 | // Send back error if empty. |
74 | - if ( empty( $oembed_string ) ) { |
|
75 | - wp_send_json_error( '<p class="ui-state-error-text">' . esc_html__( 'Please Try Again', 'cmb2' ) . '</p>' ); |
|
74 | + if (empty($oembed_string)) { |
|
75 | + wp_send_json_error('<p class="ui-state-error-text">' . esc_html__('Please Try Again', 'cmb2') . '</p>'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Set width of embed. |
79 | - $embed_width = isset( $_REQUEST['oembed_width'] ) && intval( $_REQUEST['oembed_width'] ) < 640 ? intval( $_REQUEST['oembed_width'] ) : '640'; |
|
79 | + $embed_width = isset($_REQUEST['oembed_width']) && intval($_REQUEST['oembed_width']) < 640 ? intval($_REQUEST['oembed_width']) : '640'; |
|
80 | 80 | |
81 | 81 | // Set url. |
82 | - $oembed_url = esc_url( $oembed_string ); |
|
82 | + $oembed_url = esc_url($oembed_string); |
|
83 | 83 | |
84 | 84 | // Set args. |
85 | 85 | $embed_args = array( |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | $this->ajax_update = true; |
90 | 90 | |
91 | 91 | // Get embed code (or fallback link). |
92 | - $html = $this->get_oembed( array( |
|
92 | + $html = $this->get_oembed(array( |
|
93 | 93 | 'url' => $oembed_url, |
94 | 94 | 'object_id' => $_REQUEST['object_id'], |
95 | - 'object_type' => isset( $_REQUEST['object_type'] ) ? $_REQUEST['object_type'] : 'post', |
|
95 | + 'object_type' => isset($_REQUEST['object_type']) ? $_REQUEST['object_type'] : 'post', |
|
96 | 96 | 'oembed_args' => $embed_args, |
97 | 97 | 'field_id' => $_REQUEST['field_id'], |
98 | - ) ); |
|
98 | + )); |
|
99 | 99 | |
100 | - wp_send_json_success( $html ); |
|
100 | + wp_send_json_success($html); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -107,22 +107,22 @@ discard block |
||
107 | 107 | * @param array $args Arguments for method. |
108 | 108 | * @return mixed HTML markup with embed or fallback. |
109 | 109 | */ |
110 | - public function get_oembed_no_edit( $args ) { |
|
110 | + public function get_oembed_no_edit($args) { |
|
111 | 111 | global $wp_embed; |
112 | 112 | |
113 | - $oembed_url = esc_url( $args['url'] ); |
|
113 | + $oembed_url = esc_url($args['url']); |
|
114 | 114 | |
115 | 115 | // Sanitize object_id. |
116 | - $this->object_id = is_numeric( $args['object_id'] ) ? absint( $args['object_id'] ) : sanitize_text_field( $args['object_id'] ); |
|
116 | + $this->object_id = is_numeric($args['object_id']) ? absint($args['object_id']) : sanitize_text_field($args['object_id']); |
|
117 | 117 | |
118 | - $args = wp_parse_args( $args, array( |
|
118 | + $args = wp_parse_args($args, array( |
|
119 | 119 | 'object_type' => 'post', |
120 | 120 | 'oembed_args' => array(), |
121 | 121 | 'field_id' => false, |
122 | 122 | 'wp_error' => false, |
123 | - ) ); |
|
123 | + )); |
|
124 | 124 | |
125 | - $this->embed_args =& $args; |
|
125 | + $this->embed_args = & $args; |
|
126 | 126 | |
127 | 127 | /* |
128 | 128 | * Set the post_ID so oEmbed won't fail |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | $wp_embed->post_ID = $this->object_id; |
132 | 132 | |
133 | 133 | // Special scenario if NOT a post object. |
134 | - if ( isset( $args['object_type'] ) && 'post' != $args['object_type'] ) { |
|
134 | + if (isset($args['object_type']) && 'post' != $args['object_type']) { |
|
135 | 135 | |
136 | - if ( 'options-page' == $args['object_type'] ) { |
|
136 | + if ('options-page' == $args['object_type']) { |
|
137 | 137 | |
138 | 138 | // Bogus id to pass some numeric checks. Issue with a VERY large WP install? |
139 | 139 | $wp_embed->post_ID = 1987645321; |
@@ -144,26 +144,26 @@ discard block |
||
144 | 144 | $this->object_type = $args['object_type']; |
145 | 145 | |
146 | 146 | // Gets ombed cache from our object's meta (vs postmeta). |
147 | - add_filter( 'get_post_metadata', array( $this, 'hijack_oembed_cache_get' ), 10, 3 ); |
|
147 | + add_filter('get_post_metadata', array($this, 'hijack_oembed_cache_get'), 10, 3); |
|
148 | 148 | |
149 | 149 | // Sets ombed cache in our object's meta (vs postmeta). |
150 | - add_filter( 'update_post_metadata', array( $this, 'hijack_oembed_cache_set' ), 10, 4 ); |
|
150 | + add_filter('update_post_metadata', array($this, 'hijack_oembed_cache_set'), 10, 4); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
154 | 154 | $embed_args = ''; |
155 | 155 | |
156 | - foreach ( $args['oembed_args'] as $key => $val ) { |
|
156 | + foreach ($args['oembed_args'] as $key => $val) { |
|
157 | 157 | $embed_args .= " $key=\"$val\""; |
158 | 158 | } |
159 | 159 | |
160 | 160 | // Ping WordPress for an embed. |
161 | - $embed = $wp_embed->run_shortcode( '[embed' . $embed_args . ']' . $oembed_url . '[/embed]' ); |
|
161 | + $embed = $wp_embed->run_shortcode('[embed' . $embed_args . ']' . $oembed_url . '[/embed]'); |
|
162 | 162 | |
163 | 163 | // Fallback that WordPress creates when no oEmbed was found. |
164 | - $fallback = $wp_embed->maybe_make_link( $oembed_url ); |
|
164 | + $fallback = $wp_embed->maybe_make_link($oembed_url); |
|
165 | 165 | |
166 | - return compact( 'embed', 'fallback', 'args' ); |
|
166 | + return compact('embed', 'fallback', 'args'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * @param array $args Arguments for method. |
174 | 174 | * @return string HTML markup with embed or fallback. |
175 | 175 | */ |
176 | - public function get_oembed( $args ) { |
|
177 | - $oembed = $this->get_oembed_no_edit( $args ); |
|
176 | + public function get_oembed($args) { |
|
177 | + $oembed = $this->get_oembed_no_edit($args); |
|
178 | 178 | |
179 | 179 | // Send back our embed. |
180 | - if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) { |
|
181 | - return '<div class="cmb2-oembed embed-status">' . $oembed['embed'] . '<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button" rel="' . $oembed['args']['field_id'] . '">' . esc_html__( 'Remove Embed', 'cmb2' ) . '</a></p></div>'; |
|
180 | + if ($oembed['embed'] && $oembed['embed'] != $oembed['fallback']) { |
|
181 | + return '<div class="cmb2-oembed embed-status">' . $oembed['embed'] . '<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button" rel="' . $oembed['args']['field_id'] . '">' . esc_html__('Remove Embed', 'cmb2') . '</a></p></div>'; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Otherwise, send back error info that no oEmbeds were found. |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | '<p class="ui-state-error-text">%s</p>', |
187 | 187 | sprintf( |
188 | 188 | /* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */ |
189 | - esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ), |
|
189 | + esc_html__('No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2'), |
|
190 | 190 | $oembed['fallback'], |
191 | 191 | '<a href="https://wordpress.org/support/article/embeds/" target="_blank">codex.wordpress.org/Embeds</a>' |
192 | 192 | ) |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | * @param string $meta_key Object metakey. |
204 | 204 | * @return mixed Object's oEmbed cached data. |
205 | 205 | */ |
206 | - public function hijack_oembed_cache_get( $check, $object_id, $meta_key ) { |
|
207 | - if ( ! $this->hijack || ( $this->object_id != $object_id && 1987645321 !== $object_id ) ) { |
|
206 | + public function hijack_oembed_cache_get($check, $object_id, $meta_key) { |
|
207 | + if ( ! $this->hijack || ($this->object_id != $object_id && 1987645321 !== $object_id)) { |
|
208 | 208 | return $check; |
209 | 209 | } |
210 | 210 | |
211 | - if ( $this->ajax_update ) { |
|
211 | + if ($this->ajax_update) { |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | |
215 | - return $this->cache_action( $meta_key ); |
|
215 | + return $this->cache_action($meta_key); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | * @param mixed $meta_value Value of the postmeta to be saved. |
227 | 227 | * @return boolean Whether to continue setting. |
228 | 228 | */ |
229 | - public function hijack_oembed_cache_set( $check, $object_id, $meta_key, $meta_value ) { |
|
229 | + public function hijack_oembed_cache_set($check, $object_id, $meta_key, $meta_value) { |
|
230 | 230 | |
231 | 231 | if ( |
232 | 232 | ! $this->hijack |
233 | - || ( $this->object_id != $object_id && 1987645321 !== $object_id ) |
|
233 | + || ($this->object_id != $object_id && 1987645321 !== $object_id) |
|
234 | 234 | // Only want to hijack oembed meta values. |
235 | - || 0 !== strpos( $meta_key, '_oembed_' ) |
|
235 | + || 0 !== strpos($meta_key, '_oembed_') |
|
236 | 236 | ) { |
237 | 237 | return $check; |
238 | 238 | } |
239 | 239 | |
240 | - $this->cache_action( $meta_key, $meta_value ); |
|
240 | + $this->cache_action($meta_key, $meta_value); |
|
241 | 241 | |
242 | 242 | // Anything other than `null` to cancel saving to postmeta. |
243 | 243 | return true; |
@@ -251,28 +251,28 @@ discard block |
||
251 | 251 | * @param string $meta_key Postmeta's key. |
252 | 252 | * @return mixed |
253 | 253 | */ |
254 | - protected function cache_action( $meta_key ) { |
|
254 | + protected function cache_action($meta_key) { |
|
255 | 255 | $func_args = func_get_args(); |
256 | - $action = isset( $func_args[1] ) ? 'update' : 'get'; |
|
256 | + $action = isset($func_args[1]) ? 'update' : 'get'; |
|
257 | 257 | |
258 | - if ( 'options-page' === $this->object_type ) { |
|
258 | + if ('options-page' === $this->object_type) { |
|
259 | 259 | |
260 | - $args = array( $meta_key ); |
|
260 | + $args = array($meta_key); |
|
261 | 261 | |
262 | - if ( 'update' === $action ) { |
|
262 | + if ('update' === $action) { |
|
263 | 263 | $args[] = $func_args[1]; |
264 | 264 | $args[] = true; |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Cache the result to our options. |
268 | - $status = call_user_func_array( array( cmb2_options( $this->object_id ), $action ), $args ); |
|
268 | + $status = call_user_func_array(array(cmb2_options($this->object_id), $action), $args); |
|
269 | 269 | } else { |
270 | 270 | |
271 | - $args = array( $this->object_type, $this->object_id, $meta_key ); |
|
271 | + $args = array($this->object_type, $this->object_id, $meta_key); |
|
272 | 272 | $args[] = 'update' === $action ? $func_args[1] : true; |
273 | 273 | |
274 | 274 | // Cache the result to our metadata. |
275 | - $status = call_user_func_array( $action . '_metadata', $args ); |
|
275 | + $status = call_user_func_array($action . '_metadata', $args); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $status; |
@@ -286,37 +286,37 @@ discard block |
||
286 | 286 | * @param string $option_key The options-page option key. |
287 | 287 | * @return void |
288 | 288 | */ |
289 | - public static function clean_stale_options_page_oembeds( $option_key ) { |
|
290 | - $options = cmb2_options( $option_key )->get_options(); |
|
289 | + public static function clean_stale_options_page_oembeds($option_key) { |
|
290 | + $options = cmb2_options($option_key)->get_options(); |
|
291 | 291 | $modified = false; |
292 | - if ( is_array( $options ) ) { |
|
292 | + if (is_array($options)) { |
|
293 | 293 | |
294 | - $ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, '', array(), 0 ); |
|
294 | + $ttl = apply_filters('oembed_ttl', DAY_IN_SECONDS, '', array(), 0); |
|
295 | 295 | $now = time(); |
296 | 296 | |
297 | - foreach ( $options as $key => $value ) { |
|
297 | + foreach ($options as $key => $value) { |
|
298 | 298 | // Check for cached oembed data. |
299 | - if ( 0 === strpos( $key, '_oembed_time_' ) ) { |
|
300 | - $cached_recently = ( $now - $value ) < $ttl; |
|
299 | + if (0 === strpos($key, '_oembed_time_')) { |
|
300 | + $cached_recently = ($now - $value) < $ttl; |
|
301 | 301 | |
302 | - if ( ! $cached_recently ) { |
|
302 | + if ( ! $cached_recently) { |
|
303 | 303 | $modified = true; |
304 | 304 | // Remove the the cached ttl expiration, and the cached oembed value. |
305 | - unset( $options[ $key ] ); |
|
306 | - unset( $options[ str_replace( '_oembed_time_', '_oembed_', $key ) ] ); |
|
305 | + unset($options[$key]); |
|
306 | + unset($options[str_replace('_oembed_time_', '_oembed_', $key)]); |
|
307 | 307 | } |
308 | 308 | } // End if. |
309 | 309 | // Remove the cached unknown values. |
310 | - elseif ( '{{unknown}}' === $value ) { |
|
310 | + elseif ('{{unknown}}' === $value) { |
|
311 | 311 | $modified = true; |
312 | - unset( $options[ $key ] ); |
|
312 | + unset($options[$key]); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Update the option and remove stale cache data. |
318 | - if ( $modified ) { |
|
319 | - $updated = cmb2_options( $option_key )->set( $options ); |
|
318 | + if ($modified) { |
|
319 | + $updated = cmb2_options($option_key)->set($options); |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @since 2.0.7 |
51 | 51 | * @param array|string $dependencies Array (or string) of dependencies to add. |
52 | 52 | */ |
53 | - public static function add_dependencies( $dependencies ) { |
|
54 | - foreach ( (array) $dependencies as $dependency ) { |
|
55 | - self::$dependencies[ $dependency ] = $dependency; |
|
53 | + public static function add_dependencies($dependencies) { |
|
54 | + foreach ((array) $dependencies as $dependency) { |
|
55 | + self::$dependencies[$dependency] = $dependency; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @param CMB2_Field $field Field object. |
65 | 65 | */ |
66 | - public static function add_field_data( CMB2_Field $field ) { |
|
66 | + public static function add_field_data(CMB2_Field $field) { |
|
67 | 67 | $hash = $field->hash_id(); |
68 | - if ( ! isset( self::$fields[ $hash ] ) ) { |
|
69 | - self::$fields[ $hash ] = $field->js_data(); |
|
68 | + if ( ! isset(self::$fields[$hash])) { |
|
69 | + self::$fields[$hash] = $field->js_data(); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
@@ -77,57 +77,57 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public static function enqueue() { |
79 | 79 | // Filter required script dependencies. |
80 | - $dependencies = self::$dependencies = apply_filters( 'cmb2_script_dependencies', self::$dependencies ); |
|
80 | + $dependencies = self::$dependencies = apply_filters('cmb2_script_dependencies', self::$dependencies); |
|
81 | 81 | |
82 | 82 | // Only use minified files if SCRIPT_DEBUG is off. |
83 | - $debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; |
|
83 | + $debug = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG; |
|
84 | 84 | |
85 | 85 | $min = $debug ? '' : '.min'; |
86 | 86 | |
87 | 87 | // if colorpicker. |
88 | - if ( isset( $dependencies['wp-color-picker'] ) ) { |
|
89 | - if ( ! is_admin() ) { |
|
88 | + if (isset($dependencies['wp-color-picker'])) { |
|
89 | + if ( ! is_admin()) { |
|
90 | 90 | self::colorpicker_frontend(); |
91 | 91 | } |
92 | 92 | |
93 | - if ( isset( $dependencies['wp-color-picker-alpha'] ) ) { |
|
93 | + if (isset($dependencies['wp-color-picker-alpha'])) { |
|
94 | 94 | self::register_colorpicker_alpha(); |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | 98 | // if file/file_list. |
99 | - if ( isset( $dependencies['media-editor'] ) ) { |
|
99 | + if (isset($dependencies['media-editor'])) { |
|
100 | 100 | wp_enqueue_media(); |
101 | 101 | CMB2_Type_File_Base::output_js_underscore_templates(); |
102 | 102 | } |
103 | 103 | |
104 | 104 | // if timepicker. |
105 | - if ( isset( $dependencies['jquery-ui-datetimepicker'] ) ) { |
|
105 | + if (isset($dependencies['jquery-ui-datetimepicker'])) { |
|
106 | 106 | self::register_datetimepicker(); |
107 | 107 | } |
108 | 108 | |
109 | 109 | // if cmb2-wysiwyg. |
110 | - $enqueue_wysiwyg = isset( $dependencies['cmb2-wysiwyg'] ) && $debug; |
|
111 | - unset( $dependencies['cmb2-wysiwyg'] ); |
|
110 | + $enqueue_wysiwyg = isset($dependencies['cmb2-wysiwyg']) && $debug; |
|
111 | + unset($dependencies['cmb2-wysiwyg']); |
|
112 | 112 | |
113 | 113 | // if cmb2-char-counter. |
114 | - $enqueue_char_counter = isset( $dependencies['cmb2-char-counter'] ) && $debug; |
|
115 | - unset( $dependencies['cmb2-char-counter'] ); |
|
114 | + $enqueue_char_counter = isset($dependencies['cmb2-char-counter']) && $debug; |
|
115 | + unset($dependencies['cmb2-char-counter']); |
|
116 | 116 | |
117 | 117 | // Enqueue cmb JS. |
118 | - wp_enqueue_script( self::$handle, CMB2_Utils::url( "js/cmb2{$min}.js" ), array_values( $dependencies ), CMB2_VERSION, true ); |
|
118 | + wp_enqueue_script(self::$handle, CMB2_Utils::url("js/cmb2{$min}.js"), array_values($dependencies), CMB2_VERSION, true); |
|
119 | 119 | |
120 | 120 | // if SCRIPT_DEBUG, we need to enqueue separately. |
121 | - if ( $enqueue_wysiwyg ) { |
|
122 | - wp_enqueue_script( 'cmb2-wysiwyg', CMB2_Utils::url( 'js/cmb2-wysiwyg.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION ); |
|
121 | + if ($enqueue_wysiwyg) { |
|
122 | + wp_enqueue_script('cmb2-wysiwyg', CMB2_Utils::url('js/cmb2-wysiwyg.js'), array('jquery', 'wp-util'), CMB2_VERSION); |
|
123 | 123 | } |
124 | - if ( $enqueue_char_counter ) { |
|
125 | - wp_enqueue_script( 'cmb2-char-counter', CMB2_Utils::url( 'js/cmb2-char-counter.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION ); |
|
124 | + if ($enqueue_char_counter) { |
|
125 | + wp_enqueue_script('cmb2-char-counter', CMB2_Utils::url('js/cmb2-char-counter.js'), array('jquery', 'wp-util'), CMB2_VERSION); |
|
126 | 126 | } |
127 | 127 | |
128 | - self::localize( $debug ); |
|
128 | + self::localize($debug); |
|
129 | 129 | |
130 | - do_action( 'cmb2_footer_enqueue' ); |
|
130 | + do_action('cmb2_footer_enqueue'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return void |
141 | 141 | */ |
142 | - public static function register_colorpicker_alpha( $enqueue = false ) { |
|
142 | + public static function register_colorpicker_alpha($enqueue = false) { |
|
143 | 143 | // Only use minified files if SCRIPT_DEBUG is off. |
144 | - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
144 | + $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
145 | 145 | $func = $enqueue ? 'wp_enqueue_script' : 'wp_register_script'; |
146 | - $func( 'wp-color-picker-alpha', CMB2_Utils::url( "js/wp-color-picker-alpha{$min}.js" ), array( 'wp-color-picker' ), '2.1.3' ); |
|
146 | + $func('wp-color-picker-alpha', CMB2_Utils::url("js/wp-color-picker-alpha{$min}.js"), array('wp-color-picker'), '2.1.3'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return void |
157 | 157 | */ |
158 | - public static function register_datetimepicker( $enqueue = false ) { |
|
158 | + public static function register_datetimepicker($enqueue = false) { |
|
159 | 159 | $func = $enqueue ? 'wp_enqueue_script' : 'wp_register_script'; |
160 | - $func( 'jquery-ui-datetimepicker', CMB2_Utils::url( 'js/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-slider' ), '1.5.0' ); |
|
160 | + $func('jquery-ui-datetimepicker', CMB2_Utils::url('js/jquery-ui-timepicker-addon.min.js'), array('jquery-ui-slider'), '1.5.0'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * @since 2.0.7 |
167 | 167 | */ |
168 | 168 | protected static function colorpicker_frontend() { |
169 | - wp_register_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), CMB2_VERSION ); |
|
170 | - wp_register_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ), CMB2_VERSION ); |
|
171 | - wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', array( |
|
172 | - 'clear' => esc_html__( 'Clear', 'cmb2' ), |
|
173 | - 'defaultString' => esc_html__( 'Default', 'cmb2' ), |
|
174 | - 'pick' => esc_html__( 'Select Color', 'cmb2' ), |
|
175 | - 'current' => esc_html__( 'Current Color', 'cmb2' ), |
|
176 | - ) ); |
|
169 | + wp_register_script('iris', admin_url('js/iris.min.js'), array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), CMB2_VERSION); |
|
170 | + wp_register_script('wp-color-picker', admin_url('js/color-picker.min.js'), array('iris'), CMB2_VERSION); |
|
171 | + wp_localize_script('wp-color-picker', 'wpColorPickerL10n', array( |
|
172 | + 'clear' => esc_html__('Clear', 'cmb2'), |
|
173 | + 'defaultString' => esc_html__('Default', 'cmb2'), |
|
174 | + 'pick' => esc_html__('Select Color', 'cmb2'), |
|
175 | + 'current' => esc_html__('Current Color', 'cmb2'), |
|
176 | + )); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @param mixed $debug Whether or not we are debugging. |
185 | 185 | */ |
186 | - protected static function localize( $debug ) { |
|
186 | + protected static function localize($debug) { |
|
187 | 187 | static $localized = false; |
188 | - if ( $localized ) { |
|
188 | + if ($localized) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $localized = true; |
193 | 193 | $l10n = array( |
194 | 194 | 'fields' => self::$fields, |
195 | - 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), |
|
196 | - 'ajaxurl' => admin_url( '/admin-ajax.php' ), |
|
195 | + 'ajax_nonce' => wp_create_nonce('ajax_nonce'), |
|
196 | + 'ajaxurl' => admin_url('/admin-ajax.php'), |
|
197 | 197 | 'script_debug' => $debug, |
198 | 198 | 'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2', |
199 | 199 | 'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2', |
@@ -204,49 +204,49 @@ discard block |
||
204 | 204 | 'date_picker' => array( |
205 | 205 | 'changeMonth' => true, |
206 | 206 | 'changeYear' => true, |
207 | - 'dateFormat' => _x( 'mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2' ), |
|
208 | - 'dayNames' => explode( ',', esc_html__( 'Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2' ) ), |
|
209 | - 'dayNamesMin' => explode( ',', esc_html__( 'Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2' ) ), |
|
210 | - 'dayNamesShort' => explode( ',', esc_html__( 'Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2' ) ), |
|
211 | - 'monthNames' => explode( ',', esc_html__( 'January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2' ) ), |
|
212 | - 'monthNamesShort' => explode( ',', esc_html__( 'Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2' ) ), |
|
213 | - 'nextText' => esc_html__( 'Next', 'cmb2' ), |
|
214 | - 'prevText' => esc_html__( 'Prev', 'cmb2' ), |
|
215 | - 'currentText' => esc_html__( 'Today', 'cmb2' ), |
|
216 | - 'closeText' => esc_html__( 'Done', 'cmb2' ), |
|
217 | - 'clearText' => esc_html__( 'Clear', 'cmb2' ), |
|
207 | + 'dateFormat' => _x('mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2'), |
|
208 | + 'dayNames' => explode(',', esc_html__('Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2')), |
|
209 | + 'dayNamesMin' => explode(',', esc_html__('Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2')), |
|
210 | + 'dayNamesShort' => explode(',', esc_html__('Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2')), |
|
211 | + 'monthNames' => explode(',', esc_html__('January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2')), |
|
212 | + 'monthNamesShort' => explode(',', esc_html__('Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2')), |
|
213 | + 'nextText' => esc_html__('Next', 'cmb2'), |
|
214 | + 'prevText' => esc_html__('Prev', 'cmb2'), |
|
215 | + 'currentText' => esc_html__('Today', 'cmb2'), |
|
216 | + 'closeText' => esc_html__('Done', 'cmb2'), |
|
217 | + 'clearText' => esc_html__('Clear', 'cmb2'), |
|
218 | 218 | ), |
219 | 219 | 'time_picker' => array( |
220 | - 'timeOnlyTitle' => esc_html__( 'Choose Time', 'cmb2' ), |
|
221 | - 'timeText' => esc_html__( 'Time', 'cmb2' ), |
|
222 | - 'hourText' => esc_html__( 'Hour', 'cmb2' ), |
|
223 | - 'minuteText' => esc_html__( 'Minute', 'cmb2' ), |
|
224 | - 'secondText' => esc_html__( 'Second', 'cmb2' ), |
|
225 | - 'currentText' => esc_html__( 'Now', 'cmb2' ), |
|
226 | - 'closeText' => esc_html__( 'Done', 'cmb2' ), |
|
227 | - 'timeFormat' => _x( 'hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2' ), |
|
220 | + 'timeOnlyTitle' => esc_html__('Choose Time', 'cmb2'), |
|
221 | + 'timeText' => esc_html__('Time', 'cmb2'), |
|
222 | + 'hourText' => esc_html__('Hour', 'cmb2'), |
|
223 | + 'minuteText' => esc_html__('Minute', 'cmb2'), |
|
224 | + 'secondText' => esc_html__('Second', 'cmb2'), |
|
225 | + 'currentText' => esc_html__('Now', 'cmb2'), |
|
226 | + 'closeText' => esc_html__('Done', 'cmb2'), |
|
227 | + 'timeFormat' => _x('hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2'), |
|
228 | 228 | 'controlType' => 'select', |
229 | 229 | 'stepMinute' => 5, |
230 | 230 | ), |
231 | 231 | ), |
232 | 232 | 'strings' => array( |
233 | - 'upload_file' => esc_html__( 'Use this file', 'cmb2' ), |
|
234 | - 'upload_files' => esc_html__( 'Use these files', 'cmb2' ), |
|
235 | - 'remove_image' => esc_html__( 'Remove Image', 'cmb2' ), |
|
236 | - 'remove_file' => esc_html__( 'Remove', 'cmb2' ), |
|
237 | - 'file' => esc_html__( 'File:', 'cmb2' ), |
|
238 | - 'download' => esc_html__( 'Download', 'cmb2' ), |
|
239 | - 'check_toggle' => esc_html__( 'Select / Deselect All', 'cmb2' ), |
|
233 | + 'upload_file' => esc_html__('Use this file', 'cmb2'), |
|
234 | + 'upload_files' => esc_html__('Use these files', 'cmb2'), |
|
235 | + 'remove_image' => esc_html__('Remove Image', 'cmb2'), |
|
236 | + 'remove_file' => esc_html__('Remove', 'cmb2'), |
|
237 | + 'file' => esc_html__('File:', 'cmb2'), |
|
238 | + 'download' => esc_html__('Download', 'cmb2'), |
|
239 | + 'check_toggle' => esc_html__('Select / Deselect All', 'cmb2'), |
|
240 | 240 | ), |
241 | 241 | ); |
242 | 242 | |
243 | - if ( isset( self::$dependencies['code-editor'] ) && function_exists( 'wp_enqueue_code_editor' ) ) { |
|
244 | - $l10n['defaults']['code_editor'] = wp_enqueue_code_editor( array( |
|
243 | + if (isset(self::$dependencies['code-editor']) && function_exists('wp_enqueue_code_editor')) { |
|
244 | + $l10n['defaults']['code_editor'] = wp_enqueue_code_editor(array( |
|
245 | 245 | 'type' => 'text/html', |
246 | - ) ); |
|
246 | + )); |
|
247 | 247 | } |
248 | 248 | |
249 | - wp_localize_script( self::$handle, self::$js_variable, apply_filters( 'cmb2_localized_data', $l10n ) ); |
|
249 | + wp_localize_script(self::$handle, self::$js_variable, apply_filters('cmb2_localized_data', $l10n)); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | } |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * @param string $img_url Attachment url. |
36 | 36 | * @return int|false Attachment ID or false |
37 | 37 | */ |
38 | - public static function image_id_from_url( $img_url ) { |
|
38 | + public static function image_id_from_url($img_url) { |
|
39 | 39 | $attachment_id = 0; |
40 | 40 | $dir = wp_upload_dir(); |
41 | 41 | |
42 | 42 | // Is URL in uploads directory? |
43 | - if ( false === strpos( $img_url, $dir['baseurl'] . '/' ) ) { |
|
43 | + if (false === strpos($img_url, $dir['baseurl'] . '/')) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | - $file = basename( $img_url ); |
|
47 | + $file = basename($img_url); |
|
48 | 48 | |
49 | 49 | $query_args = array( |
50 | 50 | 'post_type' => 'attachment', |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | ), |
60 | 60 | ); |
61 | 61 | |
62 | - $query = new WP_Query( $query_args ); |
|
62 | + $query = new WP_Query($query_args); |
|
63 | 63 | |
64 | - if ( $query->have_posts() ) { |
|
64 | + if ($query->have_posts()) { |
|
65 | 65 | |
66 | - foreach ( $query->posts as $post_id ) { |
|
67 | - $meta = wp_get_attachment_metadata( $post_id ); |
|
68 | - $original_file = basename( $meta['file'] ); |
|
69 | - $cropped_image_files = isset( $meta['sizes'] ) ? wp_list_pluck( $meta['sizes'], 'file' ) : array(); |
|
70 | - if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) { |
|
66 | + foreach ($query->posts as $post_id) { |
|
67 | + $meta = wp_get_attachment_metadata($post_id); |
|
68 | + $original_file = basename($meta['file']); |
|
69 | + $cropped_image_files = isset($meta['sizes']) ? wp_list_pluck($meta['sizes'], 'file') : array(); |
|
70 | + if ($original_file === $file || in_array($file, $cropped_image_files)) { |
|
71 | 71 | $attachment_id = $post_id; |
72 | 72 | break; |
73 | 73 | } |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | public static function get_available_image_sizes() { |
89 | 89 | global $_wp_additional_image_sizes; |
90 | 90 | |
91 | - $default_image_sizes = array( 'thumbnail', 'medium', 'large' ); |
|
92 | - foreach ( $default_image_sizes as $size ) { |
|
93 | - $image_sizes[ $size ] = array( |
|
94 | - 'height' => intval( get_option( "{$size}_size_h" ) ), |
|
95 | - 'width' => intval( get_option( "{$size}_size_w" ) ), |
|
96 | - 'crop' => get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false, |
|
91 | + $default_image_sizes = array('thumbnail', 'medium', 'large'); |
|
92 | + foreach ($default_image_sizes as $size) { |
|
93 | + $image_sizes[$size] = array( |
|
94 | + 'height' => intval(get_option("{$size}_size_h")), |
|
95 | + 'width' => intval(get_option("{$size}_size_w")), |
|
96 | + 'crop' => get_option("{$size}_crop") ? get_option("{$size}_crop") : false, |
|
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
100 | - if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) { |
|
101 | - $image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes ); |
|
100 | + if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes)) { |
|
101 | + $image_sizes = array_merge($image_sizes, $_wp_additional_image_sizes); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return $image_sizes; |
@@ -117,55 +117,55 @@ discard block |
||
117 | 117 | * @param array|string $size Image size. Accepts an array of width and height (in that order). |
118 | 118 | * @return false|string Named image size e.g. 'thumbnail' |
119 | 119 | */ |
120 | - public static function get_named_size( $size ) { |
|
120 | + public static function get_named_size($size) { |
|
121 | 121 | $data = array(); |
122 | 122 | |
123 | 123 | // Find the best match when '$size' is an array. |
124 | - if ( is_array( $size ) ) { |
|
124 | + if (is_array($size)) { |
|
125 | 125 | $image_sizes = self::get_available_image_sizes(); |
126 | 126 | $candidates = array(); |
127 | 127 | |
128 | - foreach ( $image_sizes as $_size => $data ) { |
|
128 | + foreach ($image_sizes as $_size => $data) { |
|
129 | 129 | |
130 | 130 | // If there's an exact match to an existing image size, short circuit. |
131 | - if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { |
|
132 | - $candidates[ $data['width'] * $data['height'] ] = array( $_size, $data ); |
|
131 | + if ($data['width'] == $size[0] && $data['height'] == $size[1]) { |
|
132 | + $candidates[$data['width'] * $data['height']] = array($_size, $data); |
|
133 | 133 | break; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // If it's not an exact match, consider larger sizes with the same aspect ratio. |
137 | - if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) { |
|
137 | + if ($data['width'] >= $size[0] && $data['height'] >= $size[1]) { |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * To test for varying crops, we constrain the dimensions of the larger image |
141 | 141 | * to the dimensions of the smaller image and see if they match. |
142 | 142 | */ |
143 | - if ( $data['width'] > $size[0] ) { |
|
144 | - $constrained_size = wp_constrain_dimensions( $data['width'], $data['height'], $size[0] ); |
|
145 | - $expected_size = array( $size[0], $size[1] ); |
|
143 | + if ($data['width'] > $size[0]) { |
|
144 | + $constrained_size = wp_constrain_dimensions($data['width'], $data['height'], $size[0]); |
|
145 | + $expected_size = array($size[0], $size[1]); |
|
146 | 146 | } else { |
147 | - $constrained_size = wp_constrain_dimensions( $size[0], $size[1], $data['width'] ); |
|
148 | - $expected_size = array( $data['width'], $data['height'] ); |
|
147 | + $constrained_size = wp_constrain_dimensions($size[0], $size[1], $data['width']); |
|
148 | + $expected_size = array($data['width'], $data['height']); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // If the image dimensions are within 1px of the expected size, we consider it a match. |
152 | - $matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 ); |
|
152 | + $matched = (abs($constrained_size[0] - $expected_size[0]) <= 1 && abs($constrained_size[1] - $expected_size[1]) <= 1); |
|
153 | 153 | |
154 | - if ( $matched ) { |
|
155 | - $candidates[ $data['width'] * $data['height'] ] = array( $_size, $data ); |
|
154 | + if ($matched) { |
|
155 | + $candidates[$data['width'] * $data['height']] = array($_size, $data); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - if ( ! empty( $candidates ) ) { |
|
160 | + if ( ! empty($candidates)) { |
|
161 | 161 | // Sort the array by size if we have more than one candidate. |
162 | - if ( 1 < count( $candidates ) ) { |
|
163 | - ksort( $candidates ); |
|
162 | + if (1 < count($candidates)) { |
|
163 | + ksort($candidates); |
|
164 | 164 | } |
165 | 165 | |
166 | - $data = array_shift( $candidates ); |
|
166 | + $data = array_shift($candidates); |
|
167 | 167 | $data = $data[0]; |
168 | - } elseif ( ! empty( $image_sizes['thumbnail'] ) && $image_sizes['thumbnail']['width'] >= $size[0] && $image_sizes['thumbnail']['width'] >= $size[1] ) { |
|
168 | + } elseif ( ! empty($image_sizes['thumbnail']) && $image_sizes['thumbnail']['width'] >= $size[0] && $image_sizes['thumbnail']['width'] >= $size[1]) { |
|
169 | 169 | /* |
170 | 170 | * When the size requested is smaller than the thumbnail dimensions, we |
171 | 171 | * fall back to the thumbnail size. |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | } else { |
175 | 175 | return false; |
176 | 176 | } |
177 | - } elseif ( ! empty( $image_sizes[ $size ] ) ) { |
|
177 | + } elseif ( ! empty($image_sizes[$size])) { |
|
178 | 178 | $data = $size; |
179 | 179 | }// End if. |
180 | 180 | |
181 | 181 | // If we still don't have a match at this point, return false. |
182 | - if ( empty( $data ) ) { |
|
182 | + if (empty($data)) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
@@ -193,20 +193,20 @@ discard block |
||
193 | 193 | * @param string $tzstring Time string. |
194 | 194 | * @return string Offset time string |
195 | 195 | */ |
196 | - public static function timezone_offset( $tzstring ) { |
|
196 | + public static function timezone_offset($tzstring) { |
|
197 | 197 | $tz_offset = 0; |
198 | 198 | |
199 | - if ( ! empty( $tzstring ) && is_string( $tzstring ) ) { |
|
200 | - if ( 'UTC' === substr( $tzstring, 0, 3 ) ) { |
|
201 | - $tzstring = str_replace( array( ':15', ':30', ':45' ), array( '.25', '.5', '.75' ), $tzstring ); |
|
202 | - return intval( floatval( substr( $tzstring, 3 ) ) * HOUR_IN_SECONDS ); |
|
199 | + if ( ! empty($tzstring) && is_string($tzstring)) { |
|
200 | + if ('UTC' === substr($tzstring, 0, 3)) { |
|
201 | + $tzstring = str_replace(array(':15', ':30', ':45'), array('.25', '.5', '.75'), $tzstring); |
|
202 | + return intval(floatval(substr($tzstring, 3)) * HOUR_IN_SECONDS); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | try { |
206 | - $date_time_zone_selected = new DateTimeZone( $tzstring ); |
|
207 | - $tz_offset = timezone_offset_get( $date_time_zone_selected, date_create() ); |
|
208 | - } catch ( Exception $e ) { |
|
209 | - self::log_if_debug( __METHOD__, __LINE__, $e->getMessage() ); |
|
206 | + $date_time_zone_selected = new DateTimeZone($tzstring); |
|
207 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
208 | + } catch (Exception $e) { |
|
209 | + self::log_if_debug(__METHOD__, __LINE__, $e->getMessage()); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
@@ -225,18 +225,18 @@ discard block |
||
225 | 225 | * @return string Timezone string |
226 | 226 | */ |
227 | 227 | public static function timezone_string() { |
228 | - $current_offset = get_option( 'gmt_offset' ); |
|
229 | - $tzstring = get_option( 'timezone_string' ); |
|
228 | + $current_offset = get_option('gmt_offset'); |
|
229 | + $tzstring = get_option('timezone_string'); |
|
230 | 230 | |
231 | 231 | // Remove old Etc mappings. Fallback to gmt_offset. |
232 | - if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) { |
|
232 | + if (false !== strpos($tzstring, 'Etc/GMT')) { |
|
233 | 233 | $tzstring = ''; |
234 | 234 | } |
235 | 235 | |
236 | - if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists. |
|
237 | - if ( 0 == $current_offset ) { |
|
236 | + if (empty($tzstring)) { // Create a UTC+- zone if no timezone string exists. |
|
237 | + if (0 == $current_offset) { |
|
238 | 238 | $tzstring = 'UTC+0'; |
239 | - } elseif ( $current_offset < 0 ) { |
|
239 | + } elseif ($current_offset < 0) { |
|
240 | 240 | $tzstring = 'UTC' . $current_offset; |
241 | 241 | } else { |
242 | 242 | $tzstring = 'UTC+' . $current_offset; |
@@ -253,14 +253,13 @@ discard block |
||
253 | 253 | * @param string|int $string Possible timestamp string. |
254 | 254 | * @return int Time stamp. |
255 | 255 | */ |
256 | - public static function make_valid_time_stamp( $string ) { |
|
257 | - if ( ! $string ) { |
|
256 | + public static function make_valid_time_stamp($string) { |
|
257 | + if ( ! $string) { |
|
258 | 258 | return 0; |
259 | 259 | } |
260 | 260 | |
261 | - return self::is_valid_time_stamp( $string ) |
|
262 | - ? (int) $string : |
|
263 | - strtotime( (string) $string ); |
|
261 | + return self::is_valid_time_stamp($string) |
|
262 | + ? (int) $string : strtotime((string) $string); |
|
264 | 263 | } |
265 | 264 | |
266 | 265 | /** |
@@ -270,7 +269,7 @@ discard block |
||
270 | 269 | * @param mixed $timestamp Value to check. |
271 | 270 | * @return boolean Whether value is a valid timestamp |
272 | 271 | */ |
273 | - public static function is_valid_time_stamp( $timestamp ) { |
|
272 | + public static function is_valid_time_stamp($timestamp) { |
|
274 | 273 | return (string) (int) $timestamp === (string) $timestamp |
275 | 274 | && $timestamp <= PHP_INT_MAX |
276 | 275 | && $timestamp >= ~PHP_INT_MAX; |
@@ -283,7 +282,7 @@ discard block |
||
283 | 282 | * @param mixed $value Value to check. |
284 | 283 | * @return bool True or false |
285 | 284 | */ |
286 | - public static function isempty( $value ) { |
|
285 | + public static function isempty($value) { |
|
287 | 286 | return null === $value || '' === $value || false === $value || array() === $value; |
288 | 287 | } |
289 | 288 | |
@@ -294,7 +293,7 @@ discard block |
||
294 | 293 | * @param mixed $value Value to check. |
295 | 294 | * @return bool True or false |
296 | 295 | */ |
297 | - public static function notempty( $value ) { |
|
296 | + public static function notempty($value) { |
|
298 | 297 | return null !== $value && '' !== $value && false !== $value && array() !== $value; |
299 | 298 | } |
300 | 299 | |
@@ -305,8 +304,8 @@ discard block |
||
305 | 304 | * @param mixed $value Value to check. |
306 | 305 | * @return array True or false. |
307 | 306 | */ |
308 | - public static function filter_empty( $value ) { |
|
309 | - return array_filter( $value, array( __CLASS__, 'notempty' ) ); |
|
307 | + public static function filter_empty($value) { |
|
308 | + return array_filter($value, array(__CLASS__, 'notempty')); |
|
310 | 309 | } |
311 | 310 | |
312 | 311 | /** |
@@ -317,10 +316,10 @@ discard block |
||
317 | 316 | * @param array $new New array to insert. |
318 | 317 | * @param int $position Position in the main array to insert the new array. |
319 | 318 | */ |
320 | - public static function array_insert( &$array, $new, $position ) { |
|
321 | - $before = array_slice( $array, 0, $position - 1 ); |
|
322 | - $after = array_diff_key( $array, $before ); |
|
323 | - $array = array_merge( $before, $new, $after ); |
|
319 | + public static function array_insert(&$array, $new, $position) { |
|
320 | + $before = array_slice($array, 0, $position - 1); |
|
321 | + $after = array_diff_key($array, $before); |
|
322 | + $array = array_merge($before, $new, $after); |
|
324 | 323 | } |
325 | 324 | |
326 | 325 | /** |
@@ -333,19 +332,19 @@ discard block |
||
333 | 332 | * @param string $path URL path. |
334 | 333 | * @return string URL to CMB2 resources |
335 | 334 | */ |
336 | - public static function url( $path = '' ) { |
|
337 | - if ( self::$url ) { |
|
335 | + public static function url($path = '') { |
|
336 | + if (self::$url) { |
|
338 | 337 | return self::$url . $path; |
339 | 338 | } |
340 | 339 | |
341 | - $cmb2_url = self::get_url_from_dir( cmb2_dir() ); |
|
340 | + $cmb2_url = self::get_url_from_dir(cmb2_dir()); |
|
342 | 341 | |
343 | 342 | /** |
344 | 343 | * Filter the CMB location url. |
345 | 344 | * |
346 | 345 | * @param string $cmb2_url Currently registered url. |
347 | 346 | */ |
348 | - self::$url = trailingslashit( apply_filters( 'cmb2_meta_box_url', $cmb2_url, CMB2_VERSION ) ); |
|
347 | + self::$url = trailingslashit(apply_filters('cmb2_meta_box_url', $cmb2_url, CMB2_VERSION)); |
|
349 | 348 | |
350 | 349 | return self::$url . $path; |
351 | 350 | } |
@@ -357,28 +356,28 @@ discard block |
||
357 | 356 | * @param string $dir Directory path to convert. |
358 | 357 | * @return string Converted URL. |
359 | 358 | */ |
360 | - public static function get_url_from_dir( $dir ) { |
|
361 | - $dir = self::normalize_path( $dir ); |
|
359 | + public static function get_url_from_dir($dir) { |
|
360 | + $dir = self::normalize_path($dir); |
|
362 | 361 | |
363 | 362 | // Let's test if We are in the plugins or mu-plugins dir. |
364 | - $test_dir = trailingslashit( $dir ) . 'unneeded.php'; |
|
363 | + $test_dir = trailingslashit($dir) . 'unneeded.php'; |
|
365 | 364 | if ( |
366 | - 0 === strpos( $test_dir, self::normalize_path( WPMU_PLUGIN_DIR ) ) |
|
367 | - || 0 === strpos( $test_dir, self::normalize_path( WP_PLUGIN_DIR ) ) |
|
365 | + 0 === strpos($test_dir, self::normalize_path(WPMU_PLUGIN_DIR)) |
|
366 | + || 0 === strpos($test_dir, self::normalize_path(WP_PLUGIN_DIR)) |
|
368 | 367 | ) { |
369 | 368 | // Ok, then use plugins_url, as it is more reliable. |
370 | - return trailingslashit( plugins_url( '', $test_dir ) ); |
|
369 | + return trailingslashit(plugins_url('', $test_dir)); |
|
371 | 370 | } |
372 | 371 | |
373 | 372 | // Ok, now let's test if we are in the theme dir. |
374 | - $theme_root = self::normalize_path( get_theme_root() ); |
|
375 | - if ( 0 === strpos( $dir, $theme_root ) ) { |
|
373 | + $theme_root = self::normalize_path(get_theme_root()); |
|
374 | + if (0 === strpos($dir, $theme_root)) { |
|
376 | 375 | // Ok, then use get_theme_root_uri. |
377 | 376 | return set_url_scheme( |
378 | 377 | trailingslashit( |
379 | 378 | str_replace( |
380 | - untrailingslashit( $theme_root ), |
|
381 | - untrailingslashit( get_theme_root_uri() ), |
|
379 | + untrailingslashit($theme_root), |
|
380 | + untrailingslashit(get_theme_root_uri()), |
|
382 | 381 | $dir |
383 | 382 | ) |
384 | 383 | ) |
@@ -387,15 +386,15 @@ discard block |
||
387 | 386 | |
388 | 387 | // Check to see if it's anywhere in the root directory. |
389 | 388 | $site_dir = self::get_normalized_abspath(); |
390 | - $site_url = trailingslashit( is_multisite() ? network_site_url() : site_url() ); |
|
389 | + $site_url = trailingslashit(is_multisite() ? network_site_url() : site_url()); |
|
391 | 390 | |
392 | 391 | $url = str_replace( |
393 | - array( $site_dir, WP_PLUGIN_DIR ), |
|
394 | - array( $site_url, WP_PLUGIN_URL ), |
|
392 | + array($site_dir, WP_PLUGIN_DIR), |
|
393 | + array($site_url, WP_PLUGIN_URL), |
|
395 | 394 | $dir |
396 | 395 | ); |
397 | 396 | |
398 | - return set_url_scheme( $url ); |
|
397 | + return set_url_scheme($url); |
|
399 | 398 | } |
400 | 399 | |
401 | 400 | /** |
@@ -406,7 +405,7 @@ discard block |
||
406 | 405 | * @return string Normalized absolute path. |
407 | 406 | */ |
408 | 407 | protected static function get_normalized_abspath() { |
409 | - return self::normalize_path( self::$ABSPATH ); |
|
408 | + return self::normalize_path(self::$ABSPATH); |
|
410 | 409 | } |
411 | 410 | |
412 | 411 | /** |
@@ -422,16 +421,16 @@ discard block |
||
422 | 421 | * @param string $path Path to normalize. |
423 | 422 | * @return string Normalized path. |
424 | 423 | */ |
425 | - protected static function normalize_path( $path ) { |
|
426 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
427 | - return wp_normalize_path( $path ); |
|
424 | + protected static function normalize_path($path) { |
|
425 | + if (function_exists('wp_normalize_path')) { |
|
426 | + return wp_normalize_path($path); |
|
428 | 427 | } |
429 | 428 | |
430 | 429 | // Replace newer WP's version of wp_normalize_path. |
431 | - $path = str_replace( '\\', '/', $path ); |
|
432 | - $path = preg_replace( '|(?<=.)/+|', '/', $path ); |
|
433 | - if ( ':' === substr( $path, 1, 1 ) ) { |
|
434 | - $path = ucfirst( $path ); |
|
430 | + $path = str_replace('\\', '/', $path); |
|
431 | + $path = preg_replace('|(?<=.)/+|', '/', $path); |
|
432 | + if (':' === substr($path, 1, 1)) { |
|
433 | + $path = ucfirst($path); |
|
435 | 434 | } |
436 | 435 | |
437 | 436 | return $path; |
@@ -445,9 +444,9 @@ discard block |
||
445 | 444 | * @param string $date_format Expected date format. |
446 | 445 | * @return mixed Unix timestamp representing the date. |
447 | 446 | */ |
448 | - public static function get_timestamp_from_value( $value, $date_format ) { |
|
449 | - $date_object = date_create_from_format( $date_format, $value ); |
|
450 | - return $date_object ? $date_object->setTime( 0, 0, 0 )->getTimeStamp() : strtotime( $value ); |
|
447 | + public static function get_timestamp_from_value($value, $date_format) { |
|
448 | + $date_object = date_create_from_format($date_format, $value); |
|
449 | + return $date_object ? $date_object->setTime(0, 0, 0)->getTimeStamp() : strtotime($value); |
|
451 | 450 | } |
452 | 451 | |
453 | 452 | /** |
@@ -465,48 +464,48 @@ discard block |
||
465 | 464 | * @param string $format PHP date format. |
466 | 465 | * @return string reformatted string |
467 | 466 | */ |
468 | - public static function php_to_js_dateformat( $format ) { |
|
467 | + public static function php_to_js_dateformat($format) { |
|
469 | 468 | |
470 | 469 | // order is relevant here, since the replacement will be done sequentially. |
471 | 470 | $supported_options = array( |
472 | - 'd' => 'dd', // Day, leading 0. |
|
473 | - 'j' => 'd', // Day, no 0. |
|
474 | - 'z' => 'o', // Day of the year, no leading zeroes. |
|
471 | + 'd' => 'dd', // Day, leading 0. |
|
472 | + 'j' => 'd', // Day, no 0. |
|
473 | + 'z' => 'o', // Day of the year, no leading zeroes. |
|
475 | 474 | // 'D' => 'D', // Day name short, not sure how it'll work with translations. |
476 | - 'l ' => 'DD ', // Day name full, idem before. |
|
477 | - 'l, ' => 'DD, ', // Day name full, idem before. |
|
478 | - 'm' => 'mm', // Month of the year, leading 0. |
|
479 | - 'n' => 'm', // Month of the year, no leading 0. |
|
475 | + 'l ' => 'DD ', // Day name full, idem before. |
|
476 | + 'l, ' => 'DD, ', // Day name full, idem before. |
|
477 | + 'm' => 'mm', // Month of the year, leading 0. |
|
478 | + 'n' => 'm', // Month of the year, no leading 0. |
|
480 | 479 | // 'M' => 'M', // Month, Short name. |
481 | - 'F ' => 'MM ', // Month, full name. |
|
482 | - 'F, ' => 'MM, ', // Month, full name. |
|
483 | - 'y' => 'y', // Year, two digit. |
|
484 | - 'Y' => 'yy', // Year, full. |
|
485 | - 'H' => 'HH', // Hour with leading 0 (24 hour). |
|
486 | - 'G' => 'H', // Hour with no leading 0 (24 hour). |
|
487 | - 'h' => 'hh', // Hour with leading 0 (12 hour). |
|
488 | - 'g' => 'h', // Hour with no leading 0 (12 hour). |
|
489 | - 'i' => 'mm', // Minute with leading 0. |
|
490 | - 's' => 'ss', // Second with leading 0. |
|
491 | - 'a' => 'tt', // am/pm. |
|
480 | + 'F ' => 'MM ', // Month, full name. |
|
481 | + 'F, ' => 'MM, ', // Month, full name. |
|
482 | + 'y' => 'y', // Year, two digit. |
|
483 | + 'Y' => 'yy', // Year, full. |
|
484 | + 'H' => 'HH', // Hour with leading 0 (24 hour). |
|
485 | + 'G' => 'H', // Hour with no leading 0 (24 hour). |
|
486 | + 'h' => 'hh', // Hour with leading 0 (12 hour). |
|
487 | + 'g' => 'h', // Hour with no leading 0 (12 hour). |
|
488 | + 'i' => 'mm', // Minute with leading 0. |
|
489 | + 's' => 'ss', // Second with leading 0. |
|
490 | + 'a' => 'tt', // am/pm. |
|
492 | 491 | 'A' => 'TT', // AM/PM. |
493 | 492 | ); |
494 | 493 | |
495 | - foreach ( $supported_options as $php => $js ) { |
|
494 | + foreach ($supported_options as $php => $js) { |
|
496 | 495 | // replaces every instance of a supported option, but skips escaped characters. |
497 | - $format = preg_replace( "~(?<!\\\\)$php~", $js, $format ); |
|
496 | + $format = preg_replace("~(?<!\\\\)$php~", $js, $format); |
|
498 | 497 | } |
499 | 498 | |
500 | 499 | $supported_options = array( |
501 | - 'l' => 'DD', // Day name full, idem before. |
|
502 | - 'F' => 'MM', // Month, full name. |
|
500 | + 'l' => 'DD', // Day name full, idem before. |
|
501 | + 'F' => 'MM', // Month, full name. |
|
503 | 502 | ); |
504 | 503 | |
505 | - if ( isset( $supported_options[ $format ] ) ) { |
|
506 | - $format = $supported_options[ $format ]; |
|
504 | + if (isset($supported_options[$format])) { |
|
505 | + $format = $supported_options[$format]; |
|
507 | 506 | } |
508 | 507 | |
509 | - $format = preg_replace_callback( '~(?:\\\.)+~', array( __CLASS__, 'wrap_escaped_chars' ), $format ); |
|
508 | + $format = preg_replace_callback('~(?:\\\.)+~', array(__CLASS__, 'wrap_escaped_chars'), $format); |
|
510 | 509 | |
511 | 510 | return $format; |
512 | 511 | } |
@@ -518,8 +517,8 @@ discard block |
||
518 | 517 | * @param string $value Value to wrap/escape. |
519 | 518 | * @return string Modified value |
520 | 519 | */ |
521 | - public static function wrap_escaped_chars( $value ) { |
|
522 | - return ''' . str_replace( '\\', '', $value[0] ) . '''; |
|
520 | + public static function wrap_escaped_chars($value) { |
|
521 | + return ''' . str_replace('\\', '', $value[0]) . '''; |
|
523 | 522 | } |
524 | 523 | |
525 | 524 | /** |
@@ -532,9 +531,9 @@ discard block |
||
532 | 531 | * @param mixed $msg Message to output. |
533 | 532 | * @param mixed $debug Variable to print_r. |
534 | 533 | */ |
535 | - public static function log_if_debug( $function, $line, $msg, $debug = null ) { |
|
536 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
537 | - error_log( "In $function, $line:" . print_r( $msg, true ) . ( $debug ? print_r( $debug, true ) : '' ) ); |
|
534 | + public static function log_if_debug($function, $line, $msg, $debug = null) { |
|
535 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
536 | + error_log("In $function, $line:" . print_r($msg, true) . ($debug ? print_r($debug, true) : '')); |
|
538 | 537 | } |
539 | 538 | } |
540 | 539 | |
@@ -545,9 +544,9 @@ discard block |
||
545 | 544 | * @param string $file File url. |
546 | 545 | * @return string|false File extension or false |
547 | 546 | */ |
548 | - public static function get_file_ext( $file ) { |
|
549 | - $parsed = parse_url( $file, PHP_URL_PATH ); |
|
550 | - return $parsed ? strtolower( pathinfo( $parsed, PATHINFO_EXTENSION ) ) : false; |
|
547 | + public static function get_file_ext($file) { |
|
548 | + $parsed = parse_url($file, PHP_URL_PATH); |
|
549 | + return $parsed ? strtolower(pathinfo($parsed, PATHINFO_EXTENSION)) : false; |
|
551 | 550 | } |
552 | 551 | |
553 | 552 | /** |
@@ -557,9 +556,9 @@ discard block |
||
557 | 556 | * @param string $value File url or path. |
558 | 557 | * @return string File name |
559 | 558 | */ |
560 | - public static function get_file_name_from_path( $value ) { |
|
561 | - $parts = explode( '/', $value ); |
|
562 | - return is_array( $parts ) ? end( $parts ) : $value; |
|
559 | + public static function get_file_name_from_path($value) { |
|
560 | + $parts = explode('/', $value); |
|
561 | + return is_array($parts) ? end($parts) : $value; |
|
563 | 562 | } |
564 | 563 | |
565 | 564 | /** |
@@ -569,8 +568,8 @@ discard block |
||
569 | 568 | * @param string $version WP version string to compare. |
570 | 569 | * @return bool Result of comparison check. |
571 | 570 | */ |
572 | - public static function wp_at_least( $version ) { |
|
573 | - return version_compare( get_bloginfo( 'version' ), $version, '>=' ); |
|
571 | + public static function wp_at_least($version) { |
|
572 | + return version_compare(get_bloginfo('version'), $version, '>='); |
|
574 | 573 | } |
575 | 574 | |
576 | 575 | /** |
@@ -581,18 +580,18 @@ discard block |
||
581 | 580 | * @param array $attr_exclude Attributes that should NOT be concatenated. |
582 | 581 | * @return string String of attributes for form element. |
583 | 582 | */ |
584 | - public static function concat_attrs( $attrs, $attr_exclude = array() ) { |
|
583 | + public static function concat_attrs($attrs, $attr_exclude = array()) { |
|
585 | 584 | $attr_exclude[] = 'rendered'; |
586 | 585 | $attr_exclude[] = 'js_dependencies'; |
587 | 586 | |
588 | 587 | $attributes = ''; |
589 | - foreach ( $attrs as $attr => $val ) { |
|
590 | - $excluded = in_array( $attr, (array) $attr_exclude, true ); |
|
588 | + foreach ($attrs as $attr => $val) { |
|
589 | + $excluded = in_array($attr, (array) $attr_exclude, true); |
|
591 | 590 | $empty = false === $val && 'value' !== $attr; |
592 | - if ( ! $excluded && ! $empty ) { |
|
591 | + if ( ! $excluded && ! $empty) { |
|
593 | 592 | // if data attribute, use single quote wraps, else double. |
594 | - $quotes = self::is_data_attribute( $attr ) ? "'" : '"'; |
|
595 | - $attributes .= sprintf( ' %1$s=%3$s%2$s%3$s', $attr, $val, $quotes ); |
|
593 | + $quotes = self::is_data_attribute($attr) ? "'" : '"'; |
|
594 | + $attributes .= sprintf(' %1$s=%3$s%2$s%3$s', $attr, $val, $quotes); |
|
596 | 595 | } |
597 | 596 | } |
598 | 597 | return $attributes; |
@@ -606,8 +605,8 @@ discard block |
||
606 | 605 | * @param string $att HTML attribute. |
607 | 606 | * @return boolean |
608 | 607 | */ |
609 | - public static function is_data_attribute( $att ) { |
|
610 | - return 0 === stripos( $att, 'data-' ); |
|
608 | + public static function is_data_attribute($att) { |
|
609 | + return 0 === stripos($att, 'data-'); |
|
611 | 610 | } |
612 | 611 | |
613 | 612 | /** |
@@ -620,17 +619,17 @@ discard block |
||
620 | 619 | * |
621 | 620 | * @return array The array. |
622 | 621 | */ |
623 | - public static function ensure_array( $value, $default = array() ) { |
|
624 | - if ( empty( $value ) ) { |
|
622 | + public static function ensure_array($value, $default = array()) { |
|
623 | + if (empty($value)) { |
|
625 | 624 | return $default; |
626 | 625 | } |
627 | 626 | |
628 | - if ( is_array( $value ) || is_object( $value ) ) { |
|
627 | + if (is_array($value) || is_object($value)) { |
|
629 | 628 | return (array) $value; |
630 | 629 | } |
631 | 630 | |
632 | 631 | // Not sure anything would be non-scalar that is not an array or object? |
633 | - if ( ! is_scalar( $value ) ) { |
|
632 | + if ( ! is_scalar($value)) { |
|
634 | 633 | return $default; |
635 | 634 | } |
636 | 635 | |
@@ -645,9 +644,9 @@ discard block |
||
645 | 644 | * @param mixed $value Value to normalize (if numeric). |
646 | 645 | * @return mixed Possibly normalized value. |
647 | 646 | */ |
648 | - public static function normalize_if_numeric( $value ) { |
|
649 | - if ( is_numeric( $value ) ) { |
|
650 | - $value = false !== strpos( $value, '.' ) ? floatval( $value ) : intval( $value ); |
|
647 | + public static function normalize_if_numeric($value) { |
|
648 | + if (is_numeric($value)) { |
|
649 | + $value = false !== strpos($value, '.') ? floatval($value) : intval($value); |
|
651 | 650 | } |
652 | 651 | |
653 | 652 | return $value; |
@@ -662,8 +661,8 @@ discard block |
||
662 | 661 | * |
663 | 662 | * @return string |
664 | 663 | */ |
665 | - public static function generate_hash( $string ) { |
|
666 | - return substr( base_convert( md5( $string ), 16, 32 ), 0, 12 ); |
|
664 | + public static function generate_hash($string) { |
|
665 | + return substr(base_convert(md5($string), 16, 32), 0, 12); |
|
667 | 666 | } |
668 | 667 | |
669 | 668 | } |
@@ -36,46 +36,46 @@ discard block |
||
36 | 36 | * @param CMB2 $cmb The CMB2 object to hookup. |
37 | 37 | * @param string $option_key Option key to use. |
38 | 38 | */ |
39 | - public function __construct( CMB2 $cmb, $option_key ) { |
|
39 | + public function __construct(CMB2 $cmb, $option_key) { |
|
40 | 40 | $this->cmb = $cmb; |
41 | 41 | $this->option_key = $option_key; |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function hooks() { |
45 | - if ( empty( $this->option_key ) ) { |
|
45 | + if (empty($this->option_key)) { |
|
46 | 46 | return; |
47 | 47 | } |
48 | 48 | |
49 | - if ( ! $this->cmb->prop( 'autoload', true ) ) { |
|
49 | + if ( ! $this->cmb->prop('autoload', true)) { |
|
50 | 50 | // Disable option autoload if requested. |
51 | - add_filter( "cmb2_should_autoload_{$this->option_key}", '__return_false' ); |
|
51 | + add_filter("cmb2_should_autoload_{$this->option_key}", '__return_false'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * For WP < 4.7. Ensure the register_setting function exists. |
56 | 56 | */ |
57 | - if ( ! CMB2_Utils::wp_at_least( '4.7' ) && ! function_exists( 'register_setting' ) ) { |
|
57 | + if ( ! CMB2_Utils::wp_at_least('4.7') && ! function_exists('register_setting')) { |
|
58 | 58 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Register setting to cmb2 group. |
62 | - register_setting( 'cmb2', $this->option_key ); |
|
62 | + register_setting('cmb2', $this->option_key); |
|
63 | 63 | |
64 | 64 | // Handle saving the data. |
65 | - add_action( 'admin_post_' . $this->option_key, array( $this, 'save_options' ) ); |
|
65 | + add_action('admin_post_' . $this->option_key, array($this, 'save_options')); |
|
66 | 66 | |
67 | 67 | // Optionally network_admin_menu. |
68 | - $hook = $this->cmb->prop( 'admin_menu_hook' ); |
|
68 | + $hook = $this->cmb->prop('admin_menu_hook'); |
|
69 | 69 | |
70 | 70 | // Hook in to add our menu. |
71 | - add_action( $hook, array( $this, 'options_page_menu_hooks' ) ); |
|
71 | + add_action($hook, array($this, 'options_page_menu_hooks')); |
|
72 | 72 | |
73 | 73 | // If in the network admin, need to use get/update_site_option. |
74 | - if ( 'network_admin_menu' === $hook ) { |
|
74 | + if ('network_admin_menu' === $hook) { |
|
75 | 75 | // Override CMB's getter. |
76 | - add_filter( "cmb2_override_option_get_{$this->option_key}", array( $this, 'network_get_override' ), 10, 2 ); |
|
76 | + add_filter("cmb2_override_option_get_{$this->option_key}", array($this, 'network_get_override'), 10, 2); |
|
77 | 77 | // Override CMB's setter. |
78 | - add_filter( "cmb2_override_option_save_{$this->option_key}", array( $this, 'network_update_override' ), 10, 2 ); |
|
78 | + add_filter("cmb2_override_option_save_{$this->option_key}", array($this, 'network_update_override'), 10, 2); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | * @return void |
88 | 88 | */ |
89 | 89 | public function options_page_menu_hooks() { |
90 | - $parent_slug = $this->cmb->prop( 'parent_slug' ); |
|
91 | - $title = $this->cmb->prop( 'title' ); |
|
92 | - $menu_title = $this->cmb->prop( 'menu_title', $title ); |
|
93 | - $capability = $this->cmb->prop( 'capability' ); |
|
94 | - $callback = array( $this, 'options_page_output' ); |
|
90 | + $parent_slug = $this->cmb->prop('parent_slug'); |
|
91 | + $title = $this->cmb->prop('title'); |
|
92 | + $menu_title = $this->cmb->prop('menu_title', $title); |
|
93 | + $capability = $this->cmb->prop('capability'); |
|
94 | + $callback = array($this, 'options_page_output'); |
|
95 | 95 | |
96 | - if ( $parent_slug ) { |
|
96 | + if ($parent_slug) { |
|
97 | 97 | $page_hook = add_submenu_page( |
98 | 98 | $parent_slug, |
99 | 99 | $title, |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | $capability, |
110 | 110 | $this->option_key, |
111 | 111 | $callback, |
112 | - $this->cmb->prop( 'icon_url' ), |
|
113 | - $this->cmb->prop( 'position' ) |
|
112 | + $this->cmb->prop('icon_url'), |
|
113 | + $this->cmb->prop('position') |
|
114 | 114 | ); |
115 | 115 | } |
116 | 116 | |
117 | - if ( $this->cmb->prop( 'cmb_styles' ) ) { |
|
117 | + if ($this->cmb->prop('cmb_styles')) { |
|
118 | 118 | // Include CMB CSS in the head to avoid FOUC. |
119 | - add_action( "admin_print_styles-{$page_hook}", array( 'CMB2_Hookup', 'enqueue_cmb_css' ) ); |
|
119 | + add_action("admin_print_styles-{$page_hook}", array('CMB2_Hookup', 'enqueue_cmb_css')); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $this->maybe_register_message(); |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | * @return void |
132 | 132 | */ |
133 | 133 | public function maybe_register_message() { |
134 | - $is_options_page = self::is_page( $this->option_key ); |
|
135 | - $should_notify = ! $this->cmb->prop( 'disable_settings_errors' ) && isset( $_GET['settings-updated'] ) && $is_options_page; |
|
134 | + $is_options_page = self::is_page($this->option_key); |
|
135 | + $should_notify = ! $this->cmb->prop('disable_settings_errors') && isset($_GET['settings-updated']) && $is_options_page; |
|
136 | 136 | $is_updated = $should_notify && 'true' === $_GET['settings-updated']; |
137 | 137 | $setting = "{$this->option_key}-notices"; |
138 | 138 | $code = ''; |
139 | - $message = __( 'Nothing to update.', 'cmb2' ); |
|
139 | + $message = __('Nothing to update.', 'cmb2'); |
|
140 | 140 | $type = 'notice-warning'; |
141 | 141 | |
142 | - if ( $is_updated ) { |
|
143 | - $message = __( 'Settings updated.', 'cmb2' ); |
|
142 | + if ($is_updated) { |
|
143 | + $message = __('Settings updated.', 'cmb2'); |
|
144 | 144 | $type = 'updated'; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // Check if parameter has registered a callback. |
148 | - if ( $cb = $this->cmb->maybe_callback( 'message_cb' ) ) { |
|
148 | + if ($cb = $this->cmb->maybe_callback('message_cb')) { |
|
149 | 149 | |
150 | 150 | /** |
151 | 151 | * The 'message_cb' callback will receive the following parameters. |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | * Will be 'updated' if $is_updated is true, else 'notice-warning'. |
172 | 172 | * } |
173 | 173 | */ |
174 | - $args = compact( 'is_options_page', 'should_notify', 'is_updated', 'setting', 'code', 'message', 'type' ); |
|
174 | + $args = compact('is_options_page', 'should_notify', 'is_updated', 'setting', 'code', 'message', 'type'); |
|
175 | 175 | |
176 | - $this->cmb->do_callback( $cb, $args ); |
|
176 | + $this->cmb->do_callback($cb, $args); |
|
177 | 177 | |
178 | - } elseif ( $should_notify ) { |
|
178 | + } elseif ($should_notify) { |
|
179 | 179 | |
180 | - add_settings_error( $setting, $code, $message, $type ); |
|
180 | + add_settings_error($setting, $code, $message, $type); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
@@ -189,28 +189,28 @@ discard block |
||
189 | 189 | public function options_page_output() { |
190 | 190 | $this->maybe_output_settings_notices(); |
191 | 191 | |
192 | - $callback = $this->cmb->prop( 'display_cb' ); |
|
193 | - if ( is_callable( $callback ) ) { |
|
194 | - return call_user_func( $callback, $this ); |
|
192 | + $callback = $this->cmb->prop('display_cb'); |
|
193 | + if (is_callable($callback)) { |
|
194 | + return call_user_func($callback, $this); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | $tabs = $this->get_tab_group_tabs(); |
198 | 198 | ?> |
199 | - <div class="wrap cmb2-options-page option-<?php echo esc_attr( sanitize_html_class( $this->option_key ) ); ?>"> |
|
200 | - <?php if ( $this->cmb->prop( 'title' ) ) : ?> |
|
201 | - <h2><?php echo wp_kses_post( $this->cmb->prop( 'title' ) ); ?></h2> |
|
199 | + <div class="wrap cmb2-options-page option-<?php echo esc_attr(sanitize_html_class($this->option_key)); ?>"> |
|
200 | + <?php if ($this->cmb->prop('title')) : ?> |
|
201 | + <h2><?php echo wp_kses_post($this->cmb->prop('title')); ?></h2> |
|
202 | 202 | <?php endif; ?> |
203 | - <?php if ( ! empty( $tabs ) ) : ?> |
|
203 | + <?php if ( ! empty($tabs)) : ?> |
|
204 | 204 | <h2 class="nav-tab-wrapper"> |
205 | - <?php foreach ( $tabs as $option_key => $tab_title ) : ?> |
|
206 | - <a class="nav-tab<?php if ( self::is_page( $option_key ) ) : ?> nav-tab-active<?php endif; ?>" href="<?php menu_page_url( $option_key ); ?>"><?php echo wp_kses_post( $tab_title ); ?></a> |
|
205 | + <?php foreach ($tabs as $option_key => $tab_title) : ?> |
|
206 | + <a class="nav-tab<?php if (self::is_page($option_key)) : ?> nav-tab-active<?php endif; ?>" href="<?php menu_page_url($option_key); ?>"><?php echo wp_kses_post($tab_title); ?></a> |
|
207 | 207 | <?php endforeach; ?> |
208 | 208 | </h2> |
209 | 209 | <?php endif; ?> |
210 | - <form class="cmb-form" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="POST" id="<?php echo $this->cmb->cmb_id; ?>" enctype="multipart/form-data" encoding="multipart/form-data"> |
|
211 | - <input type="hidden" name="action" value="<?php echo esc_attr( $this->option_key ); ?>"> |
|
210 | + <form class="cmb-form" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="POST" id="<?php echo $this->cmb->cmb_id; ?>" enctype="multipart/form-data" encoding="multipart/form-data"> |
|
211 | + <input type="hidden" name="action" value="<?php echo esc_attr($this->option_key); ?>"> |
|
212 | 212 | <?php $this->options_page_metabox(); ?> |
213 | - <?php submit_button( esc_attr( $this->cmb->prop( 'save_button' ) ), 'primary', 'submit-cmb' ); ?> |
|
213 | + <?php submit_button(esc_attr($this->cmb->prop('save_button')), 'primary', 'submit-cmb'); ?> |
|
214 | 214 | </form> |
215 | 215 | </div> |
216 | 216 | <?php |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | global $parent_file; |
229 | 229 | |
230 | 230 | // The settings sub-pages will already have settings_errors() called in wp-admin/options-head.php. |
231 | - if ( 'options-general.php' !== $parent_file ) { |
|
232 | - settings_errors( "{$this->option_key}-notices" ); |
|
231 | + if ('options-general.php' !== $parent_file) { |
|
232 | + settings_errors("{$this->option_key}-notices"); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
@@ -241,21 +241,21 @@ discard block |
||
241 | 241 | * @return array Array of tab information ($option_key => $tab_title) |
242 | 242 | */ |
243 | 243 | public function get_tab_group_tabs() { |
244 | - $tab_group = $this->cmb->prop( 'tab_group' ); |
|
244 | + $tab_group = $this->cmb->prop('tab_group'); |
|
245 | 245 | $tabs = array(); |
246 | 246 | |
247 | - if ( $tab_group ) { |
|
248 | - $boxes = CMB2_Boxes::get_by( 'tab_group', $tab_group ); |
|
247 | + if ($tab_group) { |
|
248 | + $boxes = CMB2_Boxes::get_by('tab_group', $tab_group); |
|
249 | 249 | |
250 | - foreach ( $boxes as $cmb_id => $cmb ) { |
|
250 | + foreach ($boxes as $cmb_id => $cmb) { |
|
251 | 251 | $option_key = $cmb->options_page_keys(); |
252 | 252 | |
253 | 253 | // Must have an option key, must be an options page box. |
254 | - if ( ! isset( $option_key[0] ) || 'options-page' !== $cmb->mb_object_type() ) { |
|
254 | + if ( ! isset($option_key[0]) || 'options-page' !== $cmb->mb_object_type()) { |
|
255 | 255 | continue; |
256 | 256 | } |
257 | 257 | |
258 | - $tabs[ $option_key[0] ] = $cmb->prop( 'tab_title', $cmb->prop( 'title' ) ); |
|
258 | + $tabs[$option_key[0]] = $cmb->prop('tab_title', $cmb->prop('title')); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @since 2.2.5 |
269 | 269 | */ |
270 | 270 | public function options_page_metabox() { |
271 | - $this->show_form_for_type( 'options-page' ); |
|
271 | + $this->show_form_for_type('options-page'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -279,26 +279,26 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function save_options() { |
281 | 281 | $url = wp_get_referer(); |
282 | - if ( ! $url ) { |
|
282 | + if ( ! $url) { |
|
283 | 283 | $url = admin_url(); |
284 | 284 | } |
285 | 285 | |
286 | 286 | if ( |
287 | - $this->can_save( 'options-page' ) |
|
287 | + $this->can_save('options-page') |
|
288 | 288 | // check params. |
289 | - && isset( $_POST['submit-cmb'], $_POST['action'] ) |
|
289 | + && isset($_POST['submit-cmb'], $_POST['action']) |
|
290 | 290 | && $this->option_key === $_POST['action'] |
291 | 291 | ) { |
292 | 292 | |
293 | 293 | $updated = $this->cmb |
294 | - ->save_fields( $this->option_key, $this->cmb->object_type(), $_POST ) |
|
294 | + ->save_fields($this->option_key, $this->cmb->object_type(), $_POST) |
|
295 | 295 | ->was_updated(); // Will be false if no values were changed/updated. |
296 | 296 | |
297 | - $url = add_query_arg( 'settings-updated', $updated ? 'true' : 'false', $url ); |
|
298 | - $url = apply_filters( 'cmb2_options_page_redirect_url', $url ); |
|
297 | + $url = add_query_arg('settings-updated', $updated ? 'true' : 'false', $url); |
|
298 | + $url = apply_filters('cmb2_options_page_redirect_url', $url); |
|
299 | 299 | } |
300 | 300 | |
301 | - wp_safe_redirect( esc_url_raw( $url ), 303 /* WP_Http::SEE_OTHER */ ); |
|
301 | + wp_safe_redirect(esc_url_raw($url), 303 /* WP_Http::SEE_OTHER */); |
|
302 | 302 | exit; |
303 | 303 | } |
304 | 304 | |
@@ -311,8 +311,8 @@ discard block |
||
311 | 311 | * @param mixed $default Default value to use. |
312 | 312 | * @return mixed Value set for the network option. |
313 | 313 | */ |
314 | - public function network_get_override( $test, $default = false ) { |
|
315 | - return get_site_option( $this->option_key, $default ); |
|
314 | + public function network_get_override($test, $default = false) { |
|
315 | + return get_site_option($this->option_key, $default); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | * @param mixed $option_value Value to use. |
325 | 325 | * @return bool Success/Failure |
326 | 326 | */ |
327 | - public function network_update_override( $test, $option_value ) { |
|
328 | - return update_site_option( $this->option_key, $option_value ); |
|
327 | + public function network_update_override($test, $option_value) { |
|
328 | + return update_site_option($this->option_key, $option_value); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @param string $page Page slug. |
337 | 337 | * @return boolean |
338 | 338 | */ |
339 | - public static function is_page( $page ) { |
|
340 | - return isset( $_GET['page'] ) && $page === $_GET['page']; |
|
339 | + public static function is_page($page) { |
|
340 | + return isset($_GET['page']) && $page === $_GET['page']; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | * @throws Exception Throws an exception if the field is invalid. |
349 | 349 | * @return mixed |
350 | 350 | */ |
351 | - public function __get( $field ) { |
|
352 | - switch ( $field ) { |
|
351 | + public function __get($field) { |
|
352 | + switch ($field) { |
|
353 | 353 | case 'object_type': |
354 | 354 | case 'option_key': |
355 | 355 | case 'cmb': |
356 | 356 | return $this->{$field}; |
357 | 357 | default: |
358 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) ); |
|
358 | + throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field)); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | } |