PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
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 / MultiFormGoals / MultiFormGoal / Shortcode.php

Shortcode.php in GiveWP – Donation Plugin and Fundraising Platform 2.19.6, at src/MultiFormGoals/MultiFormGoal/Shortcode.php

106 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\MultiFormGoals\MultiFormGoal;
4
5 use Give\MultiFormGoals\MultiFormGoal\Model as MultiFormGoal;
6
7 class Shortcode
8 {
9
10 /**
11 * @since 2.9.6 Extracted from harded-coded value in `addShortcode()`.
12 * @var string Shortcode tag to be searched in post content.
13 * */
14 protected $tag = 'give_multi_form_goal';
15
16 /**
17 * Registers Multi-Form Goal Shortcode
18 *
19 * @since 2.9.0
20 **/
21 public function addShortcode()
22 {
23 add_shortcode($this->tag, [$this, 'renderCallback']);
24 }
25
26 /**
27 * Returns Shortcode markup
28 *
29 * @since 2.9.0
30 **/
31 public function renderCallback($attributes)
32 {
33 $attributes = $this->parseAttributes(
34 [
35 'ids' => [],
36 'tags' => [],
37 'categories' => [],
38 'goal' => '1000',
39 'enddate' => '',
40 'color' => '#28c77b',
41 'heading' => 'Example Heading',
42 'image' => GIVE_PLUGIN_URL . 'assets/dist/images/onboarding-preview-form-image.min.jpg',
43 'summary' => 'This is a summary.',
44
45 ],
46 $attributes,
47 'give_multi_form_goal'
48 );
49 $multiFormGoal = new MultiFormGoal(
50 [
51 'ids' => $attributes['ids'],
52 'tags' => $attributes['tags'],
53 'categories' => $attributes['categories'],
54 'goal' => $attributes['goal'],
55 'enddate' => $attributes['enddate'],
56 'color' => $attributes['color'],
57 'heading' => $attributes['heading'],
58 'imageSrc' => $attributes['image'],
59 'summary' => $attributes['summary'],
60 ]
61 );
62
63 return $multiFormGoal->getOutput();
64 }
65
66 /**
67 * Parse multiple attributes with defualt values and types (infered from the default values).
68 * @link https://developer.wordpress.org/reference/functions/shortcode_atts/
69 * @since 2.9.6
70 *
71 * @param array $pairs Entire list of supported attributes and their defaults.
72 * @param array $attributes User defined attributes.
73 *
74 * @reutrn array
75 */
76 protected function parseAttributes($pairs, $attributes)
77 {
78 if ($attributes) {
79 foreach ($attributes as $key => &$attribute) {
80 if (isset($pairs[$key]) && is_array($pairs[$key])) {
81 $attribute = $this->parseAttributeArray($attribute);
82 }
83 }
84 }
85
86 return shortcode_atts($pairs, $attributes, $this->tag);
87 }
88
89 /**
90 * Parses an individual attributes as an array (or from a comma-separated string).
91 * @since 2.9.6
92 *
93 * @param string|array $value
94 *
95 * @return array
96 */
97 protected function parseAttributeArray($value)
98 {
99 if ( ! is_array($value) && ! empty($value)) {
100 $value = explode(',', $value);
101 }
102
103 return $value;
104 }
105 }
106