@@ -81,17 +81,17 @@ discard block |
||
| 81 | 81 | * @since 2.2.3 |
| 82 | 82 | * @param array $args Object properties array. |
| 83 | 83 | */ |
| 84 | - public function __construct( $args = array() ) { |
|
| 85 | - if ( ! empty( $args ) ) { |
|
| 86 | - foreach ( array( |
|
| 84 | + public function __construct($args = array()) { |
|
| 85 | + if ( ! empty($args)) { |
|
| 86 | + foreach (array( |
|
| 87 | 87 | 'cmb_id', |
| 88 | 88 | 'properties_name', |
| 89 | 89 | 'object_id', |
| 90 | 90 | 'object_type', |
| 91 | 91 | 'data_to_save', |
| 92 | - ) as $object_prop ) { |
|
| 93 | - if ( isset( $args[ $object_prop ] ) ) { |
|
| 94 | - $this->{$object_prop} = $args[ $object_prop ]; |
|
| 92 | + ) as $object_prop) { |
|
| 93 | + if (isset($args[$object_prop])) { |
|
| 94 | + $this->{$object_prop} = $args[$object_prop]; |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @param integer $object_id Object ID. |
| 105 | 105 | * @return integer Object ID |
| 106 | 106 | */ |
| 107 | - public function object_id( $object_id = 0 ) { |
|
| 108 | - if ( $object_id ) { |
|
| 107 | + public function object_id($object_id = 0) { |
|
| 108 | + if ($object_id) { |
|
| 109 | 109 | $this->object_id = $object_id; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | * @param string $object_type Object Type. |
| 120 | 120 | * @return string Object type |
| 121 | 121 | */ |
| 122 | - public function object_type( $object_type = '' ) { |
|
| 123 | - if ( $object_type ) { |
|
| 122 | + public function object_type($object_type = '') { |
|
| 123 | + if ($object_type) { |
|
| 124 | 124 | $this->object_type = $object_type; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -137,15 +137,15 @@ discard block |
||
| 137 | 137 | global $pagenow; |
| 138 | 138 | $type = 'post'; |
| 139 | 139 | |
| 140 | - if ( in_array( $pagenow, array( 'user-edit.php', 'profile.php', 'user-new.php' ), true ) ) { |
|
| 140 | + if (in_array($pagenow, array('user-edit.php', 'profile.php', 'user-new.php'), true)) { |
|
| 141 | 141 | $type = 'user'; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( in_array( $pagenow, array( 'edit-comments.php', 'comment.php' ), true ) ) { |
|
| 144 | + if (in_array($pagenow, array('edit-comments.php', 'comment.php'), true)) { |
|
| 145 | 145 | $type = 'comment'; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) ) { |
|
| 148 | + if (in_array($pagenow, array('edit-tags.php', 'term.php'), true)) { |
|
| 149 | 149 | $type = 'term'; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | * @param mixed $value Value to set if no value found. |
| 161 | 161 | * @return mixed Metabox config property value or false. |
| 162 | 162 | */ |
| 163 | - public function set_prop( $property, $value ) { |
|
| 164 | - $this->{$this->properties_name}[ $property ] = $value; |
|
| 163 | + public function set_prop($property, $value) { |
|
| 164 | + $this->{$this->properties_name}[$property] = $value; |
|
| 165 | 165 | |
| 166 | - return $this->prop( $property ); |
|
| 166 | + return $this->prop($property); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | * @param mixed $fallback Fallback value to set if no value found. |
| 175 | 175 | * @return mixed Metabox config property value or false |
| 176 | 176 | */ |
| 177 | - public function prop( $property, $fallback = null ) { |
|
| 178 | - if ( array_key_exists( $property, $this->{$this->properties_name} ) ) { |
|
| 179 | - return $this->{$this->properties_name}[ $property ]; |
|
| 180 | - } elseif ( $fallback ) { |
|
| 181 | - return $this->{$this->properties_name}[ $property ] = $fallback; |
|
| 177 | + public function prop($property, $fallback = null) { |
|
| 178 | + if (array_key_exists($property, $this->{$this->properties_name} )) { |
|
| 179 | + return $this->{$this->properties_name}[$property]; |
|
| 180 | + } elseif ($fallback) { |
|
| 181 | + return $this->{$this->properties_name}[$property] = $fallback; |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * @param CMB2_Field $field_group (optional) CMB2_Field object (group parent). |
| 191 | 191 | * @return array Array of field arguments. |
| 192 | 192 | */ |
| 193 | - protected function get_default_args( $field_args, $field_group = null ) { |
|
| 194 | - if ( $field_group ) { |
|
| 193 | + protected function get_default_args($field_args, $field_group = null) { |
|
| 194 | + if ($field_group) { |
|
| 195 | 195 | $args = array( |
| 196 | 196 | 'field_args' => $field_args, |
| 197 | 197 | 'group_field' => $field_group, |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | * @param CMB2_Field $field_group (optional) CMB2_Field object (group parent). |
| 217 | 217 | * @return CMB2_Field CMB2_Field object |
| 218 | 218 | */ |
| 219 | - protected function get_new_field( $field_args, $field_group = null ) { |
|
| 220 | - return new CMB2_Field( $this->get_default_args( $field_args, $field_group ) ); |
|
| 219 | + protected function get_new_field($field_args, $field_group = null) { |
|
| 220 | + return new CMB2_Field($this->get_default_args($field_args, $field_group)); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | $show = true; |
| 233 | 233 | |
| 234 | 234 | // Use the callback to determine showing the cmb, if it exists. |
| 235 | - if ( is_callable( $this->prop( 'show_on_cb' ) ) ) { |
|
| 236 | - $show = (bool) call_user_func( $this->prop( 'show_on_cb' ), $this ); |
|
| 235 | + if (is_callable($this->prop('show_on_cb'))) { |
|
| 236 | + $show = (bool) call_user_func($this->prop('show_on_cb'), $this); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | return $show; |
@@ -245,8 +245,8 @@ discard block |
||
| 245 | 245 | * @since 2.0.0 |
| 246 | 246 | * @param string $param Field parameter. |
| 247 | 247 | */ |
| 248 | - public function peform_param_callback( $param ) { |
|
| 249 | - echo $this->get_param_callback_result( $param ); |
|
| 248 | + public function peform_param_callback($param) { |
|
| 249 | + echo $this->get_param_callback_result($param); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -256,36 +256,36 @@ discard block |
||
| 256 | 256 | * @param string $param Field parameter. |
| 257 | 257 | * @return mixed Results of param/param callback |
| 258 | 258 | */ |
| 259 | - public function get_param_callback_result( $param ) { |
|
| 259 | + public function get_param_callback_result($param) { |
|
| 260 | 260 | |
| 261 | 261 | // If we've already retrieved this param's value. |
| 262 | - if ( array_key_exists( $param, $this->callback_results ) ) { |
|
| 262 | + if (array_key_exists($param, $this->callback_results)) { |
|
| 263 | 263 | |
| 264 | 264 | // Send it back. |
| 265 | - return $this->callback_results[ $param ]; |
|
| 265 | + return $this->callback_results[$param]; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // Check if parameter has registered a callback. |
| 269 | - if ( $cb = $this->maybe_callback( $param ) ) { |
|
| 269 | + if ($cb = $this->maybe_callback($param)) { |
|
| 270 | 270 | |
| 271 | 271 | // Ok, callback is good, let's run it and store the result. |
| 272 | 272 | ob_start(); |
| 273 | - $returned = $this->do_callback( $cb ); |
|
| 273 | + $returned = $this->do_callback($cb); |
|
| 274 | 274 | |
| 275 | 275 | // Grab the result from the output buffer and store it. |
| 276 | 276 | $echoed = ob_get_clean(); |
| 277 | 277 | |
| 278 | 278 | // This checks if the user returned or echoed their callback. |
| 279 | 279 | // Defaults to using the echoed value. |
| 280 | - $this->callback_results[ $param ] = $echoed ? $echoed : $returned; |
|
| 280 | + $this->callback_results[$param] = $echoed ? $echoed : $returned; |
|
| 281 | 281 | |
| 282 | 282 | } else { |
| 283 | 283 | |
| 284 | 284 | // Otherwise just get whatever is there. |
| 285 | - $this->callback_results[ $param ] = isset( $this->{$this->properties_name}[ $param ] ) ? $this->{$this->properties_name}[ $param ] : false; |
|
| 285 | + $this->callback_results[$param] = isset($this->{$this->properties_name}[$param]) ? $this->{$this->properties_name}[$param] : false; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - return $this->callback_results[ $param ]; |
|
| 288 | + return $this->callback_results[$param]; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | * @param string $param Field parameter. |
| 296 | 296 | * @return CMB2_Base |
| 297 | 297 | */ |
| 298 | - public function unset_param_callback_cache( $param ) { |
|
| 299 | - if ( isset( $this->callback_results[ $param ] ) ) { |
|
| 300 | - unset( $this->callback_results[ $param ] ); |
|
| 298 | + public function unset_param_callback_cache($param) { |
|
| 299 | + if (isset($this->callback_results[$param])) { |
|
| 300 | + unset($this->callback_results[$param]); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | return $this; |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | * @param mixed $additional_params Any additoinal parameters which should be passed to the callback. |
| 312 | 312 | * @return mixed Return of the callback function. |
| 313 | 313 | */ |
| 314 | - protected function do_callback( $cb, $additional_params = null ) { |
|
| 315 | - return call_user_func( $cb, $this->{$this->properties_name}, $this, $additional_params ); |
|
| 314 | + protected function do_callback($cb, $additional_params = null) { |
|
| 315 | + return call_user_func($cb, $this->{$this->properties_name}, $this, $additional_params); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -322,21 +322,21 @@ discard block |
||
| 322 | 322 | * @param string $cb Callback string. |
| 323 | 323 | * @return mixed NULL, false for NO validation, or $cb string if it exists. |
| 324 | 324 | */ |
| 325 | - public function maybe_callback( $cb ) { |
|
| 325 | + public function maybe_callback($cb) { |
|
| 326 | 326 | $args = $this->{$this->properties_name}; |
| 327 | - if ( ! isset( $args[ $cb ] ) ) { |
|
| 327 | + if ( ! isset($args[$cb])) { |
|
| 328 | 328 | return null; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // Check if requesting explicitly false. |
| 332 | - $cb = false !== $args[ $cb ] && 'false' !== $args[ $cb ] ? $args[ $cb ] : false; |
|
| 332 | + $cb = false !== $args[$cb] && 'false' !== $args[$cb] ? $args[$cb] : false; |
|
| 333 | 333 | |
| 334 | 334 | // If requesting NO validation, return false. |
| 335 | - if ( ! $cb ) { |
|
| 335 | + if ( ! $cb) { |
|
| 336 | 336 | return false; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - if ( is_callable( $cb ) ) { |
|
| 339 | + if (is_callable($cb)) { |
|
| 340 | 340 | return $cb; |
| 341 | 341 | } |
| 342 | 342 | |
@@ -360,13 +360,13 @@ discard block |
||
| 360 | 360 | * |
| 361 | 361 | * @return null|bool Null if hook is registered, or bool for value. |
| 362 | 362 | */ |
| 363 | - public function maybe_hook_parameter( $hook_name, $val = null, $hook_function = 'add_filter' ) { |
|
| 363 | + public function maybe_hook_parameter($hook_name, $val = null, $hook_function = 'add_filter') { |
|
| 364 | 364 | |
| 365 | 365 | // Remove filter prefix, add param suffix. |
| 366 | - $parameter = substr( $hook_name, strlen( 'cmb2_api_' ) ) . '_cb'; |
|
| 366 | + $parameter = substr($hook_name, strlen('cmb2_api_')) . '_cb'; |
|
| 367 | 367 | |
| 368 | 368 | return self::maybe_hook( |
| 369 | - $this->prop( $parameter, $val ), |
|
| 369 | + $this->prop($parameter, $val), |
|
| 370 | 370 | $hook_name, |
| 371 | 371 | $hook_function |
| 372 | 372 | ); |
@@ -384,9 +384,9 @@ discard block |
||
| 384 | 384 | * |
| 385 | 385 | * @return null|bool Null if hook is registered, or bool for value. |
| 386 | 386 | */ |
| 387 | - public static function maybe_hook( $val, $hook_name, $hook_function ) { |
|
| 388 | - if ( is_callable( $val ) ) { |
|
| 389 | - call_user_func( $hook_function, $hook_name, $val, 10, 2 ); |
|
| 387 | + public static function maybe_hook($val, $hook_name, $hook_function) { |
|
| 388 | + if (is_callable($val)) { |
|
| 389 | + call_user_func($hook_function, $hook_name, $val, 10, 2); |
|
| 390 | 390 | return null; |
| 391 | 391 | } |
| 392 | 392 | |
@@ -411,19 +411,19 @@ discard block |
||
| 411 | 411 | * key to generate message from additional arguments. |
| 412 | 412 | * Default null. |
| 413 | 413 | */ |
| 414 | - protected function deprecated_param( $function, $version, $message = null ) { |
|
| 414 | + protected function deprecated_param($function, $version, $message = null) { |
|
| 415 | 415 | |
| 416 | - if ( is_numeric( $message ) ) { |
|
| 416 | + if (is_numeric($message)) { |
|
| 417 | 417 | $args = func_get_args(); |
| 418 | 418 | |
| 419 | - switch ( $message ) { |
|
| 419 | + switch ($message) { |
|
| 420 | 420 | |
| 421 | 421 | case self::DEPRECATED_PARAM: |
| 422 | - $message = sprintf( __( 'The "%1$s" field parameter has been deprecated in favor of the "%2$s" parameter.', 'cmb2' ), $args[3], $args[4] ); |
|
| 422 | + $message = sprintf(__('The "%1$s" field parameter has been deprecated in favor of the "%2$s" parameter.', 'cmb2'), $args[3], $args[4]); |
|
| 423 | 423 | break; |
| 424 | 424 | |
| 425 | 425 | case self::DEPRECATED_CB_PARAM: |
| 426 | - $message = sprintf( __( 'Using the "%1$s" field parameter as a callback has been deprecated in favor of the "%2$s" parameter.', 'cmb2' ), $args[3], $args[4] ); |
|
| 426 | + $message = sprintf(__('Using the "%1$s" field parameter as a callback has been deprecated in favor of the "%2$s" parameter.', 'cmb2'), $args[3], $args[4]); |
|
| 427 | 427 | break; |
| 428 | 428 | |
| 429 | 429 | default: |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | * @param string $message A message regarding the change. |
| 442 | 442 | * @param string $version The version of CMB2 that deprecated the argument used. |
| 443 | 443 | */ |
| 444 | - do_action( 'deprecated_argument_run', $function, $message, $version ); |
|
| 444 | + do_action('deprecated_argument_run', $function, $message, $version); |
|
| 445 | 445 | |
| 446 | 446 | /** |
| 447 | 447 | * Filters whether to trigger an error for deprecated arguments. This is a WP core filter. |
@@ -450,18 +450,18 @@ discard block |
||
| 450 | 450 | * |
| 451 | 451 | * @param bool $trigger Whether to trigger the error for deprecated arguments. Default true. |
| 452 | 452 | */ |
| 453 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { |
|
| 454 | - if ( function_exists( '__' ) ) { |
|
| 455 | - if ( ! is_null( $message ) ) { |
|
| 456 | - trigger_error( sprintf( __( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', 'cmb2' ), $function, $version, $message ) ); |
|
| 453 | + if (defined('WP_DEBUG') && WP_DEBUG && apply_filters('deprecated_argument_trigger_error', true)) { |
|
| 454 | + if (function_exists('__')) { |
|
| 455 | + if ( ! is_null($message)) { |
|
| 456 | + trigger_error(sprintf(__('%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', 'cmb2'), $function, $version, $message)); |
|
| 457 | 457 | } else { |
| 458 | - trigger_error( sprintf( __( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', 'cmb2' ), $function, $version ) ); |
|
| 458 | + trigger_error(sprintf(__('%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', 'cmb2'), $function, $version)); |
|
| 459 | 459 | } |
| 460 | 460 | } else { |
| 461 | - if ( ! is_null( $message ) ) { |
|
| 462 | - trigger_error( sprintf( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) ); |
|
| 461 | + if ( ! is_null($message)) { |
|
| 462 | + trigger_error(sprintf('%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message)); |
|
| 463 | 463 | } else { |
| 464 | - trigger_error( sprintf( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) ); |
|
| 464 | + trigger_error(sprintf('%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version)); |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | } |
@@ -474,11 +474,11 @@ discard block |
||
| 474 | 474 | * @throws Exception Throws an exception if the field is invalid. |
| 475 | 475 | * @return mixed |
| 476 | 476 | */ |
| 477 | - public function __get( $field ) { |
|
| 478 | - switch ( $field ) { |
|
| 477 | + public function __get($field) { |
|
| 478 | + switch ($field) { |
|
| 479 | 479 | case 'args': |
| 480 | 480 | case 'meta_box': |
| 481 | - if ( $field === $this->properties_name ) { |
|
| 481 | + if ($field === $this->properties_name) { |
|
| 482 | 482 | return $this->{$this->properties_name}; |
| 483 | 483 | } |
| 484 | 484 | case 'properties': |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | case 'object_type': |
| 489 | 489 | return $this->{$field}; |
| 490 | 490 | default: |
| 491 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) ); |
|
| 491 | + throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field)); |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | * @param array $args All arguments passed to the method. |
| 503 | 503 | * @return mixed |
| 504 | 504 | */ |
| 505 | - public function __call( $method, $args ) { |
|
| 506 | - $object_class = strtolower( get_class( $this ) ); |
|
| 505 | + public function __call($method, $args) { |
|
| 506 | + $object_class = strtolower(get_class($this)); |
|
| 507 | 507 | |
| 508 | - if ( ! has_filter( "{$object_class}_inherit_{$method}" ) ) { |
|
| 509 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), get_class( $this ), $method ) ); |
|
| 508 | + if ( ! has_filter("{$object_class}_inherit_{$method}")) { |
|
| 509 | + throw new Exception(sprintf(esc_html__('Invalid %1$s method: %2$s', 'cmb2'), get_class($this), $method)); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - array_unshift( $args, $this ); |
|
| 512 | + array_unshift($args, $this); |
|
| 513 | 513 | |
| 514 | 514 | /** |
| 515 | 515 | * Allows overloading the object (CMB2 or CMB2_Field) with additional capabilities |
@@ -528,6 +528,6 @@ discard block |
||
| 528 | 528 | * @param array $args The arguments to be passed to the hook. |
| 529 | 529 | * The first argument will always be this object instance. |
| 530 | 530 | */ |
| 531 | - return apply_filters_ref_array( "{$object_class}_inherit_{$method}", $args ); |
|
| 531 | + return apply_filters_ref_array("{$object_class}_inherit_{$method}", $args); |
|
| 532 | 532 | } |
| 533 | 533 | } |
@@ -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 | } |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | * @since 2.0.7 |
| 51 | 51 | * @param array|string $dependencies Array (or string) of dependencies to add. |
| 52 | 52 | */ |
| 53 | - public static function add_dependencies( $dependencies ) { |
|
| 54 | - foreach ( (array) $dependencies as $dependency ) { |
|
| 55 | - self::$dependencies[ $dependency ] = $dependency; |
|
| 53 | + public static function add_dependencies($dependencies) { |
|
| 54 | + foreach ((array) $dependencies as $dependency) { |
|
| 55 | + self::$dependencies[$dependency] = $dependency; |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @param CMB2_Field $field Field object. |
| 65 | 65 | */ |
| 66 | - public static function add_field_data( CMB2_Field $field ) { |
|
| 66 | + public static function add_field_data(CMB2_Field $field) { |
|
| 67 | 67 | $hash = $field->hash_id(); |
| 68 | - if ( ! isset( self::$fields[ $hash ] ) ) { |
|
| 69 | - self::$fields[ $hash ] = $field->js_data(); |
|
| 68 | + if ( ! isset(self::$fields[$hash])) { |
|
| 69 | + self::$fields[$hash] = $field->js_data(); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
@@ -77,57 +77,57 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public static function enqueue() { |
| 79 | 79 | // Filter required script dependencies. |
| 80 | - $dependencies = self::$dependencies = apply_filters( 'cmb2_script_dependencies', self::$dependencies ); |
|
| 80 | + $dependencies = self::$dependencies = apply_filters('cmb2_script_dependencies', self::$dependencies); |
|
| 81 | 81 | |
| 82 | 82 | // Only use minified files if SCRIPT_DEBUG is off. |
| 83 | - $debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; |
|
| 83 | + $debug = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG; |
|
| 84 | 84 | |
| 85 | 85 | $min = $debug ? '' : '.min'; |
| 86 | 86 | |
| 87 | 87 | // if colorpicker. |
| 88 | - if ( isset( $dependencies['wp-color-picker'] ) ) { |
|
| 89 | - if ( ! is_admin() ) { |
|
| 88 | + if (isset($dependencies['wp-color-picker'])) { |
|
| 89 | + if ( ! is_admin()) { |
|
| 90 | 90 | self::colorpicker_frontend(); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( isset( $dependencies['wp-color-picker-alpha'] ) ) { |
|
| 93 | + if (isset($dependencies['wp-color-picker-alpha'])) { |
|
| 94 | 94 | self::register_colorpicker_alpha(); |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // if file/file_list. |
| 99 | - if ( isset( $dependencies['media-editor'] ) ) { |
|
| 99 | + if (isset($dependencies['media-editor'])) { |
|
| 100 | 100 | wp_enqueue_media(); |
| 101 | 101 | CMB2_Type_File_Base::output_js_underscore_templates(); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // if timepicker. |
| 105 | - if ( isset( $dependencies['jquery-ui-datetimepicker'] ) ) { |
|
| 105 | + if (isset($dependencies['jquery-ui-datetimepicker'])) { |
|
| 106 | 106 | self::register_datetimepicker(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // if cmb2-wysiwyg. |
| 110 | - $enqueue_wysiwyg = isset( $dependencies['cmb2-wysiwyg'] ) && $debug; |
|
| 111 | - unset( $dependencies['cmb2-wysiwyg'] ); |
|
| 110 | + $enqueue_wysiwyg = isset($dependencies['cmb2-wysiwyg']) && $debug; |
|
| 111 | + unset($dependencies['cmb2-wysiwyg']); |
|
| 112 | 112 | |
| 113 | 113 | // if cmb2-char-counter. |
| 114 | - $enqueue_char_counter = isset( $dependencies['cmb2-char-counter'] ) && $debug; |
|
| 115 | - unset( $dependencies['cmb2-char-counter'] ); |
|
| 114 | + $enqueue_char_counter = isset($dependencies['cmb2-char-counter']) && $debug; |
|
| 115 | + unset($dependencies['cmb2-char-counter']); |
|
| 116 | 116 | |
| 117 | 117 | // Enqueue cmb JS. |
| 118 | - wp_enqueue_script( self::$handle, CMB2_Utils::url( "js/cmb2{$min}.js" ), array_values( $dependencies ), CMB2_VERSION, true ); |
|
| 118 | + wp_enqueue_script(self::$handle, CMB2_Utils::url("js/cmb2{$min}.js"), array_values($dependencies), CMB2_VERSION, true); |
|
| 119 | 119 | |
| 120 | 120 | // if SCRIPT_DEBUG, we need to enqueue separately. |
| 121 | - if ( $enqueue_wysiwyg ) { |
|
| 122 | - wp_enqueue_script( 'cmb2-wysiwyg', CMB2_Utils::url( 'js/cmb2-wysiwyg.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION ); |
|
| 121 | + if ($enqueue_wysiwyg) { |
|
| 122 | + wp_enqueue_script('cmb2-wysiwyg', CMB2_Utils::url('js/cmb2-wysiwyg.js'), array('jquery', 'wp-util'), CMB2_VERSION); |
|
| 123 | 123 | } |
| 124 | - if ( $enqueue_char_counter ) { |
|
| 125 | - wp_enqueue_script( 'cmb2-char-counter', CMB2_Utils::url( 'js/cmb2-char-counter.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION ); |
|
| 124 | + if ($enqueue_char_counter) { |
|
| 125 | + wp_enqueue_script('cmb2-char-counter', CMB2_Utils::url('js/cmb2-char-counter.js'), array('jquery', 'wp-util'), CMB2_VERSION); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - self::localize( $debug ); |
|
| 128 | + self::localize($debug); |
|
| 129 | 129 | |
| 130 | - do_action( 'cmb2_footer_enqueue' ); |
|
| 130 | + do_action('cmb2_footer_enqueue'); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return void |
| 141 | 141 | */ |
| 142 | - public static function register_colorpicker_alpha( $enqueue = false ) { |
|
| 142 | + public static function register_colorpicker_alpha($enqueue = false) { |
|
| 143 | 143 | // Only use minified files if SCRIPT_DEBUG is off. |
| 144 | - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 144 | + $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 145 | 145 | $func = $enqueue ? 'wp_enqueue_script' : 'wp_register_script'; |
| 146 | - $func( 'wp-color-picker-alpha', CMB2_Utils::url( "js/wp-color-picker-alpha{$min}.js" ), array( 'wp-color-picker' ), '2.1.3' ); |
|
| 146 | + $func('wp-color-picker-alpha', CMB2_Utils::url("js/wp-color-picker-alpha{$min}.js"), array('wp-color-picker'), '2.1.3'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return void |
| 157 | 157 | */ |
| 158 | - public static function register_datetimepicker( $enqueue = false ) { |
|
| 158 | + public static function register_datetimepicker($enqueue = false) { |
|
| 159 | 159 | $func = $enqueue ? 'wp_enqueue_script' : 'wp_register_script'; |
| 160 | - $func( 'jquery-ui-datetimepicker', CMB2_Utils::url( 'js/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-slider' ), '1.5.0' ); |
|
| 160 | + $func('jquery-ui-datetimepicker', CMB2_Utils::url('js/jquery-ui-timepicker-addon.min.js'), array('jquery-ui-slider'), '1.5.0'); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | * @since 2.0.7 |
| 167 | 167 | */ |
| 168 | 168 | protected static function colorpicker_frontend() { |
| 169 | - wp_register_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), CMB2_VERSION ); |
|
| 170 | - wp_register_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ), CMB2_VERSION ); |
|
| 171 | - wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', array( |
|
| 172 | - 'clear' => esc_html__( 'Clear', 'cmb2' ), |
|
| 173 | - 'defaultString' => esc_html__( 'Default', 'cmb2' ), |
|
| 174 | - 'pick' => esc_html__( 'Select Color', 'cmb2' ), |
|
| 175 | - 'current' => esc_html__( 'Current Color', 'cmb2' ), |
|
| 176 | - ) ); |
|
| 169 | + wp_register_script('iris', admin_url('js/iris.min.js'), array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), CMB2_VERSION); |
|
| 170 | + wp_register_script('wp-color-picker', admin_url('js/color-picker.min.js'), array('iris'), CMB2_VERSION); |
|
| 171 | + wp_localize_script('wp-color-picker', 'wpColorPickerL10n', array( |
|
| 172 | + 'clear' => esc_html__('Clear', 'cmb2'), |
|
| 173 | + 'defaultString' => esc_html__('Default', 'cmb2'), |
|
| 174 | + 'pick' => esc_html__('Select Color', 'cmb2'), |
|
| 175 | + 'current' => esc_html__('Current Color', 'cmb2'), |
|
| 176 | + )); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -183,17 +183,17 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @param mixed $debug Whether or not we are debugging. |
| 185 | 185 | */ |
| 186 | - protected static function localize( $debug ) { |
|
| 186 | + protected static function localize($debug) { |
|
| 187 | 187 | static $localized = false; |
| 188 | - if ( $localized ) { |
|
| 188 | + if ($localized) { |
|
| 189 | 189 | return; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $localized = true; |
| 193 | 193 | $l10n = array( |
| 194 | 194 | 'fields' => self::$fields, |
| 195 | - 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), |
|
| 196 | - 'ajaxurl' => admin_url( '/admin-ajax.php' ), |
|
| 195 | + 'ajax_nonce' => wp_create_nonce('ajax_nonce'), |
|
| 196 | + 'ajaxurl' => admin_url('/admin-ajax.php'), |
|
| 197 | 197 | 'script_debug' => $debug, |
| 198 | 198 | 'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2', |
| 199 | 199 | 'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2', |
@@ -204,49 +204,49 @@ discard block |
||
| 204 | 204 | 'date_picker' => array( |
| 205 | 205 | 'changeMonth' => true, |
| 206 | 206 | 'changeYear' => true, |
| 207 | - 'dateFormat' => _x( 'mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2' ), |
|
| 208 | - 'dayNames' => explode( ',', esc_html__( 'Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2' ) ), |
|
| 209 | - 'dayNamesMin' => explode( ',', esc_html__( 'Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2' ) ), |
|
| 210 | - 'dayNamesShort' => explode( ',', esc_html__( 'Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2' ) ), |
|
| 211 | - 'monthNames' => explode( ',', esc_html__( 'January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2' ) ), |
|
| 212 | - 'monthNamesShort' => explode( ',', esc_html__( 'Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2' ) ), |
|
| 213 | - 'nextText' => esc_html__( 'Next', 'cmb2' ), |
|
| 214 | - 'prevText' => esc_html__( 'Prev', 'cmb2' ), |
|
| 215 | - 'currentText' => esc_html__( 'Today', 'cmb2' ), |
|
| 216 | - 'closeText' => esc_html__( 'Done', 'cmb2' ), |
|
| 217 | - 'clearText' => esc_html__( 'Clear', 'cmb2' ), |
|
| 207 | + 'dateFormat' => _x('mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2'), |
|
| 208 | + 'dayNames' => explode(',', esc_html__('Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2')), |
|
| 209 | + 'dayNamesMin' => explode(',', esc_html__('Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2')), |
|
| 210 | + 'dayNamesShort' => explode(',', esc_html__('Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2')), |
|
| 211 | + 'monthNames' => explode(',', esc_html__('January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2')), |
|
| 212 | + 'monthNamesShort' => explode(',', esc_html__('Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2')), |
|
| 213 | + 'nextText' => esc_html__('Next', 'cmb2'), |
|
| 214 | + 'prevText' => esc_html__('Prev', 'cmb2'), |
|
| 215 | + 'currentText' => esc_html__('Today', 'cmb2'), |
|
| 216 | + 'closeText' => esc_html__('Done', 'cmb2'), |
|
| 217 | + 'clearText' => esc_html__('Clear', 'cmb2'), |
|
| 218 | 218 | ), |
| 219 | 219 | 'time_picker' => array( |
| 220 | - 'timeOnlyTitle' => esc_html__( 'Choose Time', 'cmb2' ), |
|
| 221 | - 'timeText' => esc_html__( 'Time', 'cmb2' ), |
|
| 222 | - 'hourText' => esc_html__( 'Hour', 'cmb2' ), |
|
| 223 | - 'minuteText' => esc_html__( 'Minute', 'cmb2' ), |
|
| 224 | - 'secondText' => esc_html__( 'Second', 'cmb2' ), |
|
| 225 | - 'currentText' => esc_html__( 'Now', 'cmb2' ), |
|
| 226 | - 'closeText' => esc_html__( 'Done', 'cmb2' ), |
|
| 227 | - 'timeFormat' => _x( 'hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2' ), |
|
| 220 | + 'timeOnlyTitle' => esc_html__('Choose Time', 'cmb2'), |
|
| 221 | + 'timeText' => esc_html__('Time', 'cmb2'), |
|
| 222 | + 'hourText' => esc_html__('Hour', 'cmb2'), |
|
| 223 | + 'minuteText' => esc_html__('Minute', 'cmb2'), |
|
| 224 | + 'secondText' => esc_html__('Second', 'cmb2'), |
|
| 225 | + 'currentText' => esc_html__('Now', 'cmb2'), |
|
| 226 | + 'closeText' => esc_html__('Done', 'cmb2'), |
|
| 227 | + 'timeFormat' => _x('hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2'), |
|
| 228 | 228 | 'controlType' => 'select', |
| 229 | 229 | 'stepMinute' => 5, |
| 230 | 230 | ), |
| 231 | 231 | ), |
| 232 | 232 | 'strings' => array( |
| 233 | - 'upload_file' => esc_html__( 'Use this file', 'cmb2' ), |
|
| 234 | - 'upload_files' => esc_html__( 'Use these files', 'cmb2' ), |
|
| 235 | - 'remove_image' => esc_html__( 'Remove Image', 'cmb2' ), |
|
| 236 | - 'remove_file' => esc_html__( 'Remove', 'cmb2' ), |
|
| 237 | - 'file' => esc_html__( 'File:', 'cmb2' ), |
|
| 238 | - 'download' => esc_html__( 'Download', 'cmb2' ), |
|
| 239 | - 'check_toggle' => esc_html__( 'Select / Deselect All', 'cmb2' ), |
|
| 233 | + 'upload_file' => esc_html__('Use this file', 'cmb2'), |
|
| 234 | + 'upload_files' => esc_html__('Use these files', 'cmb2'), |
|
| 235 | + 'remove_image' => esc_html__('Remove Image', 'cmb2'), |
|
| 236 | + 'remove_file' => esc_html__('Remove', 'cmb2'), |
|
| 237 | + 'file' => esc_html__('File:', 'cmb2'), |
|
| 238 | + 'download' => esc_html__('Download', 'cmb2'), |
|
| 239 | + 'check_toggle' => esc_html__('Select / Deselect All', 'cmb2'), |
|
| 240 | 240 | ), |
| 241 | 241 | ); |
| 242 | 242 | |
| 243 | - if ( isset( self::$dependencies['code-editor'] ) && function_exists( 'wp_enqueue_code_editor' ) ) { |
|
| 244 | - $l10n['defaults']['code_editor'] = wp_enqueue_code_editor( array( |
|
| 243 | + if (isset(self::$dependencies['code-editor']) && function_exists('wp_enqueue_code_editor')) { |
|
| 244 | + $l10n['defaults']['code_editor'] = wp_enqueue_code_editor(array( |
|
| 245 | 245 | 'type' => 'text/html', |
| 246 | - ) ); |
|
| 246 | + )); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - wp_localize_script( self::$handle, self::$js_variable, apply_filters( 'cmb2_localized_data', $l10n ) ); |
|
| 249 | + wp_localize_script(self::$handle, self::$js_variable, apply_filters('cmb2_localized_data', $l10n)); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | } |
@@ -12,51 +12,51 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class CMB2_Type_Text_Datetime_Timestamp_Timezone extends CMB2_Type_Base { |
| 14 | 14 | |
| 15 | - public function render( $args = array() ) { |
|
| 15 | + public function render($args = array()) { |
|
| 16 | 16 | $field = $this->field; |
| 17 | 17 | |
| 18 | 18 | $value = $field->escaped_value(); |
| 19 | - if ( empty( $value ) ) { |
|
| 19 | + if (empty($value)) { |
|
| 20 | 20 | $value = $field->get_default(); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - $args = wp_parse_args( $this->args, array( |
|
| 23 | + $args = wp_parse_args($this->args, array( |
|
| 24 | 24 | 'value' => $value, |
| 25 | - 'desc' => $this->_desc( true ), |
|
| 25 | + 'desc' => $this->_desc(true), |
|
| 26 | 26 | 'text_datetime_timestamp' => array(), |
| 27 | 27 | 'select_timezone' => array(), |
| 28 | - ) ); |
|
| 28 | + )); |
|
| 29 | 29 | |
| 30 | 30 | $args['value'] = $value; |
| 31 | - if ( is_array( $args['value'] ) ) { |
|
| 31 | + if (is_array($args['value'])) { |
|
| 32 | 32 | $args['value'] = ''; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - $datetime = maybe_unserialize( $args['value'] ); |
|
| 35 | + $datetime = maybe_unserialize($args['value']); |
|
| 36 | 36 | $value = $tzstring = ''; |
| 37 | 37 | |
| 38 | - if ( $datetime && $datetime instanceof DateTime ) { |
|
| 38 | + if ($datetime && $datetime instanceof DateTime) { |
|
| 39 | 39 | $tz = $datetime->getTimezone(); |
| 40 | 40 | $tzstring = $tz->getName(); |
| 41 | 41 | $value = $datetime->getTimestamp(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $timestamp_args = wp_parse_args( $args['text_datetime_timestamp'], array( |
|
| 44 | + $timestamp_args = wp_parse_args($args['text_datetime_timestamp'], array( |
|
| 45 | 45 | 'desc' => '', |
| 46 | 46 | 'value' => $value, |
| 47 | 47 | 'rendered' => true, |
| 48 | - ) ); |
|
| 49 | - $datetime_timestamp = $this->types->text_datetime_timestamp( $timestamp_args ); |
|
| 48 | + )); |
|
| 49 | + $datetime_timestamp = $this->types->text_datetime_timestamp($timestamp_args); |
|
| 50 | 50 | |
| 51 | - $timezone_select_args = wp_parse_args( $args['select_timezone'], array( |
|
| 51 | + $timezone_select_args = wp_parse_args($args['select_timezone'], array( |
|
| 52 | 52 | 'class' => 'cmb2_select cmb2-select-timezone', |
| 53 | - 'name' => $this->_name( '[timezone]' ), |
|
| 54 | - 'id' => $this->_id( '_timezone' ), |
|
| 55 | - 'options' => wp_timezone_choice( $tzstring ), |
|
| 53 | + 'name' => $this->_name('[timezone]'), |
|
| 54 | + 'id' => $this->_id('_timezone'), |
|
| 55 | + 'options' => wp_timezone_choice($tzstring), |
|
| 56 | 56 | 'desc' => $args['desc'], |
| 57 | 57 | 'rendered' => true, |
| 58 | - ) ); |
|
| 59 | - $select = $this->types->select( $timezone_select_args ); |
|
| 58 | + )); |
|
| 59 | + $select = $this->types->select($timezone_select_args); |
|
| 60 | 60 | |
| 61 | 61 | return $this->rendered( |
| 62 | 62 | $datetime_timestamp . "\n" . $select |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param array $args Array of arguments for the type. |
| 29 | 29 | * @param mixed $is_checked Whether or not the field is checked, or default value. |
| 30 | 30 | */ |
| 31 | - public function __construct( CMB2_Types $types, $args = array(), $is_checked = null ) { |
|
| 32 | - parent::__construct( $types, $args ); |
|
| 31 | + public function __construct(CMB2_Types $types, $args = array(), $is_checked = null) { |
|
| 32 | + parent::__construct($types, $args); |
|
| 33 | 33 | $this->is_checked = $is_checked; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $args Array of arguments for the rendering. |
| 42 | 42 | * @return CMB2_Type_Base|string |
| 43 | 43 | */ |
| 44 | - public function render( $args = array() ) { |
|
| 44 | + public function render($args = array()) { |
|
| 45 | 45 | $defaults = array( |
| 46 | 46 | 'type' => 'checkbox', |
| 47 | 47 | 'class' => 'cmb2-option cmb2-list', |
@@ -52,20 +52,20 @@ discard block |
||
| 52 | 52 | $meta_value = $this->field->escaped_value(); |
| 53 | 53 | |
| 54 | 54 | $is_checked = null === $this->is_checked |
| 55 | - ? ! empty( $meta_value ) |
|
| 55 | + ? ! empty($meta_value) |
|
| 56 | 56 | : $this->is_checked; |
| 57 | 57 | |
| 58 | - if ( $is_checked ) { |
|
| 58 | + if ($is_checked) { |
|
| 59 | 59 | $defaults['checked'] = 'checked'; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $args = $this->parse_args( 'checkbox', $defaults ); |
|
| 62 | + $args = $this->parse_args('checkbox', $defaults); |
|
| 63 | 63 | |
| 64 | 64 | return $this->rendered( |
| 65 | 65 | sprintf( |
| 66 | 66 | '%s <label for="%s">%s</label>', |
| 67 | - parent::render( $args ), |
|
| 68 | - $this->_id( '', false ), |
|
| 67 | + parent::render($args), |
|
| 68 | + $this->_id('', false), |
|
| 69 | 69 | $this->_desc() |
| 70 | 70 | ) |
| 71 | 71 | ); |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param array $args Array of arguments for the type. |
| 29 | 29 | * @param string $value Value that the field type is currently set to, or default value. |
| 30 | 30 | */ |
| 31 | - public function __construct( CMB2_Types $types, $args = array(), $value = '' ) { |
|
| 32 | - parent::__construct( $types, $args ); |
|
| 31 | + public function __construct(CMB2_Types $types, $args = array(), $value = '') { |
|
| 32 | + parent::__construct($types, $args); |
|
| 33 | 33 | $this->value = $value ? $value : $this->value; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -42,41 +42,41 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return CMB2_Type_Base|string |
| 44 | 44 | */ |
| 45 | - public function render( $args = array() ) { |
|
| 45 | + public function render($args = array()) { |
|
| 46 | 46 | $meta_value = $this->value ? $this->value : $this->field->escaped_value(); |
| 47 | 47 | |
| 48 | 48 | $hex_color = '(([a-fA-F0-9]){3}){1,2}$'; |
| 49 | - if ( preg_match( '/^' . $hex_color . '/i', $meta_value ) ) { |
|
| 49 | + if (preg_match('/^' . $hex_color . '/i', $meta_value)) { |
|
| 50 | 50 | // Value is just 123abc, so prepend #. |
| 51 | 51 | $meta_value = '#' . $meta_value; |
| 52 | 52 | } elseif ( |
| 53 | 53 | // If value doesn't match #123abc... |
| 54 | - ! preg_match( '/^#' . $hex_color . '/i', $meta_value ) |
|
| 54 | + ! preg_match('/^#' . $hex_color . '/i', $meta_value) |
|
| 55 | 55 | // And value doesn't match rgba()... |
| 56 | - && 0 !== strpos( trim( $meta_value ), 'rgba' ) |
|
| 56 | + && 0 !== strpos(trim($meta_value), 'rgba') |
|
| 57 | 57 | ) { |
| 58 | 58 | // Then sanitize to just #. |
| 59 | 59 | $meta_value = '#'; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 62 | + wp_enqueue_style('wp-color-picker'); |
|
| 63 | 63 | |
| 64 | - $args = wp_parse_args( $args, array( |
|
| 64 | + $args = wp_parse_args($args, array( |
|
| 65 | 65 | 'class' => 'cmb2-text-small', |
| 66 | - ) ); |
|
| 66 | + )); |
|
| 67 | 67 | |
| 68 | 68 | $args['class'] .= ' cmb2-colorpicker'; |
| 69 | 69 | $args['value'] = $meta_value; |
| 70 | - $args['js_dependencies'] = array( 'wp-color-picker' ); |
|
| 70 | + $args['js_dependencies'] = array('wp-color-picker'); |
|
| 71 | 71 | |
| 72 | - if ( $this->field->options( 'alpha' ) ) { |
|
| 72 | + if ($this->field->options('alpha')) { |
|
| 73 | 73 | $args['js_dependencies'][] = 'wp-color-picker-alpha'; |
| 74 | 74 | $args['data-alpha'] = 'true'; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $args = wp_parse_args( $this->args, $args ); |
|
| 77 | + $args = wp_parse_args($this->args, $args); |
|
| 78 | 78 | |
| 79 | - return parent::render( $args ); |
|
| 79 | + return parent::render($args); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | * @since 2.2.6.2 |
| 86 | 86 | */ |
| 87 | 87 | public static function dequeue_rgba_colorpicker_script() { |
| 88 | - if ( wp_script_is( 'jw-cmb2-rgba-picker-js', 'enqueued' ) ) { |
|
| 89 | - wp_dequeue_script( 'jw-cmb2-rgba-picker-js' ); |
|
| 90 | - CMB2_JS::register_colorpicker_alpha( true ); |
|
| 88 | + if (wp_script_is('jw-cmb2-rgba-picker-js', 'enqueued')) { |
|
| 89 | + wp_dequeue_script('jw-cmb2-rgba-picker-js'); |
|
| 90 | + CMB2_JS::register_colorpicker_alpha(true); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -21,17 +21,17 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function render() { |
| 23 | 23 | return $this->rendered( |
| 24 | - $this->types->radio( array( |
|
| 24 | + $this->types->radio(array( |
|
| 25 | 25 | 'options' => $this->get_term_options(), |
| 26 | - ), 'taxonomy_radio_hierarchical' ) |
|
| 26 | + ), 'taxonomy_radio_hierarchical') |
|
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - protected function list_term_input( $term, $saved_term ) { |
|
| 31 | - $options = parent::list_term_input( $term, $saved_term ); |
|
| 32 | - $children = $this->build_children( $term, $saved_term ); |
|
| 30 | + protected function list_term_input($term, $saved_term) { |
|
| 31 | + $options = parent::list_term_input($term, $saved_term); |
|
| 32 | + $children = $this->build_children($term, $saved_term); |
|
| 33 | 33 | |
| 34 | - if ( ! empty( $children ) ) { |
|
| 34 | + if ( ! empty($children)) { |
|
| 35 | 35 | $options .= $children; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -27,26 +27,26 @@ |
||
| 27 | 27 | * @param CMB2_Types $types |
| 28 | 28 | * @param array $args |
| 29 | 29 | */ |
| 30 | - public function __construct( CMB2_Types $types, $args = array(), $type = '' ) { |
|
| 31 | - parent::__construct( $types, $args ); |
|
| 30 | + public function __construct(CMB2_Types $types, $args = array(), $type = '') { |
|
| 31 | + parent::__construct($types, $args); |
|
| 32 | 32 | $this->type = $type ? $type : $this->type; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function render() { |
| 36 | - $args = $this->parse_args( $this->type, array( |
|
| 36 | + $args = $this->parse_args($this->type, array( |
|
| 37 | 37 | 'class' => 'cmb2-radio-list cmb2-list', |
| 38 | - 'options' => $this->concat_items( array( |
|
| 38 | + 'options' => $this->concat_items(array( |
|
| 39 | 39 | 'label' => 'test', |
| 40 | 40 | 'method' => 'list_input', |
| 41 | - ) ), |
|
| 42 | - 'desc' => $this->_desc( true ), |
|
| 43 | - ) ); |
|
| 41 | + )), |
|
| 42 | + 'desc' => $this->_desc(true), |
|
| 43 | + )); |
|
| 44 | 44 | |
| 45 | - return $this->rendered( $this->ul( $args ) ); |
|
| 45 | + return $this->rendered($this->ul($args)); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - protected function ul( $a ) { |
|
| 49 | - return sprintf( '<ul class="%s">%s</ul>%s', $a['class'], $a['options'], $a['desc'] ); |
|
| 48 | + protected function ul($a) { |
|
| 49 | + return sprintf('<ul class="%s">%s</ul>%s', $a['class'], $a['options'], $a['desc']); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | } |