PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 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 All 255 releases
give / src / Campaigns / Actions / PreventDeleteDefaultForm.php

PreventDeleteDefaultForm.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Campaigns/Actions/PreventDeleteDefaultForm.php

54 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Campaigns\Actions;
4
5 use Give\Campaigns\Models\Campaign;
6
7 /**
8 * @since 4.1.0
9 */
10 class PreventDeleteDefaultForm
11 {
12 /**
13 * @since 4.1.0
14 */
15 public function __invoke($postId)
16 {
17 if (get_post_type($postId) !== 'give_forms') {
18 return;
19 }
20
21 $campaign = Campaign::findByFormId($postId);
22
23 if ($campaign && $campaign->defaultFormId == $postId) {
24 wp_die(sprintf(__('The form %s with ID %d cannot be deleted because it is the default form for a campaign.',
25 'give'),
26 $campaign->defaultForm()->title,
27 $postId));
28 }
29 }
30
31 /**
32 * @since 4.1.0
33 */
34 public function preventTrashStatusChange($newStatus, $oldStatus, $post)
35 {
36 if ($newStatus === 'trash' && get_post_type($post->ID) === 'give_forms') {
37 $campaign = Campaign::findByFormId($post->ID);
38
39
40 if ($campaign && $campaign->defaultFormId == $post->ID) {
41 wp_update_post([
42 'ID' => $post->ID,
43 'post_status' => $oldStatus,
44 ]);
45
46 wp_die(sprintf(__('The form %s with ID %d cannot be moved to trash because it is the default form for a campaign.',
47 'give'),
48 $campaign->defaultForm()->title,
49 $post->ID));
50 }
51 }
52 }
53 }
54