PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.9
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.9
1.8.13.1 1.8.13 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 All 212 releases
charitable / includes / users / class-charitable-user-avatar.php

class-charitable-user-avatar.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.9, at includes/users/class-charitable-user-avatar.php

377 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The main Charitable User Avatar class.
4 *
5 * The responsibility of this class is to load all the plugin's functionality.
6 *
7 * @package Charitable User Avatar
8 * @copyright Copyright (c) 2017, Eric Daams
9 * @license http://opensource.org/licenses/gpl-1.0.0.php GNU Public License
10 * @since 1.0.0
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) { exit; }
14
15 if ( ! class_exists( 'Charitable_User_Avatar' ) ) :
16
17 /**
18 * Charitable_User_Avatar
19 *
20 * @since 1.0.0
21 */
22 class Charitable_User_Avatar {
23
24 /* @var string */
25 const VERSION = '1.0.7';
26
27 /* @var string */
28 const DB_VERSION = '20150818';
29
30 /* @var string */
31 const NAME = 'Charitable User Avatar';
32
33 /* @var string */
34 const AUTHOR = 'Studio 164a';
35
36 /**
37 * Single class instance.
38 *
39 * @var Charitable_User_Avatar
40 */
41 private static $instance = null;
42
43 /**
44 * The root file of the plugin.
45 *
46 * @var string
47 */
48 private $plugin_file;
49
50 /**
51 * The root directory of the plugin.
52 *
53 * @var string
54 */
55 private $directory_path;
56
57 /**
58 * The root directory of the plugin as a URL.
59 *
60 * @var string
61 */
62 private $directory_url;
63
64 /**
65 * Store of registered objects.
66 *
67 * @var array
68 */
69 private $registry;
70
71 /**
72 * Create class instance.
73 *
74 * @since 1.0.0
75 *
76 * @param string $plugin_file The core plugin file.
77 */
78 public function __construct() {
79 // $this->plugin_file = $plugin_file;
80 // $this->directory_path = plugin_dir_path( $plugin_file );
81 // $this->directory_url = plugin_dir_url( $plugin_file );
82
83 add_action( 'charitable_start', array( $this, 'start' ), 5 );
84 // echo 'made it2'; exit;
85 }
86
87 /**
88 * Returns the original instance of this class.
89 *
90 * @since 1.0.0
91 *
92 * @return Charitable_User_Avatar
93 */
94 public static function get_instance() {
95 return self::$instance;
96 }
97
98 /**
99 * Run the startup sequence on the charitable_start hook.
100 *
101 * This is only ever executed once.
102 *
103 * @since 1.0.0
104 *
105 * @return void
106 */
107 public function start() {
108 // If we've already started (i.e. run this function once before), do not pass go.
109 if ( $this->started() ) {
110 return;
111 }
112
113 // Set static instance.
114 self::$instance = $this;
115
116 // $this->load_dependencies();
117
118 $this->attach_hooks_and_filters();
119
120 // $this->maybe_start_ambassadors();
121
122 // $this->setup_licensing();
123
124 // $this->setup_i18n();
125
126 // Hook in here to do something when the plugin is first loaded.
127 do_action( 'charitable_user_avatar_start', $this );
128 }
129
130 /**
131 * Include necessary files.
132 *
133 * @return void
134 * @since 1.0.0
135 */
136 private function load_dependencies() {
137 require_once( $this->get_path( 'includes' ) . 'charitable-user-avatar-functions.php' );
138 require_once( $this->get_path( 'includes' ) . 'class-charitable-user-avatar-profile-form.php' );
139 }
140
141 /**
142 * Set up hook and filter callback functions.
143 *
144 * @return void
145 * @since 1.0.0
146 */
147 private function attach_hooks_and_filters() {
148 // add_action( 'charitable_user_avatar_start', array( 'Charitable_User_Avatar_Profile_Form', 'start' ) );
149 echo 'bingoffffffffffff'; exit;
150 add_filter( 'charitable_user_avatar', array( $this, 'get_user_avatar' ), 10, 3 );
151 add_filter( 'charitable_user_avatar_src', array( $this, 'get_user_avatar_src' ), 10, 3 );
152 }
153
154 /**
155 * Load up the Ambassadors integration if Ambassadors is installed.
156 *
157 * @return void
158 * @since 1.0.2
159 */
160 private function maybe_start_ambassadors() {
161 if ( ! class_exists( 'Charitable_Ambassadors' ) ) {
162 return;
163 }
164
165 require_once( $this->get_path( 'includes' ) . 'ambassadors/class-charitable-user-avatar-campaign-form.php' );
166
167 add_action( 'charitable_user_avatar_start', array( 'Charitable_User_Avatar_Campaign_Form', 'start' ) );
168 }
169
170 /**
171 * Set up licensing for the extension.
172 *
173 * @return void
174 * @since 1.0.0
175 */
176 private function setup_licensing() {
177 charitable_get_helper( 'licenses' )->register_licensed_product(
178 Charitable_User_Avatar::NAME,
179 Charitable_User_Avatar::AUTHOR,
180 Charitable_User_Avatar::VERSION,
181 $this->plugin_file
182 );
183 }
184
185 /**
186 * Set up the internationalisation for the plugin.
187 *
188 * @return void
189 * @since 1.1.0
190 */
191 private function setup_i18n() {
192 if ( class_exists( 'Charitable_i18n' ) ) {
193
194 require_once( $this->get_path( 'includes' ) . 'i18n/class-charitable-user-avatar-i18n.php' );
195
196 Charitable_User_Avatar_i18n::get_instance();
197 }
198 }
199
200 /**
201 * Returns whether we are currently in the start phase of the plugin.
202 *
203 * @return bool
204 * @since 1.0.0
205 */
206 public function is_start() {
207 return current_filter() == 'charitable_user_avatar_start';
208 }
209
210 /**
211 * Returns whether the plugin has already started.
212 *
213 * @return bool
214 * @since 1.0.0
215 */
216 public function started() {
217 return did_action( 'charitable_user_avatar_start' ) || current_filter() == 'charitable_user_avatar_start';
218 }
219
220 /**
221 * Returns the plugin's version number.
222 *
223 * @return string
224 * @since 1.0.0
225 */
226 public function get_version() {
227 return self::VERSION;
228 }
229
230 /**
231 * Returns plugin paths.
232 *
233 * @param string $path // If empty, returns the path to the plugin.
234 * @param bool $absolute_path // If true, returns the file system path. If false, returns it as a URL.
235 * @return string
236 * @since 1.0.0
237 */
238 public function get_path($type = '', $absolute_path = true ) {
239 $base = $absolute_path ? $this->directory_path : $this->directory_url;
240
241 switch( $type ) {
242 case 'includes' :
243 $path = $base . 'includes/';
244 break;
245
246 case 'admin' :
247 $path = $base . 'includes/admin/';
248 break;
249
250 case 'templates' :
251 $path = $base . 'templates/';
252 break;
253
254 case 'assets' :
255 $path = $base . 'assets/';
256 break;
257
258 case 'directory' :
259 $path = $base;
260 break;
261
262 default :
263 $path = $this->plugin_file;
264 }
265
266 return $path;
267 }
268
269 /**
270 * Stores an object in the plugin's registry.
271 *
272 * @since 1.0.0
273 *
274 * @param mixed $object
275 * @return void
276 */
277 public function register_object( $object ) {
278 if ( ! is_object( $object ) ) {
279 return;
280 }
281
282 $class = get_class( $object );
283
284 $this->registry[ $class ] = $object;
285 }
286
287 /**
288 * Returns a registered object.
289 *
290 * @param string $class The type of class you want to retrieve.
291 * @return mixed The object if its registered. Otherwise false.
292 * @since 1.0.0
293 */
294 public function get_object( $class ) {
295 return isset( $this->registry[ $class ] ) ? $this->registry[ $class ] : false;
296 }
297
298 /**
299 * Return the user's avatar, or false if the user has not uploaded their own avatar.
300 *
301 * @since 1.0.0
302 *
303 * @param string|false $avatar The default avatar to use if one hasn't been set.
304 * @param Charitable_User $user The Charitable_User object.
305 * @return string
306 */
307 public function get_user_avatar( $avatar, Charitable_User $user ) {
308
309 $custom_avatar = get_user_meta( $user->ID, 'avatar', true );
310
311 if ( empty( $custom_avatar ) ) {
312 return $avatar;
313 }
314
315 if ( is_null( get_post( $custom_avatar ) ) ) {
316 return $avatar;
317 }
318
319 return $custom_avatar;
320 }
321
322 /**
323 * Return the src of the user's avatar, or false if they have not uploaded their own.
324 *
325 * @param string|false $avatar_src
326 * @param Charitable_User $user
327 * @param string $size
328 * @return string|false
329 * @since 1.0.0
330 */
331 public function get_user_avatar_src( $avatar_src, Charitable_User $user, $size = '' ) {
332 $avatar_attachment_id = $this->get_user_avatar( $avatar_src, $user );
333
334 if ( $avatar_attachment_id ) {
335 $attachment_src = wp_get_attachment_image_src( $avatar_attachment_id, $size );
336
337 if ( $attachment_src ) {
338 $avatar_src = $attachment_src[ 0 ];
339 }
340 }
341
342 return $avatar_src;
343 }
344
345 /**
346 * Throw error on object clone.
347 *
348 * This class is specifically designed to be instantiated once. You can retrieve the instance using charitable()
349 *
350 * @since 1.0.0
351 * @return void
352 */
353 public function __clone() {
354 charitable_get_deprecated()->doing_it_wrong(
355 __FUNCTION__,
356 __( 'Cheatin&#8217; huh?', 'charitable-user-avatar' ),
357 '1.0.0'
358 );
359 }
360
361 /**
362 * Disable unserializing of the class.
363 *
364 * @since 1.0.0
365 * @return void
366 */
367 public function __wakeup() {
368 charitable_get_deprecated()->doing_it_wrong(
369 __FUNCTION__,
370 __( 'Cheatin&#8217; huh?', 'charitable-user-avatar' ),
371 '1.0.0'
372 );
373 }
374 }
375
376 endif;
377