PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.57
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.57
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 / charitable-core-functions.php

charitable-core-functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.57, at includes/charitable-core-functions.php

225 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Core Functions.
4 *
5 * General core functions.
6 *
7 * @package Charitable/Functions/Core
8 * @author Eric Daams
9 * @copyright Copyright (c) 2022, Studio 164a
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.0.0
12 * @version 1.6.37
13 */
14
15 // Exit if accessed directly.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * This returns the original Charitable object.
22 *
23 * Use this whenever you want to get an instance of the class. There is no
24 * reason to instantiate a new object, though you can do so if you're stubborn :)
25 *
26 * @since 1.0.0
27 *
28 * @return Charitable
29 */
30 function charitable() {
31 return Charitable::get_instance();
32 }
33
34 /**
35 * This returns the value for a particular Charitable setting.
36 *
37 * @since 1.0.0
38 *
39 * @param mixed $key Accepts an array of strings or a single string.
40 * @param mixed $default The value to return if key is not set.
41 * @param array $settings Optional. Used when $key is an array.
42 * @param mixed $original_key Optional. Original array of keys.
43 * @return mixed
44 */
45 function charitable_get_option( $key, $default = false, $settings = array(), $original_key = array() ) {
46 if ( empty( $settings ) ) {
47 $settings = get_option( 'charitable_settings' );
48 }
49
50 if ( ! is_array( $key ) ) {
51 $key = array( $key );
52 }
53
54 $current_key = current( $key );
55
56 if ( empty( $original_key ) ) {
57 $original_key = $key;
58 }
59
60 /* Key does not exist */
61 if ( ! isset( $settings[ $current_key ] ) ) {
62 return $default;
63 }
64
65 array_shift( $key );
66
67 if ( ! empty( $key ) ) {
68 return charitable_get_option( $key, $default, $settings[ $current_key ], $original_key );
69 }
70
71 /**
72 * Filter the option value.
73 *
74 * @since 1.6.37
75 *
76 * @param mixed $value The option value.
77 * @param mixed $key The key, or list of keys.
78 * @param mixed $default The default value.
79 */
80 return apply_filters( 'charitable_option_' . $current_key, $settings[ $current_key ], $original_key, $default );
81 }
82
83 /**
84 * Returns a helper class.
85 *
86 * @since 1.0.0
87 *
88 * @param string $class_key The class to get an object for.
89 * @return mixed|false
90 */
91 function charitable_get_helper( $class_key ) {
92 return charitable()->registry()->get( $class_key );
93 }
94
95 /**
96 * Returns the Charitable_Notices class instance.
97 *
98 * @since 1.0.0
99 *
100 * @return Charitable_Notices
101 */
102 function charitable_get_notices() {
103 return charitable()->registry()->get( 'notices' );
104 }
105
106 /**
107 * Returns the Charitable_Donation_Processor class instance.
108 *
109 * @since 1.0.0
110 *
111 * @return Charitable_Donation_Processor
112 */
113 function charitable_get_donation_processor() {
114 $registry = charitable()->registry();
115
116 if ( ! $registry->has( 'donation_processor' ) ) {
117 $registry->register_object( Charitable_Donation_Processor::get_instance() );
118 }
119
120 return $registry->get( 'donation_processor' );
121 }
122
123 /**
124 * Return Charitable_Locations helper class.
125 *
126 * @since 1.0.0
127 *
128 * @return Charitable_Locations
129 */
130 function charitable_get_location_helper() {
131 return charitable()->registry()->get( 'locations' );
132 }
133
134 /**
135 * Returns the current user's session object.
136 *
137 * @since 1.0.0
138 *
139 * @return Charitable_Session
140 */
141 function charitable_get_session() {
142 return charitable()->registry()->get( 'session' );
143 }
144
145 /**
146 * Returns the current request helper object.
147 *
148 * @since 1.0.0
149 *
150 * @return Charitable_Request
151 */
152 function charitable_get_request() {
153 $registry = charitable()->registry();
154
155 if ( ! $registry->has( 'request' ) ) {
156 $registry->register_object( Charitable_Request::get_instance() );
157 }
158
159 return $registry->get( 'request' );
160 }
161
162 /**
163 * Returns the Charitable_User_Dashboard object.
164 *
165 * @since 1.0.0
166 *
167 * @return Charitable_User_Dashboard
168 */
169 function charitable_get_user_dashboard() {
170 return charitable()->registry()->get( 'user_dashboard' );
171 }
172
173 /**
174 * Return the database table helper object.
175 *
176 * @since 1.0.0
177 *
178 * @param string $table The table key.
179 * @return mixed|null A child class of Charitable_DB if table exists. null otherwise.
180 */
181 function charitable_get_table( $table ) {
182 return charitable()->get_db_table( $table );
183 }
184
185 /**
186 * Returns the current donation form.
187 *
188 * @since 1.0.0
189 *
190 * @return Charitable_Donation_Form_Interface|false
191 */
192 function charitable_get_current_donation_form() {
193 $campaign = charitable_get_current_campaign();
194 return false === $campaign ? false : $campaign->get_donation_form();
195 }
196
197 /**
198 * Returns the provided array as a HTML element attribute.
199 *
200 * @since 1.0.0
201 *
202 * @param array $args Arguments to be added.
203 * @return string
204 */
205 function charitable_get_action_args( $args ) {
206 return sprintf( "data-charitable-args='%s'", json_encode( $args ) );
207 }
208
209 /**
210 * Returns the Charitable_Deprecated class, loading the file if required.
211 *
212 * @since 1.4.0
213 *
214 * @return Charitable_Deprecated
215 */
216 function charitable_get_deprecated() {
217 $registry = charitable()->registry();
218
219 if ( ! $registry->has( 'deprecated' ) ) {
220 $registry->register_object( Charitable_Deprecated::get_instance() );
221 }
222
223 return $registry->get( 'deprecated' );
224 }
225