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 -90 2.31.12.17.0 View file →
@@ -3,103 +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 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.',
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.',
44 41
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 - );
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 + }
62 61
63 - return $multiFormGoal->getOutput();
64 - }
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 ) {
65 71
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 - }
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 + }
85 79
86 - return shortcode_atts($pairs, $attributes, $this->tag);
87 - }
80 + return shortcode_atts( $pairs, $attributes, $this->tag );
81 + }
88 82
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 - }
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 + }
105 95 }