← All changes
|
includes/admin/forms/views/class-charitable-admin-form-view.php
+43
-18
1.6.7
→
1.8.13
View file →
| @@ -4,17 +4,19 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * This is responsible for rendering the output of forms in the WordPress dashboard. |
| 6 | 6 | * |
| 7 | 7 | * @package Charitable/Forms/Charitable_Admin_Form_View |
| 8 | - * @author Eric Daams | |
| 9 | - * @copyright Copyright (c) 2018, Studio 164a | |
| 8 | + * @author David Bisset | |
| 9 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 10 | 10 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 11 | 11 | * @since 1.5.0 |
| 12 | - * @version 1.5.9 | |
| 12 | + * @version 1.6.45 | |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | // Exit if accessed directly. |
| 16 | -if ( ! defined( 'ABSPATH' ) ) { exit; } | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit; | |
| 18 | +} | |
| 17 | 19 | |
| 18 | 20 | if ( ! class_exists( 'Charitable_Admin_Form_View' ) ) : |
| 19 | 21 | |
| 20 | 22 | /** |
| @@ -342,15 +344,15 @@ | ||
| 342 | 344 | * @param array $field Field definition. |
| 343 | 345 | * @return boolean |
| 344 | 346 | */ |
| 345 | 347 | protected function is_field_checked( $field ) { |
| 346 | - if ( array_key_exists( 'checked', $field ) ) { | |
| 348 | + if ( isset( $field['checked'] ) ) { | |
| 347 | 349 | return $field['checked']; |
| 348 | 350 | } |
| 349 | 351 | |
| 350 | 352 | $value = $this->get_current_value( $field ); |
| 351 | 353 | |
| 352 | - if ( array_key_exists( 'value', $field ) ) { | |
| 354 | + if ( isset( $field['value'] ) ) { | |
| 353 | 355 | return $field['value'] == $value; |
| 354 | 356 | } |
| 355 | 357 | |
| 356 | 358 | return false != $value; |
| @@ -364,21 +366,41 @@ | ||
| 364 | 366 | * @param array $field Field definition. |
| 365 | 367 | * @return mixed |
| 366 | 368 | */ |
| 367 | 369 | protected function get_current_value( $field ) { |
| 368 | - global $post; | |
| 369 | - | |
| 370 | 370 | if ( empty( $field['key'] ) ) { |
| 371 | 371 | return; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $default = array_key_exists( 'default', $field ) ? $field['default'] : ''; |
| 375 | - $value = get_post_meta( $post->ID, $field['key'], true ); | |
| 376 | 375 | |
| 377 | - return $value ? $value : $default; | |
| 376 | + if ( ! in_array( $field['key'], $this->get_post_custom_keys() ) ) { | |
| 377 | + return $default; | |
| 378 | + } | |
| 379 | + | |
| 380 | + return get_post_meta( $this->get_post()->ID, $field['key'], true ); | |
| 378 | 381 | } |
| 379 | 382 | |
| 380 | 383 | /** |
| 384 | + * Get the post object. | |
| 385 | + * | |
| 386 | + * @since 1.6.45 | |
| 387 | + * | |
| 388 | + * @global WP_Post $post | |
| 389 | + * | |
| 390 | + * @return WP_Post|Null | |
| 391 | + */ | |
| 392 | + public function get_post() { | |
| 393 | + if ( ! isset( $this->post ) ) { | |
| 394 | + global $post; | |
| 395 | + | |
| 396 | + $this->post = $post; | |
| 397 | + } | |
| 398 | + | |
| 399 | + return $this->post; | |
| 400 | + } | |
| 401 | + | |
| 402 | + /** | |
| 381 | 403 | * Return the custom keys for the current post. |
| 382 | 404 | * |
| 383 | 405 | * @since 1.5.0 |
| 384 | 406 | * |
| @@ -384,14 +406,14 @@ | ||
| 384 | 406 | * |
| 385 | 407 | * @return array |
| 386 | 408 | */ |
| 387 | 409 | protected function get_post_custom_keys() { |
| 388 | - if ( ! is_a( $this->post, 'WP_Post' ) ) { | |
| 410 | + if ( ! is_a( $this->get_post(), 'WP_Post' ) ) { | |
| 389 | 411 | return array(); |
| 390 | 412 | } |
| 391 | 413 | |
| 392 | 414 | if ( ! isset( $this->post_custom_keys ) ) { |
| 393 | - $this->post_custom_keys = get_post_custom_keys( $this->post->ID ); | |
| 415 | + $this->post_custom_keys = get_post_custom_keys( $this->get_post()->ID ); | |
| 394 | 416 | |
| 395 | 417 | if ( ! is_array( $this->post_custom_keys ) ) { |
| 396 | 418 | $this->post_custom_keys = array(); |
| 397 | 419 | } |
| @@ -415,14 +437,17 @@ | ||
| 415 | 437 | * @since 1.0.0 |
| 416 | 438 | * |
| 417 | 439 | * @param string[] $types Field types. |
| 418 | 440 | */ |
| 419 | - $default_field_types = apply_filters( 'charitable_default_template_field_types', array( | |
| 420 | - 'text', | |
| 421 | - 'email', | |
| 422 | - 'password', | |
| 423 | - 'date', | |
| 424 | - ) ); | |
| 441 | + $default_field_types = apply_filters( | |
| 442 | + 'charitable_default_template_field_types', | |
| 443 | + array( | |
| 444 | + 'text', | |
| 445 | + 'email', | |
| 446 | + 'password', | |
| 447 | + 'date', | |
| 448 | + ) | |
| 449 | + ); | |
| 425 | 450 | |
| 426 | 451 | return in_array( $field_type, $default_field_types ); |
| 427 | 452 | } |
| 428 | 453 | |