PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.10.0
GiveWP – Donation Plugin and Fundraising Platform v2.10.0
4.16.4 4.16.3 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
299 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 $content = $this->getDonorDashboardPageContent();
113
114 $pageId = wp_insert_post(
115 [
116 'comment_status' => 'close',
117 'ping_status' => 'close',
118 'post_author' => 1,
119 'post_title' => __( 'Donor Dashboard', 'give' ),
120 'post_status' => 'publish',
121 'post_content' => $content,
122 'post_type' => 'page',
123 ]
124 );
125
126 if ( $pageId ) {
127
128 give_update_option( 'donor_dashboard_page', $pageId );
129
130 give_update_option( 'override_legacy_donation_management_pages', 'enabled' );
131
132 $overrideSettingsMap = [
133 'history_page',
134 'subscriptions_page',
135 ];
136
137 foreach ( $overrideSettingsMap as $setting ) {
138 if ( give_get_option( $setting ) !== $pageId ) {
139 give_update_option( $setting, $pageId );
140 }
141 }
142 }
143
144 }
145
146 /**
147 * Get default content for donor profile page, based on format (block vs shortcode)
148 *
149 * @param string $format
150 * @return string
151 *
152 * @since 2.10.0
153 */
154 protected function getDonorDashboardPageContent() {
155
156 if ( $this->shouldGenerateWithBlock() ) {
157 return get_comment_delimited_block_content(
158 'give/donor-dashboard',
159 [
160 'align' => 'wide',
161 ],
162 null
163 );
164 } else {
165 return '[give_donor_dashboard]';
166 }
167
168 }
169
170 /**
171 * Determine whether the Donor Dashboard page should be generated with a block
172 *
173 * @return bool
174 *
175 * @since 2.10.0
176 */
177 private function shouldGenerateWithBlock() {
178
179 $usingBlocks = $this->isBlockEditorActive() || $this->isGutenbergEditorActive() ? true : false;
180 $usingClassicEditor = $this->isClassicEditorActive();
181 $usingDisableGutenberg = $this->isDisableGutenbergActive();
182
183 if ( $usingClassicEditor === false && $usingDisableGutenberg === false && $usingBlocks ) {
184 return true;
185 }
186
187 return false;
188
189 }
190
191 /**
192 * Determine whether the Gutenberg editor is active
193 *
194 * @return bool
195 *
196 * @since 2.10.0
197 */
198 private function isGutenbergEditorActive() {
199 if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) {
200 // Gutenberg is installed and activated.
201 return true;
202 }
203 return false;
204 }
205
206 /**
207 * Determine whether block editor is active
208 *
209 * @return bool
210 *
211 * @since 2.10.0
212 */
213 private function isBlockEditorActive() {
214 if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) {
215 // Block editor.
216 return true;
217 }
218 return false;
219 }
220
221 /**
222 * Determine whether the Classic editor is active
223 *
224 * @return bool
225 *
226 * @since 2.10.0
227 */
228 private function isClassicEditorActive() {
229
230 include_once ABSPATH . 'wp-admin/includes/plugin.php';
231
232 if ( is_plugin_active( 'classic-editor/classic-editor.php' ) && ( get_option( 'classic-editor-replace' ) !== 'no-replace' ) ) {
233 return true;
234 }
235
236 return false;
237
238 }
239
240 /**
241 * Determine whether the Disable Gutenberg plugin is active
242 *
243 * @return bool
244 *
245 * @since 2.10.0
246 */
247 private function isDisableGutenbergActive() {
248
249 include_once ABSPATH . 'wp-admin/includes/plugin.php';
250
251 if ( is_plugin_active( 'disable-gutenberg/disable-gutenberg.php' ) ) {
252 return true;
253 }
254
255 return false;
256
257 }
258
259 /**
260 * Filter and override legacy donation management page settings
261 *
262 * @param array $settings
263 * @return array
264 *
265 * @since 2.10.0
266 */
267 public function overrideLegacyDonationManagementPageSettings( $settings ) {
268
269 // Only override settings if the the override legacy donation management pages setting is enabled
270 if ( $this->donorDashboardPageIsPublished() && give_is_setting_enabled( give_get_option( 'override_legacy_donation_management_pages', 'enabled' ) ) ) {
271
272 $pageId = give_get_option( 'donor_dashboard_page' );
273
274 $overrideSettingsMap = [
275 'history_page',
276 'subscriptions_page',
277 ];
278
279 foreach ( $overrideSettingsMap as $setting ) {
280 if ( give_get_option( $setting ) !== $pageId ) {
281 give_update_option( $setting, $pageId );
282 }
283 }
284
285 // Hide settings that are overriden by Donor Profile setting
286 $key = 0;
287 foreach ( $settings as $setting ) {
288 if ( in_array( $setting['id'], $overrideSettingsMap ) ) {
289 unset( $settings[ $key ] );
290 }
291 $key++;
292 }
293 }
294
295 return $settings;
296 }
297
298 }
299