PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.10.4
GiveWP – Donation Plugin and Fundraising Platform v2.10.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 5 years ago SuccessNotice.php 5 years ago UpgradeNotice.php 5 years ago
Settings.php
305 lines
1 <?php
2
3 namespace Give\DonorDashboards\Admin;
4
5 /**
6 * @since 2.10.0
7 */
8 class Settings {
9
10 /**
11 * Register settings related to Donor Profiles
12 *
13 * @param array $settings
14 * @return array
15 *
16 * @since 2.10.0
17 */
18 public function register( $settings ) {
19
20 $donorDashboardSettings = [
21 $this->getDonorDashboardPageSetting(),
22 $this->donorDashboardPageIsPublished() ? $this->getOverrideLegacyDonationManagementPagesSetting() : null,
23 ];
24
25 return give_settings_array_insert(
26 $settings,
27 'history_page',
28 $donorDashboardSettings
29 );
30 }
31
32 /**
33 * Return true if donor profile page is defined and published, false if not
34 *
35 * @return boolean
36 *
37 * @since 2.10.0
38 */
39 protected function donorDashboardPageIsPublished() {
40 $donorDashboardPageId = ! empty( give_get_option( 'donor_dashboard_page' ) ) ? give_get_option( 'donor_dashboard_page' ) : null;
41 return $donorDashboardPageId && get_post_status( $donorDashboardPageId ) === 'publish';
42 }
43
44 /**
45 * Return CMB2 compatible array used to render/control donor profile page setting
46 *
47 * @return array
48 *
49 * @since 2.10.0
50 */
51 protected function getDonorDashboardPageSetting() {
52
53 $generateDonorDashboardPageUrl = add_query_arg(
54 [
55 'give-generate-donor-dashboard-page' => '1',
56 ],
57 admin_url( 'edit.php' )
58 );
59
60 $generateDonorDashboardPageDesc = $this->donorDashboardPageIsPublished() ? '' : sprintf( __( ' Need helping setting one up? <a href="%s">Generate a new Donor Dashboard page.</a>', 'give' ), $generateDonorDashboardPageUrl );
61
62 return [
63 'name' => __( 'Donor Dashboard Page', 'give' ),
64 'desc' => __( '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. ', 'give' ) . $generateDonorDashboardPageDesc,
65 'id' => 'donor_dashboard_page',
66 'type' => 'select',
67 'class' => 'give-select give-select-chosen',
68 'options' => give_cmb2_get_post_options(
69 [
70 'post_type' => 'page',
71 'numberposts' => 30,
72 ]
73 ),
74 'attributes' => [
75 'data-search-type' => 'pages',
76 'data-placeholder' => esc_html__( 'Choose a page', 'give' ),
77 ],
78 ];
79 }
80
81 /**
82 * Return CMB2 compatible array used to render/control override legacy donation manamgent pages setting
83 *
84 * @return array
85 *
86 * @since 2.10.0
87 */
88 protected function getOverrideLegacyDonationManagementPagesSetting() {
89 return [
90 'name' => esc_html__( 'Override Legacy Donation Management Pages', 'give' ),
91 'desc' => esc_html__( 'Use the Donor Dashboard instead of the legacy donation management pages (Donation History, Edit Profile, Subscriptions, etc).', 'give' ),
92 'id' => 'override_legacy_donation_management_pages',
93 'wrapper_class' => 'override-legacy-donation-management-pages',
94 'type' => 'radio_inline',
95 'default' => 'enabled',
96 'options' => [
97 'enabled' => esc_html__( 'Enabled', 'give' ),
98 'disabled' => esc_html__( 'Disabled', 'give' ),
99 ],
100 ];
101 }
102
103 /**
104 * Generate donor profile page, and update site setting to use it
105 *
106 * @return void
107 *
108 * @since 2.10.0
109 */
110 public function generateDonorDashboardPage() {
111
112 // Check if a Donor Dashboard page has already been created
113
114 if ( ! empty( give_get_option( 'donor_dashboard_page' ) ) ) {
115 return;
116 }
117
118 $content = $this->getDonorDashboardPageContent();
119
120 $pageId = wp_insert_post(
121 [
122 'comment_status' => 'close',
123 'ping_status' => 'close',
124 'post_author' => 1,
125 'post_title' => __( 'Donor Dashboard', 'give' ),
126 'post_status' => 'publish',
127 'post_content' => $content,
128 'post_type' => 'page',
129 ]
130 );
131
132 if ( $pageId ) {
133
134 give_update_option( 'donor_dashboard_page', $pageId );
135
136 give_update_option( 'override_legacy_donation_management_pages', 'enabled' );
137
138 $overrideSettingsMap = [
139 'history_page',
140 'subscriptions_page',
141 ];
142
143 foreach ( $overrideSettingsMap as $setting ) {
144 if ( give_get_option( $setting ) !== $pageId ) {
145 give_update_option( $setting, $pageId );
146 }
147 }
148 }
149
150 }
151
152 /**
153 * Get default content for donor profile page, based on format (block vs shortcode)
154 *
155 * @param string $format
156 * @return string
157 *
158 * @since 2.10.0
159 */
160 protected function getDonorDashboardPageContent() {
161
162 if ( $this->shouldGenerateWithBlock() ) {
163 return get_comment_delimited_block_content(
164 'give/donor-dashboard',
165 [
166 'align' => 'wide',
167 ],
168 null
169 );
170 } else {
171 return '[give_donor_dashboard]';
172 }
173
174 }
175
176 /**
177 * Determine whether the Donor Dashboard page should be generated with a block
178 *
179 * @return bool
180 *
181 * @since 2.10.0
182 */
183 private function shouldGenerateWithBlock() {
184
185 $usingBlocks = $this->isBlockEditorActive() || $this->isGutenbergEditorActive() ? true : false;
186 $usingClassicEditor = $this->isClassicEditorActive();
187 $usingDisableGutenberg = $this->isDisableGutenbergActive();
188
189 if ( $usingClassicEditor === false && $usingDisableGutenberg === false && $usingBlocks ) {
190 return true;
191 }
192
193 return false;
194
195 }
196
197 /**
198 * Determine whether the Gutenberg editor is active
199 *
200 * @return bool
201 *
202 * @since 2.10.0
203 */
204 private function isGutenbergEditorActive() {
205 if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) {
206 // Gutenberg is installed and activated.
207 return true;
208 }
209 return false;
210 }
211
212 /**
213 * Determine whether block editor is active
214 *
215 * @return bool
216 *
217 * @since 2.10.0
218 */
219 private function isBlockEditorActive() {
220 if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) {
221 // Block editor.
222 return true;
223 }
224 return false;
225 }
226
227 /**
228 * Determine whether the Classic editor is active
229 *
230 * @return bool
231 *
232 * @since 2.10.0
233 */
234 private function isClassicEditorActive() {
235
236 include_once ABSPATH . 'wp-admin/includes/plugin.php';
237
238 if ( is_plugin_active( 'classic-editor/classic-editor.php' ) && ( get_option( 'classic-editor-replace' ) !== 'no-replace' ) ) {
239 return true;
240 }
241
242 return false;
243
244 }
245
246 /**
247 * Determine whether the Disable Gutenberg plugin is active
248 *
249 * @return bool
250 *
251 * @since 2.10.0
252 */
253 private function isDisableGutenbergActive() {
254
255 include_once ABSPATH . 'wp-admin/includes/plugin.php';
256
257 if ( is_plugin_active( 'disable-gutenberg/disable-gutenberg.php' ) ) {
258 return true;
259 }
260
261 return false;
262
263 }
264
265 /**
266 * Filter and override legacy donation management page settings
267 *
268 * @param array $settings
269 * @return array
270 *
271 * @since 2.10.0
272 */
273 public function overrideLegacyDonationManagementPageSettings( $settings ) {
274
275 // Only override settings if the the override legacy donation management pages setting is enabled
276 if ( $this->donorDashboardPageIsPublished() && give_is_setting_enabled( give_get_option( 'override_legacy_donation_management_pages', 'enabled' ) ) ) {
277
278 $pageId = give_get_option( 'donor_dashboard_page' );
279
280 $overrideSettingsMap = [
281 'history_page',
282 'subscriptions_page',
283 ];
284
285 foreach ( $overrideSettingsMap as $setting ) {
286 if ( give_get_option( $setting ) !== $pageId ) {
287 give_update_option( $setting, $pageId );
288 }
289 }
290
291 // Hide settings that are overriden by Donor Profile setting
292 $key = 0;
293 foreach ( $settings as $setting ) {
294 if ( in_array( $setting['id'], $overrideSettingsMap ) ) {
295 unset( $settings[ $key ] );
296 }
297 $key++;
298 }
299 }
300
301 return $settings;
302 }
303
304 }
305