@@ -6,115 +6,115 @@ |
||
6 | 6 | |
7 | 7 | class SiteReviewsFormBlock extends BlockGenerator |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function attributes() |
|
13 | - { |
|
14 | - return [ |
|
15 | - 'assign_to' => [ |
|
16 | - 'default' => '', |
|
17 | - 'type' => 'string', |
|
18 | - ], |
|
19 | - 'category' => [ |
|
20 | - 'default' => '', |
|
21 | - 'type' => 'string', |
|
22 | - ], |
|
23 | - 'className' => [ |
|
24 | - 'default' => '', |
|
25 | - 'type' => 'string', |
|
26 | - ], |
|
27 | - 'hide' => [ |
|
28 | - 'default' => '', |
|
29 | - 'type' => 'string', |
|
30 | - ], |
|
31 | - 'id' => [ |
|
32 | - 'default' => '', |
|
33 | - 'type' => 'string', |
|
34 | - ], |
|
35 | - ]; |
|
36 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function attributes() |
|
13 | + { |
|
14 | + return [ |
|
15 | + 'assign_to' => [ |
|
16 | + 'default' => '', |
|
17 | + 'type' => 'string', |
|
18 | + ], |
|
19 | + 'category' => [ |
|
20 | + 'default' => '', |
|
21 | + 'type' => 'string', |
|
22 | + ], |
|
23 | + 'className' => [ |
|
24 | + 'default' => '', |
|
25 | + 'type' => 'string', |
|
26 | + ], |
|
27 | + 'hide' => [ |
|
28 | + 'default' => '', |
|
29 | + 'type' => 'string', |
|
30 | + ], |
|
31 | + 'id' => [ |
|
32 | + 'default' => '', |
|
33 | + 'type' => 'string', |
|
34 | + ], |
|
35 | + ]; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function render(array $attributes) |
|
42 | - { |
|
43 | - $attributes['class'] = $attributes['className']; |
|
44 | - $shortcode = glsr(Shortcode::class); |
|
45 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
46 | - $this->filterFormFields(); |
|
47 | - $this->filterRatingField(); |
|
48 | - $this->filterShortcodeClass(); |
|
49 | - $this->filterSubmitButton(); |
|
50 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
51 | - $this->filterInterpolation(); |
|
52 | - } |
|
53 | - } |
|
54 | - return $shortcode->buildShortcode($attributes); |
|
55 | - } |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function render(array $attributes) |
|
42 | + { |
|
43 | + $attributes['class'] = $attributes['className']; |
|
44 | + $shortcode = glsr(Shortcode::class); |
|
45 | + if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
46 | + $this->filterFormFields(); |
|
47 | + $this->filterRatingField(); |
|
48 | + $this->filterShortcodeClass(); |
|
49 | + $this->filterSubmitButton(); |
|
50 | + if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
51 | + $this->filterInterpolation(); |
|
52 | + } |
|
53 | + } |
|
54 | + return $shortcode->buildShortcode($attributes); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - protected function filterFormFields() |
|
61 | - { |
|
62 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
63 | - array_walk($config, function (&$field) { |
|
64 | - $field['disabled'] = true; |
|
65 | - $field['tabindex'] = '-1'; |
|
66 | - }); |
|
67 | - return $config; |
|
68 | - }); |
|
69 | - } |
|
57 | + /** |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + protected function filterFormFields() |
|
61 | + { |
|
62 | + add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
63 | + array_walk($config, function (&$field) { |
|
64 | + $field['disabled'] = true; |
|
65 | + $field['tabindex'] = '-1'; |
|
66 | + }); |
|
67 | + return $config; |
|
68 | + }); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - protected function filterInterpolation() |
|
75 | - { |
|
76 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
77 | - $context['class'] = 'glsr-default glsr-block-disabled'; |
|
78 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
79 | - $context['response'] = ''; |
|
80 | - $context['submit_button'] = ''; |
|
81 | - return $context; |
|
82 | - }); |
|
83 | - } |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + protected function filterInterpolation() |
|
75 | + { |
|
76 | + add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
77 | + $context['class'] = 'glsr-default glsr-block-disabled'; |
|
78 | + $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
79 | + $context['response'] = ''; |
|
80 | + $context['submit_button'] = ''; |
|
81 | + return $context; |
|
82 | + }); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - protected function filterRatingField() |
|
89 | - { |
|
90 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
91 | - if ('rating' == $args['path']) { |
|
92 | - $stars = '<span class="glsr-stars">'; |
|
93 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5); |
|
94 | - $stars.= '</span>'; |
|
95 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
96 | - } |
|
97 | - return $html; |
|
98 | - }, 10, 3); |
|
99 | - } |
|
85 | + /** |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + protected function filterRatingField() |
|
89 | + { |
|
90 | + add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
91 | + if ('rating' == $args['path']) { |
|
92 | + $stars = '<span class="glsr-stars">'; |
|
93 | + $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5); |
|
94 | + $stars.= '</span>'; |
|
95 | + $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
96 | + } |
|
97 | + return $html; |
|
98 | + }, 10, 3); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - protected function filterShortcodeClass() |
|
105 | - { |
|
106 | - add_filter('site-reviews/style', function () { |
|
107 | - return 'default'; |
|
108 | - }); |
|
109 | - } |
|
101 | + /** |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + protected function filterShortcodeClass() |
|
105 | + { |
|
106 | + add_filter('site-reviews/style', function () { |
|
107 | + return 'default'; |
|
108 | + }); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - protected function filterSubmitButton() |
|
115 | - { |
|
116 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
117 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
118 | - }); |
|
119 | - } |
|
111 | + /** |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + protected function filterSubmitButton() |
|
115 | + { |
|
116 | + add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
117 | + return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
118 | + }); |
|
119 | + } |
|
120 | 120 | } |
@@ -38,20 +38,20 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - public function render(array $attributes) |
|
41 | + public function render( array $attributes ) |
|
42 | 42 | { |
43 | 43 | $attributes['class'] = $attributes['className']; |
44 | - $shortcode = glsr(Shortcode::class); |
|
45 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
44 | + $shortcode = glsr( Shortcode::class ); |
|
45 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
46 | 46 | $this->filterFormFields(); |
47 | 47 | $this->filterRatingField(); |
48 | 48 | $this->filterShortcodeClass(); |
49 | 49 | $this->filterSubmitButton(); |
50 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
50 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
51 | 51 | $this->filterInterpolation(); |
52 | 52 | } |
53 | 53 | } |
54 | - return $shortcode->buildShortcode($attributes); |
|
54 | + return $shortcode->buildShortcode( $attributes ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function filterFormFields() |
61 | 61 | { |
62 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
63 | - array_walk($config, function (&$field) { |
|
62 | + add_filter( 'site-reviews/config/forms/submission-form', function( array $config ) { |
|
63 | + array_walk( $config, function( &$field ) { |
|
64 | 64 | $field['disabled'] = true; |
65 | 65 | $field['tabindex'] = '-1'; |
66 | 66 | }); |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function filterInterpolation() |
75 | 75 | { |
76 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
76 | + add_filter( 'site-reviews/interpolate/reviews-form', function( $context ) { |
|
77 | 77 | $context['class'] = 'glsr-default glsr-block-disabled'; |
78 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
78 | + $context['fields'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
79 | 79 | $context['response'] = ''; |
80 | 80 | $context['submit_button'] = ''; |
81 | 81 | return $context; |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function filterRatingField() |
89 | 89 | { |
90 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
91 | - if ('rating' == $args['path']) { |
|
90 | + add_filter( 'site-reviews/rendered/field', function( $html, $type, $args ) { |
|
91 | + if( 'rating' == $args['path'] ) { |
|
92 | 92 | $stars = '<span class="glsr-stars">'; |
93 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5); |
|
94 | - $stars.= '</span>'; |
|
95 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
93 | + $stars .= str_repeat( '<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', 5 ); |
|
94 | + $stars .= '</span>'; |
|
95 | + $html = preg_replace( '/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html ); |
|
96 | 96 | } |
97 | 97 | return $html; |
98 | - }, 10, 3); |
|
98 | + }, 10, 3 ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function filterShortcodeClass() |
105 | 105 | { |
106 | - add_filter('site-reviews/style', function () { |
|
106 | + add_filter( 'site-reviews/style', function() { |
|
107 | 107 | return 'default'; |
108 | 108 | }); |
109 | 109 | } |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function filterSubmitButton() |
115 | 115 | { |
116 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
117 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
116 | + add_filter( 'site-reviews/rendered/template/form/submit-button', function( $template ) { |
|
117 | + return str_replace( 'type="submit"', 'tabindex="-1"', $template ); |
|
118 | 118 | }); |
119 | 119 | } |
120 | 120 | } |
@@ -6,65 +6,65 @@ |
||
6 | 6 | |
7 | 7 | abstract class BlockGenerator |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function attributes() |
|
13 | - { |
|
14 | - return []; |
|
15 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function attributes() |
|
13 | + { |
|
14 | + return []; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public function normalize(array $attributes) |
|
21 | - { |
|
22 | - $hide = array_flip(explode(',', $attributes['hide'])); |
|
23 | - unset($hide['if_empty']); |
|
24 | - $attributes['hide'] = implode(',', array_keys($hide)); |
|
25 | - if (!isset($attributes['assigned_to'])) { |
|
26 | - return $attributes; |
|
27 | - } |
|
28 | - if ('post_id' == $attributes['assigned_to']) { |
|
29 | - $attributes['assigned_to'] = $attributes['post_id']; |
|
30 | - } elseif ('parent_id' == $attributes['assigned_to']) { |
|
31 | - $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
|
32 | - } |
|
33 | - return $attributes; |
|
34 | - } |
|
17 | + /** |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public function normalize(array $attributes) |
|
21 | + { |
|
22 | + $hide = array_flip(explode(',', $attributes['hide'])); |
|
23 | + unset($hide['if_empty']); |
|
24 | + $attributes['hide'] = implode(',', array_keys($hide)); |
|
25 | + if (!isset($attributes['assigned_to'])) { |
|
26 | + return $attributes; |
|
27 | + } |
|
28 | + if ('post_id' == $attributes['assigned_to']) { |
|
29 | + $attributes['assigned_to'] = $attributes['post_id']; |
|
30 | + } elseif ('parent_id' == $attributes['assigned_to']) { |
|
31 | + $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
|
32 | + } |
|
33 | + return $attributes; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function register($block) |
|
40 | - { |
|
41 | - if (!function_exists('register_block_type')) { |
|
42 | - return; |
|
43 | - } |
|
44 | - register_block_type(Application::ID.'/'.$block, [ |
|
45 | - 'attributes' => $this->attributes(), |
|
46 | - 'editor_script' => Application::ID.'/blocks', |
|
47 | - 'editor_style' => Application::ID.'/blocks', |
|
48 | - 'render_callback' => [$this, 'render'], |
|
49 | - 'style' => Application::ID, |
|
50 | - ]); |
|
51 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function register($block) |
|
40 | + { |
|
41 | + if (!function_exists('register_block_type')) { |
|
42 | + return; |
|
43 | + } |
|
44 | + register_block_type(Application::ID.'/'.$block, [ |
|
45 | + 'attributes' => $this->attributes(), |
|
46 | + 'editor_script' => Application::ID.'/blocks', |
|
47 | + 'editor_style' => Application::ID.'/blocks', |
|
48 | + 'render_callback' => [$this, 'render'], |
|
49 | + 'style' => Application::ID, |
|
50 | + ]); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - abstract public function render(array $attributes); |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + abstract public function render(array $attributes); |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param mixed $shortcode |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - protected function hasVisibleFields($shortcode, array $attributes) |
|
63 | - { |
|
64 | - $args = $shortcode->normalizeAtts($attributes); |
|
65 | - $defaults = $shortcode->getHideOptions(); |
|
66 | - $hide = array_flip($args['hide']); |
|
67 | - unset($defaults['if_empty'], $hide['if_empty']); |
|
68 | - return !empty(array_diff_key($defaults, $hide)); |
|
69 | - } |
|
58 | + /** |
|
59 | + * @param mixed $shortcode |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + protected function hasVisibleFields($shortcode, array $attributes) |
|
63 | + { |
|
64 | + $args = $shortcode->normalizeAtts($attributes); |
|
65 | + $defaults = $shortcode->getHideOptions(); |
|
66 | + $hide = array_flip($args['hide']); |
|
67 | + unset($defaults['if_empty'], $hide['if_empty']); |
|
68 | + return !empty(array_diff_key($defaults, $hide)); |
|
69 | + } |
|
70 | 70 | } |
@@ -17,18 +17,18 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return array |
19 | 19 | */ |
20 | - public function normalize(array $attributes) |
|
20 | + public function normalize( array $attributes ) |
|
21 | 21 | { |
22 | - $hide = array_flip(explode(',', $attributes['hide'])); |
|
22 | + $hide = array_flip( explode( ',', $attributes['hide'] ) ); |
|
23 | 23 | unset($hide['if_empty']); |
24 | - $attributes['hide'] = implode(',', array_keys($hide)); |
|
25 | - if (!isset($attributes['assigned_to'])) { |
|
24 | + $attributes['hide'] = implode( ',', array_keys( $hide ) ); |
|
25 | + if( !isset($attributes['assigned_to']) ) { |
|
26 | 26 | return $attributes; |
27 | 27 | } |
28 | - if ('post_id' == $attributes['assigned_to']) { |
|
28 | + if( 'post_id' == $attributes['assigned_to'] ) { |
|
29 | 29 | $attributes['assigned_to'] = $attributes['post_id']; |
30 | - } elseif ('parent_id' == $attributes['assigned_to']) { |
|
31 | - $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
|
30 | + } elseif( 'parent_id' == $attributes['assigned_to'] ) { |
|
31 | + $attributes['assigned_to'] = wp_get_post_parent_id( $attributes['post_id'] ); |
|
32 | 32 | } |
33 | 33 | return $attributes; |
34 | 34 | } |
@@ -36,35 +36,35 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function register($block) |
|
39 | + public function register( $block ) |
|
40 | 40 | { |
41 | - if (!function_exists('register_block_type')) { |
|
41 | + if( !function_exists( 'register_block_type' ) ) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | - register_block_type(Application::ID.'/'.$block, [ |
|
44 | + register_block_type( Application::ID.'/'.$block, [ |
|
45 | 45 | 'attributes' => $this->attributes(), |
46 | 46 | 'editor_script' => Application::ID.'/blocks', |
47 | 47 | 'editor_style' => Application::ID.'/blocks', |
48 | 48 | 'render_callback' => [$this, 'render'], |
49 | 49 | 'style' => Application::ID, |
50 | - ]); |
|
50 | + ] ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - abstract public function render(array $attributes); |
|
56 | + abstract public function render( array $attributes ); |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @param mixed $shortcode |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - protected function hasVisibleFields($shortcode, array $attributes) |
|
62 | + protected function hasVisibleFields( $shortcode, array $attributes ) |
|
63 | 63 | { |
64 | - $args = $shortcode->normalizeAtts($attributes); |
|
64 | + $args = $shortcode->normalizeAtts( $attributes ); |
|
65 | 65 | $defaults = $shortcode->getHideOptions(); |
66 | - $hide = array_flip($args['hide']); |
|
66 | + $hide = array_flip( $args['hide'] ); |
|
67 | 67 | unset($defaults['if_empty'], $hide['if_empty']); |
68 | - return !empty(array_diff_key($defaults, $hide)); |
|
68 | + return !empty(array_diff_key( $defaults, $hide )); |
|
69 | 69 | } |
70 | 70 | } |
@@ -27,7 +27,8 @@ |
||
27 | 27 | } |
28 | 28 | if ('post_id' == $attributes['assigned_to']) { |
29 | 29 | $attributes['assigned_to'] = $attributes['post_id']; |
30 | - } elseif ('parent_id' == $attributes['assigned_to']) { |
|
30 | + } |
|
31 | + elseif ('parent_id' == $attributes['assigned_to']) { |
|
31 | 32 | $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']); |
32 | 33 | } |
33 | 34 | return $attributes; |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - public function render(array $attributes) |
|
65 | + public function render( array $attributes ) |
|
66 | 66 | { |
67 | 67 | $attributes['class'] = $attributes['className']; |
68 | - $shortcode = glsr(Shortcode::class); |
|
69 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
70 | - $attributes = $this->normalize($attributes); |
|
68 | + $shortcode = glsr( Shortcode::class ); |
|
69 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
70 | + $attributes = $this->normalize( $attributes ); |
|
71 | 71 | $this->filterReviewLinks(); |
72 | 72 | $this->filterShortcodeClass(); |
73 | - $this->filterShowMoreLinks('content'); |
|
74 | - $this->filterShowMoreLinks('response'); |
|
75 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
73 | + $this->filterShowMoreLinks( 'content' ); |
|
74 | + $this->filterShowMoreLinks( 'response' ); |
|
75 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
76 | 76 | $this->filterInterpolation(); |
77 | 77 | } |
78 | 78 | } |
79 | - return $shortcode->buildShortcode($attributes); |
|
79 | + return $shortcode->buildShortcode( $attributes ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function filterInterpolation() |
86 | 86 | { |
87 | - add_filter('site-reviews/interpolate/reviews', function ($context) { |
|
87 | + add_filter( 'site-reviews/interpolate/reviews', function( $context ) { |
|
88 | 88 | $context['class'] = 'glsr-default glsr-block-disabled'; |
89 | - $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
89 | + $context['reviews'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
90 | 90 | return $context; |
91 | 91 | }); |
92 | 92 | } |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | */ |
97 | 97 | protected function filterReviewLinks() |
98 | 98 | { |
99 | - add_filter('site-reviews/rendered/template/reviews', function ($template) { |
|
100 | - return str_replace('<a', '<a tabindex="-1"', $template); |
|
99 | + add_filter( 'site-reviews/rendered/template/reviews', function( $template ) { |
|
100 | + return str_replace( '<a', '<a tabindex="-1"', $template ); |
|
101 | 101 | }); |
102 | 102 | } |
103 | 103 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function filterShortcodeClass() |
108 | 108 | { |
109 | - add_filter('site-reviews/style', function () { |
|
109 | + add_filter( 'site-reviews/style', function() { |
|
110 | 110 | return 'default'; |
111 | 111 | }); |
112 | 112 | } |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * @param string $field |
116 | 116 | * @return void |
117 | 117 | */ |
118 | - protected function filterShowMoreLinks($field) |
|
118 | + protected function filterShowMoreLinks( $field ) |
|
119 | 119 | { |
120 | - add_filter('site-reviews/review/wrap/'.$field, function ($value) { |
|
120 | + add_filter( 'site-reviews/review/wrap/'.$field, function( $value ) { |
|
121 | 121 | $value = preg_replace( |
122 | 122 | '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s', |
123 | - '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5', |
|
123 | + '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__( 'Show more', 'site-reviews' ).'</a>$5', |
|
124 | 124 | $value |
125 | 125 | ); |
126 | 126 | return $value; |
@@ -6,124 +6,124 @@ |
||
6 | 6 | |
7 | 7 | class SiteReviewsBlock extends BlockGenerator |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function attributes() |
|
13 | - { |
|
14 | - return [ |
|
15 | - 'assigned_to' => [ |
|
16 | - 'default' => '', |
|
17 | - 'type' => 'string', |
|
18 | - ], |
|
19 | - 'category' => [ |
|
20 | - 'default' => '', |
|
21 | - 'type' => 'string', |
|
22 | - ], |
|
23 | - 'className' => [ |
|
24 | - 'default' => '', |
|
25 | - 'type' => 'string', |
|
26 | - ], |
|
27 | - 'display' => [ |
|
28 | - 'default' => 5, |
|
29 | - 'type' => 'number', |
|
30 | - ], |
|
31 | - 'hide' => [ |
|
32 | - 'default' => '', |
|
33 | - 'type' => 'string', |
|
34 | - ], |
|
35 | - 'id' => [ |
|
36 | - 'default' => '', |
|
37 | - 'type' => 'string', |
|
38 | - ], |
|
39 | - 'pagination' => [ |
|
40 | - 'default' => '', |
|
41 | - 'type' => 'string', |
|
42 | - ], |
|
43 | - 'post_id' => [ |
|
44 | - 'default' => '', |
|
45 | - 'type' => 'string', |
|
46 | - ], |
|
47 | - 'rating' => [ |
|
48 | - 'default' => 0, |
|
49 | - 'type' => 'number', |
|
50 | - ], |
|
51 | - 'schema' => [ |
|
52 | - 'default' => false, |
|
53 | - 'type' => 'boolean', |
|
54 | - ], |
|
55 | - 'type' => [ |
|
56 | - 'default' => 'local', |
|
57 | - 'type' => 'string', |
|
58 | - ], |
|
59 | - ]; |
|
60 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function attributes() |
|
13 | + { |
|
14 | + return [ |
|
15 | + 'assigned_to' => [ |
|
16 | + 'default' => '', |
|
17 | + 'type' => 'string', |
|
18 | + ], |
|
19 | + 'category' => [ |
|
20 | + 'default' => '', |
|
21 | + 'type' => 'string', |
|
22 | + ], |
|
23 | + 'className' => [ |
|
24 | + 'default' => '', |
|
25 | + 'type' => 'string', |
|
26 | + ], |
|
27 | + 'display' => [ |
|
28 | + 'default' => 5, |
|
29 | + 'type' => 'number', |
|
30 | + ], |
|
31 | + 'hide' => [ |
|
32 | + 'default' => '', |
|
33 | + 'type' => 'string', |
|
34 | + ], |
|
35 | + 'id' => [ |
|
36 | + 'default' => '', |
|
37 | + 'type' => 'string', |
|
38 | + ], |
|
39 | + 'pagination' => [ |
|
40 | + 'default' => '', |
|
41 | + 'type' => 'string', |
|
42 | + ], |
|
43 | + 'post_id' => [ |
|
44 | + 'default' => '', |
|
45 | + 'type' => 'string', |
|
46 | + ], |
|
47 | + 'rating' => [ |
|
48 | + 'default' => 0, |
|
49 | + 'type' => 'number', |
|
50 | + ], |
|
51 | + 'schema' => [ |
|
52 | + 'default' => false, |
|
53 | + 'type' => 'boolean', |
|
54 | + ], |
|
55 | + 'type' => [ |
|
56 | + 'default' => 'local', |
|
57 | + 'type' => 'string', |
|
58 | + ], |
|
59 | + ]; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function render(array $attributes) |
|
66 | - { |
|
67 | - $attributes['class'] = $attributes['className']; |
|
68 | - $shortcode = glsr(Shortcode::class); |
|
69 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
70 | - $attributes = $this->normalize($attributes); |
|
71 | - $this->filterReviewLinks(); |
|
72 | - $this->filterShortcodeClass(); |
|
73 | - $this->filterShowMoreLinks('content'); |
|
74 | - $this->filterShowMoreLinks('response'); |
|
75 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
76 | - $this->filterInterpolation(); |
|
77 | - } |
|
78 | - } |
|
79 | - return $shortcode->buildShortcode($attributes); |
|
80 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function render(array $attributes) |
|
66 | + { |
|
67 | + $attributes['class'] = $attributes['className']; |
|
68 | + $shortcode = glsr(Shortcode::class); |
|
69 | + if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
70 | + $attributes = $this->normalize($attributes); |
|
71 | + $this->filterReviewLinks(); |
|
72 | + $this->filterShortcodeClass(); |
|
73 | + $this->filterShowMoreLinks('content'); |
|
74 | + $this->filterShowMoreLinks('response'); |
|
75 | + if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
76 | + $this->filterInterpolation(); |
|
77 | + } |
|
78 | + } |
|
79 | + return $shortcode->buildShortcode($attributes); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - protected function filterInterpolation() |
|
86 | - { |
|
87 | - add_filter('site-reviews/interpolate/reviews', function ($context) { |
|
88 | - $context['class'] = 'glsr-default glsr-block-disabled'; |
|
89 | - $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
90 | - return $context; |
|
91 | - }); |
|
92 | - } |
|
82 | + /** |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + protected function filterInterpolation() |
|
86 | + { |
|
87 | + add_filter('site-reviews/interpolate/reviews', function ($context) { |
|
88 | + $context['class'] = 'glsr-default glsr-block-disabled'; |
|
89 | + $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
90 | + return $context; |
|
91 | + }); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - protected function filterReviewLinks() |
|
98 | - { |
|
99 | - add_filter('site-reviews/rendered/template/reviews', function ($template) { |
|
100 | - return str_replace('<a', '<a tabindex="-1"', $template); |
|
101 | - }); |
|
102 | - } |
|
94 | + /** |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + protected function filterReviewLinks() |
|
98 | + { |
|
99 | + add_filter('site-reviews/rendered/template/reviews', function ($template) { |
|
100 | + return str_replace('<a', '<a tabindex="-1"', $template); |
|
101 | + }); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - protected function filterShortcodeClass() |
|
108 | - { |
|
109 | - add_filter('site-reviews/style', function () { |
|
110 | - return 'default'; |
|
111 | - }); |
|
112 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + protected function filterShortcodeClass() |
|
108 | + { |
|
109 | + add_filter('site-reviews/style', function () { |
|
110 | + return 'default'; |
|
111 | + }); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param string $field |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - protected function filterShowMoreLinks($field) |
|
119 | - { |
|
120 | - add_filter('site-reviews/review/wrap/'.$field, function ($value) { |
|
121 | - $value = preg_replace( |
|
122 | - '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s', |
|
123 | - '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5', |
|
124 | - $value |
|
125 | - ); |
|
126 | - return $value; |
|
127 | - }); |
|
128 | - } |
|
114 | + /** |
|
115 | + * @param string $field |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + protected function filterShowMoreLinks($field) |
|
119 | + { |
|
120 | + add_filter('site-reviews/review/wrap/'.$field, function ($value) { |
|
121 | + $value = preg_replace( |
|
122 | + '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s', |
|
123 | + '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5', |
|
124 | + $value |
|
125 | + ); |
|
126 | + return $value; |
|
127 | + }); |
|
128 | + } |
|
129 | 129 | } |
@@ -68,9 +68,11 @@ discard block |
||
68 | 68 | { |
69 | 69 | if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
70 | 70 | $this->storage[$property] = $value; |
71 | - } elseif (!isset($this->$property)) { |
|
71 | + } |
|
72 | + elseif (!isset($this->$property)) { |
|
72 | 73 | $this->$property = $value; |
73 | - } else { |
|
74 | + } |
|
75 | + else { |
|
74 | 76 | throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
75 | 77 | } |
76 | 78 | } |
@@ -165,7 +167,8 @@ discard block |
||
165 | 167 | { |
166 | 168 | try { |
167 | 169 | return $this->make($parameter->getClass()->name); |
168 | - } catch (Exception $error) { |
|
170 | + } |
|
171 | + catch (Exception $error) { |
|
169 | 172 | if ($parameter->isOptional()) { |
170 | 173 | return $parameter->getDefaultValue(); |
171 | 174 | } |
@@ -11,226 +11,226 @@ |
||
11 | 11 | |
12 | 12 | abstract class Container |
13 | 13 | { |
14 | - const PROTECTED_PROPERTIES = [ |
|
15 | - 'instance', |
|
16 | - 'services', |
|
17 | - 'session', |
|
18 | - 'storage', |
|
19 | - ]; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var static |
|
23 | - */ |
|
24 | - protected static $instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * The container's bound services. |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $services = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $session = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * The container's storage items. |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $storage = []; |
|
42 | - |
|
43 | - /** |
|
44 | - * @return static |
|
45 | - */ |
|
46 | - public static function load() |
|
47 | - { |
|
48 | - if (empty(static::$instance)) { |
|
49 | - static::$instance = new static(); |
|
50 | - } |
|
51 | - return static::$instance; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $property |
|
56 | - * @return mixed |
|
57 | - */ |
|
58 | - public function __get($property) |
|
59 | - { |
|
60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
61 | - return $this->$property; |
|
62 | - } |
|
63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | - if (defined($constant)) { |
|
65 | - return constant($constant); |
|
66 | - } |
|
67 | - return Arr::get($this->storage, $property, null); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param string $property |
|
72 | - * @param string $value |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function __set($property, $value) |
|
76 | - { |
|
77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
78 | - $this->storage[$property] = $value; |
|
79 | - } elseif (!isset($this->$property)) { |
|
80 | - $this->$property = $value; |
|
81 | - } else { |
|
82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Bind a service to the container. |
|
88 | - * @param string $alias |
|
89 | - * @param mixed $concrete |
|
90 | - * @return mixed |
|
91 | - */ |
|
92 | - public function bind($alias, $concrete) |
|
93 | - { |
|
94 | - $this->services[$alias] = $concrete; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Request a service from the container. |
|
99 | - * @param mixed $abstract |
|
100 | - * @return mixed |
|
101 | - */ |
|
102 | - public function make($abstract) |
|
103 | - { |
|
104 | - if (!isset($this->services[$abstract])) { |
|
105 | - $abstract = $this->addNamespace($abstract); |
|
106 | - } |
|
107 | - if (isset($this->services[$abstract])) { |
|
108 | - $abstract = $this->services[$abstract]; |
|
109 | - } |
|
110 | - if (is_callable($abstract)) { |
|
111 | - return call_user_func_array($abstract, [$this]); |
|
112 | - } |
|
113 | - if (is_object($abstract)) { |
|
114 | - return $abstract; |
|
115 | - } |
|
116 | - return $this->resolve($abstract); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function sessionClear() |
|
123 | - { |
|
124 | - $this->session = []; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return mixed |
|
129 | - */ |
|
130 | - public function sessionGet($key, $fallback = '') |
|
131 | - { |
|
132 | - $value = Arr::get($this->session, $key, $fallback); |
|
133 | - unset($this->session[$key]); |
|
134 | - return $value; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public function sessionSet($key, $value) |
|
141 | - { |
|
142 | - $this->session[$key] = $value; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Bind a singleton instance to the container. |
|
147 | - * @param string $alias |
|
148 | - * @param callable|string|null $binding |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public function singleton($alias, $binding) |
|
152 | - { |
|
153 | - $this->bind($alias, $this->make($binding)); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Prefix the current namespace to the abstract if absent. |
|
158 | - * @param string $abstract |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - protected function addNamespace($abstract) |
|
162 | - { |
|
163 | - if (false === strpos($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
164 | - $abstract = __NAMESPACE__.'\\'.$abstract; |
|
165 | - } |
|
166 | - return $abstract; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Resolve a service from the container. |
|
171 | - * @param mixed $concrete |
|
172 | - * @return mixed |
|
173 | - * @throws Exception |
|
174 | - */ |
|
175 | - protected function resolve($concrete) |
|
176 | - { |
|
177 | - if ($concrete instanceof Closure) { |
|
178 | - return $concrete($this); |
|
179 | - } |
|
180 | - $reflector = new ReflectionClass($concrete); |
|
181 | - if (!$reflector->isInstantiable()) { |
|
182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
183 | - } |
|
184 | - $constructor = $reflector->getConstructor(); |
|
185 | - if (empty($constructor)) { |
|
186 | - return new $concrete(); |
|
187 | - } |
|
188 | - return $reflector->newInstanceArgs( |
|
189 | - $this->resolveDependencies($constructor->getParameters()) |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Resolve a class based dependency from the container. |
|
195 | - * @return mixed |
|
196 | - * @throws Exception |
|
197 | - */ |
|
198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
199 | - { |
|
200 | - try { |
|
201 | - return $this->make($parameter->getClass()->name); |
|
202 | - } catch (Exception $error) { |
|
203 | - if ($parameter->isOptional()) { |
|
204 | - return $parameter->getDefaultValue(); |
|
205 | - } |
|
206 | - throw $error; |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Resolve all of the dependencies from the ReflectionParameters. |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - protected function resolveDependencies(array $dependencies) |
|
215 | - { |
|
216 | - $results = []; |
|
217 | - foreach ($dependencies as $dependency) { |
|
218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
219 | - ? $this->resolveClass($dependency) |
|
220 | - : $this->resolveDependency($dependency); |
|
221 | - } |
|
222 | - return $results; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Resolve a single ReflectionParameter dependency. |
|
227 | - * @return array|null |
|
228 | - */ |
|
229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
230 | - { |
|
231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
232 | - return $parameter->getDefaultValue(); |
|
233 | - } |
|
234 | - return null; |
|
235 | - } |
|
14 | + const PROTECTED_PROPERTIES = [ |
|
15 | + 'instance', |
|
16 | + 'services', |
|
17 | + 'session', |
|
18 | + 'storage', |
|
19 | + ]; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var static |
|
23 | + */ |
|
24 | + protected static $instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * The container's bound services. |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $services = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $session = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * The container's storage items. |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $storage = []; |
|
42 | + |
|
43 | + /** |
|
44 | + * @return static |
|
45 | + */ |
|
46 | + public static function load() |
|
47 | + { |
|
48 | + if (empty(static::$instance)) { |
|
49 | + static::$instance = new static(); |
|
50 | + } |
|
51 | + return static::$instance; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $property |
|
56 | + * @return mixed |
|
57 | + */ |
|
58 | + public function __get($property) |
|
59 | + { |
|
60 | + if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
61 | + return $this->$property; |
|
62 | + } |
|
63 | + $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | + if (defined($constant)) { |
|
65 | + return constant($constant); |
|
66 | + } |
|
67 | + return Arr::get($this->storage, $property, null); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param string $property |
|
72 | + * @param string $value |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function __set($property, $value) |
|
76 | + { |
|
77 | + if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
78 | + $this->storage[$property] = $value; |
|
79 | + } elseif (!isset($this->$property)) { |
|
80 | + $this->$property = $value; |
|
81 | + } else { |
|
82 | + throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Bind a service to the container. |
|
88 | + * @param string $alias |
|
89 | + * @param mixed $concrete |
|
90 | + * @return mixed |
|
91 | + */ |
|
92 | + public function bind($alias, $concrete) |
|
93 | + { |
|
94 | + $this->services[$alias] = $concrete; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Request a service from the container. |
|
99 | + * @param mixed $abstract |
|
100 | + * @return mixed |
|
101 | + */ |
|
102 | + public function make($abstract) |
|
103 | + { |
|
104 | + if (!isset($this->services[$abstract])) { |
|
105 | + $abstract = $this->addNamespace($abstract); |
|
106 | + } |
|
107 | + if (isset($this->services[$abstract])) { |
|
108 | + $abstract = $this->services[$abstract]; |
|
109 | + } |
|
110 | + if (is_callable($abstract)) { |
|
111 | + return call_user_func_array($abstract, [$this]); |
|
112 | + } |
|
113 | + if (is_object($abstract)) { |
|
114 | + return $abstract; |
|
115 | + } |
|
116 | + return $this->resolve($abstract); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function sessionClear() |
|
123 | + { |
|
124 | + $this->session = []; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return mixed |
|
129 | + */ |
|
130 | + public function sessionGet($key, $fallback = '') |
|
131 | + { |
|
132 | + $value = Arr::get($this->session, $key, $fallback); |
|
133 | + unset($this->session[$key]); |
|
134 | + return $value; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public function sessionSet($key, $value) |
|
141 | + { |
|
142 | + $this->session[$key] = $value; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Bind a singleton instance to the container. |
|
147 | + * @param string $alias |
|
148 | + * @param callable|string|null $binding |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public function singleton($alias, $binding) |
|
152 | + { |
|
153 | + $this->bind($alias, $this->make($binding)); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Prefix the current namespace to the abstract if absent. |
|
158 | + * @param string $abstract |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + protected function addNamespace($abstract) |
|
162 | + { |
|
163 | + if (false === strpos($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
164 | + $abstract = __NAMESPACE__.'\\'.$abstract; |
|
165 | + } |
|
166 | + return $abstract; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Resolve a service from the container. |
|
171 | + * @param mixed $concrete |
|
172 | + * @return mixed |
|
173 | + * @throws Exception |
|
174 | + */ |
|
175 | + protected function resolve($concrete) |
|
176 | + { |
|
177 | + if ($concrete instanceof Closure) { |
|
178 | + return $concrete($this); |
|
179 | + } |
|
180 | + $reflector = new ReflectionClass($concrete); |
|
181 | + if (!$reflector->isInstantiable()) { |
|
182 | + throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
183 | + } |
|
184 | + $constructor = $reflector->getConstructor(); |
|
185 | + if (empty($constructor)) { |
|
186 | + return new $concrete(); |
|
187 | + } |
|
188 | + return $reflector->newInstanceArgs( |
|
189 | + $this->resolveDependencies($constructor->getParameters()) |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Resolve a class based dependency from the container. |
|
195 | + * @return mixed |
|
196 | + * @throws Exception |
|
197 | + */ |
|
198 | + protected function resolveClass(ReflectionParameter $parameter) |
|
199 | + { |
|
200 | + try { |
|
201 | + return $this->make($parameter->getClass()->name); |
|
202 | + } catch (Exception $error) { |
|
203 | + if ($parameter->isOptional()) { |
|
204 | + return $parameter->getDefaultValue(); |
|
205 | + } |
|
206 | + throw $error; |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Resolve all of the dependencies from the ReflectionParameters. |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + protected function resolveDependencies(array $dependencies) |
|
215 | + { |
|
216 | + $results = []; |
|
217 | + foreach ($dependencies as $dependency) { |
|
218 | + $results[] = !is_null($class = $dependency->getClass()) |
|
219 | + ? $this->resolveClass($dependency) |
|
220 | + : $this->resolveDependency($dependency); |
|
221 | + } |
|
222 | + return $results; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Resolve a single ReflectionParameter dependency. |
|
227 | + * @return array|null |
|
228 | + */ |
|
229 | + protected function resolveDependency(ReflectionParameter $parameter) |
|
230 | + { |
|
231 | + if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
232 | + return $parameter->getDefaultValue(); |
|
233 | + } |
|
234 | + return null; |
|
235 | + } |
|
236 | 236 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public static function load() |
47 | 47 | { |
48 | - if (empty(static::$instance)) { |
|
48 | + if( empty(static::$instance) ) { |
|
49 | 49 | static::$instance = new static(); |
50 | 50 | } |
51 | 51 | return static::$instance; |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * @param string $property |
56 | 56 | * @return mixed |
57 | 57 | */ |
58 | - public function __get($property) |
|
58 | + public function __get( $property ) |
|
59 | 59 | { |
60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
60 | + if( property_exists( $this, $property ) && !in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
61 | 61 | return $this->$property; |
62 | 62 | } |
63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | - if (defined($constant)) { |
|
65 | - return constant($constant); |
|
63 | + $constant = 'static::'.strtoupper( Str::snakeCase( $property ) ); |
|
64 | + if( defined( $constant ) ) { |
|
65 | + return constant( $constant ); |
|
66 | 66 | } |
67 | - return Arr::get($this->storage, $property, null); |
|
67 | + return Arr::get( $this->storage, $property, null ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | * @param string $value |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public function __set($property, $value) |
|
75 | + public function __set( $property, $value ) |
|
76 | 76 | { |
77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
77 | + if( !property_exists( $this, $property ) || in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
78 | 78 | $this->storage[$property] = $value; |
79 | - } elseif (!isset($this->$property)) { |
|
79 | + } elseif( !isset($this->$property) ) { |
|
80 | 80 | $this->$property = $value; |
81 | 81 | } else { |
82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
82 | + throw new Exception( sprintf( 'The "%s" property cannot be changed once set.', $property ) ); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param mixed $concrete |
90 | 90 | * @return mixed |
91 | 91 | */ |
92 | - public function bind($alias, $concrete) |
|
92 | + public function bind( $alias, $concrete ) |
|
93 | 93 | { |
94 | 94 | $this->services[$alias] = $concrete; |
95 | 95 | } |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | * @param mixed $abstract |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - public function make($abstract) |
|
102 | + public function make( $abstract ) |
|
103 | 103 | { |
104 | - if (!isset($this->services[$abstract])) { |
|
105 | - $abstract = $this->addNamespace($abstract); |
|
104 | + if( !isset($this->services[$abstract]) ) { |
|
105 | + $abstract = $this->addNamespace( $abstract ); |
|
106 | 106 | } |
107 | - if (isset($this->services[$abstract])) { |
|
107 | + if( isset($this->services[$abstract]) ) { |
|
108 | 108 | $abstract = $this->services[$abstract]; |
109 | 109 | } |
110 | - if (is_callable($abstract)) { |
|
111 | - return call_user_func_array($abstract, [$this]); |
|
110 | + if( is_callable( $abstract ) ) { |
|
111 | + return call_user_func_array( $abstract, [$this] ); |
|
112 | 112 | } |
113 | - if (is_object($abstract)) { |
|
113 | + if( is_object( $abstract ) ) { |
|
114 | 114 | return $abstract; |
115 | 115 | } |
116 | - return $this->resolve($abstract); |
|
116 | + return $this->resolve( $abstract ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @return mixed |
129 | 129 | */ |
130 | - public function sessionGet($key, $fallback = '') |
|
130 | + public function sessionGet( $key, $fallback = '' ) |
|
131 | 131 | { |
132 | - $value = Arr::get($this->session, $key, $fallback); |
|
132 | + $value = Arr::get( $this->session, $key, $fallback ); |
|
133 | 133 | unset($this->session[$key]); |
134 | 134 | return $value; |
135 | 135 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @return void |
139 | 139 | */ |
140 | - public function sessionSet($key, $value) |
|
140 | + public function sessionSet( $key, $value ) |
|
141 | 141 | { |
142 | 142 | $this->session[$key] = $value; |
143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param callable|string|null $binding |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function singleton($alias, $binding) |
|
151 | + public function singleton( $alias, $binding ) |
|
152 | 152 | { |
153 | - $this->bind($alias, $this->make($binding)); |
|
153 | + $this->bind( $alias, $this->make( $binding ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param string $abstract |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - protected function addNamespace($abstract) |
|
161 | + protected function addNamespace( $abstract ) |
|
162 | 162 | { |
163 | - if (false === strpos($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
163 | + if( false === strpos( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) { |
|
164 | 164 | $abstract = __NAMESPACE__.'\\'.$abstract; |
165 | 165 | } |
166 | 166 | return $abstract; |
@@ -172,21 +172,21 @@ discard block |
||
172 | 172 | * @return mixed |
173 | 173 | * @throws Exception |
174 | 174 | */ |
175 | - protected function resolve($concrete) |
|
175 | + protected function resolve( $concrete ) |
|
176 | 176 | { |
177 | - if ($concrete instanceof Closure) { |
|
178 | - return $concrete($this); |
|
177 | + if( $concrete instanceof Closure ) { |
|
178 | + return $concrete( $this ); |
|
179 | 179 | } |
180 | - $reflector = new ReflectionClass($concrete); |
|
181 | - if (!$reflector->isInstantiable()) { |
|
182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
180 | + $reflector = new ReflectionClass( $concrete ); |
|
181 | + if( !$reflector->isInstantiable() ) { |
|
182 | + throw new Exception( 'Target ['.$concrete.'] is not instantiable.' ); |
|
183 | 183 | } |
184 | 184 | $constructor = $reflector->getConstructor(); |
185 | - if (empty($constructor)) { |
|
185 | + if( empty($constructor) ) { |
|
186 | 186 | return new $concrete(); |
187 | 187 | } |
188 | 188 | return $reflector->newInstanceArgs( |
189 | - $this->resolveDependencies($constructor->getParameters()) |
|
189 | + $this->resolveDependencies( $constructor->getParameters() ) |
|
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @return mixed |
196 | 196 | * @throws Exception |
197 | 197 | */ |
198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
198 | + protected function resolveClass( ReflectionParameter $parameter ) |
|
199 | 199 | { |
200 | 200 | try { |
201 | - return $this->make($parameter->getClass()->name); |
|
202 | - } catch (Exception $error) { |
|
203 | - if ($parameter->isOptional()) { |
|
201 | + return $this->make( $parameter->getClass()->name ); |
|
202 | + } catch( Exception $error ) { |
|
203 | + if( $parameter->isOptional() ) { |
|
204 | 204 | return $parameter->getDefaultValue(); |
205 | 205 | } |
206 | 206 | throw $error; |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | * Resolve all of the dependencies from the ReflectionParameters. |
212 | 212 | * @return array |
213 | 213 | */ |
214 | - protected function resolveDependencies(array $dependencies) |
|
214 | + protected function resolveDependencies( array $dependencies ) |
|
215 | 215 | { |
216 | 216 | $results = []; |
217 | - foreach ($dependencies as $dependency) { |
|
218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
219 | - ? $this->resolveClass($dependency) |
|
220 | - : $this->resolveDependency($dependency); |
|
217 | + foreach( $dependencies as $dependency ) { |
|
218 | + $results[] = !is_null( $class = $dependency->getClass() ) |
|
219 | + ? $this->resolveClass( $dependency ) |
|
220 | + : $this->resolveDependency( $dependency ); |
|
221 | 221 | } |
222 | 222 | return $results; |
223 | 223 | } |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * Resolve a single ReflectionParameter dependency. |
227 | 227 | * @return array|null |
228 | 228 | */ |
229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
229 | + protected function resolveDependency( ReflectionParameter $parameter ) |
|
230 | 230 | { |
231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
231 | + if( $parameter->isArray() && $parameter->isDefaultValueAvailable() ) { |
|
232 | 232 | return $parameter->getDefaultValue(); |
233 | 233 | } |
234 | 234 | return null; |
@@ -7,12 +7,12 @@ |
||
7 | 7 | |
8 | 8 | class RegisterTaxonomy |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function handle(Command $command) |
|
14 | - { |
|
15 | - register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
16 | - register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
17 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function handle(Command $command) |
|
14 | + { |
|
15 | + register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
16 | + register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
17 | + } |
|
18 | 18 | } |
@@ -10,9 +10,9 @@ |
||
10 | 10 | /** |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function handle(Command $command) |
|
13 | + public function handle( Command $command ) |
|
14 | 14 | { |
15 | - register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
16 | - register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
15 | + register_taxonomy( Application::TAXONOMY, Application::POST_TYPE, $command->args ); |
|
16 | + register_taxonomy_for_object_type( Application::TAXONOMY, Application::POST_TYPE ); |
|
17 | 17 | } |
18 | 18 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function handle(Command $command) |
|
21 | + public function handle( Command $command ) |
|
22 | 22 | { |
23 | - $this->generatePointers($command->pointers); |
|
23 | + $this->generatePointers( $command->pointers ); |
|
24 | 24 | $this->enqueueAssets(); |
25 | 25 | $this->localizeAssets(); |
26 | 26 | } |
@@ -32,23 +32,23 @@ discard block |
||
32 | 32 | { |
33 | 33 | wp_enqueue_style( |
34 | 34 | Application::ID, |
35 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
35 | + glsr()->url( 'assets/styles/'.Application::ID.'-admin.css' ), |
|
36 | 36 | [], |
37 | 37 | glsr()->version |
38 | 38 | ); |
39 | - if (!$this->isCurrentScreen()) { |
|
39 | + if( !$this->isCurrentScreen() ) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'-admin.js' ), |
|
45 | 45 | $this->getDependencies(), |
46 | 46 | glsr()->version, |
47 | 47 | true |
48 | 48 | ); |
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
49 | + if( !empty($this->pointers) ) { |
|
50 | + wp_enqueue_style( 'wp-pointer' ); |
|
51 | + wp_enqueue_script( 'wp-pointer' ); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -60,33 +60,33 @@ discard block |
||
60 | 60 | $variables = [ |
61 | 61 | 'action' => Application::PREFIX.'action', |
62 | 62 | 'addons' => [], |
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
63 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
64 | 64 | 'hideoptions' => [ |
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
65 | + 'site_reviews' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
|
68 | 68 | ], |
69 | 69 | 'nameprefix' => Application::ID, |
70 | 70 | 'nonce' => [ |
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
71 | + 'change-status' => wp_create_nonce( 'change-status' ), |
|
72 | + 'clear-console' => wp_create_nonce( 'clear-console' ), |
|
73 | + 'count-reviews' => wp_create_nonce( 'count-reviews' ), |
|
74 | + 'fetch-console' => wp_create_nonce( 'fetch-console' ), |
|
75 | + 'mce-shortcode' => wp_create_nonce( 'mce-shortcode' ), |
|
76 | + 'sync-reviews' => wp_create_nonce( 'sync-reviews' ), |
|
77 | + 'toggle-pinned' => wp_create_nonce( 'toggle-pinned' ), |
|
78 | 78 | ], |
79 | 79 | 'pointers' => $this->pointers, |
80 | 80 | 'shortcodes' => [], |
81 | 81 | 'tinymce' => [ |
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
82 | + 'glsr_shortcode' => glsr()->url( 'assets/scripts/mce-plugin.js' ), |
|
83 | 83 | ], |
84 | 84 | ]; |
85 | - if (user_can_richedit()) { |
|
85 | + if( user_can_richedit() ) { |
|
86 | 86 | $variables['shortcodes'] = $this->localizeShortcodes(); |
87 | 87 | } |
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
88 | + $variables = apply_filters( 'site-reviews/enqueue/admin/localize', $variables ); |
|
89 | + wp_localize_script( Application::ID, 'GLSR', $variables ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function getDependencies() |
96 | 96 | { |
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
97 | + $dependencies = apply_filters( 'site-reviews/enqueue/admin/dependencies', [] ); |
|
98 | + $dependencies = array_merge( $dependencies, [ |
|
99 | 99 | 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
100 | - ]); |
|
100 | + ] ); |
|
101 | 101 | return $dependencies; |
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - protected function generatePointer(array $pointer) |
|
107 | + protected function generatePointer( array $pointer ) |
|
108 | 108 | { |
109 | 109 | return [ |
110 | 110 | 'id' => $pointer['id'], |
@@ -120,19 +120,19 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - protected function generatePointers(array $pointers) |
|
123 | + protected function generatePointers( array $pointers ) |
|
124 | 124 | { |
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
125 | + $dismissedPointers = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); |
|
126 | + $dismissedPointers = explode( ',', (string)$dismissedPointers ); |
|
127 | 127 | $generatedPointers = []; |
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
128 | + foreach( $pointers as $pointer ) { |
|
129 | + if( $pointer['screen'] != glsr_current_screen()->id ) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
132 | + if( in_array( $pointer['id'], $dismissedPointers ) ) { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
135 | + $generatedPointers[] = $this->generatePointer( $pointer ); |
|
136 | 136 | } |
137 | 137 | $this->pointers = $generatedPointers; |
138 | 138 | } |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | protected function localizeShortcodes() |
157 | 157 | { |
158 | 158 | $variables = []; |
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
159 | + foreach( glsr()->mceShortcodes as $tag => $args ) { |
|
160 | + if( empty($args['required']) ) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | $variables[$tag] = $args['required']; |
@@ -10,158 +10,158 @@ |
||
10 | 10 | |
11 | 11 | class EnqueueAdminAssets |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $pointers; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $pointers; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function handle(Command $command) |
|
22 | - { |
|
23 | - $this->generatePointers($command->pointers); |
|
24 | - $this->enqueueAssets(); |
|
25 | - $this->localizeAssets(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function handle(Command $command) |
|
22 | + { |
|
23 | + $this->generatePointers($command->pointers); |
|
24 | + $this->enqueueAssets(); |
|
25 | + $this->localizeAssets(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function enqueueAssets() |
|
32 | - { |
|
33 | - wp_enqueue_style( |
|
34 | - Application::ID, |
|
35 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
36 | - [], |
|
37 | - glsr()->version |
|
38 | - ); |
|
39 | - if (!$this->isCurrentScreen()) { |
|
40 | - return; |
|
41 | - } |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID, |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | - $this->getDependencies(), |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
52 | - } |
|
53 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function enqueueAssets() |
|
32 | + { |
|
33 | + wp_enqueue_style( |
|
34 | + Application::ID, |
|
35 | + glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
36 | + [], |
|
37 | + glsr()->version |
|
38 | + ); |
|
39 | + if (!$this->isCurrentScreen()) { |
|
40 | + return; |
|
41 | + } |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID, |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | + $this->getDependencies(), |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + if (!empty($this->pointers)) { |
|
50 | + wp_enqueue_style('wp-pointer'); |
|
51 | + wp_enqueue_script('wp-pointer'); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function localizeAssets() |
|
59 | - { |
|
60 | - $variables = [ |
|
61 | - 'action' => Application::PREFIX.'action', |
|
62 | - 'addons' => [], |
|
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | - 'hideoptions' => [ |
|
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | - ], |
|
69 | - 'nameprefix' => Application::ID, |
|
70 | - 'nonce' => [ |
|
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | - ], |
|
79 | - 'pointers' => $this->pointers, |
|
80 | - 'shortcodes' => [], |
|
81 | - 'tinymce' => [ |
|
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | - ], |
|
84 | - ]; |
|
85 | - if (user_can_richedit()) { |
|
86 | - $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | - } |
|
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function localizeAssets() |
|
59 | + { |
|
60 | + $variables = [ |
|
61 | + 'action' => Application::PREFIX.'action', |
|
62 | + 'addons' => [], |
|
63 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | + 'hideoptions' => [ |
|
65 | + 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | + ], |
|
69 | + 'nameprefix' => Application::ID, |
|
70 | + 'nonce' => [ |
|
71 | + 'change-status' => wp_create_nonce('change-status'), |
|
72 | + 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | + 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | + 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | + 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | + 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | + 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | + ], |
|
79 | + 'pointers' => $this->pointers, |
|
80 | + 'shortcodes' => [], |
|
81 | + 'tinymce' => [ |
|
82 | + 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | + ], |
|
84 | + ]; |
|
85 | + if (user_can_richedit()) { |
|
86 | + $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | + } |
|
88 | + $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | + wp_localize_script(Application::ID, 'GLSR', $variables); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getDependencies() |
|
96 | - { |
|
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
99 | - 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | - ]); |
|
101 | - return $dependencies; |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getDependencies() |
|
96 | + { |
|
97 | + $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | + $dependencies = array_merge($dependencies, [ |
|
99 | + 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | + ]); |
|
101 | + return $dependencies; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function generatePointer(array $pointer) |
|
108 | - { |
|
109 | - return [ |
|
110 | - 'id' => $pointer['id'], |
|
111 | - 'options' => [ |
|
112 | - 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | - 'position' => $pointer['position'], |
|
114 | - ], |
|
115 | - 'screen' => $pointer['screen'], |
|
116 | - 'target' => $pointer['target'], |
|
117 | - ]; |
|
118 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function generatePointer(array $pointer) |
|
108 | + { |
|
109 | + return [ |
|
110 | + 'id' => $pointer['id'], |
|
111 | + 'options' => [ |
|
112 | + 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | + 'position' => $pointer['position'], |
|
114 | + ], |
|
115 | + 'screen' => $pointer['screen'], |
|
116 | + 'target' => $pointer['target'], |
|
117 | + ]; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function generatePointers(array $pointers) |
|
124 | - { |
|
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | - $generatedPointers = []; |
|
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | - } |
|
137 | - $this->pointers = $generatedPointers; |
|
138 | - } |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function generatePointers(array $pointers) |
|
124 | + { |
|
125 | + $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | + $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | + $generatedPointers = []; |
|
128 | + foreach ($pointers as $pointer) { |
|
129 | + if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | + } |
|
137 | + $this->pointers = $generatedPointers; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isCurrentScreen() |
|
144 | - { |
|
145 | - $screen = glsr_current_screen(); |
|
146 | - return Application::POST_TYPE == $screen->post_type |
|
147 | - || 'dashboard' == $screen->id |
|
148 | - || 'plugins_page_'.Application::ID == $screen->id |
|
149 | - || 'post' == $screen->base |
|
150 | - || 'widgets' == $screen->id; |
|
151 | - } |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isCurrentScreen() |
|
144 | + { |
|
145 | + $screen = glsr_current_screen(); |
|
146 | + return Application::POST_TYPE == $screen->post_type |
|
147 | + || 'dashboard' == $screen->id |
|
148 | + || 'plugins_page_'.Application::ID == $screen->id |
|
149 | + || 'post' == $screen->base |
|
150 | + || 'widgets' == $screen->id; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function localizeShortcodes() |
|
157 | - { |
|
158 | - $variables = []; |
|
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - $variables[$tag] = $args['required']; |
|
164 | - } |
|
165 | - return $variables; |
|
166 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function localizeShortcodes() |
|
157 | + { |
|
158 | + $variables = []; |
|
159 | + foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | + if (empty($args['required'])) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + $variables[$tag] = $args['required']; |
|
164 | + } |
|
165 | + return $variables; |
|
166 | + } |
|
167 | 167 | } |
@@ -6,16 +6,16 @@ |
||
6 | 6 | |
7 | 7 | class RegisterPostType |
8 | 8 | { |
9 | - /** |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function handle(Command $command) |
|
13 | - { |
|
14 | - if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
15 | - register_post_type($command->postType, $command->args); |
|
16 | - glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
17 | - $command->postType => $command->columns, |
|
18 | - ]); |
|
19 | - } |
|
20 | - } |
|
9 | + /** |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function handle(Command $command) |
|
13 | + { |
|
14 | + if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
15 | + register_post_type($command->postType, $command->args); |
|
16 | + glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
17 | + $command->postType => $command->columns, |
|
18 | + ]); |
|
19 | + } |
|
20 | + } |
|
21 | 21 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | /** |
10 | 10 | * @return void |
11 | 11 | */ |
12 | - public function handle(Command $command) |
|
12 | + public function handle( Command $command ) |
|
13 | 13 | { |
14 | - if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
15 | - register_post_type($command->postType, $command->args); |
|
16 | - glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
14 | + if( !in_array( $command->postType, get_post_types( ['_builtin' => true] ) ) ) { |
|
15 | + register_post_type( $command->postType, $command->args ); |
|
16 | + glsr()->postTypeColumns = wp_parse_args( glsr()->postTypeColumns, [ |
|
17 | 17 | $command->postType => $command->columns, |
18 | - ]); |
|
18 | + ] ); |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | } |
@@ -148,7 +148,8 @@ |
||
148 | 148 | { |
149 | 149 | if ('parent_id' == $postId) { |
150 | 150 | $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
151 | - } elseif ('post_id' == $postId) { |
|
151 | + } |
|
152 | + elseif ('post_id' == $postId) { |
|
152 | 153 | $postId = intval(get_the_ID()); |
153 | 154 | } |
154 | 155 | return $postId; |
@@ -11,223 +11,223 @@ |
||
11 | 11 | |
12 | 12 | abstract class Shortcode implements ShortcodeContract |
13 | 13 | { |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $partialName; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $shortcodeName; |
|
23 | - |
|
24 | - /** |
|
25 | - * @param string|array $atts |
|
26 | - * @param string $type |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
30 | - { |
|
31 | - $this->partialName = $this->getShortcodePartialName(); |
|
32 | - $this->shortcodeName = $this->getShortcodeName(); |
|
33 | - $args = $this->normalizeArgs($args, $type); |
|
34 | - $atts = $this->normalizeAtts($atts, $type); |
|
35 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
36 | - $title = !empty($atts['title']) |
|
37 | - ? $args['before_title'].$atts['title'].$args['after_title'] |
|
38 | - : ''; |
|
39 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
40 | - return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string|array $atts |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function buildShortcode($atts = []) |
|
48 | - { |
|
49 | - return $this->build($atts); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function getDefaults($atts) |
|
56 | - { |
|
57 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @return array |
|
62 | - */ |
|
63 | - public function getHideOptions() |
|
64 | - { |
|
65 | - $options = $this->hideOptions(); |
|
66 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
73 | - { |
|
74 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function getShortcodeDefaultsClassName() |
|
81 | - { |
|
82 | - return Helper::buildClassName( |
|
83 | - $this->getShortcodeClassName('Defaults'), |
|
84 | - 'Defaults' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getShortcodeName() |
|
92 | - { |
|
93 | - return Str::snakeCase($this->getShortcodeClassName()); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function getShortcodePartialName() |
|
100 | - { |
|
101 | - return Str::dashCase($this->getShortcodeClassName()); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param array|string $args |
|
106 | - * @param string $type |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function normalizeArgs($args, $type = 'shortcode') |
|
110 | - { |
|
111 | - $args = wp_parse_args($args, [ |
|
112 | - 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
113 | - 'after_widget' => '</div>', |
|
114 | - 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
115 | - 'after_title' => '</h3>', |
|
116 | - ]); |
|
117 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param array|string $atts |
|
122 | - * @param string $type |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
126 | - { |
|
127 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
128 | - $atts = $this->getDefaults($atts); |
|
129 | - array_walk($atts, function (&$value, $key) { |
|
130 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
131 | - if (!method_exists($this, $methodName)) { |
|
132 | - return; |
|
133 | - } |
|
134 | - $value = $this->$methodName($value); |
|
135 | - }); |
|
136 | - return $atts; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - abstract protected function hideOptions(); |
|
143 | - |
|
144 | - /** |
|
145 | - * @param string $postId |
|
146 | - * @return int|string |
|
147 | - */ |
|
148 | - protected function normalizeAssignedTo($postId) |
|
149 | - { |
|
150 | - if ('parent_id' == $postId) { |
|
151 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
152 | - } elseif ('post_id' == $postId) { |
|
153 | - $postId = intval(get_the_ID()); |
|
154 | - } |
|
155 | - return $postId; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param string $postId |
|
160 | - * @return int|string |
|
161 | - */ |
|
162 | - protected function normalizeAssignTo($postId) |
|
163 | - { |
|
164 | - return $this->normalizeAssignedTo($postId); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param string|array $hide |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - protected function normalizeHide($hide) |
|
172 | - { |
|
173 | - if (is_string($hide)) { |
|
174 | - $hide = explode(',', $hide); |
|
175 | - } |
|
176 | - $hideKeys = array_keys($this->getHideOptions()); |
|
177 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
178 | - return in_array($value, $hideKeys); |
|
179 | - }); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @param string $id |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - protected function normalizeId($id) |
|
187 | - { |
|
188 | - return sanitize_title($id); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $labels |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - protected function normalizeLabels($labels) |
|
196 | - { |
|
197 | - $defaults = [ |
|
198 | - __('Excellent', 'site-reviews'), |
|
199 | - __('Very good', 'site-reviews'), |
|
200 | - __('Average', 'site-reviews'), |
|
201 | - __('Poor', 'site-reviews'), |
|
202 | - __('Terrible', 'site-reviews'), |
|
203 | - ]; |
|
204 | - $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
205 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
206 | - $labels = array_map('trim', explode(',', $labels)); |
|
207 | - foreach ($defaults as $i => $label) { |
|
208 | - if (empty($labels[$i])) { |
|
209 | - continue; |
|
210 | - } |
|
211 | - $defaults[$i] = $labels[$i]; |
|
212 | - } |
|
213 | - return array_combine(range($maxRating, 1), $defaults); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param string $schema |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - protected function normalizeSchema($schema) |
|
221 | - { |
|
222 | - return wp_validate_boolean($schema); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @param string $text |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - protected function normalizeText($text) |
|
230 | - { |
|
231 | - return trim($text); |
|
232 | - } |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $partialName; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $shortcodeName; |
|
23 | + |
|
24 | + /** |
|
25 | + * @param string|array $atts |
|
26 | + * @param string $type |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function build($atts, array $args = [], $type = 'shortcode') |
|
30 | + { |
|
31 | + $this->partialName = $this->getShortcodePartialName(); |
|
32 | + $this->shortcodeName = $this->getShortcodeName(); |
|
33 | + $args = $this->normalizeArgs($args, $type); |
|
34 | + $atts = $this->normalizeAtts($atts, $type); |
|
35 | + $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
36 | + $title = !empty($atts['title']) |
|
37 | + ? $args['before_title'].$atts['title'].$args['after_title'] |
|
38 | + : ''; |
|
39 | + $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
40 | + return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string|array $atts |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function buildShortcode($atts = []) |
|
48 | + { |
|
49 | + return $this->build($atts); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function getDefaults($atts) |
|
56 | + { |
|
57 | + return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @return array |
|
62 | + */ |
|
63 | + public function getHideOptions() |
|
64 | + { |
|
65 | + $options = $this->hideOptions(); |
|
66 | + return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
73 | + { |
|
74 | + return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function getShortcodeDefaultsClassName() |
|
81 | + { |
|
82 | + return Helper::buildClassName( |
|
83 | + $this->getShortcodeClassName('Defaults'), |
|
84 | + 'Defaults' |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getShortcodeName() |
|
92 | + { |
|
93 | + return Str::snakeCase($this->getShortcodeClassName()); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function getShortcodePartialName() |
|
100 | + { |
|
101 | + return Str::dashCase($this->getShortcodeClassName()); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param array|string $args |
|
106 | + * @param string $type |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function normalizeArgs($args, $type = 'shortcode') |
|
110 | + { |
|
111 | + $args = wp_parse_args($args, [ |
|
112 | + 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
113 | + 'after_widget' => '</div>', |
|
114 | + 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
115 | + 'after_title' => '</h3>', |
|
116 | + ]); |
|
117 | + return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param array|string $atts |
|
122 | + * @param string $type |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
126 | + { |
|
127 | + $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
128 | + $atts = $this->getDefaults($atts); |
|
129 | + array_walk($atts, function (&$value, $key) { |
|
130 | + $methodName = Helper::buildMethodName($key, 'normalize'); |
|
131 | + if (!method_exists($this, $methodName)) { |
|
132 | + return; |
|
133 | + } |
|
134 | + $value = $this->$methodName($value); |
|
135 | + }); |
|
136 | + return $atts; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + abstract protected function hideOptions(); |
|
143 | + |
|
144 | + /** |
|
145 | + * @param string $postId |
|
146 | + * @return int|string |
|
147 | + */ |
|
148 | + protected function normalizeAssignedTo($postId) |
|
149 | + { |
|
150 | + if ('parent_id' == $postId) { |
|
151 | + $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
152 | + } elseif ('post_id' == $postId) { |
|
153 | + $postId = intval(get_the_ID()); |
|
154 | + } |
|
155 | + return $postId; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param string $postId |
|
160 | + * @return int|string |
|
161 | + */ |
|
162 | + protected function normalizeAssignTo($postId) |
|
163 | + { |
|
164 | + return $this->normalizeAssignedTo($postId); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param string|array $hide |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + protected function normalizeHide($hide) |
|
172 | + { |
|
173 | + if (is_string($hide)) { |
|
174 | + $hide = explode(',', $hide); |
|
175 | + } |
|
176 | + $hideKeys = array_keys($this->getHideOptions()); |
|
177 | + return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
178 | + return in_array($value, $hideKeys); |
|
179 | + }); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @param string $id |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + protected function normalizeId($id) |
|
187 | + { |
|
188 | + return sanitize_title($id); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $labels |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + protected function normalizeLabels($labels) |
|
196 | + { |
|
197 | + $defaults = [ |
|
198 | + __('Excellent', 'site-reviews'), |
|
199 | + __('Very good', 'site-reviews'), |
|
200 | + __('Average', 'site-reviews'), |
|
201 | + __('Poor', 'site-reviews'), |
|
202 | + __('Terrible', 'site-reviews'), |
|
203 | + ]; |
|
204 | + $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
205 | + $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
206 | + $labels = array_map('trim', explode(',', $labels)); |
|
207 | + foreach ($defaults as $i => $label) { |
|
208 | + if (empty($labels[$i])) { |
|
209 | + continue; |
|
210 | + } |
|
211 | + $defaults[$i] = $labels[$i]; |
|
212 | + } |
|
213 | + return array_combine(range($maxRating, 1), $defaults); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param string $schema |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + protected function normalizeSchema($schema) |
|
221 | + { |
|
222 | + return wp_validate_boolean($schema); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @param string $text |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + protected function normalizeText($text) |
|
230 | + { |
|
231 | + return trim($text); |
|
232 | + } |
|
233 | 233 | } |
@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | * @param string $type |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
29 | + public function build( $atts, array $args = [], $type = 'shortcode' ) |
|
30 | 30 | { |
31 | 31 | $this->partialName = $this->getShortcodePartialName(); |
32 | 32 | $this->shortcodeName = $this->getShortcodeName(); |
33 | - $args = $this->normalizeArgs($args, $type); |
|
34 | - $atts = $this->normalizeAtts($atts, $type); |
|
35 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
33 | + $args = $this->normalizeArgs( $args, $type ); |
|
34 | + $atts = $this->normalizeAtts( $atts, $type ); |
|
35 | + $partial = glsr( Partial::class )->build( $this->partialName, $atts ); |
|
36 | 36 | $title = !empty($atts['title']) |
37 | 37 | ? $args['before_title'].$atts['title'].$args['after_title'] |
38 | 38 | : ''; |
39 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
39 | + $debug = sprintf( '<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json'] ); |
|
40 | 40 | return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
41 | 41 | } |
42 | 42 | |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | * @param string|array $atts |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public function buildShortcode($atts = []) |
|
47 | + public function buildShortcode( $atts = [] ) |
|
48 | 48 | { |
49 | - return $this->build($atts); |
|
49 | + return $this->build( $atts ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public function getDefaults($atts) |
|
55 | + public function getDefaults( $atts ) |
|
56 | 56 | { |
57 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
57 | + return glsr( $this->getShortcodeDefaultsClassName() )->restrict( wp_parse_args( $atts ) ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | public function getHideOptions() |
64 | 64 | { |
65 | 65 | $options = $this->hideOptions(); |
66 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
66 | + return apply_filters( 'site-reviews/shortcode/hide-options', $options, $this->shortcodeName ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
72 | + public function getShortcodeClassName( $replace = '', $search = 'Shortcode' ) |
|
73 | 73 | { |
74 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
74 | + return str_replace( $search, $replace, (new ReflectionClass( $this ))->getShortName() ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function getShortcodeDefaultsClassName() |
81 | 81 | { |
82 | 82 | return Helper::buildClassName( |
83 | - $this->getShortcodeClassName('Defaults'), |
|
83 | + $this->getShortcodeClassName( 'Defaults' ), |
|
84 | 84 | 'Defaults' |
85 | 85 | ); |
86 | 86 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function getShortcodeName() |
92 | 92 | { |
93 | - return Str::snakeCase($this->getShortcodeClassName()); |
|
93 | + return Str::snakeCase( $this->getShortcodeClassName() ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function getShortcodePartialName() |
100 | 100 | { |
101 | - return Str::dashCase($this->getShortcodeClassName()); |
|
101 | + return Str::dashCase( $this->getShortcodeClassName() ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * @param string $type |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function normalizeArgs($args, $type = 'shortcode') |
|
109 | + public function normalizeArgs( $args, $type = 'shortcode' ) |
|
110 | 110 | { |
111 | - $args = wp_parse_args($args, [ |
|
111 | + $args = wp_parse_args( $args, [ |
|
112 | 112 | 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
113 | 113 | 'after_widget' => '</div>', |
114 | 114 | 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
115 | 115 | 'after_title' => '</h3>', |
116 | - ]); |
|
117 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
116 | + ] ); |
|
117 | + return apply_filters( 'site-reviews/shortcode/args', $args, $type, $this->partialName ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | * @param string $type |
123 | 123 | * @return array |
124 | 124 | */ |
125 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
125 | + public function normalizeAtts( $atts, $type = 'shortcode' ) |
|
126 | 126 | { |
127 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
128 | - $atts = $this->getDefaults($atts); |
|
129 | - array_walk($atts, function (&$value, $key) { |
|
130 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
131 | - if (!method_exists($this, $methodName)) { |
|
127 | + $atts = apply_filters( 'site-reviews/shortcode/atts', $atts, $type, $this->partialName ); |
|
128 | + $atts = $this->getDefaults( $atts ); |
|
129 | + array_walk( $atts, function( &$value, $key ) { |
|
130 | + $methodName = Helper::buildMethodName( $key, 'normalize' ); |
|
131 | + if( !method_exists( $this, $methodName ) ) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | - $value = $this->$methodName($value); |
|
134 | + $value = $this->$methodName( $value ); |
|
135 | 135 | }); |
136 | 136 | return $atts; |
137 | 137 | } |
@@ -145,12 +145,12 @@ discard block |
||
145 | 145 | * @param string $postId |
146 | 146 | * @return int|string |
147 | 147 | */ |
148 | - protected function normalizeAssignedTo($postId) |
|
148 | + protected function normalizeAssignedTo( $postId ) |
|
149 | 149 | { |
150 | - if ('parent_id' == $postId) { |
|
151 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
152 | - } elseif ('post_id' == $postId) { |
|
153 | - $postId = intval(get_the_ID()); |
|
150 | + if( 'parent_id' == $postId ) { |
|
151 | + $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) ); |
|
152 | + } elseif( 'post_id' == $postId ) { |
|
153 | + $postId = intval( get_the_ID() ); |
|
154 | 154 | } |
155 | 155 | return $postId; |
156 | 156 | } |
@@ -159,23 +159,23 @@ discard block |
||
159 | 159 | * @param string $postId |
160 | 160 | * @return int|string |
161 | 161 | */ |
162 | - protected function normalizeAssignTo($postId) |
|
162 | + protected function normalizeAssignTo( $postId ) |
|
163 | 163 | { |
164 | - return $this->normalizeAssignedTo($postId); |
|
164 | + return $this->normalizeAssignedTo( $postId ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | 168 | * @param string|array $hide |
169 | 169 | * @return array |
170 | 170 | */ |
171 | - protected function normalizeHide($hide) |
|
171 | + protected function normalizeHide( $hide ) |
|
172 | 172 | { |
173 | - if (is_string($hide)) { |
|
174 | - $hide = explode(',', $hide); |
|
173 | + if( is_string( $hide ) ) { |
|
174 | + $hide = explode( ',', $hide ); |
|
175 | 175 | } |
176 | - $hideKeys = array_keys($this->getHideOptions()); |
|
177 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
178 | - return in_array($value, $hideKeys); |
|
176 | + $hideKeys = array_keys( $this->getHideOptions() ); |
|
177 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use ($hideKeys) { |
|
178 | + return in_array( $value, $hideKeys ); |
|
179 | 179 | }); |
180 | 180 | } |
181 | 181 | |
@@ -183,51 +183,51 @@ discard block |
||
183 | 183 | * @param string $id |
184 | 184 | * @return string |
185 | 185 | */ |
186 | - protected function normalizeId($id) |
|
186 | + protected function normalizeId( $id ) |
|
187 | 187 | { |
188 | - return sanitize_title($id); |
|
188 | + return sanitize_title( $id ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param string $labels |
193 | 193 | * @return array |
194 | 194 | */ |
195 | - protected function normalizeLabels($labels) |
|
195 | + protected function normalizeLabels( $labels ) |
|
196 | 196 | { |
197 | 197 | $defaults = [ |
198 | - __('Excellent', 'site-reviews'), |
|
199 | - __('Very good', 'site-reviews'), |
|
200 | - __('Average', 'site-reviews'), |
|
201 | - __('Poor', 'site-reviews'), |
|
202 | - __('Terrible', 'site-reviews'), |
|
198 | + __( 'Excellent', 'site-reviews' ), |
|
199 | + __( 'Very good', 'site-reviews' ), |
|
200 | + __( 'Average', 'site-reviews' ), |
|
201 | + __( 'Poor', 'site-reviews' ), |
|
202 | + __( 'Terrible', 'site-reviews' ), |
|
203 | 203 | ]; |
204 | - $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
205 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
206 | - $labels = array_map('trim', explode(',', $labels)); |
|
207 | - foreach ($defaults as $i => $label) { |
|
208 | - if (empty($labels[$i])) { |
|
204 | + $maxRating = glsr()->constant( 'MAX_RATING', Rating::class ); |
|
205 | + $defaults = array_pad( array_slice( $defaults, 0, $maxRating ), $maxRating, '' ); |
|
206 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
207 | + foreach( $defaults as $i => $label ) { |
|
208 | + if( empty($labels[$i]) ) { |
|
209 | 209 | continue; |
210 | 210 | } |
211 | 211 | $defaults[$i] = $labels[$i]; |
212 | 212 | } |
213 | - return array_combine(range($maxRating, 1), $defaults); |
|
213 | + return array_combine( range( $maxRating, 1 ), $defaults ); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
217 | 217 | * @param string $schema |
218 | 218 | * @return bool |
219 | 219 | */ |
220 | - protected function normalizeSchema($schema) |
|
220 | + protected function normalizeSchema( $schema ) |
|
221 | 221 | { |
222 | - return wp_validate_boolean($schema); |
|
222 | + return wp_validate_boolean( $schema ); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | 226 | * @param string $text |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - protected function normalizeText($text) |
|
229 | + protected function normalizeText( $text ) |
|
230 | 230 | { |
231 | - return trim($text); |
|
231 | + return trim( $text ); |
|
232 | 232 | } |
233 | 233 | } |
@@ -4,50 +4,50 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsFormPopup extends TinymcePopupGenerator |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public function fields() |
|
11 | - { |
|
12 | - return [[ |
|
13 | - 'type' => 'container', |
|
14 | - 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
15 | - ], [ |
|
16 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | - 'name' => 'title', |
|
18 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | - 'type' => 'textbox', |
|
20 | - ], [ |
|
21 | - 'label' => esc_html__('Description', 'site-reviews'), |
|
22 | - 'minHeight' => 60, |
|
23 | - 'minWidth' => 240, |
|
24 | - 'multiline' => true, |
|
25 | - 'name' => 'description', |
|
26 | - 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
27 | - 'type' => 'textbox', |
|
28 | - ], |
|
29 | - $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
30 | - [ |
|
31 | - 'label' => esc_html__('Assign To', 'site-reviews'), |
|
32 | - 'name' => 'assign_to', |
|
33 | - 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
34 | - 'type' => 'textbox', |
|
35 | - ], [ |
|
36 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
37 | - 'name' => 'class', |
|
38 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
39 | - 'type' => 'textbox', |
|
40 | - ], [ |
|
41 | - 'columns' => 2, |
|
42 | - 'items' => $this->getHideOptions(), |
|
43 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
44 | - 'layout' => 'grid', |
|
45 | - 'spacing' => 5, |
|
46 | - 'type' => 'container', |
|
47 | - ], [ |
|
48 | - 'hidden' => true, |
|
49 | - 'name' => 'id', |
|
50 | - 'type' => 'textbox', |
|
51 | - ], ]; |
|
52 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public function fields() |
|
11 | + { |
|
12 | + return [[ |
|
13 | + 'type' => 'container', |
|
14 | + 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
15 | + ], [ |
|
16 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | + 'name' => 'title', |
|
18 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | + 'type' => 'textbox', |
|
20 | + ], [ |
|
21 | + 'label' => esc_html__('Description', 'site-reviews'), |
|
22 | + 'minHeight' => 60, |
|
23 | + 'minWidth' => 240, |
|
24 | + 'multiline' => true, |
|
25 | + 'name' => 'description', |
|
26 | + 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
27 | + 'type' => 'textbox', |
|
28 | + ], |
|
29 | + $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
30 | + [ |
|
31 | + 'label' => esc_html__('Assign To', 'site-reviews'), |
|
32 | + 'name' => 'assign_to', |
|
33 | + 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
34 | + 'type' => 'textbox', |
|
35 | + ], [ |
|
36 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
37 | + 'name' => 'class', |
|
38 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
39 | + 'type' => 'textbox', |
|
40 | + ], [ |
|
41 | + 'columns' => 2, |
|
42 | + 'items' => $this->getHideOptions(), |
|
43 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
44 | + 'layout' => 'grid', |
|
45 | + 'spacing' => 5, |
|
46 | + 'type' => 'container', |
|
47 | + ], [ |
|
48 | + 'hidden' => true, |
|
49 | + 'name' => 'id', |
|
50 | + 'type' => 'textbox', |
|
51 | + ], ]; |
|
52 | + } |
|
53 | 53 | } |
@@ -11,36 +11,36 @@ |
||
11 | 11 | { |
12 | 12 | return [[ |
13 | 13 | 'type' => 'container', |
14 | - 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
14 | + 'html' => '<p class="strong">'.esc_html__( 'All settings are optional.', 'site-reviews' ).'</p>', |
|
15 | 15 | ], [ |
16 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
16 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
17 | 17 | 'name' => 'title', |
18 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
18 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
19 | 19 | 'type' => 'textbox', |
20 | 20 | ], [ |
21 | - 'label' => esc_html__('Description', 'site-reviews'), |
|
21 | + 'label' => esc_html__( 'Description', 'site-reviews' ), |
|
22 | 22 | 'minHeight' => 60, |
23 | 23 | 'minWidth' => 240, |
24 | 24 | 'multiline' => true, |
25 | 25 | 'name' => 'description', |
26 | - 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
26 | + 'tooltip' => __( 'Enter a custom shortcode description.', 'site-reviews' ), |
|
27 | 27 | 'type' => 'textbox', |
28 | 28 | ], |
29 | - $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
29 | + $this->getCategories( __( 'Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews' ) ), |
|
30 | 30 | [ |
31 | - 'label' => esc_html__('Assign To', 'site-reviews'), |
|
31 | + 'label' => esc_html__( 'Assign To', 'site-reviews' ), |
|
32 | 32 | 'name' => 'assign_to', |
33 | - 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
33 | + 'tooltip' => __( 'Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews' ), |
|
34 | 34 | 'type' => 'textbox', |
35 | 35 | ], [ |
36 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
36 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
37 | 37 | 'name' => 'class', |
38 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
38 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
39 | 39 | 'type' => 'textbox', |
40 | 40 | ], [ |
41 | 41 | 'columns' => 2, |
42 | 42 | 'items' => $this->getHideOptions(), |
43 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
43 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
44 | 44 | 'layout' => 'grid', |
45 | 45 | 'spacing' => 5, |
46 | 46 | 'type' => 'container', |