@@ -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 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public $type = null; |
38 | 38 | |
39 | - public function __construct( CMB2_Field $field ) { |
|
39 | + public function __construct(CMB2_Field $field) { |
|
40 | 40 | $this->field = $field; |
41 | 41 | } |
42 | 42 | |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | * @param string $fieldtype Non-existent field type name |
48 | 48 | * @param array $arguments All arguments passed to the method |
49 | 49 | */ |
50 | - public function __call( $fieldtype, $arguments ) { |
|
50 | + public function __call($fieldtype, $arguments) { |
|
51 | 51 | |
52 | 52 | // Check for methods to be proxied to the CMB2_Type_Base object. |
53 | - if ( $exists = $this->maybe_proxy_method( $fieldtype, $arguments ) ) { |
|
53 | + if ($exists = $this->maybe_proxy_method($fieldtype, $arguments)) { |
|
54 | 54 | return $exists['value']; |
55 | 55 | } |
56 | 56 | |
57 | 57 | // Check for custom field type class. |
58 | - if ( $object = $this->maybe_custom_field_object( $fieldtype, $arguments ) ) { |
|
58 | + if ($object = $this->maybe_custom_field_object($fieldtype, $arguments)) { |
|
59 | 59 | return $object->render(); |
60 | 60 | } |
61 | 61 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * but could also be `comment`, `user` or `options-page`. |
76 | 76 | * @param object $field_type_object This `CMB2_Types` object |
77 | 77 | */ |
78 | - do_action( "cmb2_render_{$fieldtype}", $this->field, $this->field->escaped_value(), $this->field->object_id, $this->field->object_type, $this ); |
|
78 | + do_action("cmb2_render_{$fieldtype}", $this->field, $this->field->escaped_value(), $this->field->object_id, $this->field->object_type, $this); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @since 1.1.0 |
85 | 85 | */ |
86 | 86 | public function render() { |
87 | - if ( $this->field->args( 'repeatable' ) ) { |
|
87 | + if ($this->field->args('repeatable')) { |
|
88 | 88 | $this->render_repeatable_field(); |
89 | 89 | } else { |
90 | 90 | $this->_render(); |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * @since 1.1.0 |
98 | 98 | */ |
99 | 99 | protected function _render() { |
100 | - $this->field->peform_param_callback( 'before_field' ); |
|
100 | + $this->field->peform_param_callback('before_field'); |
|
101 | 101 | echo $this->{$this->field->type()}(); |
102 | - $this->field->peform_param_callback( 'after_field' ); |
|
102 | + $this->field->peform_param_callback('after_field'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return mixed Results from called method. |
115 | 115 | */ |
116 | - protected function proxy_method( $method, $default, $args = array() ) { |
|
117 | - if ( ! is_object( $this->type ) ) { |
|
118 | - $this->guess_type_object( $method ); |
|
116 | + protected function proxy_method($method, $default, $args = array()) { |
|
117 | + if ( ! is_object($this->type)) { |
|
118 | + $this->guess_type_object($method); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( is_object( $this->type ) && method_exists( $this->type, $method ) ) { |
|
121 | + if (is_object($this->type) && method_exists($this->type, $method)) { |
|
122 | 122 | |
123 | - return empty( $args ) |
|
123 | + return empty($args) |
|
124 | 124 | ? $this->type->$method() |
125 | - : call_user_func_array( array( $this->type, $method ), $args ); |
|
125 | + : call_user_func_array(array($this->type, $method), $args); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | return $default; |
@@ -138,35 +138,35 @@ discard block |
||
138 | 138 | * @param string $method Method attempting to be called on the CMB2_Type_Base object. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | - protected function guess_type_object( $method ) { |
|
141 | + protected function guess_type_object($method) { |
|
142 | 142 | $fieldtype = $this->field->type(); |
143 | 143 | |
144 | 144 | // Try to "guess" the Type object based on the method requested. |
145 | - switch ( $method ) { |
|
145 | + switch ($method) { |
|
146 | 146 | case 'select_option': |
147 | 147 | case 'list_input': |
148 | 148 | case 'list_input_checkbox': |
149 | 149 | case 'concat_items': |
150 | - $this->get_new_render_type( $fieldtype, 'CMB2_Type_Select' ); |
|
150 | + $this->get_new_render_type($fieldtype, 'CMB2_Type_Select'); |
|
151 | 151 | break; |
152 | 152 | case 'is_valid_img_ext': |
153 | 153 | case 'img_status_output': |
154 | 154 | case 'file_status_output': |
155 | - $this->get_new_render_type( $fieldtype, 'CMB2_Type_File_Base' ); |
|
155 | + $this->get_new_render_type($fieldtype, 'CMB2_Type_File_Base'); |
|
156 | 156 | break; |
157 | 157 | case 'parse_picker_options': |
158 | - $this->get_new_render_type( $fieldtype, 'CMB2_Type_Text_Date' ); |
|
158 | + $this->get_new_render_type($fieldtype, 'CMB2_Type_Text_Date'); |
|
159 | 159 | break; |
160 | 160 | case 'get_object_terms': |
161 | 161 | case 'get_terms': |
162 | - $this->get_new_render_type( $fieldtype, 'CMB2_Type_Taxonomy_Multicheck' ); |
|
162 | + $this->get_new_render_type($fieldtype, 'CMB2_Type_Taxonomy_Multicheck'); |
|
163 | 163 | break; |
164 | 164 | case 'date_args': |
165 | 165 | case 'time_args': |
166 | - $this->get_new_render_type( $fieldtype, 'CMB2_Type_Text_Datetime_Timestamp' ); |
|
166 | + $this->get_new_render_type($fieldtype, 'CMB2_Type_Text_Datetime_Timestamp'); |
|
167 | 167 | break; |
168 | 168 | case 'parse_args': |
169 | - $this->get_new_render_type( $fieldtype, 'CMB2_Type_Text' ); |
|
169 | + $this->get_new_render_type($fieldtype, 'CMB2_Type_Text'); |
|
170 | 170 | break; |
171 | 171 | } |
172 | 172 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param array $arguments All arguments passed to the method. |
182 | 182 | * @return bool|array False if not proxied, else array with 'value' key being the return of the method. |
183 | 183 | */ |
184 | - public function maybe_proxy_method( $method, $arguments ) { |
|
184 | + public function maybe_proxy_method($method, $arguments) { |
|
185 | 185 | $exists = false; |
186 | 186 | |
187 | 187 | $proxied = array( |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | 'file_status_output' => '', |
197 | 197 | 'parse_picker_options' => array(), |
198 | 198 | ); |
199 | - if ( isset( $proxied[ $method ] ) ) { |
|
199 | + if (isset($proxied[$method])) { |
|
200 | 200 | $exists = array( |
201 | 201 | // Ok, proxy the method call to the CMB2_Type_Base object. |
202 | - 'value' => $this->proxy_method( $method, $proxied[ $method ], $arguments ), |
|
202 | + 'value' => $this->proxy_method($method, $proxied[$method], $arguments), |
|
203 | 203 | ); |
204 | 204 | } |
205 | 205 | |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | * `cmb2_render_{$field_type}` action. |
219 | 219 | * @throws Exception if custom field type class does not extend CMB2_Type_Base. |
220 | 220 | */ |
221 | - public function maybe_custom_field_object( $fieldtype, $args = array() ) { |
|
222 | - if ( $render_class_name = $this->get_render_type_class( $fieldtype ) ) { |
|
223 | - $this->type = new $render_class_name( $this, $args ); |
|
221 | + public function maybe_custom_field_object($fieldtype, $args = array()) { |
|
222 | + if ($render_class_name = $this->get_render_type_class($fieldtype)) { |
|
223 | + $this->type = new $render_class_name($this, $args); |
|
224 | 224 | |
225 | - if ( ! ( $this->type instanceof CMB2_Type_Base ) ) { |
|
226 | - throw new Exception( __( 'Custom CMB2 field type classes must extend CMB2_Type_Base.', 'cmb2' ) ); |
|
225 | + if ( ! ($this->type instanceof CMB2_Type_Base)) { |
|
226 | + throw new Exception(__('Custom CMB2 field type classes must extend CMB2_Type_Base.', 'cmb2')); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | return $this->type; |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | * @param mixed $additional Optional additional argument to pass to type class. |
243 | 243 | * @return CMB2_Type_Base Type object. |
244 | 244 | */ |
245 | - public function get_new_render_type( $fieldtype, $render_class_name = null, $args = array(), $additional = '' ) { |
|
246 | - $render_class_name = $this->get_render_type_class( $fieldtype, $render_class_name ); |
|
247 | - $this->type = new $render_class_name( $this, $args, $additional ); |
|
245 | + public function get_new_render_type($fieldtype, $render_class_name = null, $args = array(), $additional = '') { |
|
246 | + $render_class_name = $this->get_render_type_class($fieldtype, $render_class_name); |
|
247 | + $this->type = new $render_class_name($this, $args, $additional); |
|
248 | 248 | |
249 | 249 | return $this->type; |
250 | 250 | } |
@@ -257,10 +257,10 @@ discard block |
||
257 | 257 | * @param string $render_class_name The default field type class to use. Defaults to null. |
258 | 258 | * @return string The field type class to use. |
259 | 259 | */ |
260 | - public function get_render_type_class( $fieldtype, $render_class_name = null ) { |
|
261 | - $render_class_name = $this->field->args( 'render_class' ) ? $this->field->args( 'render_class' ) : $render_class_name; |
|
260 | + public function get_render_type_class($fieldtype, $render_class_name = null) { |
|
261 | + $render_class_name = $this->field->args('render_class') ? $this->field->args('render_class') : $render_class_name; |
|
262 | 262 | |
263 | - if ( has_action( "cmb2_render_class_{$fieldtype}" ) ) { |
|
263 | + if (has_action("cmb2_render_class_{$fieldtype}")) { |
|
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Filters the custom field type class used for rendering the field. Class is required to extend CMB2_Type_Base. |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | * @param string $render_class_name The custom field type class to use. Default null. |
273 | 273 | * @param object $field_type_object This `CMB2_Types` object. |
274 | 274 | */ |
275 | - $render_class_name = apply_filters( "cmb2_render_class_{$fieldtype}", $render_class_name, $this ); |
|
275 | + $render_class_name = apply_filters("cmb2_render_class_{$fieldtype}", $render_class_name, $this); |
|
276 | 276 | } |
277 | 277 | |
278 | - return $render_class_name && class_exists( $render_class_name ) ? $render_class_name : false; |
|
278 | + return $render_class_name && class_exists($render_class_name) ? $render_class_name : false; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | * @param string $fallback Fallback text. |
287 | 287 | * @return string |
288 | 288 | */ |
289 | - public function _text( $text_key, $fallback = '' ) { |
|
290 | - return $this->field->get_string( $text_key, $fallback ); |
|
289 | + public function _text($text_key, $fallback = '') { |
|
290 | + return $this->field->get_string($text_key, $fallback); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -297,8 +297,8 @@ discard block |
||
297 | 297 | * @param string $file File url |
298 | 298 | * @return string|false File extension or false |
299 | 299 | */ |
300 | - public function get_file_ext( $file ) { |
|
301 | - return CMB2_Utils::get_file_ext( $file ); |
|
300 | + public function get_file_ext($file) { |
|
301 | + return CMB2_Utils::get_file_ext($file); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * @param string $value File url or path |
309 | 309 | * @return string File name |
310 | 310 | */ |
311 | - public function get_file_name_from_path( $value ) { |
|
312 | - return CMB2_Utils::get_file_name_from_path( $value ); |
|
311 | + public function get_file_name_from_path($value) { |
|
312 | + return CMB2_Utils::get_file_name_from_path($value); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | * @param array $attr_exclude Attributes that should NOT be concatenated |
321 | 321 | * @return string String of attributes for form element |
322 | 322 | */ |
323 | - public function concat_attrs( $attrs, $attr_exclude = array() ) { |
|
324 | - return CMB2_Utils::concat_attrs( $attrs, $attr_exclude ); |
|
323 | + public function concat_attrs($attrs, $attr_exclude = array()) { |
|
324 | + return CMB2_Utils::concat_attrs($attrs, $attr_exclude); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | public function render_repeatable_field() { |
333 | 333 | $table_id = $this->field->id() . '_repeat'; |
334 | 334 | |
335 | - $this->_desc( true, true, true ); |
|
335 | + $this->_desc(true, true, true); |
|
336 | 336 | ?> |
337 | 337 | |
338 | 338 | <div id="<?php echo $table_id; ?>" class="cmb-repeat-table cmb-nested"> |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <p class="cmb-add-row"> |
344 | - <button type="button" data-selector="<?php echo $table_id; ?>" class="cmb-add-row-button button-secondary"><?php echo esc_html( $this->_text( 'add_row_text', esc_html__( 'Add Row', 'cmb2' ) ) ); ?></button> |
|
344 | + <button type="button" data-selector="<?php echo $table_id; ?>" class="cmb-add-row-button button-secondary"><?php echo esc_html($this->_text('add_row_text', esc_html__('Add Row', 'cmb2'))); ?></button> |
|
345 | 345 | </p> |
346 | 346 | |
347 | 347 | <?php |
@@ -355,21 +355,21 @@ discard block |
||
355 | 355 | * @since 1.1.0 |
356 | 356 | */ |
357 | 357 | public function repeatable_rows() { |
358 | - $meta_value = array_filter( (array) $this->field->escaped_value() ); |
|
358 | + $meta_value = array_filter((array) $this->field->escaped_value()); |
|
359 | 359 | // check for default content |
360 | 360 | $default = $this->field->get_default(); |
361 | 361 | |
362 | 362 | // check for saved data |
363 | - if ( ! empty( $meta_value ) ) { |
|
364 | - $meta_value = is_array( $meta_value ) ? array_filter( $meta_value ) : $meta_value; |
|
365 | - $meta_value = ! empty( $meta_value ) ? $meta_value : $default; |
|
363 | + if ( ! empty($meta_value)) { |
|
364 | + $meta_value = is_array($meta_value) ? array_filter($meta_value) : $meta_value; |
|
365 | + $meta_value = ! empty($meta_value) ? $meta_value : $default; |
|
366 | 366 | } else { |
367 | 367 | $meta_value = $default; |
368 | 368 | } |
369 | 369 | |
370 | 370 | // Loop value array and add a row |
371 | - if ( ! empty( $meta_value ) ) { |
|
372 | - foreach ( (array) $meta_value as $val ) { |
|
371 | + if ( ! empty($meta_value)) { |
|
372 | + foreach ((array) $meta_value as $val) { |
|
373 | 373 | $this->field->escaped_value = $val; |
374 | 374 | $this->repeat_row(); |
375 | 375 | $this->iterator++; |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | // Then add an empty row |
387 | 387 | $this->field->escaped_value = $default; |
388 | 388 | $this->iterator = $this->iterator ? $this->iterator : 1; |
389 | - $this->repeat_row( 'empty-row hidden' ); |
|
389 | + $this->repeat_row('empty-row hidden'); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -395,17 +395,17 @@ discard block |
||
395 | 395 | * @since 1.1.0 |
396 | 396 | * @param string $classes Repeatable table row's class |
397 | 397 | */ |
398 | - protected function repeat_row( $classes = 'cmb-repeat-row' ) { |
|
399 | - $classes = explode( ' ', $classes ); |
|
400 | - $classes = array_map( 'sanitize_html_class', $classes ); |
|
398 | + protected function repeat_row($classes = 'cmb-repeat-row') { |
|
399 | + $classes = explode(' ', $classes); |
|
400 | + $classes = array_map('sanitize_html_class', $classes); |
|
401 | 401 | ?> |
402 | 402 | |
403 | - <div class="cmb-row <?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
|
403 | + <div class="cmb-row <?php echo esc_attr(implode(' ', $classes)); ?>"> |
|
404 | 404 | <div class="cmb-td"> |
405 | 405 | <?php $this->_render(); ?> |
406 | 406 | </div> |
407 | 407 | <div class="cmb-td cmb-remove-row"> |
408 | - <button type="button" class="button-secondary cmb-remove-row-button" title="<?php echo esc_attr( $this->_text( 'remove_row_button_title', esc_html__( 'Remove Row', 'cmb2' ) ) ); ?>"><?php echo esc_html( $this->_text( 'remove_row_text', esc_html__( 'Remove', 'cmb2' ) ) ); ?></button> |
|
408 | + <button type="button" class="button-secondary cmb-remove-row-button" title="<?php echo esc_attr($this->_text('remove_row_button_title', esc_html__('Remove Row', 'cmb2'))); ?>"><?php echo esc_html($this->_text('remove_row_text', esc_html__('Remove', 'cmb2'))); ?></button> |
|
409 | 409 | </div> |
410 | 410 | </div> |
411 | 411 | |
@@ -421,22 +421,22 @@ discard block |
||
421 | 421 | * @param bool $repeat_group Whether to repeat the group. |
422 | 422 | * @return string Field's description markup. |
423 | 423 | */ |
424 | - public function _desc( $paragraph = false, $echo = false, $repeat_group = false ) { |
|
424 | + public function _desc($paragraph = false, $echo = false, $repeat_group = false) { |
|
425 | 425 | // Prevent description from printing multiple times for repeatable fields |
426 | - if ( ! $repeat_group && ( $this->field->args( 'repeatable' ) || $this->iterator > 0 ) ) { |
|
426 | + if ( ! $repeat_group && ($this->field->args('repeatable') || $this->iterator > 0)) { |
|
427 | 427 | return ''; |
428 | 428 | } |
429 | 429 | |
430 | - $desc = $this->field->args( 'description' ); |
|
430 | + $desc = $this->field->args('description'); |
|
431 | 431 | |
432 | - if ( ! $desc ) { |
|
432 | + if ( ! $desc) { |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
436 | 436 | $tag = $paragraph ? 'p' : 'span'; |
437 | - $desc = sprintf( "\n" . '<%1$s class="cmb2-metabox-description">%2$s</%1$s>' . "\n", $tag, $desc ); |
|
437 | + $desc = sprintf("\n" . '<%1$s class="cmb2-metabox-description">%2$s</%1$s>' . "\n", $tag, $desc); |
|
438 | 438 | |
439 | - if ( $echo ) { |
|
439 | + if ($echo) { |
|
440 | 440 | echo $desc; |
441 | 441 | } |
442 | 442 | |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | * @param string $suffix For multi-part fields |
451 | 451 | * @return string Name attribute |
452 | 452 | */ |
453 | - public function _name( $suffix = '' ) { |
|
454 | - return $this->field->args( '_name' ) . ( $this->field->args( 'repeatable' ) ? '[' . $this->iterator . ']' : '' ) . $suffix; |
|
453 | + public function _name($suffix = '') { |
|
454 | + return $this->field->args('_name') . ($this->field->args('repeatable') ? '[' . $this->iterator . ']' : '') . $suffix; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | * @param bool $append_repeatable_iterator Whether to append the iterator attribue if the field is repeatable. |
463 | 463 | * @return string Id attribute |
464 | 464 | */ |
465 | - public function _id( $suffix = '', $append_repeatable_iterator = true ) { |
|
466 | - $id = $this->field->id() . $suffix . ( $this->field->args( 'repeatable' ) ? '_' . $this->iterator : '' ); |
|
465 | + public function _id($suffix = '', $append_repeatable_iterator = true) { |
|
466 | + $id = $this->field->id() . $suffix . ($this->field->args('repeatable') ? '_' . $this->iterator : ''); |
|
467 | 467 | |
468 | - if ( $append_repeatable_iterator && $this->field->args( 'repeatable' ) ) { |
|
468 | + if ($append_repeatable_iterator && $this->field->args('repeatable')) { |
|
469 | 469 | $id .= '" data-iterator="' . $this->iterator; |
470 | 470 | } |
471 | 471 | |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * @param string $type Field type |
481 | 481 | * @return string Form input element |
482 | 482 | */ |
483 | - public function input( $args = array(), $type = __FUNCTION__ ) { |
|
484 | - return $this->get_new_render_type( 'text', 'CMB2_Type_Text', $args, $type )->render(); |
|
483 | + public function input($args = array(), $type = __FUNCTION__) { |
|
484 | + return $this->get_new_render_type('text', 'CMB2_Type_Text', $args, $type)->render(); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,8 +491,8 @@ discard block |
||
491 | 491 | * @param array $args Override arguments |
492 | 492 | * @return string Form textarea element |
493 | 493 | */ |
494 | - public function textarea( $args = array() ) { |
|
495 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea', $args )->render(); |
|
494 | + public function textarea($args = array()) { |
|
495 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Textarea', $args)->render(); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -509,167 +509,167 @@ discard block |
||
509 | 509 | 'desc' => '', |
510 | 510 | 'class' => 'cmb2-hidden', |
511 | 511 | ); |
512 | - if ( $this->field->group ) { |
|
512 | + if ($this->field->group) { |
|
513 | 513 | $args['data-groupid'] = $this->field->group->id(); |
514 | 514 | $args['data-iterator'] = $this->iterator; |
515 | 515 | } |
516 | 516 | |
517 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', $args, 'input' )->render(); |
|
517 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text', $args, 'input')->render(); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | public function text_small() { |
521 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array( |
|
521 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text', array( |
|
522 | 522 | 'class' => 'cmb2-text-small', |
523 | 523 | 'desc' => $this->_desc(), |
524 | - ), 'input' )->render(); |
|
524 | + ), 'input')->render(); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | public function text_medium() { |
528 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array( |
|
528 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text', array( |
|
529 | 529 | 'class' => 'cmb2-text-medium', |
530 | 530 | 'desc' => $this->_desc(), |
531 | - ), 'input' )->render(); |
|
531 | + ), 'input')->render(); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | public function text_email() { |
535 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array( |
|
535 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text', array( |
|
536 | 536 | 'class' => 'cmb2-text-email cmb2-text-medium', |
537 | 537 | 'type' => 'email', |
538 | - ), 'input' )->render(); |
|
538 | + ), 'input')->render(); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | public function text_url() { |
542 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array( |
|
542 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text', array( |
|
543 | 543 | 'class' => 'cmb2-text-url cmb2-text-medium regular-text', |
544 | - 'value' => $this->field->escaped_value( 'esc_url' ), |
|
545 | - ), 'input' )->render(); |
|
544 | + 'value' => $this->field->escaped_value('esc_url'), |
|
545 | + ), 'input')->render(); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | public function text_money() { |
549 | - $input = $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array( |
|
549 | + $input = $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text', array( |
|
550 | 550 | 'class' => 'cmb2-text-money', |
551 | 551 | 'desc' => $this->_desc(), |
552 | - ), 'input' )->render(); |
|
553 | - return ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$ ' : ' ' ) . $input; |
|
552 | + ), 'input')->render(); |
|
553 | + return ( ! $this->field->get_param_callback_result('before_field') ? '$ ' : ' ') . $input; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | public function textarea_small() { |
557 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea', array( |
|
557 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Textarea', array( |
|
558 | 558 | 'class' => 'cmb2-textarea-small', |
559 | 559 | 'rows' => 4, |
560 | - ) )->render(); |
|
560 | + ))->render(); |
|
561 | 561 | } |
562 | 562 | |
563 | - public function textarea_code( $args = array() ) { |
|
564 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea_Code', $args )->render(); |
|
563 | + public function textarea_code($args = array()) { |
|
564 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Textarea_Code', $args)->render(); |
|
565 | 565 | } |
566 | 566 | |
567 | - public function wysiwyg( $args = array() ) { |
|
568 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Wysiwyg', $args )->render(); |
|
567 | + public function wysiwyg($args = array()) { |
|
568 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Wysiwyg', $args)->render(); |
|
569 | 569 | } |
570 | 570 | |
571 | - public function text_date( $args = array() ) { |
|
572 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Date', $args )->render(); |
|
571 | + public function text_date($args = array()) { |
|
572 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text_Date', $args)->render(); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | // Alias for text_date |
576 | - public function text_date_timestamp( $args = array() ) { |
|
577 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Date', $args )->render(); |
|
576 | + public function text_date_timestamp($args = array()) { |
|
577 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text_Date', $args)->render(); |
|
578 | 578 | } |
579 | 579 | |
580 | - public function text_time( $args = array() ) { |
|
581 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Time', $args )->render(); |
|
580 | + public function text_time($args = array()) { |
|
581 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text_Time', $args)->render(); |
|
582 | 582 | } |
583 | 583 | |
584 | - public function text_datetime_timestamp( $args = array() ) { |
|
585 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp', $args )->render(); |
|
584 | + public function text_datetime_timestamp($args = array()) { |
|
585 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp', $args)->render(); |
|
586 | 586 | } |
587 | 587 | |
588 | - public function text_datetime_timestamp_timezone( $args = array() ) { |
|
589 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp_Timezone', $args )->render(); |
|
588 | + public function text_datetime_timestamp_timezone($args = array()) { |
|
589 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp_Timezone', $args)->render(); |
|
590 | 590 | } |
591 | 591 | |
592 | - public function select_timezone( $args = array() ) { |
|
593 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Select_Timezone', $args )->render(); |
|
592 | + public function select_timezone($args = array()) { |
|
593 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Select_Timezone', $args)->render(); |
|
594 | 594 | } |
595 | 595 | |
596 | - public function colorpicker( $args = array(), $meta_value = '' ) { |
|
597 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Colorpicker', $args, $meta_value )->render(); |
|
596 | + public function colorpicker($args = array(), $meta_value = '') { |
|
597 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Colorpicker', $args, $meta_value)->render(); |
|
598 | 598 | } |
599 | 599 | |
600 | - public function title( $args = array() ) { |
|
601 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Title', $args )->render(); |
|
600 | + public function title($args = array()) { |
|
601 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Title', $args)->render(); |
|
602 | 602 | } |
603 | 603 | |
604 | - public function select( $args = array() ) { |
|
605 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Select', $args )->render(); |
|
604 | + public function select($args = array()) { |
|
605 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Select', $args)->render(); |
|
606 | 606 | } |
607 | 607 | |
608 | - public function taxonomy_select( $args = array() ) { |
|
609 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Select', $args )->render(); |
|
608 | + public function taxonomy_select($args = array()) { |
|
609 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Taxonomy_Select', $args)->render(); |
|
610 | 610 | } |
611 | 611 | |
612 | - public function taxonomy_select_hierarchical( $args = array() ) { |
|
613 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Select_Hierarchical', $args )->render(); |
|
612 | + public function taxonomy_select_hierarchical($args = array()) { |
|
613 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Taxonomy_Select_Hierarchical', $args)->render(); |
|
614 | 614 | } |
615 | 615 | |
616 | - public function radio( $args = array(), $type = __FUNCTION__ ) { |
|
617 | - return $this->get_new_render_type( $type, 'CMB2_Type_Radio', $args, $type )->render(); |
|
616 | + public function radio($args = array(), $type = __FUNCTION__) { |
|
617 | + return $this->get_new_render_type($type, 'CMB2_Type_Radio', $args, $type)->render(); |
|
618 | 618 | } |
619 | 619 | |
620 | - public function radio_inline( $args = array() ) { |
|
621 | - return $this->radio( $args, __FUNCTION__ ); |
|
620 | + public function radio_inline($args = array()) { |
|
621 | + return $this->radio($args, __FUNCTION__); |
|
622 | 622 | } |
623 | 623 | |
624 | - public function multicheck( $type = 'checkbox' ) { |
|
625 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Multicheck', array(), $type )->render(); |
|
624 | + public function multicheck($type = 'checkbox') { |
|
625 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Multicheck', array(), $type)->render(); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | public function multicheck_inline() { |
629 | - return $this->multicheck( 'multicheck_inline' ); |
|
629 | + return $this->multicheck('multicheck_inline'); |
|
630 | 630 | } |
631 | 631 | |
632 | - public function checkbox( $args = array(), $is_checked = null ) { |
|
632 | + public function checkbox($args = array(), $is_checked = null) { |
|
633 | 633 | // Avoid get_new_render_type since we need a different default for the 3rd argument than ''. |
634 | - $render_class_name = $this->get_render_type_class( __FUNCTION__, 'CMB2_Type_Checkbox' ); |
|
635 | - $this->type = new $render_class_name( $this, $args, $is_checked ); |
|
634 | + $render_class_name = $this->get_render_type_class(__FUNCTION__, 'CMB2_Type_Checkbox'); |
|
635 | + $this->type = new $render_class_name($this, $args, $is_checked); |
|
636 | 636 | return $this->type->render(); |
637 | 637 | } |
638 | 638 | |
639 | - public function taxonomy_radio( $args = array() ) { |
|
640 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Radio', $args )->render(); |
|
639 | + public function taxonomy_radio($args = array()) { |
|
640 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Taxonomy_Radio', $args)->render(); |
|
641 | 641 | } |
642 | 642 | |
643 | - public function taxonomy_radio_hierarchical( $args = array() ) { |
|
644 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Radio_Hierarchical', $args )->render(); |
|
643 | + public function taxonomy_radio_hierarchical($args = array()) { |
|
644 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Taxonomy_Radio_Hierarchical', $args)->render(); |
|
645 | 645 | } |
646 | 646 | |
647 | - public function taxonomy_radio_inline( $args = array() ) { |
|
648 | - return $this->taxonomy_radio( $args ); |
|
647 | + public function taxonomy_radio_inline($args = array()) { |
|
648 | + return $this->taxonomy_radio($args); |
|
649 | 649 | } |
650 | 650 | |
651 | - public function taxonomy_multicheck( $args = array() ) { |
|
652 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck', $args )->render(); |
|
651 | + public function taxonomy_multicheck($args = array()) { |
|
652 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck', $args)->render(); |
|
653 | 653 | } |
654 | 654 | |
655 | - public function taxonomy_multicheck_hierarchical( $args = array() ) { |
|
656 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck_Hierarchical', $args )->render(); |
|
655 | + public function taxonomy_multicheck_hierarchical($args = array()) { |
|
656 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck_Hierarchical', $args)->render(); |
|
657 | 657 | } |
658 | 658 | |
659 | - public function taxonomy_multicheck_inline( $args = array() ) { |
|
660 | - return $this->taxonomy_multicheck( $args ); |
|
659 | + public function taxonomy_multicheck_inline($args = array()) { |
|
660 | + return $this->taxonomy_multicheck($args); |
|
661 | 661 | } |
662 | 662 | |
663 | - public function oembed( $args = array() ) { |
|
664 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Oembed', $args )->render(); |
|
663 | + public function oembed($args = array()) { |
|
664 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_Oembed', $args)->render(); |
|
665 | 665 | } |
666 | 666 | |
667 | - public function file_list( $args = array() ) { |
|
668 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_File_List', $args )->render(); |
|
667 | + public function file_list($args = array()) { |
|
668 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_File_List', $args)->render(); |
|
669 | 669 | } |
670 | 670 | |
671 | - public function file( $args = array() ) { |
|
672 | - return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_File', $args )->render(); |
|
671 | + public function file($args = array()) { |
|
672 | + return $this->get_new_render_type(__FUNCTION__, 'CMB2_Type_File', $args)->render(); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @param string $path Path to append. |
17 | 17 | * @return string Directory with optional path appended |
18 | 18 | */ |
19 | -function cmb2_dir( $path = '' ) { |
|
19 | +function cmb2_dir($path = '') { |
|
20 | 20 | return CMB2_DIR . $path; |
21 | 21 | } |
22 | 22 | |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | * @since 1.0.0 |
27 | 27 | * @param string $class_name Name of the class being requested. |
28 | 28 | */ |
29 | -function cmb2_autoload_classes( $class_name ) { |
|
30 | - if ( 0 !== strpos( $class_name, 'CMB2' ) ) { |
|
29 | +function cmb2_autoload_classes($class_name) { |
|
30 | + if (0 !== strpos($class_name, 'CMB2')) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | 34 | $path = 'includes'; |
35 | 35 | |
36 | - if ( 'CMB2_Type' === $class_name || 0 === strpos( $class_name, 'CMB2_Type_' ) ) { |
|
36 | + if ('CMB2_Type' === $class_name || 0 === strpos($class_name, 'CMB2_Type_')) { |
|
37 | 37 | $path .= '/types'; |
38 | 38 | } |
39 | 39 | |
40 | - if ( 'CMB2_REST' === $class_name || 0 === strpos( $class_name, 'CMB2_REST_' ) ) { |
|
40 | + if ('CMB2_REST' === $class_name || 0 === strpos($class_name, 'CMB2_REST_')) { |
|
41 | 41 | $path .= '/rest-api'; |
42 | 42 | } |
43 | 43 | |
44 | - include_once( cmb2_dir( "$path/{$class_name}.php" ) ); |
|
44 | + include_once(cmb2_dir("$path/{$class_name}.php")); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @param string $key Option key to fetch. |
75 | 75 | * @return CMB2_Option object Options class for setting/getting options for metabox |
76 | 76 | */ |
77 | -function cmb2_options( $key ) { |
|
78 | - return CMB2_Options::get( $key ); |
|
77 | +function cmb2_options($key) { |
|
78 | + return CMB2_Options::get($key); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -94,23 +94,23 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return string oEmbed string |
96 | 96 | */ |
97 | -function cmb2_get_oembed( $args = array() ) { |
|
98 | - $oembed = cmb2_ajax()->get_oembed_no_edit( $args ); |
|
97 | +function cmb2_get_oembed($args = array()) { |
|
98 | + $oembed = cmb2_ajax()->get_oembed_no_edit($args); |
|
99 | 99 | |
100 | 100 | // Send back our embed. |
101 | - if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) { |
|
101 | + if ($oembed['embed'] && $oembed['embed'] != $oembed['fallback']) { |
|
102 | 102 | return '<div class="cmb2-oembed">' . $oembed['embed'] . '</div>'; |
103 | 103 | } |
104 | 104 | |
105 | 105 | $error = sprintf( |
106 | 106 | /* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */ |
107 | - esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ), |
|
107 | + esc_html__('No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2'), |
|
108 | 108 | $oembed['fallback'], |
109 | 109 | '<a href="https://wordpress.org/support/article/embeds/" target="_blank">codex.wordpress.org/Embeds</a>' |
110 | 110 | ); |
111 | 111 | |
112 | - if ( isset( $args['wp_error'] ) && $args['wp_error'] ) { |
|
113 | - return new WP_Error( 'cmb2_get_oembed_result', $error, compact( 'oembed', 'args' ) ); |
|
112 | + if (isset($args['wp_error']) && $args['wp_error']) { |
|
113 | + return new WP_Error('cmb2_get_oembed_result', $error, compact('oembed', 'args')); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | // Otherwise, send back error info that no oEmbeds were found. |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param array $args oEmbed args. |
127 | 127 | */ |
128 | -function cmb2_do_oembed( $args = array() ) { |
|
129 | - echo cmb2_get_oembed( $args ); |
|
128 | +function cmb2_do_oembed($args = array()) { |
|
129 | + echo cmb2_get_oembed($args); |
|
130 | 130 | } |
131 | -add_action( 'cmb2_do_oembed', 'cmb2_do_oembed' ); |
|
131 | +add_action('cmb2_do_oembed', 'cmb2_do_oembed'); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * A helper function to get an option from a CMB2 options array |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param mixed $default Optional default fallback value. |
140 | 140 | * @return array Options array or specific field |
141 | 141 | */ |
142 | -function cmb2_get_option( $option_key, $field_id = '', $default = false ) { |
|
143 | - return cmb2_options( $option_key )->get( $field_id, $default ); |
|
142 | +function cmb2_get_option($option_key, $field_id = '', $default = false) { |
|
143 | + return cmb2_options($option_key)->get($field_id, $default); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * @param boolean $single Whether data should not be an array. |
154 | 154 | * @return boolean Success/Failure |
155 | 155 | */ |
156 | -function cmb2_update_option( $option_key, $field_id, $value, $single = true ) { |
|
157 | - if ( cmb2_options( $option_key )->update( $field_id, $value, false, $single ) ) { |
|
158 | - return cmb2_options( $option_key )->set(); |
|
156 | +function cmb2_update_option($option_key, $field_id, $value, $single = true) { |
|
157 | + if (cmb2_options($option_key)->update($field_id, $value, false, $single)) { |
|
158 | + return cmb2_options($option_key)->set(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return false; |
@@ -172,18 +172,18 @@ discard block |
||
172 | 172 | * Defaults to metabox object type. |
173 | 173 | * @return CMB2_Field|null CMB2_Field object unless metabox config cannot be found |
174 | 174 | */ |
175 | -function cmb2_get_field( $meta_box, $field_id, $object_id = 0, $object_type = '' ) { |
|
175 | +function cmb2_get_field($meta_box, $field_id, $object_id = 0, $object_type = '') { |
|
176 | 176 | |
177 | 177 | $object_id = $object_id ? $object_id : get_the_ID(); |
178 | - $cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox( $meta_box, $object_id ); |
|
178 | + $cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox($meta_box, $object_id); |
|
179 | 179 | |
180 | - if ( ! $cmb ) { |
|
180 | + if ( ! $cmb) { |
|
181 | 181 | return; |
182 | 182 | } |
183 | 183 | |
184 | - $cmb->object_type( $object_type ? $object_type : $cmb->mb_object_type() ); |
|
184 | + $cmb->object_type($object_type ? $object_type : $cmb->mb_object_type()); |
|
185 | 185 | |
186 | - return $cmb->get_field( $field_id ); |
|
186 | + return $cmb->get_field($field_id); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * Defaults to metabox object type. |
198 | 198 | * @return mixed Maybe escaped value |
199 | 199 | */ |
200 | -function cmb2_get_field_value( $meta_box, $field_id, $object_id = 0, $object_type = '' ) { |
|
201 | - $field = cmb2_get_field( $meta_box, $field_id, $object_id, $object_type ); |
|
200 | +function cmb2_get_field_value($meta_box, $field_id, $object_id = 0, $object_type = '') { |
|
201 | + $field = cmb2_get_field($meta_box, $field_id, $object_id, $object_type); |
|
202 | 202 | return $field->escaped_value(); |
203 | 203 | } |
204 | 204 | |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | * @param array $meta_box_config Metabox Config array. |
210 | 210 | * @return CMB2 object Instantiated CMB2 object |
211 | 211 | */ |
212 | -function new_cmb2_box( array $meta_box_config ) { |
|
213 | - return cmb2_get_metabox( $meta_box_config ); |
|
212 | +function new_cmb2_box(array $meta_box_config) { |
|
213 | + return cmb2_get_metabox($meta_box_config); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -223,27 +223,27 @@ discard block |
||
223 | 223 | * Defaults to metabox object type. |
224 | 224 | * @return CMB2 object |
225 | 225 | */ |
226 | -function cmb2_get_metabox( $meta_box, $object_id = 0, $object_type = '' ) { |
|
226 | +function cmb2_get_metabox($meta_box, $object_id = 0, $object_type = '') { |
|
227 | 227 | |
228 | - if ( $meta_box instanceof CMB2 ) { |
|
228 | + if ($meta_box instanceof CMB2) { |
|
229 | 229 | return $meta_box; |
230 | 230 | } |
231 | 231 | |
232 | - if ( is_string( $meta_box ) ) { |
|
233 | - $cmb = CMB2_Boxes::get( $meta_box ); |
|
232 | + if (is_string($meta_box)) { |
|
233 | + $cmb = CMB2_Boxes::get($meta_box); |
|
234 | 234 | } else { |
235 | 235 | // See if we already have an instance of this metabox. |
236 | - $cmb = CMB2_Boxes::get( $meta_box['id'] ); |
|
236 | + $cmb = CMB2_Boxes::get($meta_box['id']); |
|
237 | 237 | // If not, we'll initate a new metabox. |
238 | - $cmb = $cmb ? $cmb : new CMB2( $meta_box, $object_id ); |
|
238 | + $cmb = $cmb ? $cmb : new CMB2($meta_box, $object_id); |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( $cmb && $object_id ) { |
|
242 | - $cmb->object_id( $object_id ); |
|
241 | + if ($cmb && $object_id) { |
|
242 | + $cmb->object_id($object_id); |
|
243 | 243 | } |
244 | 244 | |
245 | - if ( $cmb && $object_type ) { |
|
246 | - $cmb->object_type( $object_type ); |
|
245 | + if ($cmb && $object_type) { |
|
246 | + $cmb->object_type($object_type); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | return $cmb; |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | * @param array $data_to_sanitize Array of field_id => value data for sanitizing (likely $_POST data). |
258 | 258 | * @return mixed Array of sanitized values or false if no CMB2 object found |
259 | 259 | */ |
260 | -function cmb2_get_metabox_sanitized_values( $meta_box, array $data_to_sanitize ) { |
|
261 | - $cmb = cmb2_get_metabox( $meta_box ); |
|
262 | - return $cmb ? $cmb->get_sanitized_values( $data_to_sanitize ) : false; |
|
260 | +function cmb2_get_metabox_sanitized_values($meta_box, array $data_to_sanitize) { |
|
261 | + $cmb = cmb2_get_metabox($meta_box); |
|
262 | + return $cmb ? $cmb->get_sanitized_values($data_to_sanitize) : false; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -271,17 +271,17 @@ discard block |
||
271 | 271 | * @param array $args Optional arguments array. |
272 | 272 | * @return string CMB2 html form markup |
273 | 273 | */ |
274 | -function cmb2_get_metabox_form( $meta_box, $object_id = 0, $args = array() ) { |
|
274 | +function cmb2_get_metabox_form($meta_box, $object_id = 0, $args = array()) { |
|
275 | 275 | |
276 | 276 | $object_id = $object_id ? $object_id : get_the_ID(); |
277 | - $cmb = cmb2_get_metabox( $meta_box, $object_id ); |
|
277 | + $cmb = cmb2_get_metabox($meta_box, $object_id); |
|
278 | 278 | |
279 | 279 | ob_start(); |
280 | 280 | // Get cmb form. |
281 | - cmb2_print_metabox_form( $cmb, $object_id, $args ); |
|
281 | + cmb2_print_metabox_form($cmb, $object_id, $args); |
|
282 | 282 | $form = ob_get_clean(); |
283 | 283 | |
284 | - return apply_filters( 'cmb2_get_metabox_form', $form, $object_id, $cmb ); |
|
284 | + return apply_filters('cmb2_get_metabox_form', $form, $object_id, $cmb); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -292,59 +292,59 @@ discard block |
||
292 | 292 | * @param int $object_id Object ID. |
293 | 293 | * @param array $args Optional arguments array. |
294 | 294 | */ |
295 | -function cmb2_print_metabox_form( $meta_box, $object_id = 0, $args = array() ) { |
|
295 | +function cmb2_print_metabox_form($meta_box, $object_id = 0, $args = array()) { |
|
296 | 296 | |
297 | 297 | $object_id = $object_id ? $object_id : get_the_ID(); |
298 | - $cmb = cmb2_get_metabox( $meta_box, $object_id ); |
|
298 | + $cmb = cmb2_get_metabox($meta_box, $object_id); |
|
299 | 299 | |
300 | 300 | // if passing a metabox ID, and that ID was not found. |
301 | - if ( ! $cmb ) { |
|
301 | + if ( ! $cmb) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
305 | - $args = wp_parse_args( $args, array( |
|
305 | + $args = wp_parse_args($args, array( |
|
306 | 306 | 'form_format' => '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<input type="submit" name="submit-cmb" value="%4$s" class="button-primary"></form>', |
307 | - 'save_button' => esc_html__( 'Save', 'cmb2' ), |
|
307 | + 'save_button' => esc_html__('Save', 'cmb2'), |
|
308 | 308 | 'object_type' => $cmb->mb_object_type(), |
309 | - 'cmb_styles' => $cmb->prop( 'cmb_styles' ), |
|
310 | - 'enqueue_js' => $cmb->prop( 'enqueue_js' ), |
|
311 | - ) ); |
|
309 | + 'cmb_styles' => $cmb->prop('cmb_styles'), |
|
310 | + 'enqueue_js' => $cmb->prop('enqueue_js'), |
|
311 | + )); |
|
312 | 312 | |
313 | 313 | // Set object type explicitly (rather than trying to guess from context). |
314 | - $cmb->object_type( $args['object_type'] ); |
|
314 | + $cmb->object_type($args['object_type']); |
|
315 | 315 | |
316 | 316 | // Save the metabox if it's been submitted |
317 | 317 | // check permissions |
318 | 318 | // @todo more hardening? |
319 | 319 | if ( |
320 | - $cmb->prop( 'save_fields' ) |
|
320 | + $cmb->prop('save_fields') |
|
321 | 321 | // check nonce. |
322 | - && isset( $_POST['submit-cmb'], $_POST['object_id'], $_POST[ $cmb->nonce() ] ) |
|
323 | - && wp_verify_nonce( $_POST[ $cmb->nonce() ], $cmb->nonce() ) |
|
322 | + && isset($_POST['submit-cmb'], $_POST['object_id'], $_POST[$cmb->nonce()]) |
|
323 | + && wp_verify_nonce($_POST[$cmb->nonce()], $cmb->nonce()) |
|
324 | 324 | && $object_id && $_POST['object_id'] == $object_id |
325 | 325 | ) { |
326 | - $cmb->save_fields( $object_id, $cmb->object_type(), $_POST ); |
|
326 | + $cmb->save_fields($object_id, $cmb->object_type(), $_POST); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Enqueue JS/CSS. |
330 | - if ( $args['cmb_styles'] ) { |
|
330 | + if ($args['cmb_styles']) { |
|
331 | 331 | CMB2_Hookup::enqueue_cmb_css(); |
332 | 332 | } |
333 | 333 | |
334 | - if ( $args['enqueue_js'] ) { |
|
334 | + if ($args['enqueue_js']) { |
|
335 | 335 | CMB2_Hookup::enqueue_cmb_js(); |
336 | 336 | } |
337 | 337 | |
338 | - $form_format = apply_filters( 'cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb ); |
|
338 | + $form_format = apply_filters('cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb); |
|
339 | 339 | |
340 | - $format_parts = explode( '%3$s', $form_format ); |
|
340 | + $format_parts = explode('%3$s', $form_format); |
|
341 | 341 | |
342 | 342 | // Show cmb form. |
343 | - printf( $format_parts[0], esc_attr( $cmb->cmb_id ), esc_attr( $object_id ) ); |
|
343 | + printf($format_parts[0], esc_attr($cmb->cmb_id), esc_attr($object_id)); |
|
344 | 344 | $cmb->show_form(); |
345 | 345 | |
346 | - if ( isset( $format_parts[1] ) && $format_parts[1] ) { |
|
347 | - printf( str_ireplace( '%4$s', '%1$s', $format_parts[1] ), esc_attr( $args['save_button'] ) ); |
|
346 | + if (isset($format_parts[1]) && $format_parts[1]) { |
|
347 | + printf(str_ireplace('%4$s', '%1$s', $format_parts[1]), esc_attr($args['save_button'])); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | } |
@@ -358,15 +358,15 @@ discard block |
||
358 | 358 | * @param array $args Optional arguments array. |
359 | 359 | * @return string |
360 | 360 | */ |
361 | -function cmb2_metabox_form( $meta_box, $object_id = 0, $args = array() ) { |
|
362 | - if ( ! isset( $args['echo'] ) || $args['echo'] ) { |
|
363 | - cmb2_print_metabox_form( $meta_box, $object_id, $args ); |
|
361 | +function cmb2_metabox_form($meta_box, $object_id = 0, $args = array()) { |
|
362 | + if ( ! isset($args['echo']) || $args['echo']) { |
|
363 | + cmb2_print_metabox_form($meta_box, $object_id, $args); |
|
364 | 364 | } else { |
365 | - return cmb2_get_metabox_form( $meta_box, $object_id, $args ); |
|
365 | + return cmb2_get_metabox_form($meta_box, $object_id, $args); |
|
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | -if ( ! function_exists( 'date_create_from_format' ) ) { |
|
369 | +if ( ! function_exists('date_create_from_format')) { |
|
370 | 370 | |
371 | 371 | /** |
372 | 372 | * Reimplementation of DateTime::createFromFormat for PHP < 5.3. :( |
@@ -377,11 +377,11 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @return DateTime |
379 | 379 | */ |
380 | - function date_create_from_format( $date_format, $date_value ) { |
|
380 | + function date_create_from_format($date_format, $date_value) { |
|
381 | 381 | |
382 | 382 | $schedule_format = str_replace( |
383 | - array( 'M', 'Y', 'm', 'd', 'H', 'i', 'a' ), |
|
384 | - array( '%b', '%Y', '%m', '%d', '%H', '%M', '%p' ), |
|
383 | + array('M', 'Y', 'm', 'd', 'H', 'i', 'a'), |
|
384 | + array('%b', '%Y', '%m', '%d', '%H', '%M', '%p'), |
|
385 | 385 | $date_format |
386 | 386 | ); |
387 | 387 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * %Y, %m and %d correspond to date()'s Y m and d. |
390 | 390 | * %I corresponds to H, %M to i and %p to a |
391 | 391 | */ |
392 | - $parsed_time = strptime( $date_value, $schedule_format ); |
|
392 | + $parsed_time = strptime($date_value, $schedule_format); |
|
393 | 393 | |
394 | 394 | $ymd = sprintf( |
395 | 395 | /** |
@@ -398,19 +398,19 @@ discard block |
||
398 | 398 | * 4 or 2 characters, as needed |
399 | 399 | */ |
400 | 400 | '%04d-%02d-%02d %02d:%02d:%02d', |
401 | - $parsed_time['tm_year'] + 1900, // This will be "111", so we need to add 1900. |
|
402 | - $parsed_time['tm_mon'] + 1, // This will be the month minus one, so we add one. |
|
401 | + $parsed_time['tm_year'] + 1900, // This will be "111", so we need to add 1900. |
|
402 | + $parsed_time['tm_mon'] + 1, // This will be the month minus one, so we add one. |
|
403 | 403 | $parsed_time['tm_mday'], |
404 | 404 | $parsed_time['tm_hour'], |
405 | 405 | $parsed_time['tm_min'], |
406 | 406 | $parsed_time['tm_sec'] |
407 | 407 | ); |
408 | 408 | |
409 | - return new DateTime( $ymd ); |
|
409 | + return new DateTime($ymd); |
|
410 | 410 | } |
411 | 411 | }// End if. |
412 | 412 | |
413 | -if ( ! function_exists( 'date_timestamp_get' ) ) { |
|
413 | +if ( ! function_exists('date_timestamp_get')) { |
|
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Returns the Unix timestamp representing the date. |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @return int |
422 | 422 | */ |
423 | - function date_timestamp_get( DateTime $date ) { |
|
424 | - return $date->format( 'U' ); |
|
423 | + function date_timestamp_get(DateTime $date) { |
|
424 | + return $date->format('U'); |
|
425 | 425 | } |
426 | 426 | }// End if. |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param CMB2 $cmb_instance CMB2 instance. |
28 | 28 | */ |
29 | - public static function add( CMB2 $cmb_instance ) { |
|
30 | - self::$cmb2_instances[ $cmb_instance->cmb_id ] = $cmb_instance; |
|
29 | + public static function add(CMB2 $cmb_instance) { |
|
30 | + self::$cmb2_instances[$cmb_instance->cmb_id] = $cmb_instance; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param string $cmb_id A CMB2 instance id. |
39 | 39 | */ |
40 | - public static function remove( $cmb_id ) { |
|
41 | - if ( array_key_exists( $cmb_id, self::$cmb2_instances ) ) { |
|
42 | - unset( self::$cmb2_instances[ $cmb_id ] ); |
|
40 | + public static function remove($cmb_id) { |
|
41 | + if (array_key_exists($cmb_id, self::$cmb2_instances)) { |
|
42 | + unset(self::$cmb2_instances[$cmb_id]); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return CMB2|bool False or CMB2 object instance. |
54 | 54 | */ |
55 | - public static function get( $cmb_id ) { |
|
56 | - if ( empty( self::$cmb2_instances ) || empty( self::$cmb2_instances[ $cmb_id ] ) ) { |
|
55 | + public static function get($cmb_id) { |
|
56 | + if (empty(self::$cmb2_instances) || empty(self::$cmb2_instances[$cmb_id])) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - return self::$cmb2_instances[ $cmb_id ]; |
|
60 | + return self::$cmb2_instances[$cmb_id]; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -78,21 +78,21 @@ discard block |
||
78 | 78 | * @param mixed $compare (Optional) The value to compare. |
79 | 79 | * @return CMB2[] Array of matching cmb2 instances. |
80 | 80 | */ |
81 | - public static function get_by( $property, $compare = 'nocompare' ) { |
|
81 | + public static function get_by($property, $compare = 'nocompare') { |
|
82 | 82 | $boxes = array(); |
83 | 83 | |
84 | - foreach ( self::$cmb2_instances as $cmb_id => $cmb ) { |
|
85 | - $prop = $cmb->prop( $property ); |
|
84 | + foreach (self::$cmb2_instances as $cmb_id => $cmb) { |
|
85 | + $prop = $cmb->prop($property); |
|
86 | 86 | |
87 | - if ( 'nocompare' === $compare ) { |
|
88 | - if ( ! empty( $prop ) ) { |
|
89 | - $boxes[ $cmb_id ] = $cmb; |
|
87 | + if ('nocompare' === $compare) { |
|
88 | + if ( ! empty($prop)) { |
|
89 | + $boxes[$cmb_id] = $cmb; |
|
90 | 90 | } |
91 | 91 | continue; |
92 | 92 | } |
93 | 93 | |
94 | - if ( $compare === $prop ) { |
|
95 | - $boxes[ $cmb_id ] = $cmb; |
|
94 | + if ($compare === $prop) { |
|
95 | + $boxes[$cmb_id] = $cmb; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -107,16 +107,16 @@ discard block |
||
107 | 107 | * @param mixed $to_ignore The value to ignore. |
108 | 108 | * @return CMB2[] Array of matching cmb2 instances. |
109 | 109 | */ |
110 | - public static function filter_by( $property, $to_ignore = null ) { |
|
110 | + public static function filter_by($property, $to_ignore = null) { |
|
111 | 111 | $boxes = array(); |
112 | 112 | |
113 | - foreach ( self::$cmb2_instances as $cmb_id => $cmb ) { |
|
113 | + foreach (self::$cmb2_instances as $cmb_id => $cmb) { |
|
114 | 114 | |
115 | - if ( $to_ignore === $cmb->prop( $property ) ) { |
|
115 | + if ($to_ignore === $cmb->prop($property)) { |
|
116 | 116 | continue; |
117 | 117 | } |
118 | 118 | |
119 | - $boxes[ $cmb_id ] = $cmb; |
|
119 | + $boxes[$cmb_id] = $cmb; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return $boxes; |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param mixed $to_ignore The value to ignore. |
133 | 133 | * @return CMB2[] Array of matching cmb2 instances. |
134 | 134 | */ |
135 | - public static function get_by_property( $property, $to_ignore = null ) { |
|
136 | - _deprecated_function( __METHOD__, '2.4.0', 'CMB2_Boxes::filter_by()' ); |
|
137 | - return self::filter_by( $property ); |
|
135 | + public static function get_by_property($property, $to_ignore = null) { |
|
136 | + _deprecated_function(__METHOD__, '2.4.0', 'CMB2_Boxes::filter_by()'); |
|
137 | + return self::filter_by($property); |
|
138 | 138 | } |
139 | 139 | } |