PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / DonorDashboards / Admin / Settings.php
give / src / DonorDashboards / Admin Last commit date
Settings.php 4 years ago SuccessNotice.php 4 years ago UpgradeNotice.php 4 years ago
Settings.php
327 lines
1 <?php
2
3 namespace Give\DonorDashboards\Admin;
4
5 /**
6 * @since 2.10.0
7 */
8 class Settings
9 {
10
11 /**
12 * Register settings related to Donor Profiles
13 *
14 * @since 2.10.0
15 *
16 * @param array $settings
17 *
18 * @return array
19 *
20 */
21 public function register($settings)
22 {
23 $donorDashboardSettings = [
24 $this->getDonorDashboardPageSetting(),
25 $this->donorDashboardPageIsPublished() ? $this->getOverrideLegacyDonationManagementPagesSetting() : null,
26 ];
27
28 return give_settings_array_insert(
29 $settings,
30 'history_page',
31 $donorDashboardSettings
32 );
33 }
34
35 /**
36 * Return true if donor profile page is defined and published, false if not
37 *
38 * @since 2.10.0
39 * @return boolean
40 *
41 */
42 protected function donorDashboardPageIsPublished()
43 {
44 $donorDashboardPageId = ! empty(give_get_option('donor_dashboard_page')) ? give_get_option(
45 'donor_dashboard_page'
46 ) : null;
47
48 return $donorDashboardPageId && get_post_status($donorDashboardPageId) === 'publish';
49 }
50
51 /**
52 * Return CMB2 compatible array used to render/control donor profile page setting
53 *
54 * @since 2.10.0
55 * @return array
56 *
57 */
58 protected function getDonorDashboardPageSetting()
59 {
60 $generateDonorDashboardPageUrl = add_query_arg(
61 [
62 'give-generate-donor-dashboard-page' => '1',
63 ],
64 admin_url('edit.php')
65 );
66
67 $generateDonorDashboardPageDesc = $this->donorDashboardPageIsPublished() ? '' : sprintf(
68 __(' Need helping setting one up? <a href="%s">Generate a new Donor Dashboard page.</a>', 'give'),
69 $generateDonorDashboardPageUrl
70 );
71
72 return [
73 'name' => __('Donor Dashboard Page', 'give'),
74 'desc' => __(
75 'This is the page where donors can manage their information, review history and more -- all in one place. The Donor Dashboard block or <code>[give_donor_dashboard]</code> shortcode should be on this page. ',
76 'give'
77 ) . $generateDonorDashboardPageDesc,
78 'id' => 'donor_dashboard_page',
79 'type' => 'select',
80 'class' => 'give-select give-select-chosen',
81 'options' => give_cmb2_get_post_options(
82 [
83 'post_type' => 'page',
84 'numberposts' => 30,
85 ]
86 ),
87 'attributes' => [
88 'data-search-type' => 'pages',
89 'data-placeholder' => esc_html__('Choose a page', 'give'),
90 ],
91 ];
92 }
93
94 /**
95 * Return CMB2 compatible array used to render/control override legacy donation management pages setting
96 *
97 * @since 2.10.0
98 * @return array
99 *
100 */
101 protected function getOverrideLegacyDonationManagementPagesSetting()
102 {
103 return [
104 'name' => esc_html__('Override Legacy Donation Management Pages', 'give'),
105 'desc' => esc_html__(
106 'Use the Donor Dashboard instead of the legacy donation management pages (Donation History, Edit Profile, Subscriptions, etc).',
107 'give'
108 ),
109 'id' => 'override_legacy_donation_management_pages',
110 'wrapper_class' => 'override-legacy-donation-management-pages',
111 'type' => 'radio_inline',
112 'default' => 'enabled',
113 'options' => [
114 'enabled' => esc_html__('Enabled', 'give'),
115 'disabled' => esc_html__('Disabled', 'give'),
116 ],
117 ];
118 }
119
120 /**
121 * Generate donor profile page, and update site setting to use it
122 *
123 * @since 2.10.0
124 * @return void
125 *
126 */
127 public function generateDonorDashboardPage()
128 {
129 // Check if a Donor Dashboard page has already been created
130
131 if ( ! empty(give_get_option('donor_dashboard_page'))) {
132 return;
133 }
134
135 $content = $this->getDonorDashboardPageContent();
136
137 $pageId = wp_insert_post(
138 [
139 'comment_status' => 'close',
140 'ping_status' => 'close',
141 'post_author' => 1,
142 'post_title' => __('Donor Dashboard', 'give'),
143 'post_status' => 'publish',
144 'post_content' => $content,
145 'post_type' => 'page',
146 ]
147 );
148
149 if ($pageId) {
150 give_update_option('donor_dashboard_page', $pageId);
151
152 give_update_option('override_legacy_donation_management_pages', 'enabled');
153
154 $overrideSettingsMap = [
155 'history_page',
156 'subscriptions_page',
157 ];
158
159 foreach ($overrideSettingsMap as $setting) {
160 if (give_get_option($setting) !== $pageId) {
161 give_update_option($setting, $pageId);
162 }
163 }
164 }
165 }
166
167 /**
168 * Get default content for donor profile page, based on format (block vs shortcode)
169 *
170 * @since 2.10.0
171 *
172 * @param string $format
173 *
174 * @return string
175 *
176 */
177 protected function getDonorDashboardPageContent()
178 {
179 if ($this->shouldGenerateWithBlock()) {
180 return get_comment_delimited_block_content(
181 'give/donor-dashboard',
182 [
183 'align' => 'wide',
184 ],
185 null
186 );
187 } else {
188 return '[give_donor_dashboard]';
189 }
190 }
191
192 /**
193 * Determine whether the Donor Dashboard page should be generated with a block
194 *
195 * @since 2.10.0
196 * @return bool
197 *
198 */
199 private function shouldGenerateWithBlock()
200 {
201 $usingBlocks = $this->isBlockEditorActive() || $this->isGutenbergEditorActive() ? true : false;
202 $usingClassicEditor = $this->isClassicEditorActive();
203 $usingDisableGutenberg = $this->isDisableGutenbergActive();
204
205 if ($usingClassicEditor === false && $usingDisableGutenberg === false && $usingBlocks) {
206 return true;
207 }
208
209 return false;
210 }
211
212 /**
213 * Determine whether the Gutenberg editor is active
214 *
215 * @since 2.10.0
216 * @return bool
217 *
218 */
219 private function isGutenbergEditorActive()
220 {
221 if (has_filter('replace_editor', 'gutenberg_init')) {
222 // Gutenberg is installed and activated.
223 return true;
224 }
225
226 return false;
227 }
228
229 /**
230 * Determine whether block editor is active
231 *
232 * @since 2.10.0
233 * @return bool
234 *
235 */
236 private function isBlockEditorActive()
237 {
238 if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) {
239 // Block editor.
240 return true;
241 }
242
243 return false;
244 }
245
246 /**
247 * Determine whether the Classic editor is active
248 *
249 * @since 2.10.0
250 * @return bool
251 *
252 */
253 private function isClassicEditorActive()
254 {
255 include_once ABSPATH . 'wp-admin/includes/plugin.php';
256
257 if (is_plugin_active('classic-editor/classic-editor.php') && (get_option(
258 'classic-editor-replace'
259 ) !== 'no-replace')) {
260 return true;
261 }
262
263 return false;
264 }
265
266 /**
267 * Determine whether Disable Gutenberg plugin is active
268 *
269 * @since 2.10.0
270 * @return bool
271 *
272 */
273 private function isDisableGutenbergActive()
274 {
275 include_once ABSPATH . 'wp-admin/includes/plugin.php';
276
277 if (is_plugin_active('disable-gutenberg/disable-gutenberg.php')) {
278 return true;
279 }
280
281 return false;
282 }
283
284 /**
285 * Filter and override legacy donation management page settings
286 *
287 * @since 2.10.0
288 *
289 * @param array $settings
290 *
291 * @return array
292 *
293 */
294 public function overrideLegacyDonationManagementPageSettings($settings)
295 {
296 // Only override settings if the override legacy donation management pages setting is enabled
297 if ($this->donorDashboardPageIsPublished() && give_is_setting_enabled(
298 give_get_option('override_legacy_donation_management_pages', 'enabled')
299 )) {
300 $pageId = give_get_option('donor_dashboard_page');
301
302 $overrideSettingsMap = [
303 'history_page',
304 'subscriptions_page',
305 ];
306
307 foreach ($overrideSettingsMap as $setting) {
308 if (give_get_option($setting) !== $pageId) {
309 give_update_option($setting, $pageId);
310 }
311 }
312
313 // Hide settings that are overridden by Donor Profile setting
314 $key = 0;
315 foreach ($settings as $setting) {
316 if (in_array($setting['id'], $overrideSettingsMap)) {
317 unset($settings[$key]);
318 }
319 $key++;
320 }
321 }
322
323 return $settings;
324 }
325
326 }
327