PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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 1.7.0.9 All 211 releases
charitable / includes / admin / onboarding / class-charitable-onboarding.php

class-charitable-onboarding.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/admin/onboarding/class-charitable-onboarding.php

225 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Onboarding.
4 *
5 * @package Charitable/Classes/Charitable_Onboarding
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.8.1.12
10 * @version 1.8.1.12
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Onboarding' ) ) :
19
20 /**
21 * Charitable_Onboarding
22 *
23 * @final
24 * @since 1.8.1.12
25 */
26 class Charitable_Onboarding {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Onboarding|null
32 */
33 private static $instance = null;
34
35
36 /**
37 * The installed plugins.
38 *
39 * @var array
40 */
41 private $checklist_option_name = 'charitable_setup_checklist_completed_steps';
42
43
44 /**
45 * Create object instance.
46 *
47 * @since 1.8.1.12
48 */
49 public function __construct() {
50 }
51
52 /**
53 * Run things upon init.
54 *
55 * @since 1.8.1.12
56 *
57 * @return void
58 */
59 public function init() {
60 }
61
62 /**
63 * Enqueue assets.
64 *
65 * @since 1.8.1.12
66 */
67 public function enqueue_scripts() {
68
69 $min = charitable_get_min_suffix();
70 $version = charitable()->get_version();
71 $assets_dir = charitable()->get_path( 'assets', false );
72
73 /* The following styles are only loaded on Charitable screens. */
74 $screen = get_current_screen();
75
76 if ( ( ! empty( $_GET['page'] ) && 'charitable-setup-checklist' === $_GET['page'] ) ) { // phpcs:ignore
77
78 wp_enqueue_style(
79 'charitable-setup-checklist',
80 $assets_dir . 'css/setup-checklist/setup-checklist' . $min . '.css',
81 array(),
82 $version
83 );
84
85 }
86 }
87
88 /**
89 * Check if a step is completed.
90 *
91 * This is how we tell when a step is completed on the checklist.
92 *
93 * "plugin-config" - if the user has saved general settings at least once.
94 * "opt-in" - if the user has opted in to the newsletter/sharing data.
95 * "connect-payment" - if any payment gateway is connected.
96 * "first-campaign" - if a campaign has been created.
97 * "fundraising-next-level" - when pro is active or ???
98 *
99 * @since 1.8.1.12
100 *
101 * @param string $step The step to check.
102 *
103 * @return bool
104 */
105 public function is_step_completed( $step = '' ) {
106
107 if ( empty( $step ) ) {
108 return false;
109 }
110
111 // we store this as an option, so load the option and check the array key.
112 $completed_steps = get_option( $this->checklist_option_name, array() );
113 if ( in_array( $step, $completed_steps ) ) {
114 return true;
115 }
116
117 // if the step is not in the array, sometimes we can "double" check depending on the step.
118 switch ( $step ) {
119 case 'first-campaign':
120 // if there is at least one campaign, this is completed.
121 $campaigns_count = Charitable_Campaigns::query(
122 array(
123 'posts_per_page' => -1,
124 'fields' => 'ids',
125 )
126 )->found_posts;
127 if ( $campaigns_count > 0 ) {
128 return true;
129 }
130 break;
131
132 default:
133 // code...
134 break;
135 }
136
137 return false;
138 }
139
140 /**
141 * Check if the first campaign step is completed.
142 *
143 * @since 1.8.1.12
144 *
145 * @return bool
146 */
147 public function check_step_first_campaign() {
148 if ( $this->is_step_completed( 'first-campaign' ) ) {
149 return true;
150 }
151
152 // if there is at least one campaign, this is completed.
153 $campaigns = charitable_get_table( 'campaign' )->count();
154 if ( $campaigns > 0 ) {
155 $this->mark_step_completed( 'first-campaign' );
156 return true;
157 }
158
159 return false;
160 }
161
162 /**
163 * Check if the first donation step is completed.
164 *
165 * @since 1.8.2
166 *
167 * @return bool
168 */
169 public function check_step_first_donation() {
170 if ( $this->is_step_completed( 'first-donation' ) ) {
171 return true;
172 }
173 if ( ! isset( $_GET['post_type'] ) || 'donation' !== $_GET['post_type'] ) { // phpcs:ignore
174 return false;
175 }
176
177 $this->mark_step_completed( 'first-campaign' );
178
179 return true;
180 }
181
182 /**
183 * Mark a step as completed.
184 *
185 * @since 1.8.1.12
186 *
187 * @param string $step The step to mark as completed.
188 *
189 * @return bool
190 */
191 public function mark_step_completed( $step = '' ) {
192 if ( empty( $step ) ) {
193 return false;
194 }
195
196 // we store this as an option, so load the option and check the array key.
197 $completed_steps = get_option( $this->checklist_option_name, array() );
198 if ( ! in_array( $step, $completed_steps ) ) {
199 $completed_steps[] = $step;
200 update_option( $this->checklist_option_name, $completed_steps );
201 }
202
203 return true;
204 }
205
206
207
208 /**
209 * Returns and/or create the single instance of this class.
210 *
211 * @since 1.8.1.12
212 *
213 * @return Charitable_Onboarding
214 */
215 public static function get_instance() {
216 if ( is_null( self::$instance ) ) {
217 self::$instance = new self();
218 }
219
220 return self::$instance;
221 }
222 }
223
224 endif;
225