PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
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
← All changes | src/MultiFormGoals/MultiFormGoal/Shortcode.php +80 -102 4.16.02.17.0 View file →
@@ -3,115 +3,93 @@
3 3 namespace Give\MultiFormGoals\MultiFormGoal;
4 4
5 5 use Give\MultiFormGoals\MultiFormGoal\Model as MultiFormGoal;
6 6
7 -class Shortcode
8 -{
7 +class Shortcode {
9 8
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';
9 + /**
10 + * @since 2.9.6 Extracted from harded-coded value in `addShortcode()`.
11 + * @var string Shortcode tag to be searched in post content.
12 + * */
13 + protected $tag = 'give_multi_form_goal';
15 14
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 - }
15 + /**
16 + * Registers Multi-Form Goal Shortcode
17 + *
18 + * @since 2.9.0
19 + **/
20 + public function addShortcode() {
21 + add_shortcode( $this->tag, [ $this, 'renderCallback' ] );
22 + }
25 23
26 - /**
27 - * Returns Shortcode markup
28 - *
29 - * @since 3.7.0 Sanitize attributes
30 - * @since 3.0.3 Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
31 - * @since 2.9.0
32 - **/
33 - public function renderCallback($attributes)
34 - {
35 - $attributes = give_clean($attributes);
24 + /**
25 + * Returns Shortcode markup
26 + *
27 + * @since 2.9.0
28 + **/
29 + public function renderCallback( $attributes ) {
30 + $attributes = $this->parseAttributes(
31 + [
32 + 'ids' => [],
33 + 'tags' => [],
34 + 'categories' => [],
35 + 'goal' => '1000',
36 + 'enddate' => '',
37 + 'color' => '#28c77b',
38 + 'heading' => 'Example Heading',
39 + 'image' => GIVE_PLUGIN_URL . 'assets/dist/images/onboarding-preview-form-image.min.jpg',
40 + 'summary' => 'This is a summary.',
36 41
37 - $attributes = $this->parseAttributes(
38 - [
39 - 'ids' => [],
40 - 'tags' => [],
41 - 'categories' => [],
42 - 'goal' => '1000',
43 - 'enddate' => '',
44 - 'color' => '#28c77b',
45 - 'heading' => 'Example Heading',
46 - 'image' => GIVE_PLUGIN_URL . 'build/assets/dist/images/onboarding-preview-form-image.min.jpg',
47 - 'summary' => 'This is a summary.',
42 + ],
43 + $attributes,
44 + 'give_multi_form_goal'
45 + );
46 + $multiFormGoal = new MultiFormGoal(
47 + [
48 + 'ids' => $attributes['ids'],
49 + 'tags' => $attributes['tags'],
50 + 'categories' => $attributes['categories'],
51 + 'goal' => $attributes['goal'],
52 + 'enddate' => $attributes['enddate'],
53 + 'color' => $attributes['color'],
54 + 'heading' => $attributes['heading'],
55 + 'imageSrc' => $attributes['image'],
56 + 'summary' => $attributes['summary'],
57 + ]
58 + );
59 + return $multiFormGoal->getOutput();
60 + }
48 61
49 - ],
50 - $attributes,
51 - 'give_multi_form_goal'
52 - );
62 + /**
63 + * Parse multiple attributes with defualt values and types (infered from the default values).
64 + * @link https://developer.wordpress.org/reference/functions/shortcode_atts/
65 + * @since 2.9.6
66 + * @param array $pairs Entire list of supported attributes and their defaults.
67 + * @param array $attributes User defined attributes.
68 + * @reutrn array
69 + */
70 + protected function parseAttributes( $pairs, $attributes ) {
53 71
54 - $multiFormGoal = new MultiFormGoal(
55 - [
56 - 'ids' => array_map(
57 - static function ($id) {
58 - _give_redirect_form_id($id);
72 + if ( $attributes ) {
73 + foreach ( $attributes as $key => &$attribute ) {
74 + if ( isset( $pairs[ $key ] ) && is_array( $pairs[ $key ] ) ) {
75 + $attribute = $this->parseAttributeArray( $attribute );
76 + }
77 + }
78 + }
59 79
60 - return $id;
61 - },
62 - $attributes['ids']
63 - ),
64 - 'tags' => $attributes['tags'],
65 - 'categories' => $attributes['categories'],
66 - 'goal' => $attributes['goal'],
67 - 'enddate' => $attributes['enddate'],
68 - 'color' => $attributes['color'],
69 - 'heading' => $attributes['heading'],
70 - 'imageSrc' => $attributes['image'],
71 - 'summary' => $attributes['summary'],
72 - ]
73 - );
80 + return shortcode_atts( $pairs, $attributes, $this->tag );
81 + }
74 82
75 - return $multiFormGoal->getOutput();
76 - }
77 -
78 - /**
79 - * Parse multiple attributes with defualt values and types (infered from the default values).
80 - * @link https://developer.wordpress.org/reference/functions/shortcode_atts/
81 - * @since 2.9.6
82 - *
83 - * @param array $pairs Entire list of supported attributes and their defaults.
84 - * @param array $attributes User defined attributes.
85 - *
86 - * @reutrn array
87 - */
88 - protected function parseAttributes($pairs, $attributes)
89 - {
90 - if ($attributes) {
91 - foreach ($attributes as $key => &$attribute) {
92 - if (isset($pairs[$key]) && is_array($pairs[$key])) {
93 - $attribute = $this->parseAttributeArray($attribute);
94 - }
95 - }
96 - }
97 -
98 - return shortcode_atts($pairs, $attributes, $this->tag);
99 - }
100 -
101 - /**
102 - * Parses an individual attributes as an array (or from a comma-separated string).
103 - * @since 2.9.6
104 - *
105 - * @param string|array $value
106 - *
107 - * @return array
108 - */
109 - protected function parseAttributeArray($value)
110 - {
111 - if ( ! is_array($value) && ! empty($value)) {
112 - $value = explode(',', $value);
113 - }
114 -
115 - return $value;
116 - }
83 + /**
84 + * Parses an individual attributes as an array (or from a comma-separated string).
85 + * @since 2.9.6
86 + * @param string|array $value
87 + * @return array
88 + */
89 + protected function parseAttributeArray( $value ) {
90 + if ( ! is_array( $value ) && ! empty( $value ) ) {
91 + $value = explode( ',', $value );
92 + }
93 + return $value;
94 + }
117 95 }