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

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