@@ -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 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function register_routes() { |
| 24 | 24 | /* translators: %s: register_routes() */ |
| 25 | - _doing_it_wrong( 'WP_REST_Controller::register_routes', sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), '4.7' ); |
|
| 25 | + _doing_it_wrong('WP_REST_Controller::register_routes', sprintf(__("Method '%s' must be overridden."), __METHOD__), '4.7'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | * @param WP_REST_Request $request Full data about the request. |
| 32 | 32 | * @return WP_Error|boolean |
| 33 | 33 | */ |
| 34 | - public function get_items_permissions_check( $request ) { |
|
| 35 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 34 | + public function get_items_permissions_check($request) { |
|
| 35 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 36 | 36 | 'status' => 405, |
| 37 | - ) ); |
|
| 37 | + )); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @param WP_REST_Request $request Full data about the request. |
| 44 | 44 | * @return WP_Error|WP_REST_Response |
| 45 | 45 | */ |
| 46 | - public function get_items( $request ) { |
|
| 47 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 46 | + public function get_items($request) { |
|
| 47 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 48 | 48 | 'status' => 405, |
| 49 | - ) ); |
|
| 49 | + )); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | * @param WP_REST_Request $request Full data about the request. |
| 56 | 56 | * @return WP_Error|boolean |
| 57 | 57 | */ |
| 58 | - public function get_item_permissions_check( $request ) { |
|
| 59 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 58 | + public function get_item_permissions_check($request) { |
|
| 59 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 60 | 60 | 'status' => 405, |
| 61 | - ) ); |
|
| 61 | + )); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @param WP_REST_Request $request Full data about the request. |
| 68 | 68 | * @return WP_Error|WP_REST_Response |
| 69 | 69 | */ |
| 70 | - public function get_item( $request ) { |
|
| 71 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 70 | + public function get_item($request) { |
|
| 71 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 72 | 72 | 'status' => 405, |
| 73 | - ) ); |
|
| 73 | + )); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | * @param WP_REST_Request $request Full data about the request. |
| 80 | 80 | * @return WP_Error|boolean |
| 81 | 81 | */ |
| 82 | - public function create_item_permissions_check( $request ) { |
|
| 83 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 82 | + public function create_item_permissions_check($request) { |
|
| 83 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 84 | 84 | 'status' => 405, |
| 85 | - ) ); |
|
| 85 | + )); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | * @param WP_REST_Request $request Full data about the request. |
| 92 | 92 | * @return WP_Error|WP_REST_Response |
| 93 | 93 | */ |
| 94 | - public function create_item( $request ) { |
|
| 95 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 94 | + public function create_item($request) { |
|
| 95 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 96 | 96 | 'status' => 405, |
| 97 | - ) ); |
|
| 97 | + )); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -103,10 +103,10 @@ discard block |
||
| 103 | 103 | * @param WP_REST_Request $request Full data about the request. |
| 104 | 104 | * @return WP_Error|boolean |
| 105 | 105 | */ |
| 106 | - public function update_item_permissions_check( $request ) { |
|
| 107 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 106 | + public function update_item_permissions_check($request) { |
|
| 107 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 108 | 108 | 'status' => 405, |
| 109 | - ) ); |
|
| 109 | + )); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * @param WP_REST_Request $request Full data about the request. |
| 116 | 116 | * @return WP_Error|WP_REST_Response |
| 117 | 117 | */ |
| 118 | - public function update_item( $request ) { |
|
| 119 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 118 | + public function update_item($request) { |
|
| 119 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 120 | 120 | 'status' => 405, |
| 121 | - ) ); |
|
| 121 | + )); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | * @param WP_REST_Request $request Full data about the request. |
| 128 | 128 | * @return WP_Error|boolean |
| 129 | 129 | */ |
| 130 | - public function delete_item_permissions_check( $request ) { |
|
| 131 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 130 | + public function delete_item_permissions_check($request) { |
|
| 131 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 132 | 132 | 'status' => 405, |
| 133 | - ) ); |
|
| 133 | + )); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * @param WP_REST_Request $request Full data about the request. |
| 140 | 140 | * @return WP_Error|WP_REST_Response |
| 141 | 141 | */ |
| 142 | - public function delete_item( $request ) { |
|
| 143 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 142 | + public function delete_item($request) { |
|
| 143 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 144 | 144 | 'status' => 405, |
| 145 | - ) ); |
|
| 145 | + )); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | * @param WP_REST_Request $request Request object. |
| 152 | 152 | * @return WP_Error|object $prepared_item |
| 153 | 153 | */ |
| 154 | - protected function prepare_item_for_database( $request ) { |
|
| 155 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 154 | + protected function prepare_item_for_database($request) { |
|
| 155 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 156 | 156 | 'status' => 405, |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @param WP_REST_Request $request Request object. |
| 165 | 165 | * @return WP_REST_Response $response |
| 166 | 166 | */ |
| 167 | - public function prepare_item_for_response( $item, $request ) { |
|
| 168 | - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( |
|
| 167 | + public function prepare_item_for_response($item, $request) { |
|
| 168 | + return new WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass."), __METHOD__), array( |
|
| 169 | 169 | 'status' => 405, |
| 170 | - ) ); |
|
| 170 | + )); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * @param WP_REST_Response $response Response object. |
| 177 | 177 | * @return array Response data, ready for insertion into collection data. |
| 178 | 178 | */ |
| 179 | - public function prepare_response_for_collection( $response ) { |
|
| 180 | - if ( ! ( $response instanceof WP_REST_Response ) ) { |
|
| 179 | + public function prepare_response_for_collection($response) { |
|
| 180 | + if ( ! ($response instanceof WP_REST_Response)) { |
|
| 181 | 181 | return $response; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $data = (array) $response->get_data(); |
| 185 | 185 | $server = rest_get_server(); |
| 186 | 186 | |
| 187 | - if ( method_exists( $server, 'get_compact_response_links' ) ) { |
|
| 188 | - $links = call_user_func( array( $server, 'get_compact_response_links' ), $response ); |
|
| 187 | + if (method_exists($server, 'get_compact_response_links')) { |
|
| 188 | + $links = call_user_func(array($server, 'get_compact_response_links'), $response); |
|
| 189 | 189 | } else { |
| 190 | - $links = call_user_func( array( $server, 'get_response_links' ), $response ); |
|
| 190 | + $links = call_user_func(array($server, 'get_response_links'), $response); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if ( ! empty( $links ) ) { |
|
| 193 | + if ( ! empty($links)) { |
|
| 194 | 194 | $data['_links'] = $links; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -204,27 +204,27 @@ discard block |
||
| 204 | 204 | * @param string $context |
| 205 | 205 | * @return array |
| 206 | 206 | */ |
| 207 | - public function filter_response_by_context( $data, $context ) { |
|
| 207 | + public function filter_response_by_context($data, $context) { |
|
| 208 | 208 | |
| 209 | 209 | $schema = $this->get_item_schema(); |
| 210 | - foreach ( $data as $key => $value ) { |
|
| 211 | - if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) { |
|
| 210 | + foreach ($data as $key => $value) { |
|
| 211 | + if (empty($schema['properties'][$key]) || empty($schema['properties'][$key]['context'])) { |
|
| 212 | 212 | continue; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( ! in_array( $context, $schema['properties'][ $key ]['context'] ) ) { |
|
| 216 | - unset( $data[ $key ] ); |
|
| 215 | + if ( ! in_array($context, $schema['properties'][$key]['context'])) { |
|
| 216 | + unset($data[$key]); |
|
| 217 | 217 | continue; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) { |
|
| 221 | - foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) { |
|
| 222 | - if ( empty( $details['context'] ) ) { |
|
| 220 | + if ('object' === $schema['properties'][$key]['type'] && ! empty($schema['properties'][$key]['properties'])) { |
|
| 221 | + foreach ($schema['properties'][$key]['properties'] as $attribute => $details) { |
|
| 222 | + if (empty($details['context'])) { |
|
| 223 | 223 | continue; |
| 224 | 224 | } |
| 225 | - if ( ! in_array( $context, $details['context'] ) ) { |
|
| 226 | - if ( isset( $data[ $key ][ $attribute ] ) ) { |
|
| 227 | - unset( $data[ $key ][ $attribute ] ); |
|
| 225 | + if ( ! in_array($context, $details['context'])) { |
|
| 226 | + if (isset($data[$key][$attribute])) { |
|
| 227 | + unset($data[$key][$attribute]); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @return array |
| 241 | 241 | */ |
| 242 | 242 | public function get_item_schema() { |
| 243 | - return $this->add_additional_fields_schema( array() ); |
|
| 243 | + return $this->add_additional_fields_schema(array()); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | $schema = $this->get_item_schema(); |
| 254 | 254 | |
| 255 | - foreach ( $schema['properties'] as &$property ) { |
|
| 256 | - if ( isset( $property['arg_options'] ) ) { |
|
| 257 | - unset( $property['arg_options'] ); |
|
| 255 | + foreach ($schema['properties'] as &$property) { |
|
| 256 | + if (isset($property['arg_options'])) { |
|
| 257 | + unset($property['arg_options']); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | return array( |
| 271 | 271 | 'context' => $this->get_context_param(), |
| 272 | 272 | 'page' => array( |
| 273 | - 'description' => __( 'Current page of the collection.' ), |
|
| 273 | + 'description' => __('Current page of the collection.'), |
|
| 274 | 274 | 'type' => 'integer', |
| 275 | 275 | 'default' => 1, |
| 276 | 276 | 'sanitize_callback' => 'absint', |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | 'minimum' => 1, |
| 279 | 279 | ), |
| 280 | 280 | 'per_page' => array( |
| 281 | - 'description' => __( 'Maximum number of items to be returned in result set.' ), |
|
| 281 | + 'description' => __('Maximum number of items to be returned in result set.'), |
|
| 282 | 282 | 'type' => 'integer', |
| 283 | 283 | 'default' => 10, |
| 284 | 284 | 'minimum' => 1, |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | 'validate_callback' => 'rest_validate_request_arg', |
| 288 | 288 | ), |
| 289 | 289 | 'search' => array( |
| 290 | - 'description' => __( 'Limit results to those matching a string.' ), |
|
| 290 | + 'description' => __('Limit results to those matching a string.'), |
|
| 291 | 291 | 'type' => 'string', |
| 292 | 292 | 'sanitize_callback' => 'sanitize_text_field', |
| 293 | 293 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -303,28 +303,28 @@ discard block |
||
| 303 | 303 | * @param array $args |
| 304 | 304 | * @return array |
| 305 | 305 | */ |
| 306 | - public function get_context_param( $args = array() ) { |
|
| 306 | + public function get_context_param($args = array()) { |
|
| 307 | 307 | $param_details = array( |
| 308 | - 'description' => __( 'Scope under which the request is made; determines fields present in response.' ), |
|
| 308 | + 'description' => __('Scope under which the request is made; determines fields present in response.'), |
|
| 309 | 309 | 'type' => 'string', |
| 310 | 310 | 'sanitize_callback' => 'sanitize_key', |
| 311 | 311 | 'validate_callback' => 'rest_validate_request_arg', |
| 312 | 312 | ); |
| 313 | 313 | $schema = $this->get_item_schema(); |
| 314 | - if ( empty( $schema['properties'] ) ) { |
|
| 315 | - return array_merge( $param_details, $args ); |
|
| 314 | + if (empty($schema['properties'])) { |
|
| 315 | + return array_merge($param_details, $args); |
|
| 316 | 316 | } |
| 317 | 317 | $contexts = array(); |
| 318 | - foreach ( $schema['properties'] as $attributes ) { |
|
| 319 | - if ( ! empty( $attributes['context'] ) ) { |
|
| 320 | - $contexts = array_merge( $contexts, $attributes['context'] ); |
|
| 318 | + foreach ($schema['properties'] as $attributes) { |
|
| 319 | + if ( ! empty($attributes['context'])) { |
|
| 320 | + $contexts = array_merge($contexts, $attributes['context']); |
|
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | - if ( ! empty( $contexts ) ) { |
|
| 324 | - $param_details['enum'] = array_unique( $contexts ); |
|
| 325 | - rsort( $param_details['enum'] ); |
|
| 323 | + if ( ! empty($contexts)) { |
|
| 324 | + $param_details['enum'] = array_unique($contexts); |
|
| 325 | + rsort($param_details['enum']); |
|
| 326 | 326 | } |
| 327 | - return array_merge( $param_details, $args ); |
|
| 327 | + return array_merge($param_details, $args); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -334,17 +334,17 @@ discard block |
||
| 334 | 334 | * @param WP_REST_Request $request |
| 335 | 335 | * @return array modified object with additional fields. |
| 336 | 336 | */ |
| 337 | - protected function add_additional_fields_to_object( $object, $request ) { |
|
| 337 | + protected function add_additional_fields_to_object($object, $request) { |
|
| 338 | 338 | |
| 339 | 339 | $additional_fields = $this->get_additional_fields(); |
| 340 | 340 | |
| 341 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
| 341 | + foreach ($additional_fields as $field_name => $field_options) { |
|
| 342 | 342 | |
| 343 | - if ( ! $field_options['get_callback'] ) { |
|
| 343 | + if ( ! $field_options['get_callback']) { |
|
| 344 | 344 | continue; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() ); |
|
| 347 | + $object[$field_name] = call_user_func($field_options['get_callback'], $object, $field_name, $request, $this->get_object_type()); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | return $object; |
@@ -356,22 +356,22 @@ discard block |
||
| 356 | 356 | * @param array $object |
| 357 | 357 | * @param WP_REST_Request $request |
| 358 | 358 | */ |
| 359 | - protected function update_additional_fields_for_object( $object, $request ) { |
|
| 359 | + protected function update_additional_fields_for_object($object, $request) { |
|
| 360 | 360 | |
| 361 | 361 | $additional_fields = $this->get_additional_fields(); |
| 362 | 362 | |
| 363 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
| 363 | + foreach ($additional_fields as $field_name => $field_options) { |
|
| 364 | 364 | |
| 365 | - if ( ! $field_options['update_callback'] ) { |
|
| 365 | + if ( ! $field_options['update_callback']) { |
|
| 366 | 366 | continue; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // Don't run the update callbacks if the data wasn't passed in the request. |
| 370 | - if ( ! isset( $request[ $field_name ] ) ) { |
|
| 370 | + if ( ! isset($request[$field_name])) { |
|
| 371 | 371 | continue; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() ); |
|
| 374 | + call_user_func($field_options['update_callback'], $request[$field_name], $object, $field_name, $request, $this->get_object_type()); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -382,8 +382,8 @@ discard block |
||
| 382 | 382 | * |
| 383 | 383 | * @param array $schema Schema array. |
| 384 | 384 | */ |
| 385 | - protected function add_additional_fields_schema( $schema ) { |
|
| 386 | - if ( empty( $schema['title'] ) ) { |
|
| 385 | + protected function add_additional_fields_schema($schema) { |
|
| 386 | + if (empty($schema['title'])) { |
|
| 387 | 387 | return $schema; |
| 388 | 388 | } |
| 389 | 389 | |
@@ -392,14 +392,14 @@ discard block |
||
| 392 | 392 | */ |
| 393 | 393 | $object_type = $schema['title']; |
| 394 | 394 | |
| 395 | - $additional_fields = $this->get_additional_fields( $object_type ); |
|
| 395 | + $additional_fields = $this->get_additional_fields($object_type); |
|
| 396 | 396 | |
| 397 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
| 398 | - if ( ! $field_options['schema'] ) { |
|
| 397 | + foreach ($additional_fields as $field_name => $field_options) { |
|
| 398 | + if ( ! $field_options['schema']) { |
|
| 399 | 399 | continue; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - $schema['properties'][ $field_name ] = $field_options['schema']; |
|
| 402 | + $schema['properties'][$field_name] = $field_options['schema']; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | return $schema; |
@@ -411,23 +411,23 @@ discard block |
||
| 411 | 411 | * @param string $object_type |
| 412 | 412 | * @return array |
| 413 | 413 | */ |
| 414 | - protected function get_additional_fields( $object_type = null ) { |
|
| 414 | + protected function get_additional_fields($object_type = null) { |
|
| 415 | 415 | |
| 416 | - if ( ! $object_type ) { |
|
| 416 | + if ( ! $object_type) { |
|
| 417 | 417 | $object_type = $this->get_object_type(); |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - if ( ! $object_type ) { |
|
| 420 | + if ( ! $object_type) { |
|
| 421 | 421 | return array(); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | global $wp_rest_additional_fields; |
| 425 | 425 | |
| 426 | - if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) { |
|
| 426 | + if ( ! $wp_rest_additional_fields || ! isset($wp_rest_additional_fields[$object_type])) { |
|
| 427 | 427 | return array(); |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - return $wp_rest_additional_fields[ $object_type ]; |
|
| 430 | + return $wp_rest_additional_fields[$object_type]; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | protected function get_object_type() { |
| 439 | 439 | $schema = $this->get_item_schema(); |
| 440 | 440 | |
| 441 | - if ( ! $schema || ! isset( $schema['title'] ) ) { |
|
| 441 | + if ( ! $schema || ! isset($schema['title'])) { |
|
| 442 | 442 | return null; |
| 443 | 443 | } |
| 444 | 444 | |
@@ -455,54 +455,54 @@ discard block |
||
| 455 | 455 | * WP_REST_Server::CREATABLE. |
| 456 | 456 | * @return array $endpoint_args |
| 457 | 457 | */ |
| 458 | - public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { |
|
| 458 | + public function get_endpoint_args_for_item_schema($method = WP_REST_Server::CREATABLE) { |
|
| 459 | 459 | |
| 460 | 460 | $schema = $this->get_item_schema(); |
| 461 | - $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); |
|
| 461 | + $schema_properties = ! empty($schema['properties']) ? $schema['properties'] : array(); |
|
| 462 | 462 | $endpoint_args = array(); |
| 463 | 463 | |
| 464 | - foreach ( $schema_properties as $field_id => $params ) { |
|
| 464 | + foreach ($schema_properties as $field_id => $params) { |
|
| 465 | 465 | |
| 466 | 466 | // Arguments specified as `readonly` are not allowed to be set. |
| 467 | - if ( ! empty( $params['readonly'] ) ) { |
|
| 467 | + if ( ! empty($params['readonly'])) { |
|
| 468 | 468 | continue; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - $endpoint_args[ $field_id ] = array( |
|
| 471 | + $endpoint_args[$field_id] = array( |
|
| 472 | 472 | 'validate_callback' => 'rest_validate_request_arg', |
| 473 | 473 | 'sanitize_callback' => 'rest_sanitize_request_arg', |
| 474 | 474 | ); |
| 475 | 475 | |
| 476 | - if ( isset( $params['description'] ) ) { |
|
| 477 | - $endpoint_args[ $field_id ]['description'] = $params['description']; |
|
| 476 | + if (isset($params['description'])) { |
|
| 477 | + $endpoint_args[$field_id]['description'] = $params['description']; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) { |
|
| 481 | - $endpoint_args[ $field_id ]['default'] = $params['default']; |
|
| 480 | + if (WP_REST_Server::CREATABLE === $method && isset($params['default'])) { |
|
| 481 | + $endpoint_args[$field_id]['default'] = $params['default']; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) { |
|
| 485 | - $endpoint_args[ $field_id ]['required'] = true; |
|
| 484 | + if (WP_REST_Server::CREATABLE === $method && ! empty($params['required'])) { |
|
| 485 | + $endpoint_args[$field_id]['required'] = true; |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - foreach ( array( 'type', 'format', 'enum' ) as $schema_prop ) { |
|
| 489 | - if ( isset( $params[ $schema_prop ] ) ) { |
|
| 490 | - $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; |
|
| 488 | + foreach (array('type', 'format', 'enum') as $schema_prop) { |
|
| 489 | + if (isset($params[$schema_prop])) { |
|
| 490 | + $endpoint_args[$field_id][$schema_prop] = $params[$schema_prop]; |
|
| 491 | 491 | } |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | // Merge in any options provided by the schema property. |
| 495 | - if ( isset( $params['arg_options'] ) ) { |
|
| 495 | + if (isset($params['arg_options'])) { |
|
| 496 | 496 | |
| 497 | 497 | // Only use required / default from arg_options on CREATABLE endpoints. |
| 498 | - if ( WP_REST_Server::CREATABLE !== $method ) { |
|
| 499 | - $params['arg_options'] = array_diff_key( $params['arg_options'], array( |
|
| 498 | + if (WP_REST_Server::CREATABLE !== $method) { |
|
| 499 | + $params['arg_options'] = array_diff_key($params['arg_options'], array( |
|
| 500 | 500 | 'required' => '', |
| 501 | 501 | 'default' => '', |
| 502 | - ) ); |
|
| 502 | + )); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - $endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] ); |
|
| 505 | + $endpoint_args[$field_id] = array_merge($endpoint_args[$field_id], $params['arg_options']); |
|
| 506 | 506 | } |
| 507 | 507 | }// End foreach(). |
| 508 | 508 | |
@@ -523,8 +523,8 @@ discard block |
||
| 523 | 523 | * @param int|WP_Post $post Post ID or post object. Defaults to global $post. |
| 524 | 524 | * @return WP_Post|null A `WP_Post` object when successful. |
| 525 | 525 | */ |
| 526 | - public function get_post( $post ) { |
|
| 527 | - $post_obj = get_post( $post ); |
|
| 526 | + public function get_post($post) { |
|
| 527 | + $post_obj = get_post($post); |
|
| 528 | 528 | |
| 529 | 529 | /** |
| 530 | 530 | * Filter the post. |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | * @param WP_Post|null $post_obj The post object as returned by `get_post()`. |
| 535 | 535 | * @param int|WP_Post $post The original value used to obtain the post object. |
| 536 | 536 | */ |
| 537 | - $post = apply_filters( 'rest_the_post', $post_obj, $post ); |
|
| 537 | + $post = apply_filters('rest_the_post', $post_obj, $post); |
|
| 538 | 538 | |
| 539 | 539 | return $post; |
| 540 | 540 | } |
@@ -26,15 +26,15 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return mixed show_on key or false |
| 28 | 28 | */ |
| 29 | - private static function get_show_on_key( $meta_box_args ) { |
|
| 30 | - $show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false; |
|
| 31 | - if ( $show_on && is_array( $show_on ) ) { |
|
| 29 | + private static function get_show_on_key($meta_box_args) { |
|
| 30 | + $show_on = isset($meta_box_args['show_on']) ? (array) $meta_box_args['show_on'] : false; |
|
| 31 | + if ($show_on && is_array($show_on)) { |
|
| 32 | 32 | |
| 33 | - if ( array_key_exists( 'key', $show_on ) ) { |
|
| 33 | + if (array_key_exists('key', $show_on)) { |
|
| 34 | 34 | return $show_on['key']; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $keys = array_keys( $show_on ); |
|
| 37 | + $keys = array_keys($show_on); |
|
| 38 | 38 | return $keys[0]; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return mixed show_on value or false |
| 52 | 52 | */ |
| 53 | - private static function get_show_on_value( $meta_box_args ) { |
|
| 54 | - $show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false; |
|
| 53 | + private static function get_show_on_value($meta_box_args) { |
|
| 54 | + $show_on = isset($meta_box_args['show_on']) ? (array) $meta_box_args['show_on'] : false; |
|
| 55 | 55 | |
| 56 | - if ( $show_on && is_array( $show_on ) ) { |
|
| 56 | + if ($show_on && is_array($show_on)) { |
|
| 57 | 57 | |
| 58 | - if ( array_key_exists( 'value', $show_on ) ) { |
|
| 58 | + if (array_key_exists('value', $show_on)) { |
|
| 59 | 59 | return $show_on['value']; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $keys = array_keys( $show_on ); |
|
| 62 | + $keys = array_keys($show_on); |
|
| 63 | 63 | |
| 64 | - return $show_on[ $keys[0] ]; |
|
| 64 | + return $show_on[$keys[0]]; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return array(); |
@@ -76,21 +76,21 @@ discard block |
||
| 76 | 76 | * @param CMB2 $cmb The CMB2 instance. |
| 77 | 77 | * @return bool Whether to display this metabox on the current page. |
| 78 | 78 | */ |
| 79 | - public static function check_id( $display, $meta_box_args, $cmb ) { |
|
| 79 | + public static function check_id($display, $meta_box_args, $cmb) { |
|
| 80 | 80 | |
| 81 | - $key = self::get_show_on_key( $meta_box_args ); |
|
| 82 | - if ( ! $key || 'id' !== $key ) { |
|
| 81 | + $key = self::get_show_on_key($meta_box_args); |
|
| 82 | + if ( ! $key || 'id' !== $key) { |
|
| 83 | 83 | return $display; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $object_id = is_admin() ? $cmb->object_id() : get_the_ID(); |
| 87 | 87 | |
| 88 | - if ( ! $object_id ) { |
|
| 88 | + if ( ! $object_id) { |
|
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // If current page id is in the included array, display the metabox. |
| 93 | - return in_array( $object_id, (array) self::get_show_on_value( $meta_box_args ) ); |
|
| 93 | + return in_array($object_id, (array) self::get_show_on_value($meta_box_args)); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -102,24 +102,24 @@ discard block |
||
| 102 | 102 | * @param CMB2 $cmb CMB2 object. |
| 103 | 103 | * @return bool Whether to display this metabox on the current page. |
| 104 | 104 | */ |
| 105 | - public static function check_page_template( $display, $meta_box_args, $cmb ) { |
|
| 105 | + public static function check_page_template($display, $meta_box_args, $cmb) { |
|
| 106 | 106 | |
| 107 | - $key = self::get_show_on_key( $meta_box_args ); |
|
| 108 | - if ( ! $key || 'page-template' !== $key ) { |
|
| 107 | + $key = self::get_show_on_key($meta_box_args); |
|
| 108 | + if ( ! $key || 'page-template' !== $key) { |
|
| 109 | 109 | return $display; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $object_id = $cmb->object_id(); |
| 113 | 113 | |
| 114 | - if ( ! $object_id || 'post' !== $cmb->object_type() ) { |
|
| 114 | + if ( ! $object_id || 'post' !== $cmb->object_type()) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Get current template. |
| 119 | - $current_template = get_post_meta( $object_id, '_wp_page_template', true ); |
|
| 119 | + $current_template = get_post_meta($object_id, '_wp_page_template', true); |
|
| 120 | 120 | |
| 121 | 121 | // See if there's a match. |
| 122 | - if ( $current_template && in_array( $current_template, (array) self::get_show_on_value( $meta_box_args ) ) ) { |
|
| 122 | + if ($current_template && in_array($current_template, (array) self::get_show_on_value($meta_box_args))) { |
|
| 123 | 123 | return true; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -134,36 +134,36 @@ discard block |
||
| 134 | 134 | * @param array $meta_box_args Metabox config array. |
| 135 | 135 | * @return bool Whether to display this metabox on the current page. |
| 136 | 136 | */ |
| 137 | - public static function check_admin_page( $display, $meta_box_args ) { |
|
| 137 | + public static function check_admin_page($display, $meta_box_args) { |
|
| 138 | 138 | |
| 139 | - $key = self::get_show_on_key( $meta_box_args ); |
|
| 139 | + $key = self::get_show_on_key($meta_box_args); |
|
| 140 | 140 | // check if this is a 'options-page' metabox. |
| 141 | - if ( ! $key || 'options-page' !== $key ) { |
|
| 141 | + if ( ! $key || 'options-page' !== $key) { |
|
| 142 | 142 | return $display; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // Enforce 'show_on' filter in the admin. |
| 146 | - if ( is_admin() ) { |
|
| 146 | + if (is_admin()) { |
|
| 147 | 147 | |
| 148 | 148 | // If there is no 'page' query var, our filter isn't applicable. |
| 149 | - if ( ! isset( $_GET['page'] ) ) { |
|
| 149 | + if ( ! isset($_GET['page'])) { |
|
| 150 | 150 | return $display; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $show_on = self::get_show_on_value( $meta_box_args ); |
|
| 153 | + $show_on = self::get_show_on_value($meta_box_args); |
|
| 154 | 154 | |
| 155 | - if ( empty( $show_on ) ) { |
|
| 155 | + if (empty($show_on)) { |
|
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if ( is_array( $show_on ) ) { |
|
| 160 | - foreach ( $show_on as $page ) { |
|
| 161 | - if ( $_GET['page'] == $page ) { |
|
| 159 | + if (is_array($show_on)) { |
|
| 160 | + foreach ($show_on as $page) { |
|
| 161 | + if ($_GET['page'] == $page) { |
|
| 162 | 162 | return true; |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } else { |
| 166 | - if ( $_GET['page'] == $show_on ) { |
|
| 166 | + if ($_GET['page'] == $show_on) { |
|
| 167 | 167 | return true; |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | * @param CMB2_Field $field Requested field type. |
| 36 | 36 | * @return CMB2_Field_Display |
| 37 | 37 | */ |
| 38 | - public static function get( CMB2_Field $field ) { |
|
| 38 | + public static function get(CMB2_Field $field) { |
|
| 39 | 39 | $fieldtype = $field->type(); |
| 40 | - $display_class_name = $field->args( 'display_class' ); |
|
| 40 | + $display_class_name = $field->args('display_class'); |
|
| 41 | 41 | |
| 42 | - if ( empty( $display_class_name ) ) { |
|
| 43 | - switch ( $fieldtype ) { |
|
| 42 | + if (empty($display_class_name)) { |
|
| 43 | + switch ($fieldtype) { |
|
| 44 | 44 | case 'text_url': |
| 45 | 45 | $display_class_name = 'CMB2_Display_Text_Url'; |
| 46 | 46 | break; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | }// End switch. |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ( has_action( "cmb2_display_class_{$fieldtype}" ) ) { |
|
| 110 | + if (has_action("cmb2_display_class_{$fieldtype}")) { |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Filters the custom field display class used for displaying the field. Class is required to extend CMB2_Type_Base. |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * @param string $display_class_name The custom field display class to use. |
| 120 | 120 | * @param object $field The `CMB2_Field` object. |
| 121 | 121 | */ |
| 122 | - $display_class_name = apply_filters( "cmb2_display_class_{$fieldtype}", $display_class_name, $field ); |
|
| 122 | + $display_class_name = apply_filters("cmb2_display_class_{$fieldtype}", $display_class_name, $field); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return new $display_class_name( $field ); |
|
| 125 | + return new $display_class_name($field); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @since 2.2.2 |
| 132 | 132 | * @param CMB2_Field $field A CMB2 field object. |
| 133 | 133 | */ |
| 134 | - public function __construct( CMB2_Field $field ) { |
|
| 134 | + public function __construct(CMB2_Field $field) { |
|
| 135 | 135 | $this->field = $field; |
| 136 | 136 | $this->value = $this->field->value; |
| 137 | 137 | } |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function display() { |
| 146 | 146 | // If repeatable. |
| 147 | - if ( $this->field->args( 'repeatable' ) ) { |
|
| 147 | + if ($this->field->args('repeatable')) { |
|
| 148 | 148 | |
| 149 | 149 | // And has a repeatable value. |
| 150 | - if ( is_array( $this->field->value ) ) { |
|
| 150 | + if (is_array($this->field->value)) { |
|
| 151 | 151 | |
| 152 | 152 | // Then loop and output. |
| 153 | - echo '<ul class="cmb2-' . esc_attr( sanitize_html_class( str_replace( '_', '-', $this->field->type() ) ) ) . '">'; |
|
| 154 | - foreach ( $this->field->value as $val ) { |
|
| 153 | + echo '<ul class="cmb2-' . esc_attr(sanitize_html_class(str_replace('_', '-', $this->field->type()))) . '">'; |
|
| 154 | + foreach ($this->field->value as $val) { |
|
| 155 | 155 | $this->value = $val; |
| 156 | 156 | echo '<li>', $this->_display(), '</li>'; |
| 157 | 157 | ; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @since 2.2.2 |
| 170 | 170 | */ |
| 171 | 171 | protected function _display() { |
| 172 | - print_r( $this->value ); |
|
| 172 | + print_r($this->value); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * @since 2.2.2 |
| 181 | 181 | */ |
| 182 | 182 | protected function _display() { |
| 183 | - echo make_clickable( esc_url( $this->value ) ); |
|
| 183 | + echo make_clickable(esc_url($this->value)); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | protected function _display() { |
| 194 | 194 | $this->value = $this->value ? $this->value : '0'; |
| 195 | - echo ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$' : ' ' ), $this->value; |
|
| 195 | + echo ( ! $this->field->get_param_callback_result('before_field') ? '$' : ' '), $this->value; |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @since 2.2.2 |
| 204 | 204 | */ |
| 205 | 205 | protected function _display() { |
| 206 | - echo '<span class="cmb2-colorpicker-swatch"><span style="background-color:', esc_attr( $this->value ), '"></span> ', esc_html( $this->value ), '</span>'; |
|
| 206 | + echo '<span class="cmb2-colorpicker-swatch"><span style="background-color:', esc_attr($this->value), '"></span> ', esc_html($this->value), '</span>'; |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | protected function _display() { |
| 228 | 228 | $options = $this->field->options(); |
| 229 | 229 | |
| 230 | - $fallback = $this->field->args( 'show_option_none' ); |
|
| 231 | - if ( ! $fallback && isset( $options[''] ) ) { |
|
| 230 | + $fallback = $this->field->args('show_option_none'); |
|
| 231 | + if ( ! $fallback && isset($options[''])) { |
|
| 232 | 232 | $fallback = $options['']; |
| 233 | 233 | } |
| 234 | - if ( ! $this->value && $fallback ) { |
|
| 234 | + if ( ! $this->value && $fallback) { |
|
| 235 | 235 | echo $fallback; |
| 236 | - } elseif ( isset( $options[ $this->value ] ) ) { |
|
| 237 | - echo $options[ $this->value ]; |
|
| 236 | + } elseif (isset($options[$this->value])) { |
|
| 237 | + echo $options[$this->value]; |
|
| 238 | 238 | } else { |
| 239 | - echo esc_attr( $this->value ); |
|
| 239 | + echo esc_attr($this->value); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -248,22 +248,22 @@ discard block |
||
| 248 | 248 | * @since 2.2.2 |
| 249 | 249 | */ |
| 250 | 250 | protected function _display() { |
| 251 | - if ( empty( $this->value ) || ! is_array( $this->value ) ) { |
|
| 251 | + if (empty($this->value) || ! is_array($this->value)) { |
|
| 252 | 252 | return; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $options = $this->field->options(); |
| 256 | 256 | |
| 257 | 257 | $output = array(); |
| 258 | - foreach ( $this->value as $val ) { |
|
| 259 | - if ( isset( $options[ $val ] ) ) { |
|
| 260 | - $output[] = $options[ $val ]; |
|
| 258 | + foreach ($this->value as $val) { |
|
| 259 | + if (isset($options[$val])) { |
|
| 260 | + $output[] = $options[$val]; |
|
| 261 | 261 | } else { |
| 262 | - $output[] = esc_attr( $val ); |
|
| 262 | + $output[] = esc_attr($val); |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - echo implode( ', ', $output ); |
|
| 266 | + echo implode(', ', $output); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @since 2.2.2 |
| 275 | 275 | */ |
| 276 | 276 | protected function _display() { |
| 277 | - echo wpautop( wp_kses_post( $this->value ) ); |
|
| 277 | + echo wpautop(wp_kses_post($this->value)); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @since 2.2.2 |
| 286 | 286 | */ |
| 287 | 287 | protected function _display() { |
| 288 | - echo '<xmp class="cmb2-code">' . print_r( $this->value, true ) . '</xmp>'; |
|
| 288 | + echo '<xmp class="cmb2-code">' . print_r($this->value, true) . '</xmp>'; |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * @since 2.2.2 |
| 297 | 297 | */ |
| 298 | 298 | protected function _display() { |
| 299 | - echo $this->field->get_timestamp_format( 'time_format', $this->value ); |
|
| 299 | + echo $this->field->get_timestamp_format('time_format', $this->value); |
|
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * @since 2.2.2 |
| 308 | 308 | */ |
| 309 | 309 | protected function _display() { |
| 310 | - echo $this->field->get_timestamp_format( 'date_format', $this->value ); |
|
| 310 | + echo $this->field->get_timestamp_format('date_format', $this->value); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
@@ -320,23 +320,23 @@ discard block |
||
| 320 | 320 | protected function _display() { |
| 321 | 321 | $field = $this->field; |
| 322 | 322 | |
| 323 | - if ( empty( $this->value ) ) { |
|
| 323 | + if (empty($this->value)) { |
|
| 324 | 324 | return; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - $datetime = maybe_unserialize( $this->value ); |
|
| 327 | + $datetime = maybe_unserialize($this->value); |
|
| 328 | 328 | $this->value = $tzstring = ''; |
| 329 | 329 | |
| 330 | - if ( $datetime && $datetime instanceof DateTime ) { |
|
| 330 | + if ($datetime && $datetime instanceof DateTime) { |
|
| 331 | 331 | $tz = $datetime->getTimezone(); |
| 332 | 332 | $tzstring = $tz->getName(); |
| 333 | - $this->value = $datetime->getTimestamp(); |
|
| 333 | + $this->value = $datetime->getTimestamp(); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $date = $this->field->get_timestamp_format( 'date_format', $this->value ); |
|
| 337 | - $time = $this->field->get_timestamp_format( 'time_format', $this->value ); |
|
| 336 | + $date = $this->field->get_timestamp_format('date_format', $this->value); |
|
| 337 | + $time = $this->field->get_timestamp_format('time_format', $this->value); |
|
| 338 | 338 | |
| 339 | - echo $date, ( $time ? ' ' . $time : '' ), ( $tzstring ? ', ' . $tzstring : '' ); |
|
| 339 | + echo $date, ($time ? ' ' . $time : ''), ($tzstring ? ', ' . $tzstring : ''); |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | |
@@ -347,21 +347,21 @@ discard block |
||
| 347 | 347 | * @since 2.2.2 |
| 348 | 348 | */ |
| 349 | 349 | protected function _display() { |
| 350 | - $taxonomy = $this->field->args( 'taxonomy' ); |
|
| 351 | - $types = new CMB2_Types( $this->field ); |
|
| 352 | - $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Radio' ); |
|
| 350 | + $taxonomy = $this->field->args('taxonomy'); |
|
| 351 | + $types = new CMB2_Types($this->field); |
|
| 352 | + $type = $types->get_new_render_type($this->field->type(), 'CMB2_Type_Taxonomy_Radio'); |
|
| 353 | 353 | $terms = $type->get_object_terms(); |
| 354 | 354 | $term = false; |
| 355 | 355 | |
| 356 | - if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) { |
|
| 357 | - $term = get_term_by( 'slug', $default, $taxonomy ); |
|
| 358 | - } elseif ( ! empty( $terms ) ) { |
|
| 359 | - $term = $terms[ key( $terms ) ]; |
|
| 356 | + if (is_wp_error($terms) || empty($terms) && ($default = $this->field->get_default())) { |
|
| 357 | + $term = get_term_by('slug', $default, $taxonomy); |
|
| 358 | + } elseif ( ! empty($terms)) { |
|
| 359 | + $term = $terms[key($terms)]; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( $term ) { |
|
| 363 | - $link = get_edit_term_link( $term->term_id, $taxonomy ); |
|
| 364 | - echo '<a href="', esc_url( $link ), '">', esc_html( $term->name ), '</a>'; |
|
| 362 | + if ($term) { |
|
| 363 | + $link = get_edit_term_link($term->term_id, $taxonomy); |
|
| 364 | + echo '<a href="', esc_url($link), '">', esc_html($term->name), '</a>'; |
|
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | } |
@@ -373,32 +373,32 @@ discard block |
||
| 373 | 373 | * @since 2.2.2 |
| 374 | 374 | */ |
| 375 | 375 | protected function _display() { |
| 376 | - $taxonomy = $this->field->args( 'taxonomy' ); |
|
| 377 | - $types = new CMB2_Types( $this->field ); |
|
| 378 | - $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Multicheck' ); |
|
| 376 | + $taxonomy = $this->field->args('taxonomy'); |
|
| 377 | + $types = new CMB2_Types($this->field); |
|
| 378 | + $type = $types->get_new_render_type($this->field->type(), 'CMB2_Type_Taxonomy_Multicheck'); |
|
| 379 | 379 | $terms = $type->get_object_terms(); |
| 380 | 380 | |
| 381 | - if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) { |
|
| 381 | + if (is_wp_error($terms) || empty($terms) && ($default = $this->field->get_default())) { |
|
| 382 | 382 | $terms = array(); |
| 383 | - if ( is_array( $default ) ) { |
|
| 384 | - foreach ( $default as $slug ) { |
|
| 385 | - $terms[] = get_term_by( 'slug', $slug, $taxonomy ); |
|
| 383 | + if (is_array($default)) { |
|
| 384 | + foreach ($default as $slug) { |
|
| 385 | + $terms[] = get_term_by('slug', $slug, $taxonomy); |
|
| 386 | 386 | } |
| 387 | 387 | } else { |
| 388 | - $terms[] = get_term_by( 'slug', $default, $taxonomy ); |
|
| 388 | + $terms[] = get_term_by('slug', $default, $taxonomy); |
|
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if ( is_array( $terms ) ) { |
|
| 392 | + if (is_array($terms)) { |
|
| 393 | 393 | |
| 394 | 394 | $links = array(); |
| 395 | - foreach ( $terms as $term ) { |
|
| 396 | - $link = get_edit_term_link( $term->term_id, $taxonomy ); |
|
| 397 | - $links[] = '<a href="' . esc_url( $link ) . '">' . esc_html( $term->name ) . '</a>'; |
|
| 395 | + foreach ($terms as $term) { |
|
| 396 | + $link = get_edit_term_link($term->term_id, $taxonomy); |
|
| 397 | + $links[] = '<a href="' . esc_url($link) . '">' . esc_html($term->name) . '</a>'; |
|
| 398 | 398 | } |
| 399 | 399 | // Then loop and output. |
| 400 | - echo '<div class="cmb2-taxonomy-terms-', esc_attr( sanitize_html_class( $taxonomy ) ), '">'; |
|
| 401 | - echo implode( ', ', $links ); |
|
| 400 | + echo '<div class="cmb2-taxonomy-terms-', esc_attr(sanitize_html_class($taxonomy)), '">'; |
|
| 401 | + echo implode(', ', $links); |
|
| 402 | 402 | echo '</div>'; |
| 403 | 403 | } |
| 404 | 404 | } |
@@ -411,48 +411,48 @@ discard block |
||
| 411 | 411 | * @since 2.2.2 |
| 412 | 412 | */ |
| 413 | 413 | protected function _display() { |
| 414 | - if ( empty( $this->value ) ) { |
|
| 414 | + if (empty($this->value)) { |
|
| 415 | 415 | return; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - $this->value = esc_url_raw( $this->value ); |
|
| 418 | + $this->value = esc_url_raw($this->value); |
|
| 419 | 419 | |
| 420 | - $types = new CMB2_Types( $this->field ); |
|
| 421 | - $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' ); |
|
| 420 | + $types = new CMB2_Types($this->field); |
|
| 421 | + $type = $types->get_new_render_type($this->field->type(), 'CMB2_Type_File_Base'); |
|
| 422 | 422 | |
| 423 | - $id = $this->field->get_field_clone( array( |
|
| 424 | - 'id' => $this->field->_id( '', false ) . '_id', |
|
| 425 | - ) )->escaped_value( 'absint' ); |
|
| 423 | + $id = $this->field->get_field_clone(array( |
|
| 424 | + 'id' => $this->field->_id('', false) . '_id', |
|
| 425 | + ))->escaped_value('absint'); |
|
| 426 | 426 | |
| 427 | - $this->file_output( $this->value, $id, $type ); |
|
| 427 | + $this->file_output($this->value, $id, $type); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - protected function file_output( $url_value, $id, CMB2_Type_File_Base $field_type ) { |
|
| 430 | + protected function file_output($url_value, $id, CMB2_Type_File_Base $field_type) { |
|
| 431 | 431 | // If there is no ID saved yet, try to get it from the url. |
| 432 | - if ( $url_value && ! $id ) { |
|
| 433 | - $id = CMB2_Utils::image_id_from_url( esc_url_raw( $url_value ) ); |
|
| 432 | + if ($url_value && ! $id) { |
|
| 433 | + $id = CMB2_Utils::image_id_from_url(esc_url_raw($url_value)); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - if ( $field_type->is_valid_img_ext( $url_value ) ) { |
|
| 437 | - $img_size = $this->field->args( 'preview_size' ); |
|
| 436 | + if ($field_type->is_valid_img_ext($url_value)) { |
|
| 437 | + $img_size = $this->field->args('preview_size'); |
|
| 438 | 438 | |
| 439 | - if ( $id ) { |
|
| 440 | - $image = wp_get_attachment_image( $id, $img_size, null, array( |
|
| 439 | + if ($id) { |
|
| 440 | + $image = wp_get_attachment_image($id, $img_size, null, array( |
|
| 441 | 441 | 'class' => 'cmb-image-display', |
| 442 | - ) ); |
|
| 442 | + )); |
|
| 443 | 443 | } else { |
| 444 | - $size = is_array( $img_size ) ? $img_size[0] : 200; |
|
| 445 | - $image = '<img class="cmb-image-display" style="max-width: ' . absint( $size ) . 'px; width: 100%; height: auto;" src="' . esc_url( $url_value ) . '" alt="" />'; |
|
| 444 | + $size = is_array($img_size) ? $img_size[0] : 200; |
|
| 445 | + $image = '<img class="cmb-image-display" style="max-width: ' . absint($size) . 'px; width: 100%; height: auto;" src="' . esc_url($url_value) . '" alt="" />'; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | echo $image; |
| 449 | 449 | |
| 450 | 450 | } else { |
| 451 | 451 | |
| 452 | - printf( '<div class="file-status"><span>%1$s <strong><a href="%2$s">%3$s</a></strong></span></div>', |
|
| 453 | - esc_html( $field_type->_text( 'file_text', __( 'File:', 'cmb2' ) ) ), |
|
| 454 | - esc_url( $url_value ), |
|
| 455 | - esc_html( CMB2_Utils::get_file_name_from_path( $url_value ) ) |
|
| 452 | + printf('<div class="file-status"><span>%1$s <strong><a href="%2$s">%3$s</a></strong></span></div>', |
|
| 453 | + esc_html($field_type->_text('file_text', __('File:', 'cmb2'))), |
|
| 454 | + esc_url($url_value), |
|
| 455 | + esc_html(CMB2_Utils::get_file_name_from_path($url_value)) |
|
| 456 | 456 | ); |
| 457 | 457 | |
| 458 | 458 | } |
@@ -466,16 +466,16 @@ discard block |
||
| 466 | 466 | * @since 2.2.2 |
| 467 | 467 | */ |
| 468 | 468 | protected function _display() { |
| 469 | - if ( empty( $this->value ) || ! is_array( $this->value ) ) { |
|
| 469 | + if (empty($this->value) || ! is_array($this->value)) { |
|
| 470 | 470 | return; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - $types = new CMB2_Types( $this->field ); |
|
| 474 | - $type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' ); |
|
| 473 | + $types = new CMB2_Types($this->field); |
|
| 474 | + $type = $types->get_new_render_type($this->field->type(), 'CMB2_Type_File_Base'); |
|
| 475 | 475 | |
| 476 | 476 | echo '<ul class="cmb2-display-file-list">'; |
| 477 | - foreach ( $this->value as $id => $fullurl ) { |
|
| 478 | - echo '<li>', $this->file_output( esc_url_raw( $fullurl ), $id, $type ), '</li>'; |
|
| 477 | + foreach ($this->value as $id => $fullurl) { |
|
| 478 | + echo '<li>', $this->file_output(esc_url_raw($fullurl), $id, $type), '</li>'; |
|
| 479 | 479 | } |
| 480 | 480 | echo '</ul>'; |
| 481 | 481 | } |
@@ -488,11 +488,11 @@ discard block |
||
| 488 | 488 | * @since 2.2.2 |
| 489 | 489 | */ |
| 490 | 490 | protected function _display() { |
| 491 | - if ( ! $this->value ) { |
|
| 491 | + if ( ! $this->value) { |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - cmb2_do_oembed( array( |
|
| 495 | + cmb2_do_oembed(array( |
|
| 496 | 496 | 'url' => $this->value, |
| 497 | 497 | 'object_id' => $this->field->object_id, |
| 498 | 498 | 'object_type' => $this->field->object_type, |
@@ -500,6 +500,6 @@ discard block |
||
| 500 | 500 | 'width' => '300', |
| 501 | 501 | ), |
| 502 | 502 | 'field_id' => $this->field->id(), |
| 503 | - ) ); |
|
| 503 | + )); |
|
| 504 | 504 | } |
| 505 | 505 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param CMB2_Field $field A CMB2 field object. |
| 36 | 36 | * @param mixed $value Field value. |
| 37 | 37 | */ |
| 38 | - public function __construct( CMB2_Field $field, $value ) { |
|
| 38 | + public function __construct(CMB2_Field $field, $value) { |
|
| 39 | 39 | $this->field = $field; |
| 40 | 40 | $this->value = $value; |
| 41 | 41 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param array $arguments All arguments passed to the method. |
| 51 | 51 | * @return mixed |
| 52 | 52 | */ |
| 53 | - public function __call( $name, $arguments ) { |
|
| 53 | + public function __call($name, $arguments) { |
|
| 54 | 54 | return $this->default_sanitization(); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -68,18 +68,18 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @deprecated See documentation for "cmb2_sanitize_{$field_type}". |
| 70 | 70 | */ |
| 71 | - if ( function_exists( 'apply_filters_deprecated' ) ) { |
|
| 72 | - $override_value = apply_filters_deprecated( "cmb2_validate_{$field_type}", array( null, $this->value, $this->field->object_id, $this->field->args(), $this ), '2.0.0', "cmb2_sanitize_{$field_type}" ); |
|
| 71 | + if (function_exists('apply_filters_deprecated')) { |
|
| 72 | + $override_value = apply_filters_deprecated("cmb2_validate_{$field_type}", array(null, $this->value, $this->field->object_id, $this->field->args(), $this), '2.0.0', "cmb2_sanitize_{$field_type}"); |
|
| 73 | 73 | } else { |
| 74 | - $override_value = apply_filters( "cmb2_validate_{$field_type}", null, $this->value, $this->field->object_id, $this->field->args(), $this ); |
|
| 74 | + $override_value = apply_filters("cmb2_validate_{$field_type}", null, $this->value, $this->field->object_id, $this->field->args(), $this); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( null !== $override_value ) { |
|
| 77 | + if (null !== $override_value) { |
|
| 78 | 78 | return $override_value; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $sanitized_value = ''; |
| 82 | - switch ( $field_type ) { |
|
| 82 | + switch ($field_type) { |
|
| 83 | 83 | case 'wysiwyg': |
| 84 | 84 | case 'textarea_small': |
| 85 | 85 | case 'oembed': |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | break; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return $this->_is_empty_array( $sanitized_value ) ? '' : $sanitized_value; |
|
| 112 | + return $this->_is_empty_array($sanitized_value) ? '' : $sanitized_value; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | protected function _default_sanitization() { |
| 122 | 122 | // Handle repeatable fields array. |
| 123 | - return is_array( $this->value ) ? array_map( 'sanitize_text_field', $this->value ) : sanitize_text_field( $this->value ); |
|
| 123 | + return is_array($this->value) ? array_map('sanitize_text_field', $this->value) : sanitize_text_field($this->value); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -132,14 +132,14 @@ discard block |
||
| 132 | 132 | public function taxonomy() { |
| 133 | 133 | $sanitized_value = ''; |
| 134 | 134 | |
| 135 | - if ( ! $this->field->args( 'taxonomy' ) ) { |
|
| 136 | - CMB2_Utils::log_if_debug( __METHOD__, __LINE__, "{$this->field->type()} {$this->field->_id( '', false )} is missing the 'taxonomy' parameter." ); |
|
| 135 | + if ( ! $this->field->args('taxonomy')) { |
|
| 136 | + CMB2_Utils::log_if_debug(__METHOD__, __LINE__, "{$this->field->type()} {$this->field->_id('', false)} is missing the 'taxonomy' parameter."); |
|
| 137 | 137 | } else { |
| 138 | 138 | |
| 139 | - if ( in_array( $this->field->object_type, array( 'options-page', 'term' ), true ) ) { |
|
| 139 | + if (in_array($this->field->object_type, array('options-page', 'term'), true)) { |
|
| 140 | 140 | $return_values = true; |
| 141 | 141 | } else { |
| 142 | - wp_set_object_terms( $this->field->object_id, $this->value, $this->field->args( 'taxonomy' ) ); |
|
| 142 | + wp_set_object_terms($this->field->object_id, $this->value, $this->field->args('taxonomy')); |
|
| 143 | 143 | $return_values = false; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * `add_filter( "cmb2_return_taxonomy_values_{$cmb_id}", '__return_true' );` |
| 160 | 160 | * @param CMB2_Sanitize $sanitizer This object. |
| 161 | 161 | */ |
| 162 | - if ( apply_filters( "cmb2_return_taxonomy_values_{$cmb_id}", $return_values, $this ) ) { |
|
| 162 | + if (apply_filters("cmb2_return_taxonomy_values_{$cmb_id}", $return_values, $this)) { |
|
| 163 | 163 | $sanitized_value = $this->_default_sanitization(); |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -184,14 +184,14 @@ discard block |
||
| 184 | 184 | * @return string Empty string or escaped url |
| 185 | 185 | */ |
| 186 | 186 | public function text_url() { |
| 187 | - $protocols = $this->field->args( 'protocols' ); |
|
| 187 | + $protocols = $this->field->args('protocols'); |
|
| 188 | 188 | // for repeatable. |
| 189 | - if ( is_array( $this->value ) ) { |
|
| 190 | - foreach ( $this->value as $key => $val ) { |
|
| 191 | - $this->value[ $key ] = $val ? esc_url_raw( $val, $protocols ) : $this->field->get_default(); |
|
| 189 | + if (is_array($this->value)) { |
|
| 190 | + foreach ($this->value as $key => $val) { |
|
| 191 | + $this->value[$key] = $val ? esc_url_raw($val, $protocols) : $this->field->get_default(); |
|
| 192 | 192 | } |
| 193 | 193 | } else { |
| 194 | - $this->value = $this->value ? esc_url_raw( $this->value, $protocols ) : $this->field->get_default(); |
|
| 194 | + $this->value = $this->value ? esc_url_raw($this->value, $protocols) : $this->field->get_default(); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $this->value; |
@@ -199,16 +199,16 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | public function colorpicker() { |
| 201 | 201 | // for repeatable. |
| 202 | - if ( is_array( $this->value ) ) { |
|
| 202 | + if (is_array($this->value)) { |
|
| 203 | 203 | $check = $this->value; |
| 204 | 204 | $this->value = array(); |
| 205 | - foreach ( $check as $key => $val ) { |
|
| 206 | - if ( $val && '#' != $val ) { |
|
| 207 | - $this->value[ $key ] = esc_attr( $val ); |
|
| 205 | + foreach ($check as $key => $val) { |
|
| 206 | + if ($val && '#' != $val) { |
|
| 207 | + $this->value[$key] = esc_attr($val); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | } else { |
| 211 | - $this->value = ! $this->value || '#' == $this->value ? '' : esc_attr( $this->value ); |
|
| 211 | + $this->value = ! $this->value || '#' == $this->value ? '' : esc_attr($this->value); |
|
| 212 | 212 | } |
| 213 | 213 | return $this->value; |
| 214 | 214 | } |
@@ -221,14 +221,14 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function text_email() { |
| 223 | 223 | // for repeatable. |
| 224 | - if ( is_array( $this->value ) ) { |
|
| 225 | - foreach ( $this->value as $key => $val ) { |
|
| 226 | - $val = trim( $val ); |
|
| 227 | - $this->value[ $key ] = is_email( $val ) ? $val : ''; |
|
| 224 | + if (is_array($this->value)) { |
|
| 225 | + foreach ($this->value as $key => $val) { |
|
| 226 | + $val = trim($val); |
|
| 227 | + $this->value[$key] = is_email($val) ? $val : ''; |
|
| 228 | 228 | } |
| 229 | 229 | } else { |
| 230 | - $this->value = trim( $this->value ); |
|
| 231 | - $this->value = is_email( $this->value ) ? $this->value : ''; |
|
| 230 | + $this->value = trim($this->value); |
|
| 231 | + $this->value = is_email($this->value) ? $this->value : ''; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return $this->value; |
@@ -241,28 +241,28 @@ discard block |
||
| 241 | 241 | * @return string Empty string or sanitized money value |
| 242 | 242 | */ |
| 243 | 243 | public function text_money() { |
| 244 | - if ( ! $this->value ) { |
|
| 244 | + if ( ! $this->value) { |
|
| 245 | 245 | return ''; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | global $wp_locale; |
| 249 | 249 | |
| 250 | - $search = array( $wp_locale->number_format['thousands_sep'], $wp_locale->number_format['decimal_point'] ); |
|
| 251 | - $replace = array( '', '.' ); |
|
| 250 | + $search = array($wp_locale->number_format['thousands_sep'], $wp_locale->number_format['decimal_point']); |
|
| 251 | + $replace = array('', '.'); |
|
| 252 | 252 | |
| 253 | 253 | // Strip slashes. Example: 2\'180.00. |
| 254 | 254 | // See https://github.com/CMB2/CMB2/issues/1014. |
| 255 | - $this->value = wp_unslash( $this->value ); |
|
| 255 | + $this->value = wp_unslash($this->value); |
|
| 256 | 256 | |
| 257 | 257 | // for repeatable. |
| 258 | - if ( is_array( $this->value ) ) { |
|
| 259 | - foreach ( $this->value as $key => $val ) { |
|
| 260 | - if ( $val ) { |
|
| 261 | - $this->value[ $key ] = number_format_i18n( (float) str_ireplace( $search, $replace, $val ), 2 ); |
|
| 258 | + if (is_array($this->value)) { |
|
| 259 | + foreach ($this->value as $key => $val) { |
|
| 260 | + if ($val) { |
|
| 261 | + $this->value[$key] = number_format_i18n((float) str_ireplace($search, $replace, $val), 2); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } else { |
| 265 | - $this->value = number_format_i18n( (float) str_ireplace( $search, $replace, $this->value ), 2 ); |
|
| 265 | + $this->value = number_format_i18n((float) str_ireplace($search, $replace, $this->value), 2); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | return $this->value; |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function text_date_timestamp() { |
| 278 | 278 | // date_create_from_format if there is a slash in the value. |
| 279 | - $this->value = wp_unslash( $this->value ); |
|
| 279 | + $this->value = wp_unslash($this->value); |
|
| 280 | 280 | |
| 281 | - return is_array( $this->value ) |
|
| 282 | - ? array_map( array( $this->field, 'get_timestamp_from_value' ), $this->value ) |
|
| 283 | - : $this->field->get_timestamp_from_value( $this->value ); |
|
| 281 | + return is_array($this->value) |
|
| 282 | + ? array_map(array($this->field, 'get_timestamp_from_value'), $this->value) |
|
| 283 | + : $this->field->get_timestamp_from_value($this->value); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -291,25 +291,25 @@ discard block |
||
| 291 | 291 | * @param bool $repeat Whether or not to repeat. |
| 292 | 292 | * @return string|array Timestring |
| 293 | 293 | */ |
| 294 | - public function text_datetime_timestamp( $repeat = false ) { |
|
| 294 | + public function text_datetime_timestamp($repeat = false) { |
|
| 295 | 295 | // date_create_from_format if there is a slash in the value. |
| 296 | - $this->value = wp_unslash( $this->value ); |
|
| 296 | + $this->value = wp_unslash($this->value); |
|
| 297 | 297 | |
| 298 | - $test = is_array( $this->value ) ? array_filter( $this->value ) : ''; |
|
| 299 | - if ( empty( $test ) ) { |
|
| 298 | + $test = is_array($this->value) ? array_filter($this->value) : ''; |
|
| 299 | + if (empty($test)) { |
|
| 300 | 300 | return ''; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $repeat_value = $this->_check_repeat( __FUNCTION__, $repeat ); |
|
| 304 | - if ( false !== $repeat_value ) { |
|
| 303 | + $repeat_value = $this->_check_repeat(__FUNCTION__, $repeat); |
|
| 304 | + if (false !== $repeat_value) { |
|
| 305 | 305 | return $repeat_value; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if ( isset( $this->value['date'], $this->value['time'] ) ) { |
|
| 309 | - $this->value = $this->field->get_timestamp_from_value( $this->value['date'] . ' ' . $this->value['time'] ); |
|
| 308 | + if (isset($this->value['date'], $this->value['time'])) { |
|
| 309 | + $this->value = $this->field->get_timestamp_from_value($this->value['date'] . ' ' . $this->value['time']); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if ( $tz_offset = $this->field->field_timezone_offset() ) { |
|
| 312 | + if ($tz_offset = $this->field->field_timezone_offset()) { |
|
| 313 | 313 | $this->value += (int) $tz_offset; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | * @param bool $repeat Whether or not to repeat. |
| 325 | 325 | * @return string Timestring |
| 326 | 326 | */ |
| 327 | - public function text_datetime_timestamp_timezone( $repeat = false ) { |
|
| 327 | + public function text_datetime_timestamp_timezone($repeat = false) { |
|
| 328 | 328 | static $utc_values = array(); |
| 329 | 329 | |
| 330 | - $test = is_array( $this->value ) ? array_filter( $this->value ) : ''; |
|
| 331 | - if ( empty( $test ) ) { |
|
| 330 | + $test = is_array($this->value) ? array_filter($this->value) : ''; |
|
| 331 | + if (empty($test)) { |
|
| 332 | 332 | return ''; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // date_create_from_format if there is a slash in the value. |
| 336 | - $this->value = wp_unslash( $this->value ); |
|
| 336 | + $this->value = wp_unslash($this->value); |
|
| 337 | 337 | |
| 338 | - $utc_key = $this->field->_id( '', false ) . '_utc'; |
|
| 338 | + $utc_key = $this->field->_id('', false) . '_utc'; |
|
| 339 | 339 | |
| 340 | - $repeat_value = $this->_check_repeat( __FUNCTION__, $repeat ); |
|
| 341 | - if ( false !== $repeat_value ) { |
|
| 342 | - if ( ! empty( $utc_values[ $utc_key ] ) ) { |
|
| 343 | - $this->_save_utc_value( $utc_key, $utc_values[ $utc_key ] ); |
|
| 344 | - unset( $utc_values[ $utc_key ] ); |
|
| 340 | + $repeat_value = $this->_check_repeat(__FUNCTION__, $repeat); |
|
| 341 | + if (false !== $repeat_value) { |
|
| 342 | + if ( ! empty($utc_values[$utc_key])) { |
|
| 343 | + $this->_save_utc_value($utc_key, $utc_values[$utc_key]); |
|
| 344 | + unset($utc_values[$utc_key]); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | return $repeat_value; |
@@ -349,25 +349,25 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | $tzstring = null; |
| 351 | 351 | |
| 352 | - if ( is_array( $this->value ) && array_key_exists( 'timezone', $this->value ) ) { |
|
| 352 | + if (is_array($this->value) && array_key_exists('timezone', $this->value)) { |
|
| 353 | 353 | $tzstring = $this->value['timezone']; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if ( empty( $tzstring ) ) { |
|
| 356 | + if (empty($tzstring)) { |
|
| 357 | 357 | $tzstring = CMB2_Utils::timezone_string(); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - $offset = CMB2_Utils::timezone_offset( $tzstring ); |
|
| 360 | + $offset = CMB2_Utils::timezone_offset($tzstring); |
|
| 361 | 361 | |
| 362 | - if ( 'UTC' === substr( $tzstring, 0, 3 ) ) { |
|
| 363 | - $tzstring = timezone_name_from_abbr( '', $offset, 0 ); |
|
| 362 | + if ('UTC' === substr($tzstring, 0, 3)) { |
|
| 363 | + $tzstring = timezone_name_from_abbr('', $offset, 0); |
|
| 364 | 364 | /** |
| 365 | 365 | * The timezone_name_from_abbr() returns false if not found based on offset. |
| 366 | 366 | * Since there are currently some invalid timezones in wp_timezone_dropdown(), |
| 367 | 367 | * fallback to an offset of 0 (UTC+0) |
| 368 | 368 | * https://core.trac.wordpress.org/ticket/29205 |
| 369 | 369 | */ |
| 370 | - $tzstring = false !== $tzstring ? $tzstring : timezone_name_from_abbr( '', 0, 0 ); |
|
| 370 | + $tzstring = false !== $tzstring ? $tzstring : timezone_name_from_abbr('', 0, 0); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $full_format = $this->field->args['date_format'] . ' ' . $this->field->args['time_format']; |
@@ -375,17 +375,17 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | try { |
| 377 | 377 | |
| 378 | - $datetime = date_create_from_format( $full_format, $full_date ); |
|
| 378 | + $datetime = date_create_from_format($full_format, $full_date); |
|
| 379 | 379 | |
| 380 | - if ( ! is_object( $datetime ) ) { |
|
| 380 | + if ( ! is_object($datetime)) { |
|
| 381 | 381 | $this->value = $utc_stamp = ''; |
| 382 | 382 | } else { |
| 383 | - $datetime->setTimezone( new DateTimeZone( $tzstring ) ); |
|
| 384 | - $utc_stamp = date_timestamp_get( $datetime ) - $offset; |
|
| 385 | - $this->value = serialize( $datetime ); |
|
| 383 | + $datetime->setTimezone(new DateTimeZone($tzstring)); |
|
| 384 | + $utc_stamp = date_timestamp_get($datetime) - $offset; |
|
| 385 | + $this->value = serialize($datetime); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if ( $this->field->group ) { |
|
| 388 | + if ($this->field->group) { |
|
| 389 | 389 | $this->value = array( |
| 390 | 390 | 'supporting_field_value' => $utc_stamp, |
| 391 | 391 | 'supporting_field_id' => $utc_key, |
@@ -393,15 +393,15 @@ discard block |
||
| 393 | 393 | ); |
| 394 | 394 | } else { |
| 395 | 395 | // Save the utc timestamp supporting field. |
| 396 | - if ( $repeat ) { |
|
| 397 | - $utc_values[ $utc_key ][] = $utc_stamp; |
|
| 396 | + if ($repeat) { |
|
| 397 | + $utc_values[$utc_key][] = $utc_stamp; |
|
| 398 | 398 | } else { |
| 399 | - $this->_save_utc_value( $utc_key, $utc_stamp ); |
|
| 399 | + $this->_save_utc_value($utc_key, $utc_stamp); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | - } catch ( Exception $e ) { |
|
| 402 | + } catch (Exception $e) { |
|
| 403 | 403 | $this->value = ''; |
| 404 | - CMB2_Utils::log_if_debug( __METHOD__, __LINE__, $e->getMessage() ); |
|
| 404 | + CMB2_Utils::log_if_debug(__METHOD__, __LINE__, $e->getMessage()); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | return $this->value; |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | * @return string Sanitized data |
| 415 | 415 | */ |
| 416 | 416 | public function textarea() { |
| 417 | - return is_array( $this->value ) ? array_map( 'wp_kses_post', $this->value ) : wp_kses_post( $this->value ); |
|
| 417 | + return is_array($this->value) ? array_map('wp_kses_post', $this->value) : wp_kses_post($this->value); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -425,13 +425,13 @@ discard block |
||
| 425 | 425 | * @param bool $repeat Whether or not to repeat. |
| 426 | 426 | * @return string Sanitized data |
| 427 | 427 | */ |
| 428 | - public function textarea_code( $repeat = false ) { |
|
| 429 | - $repeat_value = $this->_check_repeat( __FUNCTION__, $repeat ); |
|
| 430 | - if ( false !== $repeat_value ) { |
|
| 428 | + public function textarea_code($repeat = false) { |
|
| 429 | + $repeat_value = $this->_check_repeat(__FUNCTION__, $repeat); |
|
| 430 | + if (false !== $repeat_value) { |
|
| 431 | 431 | return $repeat_value; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - return htmlspecialchars_decode( stripslashes( $this->value ) ); |
|
| 434 | + return htmlspecialchars_decode(stripslashes($this->value)); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -441,13 +441,13 @@ discard block |
||
| 441 | 441 | * @return string Sanitized url |
| 442 | 442 | */ |
| 443 | 443 | public function file() { |
| 444 | - $file_id_key = $this->field->_id( '', false ) . '_id'; |
|
| 444 | + $file_id_key = $this->field->_id('', false) . '_id'; |
|
| 445 | 445 | |
| 446 | - if ( $this->field->group ) { |
|
| 446 | + if ($this->field->group) { |
|
| 447 | 447 | // Return an array with url/id if saving a group field. |
| 448 | - $this->value = $this->_get_group_file_value_array( $file_id_key ); |
|
| 448 | + $this->value = $this->_get_group_file_value_array($file_id_key); |
|
| 449 | 449 | } else { |
| 450 | - $this->_save_file_id_value( $file_id_key ); |
|
| 450 | + $this->_save_file_id_value($file_id_key); |
|
| 451 | 451 | $this->text_url(); |
| 452 | 452 | } |
| 453 | 453 | |
@@ -462,18 +462,18 @@ discard block |
||
| 462 | 462 | * @param mixed $id_key ID key to use. |
| 463 | 463 | * @return array |
| 464 | 464 | */ |
| 465 | - public function _get_group_file_value_array( $id_key ) { |
|
| 465 | + public function _get_group_file_value_array($id_key) { |
|
| 466 | 466 | $alldata = $this->field->group->data_to_save; |
| 467 | - $base_id = $this->field->group->_id( '', false ); |
|
| 467 | + $base_id = $this->field->group->_id('', false); |
|
| 468 | 468 | $i = $this->field->group->index; |
| 469 | 469 | |
| 470 | 470 | // Check group $alldata data. |
| 471 | - $id_val = isset( $alldata[ $base_id ][ $i ][ $id_key ] ) |
|
| 472 | - ? absint( $alldata[ $base_id ][ $i ][ $id_key ] ) |
|
| 471 | + $id_val = isset($alldata[$base_id][$i][$id_key]) |
|
| 472 | + ? absint($alldata[$base_id][$i][$id_key]) |
|
| 473 | 473 | : ''; |
| 474 | 474 | |
| 475 | 475 | // We don't want to save 0 to the DB for file fields. |
| 476 | - if ( 0 === $id_val ) { |
|
| 476 | + if (0 === $id_val) { |
|
| 477 | 477 | $id_val = ''; |
| 478 | 478 | } |
| 479 | 479 | |
@@ -492,24 +492,24 @@ discard block |
||
| 492 | 492 | * @param mixed $file_id_key ID key to use. |
| 493 | 493 | * @return mixed |
| 494 | 494 | */ |
| 495 | - public function _save_file_id_value( $file_id_key ) { |
|
| 496 | - $id_field = $this->_new_supporting_field( $file_id_key ); |
|
| 495 | + public function _save_file_id_value($file_id_key) { |
|
| 496 | + $id_field = $this->_new_supporting_field($file_id_key); |
|
| 497 | 497 | |
| 498 | 498 | // Check standard data_to_save data. |
| 499 | - $id_val = isset( $this->field->data_to_save[ $file_id_key ] ) |
|
| 500 | - ? $this->field->data_to_save[ $file_id_key ] |
|
| 499 | + $id_val = isset($this->field->data_to_save[$file_id_key]) |
|
| 500 | + ? $this->field->data_to_save[$file_id_key] |
|
| 501 | 501 | : null; |
| 502 | 502 | |
| 503 | 503 | // If there is no ID saved yet, try to get it from the url. |
| 504 | - if ( $this->value && ! $id_val ) { |
|
| 505 | - $id_val = CMB2_Utils::image_id_from_url( $this->value ); |
|
| 504 | + if ($this->value && ! $id_val) { |
|
| 505 | + $id_val = CMB2_Utils::image_id_from_url($this->value); |
|
| 506 | 506 | |
| 507 | 507 | // If there is an ID but user emptied the input value, remove the ID. |
| 508 | - } elseif ( ! $this->value && $id_val ) { |
|
| 508 | + } elseif ( ! $this->value && $id_val) { |
|
| 509 | 509 | $id_val = null; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - return $id_field->save_field( $id_val ); |
|
| 512 | + return $id_field->save_field($id_val); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -521,8 +521,8 @@ discard block |
||
| 521 | 521 | * @param mixed $utc_stamp UTC timestamp. |
| 522 | 522 | * @return mixed |
| 523 | 523 | */ |
| 524 | - public function _save_utc_value( $utc_key, $utc_stamp ) { |
|
| 525 | - return $this->_new_supporting_field( $utc_key )->save_field( $utc_stamp ); |
|
| 524 | + public function _save_utc_value($utc_key, $utc_stamp) { |
|
| 525 | + return $this->_new_supporting_field($utc_key)->save_field($utc_stamp); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -533,11 +533,11 @@ discard block |
||
| 533 | 533 | * @param mixed $new_field_id New field ID. |
| 534 | 534 | * @return CMB2_Field |
| 535 | 535 | */ |
| 536 | - public function _new_supporting_field( $new_field_id ) { |
|
| 537 | - return $this->field->get_field_clone( array( |
|
| 536 | + public function _new_supporting_field($new_field_id) { |
|
| 537 | + return $this->field->get_field_clone(array( |
|
| 538 | 538 | 'id' => $new_field_id, |
| 539 | 539 | 'sanitization_cb' => false, |
| 540 | - ) ); |
|
| 540 | + )); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -548,18 +548,18 @@ discard block |
||
| 548 | 548 | * @param bool $repeat Whether repeating or not. |
| 549 | 549 | * @return mixed Sanitized value |
| 550 | 550 | */ |
| 551 | - public function _check_repeat( $method, $repeat ) { |
|
| 552 | - if ( $repeat || ! $this->field->args( 'repeatable' ) ) { |
|
| 551 | + public function _check_repeat($method, $repeat) { |
|
| 552 | + if ($repeat || ! $this->field->args('repeatable')) { |
|
| 553 | 553 | return false; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | $values_array = $this->value; |
| 557 | 557 | |
| 558 | 558 | $new_value = array(); |
| 559 | - foreach ( $values_array as $iterator => $this->value ) { |
|
| 560 | - if ( $this->value ) { |
|
| 561 | - $val = $this->$method( true ); |
|
| 562 | - if ( ! empty( $val ) ) { |
|
| 559 | + foreach ($values_array as $iterator => $this->value) { |
|
| 560 | + if ($this->value) { |
|
| 561 | + $val = $this->$method(true); |
|
| 562 | + if ( ! empty($val)) { |
|
| 563 | 563 | $new_value[] = $val; |
| 564 | 564 | } |
| 565 | 565 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | |
| 568 | 568 | $this->value = $new_value; |
| 569 | 569 | |
| 570 | - return empty( $this->value ) ? null : $this->value; |
|
| 570 | + return empty($this->value) ? null : $this->value; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -577,10 +577,10 @@ discard block |
||
| 577 | 577 | * @param mixed $to_check Value to check. |
| 578 | 578 | * @return boolean Whether value is an array that's empty |
| 579 | 579 | */ |
| 580 | - public function _is_empty_array( $to_check ) { |
|
| 581 | - if ( is_array( $to_check ) ) { |
|
| 582 | - $cleaned_up = array_filter( $to_check ); |
|
| 583 | - return empty( $cleaned_up ); |
|
| 580 | + public function _is_empty_array($to_check) { |
|
| 581 | + if (is_array($to_check)) { |
|
| 582 | + $cleaned_up = array_filter($to_check); |
|
| 583 | + return empty($cleaned_up); |
|
| 584 | 584 | } |
| 585 | 585 | return false; |
| 586 | 586 | } |
@@ -129,25 +129,25 @@ discard block |
||
| 129 | 129 | * @since 1.1.0 |
| 130 | 130 | * @param array $args Field arguments. |
| 131 | 131 | */ |
| 132 | - public function __construct( $args ) { |
|
| 132 | + public function __construct($args) { |
|
| 133 | 133 | |
| 134 | - if ( ! empty( $args['group_field'] ) ) { |
|
| 134 | + if ( ! empty($args['group_field'])) { |
|
| 135 | 135 | $this->group = $args['group_field']; |
| 136 | 136 | $this->object_id = $this->group->object_id; |
| 137 | 137 | $this->object_type = $this->group->object_type; |
| 138 | 138 | $this->cmb_id = $this->group->cmb_id; |
| 139 | 139 | } else { |
| 140 | - $this->object_id = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
| 141 | - $this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post'; |
|
| 140 | + $this->object_id = isset($args['object_id']) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
| 141 | + $this->object_type = isset($args['object_type']) ? $args['object_type'] : 'post'; |
|
| 142 | 142 | |
| 143 | - if ( isset( $args['cmb_id'] ) ) { |
|
| 143 | + if (isset($args['cmb_id'])) { |
|
| 144 | 144 | $this->cmb_id = $args['cmb_id']; |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $this->args = $this->_set_field_defaults( $args['field_args'] ); |
|
| 148 | + $this->args = $this->_set_field_defaults($args['field_args']); |
|
| 149 | 149 | |
| 150 | - if ( $this->object_id ) { |
|
| 150 | + if ($this->object_id) { |
|
| 151 | 151 | $this->value = $this->get_data(); |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | * @param array $arguments Array of passed-in arguments. |
| 161 | 161 | * @return mixed Value of field argument |
| 162 | 162 | */ |
| 163 | - public function __call( $name, $arguments ) { |
|
| 164 | - if ( 'string' === $name ) { |
|
| 165 | - return call_user_func_array( array( $this, 'get_string' ), $arguments ); |
|
| 163 | + public function __call($name, $arguments) { |
|
| 164 | + if ('string' === $name) { |
|
| 165 | + return call_user_func_array(array($this, 'get_string'), $arguments); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $key = isset( $arguments[0] ) ? $arguments[0] : ''; |
|
| 169 | - return $this->args( $name, $key ); |
|
| 168 | + $key = isset($arguments[0]) ? $arguments[0] : ''; |
|
| 169 | + return $this->args($name, $key); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | * @param boolean $raw Whether to retrieve pre-modidifed id. |
| 177 | 177 | * @return string Field id |
| 178 | 178 | */ |
| 179 | - public function id( $raw = false ) { |
|
| 179 | + public function id($raw = false) { |
|
| 180 | 180 | $id = $raw ? '_id' : 'id'; |
| 181 | - return $this->args( $id ); |
|
| 181 | + return $this->args($id); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -189,16 +189,16 @@ discard block |
||
| 189 | 189 | * @param string $_key Sub argument to check. |
| 190 | 190 | * @return mixed Argument value or false if non-existent |
| 191 | 191 | */ |
| 192 | - public function args( $key = '', $_key = '' ) { |
|
| 193 | - $arg = $this->_data( 'args', $key ); |
|
| 192 | + public function args($key = '', $_key = '') { |
|
| 193 | + $arg = $this->_data('args', $key); |
|
| 194 | 194 | |
| 195 | - if ( in_array( $key, array( 'default', 'default_cb' ), true ) ) { |
|
| 195 | + if (in_array($key, array('default', 'default_cb'), true)) { |
|
| 196 | 196 | |
| 197 | 197 | $arg = $this->get_default(); |
| 198 | 198 | |
| 199 | - } elseif ( $_key ) { |
|
| 199 | + } elseif ($_key) { |
|
| 200 | 200 | |
| 201 | - $arg = isset( $arg[ $_key ] ) ? $arg[ $_key ] : false; |
|
| 201 | + $arg = isset($arg[$_key]) ? $arg[$_key] : false; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return $arg; |
@@ -212,10 +212,10 @@ discard block |
||
| 212 | 212 | * @param string $key Field property array key to check. |
| 213 | 213 | * @return mixed Queried property value or false |
| 214 | 214 | */ |
| 215 | - public function _data( $var, $key = '' ) { |
|
| 215 | + public function _data($var, $key = '') { |
|
| 216 | 216 | $vars = $this->{$var}; |
| 217 | - if ( $key ) { |
|
| 218 | - return array_key_exists( $key, $vars ) ? $vars[ $key ] : false; |
|
| 217 | + if ($key) { |
|
| 218 | + return array_key_exists($key, $vars) ? $vars[$key] : false; |
|
| 219 | 219 | } |
| 220 | 220 | return $vars; |
| 221 | 221 | } |
@@ -227,8 +227,8 @@ discard block |
||
| 227 | 227 | * @param string $key If value is an array, is used to get array key->value. |
| 228 | 228 | * @return mixed Field value or false if non-existent |
| 229 | 229 | */ |
| 230 | - public function value( $key = '' ) { |
|
| 231 | - return $this->_data( 'value', $key ); |
|
| 230 | + public function value($key = '') { |
|
| 231 | + return $this->_data('value', $key); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -239,14 +239,14 @@ discard block |
||
| 239 | 239 | * @param array $args Override arguments. |
| 240 | 240 | * @return mixed Meta/Option value |
| 241 | 241 | */ |
| 242 | - public function get_data( $field_id = '', $args = array() ) { |
|
| 243 | - if ( $field_id ) { |
|
| 242 | + public function get_data($field_id = '', $args = array()) { |
|
| 243 | + if ($field_id) { |
|
| 244 | 244 | $args['field_id'] = $field_id; |
| 245 | - } elseif ( $this->group ) { |
|
| 245 | + } elseif ($this->group) { |
|
| 246 | 246 | $args['field_id'] = $this->group->id(); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $a = $this->data_args( $args ); |
|
| 249 | + $a = $this->data_args($args); |
|
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | * Filter whether to override getting of meta value. |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @param CMB2_Field object $field This field object |
| 275 | 275 | */ |
| 276 | - $data = apply_filters( 'cmb2_override_meta_value', 'cmb2_field_no_override_val', $this->object_id, $a, $this ); |
|
| 276 | + $data = apply_filters('cmb2_override_meta_value', 'cmb2_field_no_override_val', $this->object_id, $a, $this); |
|
| 277 | 277 | |
| 278 | 278 | /** |
| 279 | 279 | * Filter and parameters are documented for 'cmb2_override_meta_value' filter (above). |
@@ -284,19 +284,19 @@ discard block |
||
| 284 | 284 | * |
| 285 | 285 | * @since 2.0.0 |
| 286 | 286 | */ |
| 287 | - $data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this ); |
|
| 287 | + $data = apply_filters("cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this); |
|
| 288 | 288 | |
| 289 | 289 | // If no override, get value normally. |
| 290 | - if ( 'cmb2_field_no_override_val' === $data ) { |
|
| 290 | + if ('cmb2_field_no_override_val' === $data) { |
|
| 291 | 291 | $data = 'options-page' === $a['type'] |
| 292 | - ? cmb2_options( $a['id'] )->get( $a['field_id'] ) |
|
| 293 | - : get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) ); |
|
| 292 | + ? cmb2_options($a['id'])->get($a['field_id']) |
|
| 293 | + : get_metadata($a['type'], $a['id'], $a['field_id'], ($a['single'] || $a['repeat'])); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( $this->group ) { |
|
| 296 | + if ($this->group) { |
|
| 297 | 297 | |
| 298 | - $data = is_array( $data ) && isset( $data[ $this->group->index ][ $this->args( '_id' ) ] ) |
|
| 299 | - ? $data[ $this->group->index ][ $this->args( '_id' ) ] |
|
| 298 | + $data = is_array($data) && isset($data[$this->group->index][$this->args('_id')]) |
|
| 299 | + ? $data[$this->group->index][$this->args('_id')] |
|
| 300 | 300 | : false; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -311,12 +311,12 @@ discard block |
||
| 311 | 311 | * @param bool $single Whether data is an array (add_metadata). |
| 312 | 312 | * @return mixed |
| 313 | 313 | */ |
| 314 | - public function update_data( $new_value, $single = true ) { |
|
| 315 | - $a = $this->data_args( array( |
|
| 314 | + public function update_data($new_value, $single = true) { |
|
| 315 | + $a = $this->data_args(array( |
|
| 316 | 316 | 'single' => $single, |
| 317 | - ) ); |
|
| 317 | + )); |
|
| 318 | 318 | |
| 319 | - $a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value; |
|
| 319 | + $a['value'] = $a['repeat'] ? array_values($new_value) : $new_value; |
|
| 320 | 320 | |
| 321 | 321 | /** |
| 322 | 322 | * Filter whether to override saving of meta value. |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * |
| 342 | 342 | * @param CMB2_Field object $field This field object |
| 343 | 343 | */ |
| 344 | - $override = apply_filters( 'cmb2_override_meta_save', null, $a, $this->args(), $this ); |
|
| 344 | + $override = apply_filters('cmb2_override_meta_save', null, $a, $this->args(), $this); |
|
| 345 | 345 | |
| 346 | 346 | /** |
| 347 | 347 | * Filter and parameters are documented for 'cmb2_override_meta_save' filter (above). |
@@ -352,30 +352,30 @@ discard block |
||
| 352 | 352 | * |
| 353 | 353 | * @since 2.0.0 |
| 354 | 354 | */ |
| 355 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this ); |
|
| 355 | + $override = apply_filters("cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this); |
|
| 356 | 356 | |
| 357 | 357 | // If override, return that. |
| 358 | - if ( null !== $override ) { |
|
| 358 | + if (null !== $override) { |
|
| 359 | 359 | return $override; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // Options page handling (or temp data store). |
| 363 | - if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
| 364 | - return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] ); |
|
| 363 | + if ('options-page' === $a['type'] || empty($a['id'])) { |
|
| 364 | + return cmb2_options($a['id'])->update($a['field_id'], $a['value'], false, $a['single']); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // Add metadata if not single. |
| 368 | - if ( ! $a['single'] ) { |
|
| 369 | - return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false ); |
|
| 368 | + if ( ! $a['single']) { |
|
| 369 | + return add_metadata($a['type'], $a['id'], $a['field_id'], $a['value'], false); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // Delete meta if we have an empty array. |
| 373 | - if ( is_array( $a['value'] ) && empty( $a['value'] ) ) { |
|
| 374 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value ); |
|
| 373 | + if (is_array($a['value']) && empty($a['value'])) { |
|
| 374 | + return delete_metadata($a['type'], $a['id'], $a['field_id'], $this->value); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Update metadata. |
| 378 | - return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] ); |
|
| 378 | + return update_metadata($a['type'], $a['id'], $a['field_id'], $a['value']); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -385,10 +385,10 @@ discard block |
||
| 385 | 385 | * @param string $old Old value. |
| 386 | 386 | * @return mixed |
| 387 | 387 | */ |
| 388 | - public function remove_data( $old = '' ) { |
|
| 389 | - $a = $this->data_args( array( |
|
| 388 | + public function remove_data($old = '') { |
|
| 389 | + $a = $this->data_args(array( |
|
| 390 | 390 | 'old' => $old, |
| 391 | - ) ); |
|
| 391 | + )); |
|
| 392 | 392 | |
| 393 | 393 | /** |
| 394 | 394 | * Filter whether to override removing of meta value. |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @param array $field_args All field arguments |
| 408 | 408 | * @param CMB2_Field object $field This field object |
| 409 | 409 | */ |
| 410 | - $override = apply_filters( 'cmb2_override_meta_remove', null, $a, $this->args(), $this ); |
|
| 410 | + $override = apply_filters('cmb2_override_meta_remove', null, $a, $this->args(), $this); |
|
| 411 | 411 | |
| 412 | 412 | /** |
| 413 | 413 | * Filter whether to override removing of meta value. |
@@ -429,19 +429,19 @@ discard block |
||
| 429 | 429 | * @param array $field_args All field arguments |
| 430 | 430 | * @param CMB2_Field object $field This field object |
| 431 | 431 | */ |
| 432 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this ); |
|
| 432 | + $override = apply_filters("cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this); |
|
| 433 | 433 | |
| 434 | 434 | // If no override, remove as usual. |
| 435 | - if ( null !== $override ) { |
|
| 435 | + if (null !== $override) { |
|
| 436 | 436 | return $override; |
| 437 | 437 | } // End if. |
| 438 | 438 | // Option page handling. |
| 439 | - elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
| 440 | - return cmb2_options( $a['id'] )->remove( $a['field_id'] ); |
|
| 439 | + elseif ('options-page' === $a['type'] || empty($a['id'])) { |
|
| 440 | + return cmb2_options($a['id'])->remove($a['field_id']); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | // Remove metadata. |
| 444 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old ); |
|
| 444 | + return delete_metadata($a['type'], $a['id'], $a['field_id'], $old); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -451,14 +451,14 @@ discard block |
||
| 451 | 451 | * @param array $args Override arguments. |
| 452 | 452 | * @return array Updated arguments |
| 453 | 453 | */ |
| 454 | - public function data_args( $args = array() ) { |
|
| 455 | - $args = wp_parse_args( $args, array( |
|
| 454 | + public function data_args($args = array()) { |
|
| 455 | + $args = wp_parse_args($args, array( |
|
| 456 | 456 | 'type' => $this->object_type, |
| 457 | 457 | 'id' => $this->object_id, |
| 458 | - 'field_id' => $this->id( true ), |
|
| 459 | - 'repeat' => $this->args( 'repeatable' ), |
|
| 460 | - 'single' => ! $this->args( 'multiple' ), |
|
| 461 | - ) ); |
|
| 458 | + 'field_id' => $this->id(true), |
|
| 459 | + 'repeat' => $this->args('repeatable'), |
|
| 460 | + 'single' => ! $this->args('multiple'), |
|
| 461 | + )); |
|
| 462 | 462 | return $args; |
| 463 | 463 | } |
| 464 | 464 | |
@@ -469,24 +469,24 @@ discard block |
||
| 469 | 469 | * @param mixed $meta_value Meta value. |
| 470 | 470 | * @return mixed Possibly sanitized meta value |
| 471 | 471 | */ |
| 472 | - public function sanitization_cb( $meta_value ) { |
|
| 472 | + public function sanitization_cb($meta_value) { |
|
| 473 | 473 | |
| 474 | - if ( $this->args( 'repeatable' ) && is_array( $meta_value ) ) { |
|
| 474 | + if ($this->args('repeatable') && is_array($meta_value)) { |
|
| 475 | 475 | // Remove empties. |
| 476 | - $meta_value = array_filter( $meta_value ); |
|
| 476 | + $meta_value = array_filter($meta_value); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // Check if the field has a registered validation callback. |
| 480 | - $cb = $this->maybe_callback( 'sanitization_cb' ); |
|
| 481 | - if ( false === $cb ) { |
|
| 480 | + $cb = $this->maybe_callback('sanitization_cb'); |
|
| 481 | + if (false === $cb) { |
|
| 482 | 482 | // If requesting NO validation, return meta value. |
| 483 | 483 | return $meta_value; |
| 484 | - } elseif ( $cb ) { |
|
| 484 | + } elseif ($cb) { |
|
| 485 | 485 | // Ok, callback is good, let's run it. |
| 486 | - return call_user_func( $cb, $meta_value, $this->args(), $this ); |
|
| 486 | + return call_user_func($cb, $meta_value, $this->args(), $this); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $sanitizer = new CMB2_Sanitize( $this, $meta_value ); |
|
| 489 | + $sanitizer = new CMB2_Sanitize($this, $meta_value); |
|
| 490 | 490 | $field_type = $this->type(); |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -504,9 +504,9 @@ discard block |
||
| 504 | 504 | * @param array $field_args The current field's arguments |
| 505 | 505 | * @param object $sanitizer This `CMB2_Sanitize` object |
| 506 | 506 | */ |
| 507 | - $override_value = apply_filters( "cmb2_sanitize_{$field_type}", null, $sanitizer->value, $this->object_id, $this->args(), $sanitizer ); |
|
| 507 | + $override_value = apply_filters("cmb2_sanitize_{$field_type}", null, $sanitizer->value, $this->object_id, $this->args(), $sanitizer); |
|
| 508 | 508 | |
| 509 | - if ( null !== $override_value ) { |
|
| 509 | + if (null !== $override_value) { |
|
| 510 | 510 | return $override_value; |
| 511 | 511 | } |
| 512 | 512 | |
@@ -521,14 +521,14 @@ discard block |
||
| 521 | 521 | * @param array $data_to_save $_POST data to check. |
| 522 | 522 | * @return array|int|bool Result of save, false on failure |
| 523 | 523 | */ |
| 524 | - public function save_field_from_data( array $data_to_save ) { |
|
| 524 | + public function save_field_from_data(array $data_to_save) { |
|
| 525 | 525 | $this->data_to_save = $data_to_save; |
| 526 | 526 | |
| 527 | - $meta_value = isset( $this->data_to_save[ $this->id( true ) ] ) |
|
| 528 | - ? $this->data_to_save[ $this->id( true ) ] |
|
| 527 | + $meta_value = isset($this->data_to_save[$this->id(true)]) |
|
| 528 | + ? $this->data_to_save[$this->id(true)] |
|
| 529 | 529 | : null; |
| 530 | 530 | |
| 531 | - return $this->save_field( $meta_value ); |
|
| 531 | + return $this->save_field($meta_value); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -538,25 +538,25 @@ discard block |
||
| 538 | 538 | * @param array $meta_value Desired value to sanitize/store. |
| 539 | 539 | * @return array|int|bool Result of save. false on failure |
| 540 | 540 | */ |
| 541 | - public function save_field( $meta_value ) { |
|
| 541 | + public function save_field($meta_value) { |
|
| 542 | 542 | |
| 543 | 543 | $updated = false; |
| 544 | 544 | $action = ''; |
| 545 | - $new_value = $this->sanitization_cb( $meta_value ); |
|
| 545 | + $new_value = $this->sanitization_cb($meta_value); |
|
| 546 | 546 | |
| 547 | - if ( ! $this->args( 'save_field' ) ) { |
|
| 547 | + if ( ! $this->args('save_field')) { |
|
| 548 | 548 | |
| 549 | 549 | // Nothing to see here. |
| 550 | 550 | $action = 'disabled'; |
| 551 | 551 | |
| 552 | - } elseif ( $this->args( 'multiple' ) && ! $this->args( 'repeatable' ) && ! $this->group ) { |
|
| 552 | + } elseif ($this->args('multiple') && ! $this->args('repeatable') && ! $this->group) { |
|
| 553 | 553 | |
| 554 | 554 | $this->remove_data(); |
| 555 | 555 | $count = 0; |
| 556 | 556 | |
| 557 | - if ( ! empty( $new_value ) ) { |
|
| 558 | - foreach ( $new_value as $add_new ) { |
|
| 559 | - if ( $this->update_data( $add_new, false ) ) { |
|
| 557 | + if ( ! empty($new_value)) { |
|
| 558 | + foreach ($new_value as $add_new) { |
|
| 559 | + if ($this->update_data($add_new, false)) { |
|
| 560 | 560 | $count++; |
| 561 | 561 | } |
| 562 | 562 | } |
@@ -565,20 +565,20 @@ discard block |
||
| 565 | 565 | $updated = $count ? $count : false; |
| 566 | 566 | $action = 'repeatable'; |
| 567 | 567 | |
| 568 | - } elseif ( ! CMB2_Utils::isempty( $new_value ) && $new_value !== $this->get_data() ) { |
|
| 569 | - $updated = $this->update_data( $new_value ); |
|
| 568 | + } elseif ( ! CMB2_Utils::isempty($new_value) && $new_value !== $this->get_data()) { |
|
| 569 | + $updated = $this->update_data($new_value); |
|
| 570 | 570 | $action = 'updated'; |
| 571 | - } elseif ( CMB2_Utils::isempty( $new_value ) ) { |
|
| 571 | + } elseif (CMB2_Utils::isempty($new_value)) { |
|
| 572 | 572 | $updated = $this->remove_data(); |
| 573 | 573 | $action = 'removed'; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - if ( $updated ) { |
|
| 576 | + if ($updated) { |
|
| 577 | 577 | $this->value = $this->get_data(); |
| 578 | 578 | $this->escaped_value = null; |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - $field_id = $this->id( true ); |
|
| 581 | + $field_id = $this->id(true); |
|
| 582 | 582 | |
| 583 | 583 | /** |
| 584 | 584 | * Hooks after save field action. |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * @param string $action Action performed. Could be "repeatable", "updated", or "removed". |
| 591 | 591 | * @param CMB2_Field object $field This field object |
| 592 | 592 | */ |
| 593 | - do_action( 'cmb2_save_field', $field_id, $updated, $action, $this ); |
|
| 593 | + do_action('cmb2_save_field', $field_id, $updated, $action, $this); |
|
| 594 | 594 | |
| 595 | 595 | /** |
| 596 | 596 | * Hooks after save field action. |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | * @param string $action Action performed. Could be "repeatable", "updated", or "removed". |
| 605 | 605 | * @param CMB2_Field object $field This field object |
| 606 | 606 | */ |
| 607 | - do_action( "cmb2_save_field_{$field_id}", $updated, $action, $this ); |
|
| 607 | + do_action("cmb2_save_field_{$field_id}", $updated, $action, $this); |
|
| 608 | 608 | |
| 609 | 609 | return $updated; |
| 610 | 610 | } |
@@ -617,11 +617,11 @@ discard block |
||
| 617 | 617 | */ |
| 618 | 618 | public function escaping_exception() { |
| 619 | 619 | // These types cannot be escaped. |
| 620 | - return in_array( $this->type(), array( |
|
| 620 | + return in_array($this->type(), array( |
|
| 621 | 621 | 'file_list', |
| 622 | 622 | 'multicheck', |
| 623 | 623 | 'text_datetime_timestamp_timezone', |
| 624 | - ) ); |
|
| 624 | + )); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | /** |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | * @param string $type Field type to check. |
| 632 | 632 | * @return bool True if type cannot be repeatable |
| 633 | 633 | */ |
| 634 | - public function repeatable_exception( $type ) { |
|
| 634 | + public function repeatable_exception($type) { |
|
| 635 | 635 | // These types cannot be repeatable. |
| 636 | 636 | $internal_fields = array( |
| 637 | 637 | // Use file_list instead. |
@@ -662,8 +662,8 @@ discard block |
||
| 662 | 662 | * and not values. The value can be anything, because it is meaningless. Example: |
| 663 | 663 | * array( 'my_custom_field' => 1 ) |
| 664 | 664 | */ |
| 665 | - $all_fields = array_merge( apply_filters( 'cmb2_non_repeatable_fields', array() ), $internal_fields ); |
|
| 666 | - return isset( $all_fields[ $type ] ); |
|
| 665 | + $all_fields = array_merge(apply_filters('cmb2_non_repeatable_fields', array()), $internal_fields); |
|
| 666 | + return isset($all_fields[$type]); |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | * @param string $type Field type to check. |
| 674 | 674 | * @return bool True if has own method. |
| 675 | 675 | */ |
| 676 | - public function has_args_method( $type ) { |
|
| 676 | + public function has_args_method($type) { |
|
| 677 | 677 | |
| 678 | 678 | // These types have their own arguments parser. |
| 679 | 679 | $type_methods = array( |
@@ -681,11 +681,11 @@ discard block |
||
| 681 | 681 | 'wysiwyg' => 'set_field_defaults_wysiwyg', |
| 682 | 682 | ); |
| 683 | 683 | |
| 684 | - if ( isset( $type_methods[ $type ] ) ) { |
|
| 685 | - return $type_methods[ $type ]; |
|
| 684 | + if (isset($type_methods[$type])) { |
|
| 685 | + return $type_methods[$type]; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - $all_or_nothing_types = array_flip( apply_filters( 'cmb2_all_or_nothing_types', array( |
|
| 688 | + $all_or_nothing_types = array_flip(apply_filters('cmb2_all_or_nothing_types', array( |
|
| 689 | 689 | 'select', |
| 690 | 690 | 'radio', |
| 691 | 691 | 'radio_inline', |
@@ -694,9 +694,9 @@ discard block |
||
| 694 | 694 | 'taxonomy_radio', |
| 695 | 695 | 'taxonomy_radio_inline', |
| 696 | 696 | 'taxonomy_radio_hierarchical', |
| 697 | - ), $this ) ); |
|
| 697 | + ), $this)); |
|
| 698 | 698 | |
| 699 | - if ( isset( $all_or_nothing_types[ $type ] ) ) { |
|
| 699 | + if (isset($all_or_nothing_types[$type])) { |
|
| 700 | 700 | return 'set_field_defaults_all_or_nothing_types'; |
| 701 | 701 | } |
| 702 | 702 | |
@@ -711,18 +711,18 @@ discard block |
||
| 711 | 711 | * @param mixed $meta_value Meta value. |
| 712 | 712 | * @return mixed Final value. |
| 713 | 713 | */ |
| 714 | - public function escaped_value( $func = 'esc_attr', $meta_value = '' ) { |
|
| 714 | + public function escaped_value($func = 'esc_attr', $meta_value = '') { |
|
| 715 | 715 | |
| 716 | - if ( null !== $this->escaped_value ) { |
|
| 716 | + if (null !== $this->escaped_value) { |
|
| 717 | 717 | return $this->escaped_value; |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | $meta_value = $meta_value ? $meta_value : $this->value(); |
| 721 | 721 | |
| 722 | 722 | // Check if the field has a registered escaping callback. |
| 723 | - if ( $cb = $this->maybe_callback( 'escape_cb' ) ) { |
|
| 723 | + if ($cb = $this->maybe_callback('escape_cb')) { |
|
| 724 | 724 | // Ok, callback is good, let's run it. |
| 725 | - return call_user_func( $cb, $meta_value, $this->args(), $this ); |
|
| 725 | + return call_user_func($cb, $meta_value, $this->args(), $this); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | $field_type = $this->type(); |
@@ -741,26 +741,26 @@ discard block |
||
| 741 | 741 | * @param array $field_args The current field's arguments. |
| 742 | 742 | * @param object $field This `CMB2_Field` object. |
| 743 | 743 | */ |
| 744 | - $esc = apply_filters( "cmb2_types_esc_{$field_type}", null, $meta_value, $this->args(), $this ); |
|
| 745 | - if ( null !== $esc ) { |
|
| 744 | + $esc = apply_filters("cmb2_types_esc_{$field_type}", null, $meta_value, $this->args(), $this); |
|
| 745 | + if (null !== $esc) { |
|
| 746 | 746 | return $esc; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - if ( false === $cb || $this->escaping_exception() ) { |
|
| 749 | + if (false === $cb || $this->escaping_exception()) { |
|
| 750 | 750 | // If requesting NO escaping, return meta value. |
| 751 | - return $this->val_or_default( $meta_value ); |
|
| 751 | + return $this->val_or_default($meta_value); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | // escaping function passed in? |
| 755 | 755 | $func = $func ? $func : 'esc_attr'; |
| 756 | - $meta_value = $this->val_or_default( $meta_value ); |
|
| 756 | + $meta_value = $this->val_or_default($meta_value); |
|
| 757 | 757 | |
| 758 | - if ( is_array( $meta_value ) ) { |
|
| 759 | - foreach ( $meta_value as $key => $value ) { |
|
| 760 | - $meta_value[ $key ] = call_user_func( $func, $value ); |
|
| 758 | + if (is_array($meta_value)) { |
|
| 759 | + foreach ($meta_value as $key => $value) { |
|
| 760 | + $meta_value[$key] = call_user_func($func, $value); |
|
| 761 | 761 | } |
| 762 | 762 | } else { |
| 763 | - $meta_value = call_user_func( $func, $meta_value ); |
|
| 763 | + $meta_value = call_user_func($func, $meta_value); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | $this->escaped_value = $meta_value; |
@@ -774,8 +774,8 @@ discard block |
||
| 774 | 774 | * @param mixed $meta_value Field value. |
| 775 | 775 | * @return mixed Field value, or default value |
| 776 | 776 | */ |
| 777 | - public function val_or_default( $meta_value ) { |
|
| 778 | - return ! CMB2_Utils::isempty( $meta_value ) ? $meta_value : $this->get_default(); |
|
| 777 | + public function val_or_default($meta_value) { |
|
| 778 | + return ! CMB2_Utils::isempty($meta_value) ? $meta_value : $this->get_default(); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | * @return string Offset time string |
| 786 | 786 | */ |
| 787 | 787 | public function field_timezone_offset() { |
| 788 | - return CMB2_Utils::timezone_offset( $this->field_timezone() ); |
|
| 788 | + return CMB2_Utils::timezone_offset($this->field_timezone()); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -798,12 +798,12 @@ discard block |
||
| 798 | 798 | $value = ''; |
| 799 | 799 | |
| 800 | 800 | // Is timezone arg set? |
| 801 | - if ( $this->args( 'timezone' ) ) { |
|
| 802 | - $value = $this->args( 'timezone' ); |
|
| 801 | + if ($this->args('timezone')) { |
|
| 802 | + $value = $this->args('timezone'); |
|
| 803 | 803 | } // End if. |
| 804 | 804 | // Is there another meta key with a timezone stored as its value we should use? |
| 805 | - elseif ( $this->args( 'timezone_meta_key' ) ) { |
|
| 806 | - $value = $this->get_data( $this->args( 'timezone_meta_key' ) ); |
|
| 805 | + elseif ($this->args('timezone_meta_key')) { |
|
| 806 | + $value = $this->get_data($this->args('timezone_meta_key')); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | return $value; |
@@ -817,8 +817,8 @@ discard block |
||
| 817 | 817 | * @param string $format Either date_format or time_format. |
| 818 | 818 | * @return string Formatted date |
| 819 | 819 | */ |
| 820 | - public function format_timestamp( $meta_value, $format = 'date_format' ) { |
|
| 821 | - return date( stripslashes( $this->args( $format ) ), $meta_value ); |
|
| 820 | + public function format_timestamp($meta_value, $format = 'date_format') { |
|
| 821 | + return date(stripslashes($this->args($format)), $meta_value); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -829,20 +829,20 @@ discard block |
||
| 829 | 829 | * @param string|int $meta_value Optional meta value to check. |
| 830 | 830 | * @return string Formatted date |
| 831 | 831 | */ |
| 832 | - public function get_timestamp_format( $format = 'date_format', $meta_value = 0 ) { |
|
| 832 | + public function get_timestamp_format($format = 'date_format', $meta_value = 0) { |
|
| 833 | 833 | $meta_value = $meta_value ? $meta_value : $this->escaped_value(); |
| 834 | - if ( empty( $meta_value ) ) { |
|
| 834 | + if (empty($meta_value)) { |
|
| 835 | 835 | $meta_value = $this->get_default(); |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | - $meta_value = CMB2_Utils::make_valid_time_stamp( $meta_value ); |
|
| 839 | - if ( empty( $meta_value ) ) { |
|
| 838 | + $meta_value = CMB2_Utils::make_valid_time_stamp($meta_value); |
|
| 839 | + if (empty($meta_value)) { |
|
| 840 | 840 | return ''; |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | - return is_array( $meta_value ) |
|
| 844 | - ? array_map( array( $this, 'format_timestamp' ), $meta_value, $format ) |
|
| 845 | - : $this->format_timestamp( $meta_value, $format ); |
|
| 843 | + return is_array($meta_value) |
|
| 844 | + ? array_map(array($this, 'format_timestamp'), $meta_value, $format) |
|
| 845 | + : $this->format_timestamp($meta_value, $format); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | /** |
@@ -852,8 +852,8 @@ discard block |
||
| 852 | 852 | * @param string $value Date value. |
| 853 | 853 | * @return mixed Unix timestamp representing the date. |
| 854 | 854 | */ |
| 855 | - public function get_timestamp_from_value( $value ) { |
|
| 856 | - return CMB2_Utils::get_timestamp_from_value( $value, $this->args( 'date_format' ) ); |
|
| 855 | + public function get_timestamp_from_value($value) { |
|
| 856 | + return CMB2_Utils::get_timestamp_from_value($value, $this->args('date_format')); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | public function render_field() { |
| 865 | 865 | $this->render_context = 'edit'; |
| 866 | 866 | |
| 867 | - $this->peform_param_callback( 'render_row_cb' ); |
|
| 867 | + $this->peform_param_callback('render_row_cb'); |
|
| 868 | 868 | |
| 869 | 869 | // For chaining. |
| 870 | 870 | return $this; |
@@ -878,12 +878,12 @@ discard block |
||
| 878 | 878 | public function render_field_callback() { |
| 879 | 879 | |
| 880 | 880 | // If field is requesting to not be shown on the front-end. |
| 881 | - if ( ! is_admin() && ! $this->args( 'on_front' ) ) { |
|
| 881 | + if ( ! is_admin() && ! $this->args('on_front')) { |
|
| 882 | 882 | return; |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | // If field is requesting to be conditionally shown. |
| 886 | - if ( ! $this->should_show() ) { |
|
| 886 | + if ( ! $this->should_show()) { |
|
| 887 | 887 | return; |
| 888 | 888 | } |
| 889 | 889 | |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | * |
| 895 | 895 | * @param CMB2_Field $field The current field object. |
| 896 | 896 | */ |
| 897 | - do_action( 'cmb2_before_field_row', $this ); |
|
| 897 | + do_action('cmb2_before_field_row', $this); |
|
| 898 | 898 | |
| 899 | 899 | /** |
| 900 | 900 | * Hook before field row begins. |
@@ -903,36 +903,36 @@ discard block |
||
| 903 | 903 | * |
| 904 | 904 | * @param CMB2_Field $field The current field object. |
| 905 | 905 | */ |
| 906 | - do_action( "cmb2_before_{$field_type}_field_row", $this ); |
|
| 906 | + do_action("cmb2_before_{$field_type}_field_row", $this); |
|
| 907 | 907 | |
| 908 | - $this->peform_param_callback( 'before_row' ); |
|
| 908 | + $this->peform_param_callback('before_row'); |
|
| 909 | 909 | |
| 910 | - printf( "<div class=\"cmb-row %s\" data-fieldtype=\"%s\">\n", $this->row_classes(), $field_type ); |
|
| 910 | + printf("<div class=\"cmb-row %s\" data-fieldtype=\"%s\">\n", $this->row_classes(), $field_type); |
|
| 911 | 911 | |
| 912 | - if ( ! $this->args( 'show_names' ) ) { |
|
| 912 | + if ( ! $this->args('show_names')) { |
|
| 913 | 913 | echo "\n\t<div class=\"cmb-td\">\n"; |
| 914 | 914 | |
| 915 | - $this->peform_param_callback( 'label_cb' ); |
|
| 915 | + $this->peform_param_callback('label_cb'); |
|
| 916 | 916 | |
| 917 | 917 | } else { |
| 918 | 918 | |
| 919 | - if ( $this->get_param_callback_result( 'label_cb' ) ) { |
|
| 920 | - echo '<div class="cmb-th">', $this->peform_param_callback( 'label_cb' ), '</div>'; |
|
| 919 | + if ($this->get_param_callback_result('label_cb')) { |
|
| 920 | + echo '<div class="cmb-th">', $this->peform_param_callback('label_cb'), '</div>'; |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | echo "\n\t<div class=\"cmb-td\">\n"; |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | - $this->peform_param_callback( 'before' ); |
|
| 926 | + $this->peform_param_callback('before'); |
|
| 927 | 927 | |
| 928 | - $types = new CMB2_Types( $this ); |
|
| 928 | + $types = new CMB2_Types($this); |
|
| 929 | 929 | $types->render(); |
| 930 | 930 | |
| 931 | - $this->peform_param_callback( 'after' ); |
|
| 931 | + $this->peform_param_callback('after'); |
|
| 932 | 932 | |
| 933 | 933 | echo "\n\t</div>\n</div>"; |
| 934 | 934 | |
| 935 | - $this->peform_param_callback( 'after_row' ); |
|
| 935 | + $this->peform_param_callback('after_row'); |
|
| 936 | 936 | |
| 937 | 937 | /** |
| 938 | 938 | * Hook after field row ends. |
@@ -941,14 +941,14 @@ discard block |
||
| 941 | 941 | * |
| 942 | 942 | * @param CMB2_Field $field The current field object. |
| 943 | 943 | */ |
| 944 | - do_action( "cmb2_after_{$field_type}_field_row", $this ); |
|
| 944 | + do_action("cmb2_after_{$field_type}_field_row", $this); |
|
| 945 | 945 | |
| 946 | 946 | /** |
| 947 | 947 | * Hook after field row ends. |
| 948 | 948 | * |
| 949 | 949 | * @param CMB2_Field $field The current field object. |
| 950 | 950 | */ |
| 951 | - do_action( 'cmb2_after_field_row', $this ); |
|
| 951 | + do_action('cmb2_after_field_row', $this); |
|
| 952 | 952 | |
| 953 | 953 | // For chaining. |
| 954 | 954 | return $this; |
@@ -961,13 +961,13 @@ discard block |
||
| 961 | 961 | * @return string Label html markup. |
| 962 | 962 | */ |
| 963 | 963 | public function label() { |
| 964 | - if ( ! $this->args( 'name' ) ) { |
|
| 964 | + if ( ! $this->args('name')) { |
|
| 965 | 965 | return ''; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - $style = ! $this->args( 'show_names' ) ? ' style="display:none;"' : ''; |
|
| 968 | + $style = ! $this->args('show_names') ? ' style="display:none;"' : ''; |
|
| 969 | 969 | |
| 970 | - return sprintf( "\n" . '<label%1$s for="%2$s">%3$s</label>' . "\n", $style, $this->id(), $this->args( 'name' ) ); |
|
| 970 | + return sprintf("\n" . '<label%1$s for="%2$s">%3$s</label>' . "\n", $style, $this->id(), $this->args('name')); |
|
| 971 | 971 | } |
| 972 | 972 | |
| 973 | 973 | /** |
@@ -987,34 +987,34 @@ discard block |
||
| 987 | 987 | * |
| 988 | 988 | * @param array $field_types The types of fields which should get the 'table-layout' class |
| 989 | 989 | */ |
| 990 | - $repeat_table_rows_types = apply_filters( 'cmb2_repeat_table_row_types', array( |
|
| 990 | + $repeat_table_rows_types = apply_filters('cmb2_repeat_table_row_types', array( |
|
| 991 | 991 | 'text_url', |
| 992 | 992 | 'text', |
| 993 | - ) ); |
|
| 993 | + )); |
|
| 994 | 994 | |
| 995 | 995 | $conditional_classes = array( |
| 996 | - 'cmb-type-' . str_replace( '_', '-', sanitize_html_class( $this->type() ) ) => true, |
|
| 997 | - 'cmb2-id-' . str_replace( '_', '-', sanitize_html_class( $this->id() ) ) => true, |
|
| 998 | - 'cmb-repeat' => $this->args( 'repeatable' ), |
|
| 996 | + 'cmb-type-' . str_replace('_', '-', sanitize_html_class($this->type())) => true, |
|
| 997 | + 'cmb2-id-' . str_replace('_', '-', sanitize_html_class($this->id())) => true, |
|
| 998 | + 'cmb-repeat' => $this->args('repeatable'), |
|
| 999 | 999 | 'cmb-repeat-group-field' => $this->group, |
| 1000 | - 'cmb-inline' => $this->args( 'inline' ), |
|
| 1001 | - 'table-layout' => 'edit' === $this->render_context && in_array( $this->type(), $repeat_table_rows_types ), |
|
| 1000 | + 'cmb-inline' => $this->args('inline'), |
|
| 1001 | + 'table-layout' => 'edit' === $this->render_context && in_array($this->type(), $repeat_table_rows_types), |
|
| 1002 | 1002 | ); |
| 1003 | 1003 | |
| 1004 | - foreach ( $conditional_classes as $class => $condition ) { |
|
| 1005 | - if ( $condition ) { |
|
| 1004 | + foreach ($conditional_classes as $class => $condition) { |
|
| 1005 | + if ($condition) { |
|
| 1006 | 1006 | $classes[] = $class; |
| 1007 | 1007 | } |
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | - if ( $added_classes = $this->args( 'classes' ) ) { |
|
| 1011 | - $added_classes = is_array( $added_classes ) ? implode( ' ', $added_classes ) : (string) $added_classes; |
|
| 1012 | - } elseif ( $added_classes = $this->get_param_callback_result( 'classes_cb' ) ) { |
|
| 1013 | - $added_classes = is_array( $added_classes ) ? implode( ' ', $added_classes ) : (string) $added_classes; |
|
| 1010 | + if ($added_classes = $this->args('classes')) { |
|
| 1011 | + $added_classes = is_array($added_classes) ? implode(' ', $added_classes) : (string) $added_classes; |
|
| 1012 | + } elseif ($added_classes = $this->get_param_callback_result('classes_cb')) { |
|
| 1013 | + $added_classes = is_array($added_classes) ? implode(' ', $added_classes) : (string) $added_classes; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | - if ( $added_classes ) { |
|
| 1017 | - $classes[] = esc_attr( $added_classes ); |
|
| 1016 | + if ($added_classes) { |
|
| 1017 | + $classes[] = esc_attr($added_classes); |
|
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | /** |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | * @param string $classes Space-separated list of row classes |
| 1026 | 1026 | * @param CMB2_Field object $field This field object |
| 1027 | 1027 | */ |
| 1028 | - return apply_filters( 'cmb2_row_classes', implode( ' ', $classes ), $this ); |
|
| 1028 | + return apply_filters('cmb2_row_classes', implode(' ', $classes), $this); |
|
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /** |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | public function render_column() { |
| 1037 | 1037 | $this->render_context = 'display'; |
| 1038 | 1038 | |
| 1039 | - $this->peform_param_callback( 'display_cb' ); |
|
| 1039 | + $this->peform_param_callback('display_cb'); |
|
| 1040 | 1040 | |
| 1041 | 1041 | // For chaining. |
| 1042 | 1042 | return $this; |
@@ -1049,10 +1049,10 @@ discard block |
||
| 1049 | 1049 | */ |
| 1050 | 1050 | public function get_rest_value() { |
| 1051 | 1051 | $field_type = $this->type(); |
| 1052 | - $field_id = $this->id( true ); |
|
| 1052 | + $field_id = $this->id(true); |
|
| 1053 | 1053 | |
| 1054 | - if ( $cb = $this->maybe_callback( 'rest_value_cb' ) ) { |
|
| 1055 | - add_filter( "cmb2_get_rest_value_for_{$field_id}", $cb, 99 ); |
|
| 1054 | + if ($cb = $this->maybe_callback('rest_value_cb')) { |
|
| 1055 | + add_filter("cmb2_get_rest_value_for_{$field_id}", $cb, 99); |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | $value = $this->get_data(); |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | * @param mixed $value The value from CMB2_Field::get_data() |
| 1066 | 1066 | * @param CMB2_Field $field This field object. |
| 1067 | 1067 | */ |
| 1068 | - $value = apply_filters( 'cmb2_get_rest_value', $value, $this ); |
|
| 1068 | + $value = apply_filters('cmb2_get_rest_value', $value, $this); |
|
| 1069 | 1069 | |
| 1070 | 1070 | /** |
| 1071 | 1071 | * Filter the value before it is sent to the REST request. |
@@ -1077,7 +1077,7 @@ discard block |
||
| 1077 | 1077 | * @param mixed $value The value from CMB2_Field::get_data() |
| 1078 | 1078 | * @param CMB2_Field $field This field object. |
| 1079 | 1079 | */ |
| 1080 | - $value = apply_filters( "cmb2_get_rest_value_{$field_type}", $value, $this ); |
|
| 1080 | + $value = apply_filters("cmb2_get_rest_value_{$field_type}", $value, $this); |
|
| 1081 | 1081 | |
| 1082 | 1082 | /** |
| 1083 | 1083 | * Filter the value before it is sent to the REST request. |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | * @param mixed $value The value from CMB2_Field::get_data() |
| 1090 | 1090 | * @param CMB2_Field $field This field object. |
| 1091 | 1091 | */ |
| 1092 | - return apply_filters( "cmb2_get_rest_value_for_{$field_id}", $value, $this ); |
|
| 1092 | + return apply_filters("cmb2_get_rest_value_for_{$field_id}", $value, $this); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1100,15 +1100,15 @@ discard block |
||
| 1100 | 1100 | * @return CMB2_Field|bool Supporting field object, if supported. |
| 1101 | 1101 | */ |
| 1102 | 1102 | public function get_supporting_field() { |
| 1103 | - $suffix = $this->args( 'has_supporting_data' ); |
|
| 1104 | - if ( empty( $suffix ) ) { |
|
| 1103 | + $suffix = $this->args('has_supporting_data'); |
|
| 1104 | + if (empty($suffix)) { |
|
| 1105 | 1105 | return false; |
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | - return $this->get_field_clone( array( |
|
| 1109 | - 'id' => $this->_id( '', false ) . $suffix, |
|
| 1108 | + return $this->get_field_clone(array( |
|
| 1109 | + 'id' => $this->_id('', false) . $suffix, |
|
| 1110 | 1110 | 'sanitization_cb' => false, |
| 1111 | - ) ); |
|
| 1111 | + )); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
@@ -1118,11 +1118,11 @@ discard block |
||
| 1118 | 1118 | */ |
| 1119 | 1119 | public function display_value_callback() { |
| 1120 | 1120 | // If field is requesting to be conditionally shown. |
| 1121 | - if ( ! $this->should_show() ) { |
|
| 1121 | + if ( ! $this->should_show()) { |
|
| 1122 | 1122 | return; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | - $display = new CMB2_Field_Display( $this ); |
|
| 1125 | + $display = new CMB2_Field_Display($this); |
|
| 1126 | 1126 | $field_type = $this->type(); |
| 1127 | 1127 | |
| 1128 | 1128 | /** |
@@ -1136,26 +1136,26 @@ discard block |
||
| 1136 | 1136 | * @param CMB2_Field $field This field object. |
| 1137 | 1137 | * @param CMB2_Field_Display $display The `CMB2_Field_Display` object. |
| 1138 | 1138 | */ |
| 1139 | - $pre_output = apply_filters( "cmb2_pre_field_display_{$field_type}", null, $this, $display ); |
|
| 1139 | + $pre_output = apply_filters("cmb2_pre_field_display_{$field_type}", null, $this, $display); |
|
| 1140 | 1140 | |
| 1141 | - if ( null !== $pre_output ) { |
|
| 1141 | + if (null !== $pre_output) { |
|
| 1142 | 1142 | echo $pre_output; |
| 1143 | 1143 | return; |
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | - $this->peform_param_callback( 'before_display_wrap' ); |
|
| 1146 | + $this->peform_param_callback('before_display_wrap'); |
|
| 1147 | 1147 | |
| 1148 | - printf( "<div class=\"cmb-column %s\" data-fieldtype=\"%s\">\n", $this->row_classes(), $field_type ); |
|
| 1148 | + printf("<div class=\"cmb-column %s\" data-fieldtype=\"%s\">\n", $this->row_classes(), $field_type); |
|
| 1149 | 1149 | |
| 1150 | - $this->peform_param_callback( 'before_display' ); |
|
| 1150 | + $this->peform_param_callback('before_display'); |
|
| 1151 | 1151 | |
| 1152 | - CMB2_Field_Display::get( $this )->display(); |
|
| 1152 | + CMB2_Field_Display::get($this)->display(); |
|
| 1153 | 1153 | |
| 1154 | - $this->peform_param_callback( 'after_display' ); |
|
| 1154 | + $this->peform_param_callback('after_display'); |
|
| 1155 | 1155 | |
| 1156 | 1156 | echo "\n</div>"; |
| 1157 | 1157 | |
| 1158 | - $this->peform_param_callback( 'after_display_wrap' ); |
|
| 1158 | + $this->peform_param_callback('after_display_wrap'); |
|
| 1159 | 1159 | |
| 1160 | 1160 | // For chaining. |
| 1161 | 1161 | return $this; |
@@ -1168,9 +1168,9 @@ discard block |
||
| 1168 | 1168 | * @param string $value Value to update. |
| 1169 | 1169 | * @return string Updated value |
| 1170 | 1170 | */ |
| 1171 | - public function replace_hash( $value ) { |
|
| 1171 | + public function replace_hash($value) { |
|
| 1172 | 1172 | // Replace hash with 1 based count. |
| 1173 | - return str_replace( '{#}', ( $this->index + 1 ), $value ); |
|
| 1173 | + return str_replace('{#}', ($this->index + 1), $value); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | /** |
@@ -1182,27 +1182,27 @@ discard block |
||
| 1182 | 1182 | * @param string $fallback Fallback text. |
| 1183 | 1183 | * @return string Text |
| 1184 | 1184 | */ |
| 1185 | - public function get_string( $text_key, $fallback ) { |
|
| 1185 | + public function get_string($text_key, $fallback) { |
|
| 1186 | 1186 | // If null, populate with our field strings values. |
| 1187 | - if ( null === $this->strings ) { |
|
| 1187 | + if (null === $this->strings) { |
|
| 1188 | 1188 | $this->strings = (array) $this->args['text']; |
| 1189 | 1189 | |
| 1190 | - if ( is_callable( $this->args['text_cb'] ) ) { |
|
| 1191 | - $strings = call_user_func( $this->args['text_cb'], $this ); |
|
| 1190 | + if (is_callable($this->args['text_cb'])) { |
|
| 1191 | + $strings = call_user_func($this->args['text_cb'], $this); |
|
| 1192 | 1192 | |
| 1193 | - if ( $strings && is_array( $strings ) ) { |
|
| 1193 | + if ($strings && is_array($strings)) { |
|
| 1194 | 1194 | $this->strings += $strings; |
| 1195 | 1195 | } |
| 1196 | 1196 | } |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | // If we have that string value, send it back. |
| 1200 | - if ( isset( $this->strings[ $text_key ] ) ) { |
|
| 1201 | - return $this->strings[ $text_key ]; |
|
| 1200 | + if (isset($this->strings[$text_key])) { |
|
| 1201 | + return $this->strings[$text_key]; |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | // Check options for back-compat. |
| 1205 | - $string = $this->options( $text_key ); |
|
| 1205 | + $string = $this->options($text_key); |
|
| 1206 | 1206 | |
| 1207 | 1207 | return $string ? $string : $fallback; |
| 1208 | 1208 | } |
@@ -1214,13 +1214,13 @@ discard block |
||
| 1214 | 1214 | * @param string $key Specific option to retrieve. |
| 1215 | 1215 | * @return array|mixed Array of options or specific option. |
| 1216 | 1216 | */ |
| 1217 | - public function options( $key = '' ) { |
|
| 1218 | - if ( empty( $this->field_options ) ) { |
|
| 1217 | + public function options($key = '') { |
|
| 1218 | + if (empty($this->field_options)) { |
|
| 1219 | 1219 | $this->set_options(); |
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | - if ( $key ) { |
|
| 1223 | - return array_key_exists( $key, $this->field_options ) ? $this->field_options[ $key ] : false; |
|
| 1222 | + if ($key) { |
|
| 1223 | + return array_key_exists($key, $this->field_options) ? $this->field_options[$key] : false; |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | return $this->field_options; |
@@ -1236,10 +1236,10 @@ discard block |
||
| 1236 | 1236 | public function set_options() { |
| 1237 | 1237 | $this->field_options = (array) $this->args['options']; |
| 1238 | 1238 | |
| 1239 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
| 1240 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
| 1239 | + if (is_callable($this->args['options_cb'])) { |
|
| 1240 | + $options = call_user_func($this->args['options_cb'], $this); |
|
| 1241 | 1241 | |
| 1242 | - if ( $options && is_array( $options ) ) { |
|
| 1242 | + if ($options && is_array($options)) { |
|
| 1243 | 1243 | $this->field_options = $options + $this->field_options; |
| 1244 | 1244 | } |
| 1245 | 1245 | } |
@@ -1253,12 +1253,12 @@ discard block |
||
| 1253 | 1253 | * @since 2.2.0 |
| 1254 | 1254 | * @param array $dependencies Dependies to register for this field. |
| 1255 | 1255 | */ |
| 1256 | - public function add_js_dependencies( $dependencies = array() ) { |
|
| 1257 | - foreach ( (array) $dependencies as $dependency ) { |
|
| 1258 | - $this->args['js_dependencies'][ $dependency ] = $dependency; |
|
| 1256 | + public function add_js_dependencies($dependencies = array()) { |
|
| 1257 | + foreach ((array) $dependencies as $dependency) { |
|
| 1258 | + $this->args['js_dependencies'][$dependency] = $dependency; |
|
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | - CMB2_JS::add_dependencies( $dependencies ); |
|
| 1261 | + CMB2_JS::add_dependencies($dependencies); |
|
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | /** |
@@ -1267,11 +1267,11 @@ discard block |
||
| 1267 | 1267 | * @since 2.2.0 |
| 1268 | 1268 | */ |
| 1269 | 1269 | public function register_js_data() { |
| 1270 | - if ( $this->group ) { |
|
| 1271 | - CMB2_JS::add_field_data( $this->group ); |
|
| 1270 | + if ($this->group) { |
|
| 1271 | + CMB2_JS::add_field_data($this->group); |
|
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - return CMB2_JS::add_field_data( $this ); |
|
| 1274 | + return CMB2_JS::add_field_data($this); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | /** |
@@ -1283,13 +1283,13 @@ discard block |
||
| 1283 | 1283 | */ |
| 1284 | 1284 | public function js_data() { |
| 1285 | 1285 | return array( |
| 1286 | - 'label' => $this->args( 'name' ), |
|
| 1287 | - 'id' => $this->id( true ), |
|
| 1286 | + 'label' => $this->args('name'), |
|
| 1287 | + 'id' => $this->id(true), |
|
| 1288 | 1288 | 'type' => $this->type(), |
| 1289 | 1289 | 'hash' => $this->hash_id(), |
| 1290 | 1290 | 'box' => $this->cmb_id, |
| 1291 | 1291 | 'id_attr' => $this->id(), |
| 1292 | - 'name_attr' => $this->args( '_name' ), |
|
| 1292 | + 'name_attr' => $this->args('_name'), |
|
| 1293 | 1293 | 'default' => $this->get_default(), |
| 1294 | 1294 | 'group' => $this->group_id(), |
| 1295 | 1295 | 'index' => $this->group ? $this->group->index : null, |
@@ -1304,8 +1304,8 @@ discard block |
||
| 1304 | 1304 | * @return string |
| 1305 | 1305 | */ |
| 1306 | 1306 | public function hash_id() { |
| 1307 | - if ( '' === $this->hash_id ) { |
|
| 1308 | - $this->hash_id = CMB2_Utils::generate_hash( $this->cmb_id . '||' . $this->id() ); |
|
| 1307 | + if ('' === $this->hash_id) { |
|
| 1308 | + $this->hash_id = CMB2_Utils::generate_hash($this->cmb_id . '||' . $this->id()); |
|
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | 1311 | return $this->hash_id; |
@@ -1319,7 +1319,7 @@ discard block |
||
| 1319 | 1319 | * @return string |
| 1320 | 1320 | */ |
| 1321 | 1321 | public function group_id() { |
| 1322 | - return $this->group ? $this->group->id( true ) : ''; |
|
| 1322 | + return $this->group ? $this->group->id(true) : ''; |
|
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | /** |
@@ -1332,15 +1332,15 @@ discard block |
||
| 1332 | 1332 | public function get_default() { |
| 1333 | 1333 | $default = $this->args['default']; |
| 1334 | 1334 | |
| 1335 | - if ( null !== $default ) { |
|
| 1336 | - return apply_filters( 'cmb2_default_filter', $default, $this ); |
|
| 1335 | + if (null !== $default) { |
|
| 1336 | + return apply_filters('cmb2_default_filter', $default, $this); |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | - $param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default'; |
|
| 1340 | - $default = $this->args['default'] = $this->get_param_callback_result( $param ); |
|
| 1339 | + $param = is_callable($this->args['default_cb']) ? 'default_cb' : 'default'; |
|
| 1340 | + $default = $this->args['default'] = $this->get_param_callback_result($param); |
|
| 1341 | 1341 | |
| 1342 | 1342 | // Allow a filter override of the default value. |
| 1343 | - return apply_filters( 'cmb2_default_filter', $this->args['default'], $this ); |
|
| 1343 | + return apply_filters('cmb2_default_filter', $this->args['default'], $this); |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | /** |
@@ -1351,8 +1351,8 @@ discard block |
||
| 1351 | 1351 | * @param array $args Field config array. |
| 1352 | 1352 | * @return array Modified field config array. |
| 1353 | 1353 | */ |
| 1354 | - public function _set_field_defaults( $args ) { |
|
| 1355 | - $defaults = $this->get_default_field_args( $args ); |
|
| 1354 | + public function _set_field_defaults($args) { |
|
| 1355 | + $defaults = $this->get_default_field_args($args); |
|
| 1356 | 1356 | |
| 1357 | 1357 | /** |
| 1358 | 1358 | * Filter the CMB2 Field defaults. |
@@ -1363,10 +1363,10 @@ discard block |
||
| 1363 | 1363 | * @param string $type Field type for the current field to allow for selective filtering. |
| 1364 | 1364 | * @param CMB2_Field object $field This field object. |
| 1365 | 1365 | */ |
| 1366 | - $defaults = apply_filters( 'cmb2_field_defaults', $defaults, $args['id'], $args['type'], $this ); |
|
| 1366 | + $defaults = apply_filters('cmb2_field_defaults', $defaults, $args['id'], $args['type'], $this); |
|
| 1367 | 1367 | |
| 1368 | 1368 | // Set up blank or default values for empty ones. |
| 1369 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1369 | + $args = wp_parse_args($args, $defaults); |
|
| 1370 | 1370 | |
| 1371 | 1371 | /** |
| 1372 | 1372 | * Filtering the CMB2 Field arguments once merged with the defaults, but before further processing. |
@@ -1375,7 +1375,7 @@ discard block |
||
| 1375 | 1375 | * @param array $args Metabox field config array defaults. |
| 1376 | 1376 | * @param CMB2_Field object $field This field object. |
| 1377 | 1377 | */ |
| 1378 | - $args = apply_filters( 'cmb2_field_arguments_raw', $args, $this ); |
|
| 1378 | + $args = apply_filters('cmb2_field_arguments_raw', $args, $this); |
|
| 1379 | 1379 | |
| 1380 | 1380 | /* |
| 1381 | 1381 | * Deprecated usage: |
@@ -1384,19 +1384,19 @@ discard block |
||
| 1384 | 1384 | * 'row_classes' -- use 'class', or 'class_cb' |
| 1385 | 1385 | * 'default' -- as callback (use default_cb) |
| 1386 | 1386 | */ |
| 1387 | - $args = $this->convert_deprecated_params( $args ); |
|
| 1387 | + $args = $this->convert_deprecated_params($args); |
|
| 1388 | 1388 | |
| 1389 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
| 1390 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
| 1389 | + $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception($args['type']); |
|
| 1390 | + $args['inline'] = $args['inline'] || false !== stripos($args['type'], '_inline'); |
|
| 1391 | 1391 | $args['_id'] = $args['id']; |
| 1392 | 1392 | $args['_name'] = $args['id']; |
| 1393 | 1393 | |
| 1394 | - if ( $method = $this->has_args_method( $args['type'] ) ) { |
|
| 1395 | - $args = $this->{$method}( $args ); |
|
| 1394 | + if ($method = $this->has_args_method($args['type'])) { |
|
| 1395 | + $args = $this->{$method}($args); |
|
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | - if ( $this->group ) { |
|
| 1399 | - $args = $this->set_group_sub_field_defaults( $args ); |
|
| 1398 | + if ($this->group) { |
|
| 1399 | + $args = $this->set_group_sub_field_defaults($args); |
|
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | 1402 | $with_supporting = array( |
@@ -1406,13 +1406,13 @@ discard block |
||
| 1406 | 1406 | 'text_datetime_timestamp_timezone' => '_utc', |
| 1407 | 1407 | ); |
| 1408 | 1408 | |
| 1409 | - $args['has_supporting_data'] = isset( $with_supporting[ $args['type'] ] ) |
|
| 1410 | - ? $with_supporting[ $args['type'] ] |
|
| 1409 | + $args['has_supporting_data'] = isset($with_supporting[$args['type']]) |
|
| 1410 | + ? $with_supporting[$args['type']] |
|
| 1411 | 1411 | : false; |
| 1412 | 1412 | |
| 1413 | 1413 | // Repeatable fields require jQuery sortable library. |
| 1414 | - if ( ! empty( $args['repeatable'] ) ) { |
|
| 1415 | - CMB2_JS::add_dependencies( 'jquery-ui-sortable' ); |
|
| 1414 | + if ( ! empty($args['repeatable'])) { |
|
| 1415 | + CMB2_JS::add_dependencies('jquery-ui-sortable'); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | 1418 | /** |
@@ -1422,7 +1422,7 @@ discard block |
||
| 1422 | 1422 | * @param array $args Metabox field config array after processing. |
| 1423 | 1423 | * @param CMB2_Field object $field This field object. |
| 1424 | 1424 | */ |
| 1425 | - return apply_filters( 'cmb2_field_arguments', $args, $this ); |
|
| 1425 | + return apply_filters('cmb2_field_arguments', $args, $this); |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | 1428 | /** |
@@ -1433,12 +1433,12 @@ discard block |
||
| 1433 | 1433 | * @param array $args Field config array. |
| 1434 | 1434 | * @return array Modified field config array. |
| 1435 | 1435 | */ |
| 1436 | - protected function set_field_defaults_group( $args ) { |
|
| 1437 | - $args['options'] = wp_parse_args( $args['options'], array( |
|
| 1438 | - 'add_button' => esc_html__( 'Add Group', 'cmb2' ), |
|
| 1439 | - 'remove_button' => esc_html__( 'Remove Group', 'cmb2' ), |
|
| 1436 | + protected function set_field_defaults_group($args) { |
|
| 1437 | + $args['options'] = wp_parse_args($args['options'], array( |
|
| 1438 | + 'add_button' => esc_html__('Add Group', 'cmb2'), |
|
| 1439 | + 'remove_button' => esc_html__('Remove Group', 'cmb2'), |
|
| 1440 | 1440 | 'remove_confirm' => '', |
| 1441 | - ) ); |
|
| 1441 | + )); |
|
| 1442 | 1442 | |
| 1443 | 1443 | return $args; |
| 1444 | 1444 | } |
@@ -1451,8 +1451,8 @@ discard block |
||
| 1451 | 1451 | * @param array $args Field config array. |
| 1452 | 1452 | * @return array Modified field config array. |
| 1453 | 1453 | */ |
| 1454 | - protected function set_field_defaults_wysiwyg( $args ) { |
|
| 1455 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
| 1454 | + protected function set_field_defaults_wysiwyg($args) { |
|
| 1455 | + $args['id'] = strtolower(str_ireplace('-', '_', $args['id'])); |
|
| 1456 | 1456 | $args['options']['textarea_name'] = $args['_name']; |
| 1457 | 1457 | |
| 1458 | 1458 | return $args; |
@@ -1466,13 +1466,13 @@ discard block |
||
| 1466 | 1466 | * @param array $args Field config array. |
| 1467 | 1467 | * @return array Modified field config array. |
| 1468 | 1468 | */ |
| 1469 | - protected function set_field_defaults_all_or_nothing_types( $args ) { |
|
| 1470 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
| 1471 | - $args['show_option_none'] = true === $args['show_option_none'] ? esc_html__( 'None', 'cmb2' ) : $args['show_option_none']; |
|
| 1469 | + protected function set_field_defaults_all_or_nothing_types($args) { |
|
| 1470 | + $args['show_option_none'] = isset($args['show_option_none']) ? $args['show_option_none'] : null; |
|
| 1471 | + $args['show_option_none'] = true === $args['show_option_none'] ? esc_html__('None', 'cmb2') : $args['show_option_none']; |
|
| 1472 | 1472 | |
| 1473 | - if ( null === $args['show_option_none'] ) { |
|
| 1474 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
| 1475 | - $args['show_option_none'] = $off_by_default ? false : esc_html__( 'None', 'cmb2' ); |
|
| 1473 | + if (null === $args['show_option_none']) { |
|
| 1474 | + $off_by_default = in_array($args['type'], array('select', 'radio', 'radio_inline'), true); |
|
| 1475 | + $args['show_option_none'] = $off_by_default ? false : esc_html__('None', 'cmb2'); |
|
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | return $args; |
@@ -1486,9 +1486,9 @@ discard block |
||
| 1486 | 1486 | * @param array $args Field config array. |
| 1487 | 1487 | * @return array Modified field config array. |
| 1488 | 1488 | */ |
| 1489 | - protected function set_group_sub_field_defaults( $args ) { |
|
| 1490 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
| 1491 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
| 1489 | + protected function set_group_sub_field_defaults($args) { |
|
| 1490 | + $args['id'] = $this->group->args('id') . '_' . $this->group->index . '_' . $args['id']; |
|
| 1491 | + $args['_name'] = $this->group->args('id') . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
| 1492 | 1492 | |
| 1493 | 1493 | return $args; |
| 1494 | 1494 | } |
@@ -1501,8 +1501,8 @@ discard block |
||
| 1501 | 1501 | * @param array $args Field config array. |
| 1502 | 1502 | * @return array Field defaults. |
| 1503 | 1503 | */ |
| 1504 | - protected function get_default_field_args( $args ) { |
|
| 1505 | - $type = isset( $args['type'] ) ? $args['type'] : ''; |
|
| 1504 | + protected function get_default_field_args($args) { |
|
| 1505 | + $type = isset($args['type']) ? $args['type'] : ''; |
|
| 1506 | 1506 | |
| 1507 | 1507 | return array( |
| 1508 | 1508 | 'type' => $type, |
@@ -1529,11 +1529,11 @@ discard block |
||
| 1529 | 1529 | 'save_field' => true, // Will not save if false. |
| 1530 | 1530 | 'date_format' => 'm\/d\/Y', |
| 1531 | 1531 | 'time_format' => 'h:i A', |
| 1532 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
| 1533 | - 'preview_size' => 'file' === $type ? array( 350, 350 ) : array( 50, 50 ), |
|
| 1534 | - 'render_row_cb' => array( $this, 'render_field_callback' ), |
|
| 1535 | - 'display_cb' => array( $this, 'display_value_callback' ), |
|
| 1536 | - 'label_cb' => 'title' !== $type ? array( $this, 'label' ) : '', |
|
| 1532 | + 'description' => isset($args['desc']) ? $args['desc'] : '', |
|
| 1533 | + 'preview_size' => 'file' === $type ? array(350, 350) : array(50, 50), |
|
| 1534 | + 'render_row_cb' => array($this, 'render_field_callback'), |
|
| 1535 | + 'display_cb' => array($this, 'display_value_callback'), |
|
| 1536 | + 'label_cb' => 'title' !== $type ? array($this, 'label') : '', |
|
| 1537 | 1537 | 'column' => false, |
| 1538 | 1538 | 'js_dependencies' => array(), |
| 1539 | 1539 | 'show_in_rest' => null, |
@@ -1551,13 +1551,13 @@ discard block |
||
| 1551 | 1551 | * @param CMB2_Field $field_group (optional) CMB2_Field object (group parent). |
| 1552 | 1552 | * @return array Array of field arguments. |
| 1553 | 1553 | */ |
| 1554 | - protected function get_default_args( $field_args, $field_group = null ) { |
|
| 1555 | - $args = parent::get_default_args( array(), $this->group ); |
|
| 1554 | + protected function get_default_args($field_args, $field_group = null) { |
|
| 1555 | + $args = parent::get_default_args(array(), $this->group); |
|
| 1556 | 1556 | |
| 1557 | - if ( isset( $field_args['field_args'] ) ) { |
|
| 1558 | - $args = wp_parse_args( $field_args, $args ); |
|
| 1557 | + if (isset($field_args['field_args'])) { |
|
| 1558 | + $args = wp_parse_args($field_args, $args); |
|
| 1559 | 1559 | } else { |
| 1560 | - $args['field_args'] = wp_parse_args( $field_args, $this->args ); |
|
| 1560 | + $args['field_args'] = wp_parse_args($field_args, $this->args); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | return $args; |
@@ -1573,8 +1573,8 @@ discard block |
||
| 1573 | 1573 | * |
| 1574 | 1574 | * @return CMB2_Field The new CMB2_Field instance. |
| 1575 | 1575 | */ |
| 1576 | - public function get_field_clone( $field_args ) { |
|
| 1577 | - return $this->get_new_field( $field_args ); |
|
| 1576 | + public function get_field_clone($field_args) { |
|
| 1577 | + return $this->get_new_field($field_args); |
|
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | /** |
@@ -1585,11 +1585,11 @@ discard block |
||
| 1585 | 1585 | * @return CMB2|WP_Error If new CMB2_Field is called without cmb_id arg, returns error. |
| 1586 | 1586 | */ |
| 1587 | 1587 | public function get_cmb() { |
| 1588 | - if ( ! $this->cmb_id ) { |
|
| 1589 | - return new WP_Error( 'no_cmb_id', esc_html__( 'Sorry, this field does not have a cmb_id specified.', 'cmb2' ) ); |
|
| 1588 | + if ( ! $this->cmb_id) { |
|
| 1589 | + return new WP_Error('no_cmb_id', esc_html__('Sorry, this field does not have a cmb_id specified.', 'cmb2')); |
|
| 1590 | 1590 | } |
| 1591 | 1591 | |
| 1592 | - return cmb2_get_metabox( $this->cmb_id, $this->object_id, $this->object_type ); |
|
| 1592 | + return cmb2_get_metabox($this->cmb_id, $this->object_id, $this->object_type); |
|
| 1593 | 1593 | } |
| 1594 | 1594 | |
| 1595 | 1595 | /** |
@@ -1599,16 +1599,16 @@ discard block |
||
| 1599 | 1599 | * @param array $args Metabox field config array. |
| 1600 | 1600 | * @return array Modified field config array. |
| 1601 | 1601 | */ |
| 1602 | - protected function convert_deprecated_params( $args ) { |
|
| 1602 | + protected function convert_deprecated_params($args) { |
|
| 1603 | 1603 | |
| 1604 | - if ( isset( $args['row_classes'] ) ) { |
|
| 1604 | + if (isset($args['row_classes'])) { |
|
| 1605 | 1605 | |
| 1606 | 1606 | // We'll let this one be. |
| 1607 | 1607 | // $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_PARAM, 'row_classes', 'classes' ); |
| 1608 | 1608 | // row_classes param could be a callback. This is definitely deprecated. |
| 1609 | - if ( is_callable( $args['row_classes'] ) ) { |
|
| 1609 | + if (is_callable($args['row_classes'])) { |
|
| 1610 | 1610 | |
| 1611 | - $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'row_classes', 'classes_cb' ); |
|
| 1611 | + $this->deprecated_param(__CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'row_classes', 'classes_cb'); |
|
| 1612 | 1612 | |
| 1613 | 1613 | $args['classes_cb'] = $args['row_classes']; |
| 1614 | 1614 | $args['classes'] = null; |
@@ -1617,22 +1617,22 @@ discard block |
||
| 1617 | 1617 | $args['classes'] = $args['row_classes']; |
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | - unset( $args['row_classes'] ); |
|
| 1620 | + unset($args['row_classes']); |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | // default param can be passed a callback as well. |
| 1624 | - if ( is_callable( $args['default'] ) ) { |
|
| 1624 | + if (is_callable($args['default'])) { |
|
| 1625 | 1625 | |
| 1626 | - $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'default', 'default_cb' ); |
|
| 1626 | + $this->deprecated_param(__CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'default', 'default_cb'); |
|
| 1627 | 1627 | |
| 1628 | 1628 | $args['default_cb'] = $args['default']; |
| 1629 | 1629 | $args['default'] = null; |
| 1630 | 1630 | } |
| 1631 | 1631 | |
| 1632 | 1632 | // options param can be passed a callback as well. |
| 1633 | - if ( is_callable( $args['options'] ) ) { |
|
| 1633 | + if (is_callable($args['options'])) { |
|
| 1634 | 1634 | |
| 1635 | - $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'options', 'options_cb' ); |
|
| 1635 | + $this->deprecated_param(__CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'options', 'options_cb'); |
|
| 1636 | 1636 | |
| 1637 | 1637 | $args['options_cb'] = $args['options']; |
| 1638 | 1638 | $args['options'] = array(); |
@@ -193,31 +193,31 @@ discard block |
||
| 193 | 193 | * @param array $config Metabox config array. |
| 194 | 194 | * @param integer $object_id Optional object id. |
| 195 | 195 | */ |
| 196 | - public function __construct( $config, $object_id = 0 ) { |
|
| 196 | + public function __construct($config, $object_id = 0) { |
|
| 197 | 197 | |
| 198 | - if ( empty( $config['id'] ) ) { |
|
| 199 | - wp_die( esc_html__( 'Metabox configuration is required to have an ID parameter.', 'cmb2' ) ); |
|
| 198 | + if (empty($config['id'])) { |
|
| 199 | + wp_die(esc_html__('Metabox configuration is required to have an ID parameter.', 'cmb2')); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $this->cmb_id = $config['id']; |
| 203 | - $this->meta_box = wp_parse_args( $config, $this->mb_defaults ); |
|
| 203 | + $this->meta_box = wp_parse_args($config, $this->mb_defaults); |
|
| 204 | 204 | $this->meta_box['fields'] = array(); |
| 205 | 205 | |
| 206 | 206 | // Ensures object_types is an array. |
| 207 | - $this->set_prop( 'object_types', $this->box_types() ); |
|
| 208 | - $this->object_id( $object_id ); |
|
| 207 | + $this->set_prop('object_types', $this->box_types()); |
|
| 208 | + $this->object_id($object_id); |
|
| 209 | 209 | |
| 210 | - if ( $this->is_options_page_mb() ) { |
|
| 210 | + if ($this->is_options_page_mb()) { |
|
| 211 | 211 | $this->init_options_mb(); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $this->mb_object_type(); |
| 215 | 215 | |
| 216 | - if ( ! empty( $config['fields'] ) && is_array( $config['fields'] ) ) { |
|
| 217 | - $this->add_fields( $config['fields'] ); |
|
| 216 | + if ( ! empty($config['fields']) && is_array($config['fields'])) { |
|
| 217 | + $this->add_fields($config['fields']); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - CMB2_Boxes::add( $this ); |
|
| 220 | + CMB2_Boxes::add($this); |
|
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Hook during initiation of CMB2 object |
@@ -226,13 +226,13 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @param array $cmb This CMB2 object |
| 228 | 228 | */ |
| 229 | - do_action( "cmb2_init_{$this->cmb_id}", $this ); |
|
| 229 | + do_action("cmb2_init_{$this->cmb_id}", $this); |
|
| 230 | 230 | |
| 231 | 231 | // Hook in the hookup... how meta. |
| 232 | - add_action( "cmb2_init_hookup_{$this->cmb_id}", array( 'CMB2_Hookup', 'maybe_init_and_hookup' ) ); |
|
| 232 | + add_action("cmb2_init_hookup_{$this->cmb_id}", array('CMB2_Hookup', 'maybe_init_and_hookup')); |
|
| 233 | 233 | |
| 234 | 234 | // Hook in the rest api functionality. |
| 235 | - add_action( "cmb2_init_hookup_{$this->cmb_id}", array( 'CMB2_REST', 'maybe_init_and_hookup' ) ); |
|
| 235 | + add_action("cmb2_init_hookup_{$this->cmb_id}", array('CMB2_REST', 'maybe_init_and_hookup')); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,14 +244,14 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return CMB2 |
| 246 | 246 | */ |
| 247 | - public function show_form( $object_id = 0, $object_type = '' ) { |
|
| 248 | - $this->render_form_open( $object_id, $object_type ); |
|
| 247 | + public function show_form($object_id = 0, $object_type = '') { |
|
| 248 | + $this->render_form_open($object_id, $object_type); |
|
| 249 | 249 | |
| 250 | - foreach ( $this->prop( 'fields' ) as $field_args ) { |
|
| 251 | - $this->render_field( $field_args ); |
|
| 250 | + foreach ($this->prop('fields') as $field_args) { |
|
| 251 | + $this->render_field($field_args); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - return $this->render_form_close( $object_id, $object_type ); |
|
| 254 | + return $this->render_form_close($object_id, $object_type); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @return CMB2 |
| 266 | 266 | */ |
| 267 | - public function render_form_open( $object_id = 0, $object_type = '' ) { |
|
| 268 | - $object_type = $this->object_type( $object_type ); |
|
| 269 | - $object_id = $this->object_id( $object_id ); |
|
| 267 | + public function render_form_open($object_id = 0, $object_type = '') { |
|
| 268 | + $object_type = $this->object_type($object_type); |
|
| 269 | + $object_id = $this->object_id($object_id); |
|
| 270 | 270 | |
| 271 | 271 | echo "\n<!-- Begin CMB2 Fields -->\n"; |
| 272 | 272 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * Could also be `comment`, `user` or `options-page`. |
| 283 | 283 | * @param array $cmb This CMB2 object. |
| 284 | 284 | */ |
| 285 | - do_action( 'cmb2_before_form', $this->cmb_id, $object_id, $object_type, $this ); |
|
| 285 | + do_action('cmb2_before_form', $this->cmb_id, $object_id, $object_type, $this); |
|
| 286 | 286 | |
| 287 | 287 | /** |
| 288 | 288 | * Hook before form table begins |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | * @param int $object_id The ID of the current object |
| 298 | 298 | * @param array $cmb This CMB2 object |
| 299 | 299 | */ |
| 300 | - do_action( "cmb2_before_{$object_type}_form_{$this->cmb_id}", $object_id, $this ); |
|
| 300 | + do_action("cmb2_before_{$object_type}_form_{$this->cmb_id}", $object_id, $this); |
|
| 301 | 301 | |
| 302 | - echo '<div class="', esc_attr( $this->box_classes() ), '"><div id="cmb2-metabox-', sanitize_html_class( $this->cmb_id ), '" class="cmb2-metabox cmb-field-list">'; |
|
| 302 | + echo '<div class="', esc_attr($this->box_classes()), '"><div id="cmb2-metabox-', sanitize_html_class($this->cmb_id), '" class="cmb2-metabox cmb-field-list">'; |
|
| 303 | 303 | |
| 304 | 304 | return $this; |
| 305 | 305 | } |
@@ -312,17 +312,17 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | public function box_classes() { |
| 314 | 314 | |
| 315 | - $classes = array( 'cmb2-wrap', 'form-table' ); |
|
| 315 | + $classes = array('cmb2-wrap', 'form-table'); |
|
| 316 | 316 | |
| 317 | 317 | // Use the callback to fetch classes. |
| 318 | - if ( $added_classes = $this->get_param_callback_result( 'classes_cb' ) ) { |
|
| 319 | - $added_classes = is_array( $added_classes ) ? $added_classes : array( $added_classes ); |
|
| 320 | - $classes = array_merge( $classes, $added_classes ); |
|
| 318 | + if ($added_classes = $this->get_param_callback_result('classes_cb')) { |
|
| 319 | + $added_classes = is_array($added_classes) ? $added_classes : array($added_classes); |
|
| 320 | + $classes = array_merge($classes, $added_classes); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if ( $added_classes = $this->prop( 'classes' ) ) { |
|
| 324 | - $added_classes = is_array( $added_classes ) ? $added_classes : array( $added_classes ); |
|
| 325 | - $classes = array_merge( $classes, $added_classes ); |
|
| 323 | + if ($added_classes = $this->prop('classes')) { |
|
| 324 | + $added_classes = is_array($added_classes) ? $added_classes : array($added_classes); |
|
| 325 | + $classes = array_merge($classes, $added_classes); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -330,11 +330,11 @@ discard block |
||
| 330 | 330 | * |
| 331 | 331 | * @since 2.2.4 |
| 332 | 332 | */ |
| 333 | - if ( $this->is_alternate_context_box() ) { |
|
| 333 | + if ($this->is_alternate_context_box()) { |
|
| 334 | 334 | $context = array(); |
| 335 | 335 | |
| 336 | 336 | // Include custom class if requesting no title. |
| 337 | - if ( ! $this->prop( 'title' ) && ! $this->prop( 'remove_box_wrap' ) ) { |
|
| 337 | + if ( ! $this->prop('title') && ! $this->prop('remove_box_wrap')) { |
|
| 338 | 338 | $context[] = 'cmb2-context-wrap-no-title'; |
| 339 | 339 | } |
| 340 | 340 | |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | $context[] = 'cmb2-context-wrap'; |
| 343 | 343 | |
| 344 | 344 | // Include a context-type based context wrapper. |
| 345 | - $context[] = 'cmb2-context-wrap-' . $this->prop( 'context' ); |
|
| 345 | + $context[] = 'cmb2-context-wrap-' . $this->prop('context'); |
|
| 346 | 346 | |
| 347 | 347 | // Include an ID based context wrapper as well. |
| 348 | - $context[] = 'cmb2-context-wrap-' . $this->prop( 'id' ); |
|
| 348 | + $context[] = 'cmb2-context-wrap-' . $this->prop('id'); |
|
| 349 | 349 | |
| 350 | 350 | // And merge all the classes back into the array. |
| 351 | - $classes = array_merge( $classes, $context ); |
|
| 351 | + $classes = array_merge($classes, $context); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -359,22 +359,22 @@ discard block |
||
| 359 | 359 | * @param string $classes Array of classes for the cmb2-wrap. |
| 360 | 360 | * @param CMB2 $cmb This CMB2 object. |
| 361 | 361 | */ |
| 362 | - $classes = apply_filters( 'cmb2_wrap_classes', $classes, $this ); |
|
| 362 | + $classes = apply_filters('cmb2_wrap_classes', $classes, $this); |
|
| 363 | 363 | |
| 364 | 364 | $split = array(); |
| 365 | - foreach ( array_filter( $classes ) as $class ) { |
|
| 366 | - foreach ( explode( ' ', $class ) as $_class ) { |
|
| 365 | + foreach (array_filter($classes) as $class) { |
|
| 366 | + foreach (explode(' ', $class) as $_class) { |
|
| 367 | 367 | // Clean up & sanitize. |
| 368 | - $split[] = sanitize_html_class( strip_tags( $_class ) ); |
|
| 368 | + $split[] = sanitize_html_class(strip_tags($_class)); |
|
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | $classes = $split; |
| 372 | 372 | |
| 373 | 373 | // Remove any duplicates. |
| 374 | - $classes = array_unique( $classes ); |
|
| 374 | + $classes = array_unique($classes); |
|
| 375 | 375 | |
| 376 | 376 | // Make it a string. |
| 377 | - return implode( ' ', $classes ); |
|
| 377 | + return implode(' ', $classes); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -387,9 +387,9 @@ discard block |
||
| 387 | 387 | * |
| 388 | 388 | * @return CMB2 |
| 389 | 389 | */ |
| 390 | - public function render_form_close( $object_id = 0, $object_type = '' ) { |
|
| 391 | - $object_type = $this->object_type( $object_type ); |
|
| 392 | - $object_id = $this->object_id( $object_id ); |
|
| 390 | + public function render_form_close($object_id = 0, $object_type = '') { |
|
| 391 | + $object_type = $this->object_type($object_type); |
|
| 392 | + $object_id = $this->object_id($object_id); |
|
| 393 | 393 | |
| 394 | 394 | echo '</div></div>'; |
| 395 | 395 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @param int $object_id The ID of the current object |
| 408 | 408 | * @param array $cmb This CMB2 object |
| 409 | 409 | */ |
| 410 | - do_action( "cmb2_after_{$object_type}_form_{$this->cmb_id}", $object_id, $this ); |
|
| 410 | + do_action("cmb2_after_{$object_type}_form_{$this->cmb_id}", $object_id, $this); |
|
| 411 | 411 | |
| 412 | 412 | /** |
| 413 | 413 | * Hook after form form has been rendered |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | * Could also be `comment`, `user` or `options-page`. |
| 420 | 420 | * @param array $cmb This CMB2 object. |
| 421 | 421 | */ |
| 422 | - do_action( 'cmb2_after_form', $this->cmb_id, $object_id, $object_type, $this ); |
|
| 422 | + do_action('cmb2_after_form', $this->cmb_id, $object_id, $object_type, $this); |
|
| 423 | 423 | |
| 424 | 424 | echo "\n<!-- End CMB2 Fields -->\n"; |
| 425 | 425 | |
@@ -433,26 +433,26 @@ discard block |
||
| 433 | 433 | * @param array $field_args A field configuration array. |
| 434 | 434 | * @return mixed CMB2_Field object if successful. |
| 435 | 435 | */ |
| 436 | - public function render_field( $field_args ) { |
|
| 437 | - $field_args['context'] = $this->prop( 'context' ); |
|
| 436 | + public function render_field($field_args) { |
|
| 437 | + $field_args['context'] = $this->prop('context'); |
|
| 438 | 438 | |
| 439 | - if ( 'group' === $field_args['type'] ) { |
|
| 439 | + if ('group' === $field_args['type']) { |
|
| 440 | 440 | |
| 441 | - if ( ! isset( $field_args['show_names'] ) ) { |
|
| 442 | - $field_args['show_names'] = $this->prop( 'show_names' ); |
|
| 441 | + if ( ! isset($field_args['show_names'])) { |
|
| 442 | + $field_args['show_names'] = $this->prop('show_names'); |
|
| 443 | 443 | } |
| 444 | - $field = $this->render_group( $field_args ); |
|
| 444 | + $field = $this->render_group($field_args); |
|
| 445 | 445 | |
| 446 | - } elseif ( 'hidden' === $field_args['type'] && $this->get_field( $field_args )->should_show() ) { |
|
| 446 | + } elseif ('hidden' === $field_args['type'] && $this->get_field($field_args)->should_show()) { |
|
| 447 | 447 | // Save rendering for after the metabox. |
| 448 | - $field = $this->add_hidden_field( $field_args ); |
|
| 448 | + $field = $this->add_hidden_field($field_args); |
|
| 449 | 449 | |
| 450 | 450 | } else { |
| 451 | 451 | |
| 452 | - $field_args['show_names'] = $this->prop( 'show_names' ); |
|
| 452 | + $field_args['show_names'] = $this->prop('show_names'); |
|
| 453 | 453 | |
| 454 | 454 | // Render default fields. |
| 455 | - $field = $this->get_field( $field_args )->render_field(); |
|
| 455 | + $field = $this->get_field($field_args)->render_field(); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | return $field; |
@@ -464,21 +464,21 @@ discard block |
||
| 464 | 464 | * @param array|CMB2_Field $args Array of field arguments for a group field parent or the group parent field. |
| 465 | 465 | * @return CMB2_Field|null Group field object. |
| 466 | 466 | */ |
| 467 | - public function render_group( $args ) { |
|
| 467 | + public function render_group($args) { |
|
| 468 | 468 | $field_group = false; |
| 469 | 469 | |
| 470 | - if ( $args instanceof CMB2_Field ) { |
|
| 470 | + if ($args instanceof CMB2_Field) { |
|
| 471 | 471 | $field_group = 'group' === $args->type() ? $args : false; |
| 472 | - } elseif ( isset( $args['id'], $args['fields'] ) && is_array( $args['fields'] ) ) { |
|
| 473 | - $field_group = $this->get_field( $args ); |
|
| 472 | + } elseif (isset($args['id'], $args['fields']) && is_array($args['fields'])) { |
|
| 473 | + $field_group = $this->get_field($args); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if ( ! $field_group ) { |
|
| 476 | + if ( ! $field_group) { |
|
| 477 | 477 | return; |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | $field_group->render_context = 'edit'; |
| 481 | - $field_group->peform_param_callback( 'render_row_cb' ); |
|
| 481 | + $field_group->peform_param_callback('render_row_cb'); |
|
| 482 | 482 | |
| 483 | 483 | return $field_group; |
| 484 | 484 | } |
@@ -493,51 +493,51 @@ discard block |
||
| 493 | 493 | * |
| 494 | 494 | * @return CMB2_Field|null Group field object. |
| 495 | 495 | */ |
| 496 | - public function render_group_callback( $field_args, $field_group ) { |
|
| 496 | + public function render_group_callback($field_args, $field_group) { |
|
| 497 | 497 | |
| 498 | 498 | // If field is requesting to be conditionally shown. |
| 499 | - if ( ! $field_group || ! $field_group->should_show() ) { |
|
| 499 | + if ( ! $field_group || ! $field_group->should_show()) { |
|
| 500 | 500 | return; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | $field_group->index = 0; |
| 504 | 504 | |
| 505 | - $field_group->peform_param_callback( 'before_group' ); |
|
| 505 | + $field_group->peform_param_callback('before_group'); |
|
| 506 | 506 | |
| 507 | - $desc = $field_group->args( 'description' ); |
|
| 508 | - $label = $field_group->args( 'name' ); |
|
| 507 | + $desc = $field_group->args('description'); |
|
| 508 | + $label = $field_group->args('name'); |
|
| 509 | 509 | $group_val = (array) $field_group->value(); |
| 510 | 510 | |
| 511 | - echo '<div class="cmb-row cmb-repeat-group-wrap ', esc_attr( $field_group->row_classes() ), '" data-fieldtype="group"><div class="cmb-td"><div data-groupid="', esc_attr( $field_group->id() ), '" id="', esc_attr( $field_group->id() ), '_repeat" ', $this->group_wrap_attributes( $field_group ), '>'; |
|
| 511 | + echo '<div class="cmb-row cmb-repeat-group-wrap ', esc_attr($field_group->row_classes()), '" data-fieldtype="group"><div class="cmb-td"><div data-groupid="', esc_attr($field_group->id()), '" id="', esc_attr($field_group->id()), '_repeat" ', $this->group_wrap_attributes($field_group), '>'; |
|
| 512 | 512 | |
| 513 | - if ( $desc || $label ) { |
|
| 513 | + if ($desc || $label) { |
|
| 514 | 514 | $class = $desc ? ' cmb-group-description' : ''; |
| 515 | 515 | echo '<div class="cmb-row', $class, '"><div class="cmb-th">'; |
| 516 | - if ( $label ) { |
|
| 516 | + if ($label) { |
|
| 517 | 517 | echo '<h2 class="cmb-group-name">', $label, '</h2>'; |
| 518 | 518 | } |
| 519 | - if ( $desc ) { |
|
| 519 | + if ($desc) { |
|
| 520 | 520 | echo '<p class="cmb2-metabox-description">', $desc, '</p>'; |
| 521 | 521 | } |
| 522 | 522 | echo '</div></div>'; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - if ( ! empty( $group_val ) ) { |
|
| 526 | - foreach ( $group_val as $group_key => $field_id ) { |
|
| 527 | - $this->render_group_row( $field_group ); |
|
| 525 | + if ( ! empty($group_val)) { |
|
| 526 | + foreach ($group_val as $group_key => $field_id) { |
|
| 527 | + $this->render_group_row($field_group); |
|
| 528 | 528 | $field_group->index++; |
| 529 | 529 | } |
| 530 | 530 | } else { |
| 531 | - $this->render_group_row( $field_group ); |
|
| 531 | + $this->render_group_row($field_group); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - if ( $field_group->args( 'repeatable' ) ) { |
|
| 535 | - echo '<div class="cmb-row"><div class="cmb-td"><p class="cmb-add-row"><button type="button" data-selector="', esc_attr( $field_group->id() ), '_repeat" data-grouptitle="', esc_attr( $field_group->options( 'group_title' ) ), '" class="cmb-add-group-row button-secondary">', $field_group->options( 'add_button' ), '</button></p></div></div>'; |
|
| 534 | + if ($field_group->args('repeatable')) { |
|
| 535 | + echo '<div class="cmb-row"><div class="cmb-td"><p class="cmb-add-row"><button type="button" data-selector="', esc_attr($field_group->id()), '_repeat" data-grouptitle="', esc_attr($field_group->options('group_title')), '" class="cmb-add-group-row button-secondary">', $field_group->options('add_button'), '</button></p></div></div>'; |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | echo '</div></div></div>'; |
| 539 | 539 | |
| 540 | - $field_group->peform_param_callback( 'after_group' ); |
|
| 540 | + $field_group->peform_param_callback('after_group'); |
|
| 541 | 541 | |
| 542 | 542 | return $field_group; |
| 543 | 543 | } |
@@ -549,10 +549,10 @@ discard block |
||
| 549 | 549 | * @param CMB2_Field $field_group The group CMB2_Field object. |
| 550 | 550 | * @return string The attributes string. |
| 551 | 551 | */ |
| 552 | - public function group_wrap_attributes( $field_group ) { |
|
| 552 | + public function group_wrap_attributes($field_group) { |
|
| 553 | 553 | $classes = 'cmb-nested cmb-field-list cmb-repeatable-group'; |
| 554 | - $classes .= $field_group->options( 'sortable' ) ? ' sortable' : ' non-sortable'; |
|
| 555 | - $classes .= $field_group->args( 'repeatable' ) ? ' repeatable' : ' non-repeatable'; |
|
| 554 | + $classes .= $field_group->options('sortable') ? ' sortable' : ' non-sortable'; |
|
| 555 | + $classes .= $field_group->args('repeatable') ? ' repeatable' : ' non-repeatable'; |
|
| 556 | 556 | |
| 557 | 557 | $group_wrap_attributes = array( |
| 558 | 558 | 'class' => $classes, |
@@ -569,18 +569,18 @@ discard block |
||
| 569 | 569 | * @param string $group_wrap_attributes Current attributes array. |
| 570 | 570 | * @param CMB2_Field $field_group The group CMB2_Field object. |
| 571 | 571 | */ |
| 572 | - $group_wrap_attributes = apply_filters( 'cmb2_group_wrap_attributes', $group_wrap_attributes, $field_group ); |
|
| 572 | + $group_wrap_attributes = apply_filters('cmb2_group_wrap_attributes', $group_wrap_attributes, $field_group); |
|
| 573 | 573 | |
| 574 | 574 | $atts = array(); |
| 575 | - foreach ( $group_wrap_attributes as $att => $att_value ) { |
|
| 576 | - if ( ! CMB2_Utils::is_data_attribute( $att ) ) { |
|
| 577 | - $att_value = htmlspecialchars( $att_value ); |
|
| 575 | + foreach ($group_wrap_attributes as $att => $att_value) { |
|
| 576 | + if ( ! CMB2_Utils::is_data_attribute($att)) { |
|
| 577 | + $att_value = htmlspecialchars($att_value); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - $atts[ sanitize_html_class( $att ) ] = sanitize_text_field( $att_value ); |
|
| 580 | + $atts[sanitize_html_class($att)] = sanitize_text_field($att_value); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - return CMB2_Utils::concat_attrs( $atts ); |
|
| 583 | + return CMB2_Utils::concat_attrs($atts); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -591,46 +591,46 @@ discard block |
||
| 591 | 591 | * |
| 592 | 592 | * @return CMB2 |
| 593 | 593 | */ |
| 594 | - public function render_group_row( $field_group ) { |
|
| 594 | + public function render_group_row($field_group) { |
|
| 595 | 595 | |
| 596 | - $field_group->peform_param_callback( 'before_group_row' ); |
|
| 597 | - $closed_class = $field_group->options( 'closed' ) ? ' closed' : ''; |
|
| 598 | - $confirm_deletion = $field_group->options( 'remove_confirm' ); |
|
| 599 | - $confirm_deletion = ! empty( $confirm_deletion ) ? $confirm_deletion : ''; |
|
| 596 | + $field_group->peform_param_callback('before_group_row'); |
|
| 597 | + $closed_class = $field_group->options('closed') ? ' closed' : ''; |
|
| 598 | + $confirm_deletion = $field_group->options('remove_confirm'); |
|
| 599 | + $confirm_deletion = ! empty($confirm_deletion) ? $confirm_deletion : ''; |
|
| 600 | 600 | |
| 601 | 601 | echo ' |
| 602 | 602 | <div id="cmb-group-', $field_group->id(), '-', $field_group->index, '" class="postbox cmb-row cmb-repeatable-grouping', $closed_class, '" data-iterator="', $field_group->index, '">'; |
| 603 | 603 | |
| 604 | - if ( $field_group->args( 'repeatable' ) ) { |
|
| 605 | - echo '<button type="button" data-selector="', $field_group->id(), '_repeat" data-confirm="', esc_attr( $confirm_deletion ), '" class="dashicons-before dashicons-no-alt cmb-remove-group-row" title="', esc_attr( $field_group->options( 'remove_button' ) ), '"></button>'; |
|
| 604 | + if ($field_group->args('repeatable')) { |
|
| 605 | + echo '<button type="button" data-selector="', $field_group->id(), '_repeat" data-confirm="', esc_attr($confirm_deletion), '" class="dashicons-before dashicons-no-alt cmb-remove-group-row" title="', esc_attr($field_group->options('remove_button')), '"></button>'; |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | echo ' |
| 609 | - <div class="cmbhandle" title="' , esc_attr__( 'Click to toggle', 'cmb2' ), '"><br></div> |
|
| 610 | - <h3 class="cmb-group-title cmbhandle-title"><span>', $field_group->replace_hash( $field_group->options( 'group_title' ) ), '</span></h3> |
|
| 609 | + <div class="cmbhandle" title="' , esc_attr__('Click to toggle', 'cmb2'), '"><br></div> |
|
| 610 | + <h3 class="cmb-group-title cmbhandle-title"><span>', $field_group->replace_hash($field_group->options('group_title')), '</span></h3> |
|
| 611 | 611 | |
| 612 | 612 | <div class="inside cmb-td cmb-nested cmb-field-list">'; |
| 613 | 613 | // Loop and render repeatable group fields. |
| 614 | - foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) { |
|
| 615 | - if ( 'hidden' === $field_args['type'] ) { |
|
| 614 | + foreach (array_values($field_group->args('fields')) as $field_args) { |
|
| 615 | + if ('hidden' === $field_args['type']) { |
|
| 616 | 616 | |
| 617 | 617 | // Save rendering for after the metabox. |
| 618 | - $this->add_hidden_field( $field_args, $field_group ); |
|
| 618 | + $this->add_hidden_field($field_args, $field_group); |
|
| 619 | 619 | |
| 620 | 620 | } else { |
| 621 | 621 | |
| 622 | - $field_args['show_names'] = $field_group->args( 'show_names' ); |
|
| 623 | - $field_args['context'] = $field_group->args( 'context' ); |
|
| 622 | + $field_args['show_names'] = $field_group->args('show_names'); |
|
| 623 | + $field_args['context'] = $field_group->args('context'); |
|
| 624 | 624 | |
| 625 | - $this->get_field( $field_args, $field_group )->render_field(); |
|
| 625 | + $this->get_field($field_args, $field_group)->render_field(); |
|
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if ( $field_group->args( 'repeatable' ) ) { |
|
| 629 | + if ($field_group->args('repeatable')) { |
|
| 630 | 630 | echo ' |
| 631 | 631 | <div class="cmb-row cmb-remove-field-row"> |
| 632 | 632 | <div class="cmb-remove-row"> |
| 633 | - <button type="button" data-selector="', $field_group->id(), '_repeat" data-confirm="', esc_attr( $confirm_deletion ), '" class="cmb-remove-group-row cmb-remove-group-row-button alignright button-secondary">', $field_group->options( 'remove_button' ), '</button> |
|
| 633 | + <button type="button" data-selector="', $field_group->id(), '_repeat" data-confirm="', esc_attr($confirm_deletion), '" class="cmb-remove-group-row cmb-remove-group-row-button alignright button-secondary">', $field_group->options('remove_button'), '</button> |
|
| 634 | 634 | </div> |
| 635 | 635 | </div> |
| 636 | 636 | '; |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | </div> |
| 641 | 641 | '; |
| 642 | 642 | |
| 643 | - $field_group->peform_param_callback( 'after_group_row' ); |
|
| 643 | + $field_group->peform_param_callback('after_group_row'); |
|
| 644 | 644 | |
| 645 | 645 | return $this; |
| 646 | 646 | } |
@@ -654,17 +654,17 @@ discard block |
||
| 654 | 654 | * @param CMB2_Field|null $field_group CMB2_Field group field object. |
| 655 | 655 | * @return CMB2_Field |
| 656 | 656 | */ |
| 657 | - public function add_hidden_field( $field_args, $field_group = null ) { |
|
| 658 | - if ( isset( $field_args['field_args'] ) ) { |
|
| 657 | + public function add_hidden_field($field_args, $field_group = null) { |
|
| 658 | + if (isset($field_args['field_args'])) { |
|
| 659 | 659 | // For back-compatibility. |
| 660 | - $field = new CMB2_Field( $field_args ); |
|
| 660 | + $field = new CMB2_Field($field_args); |
|
| 661 | 661 | } else { |
| 662 | - $field = $this->get_new_field( $field_args, $field_group ); |
|
| 662 | + $field = $this->get_new_field($field_args, $field_group); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - $types = new CMB2_Types( $field ); |
|
| 665 | + $types = new CMB2_Types($field); |
|
| 666 | 666 | |
| 667 | - if ( $field_group ) { |
|
| 667 | + if ($field_group) { |
|
| 668 | 668 | $types->iterator = $field_group->index; |
| 669 | 669 | } |
| 670 | 670 | |
@@ -681,8 +681,8 @@ discard block |
||
| 681 | 681 | * @return CMB2 |
| 682 | 682 | */ |
| 683 | 683 | public function render_hidden_fields() { |
| 684 | - if ( ! empty( $this->hidden_fields ) ) { |
|
| 685 | - foreach ( $this->hidden_fields as $hidden ) { |
|
| 684 | + if ( ! empty($this->hidden_fields)) { |
|
| 685 | + foreach ($this->hidden_fields as $hidden) { |
|
| 686 | 686 | $hidden->render(); |
| 687 | 687 | } |
| 688 | 688 | } |
@@ -697,33 +697,33 @@ discard block |
||
| 697 | 697 | * @param array $data_to_sanitize Array of field_id => value data for sanitizing (likely $_POST data). |
| 698 | 698 | * @return mixed |
| 699 | 699 | */ |
| 700 | - public function get_sanitized_values( array $data_to_sanitize ) { |
|
| 700 | + public function get_sanitized_values(array $data_to_sanitize) { |
|
| 701 | 701 | $this->data_to_save = $data_to_sanitize; |
| 702 | 702 | $stored_id = $this->object_id(); |
| 703 | 703 | |
| 704 | 704 | // We do this So CMB will sanitize our data for us, but not save it. |
| 705 | - $this->object_id( '_' ); |
|
| 705 | + $this->object_id('_'); |
|
| 706 | 706 | |
| 707 | 707 | // Ensure temp. data store is empty. |
| 708 | - cmb2_options( 0 )->set(); |
|
| 708 | + cmb2_options(0)->set(); |
|
| 709 | 709 | |
| 710 | 710 | // We want to get any taxonomy values back. |
| 711 | - add_filter( "cmb2_return_taxonomy_values_{$this->cmb_id}", '__return_true' ); |
|
| 711 | + add_filter("cmb2_return_taxonomy_values_{$this->cmb_id}", '__return_true'); |
|
| 712 | 712 | |
| 713 | 713 | // Process/save fields. |
| 714 | 714 | $this->process_fields(); |
| 715 | 715 | |
| 716 | 716 | // Put things back the way they were. |
| 717 | - remove_filter( "cmb2_return_taxonomy_values_{$this->cmb_id}", '__return_true' ); |
|
| 717 | + remove_filter("cmb2_return_taxonomy_values_{$this->cmb_id}", '__return_true'); |
|
| 718 | 718 | |
| 719 | 719 | // Get data from temp. data store. |
| 720 | - $sanitized_values = cmb2_options( 0 )->get_options(); |
|
| 720 | + $sanitized_values = cmb2_options(0)->get_options(); |
|
| 721 | 721 | |
| 722 | 722 | // Empty out temp. data store again. |
| 723 | - cmb2_options( 0 )->set(); |
|
| 723 | + cmb2_options(0)->set(); |
|
| 724 | 724 | |
| 725 | 725 | // Reset the object id. |
| 726 | - $this->object_id( $stored_id ); |
|
| 726 | + $this->object_id($stored_id); |
|
| 727 | 727 | |
| 728 | 728 | return $sanitized_values; |
| 729 | 729 | } |
@@ -738,18 +738,18 @@ discard block |
||
| 738 | 738 | * |
| 739 | 739 | * @return CMB2 |
| 740 | 740 | */ |
| 741 | - public function save_fields( $object_id = 0, $object_type = '', $data_to_save = array() ) { |
|
| 741 | + public function save_fields($object_id = 0, $object_type = '', $data_to_save = array()) { |
|
| 742 | 742 | |
| 743 | 743 | // Fall-back to $_POST data. |
| 744 | - $this->data_to_save = ! empty( $data_to_save ) ? $data_to_save : $_POST; |
|
| 745 | - $object_id = $this->object_id( $object_id ); |
|
| 746 | - $object_type = $this->object_type( $object_type ); |
|
| 744 | + $this->data_to_save = ! empty($data_to_save) ? $data_to_save : $_POST; |
|
| 745 | + $object_id = $this->object_id($object_id); |
|
| 746 | + $object_type = $this->object_type($object_type); |
|
| 747 | 747 | |
| 748 | 748 | $this->process_fields(); |
| 749 | 749 | |
| 750 | 750 | // If options page, save the updated options. |
| 751 | - if ( 'options-page' === $object_type ) { |
|
| 752 | - cmb2_options( $object_id )->set(); |
|
| 751 | + if ('options-page' === $object_type) { |
|
| 752 | + cmb2_options($object_id)->set(); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | return $this->after_save(); |
@@ -767,13 +767,13 @@ discard block |
||
| 767 | 767 | $this->pre_process(); |
| 768 | 768 | |
| 769 | 769 | // Remove the show_on properties so saving works. |
| 770 | - $this->prop( 'show_on', array() ); |
|
| 770 | + $this->prop('show_on', array()); |
|
| 771 | 771 | |
| 772 | 772 | // save field ids of those that are updated. |
| 773 | 773 | $this->updated = array(); |
| 774 | 774 | |
| 775 | - foreach ( $this->prop( 'fields' ) as $field_args ) { |
|
| 776 | - $this->process_field( $field_args ); |
|
| 775 | + foreach ($this->prop('fields') as $field_args) { |
|
| 776 | + $this->process_field($field_args); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | return $this; |
@@ -787,12 +787,12 @@ discard block |
||
| 787 | 787 | * |
| 788 | 788 | * @return CMB2 |
| 789 | 789 | */ |
| 790 | - public function process_field( $field_args ) { |
|
| 790 | + public function process_field($field_args) { |
|
| 791 | 791 | |
| 792 | - switch ( $field_args['type'] ) { |
|
| 792 | + switch ($field_args['type']) { |
|
| 793 | 793 | |
| 794 | 794 | case 'group': |
| 795 | - if ( $this->save_group( $field_args ) ) { |
|
| 795 | + if ($this->save_group($field_args)) { |
|
| 796 | 796 | $this->updated[] = $field_args['id']; |
| 797 | 797 | } |
| 798 | 798 | |
@@ -803,9 +803,9 @@ discard block |
||
| 803 | 803 | break; |
| 804 | 804 | |
| 805 | 805 | default: |
| 806 | - $field = $this->get_new_field( $field_args ); |
|
| 806 | + $field = $this->get_new_field($field_args); |
|
| 807 | 807 | |
| 808 | - if ( $field->save_field_from_data( $this->data_to_save ) ) { |
|
| 808 | + if ($field->save_field_from_data($this->data_to_save)) { |
|
| 809 | 809 | $this->updated[] = $field->id(); |
| 810 | 810 | } |
| 811 | 811 | |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | * @param array $cmb This CMB2 object |
| 839 | 839 | * @param int $object_id The ID of the current object |
| 840 | 840 | */ |
| 841 | - do_action( "cmb2_{$object_type}_process_fields_{$this->cmb_id}", $this, $this->object_id() ); |
|
| 841 | + do_action("cmb2_{$object_type}_process_fields_{$this->cmb_id}", $this, $this->object_id()); |
|
| 842 | 842 | |
| 843 | 843 | return $this; |
| 844 | 844 | } |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | * Will only include field ids that had values change. |
| 869 | 869 | * @param array $cmb This CMB2 object |
| 870 | 870 | */ |
| 871 | - do_action( "cmb2_save_{$object_type}_fields", $object_id, $this->cmb_id, $this->updated, $this ); |
|
| 871 | + do_action("cmb2_save_{$object_type}_fields", $object_id, $this->cmb_id, $this->updated, $this); |
|
| 872 | 872 | |
| 873 | 873 | /** |
| 874 | 874 | * Fires after all fields have been saved. |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | * Will only include field ids that had values change. |
| 885 | 885 | * @param array $cmb This CMB2 object |
| 886 | 886 | */ |
| 887 | - do_action( "cmb2_save_{$object_type}_fields_{$this->cmb_id}", $object_id, $this->updated, $this ); |
|
| 887 | + do_action("cmb2_save_{$object_type}_fields_{$this->cmb_id}", $object_id, $this->updated, $this); |
|
| 888 | 888 | |
| 889 | 889 | return $this; |
| 890 | 890 | } |
@@ -896,12 +896,12 @@ discard block |
||
| 896 | 896 | * @param array $args Field arguments array. |
| 897 | 897 | * @return mixed Return of CMB2_Field::update_data(). |
| 898 | 898 | */ |
| 899 | - public function save_group( $args ) { |
|
| 900 | - if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
| 899 | + public function save_group($args) { |
|
| 900 | + if ( ! isset($args['id'], $args['fields']) || ! is_array($args['fields'])) { |
|
| 901 | 901 | return; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - return $this->save_group_field( $this->get_new_field( $args ) ); |
|
| 904 | + return $this->save_group_field($this->get_new_field($args)); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -911,85 +911,85 @@ discard block |
||
| 911 | 911 | * @param CMB2_Field $field_group CMB2_Field group field object. |
| 912 | 912 | * @return mixed Return of CMB2_Field::update_data(). |
| 913 | 913 | */ |
| 914 | - public function save_group_field( $field_group ) { |
|
| 914 | + public function save_group_field($field_group) { |
|
| 915 | 915 | $base_id = $field_group->id(); |
| 916 | 916 | |
| 917 | - if ( ! isset( $this->data_to_save[ $base_id ] ) ) { |
|
| 917 | + if ( ! isset($this->data_to_save[$base_id])) { |
|
| 918 | 918 | return; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | $old = $field_group->get_data(); |
| 922 | 922 | // Check if group field has sanitization_cb. |
| 923 | - $group_vals = $field_group->sanitization_cb( $this->data_to_save[ $base_id ] ); |
|
| 923 | + $group_vals = $field_group->sanitization_cb($this->data_to_save[$base_id]); |
|
| 924 | 924 | $saved = array(); |
| 925 | 925 | |
| 926 | 926 | $field_group->index = 0; |
| 927 | 927 | $field_group->data_to_save = $this->data_to_save; |
| 928 | 928 | |
| 929 | - foreach ( array_values( $field_group->fields() ) as $field_args ) { |
|
| 930 | - if ( 'title' === $field_args['type'] ) { |
|
| 929 | + foreach (array_values($field_group->fields()) as $field_args) { |
|
| 930 | + if ('title' === $field_args['type']) { |
|
| 931 | 931 | // Don't process title fields. |
| 932 | 932 | continue; |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - $field = $this->get_new_field( $field_args, $field_group ); |
|
| 936 | - $sub_id = $field->id( true ); |
|
| 937 | - if ( empty( $saved[ $field_group->index ] ) ) { |
|
| 938 | - $saved[ $field_group->index ] = array(); |
|
| 935 | + $field = $this->get_new_field($field_args, $field_group); |
|
| 936 | + $sub_id = $field->id(true); |
|
| 937 | + if (empty($saved[$field_group->index])) { |
|
| 938 | + $saved[$field_group->index] = array(); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - foreach ( (array) $group_vals as $field_group->index => $post_vals ) { |
|
| 941 | + foreach ((array) $group_vals as $field_group->index => $post_vals) { |
|
| 942 | 942 | |
| 943 | 943 | // Get value. |
| 944 | - $new_val = isset( $group_vals[ $field_group->index ][ $sub_id ] ) |
|
| 945 | - ? $group_vals[ $field_group->index ][ $sub_id ] |
|
| 944 | + $new_val = isset($group_vals[$field_group->index][$sub_id]) |
|
| 945 | + ? $group_vals[$field_group->index][$sub_id] |
|
| 946 | 946 | : false; |
| 947 | 947 | |
| 948 | 948 | // Sanitize. |
| 949 | - $new_val = $field->sanitization_cb( $new_val ); |
|
| 949 | + $new_val = $field->sanitization_cb($new_val); |
|
| 950 | 950 | |
| 951 | - if ( is_array( $new_val ) && $field->args( 'has_supporting_data' ) ) { |
|
| 952 | - if ( $field->args( 'repeatable' ) ) { |
|
| 951 | + if (is_array($new_val) && $field->args('has_supporting_data')) { |
|
| 952 | + if ($field->args('repeatable')) { |
|
| 953 | 953 | $_new_val = array(); |
| 954 | - foreach ( $new_val as $group_index => $grouped_data ) { |
|
| 954 | + foreach ($new_val as $group_index => $grouped_data) { |
|
| 955 | 955 | // Add the supporting data to the $saved array stack. |
| 956 | - $saved[ $field_group->index ][ $grouped_data['supporting_field_id'] ][] = $grouped_data['supporting_field_value']; |
|
| 956 | + $saved[$field_group->index][$grouped_data['supporting_field_id']][] = $grouped_data['supporting_field_value']; |
|
| 957 | 957 | // Reset var to the actual value. |
| 958 | - $_new_val[ $group_index ] = $grouped_data['value']; |
|
| 958 | + $_new_val[$group_index] = $grouped_data['value']; |
|
| 959 | 959 | } |
| 960 | 960 | $new_val = $_new_val; |
| 961 | 961 | } else { |
| 962 | 962 | // Add the supporting data to the $saved array stack. |
| 963 | - $saved[ $field_group->index ][ $new_val['supporting_field_id'] ] = $new_val['supporting_field_value']; |
|
| 963 | + $saved[$field_group->index][$new_val['supporting_field_id']] = $new_val['supporting_field_value']; |
|
| 964 | 964 | // Reset var to the actual value. |
| 965 | 965 | $new_val = $new_val['value']; |
| 966 | 966 | } |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | // Get old value. |
| 970 | - $old_val = is_array( $old ) && isset( $old[ $field_group->index ][ $sub_id ] ) |
|
| 971 | - ? $old[ $field_group->index ][ $sub_id ] |
|
| 970 | + $old_val = is_array($old) && isset($old[$field_group->index][$sub_id]) |
|
| 971 | + ? $old[$field_group->index][$sub_id] |
|
| 972 | 972 | : false; |
| 973 | 973 | |
| 974 | - $is_updated = ( ! CMB2_Utils::isempty( $new_val ) && $new_val !== $old_val ); |
|
| 975 | - $is_removed = ( CMB2_Utils::isempty( $new_val ) && ! CMB2_Utils::isempty( $old_val ) ); |
|
| 974 | + $is_updated = ( ! CMB2_Utils::isempty($new_val) && $new_val !== $old_val); |
|
| 975 | + $is_removed = (CMB2_Utils::isempty($new_val) && ! CMB2_Utils::isempty($old_val)); |
|
| 976 | 976 | |
| 977 | 977 | // Compare values and add to `$updated` array. |
| 978 | - if ( $is_updated || $is_removed ) { |
|
| 978 | + if ($is_updated || $is_removed) { |
|
| 979 | 979 | $this->updated[] = $base_id . '::' . $field_group->index . '::' . $sub_id; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | // Add to `$saved` array. |
| 983 | - $saved[ $field_group->index ][ $sub_id ] = $new_val; |
|
| 983 | + $saved[$field_group->index][$sub_id] = $new_val; |
|
| 984 | 984 | |
| 985 | 985 | }// End foreach. |
| 986 | 986 | |
| 987 | - $saved[ $field_group->index ] = CMB2_Utils::filter_empty( $saved[ $field_group->index ] ); |
|
| 987 | + $saved[$field_group->index] = CMB2_Utils::filter_empty($saved[$field_group->index]); |
|
| 988 | 988 | }// End foreach. |
| 989 | 989 | |
| 990 | - $saved = CMB2_Utils::filter_empty( $saved ); |
|
| 990 | + $saved = CMB2_Utils::filter_empty($saved); |
|
| 991 | 991 | |
| 992 | - return $field_group->update_data( $saved, true ); |
|
| 992 | + return $field_group->update_data($saved, true); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | /** |
@@ -999,44 +999,44 @@ discard block |
||
| 999 | 999 | * @param integer|string $object_id Object ID. |
| 1000 | 1000 | * @return integer|string $object_id Object ID. |
| 1001 | 1001 | */ |
| 1002 | - public function object_id( $object_id = 0 ) { |
|
| 1002 | + public function object_id($object_id = 0) { |
|
| 1003 | 1003 | global $pagenow; |
| 1004 | 1004 | |
| 1005 | - if ( $object_id ) { |
|
| 1005 | + if ($object_id) { |
|
| 1006 | 1006 | $this->object_id = $object_id; |
| 1007 | 1007 | return $this->object_id; |
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | - if ( $this->object_id ) { |
|
| 1010 | + if ($this->object_id) { |
|
| 1011 | 1011 | return $this->object_id; |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | // Try to get our object ID from the global space. |
| 1015 | - switch ( $this->object_type() ) { |
|
| 1015 | + switch ($this->object_type()) { |
|
| 1016 | 1016 | case 'user': |
| 1017 | - $object_id = isset( $_REQUEST['user_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['user_id'] ) ) : $object_id; |
|
| 1018 | - $object_id = ! $object_id && 'user-new.php' !== $pagenow && isset( $GLOBALS['user_ID'] ) ? $GLOBALS['user_ID'] : $object_id; |
|
| 1017 | + $object_id = isset($_REQUEST['user_id']) ? sanitize_text_field(wp_unslash($_REQUEST['user_id'])) : $object_id; |
|
| 1018 | + $object_id = ! $object_id && 'user-new.php' !== $pagenow && isset($GLOBALS['user_ID']) ? $GLOBALS['user_ID'] : $object_id; |
|
| 1019 | 1019 | break; |
| 1020 | 1020 | |
| 1021 | 1021 | case 'comment': |
| 1022 | - $object_id = isset( $_REQUEST['c'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['c'] ) ) : $object_id; |
|
| 1023 | - $object_id = ! $object_id && isset( $GLOBALS['comments']->comment_ID ) ? $GLOBALS['comments']->comment_ID : $object_id; |
|
| 1022 | + $object_id = isset($_REQUEST['c']) ? sanitize_text_field(wp_unslash($_REQUEST['c'])) : $object_id; |
|
| 1023 | + $object_id = ! $object_id && isset($GLOBALS['comments']->comment_ID) ? $GLOBALS['comments']->comment_ID : $object_id; |
|
| 1024 | 1024 | break; |
| 1025 | 1025 | |
| 1026 | 1026 | case 'term': |
| 1027 | - $object_id = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : $object_id; |
|
| 1027 | + $object_id = isset($_REQUEST['tag_ID']) ? sanitize_text_field(wp_unslash($_REQUEST['tag_ID'])) : $object_id; |
|
| 1028 | 1028 | break; |
| 1029 | 1029 | |
| 1030 | 1030 | case 'options-page': |
| 1031 | 1031 | $key = $this->doing_options_page(); |
| 1032 | - if ( ! empty( $key ) ) { |
|
| 1032 | + if ( ! empty($key)) { |
|
| 1033 | 1033 | $object_id = $key; |
| 1034 | 1034 | } |
| 1035 | 1035 | break; |
| 1036 | 1036 | |
| 1037 | 1037 | default: |
| 1038 | - $object_id = isset( $GLOBALS['post']->ID ) ? $GLOBALS['post']->ID : $object_id; |
|
| 1039 | - $object_id = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) : $object_id; |
|
| 1038 | + $object_id = isset($GLOBALS['post']->ID) ? $GLOBALS['post']->ID : $object_id; |
|
| 1039 | + $object_id = isset($_REQUEST['post']) ? sanitize_text_field(wp_unslash($_REQUEST['post'])) : $object_id; |
|
| 1040 | 1040 | break; |
| 1041 | 1041 | } |
| 1042 | 1042 | |
@@ -1053,11 +1053,11 @@ discard block |
||
| 1053 | 1053 | * @return string Object type. |
| 1054 | 1054 | */ |
| 1055 | 1055 | public function mb_object_type() { |
| 1056 | - if ( null !== $this->mb_object_type ) { |
|
| 1056 | + if (null !== $this->mb_object_type) { |
|
| 1057 | 1057 | return $this->mb_object_type; |
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | - if ( $this->is_options_page_mb() ) { |
|
| 1060 | + if ($this->is_options_page_mb()) { |
|
| 1061 | 1061 | $this->mb_object_type = 'options-page'; |
| 1062 | 1062 | return $this->mb_object_type; |
| 1063 | 1063 | } |
@@ -1067,17 +1067,17 @@ discard block |
||
| 1067 | 1067 | $type = ''; |
| 1068 | 1068 | |
| 1069 | 1069 | // if it's an array of one, extract it. |
| 1070 | - if ( 1 === count( $registered_types ) ) { |
|
| 1071 | - $last = end( $registered_types ); |
|
| 1072 | - if ( is_string( $last ) ) { |
|
| 1070 | + if (1 === count($registered_types)) { |
|
| 1071 | + $last = end($registered_types); |
|
| 1072 | + if (is_string($last)) { |
|
| 1073 | 1073 | $type = $last; |
| 1074 | 1074 | } |
| 1075 | - } elseif ( ( $curr_type = $this->current_object_type() ) && in_array( $curr_type, $registered_types, true ) ) { |
|
| 1075 | + } elseif (($curr_type = $this->current_object_type()) && in_array($curr_type, $registered_types, true)) { |
|
| 1076 | 1076 | $type = $curr_type; |
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | // Get our object type. |
| 1080 | - switch ( $type ) { |
|
| 1080 | + switch ($type) { |
|
| 1081 | 1081 | |
| 1082 | 1082 | case 'user': |
| 1083 | 1083 | case 'comment': |
@@ -1101,8 +1101,8 @@ discard block |
||
| 1101 | 1101 | * |
| 1102 | 1102 | * @return array Object types. |
| 1103 | 1103 | */ |
| 1104 | - public function box_types( $fallback = array() ) { |
|
| 1105 | - return CMB2_Utils::ensure_array( $this->prop( 'object_types' ), $fallback ); |
|
| 1104 | + public function box_types($fallback = array()) { |
|
| 1105 | + return CMB2_Utils::ensure_array($this->prop('object_types'), $fallback); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1115,18 +1115,18 @@ discard block |
||
| 1115 | 1115 | * |
| 1116 | 1116 | * @return bool Whether given object type(s) are registered to this box. |
| 1117 | 1117 | */ |
| 1118 | - public function is_box_type( $object_types = array(), $fallback = array() ) { |
|
| 1118 | + public function is_box_type($object_types = array(), $fallback = array()) { |
|
| 1119 | 1119 | $object_types = (array) $object_types; |
| 1120 | - $box_types = $this->box_types( $fallback ); |
|
| 1120 | + $box_types = $this->box_types($fallback); |
|
| 1121 | 1121 | |
| 1122 | - if ( in_array( 'term', $box_types, true ) ) { |
|
| 1123 | - $taxonomies = CMB2_Utils::ensure_array( $this->prop( 'taxonomies' ) ); |
|
| 1124 | - $box_types = array_merge( $box_types, $taxonomies ); |
|
| 1122 | + if (in_array('term', $box_types, true)) { |
|
| 1123 | + $taxonomies = CMB2_Utils::ensure_array($this->prop('taxonomies')); |
|
| 1124 | + $box_types = array_merge($box_types, $taxonomies); |
|
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | - $found = array_intersect( $object_types, $box_types ); |
|
| 1127 | + $found = array_intersect($object_types, $box_types); |
|
| 1128 | 1128 | |
| 1129 | - return ! empty( $found ); |
|
| 1129 | + return ! empty($found); |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | /** |
@@ -1140,9 +1140,9 @@ discard block |
||
| 1140 | 1140 | $keys = $this->options_page_keys(); |
| 1141 | 1141 | $types = $this->box_types(); |
| 1142 | 1142 | |
| 1143 | - if ( empty( $keys ) ) { |
|
| 1143 | + if (empty($keys)) { |
|
| 1144 | 1144 | $keys = ''; |
| 1145 | - $types = $this->deinit_options_mb( $types ); |
|
| 1145 | + $types = $this->deinit_options_mb($types); |
|
| 1146 | 1146 | } else { |
| 1147 | 1147 | |
| 1148 | 1148 | // Make sure 'options-page' is one of the object types. |
@@ -1150,10 +1150,10 @@ discard block |
||
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | // Set/Reset the option_key property. |
| 1153 | - $this->set_prop( 'option_key', $keys ); |
|
| 1153 | + $this->set_prop('option_key', $keys); |
|
| 1154 | 1154 | |
| 1155 | 1155 | // Reset the object types. |
| 1156 | - $this->set_prop( 'object_types', array_unique( $types ) ); |
|
| 1156 | + $this->set_prop('object_types', array_unique($types)); |
|
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | 1159 | /** |
@@ -1164,19 +1164,19 @@ discard block |
||
| 1164 | 1164 | * @param array $types Array of types. |
| 1165 | 1165 | * @return array |
| 1166 | 1166 | */ |
| 1167 | - protected function deinit_options_mb( $types ) { |
|
| 1168 | - if ( isset( $this->meta_box['show_on']['key'] ) && 'options-page' === $this->meta_box['show_on']['key'] ) { |
|
| 1169 | - unset( $this->meta_box['show_on']['key'] ); |
|
| 1167 | + protected function deinit_options_mb($types) { |
|
| 1168 | + if (isset($this->meta_box['show_on']['key']) && 'options-page' === $this->meta_box['show_on']['key']) { |
|
| 1169 | + unset($this->meta_box['show_on']['key']); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | - if ( array_key_exists( 'options-page', $this->meta_box['show_on'] ) ) { |
|
| 1173 | - unset( $this->meta_box['show_on']['options-page'] ); |
|
| 1172 | + if (array_key_exists('options-page', $this->meta_box['show_on'])) { |
|
| 1173 | + unset($this->meta_box['show_on']['options-page']); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - $index = array_search( 'options-page', $types ); |
|
| 1176 | + $index = array_search('options-page', $types); |
|
| 1177 | 1177 | |
| 1178 | - if ( false !== $index ) { |
|
| 1179 | - unset( $types[ $index ] ); |
|
| 1178 | + if (false !== $index) { |
|
| 1179 | + unset($types[$index]); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | return $types; |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | return ( |
| 1193 | 1193 | // 'show_on' values checked for back-compatibility. |
| 1194 | 1194 | $this->is_old_school_options_page_mb() |
| 1195 | - || in_array( 'options-page', $this->box_types() ) |
|
| 1195 | + || in_array('options-page', $this->box_types()) |
|
| 1196 | 1196 | ); |
| 1197 | 1197 | } |
| 1198 | 1198 | |
@@ -1205,8 +1205,8 @@ discard block |
||
| 1205 | 1205 | public function is_old_school_options_page_mb() { |
| 1206 | 1206 | return ( |
| 1207 | 1207 | // 'show_on' values checked for back-compatibility. |
| 1208 | - isset( $this->meta_box['show_on']['key'] ) && 'options-page' === $this->meta_box['show_on']['key'] |
|
| 1209 | - || array_key_exists( 'options-page', $this->meta_box['show_on'] ) |
|
| 1208 | + isset($this->meta_box['show_on']['key']) && 'options-page' === $this->meta_box['show_on']['key'] |
|
| 1209 | + || array_key_exists('options-page', $this->meta_box['show_on']) |
|
| 1210 | 1210 | ); |
| 1211 | 1211 | } |
| 1212 | 1212 | |
@@ -1221,15 +1221,15 @@ discard block |
||
| 1221 | 1221 | $found_key = false; |
| 1222 | 1222 | $keys = $this->options_page_keys(); |
| 1223 | 1223 | |
| 1224 | - if ( empty( $keys ) ) { |
|
| 1224 | + if (empty($keys)) { |
|
| 1225 | 1225 | return $found_key; |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | - if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], $keys ) ) { |
|
| 1228 | + if ( ! empty($_GET['page']) && in_array($_GET['page'], $keys)) { |
|
| 1229 | 1229 | $found_key = $_GET['page']; |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | - if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $keys ) ) { |
|
| 1232 | + if ( ! empty($_POST['action']) && in_array($_POST['action'], $keys)) { |
|
| 1233 | 1233 | $found_key = $_POST['action']; |
| 1234 | 1234 | } |
| 1235 | 1235 | |
@@ -1244,25 +1244,25 @@ discard block |
||
| 1244 | 1244 | */ |
| 1245 | 1245 | public function options_page_keys() { |
| 1246 | 1246 | $key = ''; |
| 1247 | - if ( ! $this->is_options_page_mb() ) { |
|
| 1247 | + if ( ! $this->is_options_page_mb()) { |
|
| 1248 | 1248 | return $key; |
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | $values = null; |
| 1252 | - if ( ! empty( $this->meta_box['show_on']['value'] ) ) { |
|
| 1252 | + if ( ! empty($this->meta_box['show_on']['value'])) { |
|
| 1253 | 1253 | $values = $this->meta_box['show_on']['value']; |
| 1254 | - } elseif ( ! empty( $this->meta_box['show_on']['options-page'] ) ) { |
|
| 1254 | + } elseif ( ! empty($this->meta_box['show_on']['options-page'])) { |
|
| 1255 | 1255 | $values = $this->meta_box['show_on']['options-page']; |
| 1256 | - } elseif ( $this->prop( 'option_key' ) ) { |
|
| 1257 | - $values = $this->prop( 'option_key' ); |
|
| 1256 | + } elseif ($this->prop('option_key')) { |
|
| 1257 | + $values = $this->prop('option_key'); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | - if ( $values ) { |
|
| 1260 | + if ($values) { |
|
| 1261 | 1261 | $key = $values; |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | - if ( ! is_array( $key ) ) { |
|
| 1265 | - $key = array( $key ); |
|
| 1264 | + if ( ! is_array($key)) { |
|
| 1265 | + $key = array($key); |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | return $key; |
@@ -1275,13 +1275,13 @@ discard block |
||
| 1275 | 1275 | * @param string $object_type Type of object being saved. (e.g., post, user, or comment). Optional. |
| 1276 | 1276 | * @return string Object type. |
| 1277 | 1277 | */ |
| 1278 | - public function object_type( $object_type = '' ) { |
|
| 1279 | - if ( $object_type ) { |
|
| 1278 | + public function object_type($object_type = '') { |
|
| 1279 | + if ($object_type) { |
|
| 1280 | 1280 | $this->object_type = $object_type; |
| 1281 | 1281 | return $this->object_type; |
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | - if ( $this->object_type ) { |
|
| 1284 | + if ($this->object_type) { |
|
| 1285 | 1285 | return $this->object_type; |
| 1286 | 1286 | } |
| 1287 | 1287 | |
@@ -1300,24 +1300,24 @@ discard block |
||
| 1300 | 1300 | global $pagenow; |
| 1301 | 1301 | $type = 'post'; |
| 1302 | 1302 | |
| 1303 | - if ( in_array( $pagenow, array( 'user-edit.php', 'profile.php', 'user-new.php' ), true ) ) { |
|
| 1303 | + if (in_array($pagenow, array('user-edit.php', 'profile.php', 'user-new.php'), true)) { |
|
| 1304 | 1304 | $type = 'user'; |
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | - if ( in_array( $pagenow, array( 'edit-comments.php', 'comment.php' ), true ) ) { |
|
| 1307 | + if (in_array($pagenow, array('edit-comments.php', 'comment.php'), true)) { |
|
| 1308 | 1308 | $type = 'comment'; |
| 1309 | 1309 | } |
| 1310 | 1310 | |
| 1311 | - if ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) ) { |
|
| 1311 | + if (in_array($pagenow, array('edit-tags.php', 'term.php'), true)) { |
|
| 1312 | 1312 | $type = 'term'; |
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | - if ( defined( 'DOING_AJAX' ) && isset( $_POST['action'] ) && 'add-tag' === $_POST['action'] ) { |
|
| 1315 | + if (defined('DOING_AJAX') && isset($_POST['action']) && 'add-tag' === $_POST['action']) { |
|
| 1316 | 1316 | $type = 'term'; |
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | if ( |
| 1320 | - in_array( $pagenow, array( 'admin.php', 'admin-post.php' ), true ) |
|
| 1320 | + in_array($pagenow, array('admin.php', 'admin-post.php'), true) |
|
| 1321 | 1321 | && $this->doing_options_page() |
| 1322 | 1322 | ) { |
| 1323 | 1323 | $type = 'options-page'; |
@@ -1334,10 +1334,10 @@ discard block |
||
| 1334 | 1334 | * @param mixed $value Value to set if no value found. |
| 1335 | 1335 | * @return mixed Metabox config property value or false. |
| 1336 | 1336 | */ |
| 1337 | - public function set_prop( $property, $value ) { |
|
| 1338 | - $this->meta_box[ $property ] = $value; |
|
| 1337 | + public function set_prop($property, $value) { |
|
| 1338 | + $this->meta_box[$property] = $value; |
|
| 1339 | 1339 | |
| 1340 | - return $this->prop( $property ); |
|
| 1340 | + return $this->prop($property); |
|
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | /** |
@@ -1348,11 +1348,11 @@ discard block |
||
| 1348 | 1348 | * @param mixed $fallback Fallback value to set if no value found. |
| 1349 | 1349 | * @return mixed Metabox config property value or false. |
| 1350 | 1350 | */ |
| 1351 | - public function prop( $property, $fallback = null ) { |
|
| 1352 | - if ( array_key_exists( $property, $this->meta_box ) ) { |
|
| 1353 | - return $this->meta_box[ $property ]; |
|
| 1354 | - } elseif ( $fallback ) { |
|
| 1355 | - return $this->meta_box[ $property ] = $fallback; |
|
| 1351 | + public function prop($property, $fallback = null) { |
|
| 1352 | + if (array_key_exists($property, $this->meta_box)) { |
|
| 1353 | + return $this->meta_box[$property]; |
|
| 1354 | + } elseif ($fallback) { |
|
| 1355 | + return $this->meta_box[$property] = $fallback; |
|
| 1356 | 1356 | } |
| 1357 | 1357 | } |
| 1358 | 1358 | |
@@ -1367,31 +1367,31 @@ discard block |
||
| 1367 | 1367 | * |
| 1368 | 1368 | * @return CMB2_Field|false CMB2_Field object (or false). |
| 1369 | 1369 | */ |
| 1370 | - public function get_field( $field, $field_group = null, $reset_cached = false ) { |
|
| 1371 | - if ( $field instanceof CMB2_Field ) { |
|
| 1370 | + public function get_field($field, $field_group = null, $reset_cached = false) { |
|
| 1371 | + if ($field instanceof CMB2_Field) { |
|
| 1372 | 1372 | return $field; |
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | - $field_id = is_string( $field ) ? $field : $field['id']; |
|
| 1375 | + $field_id = is_string($field) ? $field : $field['id']; |
|
| 1376 | 1376 | |
| 1377 | - $parent_field_id = ! empty( $field_group ) ? $field_group->id() : ''; |
|
| 1378 | - $ids = $this->get_field_ids( $field_id, $parent_field_id ); |
|
| 1377 | + $parent_field_id = ! empty($field_group) ? $field_group->id() : ''; |
|
| 1378 | + $ids = $this->get_field_ids($field_id, $parent_field_id); |
|
| 1379 | 1379 | |
| 1380 | - if ( ! $ids ) { |
|
| 1380 | + if ( ! $ids) { |
|
| 1381 | 1381 | return false; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - list( $field_id, $sub_field_id ) = $ids; |
|
| 1384 | + list($field_id, $sub_field_id) = $ids; |
|
| 1385 | 1385 | |
| 1386 | - $index = implode( '', $ids ) . ( $field_group ? $field_group->index : '' ); |
|
| 1386 | + $index = implode('', $ids) . ($field_group ? $field_group->index : ''); |
|
| 1387 | 1387 | |
| 1388 | - if ( array_key_exists( $index, $this->fields ) && ! $reset_cached ) { |
|
| 1389 | - return $this->fields[ $index ]; |
|
| 1388 | + if (array_key_exists($index, $this->fields) && ! $reset_cached) { |
|
| 1389 | + return $this->fields[$index]; |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | - $this->fields[ $index ] = new CMB2_Field( $this->get_field_args( $field_id, $field, $sub_field_id, $field_group ) ); |
|
| 1392 | + $this->fields[$index] = new CMB2_Field($this->get_field_args($field_id, $field, $sub_field_id, $field_group)); |
|
| 1393 | 1393 | |
| 1394 | - return $this->fields[ $index ]; |
|
| 1394 | + return $this->fields[$index]; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | /** |
@@ -1404,22 +1404,22 @@ discard block |
||
| 1404 | 1404 | * @param CMB2_Field|null $field_group If a sub-field, will be the parent group CMB2_Field object. |
| 1405 | 1405 | * @return array Array of CMB2_Field arguments. |
| 1406 | 1406 | */ |
| 1407 | - public function get_field_args( $field_id, $field_args, $sub_field_id, $field_group ) { |
|
| 1407 | + public function get_field_args($field_id, $field_args, $sub_field_id, $field_group) { |
|
| 1408 | 1408 | |
| 1409 | 1409 | // Check if group is passed and if fields were added in the old-school fields array. |
| 1410 | - if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) { |
|
| 1410 | + if ($field_group && ($sub_field_id || 0 === $sub_field_id)) { |
|
| 1411 | 1411 | |
| 1412 | 1412 | // Update the fields array w/ any modified properties inherited from the group field. |
| 1413 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args; |
|
| 1413 | + $this->meta_box['fields'][$field_id]['fields'][$sub_field_id] = $field_args; |
|
| 1414 | 1414 | |
| 1415 | - return $this->get_default_args( $field_args, $field_group ); |
|
| 1415 | + return $this->get_default_args($field_args, $field_group); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | - if ( is_array( $field_args ) ) { |
|
| 1419 | - $this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] ); |
|
| 1418 | + if (is_array($field_args)) { |
|
| 1419 | + $this->meta_box['fields'][$field_id] = array_merge($field_args, $this->meta_box['fields'][$field_id]); |
|
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | - return $this->get_default_args( $this->meta_box['fields'][ $field_id ] ); |
|
| 1422 | + return $this->get_default_args($this->meta_box['fields'][$field_id]); |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1430,8 +1430,8 @@ discard block |
||
| 1430 | 1430 | * @param CMB2_Field $field_group (optional) CMB2_Field object (group parent). |
| 1431 | 1431 | * @return array Array of field arguments. |
| 1432 | 1432 | */ |
| 1433 | - protected function get_default_args( $field_args, $field_group = null ) { |
|
| 1434 | - if ( $field_group ) { |
|
| 1433 | + protected function get_default_args($field_args, $field_group = null) { |
|
| 1434 | + if ($field_group) { |
|
| 1435 | 1435 | $args = array( |
| 1436 | 1436 | 'field_args' => $field_args, |
| 1437 | 1437 | 'group_field' => $field_group, |
@@ -1457,21 +1457,21 @@ discard block |
||
| 1457 | 1457 | * |
| 1458 | 1458 | * @return CMB2 |
| 1459 | 1459 | */ |
| 1460 | - protected function add_fields( $fields, $parent_field_id = null ) { |
|
| 1461 | - foreach ( $fields as $field ) { |
|
| 1460 | + protected function add_fields($fields, $parent_field_id = null) { |
|
| 1461 | + foreach ($fields as $field) { |
|
| 1462 | 1462 | |
| 1463 | 1463 | $sub_fields = false; |
| 1464 | - if ( array_key_exists( 'fields', $field ) ) { |
|
| 1464 | + if (array_key_exists('fields', $field)) { |
|
| 1465 | 1465 | $sub_fields = $field['fields']; |
| 1466 | - unset( $field['fields'] ); |
|
| 1466 | + unset($field['fields']); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | $field_id = $parent_field_id |
| 1470 | - ? $this->add_group_field( $parent_field_id, $field ) |
|
| 1471 | - : $this->add_field( $field ); |
|
| 1470 | + ? $this->add_group_field($parent_field_id, $field) |
|
| 1471 | + : $this->add_field($field); |
|
| 1472 | 1472 | |
| 1473 | - if ( $sub_fields ) { |
|
| 1474 | - $this->add_fields( $sub_fields, $field_id ); |
|
| 1473 | + if ($sub_fields) { |
|
| 1474 | + $this->add_fields($sub_fields, $field_id); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | } |
| 1477 | 1477 | |
@@ -1486,8 +1486,8 @@ discard block |
||
| 1486 | 1486 | * @param int $position (optional) Position of metabox. 1 for first, etc. |
| 1487 | 1487 | * @return string|false Field id or false. |
| 1488 | 1488 | */ |
| 1489 | - public function add_field( array $field, $position = 0 ) { |
|
| 1490 | - if ( ! array_key_exists( 'id', $field ) ) { |
|
| 1489 | + public function add_field(array $field, $position = 0) { |
|
| 1490 | + if ( ! array_key_exists('id', $field)) { |
|
| 1491 | 1491 | return false; |
| 1492 | 1492 | } |
| 1493 | 1493 | |
@@ -1509,28 +1509,28 @@ discard block |
||
| 1509 | 1509 | * @param int $position (optional) Position of metabox. 1 for first, etc. |
| 1510 | 1510 | * @return mixed Array of parent/field ids or false. |
| 1511 | 1511 | */ |
| 1512 | - public function add_group_field( $parent_field_id, array $field, $position = 0 ) { |
|
| 1513 | - if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) { |
|
| 1512 | + public function add_group_field($parent_field_id, array $field, $position = 0) { |
|
| 1513 | + if ( ! array_key_exists($parent_field_id, $this->meta_box['fields'])) { |
|
| 1514 | 1514 | return false; |
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | - $parent_field = $this->meta_box['fields'][ $parent_field_id ]; |
|
| 1517 | + $parent_field = $this->meta_box['fields'][$parent_field_id]; |
|
| 1518 | 1518 | |
| 1519 | - if ( 'group' !== $parent_field['type'] ) { |
|
| 1519 | + if ('group' !== $parent_field['type']) { |
|
| 1520 | 1520 | return false; |
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | - if ( ! isset( $parent_field['fields'] ) ) { |
|
| 1524 | - $this->meta_box['fields'][ $parent_field_id ]['fields'] = array(); |
|
| 1523 | + if ( ! isset($parent_field['fields'])) { |
|
| 1524 | + $this->meta_box['fields'][$parent_field_id]['fields'] = array(); |
|
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | $this->_add_field_to_array( |
| 1528 | 1528 | $field, |
| 1529 | - $this->meta_box['fields'][ $parent_field_id ]['fields'], |
|
| 1529 | + $this->meta_box['fields'][$parent_field_id]['fields'], |
|
| 1530 | 1530 | $position |
| 1531 | 1531 | ); |
| 1532 | 1532 | |
| 1533 | - return array( $parent_field_id, $field['id'] ); |
|
| 1533 | + return array($parent_field_id, $field['id']); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | /** |
@@ -1540,13 +1540,13 @@ discard block |
||
| 1540 | 1540 | * @param array $field Metabox field config array. |
| 1541 | 1541 | * @return void |
| 1542 | 1542 | */ |
| 1543 | - protected function field_actions( $field ) { |
|
| 1544 | - switch ( $field['type'] ) { |
|
| 1543 | + protected function field_actions($field) { |
|
| 1544 | + switch ($field['type']) { |
|
| 1545 | 1545 | case 'file': |
| 1546 | 1546 | case 'file_list': |
| 1547 | 1547 | |
| 1548 | 1548 | // Initiate attachment JS hooks. |
| 1549 | - add_filter( 'wp_prepare_attachment_for_js', array( 'CMB2_Type_File_Base', 'prepare_image_sizes_for_js' ), 10, 3 ); |
|
| 1549 | + add_filter('wp_prepare_attachment_for_js', array('CMB2_Type_File_Base', 'prepare_image_sizes_for_js'), 10, 3); |
|
| 1550 | 1550 | break; |
| 1551 | 1551 | |
| 1552 | 1552 | case 'oembed': |
@@ -1555,8 +1555,8 @@ discard block |
||
| 1555 | 1555 | break; |
| 1556 | 1556 | |
| 1557 | 1557 | case 'group': |
| 1558 | - if ( empty( $field['render_row_cb'] ) ) { |
|
| 1559 | - $field['render_row_cb'] = array( $this, 'render_group_callback' ); |
|
| 1558 | + if (empty($field['render_row_cb'])) { |
|
| 1559 | + $field['render_row_cb'] = array($this, 'render_group_callback'); |
|
| 1560 | 1560 | } |
| 1561 | 1561 | break; |
| 1562 | 1562 | case 'colorpicker': |
@@ -1564,16 +1564,16 @@ discard block |
||
| 1564 | 1564 | // https://github.com/JayWood/CMB2_RGBa_Picker |
| 1565 | 1565 | // Dequeue the rgba_colorpicker custom field script if it is used, |
| 1566 | 1566 | // since we now enqueue our own more current version. |
| 1567 | - add_action( 'admin_enqueue_scripts', array( 'CMB2_Type_Colorpicker', 'dequeue_rgba_colorpicker_script' ), 99 ); |
|
| 1567 | + add_action('admin_enqueue_scripts', array('CMB2_Type_Colorpicker', 'dequeue_rgba_colorpicker_script'), 99); |
|
| 1568 | 1568 | break; |
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | - if ( isset( $field['column'] ) && false !== $field['column'] ) { |
|
| 1572 | - $field = $this->define_field_column( $field ); |
|
| 1571 | + if (isset($field['column']) && false !== $field['column']) { |
|
| 1572 | + $field = $this->define_field_column($field); |
|
| 1573 | 1573 | } |
| 1574 | 1574 | |
| 1575 | - if ( isset( $field['taxonomy'] ) && ! empty( $field['remove_default'] ) ) { |
|
| 1576 | - $this->tax_metaboxes_to_remove[ $field['taxonomy'] ] = $field['taxonomy']; |
|
| 1575 | + if (isset($field['taxonomy']) && ! empty($field['remove_default'])) { |
|
| 1576 | + $this->tax_metaboxes_to_remove[$field['taxonomy']] = $field['taxonomy']; |
|
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | return $field; |
@@ -1586,15 +1586,15 @@ discard block |
||
| 1586 | 1586 | * @param array $field Metabox field config array. |
| 1587 | 1587 | * @return array Modified metabox field config array. |
| 1588 | 1588 | */ |
| 1589 | - protected function define_field_column( array $field ) { |
|
| 1589 | + protected function define_field_column(array $field) { |
|
| 1590 | 1590 | $this->has_columns = true; |
| 1591 | 1591 | |
| 1592 | - $column = is_array( $field['column'] ) ? $field['column'] : array(); |
|
| 1592 | + $column = is_array($field['column']) ? $field['column'] : array(); |
|
| 1593 | 1593 | |
| 1594 | - $field['column'] = wp_parse_args( $column, array( |
|
| 1595 | - 'name' => isset( $field['name'] ) ? $field['name'] : '', |
|
| 1594 | + $field['column'] = wp_parse_args($column, array( |
|
| 1595 | + 'name' => isset($field['name']) ? $field['name'] : '', |
|
| 1596 | 1596 | 'position' => false, |
| 1597 | - ) ); |
|
| 1597 | + )); |
|
| 1598 | 1598 | |
| 1599 | 1599 | return $field; |
| 1600 | 1600 | } |
@@ -1607,13 +1607,13 @@ discard block |
||
| 1607 | 1607 | * @param array $fields Array (passed by reference) to append the field (array) to. |
| 1608 | 1608 | * @param integer $position Optionally specify a position in the array to be inserted. |
| 1609 | 1609 | */ |
| 1610 | - protected function _add_field_to_array( $field, &$fields, $position = 0 ) { |
|
| 1611 | - $field = $this->field_actions( $field ); |
|
| 1610 | + protected function _add_field_to_array($field, &$fields, $position = 0) { |
|
| 1611 | + $field = $this->field_actions($field); |
|
| 1612 | 1612 | |
| 1613 | - if ( $position ) { |
|
| 1614 | - CMB2_Utils::array_insert( $fields, array( $field['id'] => $field ), $position ); |
|
| 1613 | + if ($position) { |
|
| 1614 | + CMB2_Utils::array_insert($fields, array($field['id'] => $field), $position); |
|
| 1615 | 1615 | } else { |
| 1616 | - $fields[ $field['id'] ] = $field; |
|
| 1616 | + $fields[$field['id']] = $field; |
|
| 1617 | 1617 | } |
| 1618 | 1618 | } |
| 1619 | 1619 | |
@@ -1625,27 +1625,27 @@ discard block |
||
| 1625 | 1625 | * @param string $parent_field_id (optional) The field id of the group field to remove field from. |
| 1626 | 1626 | * @return bool True if field was removed. |
| 1627 | 1627 | */ |
| 1628 | - public function remove_field( $field_id, $parent_field_id = '' ) { |
|
| 1629 | - $ids = $this->get_field_ids( $field_id, $parent_field_id ); |
|
| 1628 | + public function remove_field($field_id, $parent_field_id = '') { |
|
| 1629 | + $ids = $this->get_field_ids($field_id, $parent_field_id); |
|
| 1630 | 1630 | |
| 1631 | - if ( ! $ids ) { |
|
| 1631 | + if ( ! $ids) { |
|
| 1632 | 1632 | return false; |
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | - list( $field_id, $sub_field_id ) = $ids; |
|
| 1635 | + list($field_id, $sub_field_id) = $ids; |
|
| 1636 | 1636 | |
| 1637 | - unset( $this->fields[ implode( '', $ids ) ] ); |
|
| 1637 | + unset($this->fields[implode('', $ids)]); |
|
| 1638 | 1638 | |
| 1639 | - if ( ! $sub_field_id ) { |
|
| 1640 | - unset( $this->meta_box['fields'][ $field_id ] ); |
|
| 1639 | + if ( ! $sub_field_id) { |
|
| 1640 | + unset($this->meta_box['fields'][$field_id]); |
|
| 1641 | 1641 | return true; |
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | - if ( isset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ) ) { |
|
| 1645 | - unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ); |
|
| 1644 | + if (isset($this->fields[$field_id]->args['fields'][$sub_field_id])) { |
|
| 1645 | + unset($this->fields[$field_id]->args['fields'][$sub_field_id]); |
|
| 1646 | 1646 | } |
| 1647 | - if ( isset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ) ) { |
|
| 1648 | - unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ); |
|
| 1647 | + if (isset($this->meta_box['fields'][$field_id]['fields'][$sub_field_id])) { |
|
| 1648 | + unset($this->meta_box['fields'][$field_id]['fields'][$sub_field_id]); |
|
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | 1651 | return true; |
@@ -1661,21 +1661,21 @@ discard block |
||
| 1661 | 1661 | * @param string $parent_field_id (optional) The field id of the group field to remove field from. |
| 1662 | 1662 | * @return mixed Field id. Strict compare to false, as success can return a falsey value (like 0). |
| 1663 | 1663 | */ |
| 1664 | - public function update_field_property( $field_id, $property, $value, $parent_field_id = '' ) { |
|
| 1665 | - $ids = $this->get_field_ids( $field_id, $parent_field_id ); |
|
| 1664 | + public function update_field_property($field_id, $property, $value, $parent_field_id = '') { |
|
| 1665 | + $ids = $this->get_field_ids($field_id, $parent_field_id); |
|
| 1666 | 1666 | |
| 1667 | - if ( ! $ids ) { |
|
| 1667 | + if ( ! $ids) { |
|
| 1668 | 1668 | return false; |
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | - list( $field_id, $sub_field_id ) = $ids; |
|
| 1671 | + list($field_id, $sub_field_id) = $ids; |
|
| 1672 | 1672 | |
| 1673 | - if ( ! $sub_field_id ) { |
|
| 1674 | - $this->meta_box['fields'][ $field_id ][ $property ] = $value; |
|
| 1673 | + if ( ! $sub_field_id) { |
|
| 1674 | + $this->meta_box['fields'][$field_id][$property] = $value; |
|
| 1675 | 1675 | return $field_id; |
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value; |
|
| 1678 | + $this->meta_box['fields'][$field_id]['fields'][$sub_field_id][$property] = $value; |
|
| 1679 | 1679 | return $field_id; |
| 1680 | 1680 | } |
| 1681 | 1681 | |
@@ -1687,32 +1687,32 @@ discard block |
||
| 1687 | 1687 | * @param string $parent_field_id (optional) Parent field id. |
| 1688 | 1688 | * @return mixed Array of field/parent ids, or false. |
| 1689 | 1689 | */ |
| 1690 | - public function get_field_ids( $field_id, $parent_field_id = '' ) { |
|
| 1690 | + public function get_field_ids($field_id, $parent_field_id = '') { |
|
| 1691 | 1691 | $sub_field_id = $parent_field_id ? $field_id : ''; |
| 1692 | 1692 | $field_id = $parent_field_id ? $parent_field_id : $field_id; |
| 1693 | - $fields =& $this->meta_box['fields']; |
|
| 1693 | + $fields = & $this->meta_box['fields']; |
|
| 1694 | 1694 | |
| 1695 | - if ( ! array_key_exists( $field_id, $fields ) ) { |
|
| 1696 | - $field_id = $this->search_old_school_array( $field_id, $fields ); |
|
| 1695 | + if ( ! array_key_exists($field_id, $fields)) { |
|
| 1696 | + $field_id = $this->search_old_school_array($field_id, $fields); |
|
| 1697 | 1697 | } |
| 1698 | 1698 | |
| 1699 | - if ( false === $field_id ) { |
|
| 1699 | + if (false === $field_id) { |
|
| 1700 | 1700 | return false; |
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | - if ( ! $sub_field_id ) { |
|
| 1704 | - return array( $field_id, $sub_field_id ); |
|
| 1703 | + if ( ! $sub_field_id) { |
|
| 1704 | + return array($field_id, $sub_field_id); |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | - if ( 'group' !== $fields[ $field_id ]['type'] ) { |
|
| 1707 | + if ('group' !== $fields[$field_id]['type']) { |
|
| 1708 | 1708 | return false; |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | - if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) { |
|
| 1712 | - $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] ); |
|
| 1711 | + if ( ! array_key_exists($sub_field_id, $fields[$field_id]['fields'])) { |
|
| 1712 | + $sub_field_id = $this->search_old_school_array($sub_field_id, $fields[$field_id]['fields']); |
|
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | - return false === $sub_field_id ? false : array( $field_id, $sub_field_id ); |
|
| 1715 | + return false === $sub_field_id ? false : array($field_id, $sub_field_id); |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | /** |
@@ -1723,9 +1723,9 @@ discard block |
||
| 1723 | 1723 | * @param array $fields Array of fields to search. |
| 1724 | 1724 | * @return mixed Field index or false. |
| 1725 | 1725 | */ |
| 1726 | - public function search_old_school_array( $field_id, $fields ) { |
|
| 1727 | - $ids = wp_list_pluck( $fields, 'id' ); |
|
| 1728 | - $index = array_search( $field_id, $ids ); |
|
| 1726 | + public function search_old_school_array($field_id, $fields) { |
|
| 1727 | + $ids = wp_list_pluck($fields, 'id'); |
|
| 1728 | + $index = array_search($field_id, $ids); |
|
| 1729 | 1729 | return false !== $index ? $index : false; |
| 1730 | 1730 | } |
| 1731 | 1731 | |
@@ -1737,8 +1737,8 @@ discard block |
||
| 1737 | 1737 | * @param mixed $additional_params Any additoinal parameters which should be passed to the callback. |
| 1738 | 1738 | * @return mixed Return of the callback function. |
| 1739 | 1739 | */ |
| 1740 | - public function do_callback( $cb, $additional_params = null ) { |
|
| 1741 | - return call_user_func( $cb, $this, $additional_params ); |
|
| 1740 | + public function do_callback($cb, $additional_params = null) { |
|
| 1741 | + return call_user_func($cb, $this, $additional_params); |
|
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | 1744 | /** |
@@ -1748,7 +1748,7 @@ discard block |
||
| 1748 | 1748 | * @return void |
| 1749 | 1749 | */ |
| 1750 | 1750 | public function nonce_field() { |
| 1751 | - wp_nonce_field( $this->nonce(), $this->nonce(), false, true ); |
|
| 1751 | + wp_nonce_field($this->nonce(), $this->nonce(), false, true); |
|
| 1752 | 1752 | } |
| 1753 | 1753 | |
| 1754 | 1754 | /** |
@@ -1758,8 +1758,8 @@ discard block |
||
| 1758 | 1758 | * @return string unique nonce string. |
| 1759 | 1759 | */ |
| 1760 | 1760 | public function nonce() { |
| 1761 | - if ( ! $this->generated_nonce ) { |
|
| 1762 | - $this->generated_nonce = sanitize_html_class( 'nonce_' . basename( __FILE__ ) . $this->cmb_id ); |
|
| 1761 | + if ( ! $this->generated_nonce) { |
|
| 1762 | + $this->generated_nonce = sanitize_html_class('nonce_' . basename(__FILE__) . $this->cmb_id); |
|
| 1763 | 1763 | } |
| 1764 | 1764 | |
| 1765 | 1765 | return $this->generated_nonce; |
@@ -1773,7 +1773,7 @@ discard block |
||
| 1773 | 1773 | * @return bool |
| 1774 | 1774 | */ |
| 1775 | 1775 | public function was_updated() { |
| 1776 | - return ! empty( $this->updated ); |
|
| 1776 | + return ! empty($this->updated); |
|
| 1777 | 1777 | } |
| 1778 | 1778 | |
| 1779 | 1779 | /** |
@@ -1784,7 +1784,7 @@ discard block |
||
| 1784 | 1784 | * @return bool |
| 1785 | 1785 | */ |
| 1786 | 1786 | public function is_alternate_context_box() { |
| 1787 | - return $this->prop( 'context' ) && in_array( $this->prop( 'context' ), array( 'form_top', 'before_permalink', 'after_title', 'after_editor' ), true ); |
|
| 1787 | + return $this->prop('context') && in_array($this->prop('context'), array('form_top', 'before_permalink', 'after_title', 'after_editor'), true); |
|
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | 1790 | /** |
@@ -1794,14 +1794,14 @@ discard block |
||
| 1794 | 1794 | * @throws Exception Throws an exception if the field is invalid. |
| 1795 | 1795 | * @return mixed |
| 1796 | 1796 | */ |
| 1797 | - public function __get( $property ) { |
|
| 1798 | - switch ( $property ) { |
|
| 1797 | + public function __get($property) { |
|
| 1798 | + switch ($property) { |
|
| 1799 | 1799 | case 'updated': |
| 1800 | 1800 | case 'has_columns': |
| 1801 | 1801 | case 'tax_metaboxes_to_remove': |
| 1802 | 1802 | return $this->{$property}; |
| 1803 | 1803 | default: |
| 1804 | - return parent::__get( $property ); |
|
| 1804 | + return parent::__get($property); |
|
| 1805 | 1805 | } |
| 1806 | 1806 | } |
| 1807 | 1807 | |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return CMB2_Hookup_Base $hookup The hookup object. |
| 64 | 64 | */ |
| 65 | - public static function maybe_init_and_hookup( CMB2 $cmb ) { |
|
| 66 | - if ( $cmb->prop( 'hookup' ) ) { |
|
| 65 | + public static function maybe_init_and_hookup(CMB2 $cmb) { |
|
| 66 | + if ($cmb->prop('hookup')) { |
|
| 67 | 67 | |
| 68 | - $hookup = new self( $cmb ); |
|
| 68 | + $hookup = new self($cmb); |
|
| 69 | 69 | |
| 70 | 70 | // Hook in the hookup... how meta. |
| 71 | 71 | return $hookup->universal_hooks(); |
@@ -75,18 +75,18 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function universal_hooks() { |
| 78 | - foreach ( get_class_methods( 'CMB2_Show_Filters' ) as $filter ) { |
|
| 79 | - add_filter( 'cmb2_show_on', array( 'CMB2_Show_Filters', $filter ), 10, 3 ); |
|
| 78 | + foreach (get_class_methods('CMB2_Show_Filters') as $filter) { |
|
| 79 | + add_filter('cmb2_show_on', array('CMB2_Show_Filters', $filter), 10, 3); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if ( is_admin() ) { |
|
| 82 | + if (is_admin()) { |
|
| 83 | 83 | // Register our scripts and styles for cmb. |
| 84 | - $this->once( 'admin_enqueue_scripts', array( __CLASS__, 'register_scripts' ), 8 ); |
|
| 85 | - $this->once( 'admin_enqueue_scripts', array( $this, 'do_scripts' ) ); |
|
| 84 | + $this->once('admin_enqueue_scripts', array(__CLASS__, 'register_scripts'), 8); |
|
| 85 | + $this->once('admin_enqueue_scripts', array($this, 'do_scripts')); |
|
| 86 | 86 | |
| 87 | 87 | $this->maybe_enqueue_column_display_styles(); |
| 88 | 88 | |
| 89 | - switch ( $this->object_type ) { |
|
| 89 | + switch ($this->object_type) { |
|
| 90 | 90 | case 'post': |
| 91 | 91 | return $this->post_hooks(); |
| 92 | 92 | case 'comment': |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | public function post_hooks() { |
| 107 | 107 | |
| 108 | 108 | // Fetch the context we set in our call. |
| 109 | - $context = $this->cmb->prop( 'context' ) ? $this->cmb->prop( 'context' ) : 'normal'; |
|
| 109 | + $context = $this->cmb->prop('context') ? $this->cmb->prop('context') : 'normal'; |
|
| 110 | 110 | |
| 111 | 111 | // Call the proper hook based on the context provided. |
| 112 | - switch ( $context ) { |
|
| 112 | + switch ($context) { |
|
| 113 | 113 | |
| 114 | 114 | case 'form_top': |
| 115 | - add_action( 'edit_form_top', array( $this, 'add_context_metaboxes' ) ); |
|
| 115 | + add_action('edit_form_top', array($this, 'add_context_metaboxes')); |
|
| 116 | 116 | break; |
| 117 | 117 | |
| 118 | 118 | case 'before_permalink': |
| 119 | - add_action( 'edit_form_before_permalink', array( $this, 'add_context_metaboxes' ) ); |
|
| 119 | + add_action('edit_form_before_permalink', array($this, 'add_context_metaboxes')); |
|
| 120 | 120 | break; |
| 121 | 121 | |
| 122 | 122 | case 'after_title': |
| 123 | - add_action( 'edit_form_after_title', array( $this, 'add_context_metaboxes' ) ); |
|
| 123 | + add_action('edit_form_after_title', array($this, 'add_context_metaboxes')); |
|
| 124 | 124 | break; |
| 125 | 125 | |
| 126 | 126 | case 'after_editor': |
| 127 | - add_action( 'edit_form_after_editor', array( $this, 'add_context_metaboxes' ) ); |
|
| 127 | + add_action('edit_form_after_editor', array($this, 'add_context_metaboxes')); |
|
| 128 | 128 | break; |
| 129 | 129 | |
| 130 | 130 | default: |
| 131 | - add_action( 'add_meta_boxes', array( $this, 'add_metaboxes' ) ); |
|
| 131 | + add_action('add_meta_boxes', array($this, 'add_metaboxes')); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - add_action( 'add_meta_boxes', array( $this, 'remove_default_tax_metaboxes' ) ); |
|
| 135 | - add_action( 'add_attachment', array( $this, 'save_post' ) ); |
|
| 136 | - add_action( 'edit_attachment', array( $this, 'save_post' ) ); |
|
| 137 | - add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); |
|
| 134 | + add_action('add_meta_boxes', array($this, 'remove_default_tax_metaboxes')); |
|
| 135 | + add_action('add_attachment', array($this, 'save_post')); |
|
| 136 | + add_action('edit_attachment', array($this, 'save_post')); |
|
| 137 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 138 | 138 | |
| 139 | - if ( $this->cmb->has_columns ) { |
|
| 140 | - foreach ( $this->cmb->box_types() as $post_type ) { |
|
| 141 | - add_filter( "manage_{$post_type}_posts_columns", array( $this, 'register_column_headers' ) ); |
|
| 142 | - add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'column_display' ), 10, 2 ); |
|
| 143 | - add_filter( "manage_edit-{$post_type}_sortable_columns", array( $this, 'columns_sortable' ) ); |
|
| 144 | - add_action( 'pre_get_posts', array( $this, 'columns_sortable_orderby' ) ); |
|
| 139 | + if ($this->cmb->has_columns) { |
|
| 140 | + foreach ($this->cmb->box_types() as $post_type) { |
|
| 141 | + add_filter("manage_{$post_type}_posts_columns", array($this, 'register_column_headers')); |
|
| 142 | + add_action("manage_{$post_type}_posts_custom_column", array($this, 'column_display'), 10, 2); |
|
| 143 | + add_filter("manage_edit-{$post_type}_sortable_columns", array($this, 'columns_sortable')); |
|
| 144 | + add_action('pre_get_posts', array($this, 'columns_sortable_orderby')); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | public function comment_hooks() { |
| 152 | - add_action( 'add_meta_boxes_comment', array( $this, 'add_metaboxes' ) ); |
|
| 153 | - add_action( 'edit_comment', array( $this, 'save_comment' ) ); |
|
| 152 | + add_action('add_meta_boxes_comment', array($this, 'add_metaboxes')); |
|
| 153 | + add_action('edit_comment', array($this, 'save_comment')); |
|
| 154 | 154 | |
| 155 | - if ( $this->cmb->has_columns ) { |
|
| 156 | - add_filter( 'manage_edit-comments_columns', array( $this, 'register_column_headers' ) ); |
|
| 157 | - add_action( 'manage_comments_custom_column', array( $this, 'column_display' ), 10, 3 ); |
|
| 158 | - add_filter( "manage_edit-comments_sortable_columns", array( $this, 'columns_sortable' ) ); |
|
| 159 | - add_action( 'pre_get_posts', array( $this, 'columns_sortable_orderby' ) ); |
|
| 155 | + if ($this->cmb->has_columns) { |
|
| 156 | + add_filter('manage_edit-comments_columns', array($this, 'register_column_headers')); |
|
| 157 | + add_action('manage_comments_custom_column', array($this, 'column_display'), 10, 3); |
|
| 158 | + add_filter("manage_edit-comments_sortable_columns", array($this, 'columns_sortable')); |
|
| 159 | + add_action('pre_get_posts', array($this, 'columns_sortable_orderby')); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | return $this; |
@@ -165,43 +165,43 @@ discard block |
||
| 165 | 165 | public function user_hooks() { |
| 166 | 166 | $priority = $this->get_priority(); |
| 167 | 167 | |
| 168 | - add_action( 'show_user_profile', array( $this, 'user_metabox' ), $priority ); |
|
| 169 | - add_action( 'edit_user_profile', array( $this, 'user_metabox' ), $priority ); |
|
| 170 | - add_action( 'user_new_form', array( $this, 'user_new_metabox' ), $priority ); |
|
| 168 | + add_action('show_user_profile', array($this, 'user_metabox'), $priority); |
|
| 169 | + add_action('edit_user_profile', array($this, 'user_metabox'), $priority); |
|
| 170 | + add_action('user_new_form', array($this, 'user_new_metabox'), $priority); |
|
| 171 | 171 | |
| 172 | - add_action( 'personal_options_update', array( $this, 'save_user' ) ); |
|
| 173 | - add_action( 'edit_user_profile_update', array( $this, 'save_user' ) ); |
|
| 174 | - add_action( 'user_register', array( $this, 'save_user' ) ); |
|
| 172 | + add_action('personal_options_update', array($this, 'save_user')); |
|
| 173 | + add_action('edit_user_profile_update', array($this, 'save_user')); |
|
| 174 | + add_action('user_register', array($this, 'save_user')); |
|
| 175 | 175 | |
| 176 | - if ( $this->cmb->has_columns ) { |
|
| 177 | - add_filter( 'manage_users_columns', array( $this, 'register_column_headers' ) ); |
|
| 178 | - add_filter( 'manage_users_custom_column', array( $this, 'return_column_display' ), 10, 3 ); |
|
| 179 | - add_filter( "manage_users_sortable_columns", array( $this, 'columns_sortable' ) ); |
|
| 180 | - add_action( 'pre_get_posts', array( $this, 'columns_sortable_orderby' ) ); |
|
| 176 | + if ($this->cmb->has_columns) { |
|
| 177 | + add_filter('manage_users_columns', array($this, 'register_column_headers')); |
|
| 178 | + add_filter('manage_users_custom_column', array($this, 'return_column_display'), 10, 3); |
|
| 179 | + add_filter("manage_users_sortable_columns", array($this, 'columns_sortable')); |
|
| 180 | + add_action('pre_get_posts', array($this, 'columns_sortable_orderby')); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | return $this; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | public function term_hooks() { |
| 187 | - if ( ! function_exists( 'get_term_meta' ) ) { |
|
| 188 | - wp_die( esc_html__( 'Term Metadata is a WordPress 4.4+ feature. Please upgrade your WordPress install.', 'cmb2' ) ); |
|
| 187 | + if ( ! function_exists('get_term_meta')) { |
|
| 188 | + wp_die(esc_html__('Term Metadata is a WordPress 4.4+ feature. Please upgrade your WordPress install.', 'cmb2')); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( ! $this->cmb->prop( 'taxonomies' ) ) { |
|
| 192 | - wp_die( esc_html__( 'Term metaboxes configuration requires a "taxonomies" parameter.', 'cmb2' ) ); |
|
| 191 | + if ( ! $this->cmb->prop('taxonomies')) { |
|
| 192 | + wp_die(esc_html__('Term metaboxes configuration requires a "taxonomies" parameter.', 'cmb2')); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - $this->taxonomies = (array) $this->cmb->prop( 'taxonomies' ); |
|
| 196 | - $show_on_term_add = $this->cmb->prop( 'new_term_section' ); |
|
| 197 | - $priority = $this->get_priority( 8 ); |
|
| 195 | + $this->taxonomies = (array) $this->cmb->prop('taxonomies'); |
|
| 196 | + $show_on_term_add = $this->cmb->prop('new_term_section'); |
|
| 197 | + $priority = $this->get_priority(8); |
|
| 198 | 198 | |
| 199 | - foreach ( $this->taxonomies as $taxonomy ) { |
|
| 199 | + foreach ($this->taxonomies as $taxonomy) { |
|
| 200 | 200 | // Display our form data. |
| 201 | - add_action( "{$taxonomy}_edit_form", array( $this, 'term_metabox' ), $priority, 2 ); |
|
| 201 | + add_action("{$taxonomy}_edit_form", array($this, 'term_metabox'), $priority, 2); |
|
| 202 | 202 | |
| 203 | - $show_on_add = is_array( $show_on_term_add ) |
|
| 204 | - ? in_array( $taxonomy, $show_on_term_add ) |
|
| 203 | + $show_on_add = is_array($show_on_term_add) |
|
| 204 | + ? in_array($taxonomy, $show_on_term_add) |
|
| 205 | 205 | : (bool) $show_on_term_add; |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -212,24 +212,24 @@ discard block |
||
| 212 | 212 | * @param bool $show_on_add Default is the value of the new_term_section cmb parameter. |
| 213 | 213 | * @param object $cmb The CMB2 instance |
| 214 | 214 | */ |
| 215 | - $show_on_add = apply_filters( "cmb2_show_on_term_add_form_{$this->cmb->cmb_id}", $show_on_add, $this->cmb ); |
|
| 215 | + $show_on_add = apply_filters("cmb2_show_on_term_add_form_{$this->cmb->cmb_id}", $show_on_add, $this->cmb); |
|
| 216 | 216 | |
| 217 | 217 | // Display form in add-new section (unless specified not to). |
| 218 | - if ( $show_on_add ) { |
|
| 219 | - add_action( "{$taxonomy}_add_form_fields", array( $this, 'term_metabox' ), $priority, 2 ); |
|
| 218 | + if ($show_on_add) { |
|
| 219 | + add_action("{$taxonomy}_add_form_fields", array($this, 'term_metabox'), $priority, 2); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( $this->cmb->has_columns ) { |
|
| 223 | - add_filter( "manage_edit-{$taxonomy}_columns", array( $this, 'register_column_headers' ) ); |
|
| 224 | - add_filter( "manage_{$taxonomy}_custom_column", array( $this, 'return_column_display' ), 10, 3 ); |
|
| 225 | - add_filter( "manage_edit-{$taxonomy}_sortable_columns", array( $this, 'columns_sortable' ) ); |
|
| 226 | - add_action( 'pre_get_posts', array( $this, 'columns_sortable_orderby' ) ); |
|
| 222 | + if ($this->cmb->has_columns) { |
|
| 223 | + add_filter("manage_edit-{$taxonomy}_columns", array($this, 'register_column_headers')); |
|
| 224 | + add_filter("manage_{$taxonomy}_custom_column", array($this, 'return_column_display'), 10, 3); |
|
| 225 | + add_filter("manage_edit-{$taxonomy}_sortable_columns", array($this, 'columns_sortable')); |
|
| 226 | + add_action('pre_get_posts', array($this, 'columns_sortable_orderby')); |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - add_action( 'created_term', array( $this, 'save_term' ), 10, 3 ); |
|
| 231 | - add_action( 'edited_terms', array( $this, 'save_term' ), 10, 2 ); |
|
| 232 | - add_action( 'delete_term', array( $this, 'delete_term' ), 10, 3 ); |
|
| 230 | + add_action('created_term', array($this, 'save_term'), 10, 3); |
|
| 231 | + add_action('edited_terms', array($this, 'save_term'), 10, 2); |
|
| 232 | + add_action('delete_term', array($this, 'delete_term'), 10, 3); |
|
| 233 | 233 | |
| 234 | 234 | return $this; |
| 235 | 235 | } |
@@ -237,10 +237,10 @@ discard block |
||
| 237 | 237 | public function options_page_hooks() { |
| 238 | 238 | $option_keys = $this->cmb->options_page_keys(); |
| 239 | 239 | |
| 240 | - if ( ! empty( $option_keys ) ) { |
|
| 241 | - foreach ( $option_keys as $option_key ) { |
|
| 242 | - $this->options_hookup[ $option_key ] = new CMB2_Options_Hookup( $this->cmb, $option_key ); |
|
| 243 | - $this->options_hookup[ $option_key ]->hooks(); |
|
| 240 | + if ( ! empty($option_keys)) { |
|
| 241 | + foreach ($option_keys as $option_key) { |
|
| 242 | + $this->options_hookup[$option_key] = new CMB2_Options_Hookup($this->cmb, $option_key); |
|
| 243 | + $this->options_hookup[$option_key]->hooks(); |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | * @since 2.0.7 |
| 254 | 254 | */ |
| 255 | 255 | protected static function register_styles() { |
| 256 | - if ( self::$css_registration_done ) { |
|
| 256 | + if (self::$css_registration_done) { |
|
| 257 | 257 | return; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // Only use minified files if SCRIPT_DEBUG is off. |
| 261 | - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 261 | + $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 262 | 262 | $front = is_admin() ? '' : '-front'; |
| 263 | 263 | $rtl = is_rtl() ? '-rtl' : ''; |
| 264 | 264 | |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @param array $dependencies The registered style dependencies for the cmb2 stylesheet. |
| 269 | 269 | */ |
| 270 | - $dependencies = apply_filters( 'cmb2_style_dependencies', array() ); |
|
| 271 | - wp_register_style( 'cmb2-styles', CMB2_Utils::url( "css/cmb2{$front}{$rtl}{$min}.css" ), $dependencies ); |
|
| 272 | - wp_register_style( 'cmb2-display-styles', CMB2_Utils::url( "css/cmb2-display{$rtl}{$min}.css" ), $dependencies ); |
|
| 270 | + $dependencies = apply_filters('cmb2_style_dependencies', array()); |
|
| 271 | + wp_register_style('cmb2-styles', CMB2_Utils::url("css/cmb2{$front}{$rtl}{$min}.css"), $dependencies); |
|
| 272 | + wp_register_style('cmb2-display-styles', CMB2_Utils::url("css/cmb2-display{$rtl}{$min}.css"), $dependencies); |
|
| 273 | 273 | |
| 274 | 274 | self::$css_registration_done = true; |
| 275 | 275 | } |
@@ -280,12 +280,12 @@ discard block |
||
| 280 | 280 | * @since 2.0.7 |
| 281 | 281 | */ |
| 282 | 282 | protected static function register_js() { |
| 283 | - if ( self::$js_registration_done ) { |
|
| 283 | + if (self::$js_registration_done) { |
|
| 284 | 284 | return; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | $hook = is_admin() ? 'admin_footer' : 'wp_footer'; |
| 288 | - add_action( $hook, array( 'CMB2_JS', 'enqueue' ), 8 ); |
|
| 288 | + add_action($hook, array('CMB2_JS', 'enqueue'), 8); |
|
| 289 | 289 | |
| 290 | 290 | self::$js_registration_done = true; |
| 291 | 291 | } |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * |
| 308 | 308 | * @param string $hook Current hook for the admin page. |
| 309 | 309 | */ |
| 310 | - public function do_scripts( $hook ) { |
|
| 310 | + public function do_scripts($hook) { |
|
| 311 | 311 | $hooks = array( |
| 312 | 312 | 'post.php', |
| 313 | 313 | 'post-new.php', |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | ); |
| 323 | 323 | // only pre-enqueue our scripts/styles on the proper pages |
| 324 | 324 | // show_form_for_type will have us covered if we miss something here. |
| 325 | - if ( in_array( $hook, $hooks, true ) ) { |
|
| 326 | - if ( $this->cmb->prop( 'cmb_styles' ) ) { |
|
| 325 | + if (in_array($hook, $hooks, true)) { |
|
| 326 | + if ($this->cmb->prop('cmb_styles')) { |
|
| 327 | 327 | self::enqueue_cmb_css(); |
| 328 | 328 | } |
| 329 | - if ( $this->cmb->prop( 'enqueue_js' ) ) { |
|
| 329 | + if ($this->cmb->prop('enqueue_js')) { |
|
| 330 | 330 | self::enqueue_cmb_js(); |
| 331 | 331 | } |
| 332 | 332 | } |
@@ -339,24 +339,24 @@ discard block |
||
| 339 | 339 | * |
| 340 | 340 | * @param array $columns Array of columns available for the admin page. |
| 341 | 341 | */ |
| 342 | - public function register_column_headers( $columns ) { |
|
| 343 | - foreach ( $this->cmb->prop( 'fields' ) as $key => $field ) { |
|
| 344 | - if ( empty( $field['column'] ) ) { |
|
| 342 | + public function register_column_headers($columns) { |
|
| 343 | + foreach ($this->cmb->prop('fields') as $key => $field) { |
|
| 344 | + if (empty($field['column'])) { |
|
| 345 | 345 | continue; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | $column = $field['column']; |
| 349 | 349 | |
| 350 | - if ( false === $column['position'] ) { |
|
| 351 | - $columns[ $field['id'] ] = $column['name']; |
|
| 350 | + if (false === $column['position']) { |
|
| 351 | + $columns[$field['id']] = $column['name']; |
|
| 352 | 352 | } else { |
| 353 | - $before = array_slice( $columns, 0, absint( $column['position'] ) ); |
|
| 354 | - $before[ $field['id'] ] = $column['name']; |
|
| 353 | + $before = array_slice($columns, 0, absint($column['position'])); |
|
| 354 | + $before[$field['id']] = $column['name']; |
|
| 355 | 355 | $columns = $before + $columns; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $column['field'] = $field; |
| 359 | - $this->columns[ $field['id'] ] = $column; |
|
| 359 | + $this->columns[$field['id']] = $column; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | return $columns; |
@@ -370,16 +370,16 @@ discard block |
||
| 370 | 370 | * @param string $column_name Current column name. |
| 371 | 371 | * @param mixed $object_id Current object ID. |
| 372 | 372 | */ |
| 373 | - public function column_display( $column_name, $object_id ) { |
|
| 374 | - if ( isset( $this->columns[ $column_name ] ) ) { |
|
| 375 | - $field = new CMB2_Field( array( |
|
| 376 | - 'field_args' => $this->columns[ $column_name ]['field'], |
|
| 373 | + public function column_display($column_name, $object_id) { |
|
| 374 | + if (isset($this->columns[$column_name])) { |
|
| 375 | + $field = new CMB2_Field(array( |
|
| 376 | + 'field_args' => $this->columns[$column_name]['field'], |
|
| 377 | 377 | 'object_type' => $this->object_type, |
| 378 | - 'object_id' => $this->cmb->object_id( $object_id ), |
|
| 378 | + 'object_id' => $this->cmb->object_id($object_id), |
|
| 379 | 379 | 'cmb_id' => $this->cmb->cmb_id, |
| 380 | - ) ); |
|
| 380 | + )); |
|
| 381 | 381 | |
| 382 | - $this->cmb->get_field( $field )->render_column(); |
|
| 382 | + $this->cmb->get_field($field)->render_column(); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
@@ -392,10 +392,10 @@ discard block |
||
| 392 | 392 | * |
| 393 | 393 | * @return array $columns An array of sortable columns with CMB2 columns. |
| 394 | 394 | */ |
| 395 | - public function columns_sortable( $columns ) { |
|
| 396 | - foreach ( $this->cmb->prop( 'fields' ) as $key => $field ) { |
|
| 397 | - if ( ! empty( $field['column'] ) && empty( $field['column']['disable_sortable'] ) ) { |
|
| 398 | - $columns[ $field['id'] ] = $field['id']; |
|
| 395 | + public function columns_sortable($columns) { |
|
| 396 | + foreach ($this->cmb->prop('fields') as $key => $field) { |
|
| 397 | + if ( ! empty($field['column']) && empty($field['column']['disable_sortable'])) { |
|
| 398 | + $columns[$field['id']] = $field['id']; |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
@@ -411,28 +411,28 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @return void |
| 413 | 413 | */ |
| 414 | - public function columns_sortable_orderby( $query ) { |
|
| 415 | - if ( ! is_admin() ) { |
|
| 414 | + public function columns_sortable_orderby($query) { |
|
| 415 | + if ( ! is_admin()) { |
|
| 416 | 416 | return; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - $orderby = $query->get( 'orderby' ); |
|
| 419 | + $orderby = $query->get('orderby'); |
|
| 420 | 420 | |
| 421 | - foreach ( $this->cmb->prop( 'fields' ) as $key => $field ) { |
|
| 421 | + foreach ($this->cmb->prop('fields') as $key => $field) { |
|
| 422 | 422 | if ( |
| 423 | - empty( $field['column'] ) |
|
| 424 | - || ! empty( $field['column']['disable_sortable'] ) |
|
| 423 | + empty($field['column']) |
|
| 424 | + || ! empty($field['column']['disable_sortable']) |
|
| 425 | 425 | || $field['id'] !== $orderby |
| 426 | 426 | ) { |
| 427 | 427 | continue; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - $query->set( 'meta_key', $field['id'] ); |
|
| 430 | + $query->set('meta_key', $field['id']); |
|
| 431 | 431 | |
| 432 | 432 | $type = $field['type']; |
| 433 | 433 | |
| 434 | - if ( ! empty( $field['attributes']['type'] ) ) { |
|
| 435 | - switch ( $field['attributes']['type'] ) { |
|
| 434 | + if ( ! empty($field['attributes']['type'])) { |
|
| 435 | + switch ($field['attributes']['type']) { |
|
| 436 | 436 | case 'number': |
| 437 | 437 | case 'date': |
| 438 | 438 | $type = $field['attributes']['type']; |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - switch ( $type ) { |
|
| 446 | + switch ($type) { |
|
| 447 | 447 | case 'number': |
| 448 | 448 | case 'text_date_timestamp': |
| 449 | 449 | case 'text_datetime_timestamp': |
| 450 | 450 | case 'text_money': |
| 451 | - $query->set( 'orderby', 'meta_value_num' ); |
|
| 451 | + $query->set('orderby', 'meta_value_num'); |
|
| 452 | 452 | break; |
| 453 | 453 | case 'text_time': |
| 454 | - $query->set( 'orderby', 'meta_value_time' ); |
|
| 454 | + $query->set('orderby', 'meta_value_time'); |
|
| 455 | 455 | break; |
| 456 | 456 | case 'text_date': |
| 457 | - $query->set( 'orderby', 'meta_value_date' ); |
|
| 457 | + $query->set('orderby', 'meta_value_date'); |
|
| 458 | 458 | break; |
| 459 | 459 | |
| 460 | 460 | default: |
| 461 | - $query->set( 'orderby', 'meta_value' ); |
|
| 461 | + $query->set('orderby', 'meta_value'); |
|
| 462 | 462 | break; |
| 463 | 463 | } |
| 464 | 464 | } |
@@ -469,9 +469,9 @@ discard block |
||
| 469 | 469 | * |
| 470 | 470 | * @since 2.2.2 |
| 471 | 471 | */ |
| 472 | - public function return_column_display( $empty, $custom_column, $object_id ) { |
|
| 472 | + public function return_column_display($empty, $custom_column, $object_id) { |
|
| 473 | 473 | ob_start(); |
| 474 | - $this->column_display( $custom_column, $object_id ); |
|
| 474 | + $this->column_display($custom_column, $object_id); |
|
| 475 | 475 | $column = ob_get_clean(); |
| 476 | 476 | |
| 477 | 477 | return $column ? $column : $empty; |
@@ -484,17 +484,17 @@ discard block |
||
| 484 | 484 | */ |
| 485 | 485 | public function add_context_metaboxes() { |
| 486 | 486 | |
| 487 | - if ( ! $this->show_on() ) { |
|
| 487 | + if ( ! $this->show_on()) { |
|
| 488 | 488 | return; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | $page = get_current_screen()->id; |
| 492 | 492 | |
| 493 | - foreach ( $this->cmb->box_types() as $object_type ) { |
|
| 494 | - $screen = convert_to_screen( $object_type ); |
|
| 493 | + foreach ($this->cmb->box_types() as $object_type) { |
|
| 494 | + $screen = convert_to_screen($object_type); |
|
| 495 | 495 | |
| 496 | 496 | // If we're on the right post-type/object... |
| 497 | - if ( isset( $screen->id ) && $screen->id === $page ) { |
|
| 497 | + if (isset($screen->id) && $screen->id === $page) { |
|
| 498 | 498 | |
| 499 | 499 | // Show the box. |
| 500 | 500 | $this->output_context_metabox(); |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | * @since 2.2.4 |
| 509 | 509 | */ |
| 510 | 510 | public function output_context_metabox() { |
| 511 | - $title = $this->cmb->prop( 'title' ); |
|
| 511 | + $title = $this->cmb->prop('title'); |
|
| 512 | 512 | |
| 513 | 513 | /* |
| 514 | 514 | * To keep from outputting the open/close markup, do not include |
@@ -517,17 +517,17 @@ discard block |
||
| 517 | 517 | * To output the fields 'naked' (without a postbox wrapper/style), then |
| 518 | 518 | * add a `'remove_box_wrap' => true` to your metabox registration array. |
| 519 | 519 | */ |
| 520 | - $add_wrap = ! empty( $title ) || ! $this->cmb->prop( 'remove_box_wrap' ); |
|
| 521 | - $add_handle = $add_wrap && ! empty( $title ); |
|
| 520 | + $add_wrap = ! empty($title) || ! $this->cmb->prop('remove_box_wrap'); |
|
| 521 | + $add_handle = $add_wrap && ! empty($title); |
|
| 522 | 522 | |
| 523 | 523 | // Open the context-box wrap. |
| 524 | - $this->context_box_title_markup_open( $add_handle ); |
|
| 524 | + $this->context_box_title_markup_open($add_handle); |
|
| 525 | 525 | |
| 526 | 526 | // Show the form fields. |
| 527 | 527 | $this->cmb->show_form(); |
| 528 | 528 | |
| 529 | 529 | // Close the context-box wrap. |
| 530 | - $this->context_box_title_markup_close( $add_handle ); |
|
| 530 | + $this->context_box_title_markup_close($add_handle); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | /** |
@@ -536,22 +536,22 @@ discard block |
||
| 536 | 536 | * @since 2.2.4 |
| 537 | 537 | * @param bool $add_handle Whether to add the metabox handle and opening div for .inside. |
| 538 | 538 | */ |
| 539 | - public function context_box_title_markup_open( $add_handle = true ) { |
|
| 540 | - $title = $this->cmb->prop( 'title' ); |
|
| 539 | + public function context_box_title_markup_open($add_handle = true) { |
|
| 540 | + $title = $this->cmb->prop('title'); |
|
| 541 | 541 | |
| 542 | 542 | $page = get_current_screen()->id; |
| 543 | - add_filter( "postbox_classes_{$page}_{$this->cmb->cmb_id}", array( $this, 'postbox_classes' ) ); |
|
| 543 | + add_filter("postbox_classes_{$page}_{$this->cmb->cmb_id}", array($this, 'postbox_classes')); |
|
| 544 | 544 | |
| 545 | - echo '<div id="' . $this->cmb->cmb_id . '" class="' . postbox_classes( $this->cmb->cmb_id, $page ) . '">' . "\n"; |
|
| 545 | + echo '<div id="' . $this->cmb->cmb_id . '" class="' . postbox_classes($this->cmb->cmb_id, $page) . '">' . "\n"; |
|
| 546 | 546 | |
| 547 | - if ( $add_handle ) { |
|
| 547 | + if ($add_handle) { |
|
| 548 | 548 | |
| 549 | 549 | echo '<button type="button" class="handlediv button-link" aria-expanded="true">'; |
| 550 | - echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $title ) . '</span>'; |
|
| 550 | + echo '<span class="screen-reader-text">' . sprintf(__('Toggle panel: %s'), $title) . '</span>'; |
|
| 551 | 551 | echo '<span class="toggle-indicator" aria-hidden="true"></span>'; |
| 552 | 552 | echo '</button>'; |
| 553 | 553 | |
| 554 | - echo '<h2 class="hndle"><span>' . esc_attr( $title ) . '</span></h2>' . "\n"; |
|
| 554 | + echo '<h2 class="hndle"><span>' . esc_attr($title) . '</span></h2>' . "\n"; |
|
| 555 | 555 | echo '<div class="inside">' . "\n"; |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -562,10 +562,10 @@ discard block |
||
| 562 | 562 | * @since 2.2.4 |
| 563 | 563 | * @param bool $add_inside_close Whether to add closing div for .inside. |
| 564 | 564 | */ |
| 565 | - public function context_box_title_markup_close( $add_inside_close = true ) { |
|
| 565 | + public function context_box_title_markup_close($add_inside_close = true) { |
|
| 566 | 566 | |
| 567 | 567 | // Load the closing divs for a title box. |
| 568 | - if ( $add_inside_close ) { |
|
| 568 | + if ($add_inside_close) { |
|
| 569 | 569 | echo '</div>' . "\n"; // .inside |
| 570 | 570 | } |
| 571 | 571 | |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | */ |
| 580 | 580 | public function add_metaboxes() { |
| 581 | 581 | |
| 582 | - if ( ! $this->show_on() ) { |
|
| 582 | + if ( ! $this->show_on()) { |
|
| 583 | 583 | return; |
| 584 | 584 | } |
| 585 | 585 | |
@@ -592,22 +592,22 @@ discard block |
||
| 592 | 592 | * This is a good solution if you want to handle outputting your |
| 593 | 593 | * metaboxes/fields elsewhere in the post-screen. |
| 594 | 594 | */ |
| 595 | - if ( ! $this->cmb->prop( 'title' ) ) { |
|
| 595 | + if ( ! $this->cmb->prop('title')) { |
|
| 596 | 596 | return; |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | $page = get_current_screen()->id; |
| 600 | - add_filter( "postbox_classes_{$page}_{$this->cmb->cmb_id}", array( $this, 'postbox_classes' ) ); |
|
| 600 | + add_filter("postbox_classes_{$page}_{$this->cmb->cmb_id}", array($this, 'postbox_classes')); |
|
| 601 | 601 | |
| 602 | - foreach ( $this->cmb->box_types() as $object_type ) { |
|
| 602 | + foreach ($this->cmb->box_types() as $object_type) { |
|
| 603 | 603 | add_meta_box( |
| 604 | 604 | $this->cmb->cmb_id, |
| 605 | - $this->cmb->prop( 'title' ), |
|
| 606 | - array( $this, 'metabox_callback' ), |
|
| 605 | + $this->cmb->prop('title'), |
|
| 606 | + array($this, 'metabox_callback'), |
|
| 607 | 607 | $object_type, |
| 608 | - $this->cmb->prop( 'context' ), |
|
| 609 | - $this->cmb->prop( 'priority' ), |
|
| 610 | - $this->cmb->prop( 'mb_callback_args' ) |
|
| 608 | + $this->cmb->prop('context'), |
|
| 609 | + $this->cmb->prop('priority'), |
|
| 610 | + $this->cmb->prop('mb_callback_args') |
|
| 611 | 611 | ); |
| 612 | 612 | } |
| 613 | 613 | } |
@@ -619,15 +619,15 @@ discard block |
||
| 619 | 619 | * |
| 620 | 620 | */ |
| 621 | 621 | public function remove_default_tax_metaboxes() { |
| 622 | - $to_remove = array_filter( (array) $this->cmb->tax_metaboxes_to_remove, 'taxonomy_exists' ); |
|
| 623 | - if ( empty( $to_remove ) ) { |
|
| 622 | + $to_remove = array_filter((array) $this->cmb->tax_metaboxes_to_remove, 'taxonomy_exists'); |
|
| 623 | + if (empty($to_remove)) { |
|
| 624 | 624 | return; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - foreach ( $this->cmb->box_types() as $post_type ) { |
|
| 628 | - foreach ( $to_remove as $taxonomy ) { |
|
| 629 | - $mb_id = is_taxonomy_hierarchical( $taxonomy ) ? "{$taxonomy}div" : "tagsdiv-{$taxonomy}"; |
|
| 630 | - remove_meta_box( $mb_id, $post_type, 'side' ); |
|
| 627 | + foreach ($this->cmb->box_types() as $post_type) { |
|
| 628 | + foreach ($to_remove as $taxonomy) { |
|
| 629 | + $mb_id = is_taxonomy_hierarchical($taxonomy) ? "{$taxonomy}div" : "tagsdiv-{$taxonomy}"; |
|
| 630 | + remove_meta_box($mb_id, $post_type, 'side'); |
|
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | } |
@@ -639,13 +639,13 @@ discard block |
||
| 639 | 639 | * @param array $classes Array of classes. |
| 640 | 640 | * @return array Modified array of classes |
| 641 | 641 | */ |
| 642 | - public function postbox_classes( $classes ) { |
|
| 643 | - if ( $this->cmb->prop( 'closed' ) && ! in_array( 'closed', $classes ) ) { |
|
| 642 | + public function postbox_classes($classes) { |
|
| 643 | + if ($this->cmb->prop('closed') && ! in_array('closed', $classes)) { |
|
| 644 | 644 | $classes[] = 'closed'; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if ( $this->cmb->is_alternate_context_box() ) { |
|
| 648 | - $classes = $this->alternate_context_postbox_classes( $classes ); |
|
| 647 | + if ($this->cmb->is_alternate_context_box()) { |
|
| 648 | + $classes = $this->alternate_context_postbox_classes($classes); |
|
| 649 | 649 | } else { |
| 650 | 650 | $classes[] = 'cmb2-postbox'; |
| 651 | 651 | } |
@@ -660,17 +660,17 @@ discard block |
||
| 660 | 660 | * @param array $classes Array of classes. |
| 661 | 661 | * @return array Modified array of classes |
| 662 | 662 | */ |
| 663 | - protected function alternate_context_postbox_classes( $classes ) { |
|
| 663 | + protected function alternate_context_postbox_classes($classes) { |
|
| 664 | 664 | $classes[] = 'context-box'; |
| 665 | - $classes[] = 'context-' . $this->cmb->prop( 'context' ) . '-box'; |
|
| 665 | + $classes[] = 'context-' . $this->cmb->prop('context') . '-box'; |
|
| 666 | 666 | |
| 667 | - if ( in_array( $this->cmb->cmb_id, get_hidden_meta_boxes( get_current_screen() ) ) ) { |
|
| 667 | + if (in_array($this->cmb->cmb_id, get_hidden_meta_boxes(get_current_screen()))) { |
|
| 668 | 668 | $classes[] = 'hide-if-js'; |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - $add_wrap = $this->cmb->prop( 'title' ) || ! $this->cmb->prop( 'remove_box_wrap' ); |
|
| 671 | + $add_wrap = $this->cmb->prop('title') || ! $this->cmb->prop('remove_box_wrap'); |
|
| 672 | 672 | |
| 673 | - if ( $add_wrap ) { |
|
| 673 | + if ($add_wrap) { |
|
| 674 | 674 | $classes[] = 'cmb2-postbox postbox'; |
| 675 | 675 | } else { |
| 676 | 676 | $classes[] = 'cmb2-no-box-wrap'; |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | */ |
| 687 | 687 | public function metabox_callback() { |
| 688 | 688 | $object_id = 'comment' === $this->object_type ? get_comment_ID() : get_the_ID(); |
| 689 | - $this->cmb->show_form( $object_id, $this->object_type ); |
|
| 689 | + $this->cmb->show_form($object_id, $this->object_type); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -696,10 +696,10 @@ discard block |
||
| 696 | 696 | * |
| 697 | 697 | * @param mixed $section User section metabox. |
| 698 | 698 | */ |
| 699 | - public function user_new_metabox( $section ) { |
|
| 700 | - if ( $section === $this->cmb->prop( 'new_user_section' ) ) { |
|
| 699 | + public function user_new_metabox($section) { |
|
| 700 | + if ($section === $this->cmb->prop('new_user_section')) { |
|
| 701 | 701 | $object_id = $this->cmb->object_id(); |
| 702 | - $this->cmb->object_id( isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id ); |
|
| 702 | + $this->cmb->object_id(isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : $object_id); |
|
| 703 | 703 | $this->user_metabox(); |
| 704 | 704 | } |
| 705 | 705 | } |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | * @since 1.0.0 |
| 711 | 711 | */ |
| 712 | 712 | public function user_metabox() { |
| 713 | - $this->show_form_for_type( 'user' ); |
|
| 713 | + $this->show_form_for_type('user'); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | * @since 2.2.0 |
| 720 | 720 | */ |
| 721 | 721 | public function term_metabox() { |
| 722 | - $this->show_form_for_type( 'term' ); |
|
| 722 | + $this->show_form_for_type('term'); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -729,23 +729,23 @@ discard block |
||
| 729 | 729 | * @param string $type Object type. |
| 730 | 730 | * @return void |
| 731 | 731 | */ |
| 732 | - public function show_form_for_type( $type ) { |
|
| 733 | - if ( $type != $this->object_type ) { |
|
| 732 | + public function show_form_for_type($type) { |
|
| 733 | + if ($type != $this->object_type) { |
|
| 734 | 734 | return; |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | - if ( ! $this->show_on() ) { |
|
| 737 | + if ( ! $this->show_on()) { |
|
| 738 | 738 | return; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - if ( $this->cmb->prop( 'cmb_styles' ) ) { |
|
| 741 | + if ($this->cmb->prop('cmb_styles')) { |
|
| 742 | 742 | self::enqueue_cmb_css(); |
| 743 | 743 | } |
| 744 | - if ( $this->cmb->prop( 'enqueue_js' ) ) { |
|
| 744 | + if ($this->cmb->prop('enqueue_js')) { |
|
| 745 | 745 | self::enqueue_cmb_js(); |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - $this->cmb->show_form( 0, $type ); |
|
| 748 | + $this->cmb->show_form(0, $type); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | * @param mixed $meta_box_args Array of the metabox arguments. |
| 766 | 766 | * @param mixed $cmb The CMB2 instance. |
| 767 | 767 | */ |
| 768 | - $show = (bool) apply_filters( 'cmb2_show_on', $show, $this->cmb->meta_box, $this->cmb ); |
|
| 768 | + $show = (bool) apply_filters('cmb2_show_on', $show, $this->cmb->meta_box, $this->cmb); |
|
| 769 | 769 | |
| 770 | 770 | return $show; |
| 771 | 771 | } |
@@ -778,11 +778,11 @@ discard block |
||
| 778 | 778 | * @param integer $default Default display hook priority. |
| 779 | 779 | * @return integer Hook priority. |
| 780 | 780 | */ |
| 781 | - public function get_priority( $default = 10 ) { |
|
| 782 | - $priority = $this->cmb->prop( 'priority' ); |
|
| 781 | + public function get_priority($default = 10) { |
|
| 782 | + $priority = $this->cmb->prop('priority'); |
|
| 783 | 783 | |
| 784 | - if ( ! is_numeric( $priority ) ) { |
|
| 785 | - switch ( $priority ) { |
|
| 784 | + if ( ! is_numeric($priority)) { |
|
| 785 | + switch ($priority) { |
|
| 786 | 786 | |
| 787 | 787 | case 'high': |
| 788 | 788 | $priority = 5; |
@@ -809,22 +809,22 @@ discard block |
||
| 809 | 809 | * @param mixed $post Post object. |
| 810 | 810 | * @return void |
| 811 | 811 | */ |
| 812 | - public function save_post( $post_id, $post = false ) { |
|
| 812 | + public function save_post($post_id, $post = false) { |
|
| 813 | 813 | |
| 814 | - $post_type = $post ? $post->post_type : get_post_type( $post_id ); |
|
| 814 | + $post_type = $post ? $post->post_type : get_post_type($post_id); |
|
| 815 | 815 | |
| 816 | 816 | $do_not_pass_go = ( |
| 817 | - ! $this->can_save( $post_type ) |
|
| 817 | + ! $this->can_save($post_type) |
|
| 818 | 818 | // Check user editing permissions. |
| 819 | - || ( 'page' === $post_type && ! current_user_can( 'edit_page', $post_id ) ) |
|
| 820 | - || ! current_user_can( 'edit_post', $post_id ) |
|
| 819 | + || ('page' === $post_type && ! current_user_can('edit_page', $post_id)) |
|
| 820 | + || ! current_user_can('edit_post', $post_id) |
|
| 821 | 821 | ); |
| 822 | 822 | |
| 823 | - if ( $do_not_pass_go ) { |
|
| 823 | + if ($do_not_pass_go) { |
|
| 824 | 824 | return; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - $this->cmb->save_fields( $post_id, 'post', $_POST ); |
|
| 827 | + $this->cmb->save_fields($post_id, 'post', $_POST); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -834,12 +834,12 @@ discard block |
||
| 834 | 834 | * @param int $comment_id Comment ID. |
| 835 | 835 | * @return void |
| 836 | 836 | */ |
| 837 | - public function save_comment( $comment_id ) { |
|
| 837 | + public function save_comment($comment_id) { |
|
| 838 | 838 | |
| 839 | - $can_edit = current_user_can( 'moderate_comments', $comment_id ); |
|
| 839 | + $can_edit = current_user_can('moderate_comments', $comment_id); |
|
| 840 | 840 | |
| 841 | - if ( $this->can_save( get_comment_type( $comment_id ) ) && $can_edit ) { |
|
| 842 | - $this->cmb->save_fields( $comment_id, 'comment', $_POST ); |
|
| 841 | + if ($this->can_save(get_comment_type($comment_id)) && $can_edit) { |
|
| 842 | + $this->cmb->save_fields($comment_id, 'comment', $_POST); |
|
| 843 | 843 | } |
| 844 | 844 | } |
| 845 | 845 | |
@@ -850,10 +850,10 @@ discard block |
||
| 850 | 850 | * @param int $user_id User ID. |
| 851 | 851 | * @return void |
| 852 | 852 | */ |
| 853 | - public function save_user( $user_id ) { |
|
| 853 | + public function save_user($user_id) { |
|
| 854 | 854 | // check permissions. |
| 855 | - if ( $this->can_save( 'user' ) ) { |
|
| 856 | - $this->cmb->save_fields( $user_id, 'user', $_POST ); |
|
| 855 | + if ($this->can_save('user')) { |
|
| 856 | + $this->cmb->save_fields($user_id, 'user', $_POST); |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | |
@@ -866,12 +866,12 @@ discard block |
||
| 866 | 866 | * @param string $taxonomy Taxonomy. |
| 867 | 867 | * @return void |
| 868 | 868 | */ |
| 869 | - public function save_term( $term_id, $tt_id, $taxonomy = '' ) { |
|
| 869 | + public function save_term($term_id, $tt_id, $taxonomy = '') { |
|
| 870 | 870 | $taxonomy = $taxonomy ? $taxonomy : $tt_id; |
| 871 | 871 | |
| 872 | 872 | // check permissions. |
| 873 | - if ( $this->taxonomy_can_save( $taxonomy ) && $this->can_save( 'term' ) ) { |
|
| 874 | - $this->cmb->save_fields( $term_id, 'term', $_POST ); |
|
| 873 | + if ($this->taxonomy_can_save($taxonomy) && $this->can_save('term')) { |
|
| 874 | + $this->cmb->save_fields($term_id, 'term', $_POST); |
|
| 875 | 875 | } |
| 876 | 876 | } |
| 877 | 877 | |
@@ -884,15 +884,15 @@ discard block |
||
| 884 | 884 | * @param string $taxonomy Taxonomy. |
| 885 | 885 | * @return void |
| 886 | 886 | */ |
| 887 | - public function delete_term( $term_id, $tt_id, $taxonomy = '' ) { |
|
| 888 | - if ( $this->taxonomy_can_save( $taxonomy ) ) { |
|
| 887 | + public function delete_term($term_id, $tt_id, $taxonomy = '') { |
|
| 888 | + if ($this->taxonomy_can_save($taxonomy)) { |
|
| 889 | 889 | |
| 890 | 890 | $data_to_delete = array(); |
| 891 | - foreach ( $this->cmb->prop( 'fields' ) as $field ) { |
|
| 892 | - $data_to_delete[ $field['id'] ] = ''; |
|
| 891 | + foreach ($this->cmb->prop('fields') as $field) { |
|
| 892 | + $data_to_delete[$field['id']] = ''; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | - $this->cmb->save_fields( $term_id, 'term', $data_to_delete ); |
|
| 895 | + $this->cmb->save_fields($term_id, 'term', $data_to_delete); |
|
| 896 | 896 | } |
| 897 | 897 | } |
| 898 | 898 | |
@@ -903,19 +903,19 @@ discard block |
||
| 903 | 903 | * @param string $type Current object type. |
| 904 | 904 | * @return bool Whether object can be saved. |
| 905 | 905 | */ |
| 906 | - public function can_save( $type = '' ) { |
|
| 906 | + public function can_save($type = '') { |
|
| 907 | 907 | |
| 908 | 908 | $can_save = ( |
| 909 | - $this->cmb->prop( 'save_fields' ) |
|
| 909 | + $this->cmb->prop('save_fields') |
|
| 910 | 910 | // check nonce. |
| 911 | - && isset( $_POST[ $this->cmb->nonce() ] ) |
|
| 912 | - && wp_verify_nonce( $_POST[ $this->cmb->nonce() ], $this->cmb->nonce() ) |
|
| 911 | + && isset($_POST[$this->cmb->nonce()]) |
|
| 912 | + && wp_verify_nonce($_POST[$this->cmb->nonce()], $this->cmb->nonce()) |
|
| 913 | 913 | // check if autosave. |
| 914 | - && ! ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
| 914 | + && ! (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
|
| 915 | 915 | // get the metabox types & compare it to this type. |
| 916 | - && ( $type && in_array( $type, $this->cmb->box_types() ) ) |
|
| 916 | + && ($type && in_array($type, $this->cmb->box_types())) |
|
| 917 | 917 | // Don't do updates during a switch-to-blog instance. |
| 918 | - && ! ( is_multisite() && ms_is_switched() ) |
|
| 918 | + && ! (is_multisite() && ms_is_switched()) |
|
| 919 | 919 | ); |
| 920 | 920 | |
| 921 | 921 | /** |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | * @param bool $can_save Whether the current metabox can save. |
| 925 | 925 | * @param object $cmb The CMB2 instance. |
| 926 | 926 | */ |
| 927 | - return apply_filters( 'cmb2_can_save', $can_save, $this->cmb ); |
|
| 927 | + return apply_filters('cmb2_can_save', $can_save, $this->cmb); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | /** |
@@ -935,14 +935,14 @@ discard block |
||
| 935 | 935 | * @param string $taxonomy Taxonomy of term being modified. |
| 936 | 936 | * @return bool Whether taxonomy is editable. |
| 937 | 937 | */ |
| 938 | - public function taxonomy_can_save( $taxonomy ) { |
|
| 939 | - if ( empty( $this->taxonomies ) || ! in_array( $taxonomy, $this->taxonomies ) ) { |
|
| 938 | + public function taxonomy_can_save($taxonomy) { |
|
| 939 | + if (empty($this->taxonomies) || ! in_array($taxonomy, $this->taxonomies)) { |
|
| 940 | 940 | return false; |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | - $taxonomy_object = get_taxonomy( $taxonomy ); |
|
| 943 | + $taxonomy_object = get_taxonomy($taxonomy); |
|
| 944 | 944 | // Can the user edit this term? |
| 945 | - if ( ! isset( $taxonomy_object->cap ) || ! current_user_can( $taxonomy_object->cap->edit_terms ) ) { |
|
| 945 | + if ( ! isset($taxonomy_object->cap) || ! current_user_can($taxonomy_object->cap->edit_terms)) { |
|
| 946 | 946 | return false; |
| 947 | 947 | } |
| 948 | 948 | |
@@ -959,10 +959,10 @@ discard block |
||
| 959 | 959 | if ( |
| 960 | 960 | $pagenow |
| 961 | 961 | && $this->cmb->has_columns |
| 962 | - && $this->cmb->prop( 'cmb_styles' ) |
|
| 963 | - && in_array( $pagenow, array( 'edit.php', 'users.php', 'edit-comments.php', 'edit-tags.php' ), 1 ) |
|
| 962 | + && $this->cmb->prop('cmb_styles') |
|
| 963 | + && in_array($pagenow, array('edit.php', 'users.php', 'edit-comments.php', 'edit-tags.php'), 1) |
|
| 964 | 964 | ) { |
| 965 | - self::enqueue_cmb_css( 'cmb2-display-styles' ); |
|
| 965 | + self::enqueue_cmb_css('cmb2-display-styles'); |
|
| 966 | 966 | } |
| 967 | 967 | } |
| 968 | 968 | |
@@ -974,14 +974,14 @@ discard block |
||
| 974 | 974 | * @param string $handle CSS handle. |
| 975 | 975 | * @return mixed |
| 976 | 976 | */ |
| 977 | - public static function enqueue_cmb_css( $handle = 'cmb2-styles' ) { |
|
| 977 | + public static function enqueue_cmb_css($handle = 'cmb2-styles') { |
|
| 978 | 978 | |
| 979 | 979 | /** |
| 980 | 980 | * Filter to determine if CMB2'S css should be enqueued. |
| 981 | 981 | * |
| 982 | 982 | * @param bool $enqueue_css Default is true. |
| 983 | 983 | */ |
| 984 | - if ( ! apply_filters( 'cmb2_enqueue_css', true ) ) { |
|
| 984 | + if ( ! apply_filters('cmb2_enqueue_css', true)) { |
|
| 985 | 985 | return false; |
| 986 | 986 | } |
| 987 | 987 | |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | * White list the options as this method can be used as a hook callback |
| 992 | 992 | * and have a different argument passed. |
| 993 | 993 | */ |
| 994 | - return wp_enqueue_style( 'cmb2-display-styles' === $handle ? $handle : 'cmb2-styles' ); |
|
| 994 | + return wp_enqueue_style('cmb2-display-styles' === $handle ? $handle : 'cmb2-styles'); |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | /** |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | * |
| 1007 | 1007 | * @param bool $enqueue_js Default is true. |
| 1008 | 1008 | */ |
| 1009 | - if ( ! apply_filters( 'cmb2_enqueue_js', true ) ) { |
|
| 1009 | + if ( ! apply_filters('cmb2_enqueue_js', true)) { |
|
| 1010 | 1010 | return false; |
| 1011 | 1011 | } |
| 1012 | 1012 | |