PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.2
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.2
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / fields / class-charitable-object-fields.php

class-charitable-object-fields.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11.2, at includes/fields/class-charitable-object-fields.php

108 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Object Fields model.
4 *
5 * @package Charitable/Classes/Charitable_Object_Fields
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.6.0
10 * @version 1.6.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Object_Fields' ) ) :
19
20 /**
21 * Charitable_Object_Fields
22 *
23 * @since 1.6.0
24 */
25 class Charitable_Object_Fields implements Charitable_Fields_Interface {
26
27 /**
28 * The `Charitable_Field_Registry` instance for this object.
29 *
30 * @since 1.6.0
31 *
32 * @var Charitable_Field_Registry
33 */
34 private $registry;
35
36 /**
37 * An object.
38 *
39 * @since 1.6.0
40 *
41 * @var mixed
42 */
43 private $object;
44
45 /**
46 * Create class object.
47 *
48 * @since 1.6.0
49 *
50 * @param Charitable_Field_Registry $registry An instance of `Charitable_Field_Registry`.
51 * @param mixed $object The object that will be passed to the value callback.
52 */
53 public function __construct( Charitable_Field_Registry $registry, $object ) {
54 $this->registry = $registry;
55 $this->object = $object;
56 }
57
58 /**
59 * Get the set value for a particular field.
60 *
61 * @since 1.6.0
62 *
63 * @param string $field_key The field to get a value for.
64 * @return mixed
65 */
66 public function get( $field_key ) {
67 $field = $this->registry->get_field( $field_key );
68
69 if ( ! $field ) {
70 return null;
71 }
72
73 if ( is_callable( $field->value_callback ) ) {
74 return call_user_func( $field->value_callback, $this->object, $field_key );
75 }
76
77 return null;
78 }
79
80 /**
81 * Check whether a particular field is registered.
82 *
83 * @since 1.6.0
84 *
85 * @param string $field_key The field to check for.
86 * @return boolean
87 */
88 public function has( $field_key ) {
89 return false !== $this->registry->get_field( $field_key );
90 }
91
92 /**
93 * Check whether a particular field has a callback for getting the value.
94 *
95 * @since 1.6.0
96 *
97 * @param string $field_key The field to check for.
98 * @return boolean
99 */
100 public function has_value_callback( $field_key ) {
101 $field = $this->registry->get_field( $field_key );
102
103 return $field && false !== $field->value_callback;
104 }
105 }
106
107 endif;
108