PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.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 2.31.0 2.31.1 All 253 releases
give / src / ThirdPartySupport / Elementor / Traits / HasCampaignOptions.php
HasCampaignOptions.php
66 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\ThirdPartySupport\Elementor\Traits;
4
5 use Exception;
6 use Give\Campaigns\Repositories\CampaignRepository;
7 use Give\Log\Log;
8 use Give\Campaigns\ValueObjects\CampaignPageMetaKeys;
9
10 /**
11 * Trait to get campaign options for Elementor widgets
12 *
13 * @since 4.7.0
14 */
15 trait HasCampaignOptions
16 {
17 /**
18 * Get the default campaign option
19 *
20 * @since 4.7.0
21 */
22 public function getDefaultCampaignOption(array $options): string
23 {
24 $default = !empty($options) ? array_key_first($options) : '';
25
26
27 $campaignId = get_post_meta(get_the_ID(), CampaignPageMetaKeys::CAMPAIGN_ID, true);
28
29 if (!$campaignId) {
30 return $default;
31 }
32
33 return array_key_exists($campaignId, $options) ? $campaignId : $default;
34 }
35 /**
36 * Get campaign options for select dropdown
37 *
38 * @since 4.7.0
39 */
40 public function getCampaignOptions(): array
41 {
42 try {
43 $campaignRepository = give(CampaignRepository::class);
44 $campaigns = $campaignRepository->prepareQuery()
45 ->where('status', 'active')
46 ->orderBy('campaign_title', 'ASC')
47 ->getAll();
48
49 if (empty($campaigns)) {
50 return [];
51 }
52
53 $options = [];
54 foreach ($campaigns as $campaign) {
55 $options[$campaign->id] = $campaign->title;
56 }
57
58 return $options;
59 } catch (Exception $e) {
60 Log::error('Elementor Campaign Options Error: ' . $e->getMessage());
61
62 return [];
63 }
64 }
65 }
66