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

211 lines 4.5 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) 2020, Studio 164a
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.0.0
12 * @version 1.4.0
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 * @return mixed
43 */
44 function charitable_get_option( $key, $default = false, $settings = array() ) {
45 if ( empty( $settings ) ) {
46 $settings = get_option( 'charitable_settings' );
47 }
48
49 if ( ! is_array( $key ) ) {
50 $key = array( $key );
51 }
52
53 $current_key = current( $key );
54
55 /* Key does not exist */
56 if ( ! isset( $settings[ $current_key ] ) ) {
57 return $default;
58 }
59
60 array_shift( $key );
61
62 if ( ! empty( $key ) ) {
63 return charitable_get_option( $key, $default, $settings[ $current_key ] );
64 }
65
66 return $settings[ $current_key ];
67 }
68
69 /**
70 * Returns a helper class.
71 *
72 * @since 1.0.0
73 *
74 * @param string $class_key The class to get an object for.
75 * @return mixed|false
76 */
77 function charitable_get_helper( $class_key ) {
78 return charitable()->registry()->get( $class_key );
79 }
80
81 /**
82 * Returns the Charitable_Notices class instance.
83 *
84 * @since 1.0.0
85 *
86 * @return Charitable_Notices
87 */
88 function charitable_get_notices() {
89 return charitable()->registry()->get( 'notices' );
90 }
91
92 /**
93 * Returns the Charitable_Donation_Processor class instance.
94 *
95 * @since 1.0.0
96 *
97 * @return Charitable_Donation_Processor
98 */
99 function charitable_get_donation_processor() {
100 $registry = charitable()->registry();
101
102 if ( ! $registry->has( 'donation_processor' ) ) {
103 $registry->register_object( Charitable_Donation_Processor::get_instance() );
104 }
105
106 return $registry->get( 'donation_processor' );
107 }
108
109 /**
110 * Return Charitable_Locations helper class.
111 *
112 * @since 1.0.0
113 *
114 * @return Charitable_Locations
115 */
116 function charitable_get_location_helper() {
117 return charitable()->registry()->get( 'locations' );
118 }
119
120 /**
121 * Returns the current user's session object.
122 *
123 * @since 1.0.0
124 *
125 * @return Charitable_Session
126 */
127 function charitable_get_session() {
128 return charitable()->registry()->get( 'session' );
129 }
130
131 /**
132 * Returns the current request helper object.
133 *
134 * @since 1.0.0
135 *
136 * @return Charitable_Request
137 */
138 function charitable_get_request() {
139 $registry = charitable()->registry();
140
141 if ( ! $registry->has( 'request' ) ) {
142 $registry->register_object( Charitable_Request::get_instance() );
143 }
144
145 return $registry->get( 'request' );
146 }
147
148 /**
149 * Returns the Charitable_User_Dashboard object.
150 *
151 * @since 1.0.0
152 *
153 * @return Charitable_User_Dashboard
154 */
155 function charitable_get_user_dashboard() {
156 return charitable()->registry()->get( 'user_dashboard' );
157 }
158
159 /**
160 * Return the database table helper object.
161 *
162 * @since 1.0.0
163 *
164 * @param string $table The table key.
165 * @return mixed|null A child class of Charitable_DB if table exists. null otherwise.
166 */
167 function charitable_get_table( $table ) {
168 return charitable()->get_db_table( $table );
169 }
170
171 /**
172 * Returns the current donation form.
173 *
174 * @since 1.0.0
175 *
176 * @return Charitable_Donation_Form_Interface|false
177 */
178 function charitable_get_current_donation_form() {
179 $campaign = charitable_get_current_campaign();
180 return false === $campaign ? false : $campaign->get_donation_form();
181 }
182
183 /**
184 * Returns the provided array as a HTML element attribute.
185 *
186 * @since 1.0.0
187 *
188 * @param array $args Arguments to be added.
189 * @return string
190 */
191 function charitable_get_action_args( $args ) {
192 return sprintf( "data-charitable-args='%s'", json_encode( $args ) );
193 }
194
195 /**
196 * Returns the Charitable_Deprecated class, loading the file if required.
197 *
198 * @since 1.4.0
199 *
200 * @return Charitable_Deprecated
201 */
202 function charitable_get_deprecated() {
203 $registry = charitable()->registry();
204
205 if ( ! $registry->has( 'deprecated' ) ) {
206 $registry->register_object( Charitable_Deprecated::get_instance() );
207 }
208
209 return $registry->get( 'deprecated' );
210 }
211