@@ -12,144 +12,144 @@ |
||
12 | 12 | |
13 | 13 | class Style |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $fields; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $fields; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $style; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $style; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - public $pagination; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + public $pagination; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $validation; |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $validation; |
|
34 | 34 | |
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | - $this->setConfig(); |
|
39 | - } |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | + $this->setConfig(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $view |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function filterView($view) |
|
46 | - { |
|
47 | - $styledViews = [ |
|
48 | - 'templates/form/field', |
|
49 | - 'templates/form/response', |
|
50 | - 'templates/form/submit-button', |
|
51 | - 'templates/reviews-form', |
|
52 | - ]; |
|
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | - return $view; |
|
55 | - } |
|
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
59 | - continue; |
|
60 | - } |
|
61 | - return Str::removePrefix('views/', $possibleView); |
|
62 | - } |
|
63 | - return $view; |
|
64 | - } |
|
41 | + /** |
|
42 | + * @param string $view |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function filterView($view) |
|
46 | + { |
|
47 | + $styledViews = [ |
|
48 | + 'templates/form/field', |
|
49 | + 'templates/form/response', |
|
50 | + 'templates/form/submit-button', |
|
51 | + 'templates/reviews-form', |
|
52 | + ]; |
|
53 | + if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | + return $view; |
|
55 | + } |
|
56 | + $views = $this->generatePossibleViews($view); |
|
57 | + foreach ($views as $possibleView) { |
|
58 | + if (!file_exists(glsr()->file($possibleView))) { |
|
59 | + continue; |
|
60 | + } |
|
61 | + return Str::removePrefix('views/', $possibleView); |
|
62 | + } |
|
63 | + return $view; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function get() |
|
70 | - { |
|
71 | - return apply_filters('site-reviews/style', $this->style); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function get() |
|
70 | + { |
|
71 | + return apply_filters('site-reviews/style', $this->style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public function setConfig() |
|
78 | - { |
|
79 | - $config = shortcode_atts( |
|
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
82 | - ); |
|
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | - } |
|
74 | + /** |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public function setConfig() |
|
78 | + { |
|
79 | + $config = shortcode_atts( |
|
80 | + array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | + glsr()->config('styles/'.$this->style) |
|
82 | + ); |
|
83 | + $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | + $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | + $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function modifyField(Builder $instance) |
|
92 | - { |
|
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | - return; |
|
95 | - } |
|
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function modifyField(Builder $instance) |
|
92 | + { |
|
93 | + if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | + return; |
|
95 | + } |
|
96 | + call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function paginationArgs(array $args) |
|
103 | - { |
|
104 | - return wp_parse_args($args, $this->pagination); |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function paginationArgs(array $args) |
|
103 | + { |
|
104 | + return wp_parse_args($args, $this->pagination); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - protected function customize(Builder $instance) |
|
111 | - { |
|
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | - $key = $instance->tag.'_'.$args['type']; |
|
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | - } |
|
107 | + /** |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + protected function customize(Builder $instance) |
|
111 | + { |
|
112 | + if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | + $key = $instance->tag.'_'.$args['type']; |
|
117 | + $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | + $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | + do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @param string $view |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - protected function generatePossibleViews($view) |
|
127 | - { |
|
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
130 | - $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | - $parts = explode('_', $basename); |
|
132 | - $views = [ |
|
133 | - $customPath.$basename, |
|
134 | - $customPath.$parts[0], |
|
135 | - $view, |
|
136 | - $basepath.$parts[0], |
|
137 | - ]; |
|
138 | - return array_filter($views); |
|
139 | - } |
|
122 | + /** |
|
123 | + * @param string $view |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + protected function generatePossibleViews($view) |
|
127 | + { |
|
128 | + $basename = basename($view); |
|
129 | + $basepath = rtrim($view, $basename); |
|
130 | + $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | + $parts = explode('_', $basename); |
|
132 | + $views = [ |
|
133 | + $customPath.$basename, |
|
134 | + $customPath.$parts[0], |
|
135 | + $view, |
|
136 | + $basepath.$parts[0], |
|
137 | + ]; |
|
138 | + return array_filter($views); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - protected function isPublicInstance(Builder $instance) |
|
145 | - { |
|
146 | - $args = wp_parse_args($instance->args, [ |
|
147 | - 'is_public' => false, |
|
148 | - 'is_raw' => false, |
|
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | - return false; |
|
152 | - } |
|
153 | - return true; |
|
154 | - } |
|
141 | + /** |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + protected function isPublicInstance(Builder $instance) |
|
145 | + { |
|
146 | + $args = wp_parse_args($instance->args, [ |
|
147 | + 'is_public' => false, |
|
148 | + 'is_raw' => false, |
|
149 | + ]); |
|
150 | + if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | + return false; |
|
152 | + } |
|
153 | + return true; |
|
154 | + } |
|
155 | 155 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct() |
36 | 36 | { |
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
37 | + $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' ); |
|
38 | 38 | $this->setConfig(); |
39 | 39 | } |
40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $view |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function filterView($view) |
|
45 | + public function filterView( $view ) |
|
46 | 46 | { |
47 | 47 | $styledViews = [ |
48 | 48 | 'templates/form/field', |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | 'templates/form/submit-button', |
51 | 51 | 'templates/reviews-form', |
52 | 52 | ]; |
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
54 | 54 | return $view; |
55 | 55 | } |
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
56 | + $views = $this->generatePossibleViews( $view ); |
|
57 | + foreach( $views as $possibleView ) { |
|
58 | + if( !file_exists( glsr()->file( $possibleView ) ) ) { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | - return Str::removePrefix('views/', $possibleView); |
|
61 | + return Str::removePrefix( 'views/', $possibleView ); |
|
62 | 62 | } |
63 | 63 | return $view; |
64 | 64 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function get() |
70 | 70 | { |
71 | - return apply_filters('site-reviews/style', $this->style); |
|
71 | + return apply_filters( 'site-reviews/style', $this->style ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,77 +77,77 @@ discard block |
||
77 | 77 | public function setConfig() |
78 | 78 | { |
79 | 79 | $config = shortcode_atts( |
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
80 | + array_fill_keys( ['fields', 'pagination', 'validation'], [] ), |
|
81 | + glsr()->config( 'styles/'.$this->style ) |
|
82 | 82 | ); |
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
83 | + $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] ); |
|
84 | + $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] ); |
|
85 | + $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function modifyField(Builder $instance) |
|
91 | + public function modifyField( Builder $instance ) |
|
92 | 92 | { |
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
93 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
96 | + call_user_func_array( [$this, 'customize'], [$instance] ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - public function paginationArgs(array $args) |
|
102 | + public function paginationArgs( array $args ) |
|
103 | 103 | { |
104 | - return wp_parse_args($args, $this->pagination); |
|
104 | + return wp_parse_args( $args, $this->pagination ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - protected function customize(Builder $instance) |
|
110 | + protected function customize( Builder $instance ) |
|
111 | 111 | { |
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
112 | + if( !array_key_exists( $instance->tag, $this->fields ) ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
115 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
116 | 116 | $key = $instance->tag.'_'.$args['type']; |
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
117 | + $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) ); |
|
118 | + $instance->args['class'] = trim( $args['class'].' '.$classes ); |
|
119 | + do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string $view |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - protected function generatePossibleViews($view) |
|
126 | + protected function generatePossibleViews( $view ) |
|
127 | 127 | { |
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
128 | + $basename = basename( $view ); |
|
129 | + $basepath = rtrim( $view, $basename ); |
|
130 | 130 | $customPath = 'views/partials/styles/'.$this->style.'/'; |
131 | - $parts = explode('_', $basename); |
|
131 | + $parts = explode( '_', $basename ); |
|
132 | 132 | $views = [ |
133 | 133 | $customPath.$basename, |
134 | 134 | $customPath.$parts[0], |
135 | 135 | $view, |
136 | 136 | $basepath.$parts[0], |
137 | 137 | ]; |
138 | - return array_filter($views); |
|
138 | + return array_filter( $views ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - protected function isPublicInstance(Builder $instance) |
|
144 | + protected function isPublicInstance( Builder $instance ) |
|
145 | 145 | { |
146 | - $args = wp_parse_args($instance->args, [ |
|
146 | + $args = wp_parse_args( $instance->args, [ |
|
147 | 147 | 'is_public' => false, |
148 | 148 | 'is_raw' => false, |
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
149 | + ] ); |
|
150 | + if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | return true; |
@@ -12,173 +12,173 @@ |
||
12 | 12 | |
13 | 13 | class Review implements \ArrayAccess |
14 | 14 | { |
15 | - public $assigned_to; |
|
16 | - public $author; |
|
17 | - public $avatar; |
|
18 | - public $content; |
|
19 | - public $custom; |
|
20 | - public $date; |
|
21 | - public $email; |
|
22 | - public $ID; |
|
23 | - public $ip_address; |
|
24 | - public $modified; |
|
25 | - public $pinned; |
|
26 | - public $rating; |
|
27 | - public $response; |
|
28 | - public $review_id; |
|
29 | - public $review_type; |
|
30 | - public $status; |
|
31 | - public $term_ids; |
|
32 | - public $title; |
|
33 | - public $url; |
|
34 | - public $user_id; |
|
15 | + public $assigned_to; |
|
16 | + public $author; |
|
17 | + public $avatar; |
|
18 | + public $content; |
|
19 | + public $custom; |
|
20 | + public $date; |
|
21 | + public $email; |
|
22 | + public $ID; |
|
23 | + public $ip_address; |
|
24 | + public $modified; |
|
25 | + public $pinned; |
|
26 | + public $rating; |
|
27 | + public $response; |
|
28 | + public $review_id; |
|
29 | + public $review_type; |
|
30 | + public $status; |
|
31 | + public $term_ids; |
|
32 | + public $title; |
|
33 | + public $url; |
|
34 | + public $user_id; |
|
35 | 35 | |
36 | - public function __construct(WP_Post $post) |
|
37 | - { |
|
38 | - if (Application::POST_TYPE != $post->post_type) { |
|
39 | - return; |
|
40 | - } |
|
41 | - $this->content = $post->post_content; |
|
42 | - $this->date = $post->post_date; |
|
43 | - $this->ID = intval($post->ID); |
|
44 | - $this->status = $post->post_status; |
|
45 | - $this->title = $post->post_title; |
|
46 | - $this->user_id = intval($post->post_author); |
|
47 | - $this->setProperties($post); |
|
48 | - $this->setTermIds($post); |
|
49 | - } |
|
36 | + public function __construct(WP_Post $post) |
|
37 | + { |
|
38 | + if (Application::POST_TYPE != $post->post_type) { |
|
39 | + return; |
|
40 | + } |
|
41 | + $this->content = $post->post_content; |
|
42 | + $this->date = $post->post_date; |
|
43 | + $this->ID = intval($post->ID); |
|
44 | + $this->status = $post->post_status; |
|
45 | + $this->title = $post->post_title; |
|
46 | + $this->user_id = intval($post->post_author); |
|
47 | + $this->setProperties($post); |
|
48 | + $this->setTermIds($post); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return mixed |
|
53 | - */ |
|
54 | - public function __get($key) |
|
55 | - { |
|
56 | - return $this->offsetGet($key); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return mixed |
|
53 | + */ |
|
54 | + public function __get($key) |
|
55 | + { |
|
56 | + return $this->offsetGet($key); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function __toString() |
|
63 | - { |
|
64 | - return (string) $this->build(); |
|
65 | - } |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function __toString() |
|
63 | + { |
|
64 | + return (string) $this->build(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return ReviewHtml |
|
69 | - */ |
|
70 | - public function build(array $args = []) |
|
71 | - { |
|
72 | - if (empty($this->ID)) { |
|
73 | - return new ReviewHtml($this); |
|
74 | - } |
|
75 | - $partial = glsr(SiteReviewsPartial::class); |
|
76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | - return $partial->buildReview($this); |
|
79 | - } |
|
67 | + /** |
|
68 | + * @return ReviewHtml |
|
69 | + */ |
|
70 | + public function build(array $args = []) |
|
71 | + { |
|
72 | + if (empty($this->ID)) { |
|
73 | + return new ReviewHtml($this); |
|
74 | + } |
|
75 | + $partial = glsr(SiteReviewsPartial::class); |
|
76 | + $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | + $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | + return $partial->buildReview($this); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function offsetExists($key) |
|
86 | - { |
|
87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
88 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function offsetExists($key) |
|
86 | + { |
|
87 | + return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param mixed $key |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - public function offsetGet($key) |
|
95 | - { |
|
96 | - return property_exists($this, $key) |
|
97 | - ? $this->$key |
|
98 | - : Arr::get($this->custom, $key, null); |
|
99 | - } |
|
90 | + /** |
|
91 | + * @param mixed $key |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + public function offsetGet($key) |
|
95 | + { |
|
96 | + return property_exists($this, $key) |
|
97 | + ? $this->$key |
|
98 | + : Arr::get($this->custom, $key, null); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param mixed $key |
|
103 | - * @param mixed $value |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function offsetSet($key, $value) |
|
107 | - { |
|
108 | - if (property_exists($this, $key)) { |
|
109 | - $this->$key = $value; |
|
110 | - return; |
|
111 | - } |
|
112 | - if (!is_array($this->custom)) { |
|
113 | - $this->custom = array_filter((array) $this->custom); |
|
114 | - } |
|
115 | - $this->custom[$key] = $value; |
|
116 | - } |
|
101 | + /** |
|
102 | + * @param mixed $key |
|
103 | + * @param mixed $value |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function offsetSet($key, $value) |
|
107 | + { |
|
108 | + if (property_exists($this, $key)) { |
|
109 | + $this->$key = $value; |
|
110 | + return; |
|
111 | + } |
|
112 | + if (!is_array($this->custom)) { |
|
113 | + $this->custom = array_filter((array) $this->custom); |
|
114 | + } |
|
115 | + $this->custom[$key] = $value; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @param mixed $key |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function offsetUnset($key) |
|
123 | - { |
|
124 | - $this->offsetSet($key, null); |
|
125 | - } |
|
118 | + /** |
|
119 | + * @param mixed $key |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function offsetUnset($key) |
|
123 | + { |
|
124 | + $this->offsetSet($key, null); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public function render() |
|
131 | - { |
|
132 | - echo $this->build(); |
|
133 | - } |
|
127 | + /** |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function render() |
|
131 | + { |
|
132 | + echo $this->build(); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - protected function isModified(array $properties) |
|
139 | - { |
|
140 | - return $this->date != $properties['date'] |
|
141 | - || $this->content != $properties['content'] |
|
142 | - || $this->title != $properties['title']; |
|
143 | - } |
|
135 | + /** |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + protected function isModified(array $properties) |
|
139 | + { |
|
140 | + return $this->date != $properties['date'] |
|
141 | + || $this->content != $properties['content'] |
|
142 | + || $this->title != $properties['title']; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - protected function setProperties(WP_Post $post) |
|
149 | - { |
|
150 | - $defaults = [ |
|
151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
152 | - 'date' => '', |
|
153 | - 'review_id' => '', |
|
154 | - 'review_type' => 'local', |
|
155 | - ]; |
|
156 | - $meta = array_filter( |
|
157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
158 | - 'strlen' |
|
159 | - ); |
|
160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | - $this->modified = $this->isModified($properties); |
|
163 | - array_walk($properties, function ($value, $key) { |
|
164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
165 | - return; |
|
166 | - } |
|
167 | - $this->$key = maybe_unserialize($value); |
|
168 | - }); |
|
169 | - } |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + protected function setProperties(WP_Post $post) |
|
149 | + { |
|
150 | + $defaults = [ |
|
151 | + 'author' => __('Anonymous', 'site-reviews'), |
|
152 | + 'date' => '', |
|
153 | + 'review_id' => '', |
|
154 | + 'review_type' => 'local', |
|
155 | + ]; |
|
156 | + $meta = array_filter( |
|
157 | + array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
158 | + 'strlen' |
|
159 | + ); |
|
160 | + $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | + $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | + $this->modified = $this->isModified($properties); |
|
163 | + array_walk($properties, function ($value, $key) { |
|
164 | + if (!property_exists($this, $key) || isset($this->$key)) { |
|
165 | + return; |
|
166 | + } |
|
167 | + $this->$key = maybe_unserialize($value); |
|
168 | + }); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - protected function setTermIds(WP_Post $post) |
|
175 | - { |
|
176 | - $this->term_ids = []; |
|
177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
178 | - return; |
|
179 | - } |
|
180 | - foreach ($terms as $term) { |
|
181 | - $this->term_ids[] = $term->term_id; |
|
182 | - } |
|
183 | - } |
|
171 | + /** |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + protected function setTermIds(WP_Post $post) |
|
175 | + { |
|
176 | + $this->term_ids = []; |
|
177 | + if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
178 | + return; |
|
179 | + } |
|
180 | + foreach ($terms as $term) { |
|
181 | + $this->term_ids[] = $term->term_id; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | } |
@@ -33,27 +33,27 @@ discard block |
||
33 | 33 | public $url; |
34 | 34 | public $user_id; |
35 | 35 | |
36 | - public function __construct(WP_Post $post) |
|
36 | + public function __construct( WP_Post $post ) |
|
37 | 37 | { |
38 | - if (Application::POST_TYPE != $post->post_type) { |
|
38 | + if( Application::POST_TYPE != $post->post_type ) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | $this->content = $post->post_content; |
42 | 42 | $this->date = $post->post_date; |
43 | - $this->ID = intval($post->ID); |
|
43 | + $this->ID = intval( $post->ID ); |
|
44 | 44 | $this->status = $post->post_status; |
45 | 45 | $this->title = $post->post_title; |
46 | - $this->user_id = intval($post->post_author); |
|
47 | - $this->setProperties($post); |
|
48 | - $this->setTermIds($post); |
|
46 | + $this->user_id = intval( $post->post_author ); |
|
47 | + $this->setProperties( $post ); |
|
48 | + $this->setTermIds( $post ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - public function __get($key) |
|
54 | + public function __get( $key ) |
|
55 | 55 | { |
56 | - return $this->offsetGet($key); |
|
56 | + return $this->offsetGet( $key ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -61,41 +61,41 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function __toString() |
63 | 63 | { |
64 | - return (string) $this->build(); |
|
64 | + return (string)$this->build(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @return ReviewHtml |
69 | 69 | */ |
70 | - public function build(array $args = []) |
|
70 | + public function build( array $args = [] ) |
|
71 | 71 | { |
72 | - if (empty($this->ID)) { |
|
73 | - return new ReviewHtml($this); |
|
72 | + if( empty($this->ID) ) { |
|
73 | + return new ReviewHtml( $this ); |
|
74 | 74 | } |
75 | - $partial = glsr(SiteReviewsPartial::class); |
|
76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | - return $partial->buildReview($this); |
|
75 | + $partial = glsr( SiteReviewsPartial::class ); |
|
76 | + $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
77 | + $partial->options = Arr::flattenArray( glsr( OptionManager::class )->all() ); |
|
78 | + return $partial->buildReview( $this ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - public function offsetExists($key) |
|
85 | + public function offsetExists( $key ) |
|
86 | 86 | { |
87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
87 | + return property_exists( $this, $key ) || array_key_exists( $key, (array)$this->custom ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @param mixed $key |
92 | 92 | * @return mixed |
93 | 93 | */ |
94 | - public function offsetGet($key) |
|
94 | + public function offsetGet( $key ) |
|
95 | 95 | { |
96 | - return property_exists($this, $key) |
|
96 | + return property_exists( $this, $key ) |
|
97 | 97 | ? $this->$key |
98 | - : Arr::get($this->custom, $key, null); |
|
98 | + : Arr::get( $this->custom, $key, null ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * @param mixed $value |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function offsetSet($key, $value) |
|
106 | + public function offsetSet( $key, $value ) |
|
107 | 107 | { |
108 | - if (property_exists($this, $key)) { |
|
108 | + if( property_exists( $this, $key ) ) { |
|
109 | 109 | $this->$key = $value; |
110 | 110 | return; |
111 | 111 | } |
112 | - if (!is_array($this->custom)) { |
|
113 | - $this->custom = array_filter((array) $this->custom); |
|
112 | + if( !is_array( $this->custom ) ) { |
|
113 | + $this->custom = array_filter( (array)$this->custom ); |
|
114 | 114 | } |
115 | 115 | $this->custom[$key] = $value; |
116 | 116 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @param mixed $key |
120 | 120 | * @return void |
121 | 121 | */ |
122 | - public function offsetUnset($key) |
|
122 | + public function offsetUnset( $key ) |
|
123 | 123 | { |
124 | - $this->offsetSet($key, null); |
|
124 | + $this->offsetSet( $key, null ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @return bool |
137 | 137 | */ |
138 | - protected function isModified(array $properties) |
|
138 | + protected function isModified( array $properties ) |
|
139 | 139 | { |
140 | 140 | return $this->date != $properties['date'] |
141 | 141 | || $this->content != $properties['content'] |
@@ -145,39 +145,39 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @return void |
147 | 147 | */ |
148 | - protected function setProperties(WP_Post $post) |
|
148 | + protected function setProperties( WP_Post $post ) |
|
149 | 149 | { |
150 | 150 | $defaults = [ |
151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
151 | + 'author' => __( 'Anonymous', 'site-reviews' ), |
|
152 | 152 | 'date' => '', |
153 | 153 | 'review_id' => '', |
154 | 154 | 'review_type' => 'local', |
155 | 155 | ]; |
156 | 156 | $meta = array_filter( |
157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
157 | + array_map( 'array_shift', array_filter( (array)get_post_meta( $post->ID ) ) ), |
|
158 | 158 | 'strlen' |
159 | 159 | ); |
160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | - $this->modified = $this->isModified($properties); |
|
163 | - array_walk($properties, function ($value, $key) { |
|
164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
160 | + $meta = array_merge( $defaults, Arr::unprefixArrayKeys( $meta ) ); |
|
161 | + $properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta ) ); |
|
162 | + $this->modified = $this->isModified( $properties ); |
|
163 | + array_walk( $properties, function( $value, $key ) { |
|
164 | + if( !property_exists( $this, $key ) || isset($this->$key) ) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | - $this->$key = maybe_unserialize($value); |
|
167 | + $this->$key = maybe_unserialize( $value ); |
|
168 | 168 | }); |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | 172 | * @return void |
173 | 173 | */ |
174 | - protected function setTermIds(WP_Post $post) |
|
174 | + protected function setTermIds( WP_Post $post ) |
|
175 | 175 | { |
176 | 176 | $this->term_ids = []; |
177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
177 | + if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY ) ) ) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - foreach ($terms as $term) { |
|
180 | + foreach( $terms as $term ) { |
|
181 | 181 | $this->term_ids[] = $term->term_id; |
182 | 182 | } |
183 | 183 | } |
@@ -9,205 +9,205 @@ |
||
9 | 9 | |
10 | 10 | class Email |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - public $attachments; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - public $email; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $headers; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $message; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $subject; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string|array |
|
39 | - */ |
|
40 | - public $to; |
|
41 | - |
|
42 | - /** |
|
43 | - * @return Email |
|
44 | - */ |
|
45 | - public function compose(array $email) |
|
46 | - { |
|
47 | - $this->normalize($email); |
|
48 | - $this->attachments = $this->email['attachments']; |
|
49 | - $this->headers = $this->buildHeaders(); |
|
50 | - $this->message = $this->buildHtmlMessage(); |
|
51 | - $this->subject = $this->email['subject']; |
|
52 | - $this->to = $this->email['to']; |
|
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
54 | - return $this; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $format |
|
59 | - * @return string|null |
|
60 | - */ |
|
61 | - public function read($format = '') |
|
62 | - { |
|
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
66 | - } |
|
67 | - return $this->message; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return void|bool |
|
72 | - */ |
|
73 | - public function send() |
|
74 | - { |
|
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
76 | - return; |
|
77 | - } |
|
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
79 | - $sent = wp_mail( |
|
80 | - $this->to, |
|
81 | - $this->subject, |
|
82 | - $this->message, |
|
83 | - $this->headers, |
|
84 | - $this->attachments |
|
85 | - ); |
|
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
87 | - $this->reset(); |
|
88 | - return $sent; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return void |
|
93 | - * @action phpmailer_init |
|
94 | - */ |
|
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
96 | - { |
|
97 | - if (empty($this->email)) { |
|
98 | - return; |
|
99 | - } |
|
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - protected function buildHeaders() |
|
111 | - { |
|
112 | - $allowed = [ |
|
113 | - 'bcc', 'cc', 'from', 'reply-to', |
|
114 | - ]; |
|
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
118 | - unset($headers[$key]); |
|
119 | - $headers[] = $key.': '.$value; |
|
120 | - } |
|
121 | - $headers[] = 'Content-Type: text/html'; |
|
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function buildHtmlMessage() |
|
129 | - { |
|
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate( |
|
133 | - $template, |
|
134 | - ['context' => $this->email['template-tags']], |
|
135 | - $this->email['template'] |
|
136 | - ); |
|
137 | - } elseif ($this->email['template']) { |
|
138 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
139 | - 'context' => $this->email['template-tags'], |
|
140 | - ]); |
|
141 | - } |
|
142 | - if (!isset($message)) { |
|
143 | - $message = $this->email['message']; |
|
144 | - } |
|
145 | - $message = $this->email['before'].$message.$this->email['after']; |
|
146 | - $message = strip_shortcodes($message); |
|
147 | - $message = wptexturize($message); |
|
148 | - $message = wpautop($message); |
|
149 | - $message = str_replace('<> ', '', $message); |
|
150 | - $message = str_replace(']]>', ']]>', $message); |
|
151 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
152 | - 'context' => ['message' => $message], |
|
153 | - ]); |
|
154 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param \WP_Error $error |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - protected function logMailError($error) |
|
162 | - { |
|
163 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
164 | - ->debug($this) |
|
165 | - ->debug($error); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - protected function normalize(array $email = []) |
|
172 | - { |
|
173 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
174 | - if (empty($email['reply-to'])) { |
|
175 | - $email['reply-to'] = $email['from']; |
|
176 | - } |
|
177 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - protected function reset() |
|
184 | - { |
|
185 | - $this->attachments = []; |
|
186 | - $this->email = []; |
|
187 | - $this->headers = []; |
|
188 | - $this->message = null; |
|
189 | - $this->subject = null; |
|
190 | - $this->to = null; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - protected function stripHtmlTags($string) |
|
197 | - { |
|
198 | - // remove invisible elements |
|
199 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
200 | - // replace certain elements with a line-break |
|
201 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
202 | - // replace other elements with a space |
|
203 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
204 | - // add a placeholder for plain-text bullets to list elements |
|
205 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
206 | - // strip all remaining HTML tags |
|
207 | - $string = wp_strip_all_tags($string); |
|
208 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
209 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
210 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
211 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
212 | - } |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + public $attachments; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + public $email; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $headers; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $message; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $subject; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string|array |
|
39 | + */ |
|
40 | + public $to; |
|
41 | + |
|
42 | + /** |
|
43 | + * @return Email |
|
44 | + */ |
|
45 | + public function compose(array $email) |
|
46 | + { |
|
47 | + $this->normalize($email); |
|
48 | + $this->attachments = $this->email['attachments']; |
|
49 | + $this->headers = $this->buildHeaders(); |
|
50 | + $this->message = $this->buildHtmlMessage(); |
|
51 | + $this->subject = $this->email['subject']; |
|
52 | + $this->to = $this->email['to']; |
|
53 | + add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
54 | + return $this; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $format |
|
59 | + * @return string|null |
|
60 | + */ |
|
61 | + public function read($format = '') |
|
62 | + { |
|
63 | + if ('plaintext' == $format) { |
|
64 | + $message = $this->stripHtmlTags($this->message); |
|
65 | + return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
66 | + } |
|
67 | + return $this->message; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return void|bool |
|
72 | + */ |
|
73 | + public function send() |
|
74 | + { |
|
75 | + if (!$this->message || !$this->subject || !$this->to) { |
|
76 | + return; |
|
77 | + } |
|
78 | + add_action('wp_mail_failed', [$this, 'logMailError']); |
|
79 | + $sent = wp_mail( |
|
80 | + $this->to, |
|
81 | + $this->subject, |
|
82 | + $this->message, |
|
83 | + $this->headers, |
|
84 | + $this->attachments |
|
85 | + ); |
|
86 | + remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
87 | + $this->reset(); |
|
88 | + return $sent; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @action phpmailer_init |
|
94 | + */ |
|
95 | + public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
96 | + { |
|
97 | + if (empty($this->email)) { |
|
98 | + return; |
|
99 | + } |
|
100 | + if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | + $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + protected function buildHeaders() |
|
111 | + { |
|
112 | + $allowed = [ |
|
113 | + 'bcc', 'cc', 'from', 'reply-to', |
|
114 | + ]; |
|
115 | + $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | + $headers = array_filter($headers); |
|
117 | + foreach ($headers as $key => $value) { |
|
118 | + unset($headers[$key]); |
|
119 | + $headers[] = $key.': '.$value; |
|
120 | + } |
|
121 | + $headers[] = 'Content-Type: text/html'; |
|
122 | + return apply_filters('site-reviews/email/headers', $headers, $this); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function buildHtmlMessage() |
|
129 | + { |
|
130 | + $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | + if (!empty($template)) { |
|
132 | + $message = glsr(Template::class)->interpolate( |
|
133 | + $template, |
|
134 | + ['context' => $this->email['template-tags']], |
|
135 | + $this->email['template'] |
|
136 | + ); |
|
137 | + } elseif ($this->email['template']) { |
|
138 | + $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
139 | + 'context' => $this->email['template-tags'], |
|
140 | + ]); |
|
141 | + } |
|
142 | + if (!isset($message)) { |
|
143 | + $message = $this->email['message']; |
|
144 | + } |
|
145 | + $message = $this->email['before'].$message.$this->email['after']; |
|
146 | + $message = strip_shortcodes($message); |
|
147 | + $message = wptexturize($message); |
|
148 | + $message = wpautop($message); |
|
149 | + $message = str_replace('<> ', '', $message); |
|
150 | + $message = str_replace(']]>', ']]>', $message); |
|
151 | + $message = glsr(Template::class)->build('partials/email/index', [ |
|
152 | + 'context' => ['message' => $message], |
|
153 | + ]); |
|
154 | + return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param \WP_Error $error |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + protected function logMailError($error) |
|
162 | + { |
|
163 | + glsr_log()->error('Email was not sent (wp_mail failed)') |
|
164 | + ->debug($this) |
|
165 | + ->debug($error); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + protected function normalize(array $email = []) |
|
172 | + { |
|
173 | + $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
174 | + if (empty($email['reply-to'])) { |
|
175 | + $email['reply-to'] = $email['from']; |
|
176 | + } |
|
177 | + $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + protected function reset() |
|
184 | + { |
|
185 | + $this->attachments = []; |
|
186 | + $this->email = []; |
|
187 | + $this->headers = []; |
|
188 | + $this->message = null; |
|
189 | + $this->subject = null; |
|
190 | + $this->to = null; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + protected function stripHtmlTags($string) |
|
197 | + { |
|
198 | + // remove invisible elements |
|
199 | + $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
200 | + // replace certain elements with a line-break |
|
201 | + $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
202 | + // replace other elements with a space |
|
203 | + $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
204 | + // add a placeholder for plain-text bullets to list elements |
|
205 | + $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
206 | + // strip all remaining HTML tags |
|
207 | + $string = wp_strip_all_tags($string); |
|
208 | + $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
209 | + $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
210 | + $string = str_replace('-o-^-o-', ' - ', $string); |
|
211 | + return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
212 | + } |
|
213 | 213 | } |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return Email |
44 | 44 | */ |
45 | - public function compose(array $email) |
|
45 | + public function compose( array $email ) |
|
46 | 46 | { |
47 | - $this->normalize($email); |
|
47 | + $this->normalize( $email ); |
|
48 | 48 | $this->attachments = $this->email['attachments']; |
49 | 49 | $this->headers = $this->buildHeaders(); |
50 | 50 | $this->message = $this->buildHtmlMessage(); |
51 | 51 | $this->subject = $this->email['subject']; |
52 | 52 | $this->to = $this->email['to']; |
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
53 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | * @param string $format |
59 | 59 | * @return string|null |
60 | 60 | */ |
61 | - public function read($format = '') |
|
61 | + public function read( $format = '' ) |
|
62 | 62 | { |
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
63 | + if( 'plaintext' == $format ) { |
|
64 | + $message = $this->stripHtmlTags( $this->message ); |
|
65 | + return apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
66 | 66 | } |
67 | 67 | return $this->message; |
68 | 68 | } |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function send() |
74 | 74 | { |
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
75 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
78 | + add_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
79 | 79 | $sent = wp_mail( |
80 | 80 | $this->to, |
81 | 81 | $this->subject, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $this->headers, |
84 | 84 | $this->attachments |
85 | 85 | ); |
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
86 | + remove_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
87 | 87 | $this->reset(); |
88 | 88 | return $sent; |
89 | 89 | } |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | * @return void |
93 | 93 | * @action phpmailer_init |
94 | 94 | */ |
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
95 | + public function buildPlainTextMessage( PHPMailer $phpmailer ) |
|
96 | 96 | { |
97 | - if (empty($this->email)) { |
|
97 | + if( empty($this->email) ) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
100 | + if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
103 | + $message = $this->stripHtmlTags( $phpmailer->Body ); |
|
104 | + $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | $allowed = [ |
113 | 113 | 'bcc', 'cc', 'from', 'reply-to', |
114 | 114 | ]; |
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
115 | + $headers = array_intersect_key( $this->email, array_flip( $allowed ) ); |
|
116 | + $headers = array_filter( $headers ); |
|
117 | + foreach( $headers as $key => $value ) { |
|
118 | 118 | unset($headers[$key]); |
119 | 119 | $headers[] = $key.': '.$value; |
120 | 120 | } |
121 | 121 | $headers[] = 'Content-Type: text/html'; |
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
122 | + return apply_filters( 'site-reviews/email/headers', $headers, $this ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,54 +127,54 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildHtmlMessage() |
129 | 129 | { |
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate( |
|
130 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
131 | + if( !empty($template) ) { |
|
132 | + $message = glsr( Template::class )->interpolate( |
|
133 | 133 | $template, |
134 | 134 | ['context' => $this->email['template-tags']], |
135 | 135 | $this->email['template'] |
136 | 136 | ); |
137 | - } elseif ($this->email['template']) { |
|
138 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
137 | + } elseif( $this->email['template'] ) { |
|
138 | + $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [ |
|
139 | 139 | 'context' => $this->email['template-tags'], |
140 | - ]); |
|
140 | + ] ); |
|
141 | 141 | } |
142 | - if (!isset($message)) { |
|
142 | + if( !isset($message) ) { |
|
143 | 143 | $message = $this->email['message']; |
144 | 144 | } |
145 | 145 | $message = $this->email['before'].$message.$this->email['after']; |
146 | - $message = strip_shortcodes($message); |
|
147 | - $message = wptexturize($message); |
|
148 | - $message = wpautop($message); |
|
149 | - $message = str_replace('<> ', '', $message); |
|
150 | - $message = str_replace(']]>', ']]>', $message); |
|
151 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
146 | + $message = strip_shortcodes( $message ); |
|
147 | + $message = wptexturize( $message ); |
|
148 | + $message = wpautop( $message ); |
|
149 | + $message = str_replace( '<> ', '', $message ); |
|
150 | + $message = str_replace( ']]>', ']]>', $message ); |
|
151 | + $message = glsr( Template::class )->build( 'partials/email/index', [ |
|
152 | 152 | 'context' => ['message' => $message], |
153 | - ]); |
|
154 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
153 | + ] ); |
|
154 | + return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * @param \WP_Error $error |
159 | 159 | * @return void |
160 | 160 | */ |
161 | - protected function logMailError($error) |
|
161 | + protected function logMailError( $error ) |
|
162 | 162 | { |
163 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
164 | - ->debug($this) |
|
165 | - ->debug($error); |
|
163 | + glsr_log()->error( 'Email was not sent (wp_mail failed)' ) |
|
164 | + ->debug( $this ) |
|
165 | + ->debug( $error ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - protected function normalize(array $email = []) |
|
171 | + protected function normalize( array $email = [] ) |
|
172 | 172 | { |
173 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
174 | - if (empty($email['reply-to'])) { |
|
173 | + $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email ); |
|
174 | + if( empty($email['reply-to']) ) { |
|
175 | 175 | $email['reply-to'] = $email['from']; |
176 | 176 | } |
177 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
177 | + $this->email = apply_filters( 'site-reviews/email/compose', $email, $this ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -193,21 +193,21 @@ discard block |
||
193 | 193 | /** |
194 | 194 | * @return string |
195 | 195 | */ |
196 | - protected function stripHtmlTags($string) |
|
196 | + protected function stripHtmlTags( $string ) |
|
197 | 197 | { |
198 | 198 | // remove invisible elements |
199 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
199 | + $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string ); |
|
200 | 200 | // replace certain elements with a line-break |
201 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
201 | + $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string ); |
|
202 | 202 | // replace other elements with a space |
203 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
203 | + $string = preg_replace( '@</(td|th)@iu', ' $0', $string ); |
|
204 | 204 | // add a placeholder for plain-text bullets to list elements |
205 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
205 | + $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string ); |
|
206 | 206 | // strip all remaining HTML tags |
207 | - $string = wp_strip_all_tags($string); |
|
208 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
209 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
210 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
211 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
207 | + $string = wp_strip_all_tags( $string ); |
|
208 | + $string = wp_specialchars_decode( $string, ENT_QUOTES ); |
|
209 | + $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); |
|
210 | + $string = str_replace( '-o-^-o-', ' - ', $string ); |
|
211 | + return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); |
|
212 | 212 | } |
213 | 213 | } |
@@ -134,7 +134,8 @@ |
||
134 | 134 | ['context' => $this->email['template-tags']], |
135 | 135 | $this->email['template'] |
136 | 136 | ); |
137 | - } elseif ($this->email['template']) { |
|
137 | + } |
|
138 | + elseif ($this->email['template']) { |
|
138 | 139 | $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
139 | 140 | 'context' => $this->email['template-tags'], |
140 | 141 | ]); |
@@ -4,84 +4,84 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsPopup extends TinymcePopupGenerator |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public function fields() |
|
11 | - { |
|
12 | - return [[ |
|
13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
14 | - 'minWidth' => 320, |
|
15 | - 'type' => 'container', |
|
16 | - ], [ |
|
17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
18 | - 'name' => 'title', |
|
19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
20 | - 'type' => 'textbox', |
|
21 | - ], [ |
|
22 | - 'label' => esc_html__('Display', 'site-reviews'), |
|
23 | - 'maxLength' => 5, |
|
24 | - 'name' => 'display', |
|
25 | - 'size' => 3, |
|
26 | - 'text' => '10', |
|
27 | - 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
28 | - 'type' => 'textbox', |
|
29 | - ], [ |
|
30 | - 'label' => esc_html__('Rating', 'site-reviews'), |
|
31 | - 'name' => 'rating', |
|
32 | - 'options' => [ |
|
33 | - '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
34 | - '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
35 | - '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
36 | - '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
37 | - '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
38 | - '0' => esc_html(__('Unrated', 'site-reviews')), |
|
39 | - ], |
|
40 | - 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
41 | - 'type' => 'listbox', |
|
42 | - ], [ |
|
43 | - 'label' => esc_html__('Pagination', 'site-reviews'), |
|
44 | - 'name' => 'pagination', |
|
45 | - 'options' => [ |
|
46 | - 'true' => esc_html__('Enable', 'site-reviews'), |
|
47 | - 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
48 | - 'false' => esc_html__('Disable', 'site-reviews'), |
|
49 | - ], |
|
50 | - 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
51 | - 'type' => 'listbox', |
|
52 | - ], |
|
53 | - $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
54 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
55 | - [ |
|
56 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
57 | - 'name' => 'assigned_to', |
|
58 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
59 | - 'type' => 'textbox', |
|
60 | - ], [ |
|
61 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
62 | - 'name' => 'schema', |
|
63 | - 'options' => [ |
|
64 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
65 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
66 | - ], |
|
67 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
68 | - 'type' => 'listbox', |
|
69 | - ], [ |
|
70 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
71 | - 'name' => 'class', |
|
72 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
73 | - 'type' => 'textbox', |
|
74 | - ], [ |
|
75 | - 'columns' => 2, |
|
76 | - 'items' => $this->getHideOptions(), |
|
77 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
78 | - 'layout' => 'grid', |
|
79 | - 'spacing' => 5, |
|
80 | - 'type' => 'container', |
|
81 | - ], [ |
|
82 | - 'hidden' => true, |
|
83 | - 'name' => 'id', |
|
84 | - 'type' => 'textbox', |
|
85 | - ], ]; |
|
86 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public function fields() |
|
11 | + { |
|
12 | + return [[ |
|
13 | + 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
14 | + 'minWidth' => 320, |
|
15 | + 'type' => 'container', |
|
16 | + ], [ |
|
17 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
18 | + 'name' => 'title', |
|
19 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
20 | + 'type' => 'textbox', |
|
21 | + ], [ |
|
22 | + 'label' => esc_html__('Display', 'site-reviews'), |
|
23 | + 'maxLength' => 5, |
|
24 | + 'name' => 'display', |
|
25 | + 'size' => 3, |
|
26 | + 'text' => '10', |
|
27 | + 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
28 | + 'type' => 'textbox', |
|
29 | + ], [ |
|
30 | + 'label' => esc_html__('Rating', 'site-reviews'), |
|
31 | + 'name' => 'rating', |
|
32 | + 'options' => [ |
|
33 | + '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
34 | + '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
35 | + '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
36 | + '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
37 | + '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
38 | + '0' => esc_html(__('Unrated', 'site-reviews')), |
|
39 | + ], |
|
40 | + 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
41 | + 'type' => 'listbox', |
|
42 | + ], [ |
|
43 | + 'label' => esc_html__('Pagination', 'site-reviews'), |
|
44 | + 'name' => 'pagination', |
|
45 | + 'options' => [ |
|
46 | + 'true' => esc_html__('Enable', 'site-reviews'), |
|
47 | + 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
48 | + 'false' => esc_html__('Disable', 'site-reviews'), |
|
49 | + ], |
|
50 | + 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
51 | + 'type' => 'listbox', |
|
52 | + ], |
|
53 | + $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
54 | + $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
55 | + [ |
|
56 | + 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
57 | + 'name' => 'assigned_to', |
|
58 | + 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
59 | + 'type' => 'textbox', |
|
60 | + ], [ |
|
61 | + 'label' => esc_html__('Schema', 'site-reviews'), |
|
62 | + 'name' => 'schema', |
|
63 | + 'options' => [ |
|
64 | + 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
65 | + 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
66 | + ], |
|
67 | + 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
68 | + 'type' => 'listbox', |
|
69 | + ], [ |
|
70 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
71 | + 'name' => 'class', |
|
72 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
73 | + 'type' => 'textbox', |
|
74 | + ], [ |
|
75 | + 'columns' => 2, |
|
76 | + 'items' => $this->getHideOptions(), |
|
77 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
78 | + 'layout' => 'grid', |
|
79 | + 'spacing' => 5, |
|
80 | + 'type' => 'container', |
|
81 | + ], [ |
|
82 | + 'hidden' => true, |
|
83 | + 'name' => 'id', |
|
84 | + 'type' => 'textbox', |
|
85 | + ], ]; |
|
86 | + } |
|
87 | 87 | } |
@@ -10,71 +10,71 @@ |
||
10 | 10 | public function fields() |
11 | 11 | { |
12 | 12 | return [[ |
13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
13 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
14 | 14 | 'minWidth' => 320, |
15 | 15 | 'type' => 'container', |
16 | 16 | ], [ |
17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
17 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
18 | 18 | 'name' => 'title', |
19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
19 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
20 | 20 | 'type' => 'textbox', |
21 | 21 | ], [ |
22 | - 'label' => esc_html__('Display', 'site-reviews'), |
|
22 | + 'label' => esc_html__( 'Display', 'site-reviews' ), |
|
23 | 23 | 'maxLength' => 5, |
24 | 24 | 'name' => 'display', |
25 | 25 | 'size' => 3, |
26 | 26 | 'text' => '10', |
27 | - 'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'), |
|
27 | + 'tooltip' => __( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ), |
|
28 | 28 | 'type' => 'textbox', |
29 | 29 | ], [ |
30 | - 'label' => esc_html__('Rating', 'site-reviews'), |
|
30 | + 'label' => esc_html__( 'Rating', 'site-reviews' ), |
|
31 | 31 | 'name' => 'rating', |
32 | 32 | 'options' => [ |
33 | - '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)), |
|
34 | - '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)), |
|
35 | - '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)), |
|
36 | - '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)), |
|
37 | - '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)), |
|
38 | - '0' => esc_html(__('Unrated', 'site-reviews')), |
|
33 | + '5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ) ), |
|
34 | + '4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ) ), |
|
35 | + '3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ) ), |
|
36 | + '2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ) ), |
|
37 | + '1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ) ), |
|
38 | + '0' => esc_html( __( 'Unrated', 'site-reviews' ) ), |
|
39 | 39 | ], |
40 | - 'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'), |
|
40 | + 'tooltip' => __( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ), |
|
41 | 41 | 'type' => 'listbox', |
42 | 42 | ], [ |
43 | - 'label' => esc_html__('Pagination', 'site-reviews'), |
|
43 | + 'label' => esc_html__( 'Pagination', 'site-reviews' ), |
|
44 | 44 | 'name' => 'pagination', |
45 | 45 | 'options' => [ |
46 | - 'true' => esc_html__('Enable', 'site-reviews'), |
|
47 | - 'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'), |
|
48 | - 'false' => esc_html__('Disable', 'site-reviews'), |
|
46 | + 'true' => esc_html__( 'Enable', 'site-reviews' ), |
|
47 | + 'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ), |
|
48 | + 'false' => esc_html__( 'Disable', 'site-reviews' ), |
|
49 | 49 | ], |
50 | - 'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'), |
|
50 | + 'tooltip' => __( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ), |
|
51 | 51 | 'type' => 'listbox', |
52 | 52 | ], |
53 | - $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')), |
|
54 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
53 | + $this->getTypes( __( 'Which type of review would you like to display?', 'site-reviews' ) ), |
|
54 | + $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ), |
|
55 | 55 | [ |
56 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
56 | + 'label' => esc_html__( 'Assigned To', 'site-reviews' ), |
|
57 | 57 | 'name' => 'assigned_to', |
58 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
58 | + 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews' ), |
|
59 | 59 | 'type' => 'textbox', |
60 | 60 | ], [ |
61 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
61 | + 'label' => esc_html__( 'Schema', 'site-reviews' ), |
|
62 | 62 | 'name' => 'schema', |
63 | 63 | 'options' => [ |
64 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
65 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
64 | + 'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ), |
|
65 | + 'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ), |
|
66 | 66 | ], |
67 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
67 | + 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
|
68 | 68 | 'type' => 'listbox', |
69 | 69 | ], [ |
70 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
70 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
71 | 71 | 'name' => 'class', |
72 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
72 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
73 | 73 | 'type' => 'textbox', |
74 | 74 | ], [ |
75 | 75 | 'columns' => 2, |
76 | 76 | 'items' => $this->getHideOptions(), |
77 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
77 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
78 | 78 | 'layout' => 'grid', |
79 | 79 | 'spacing' => 5, |
80 | 80 | 'type' => 'container', |
@@ -8,97 +8,97 @@ |
||
8 | 8 | |
9 | 9 | class WelcomeController extends Controller |
10 | 10 | { |
11 | - /** |
|
12 | - * @return array |
|
13 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
14 | - */ |
|
15 | - public function filterActionLinks(array $links) |
|
16 | - { |
|
17 | - $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
18 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
19 | - ]); |
|
20 | - return $links; |
|
21 | - } |
|
11 | + /** |
|
12 | + * @return array |
|
13 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
14 | + */ |
|
15 | + public function filterActionLinks(array $links) |
|
16 | + { |
|
17 | + $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
18 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
19 | + ]); |
|
20 | + return $links; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - * @filter admin_title |
|
26 | - */ |
|
27 | - public function filterAdminTitle($title) |
|
28 | - { |
|
29 | - return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
|
30 | - ? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
31 | - : $title; |
|
32 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + * @filter admin_title |
|
26 | + */ |
|
27 | + public function filterAdminTitle($title) |
|
28 | + { |
|
29 | + return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
|
30 | + ? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
31 | + : $title; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $text |
|
36 | - * @return string |
|
37 | - * @filter admin_footer_text |
|
38 | - */ |
|
39 | - public function filterFooterText($text) |
|
40 | - { |
|
41 | - if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
42 | - return $text; |
|
43 | - } |
|
44 | - $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
|
45 | - return wp_kses_post(sprintf( |
|
46 | - __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
47 | - '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
|
48 | - '<a href="'.$url.'" target="_blank">wordpress.org</a>' |
|
49 | - )); |
|
50 | - } |
|
34 | + /** |
|
35 | + * @param string $text |
|
36 | + * @return string |
|
37 | + * @filter admin_footer_text |
|
38 | + */ |
|
39 | + public function filterFooterText($text) |
|
40 | + { |
|
41 | + if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
42 | + return $text; |
|
43 | + } |
|
44 | + $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
|
45 | + return wp_kses_post(sprintf( |
|
46 | + __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
47 | + '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
|
48 | + '<a href="'.$url.'" target="_blank">wordpress.org</a>' |
|
49 | + )); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $plugin |
|
54 | - * @param bool $isNetworkActivation |
|
55 | - * @return void |
|
56 | - * @action activated_plugin |
|
57 | - */ |
|
58 | - public function redirectOnActivation($plugin, $isNetworkActivation) |
|
59 | - { |
|
60 | - if (!$isNetworkActivation |
|
61 | - && 'cli' !== php_sapi_name() |
|
62 | - && $plugin === plugin_basename(glsr()->file)) { |
|
63 | - wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
64 | - exit; |
|
65 | - } |
|
66 | - } |
|
52 | + /** |
|
53 | + * @param string $plugin |
|
54 | + * @param bool $isNetworkActivation |
|
55 | + * @return void |
|
56 | + * @action activated_plugin |
|
57 | + */ |
|
58 | + public function redirectOnActivation($plugin, $isNetworkActivation) |
|
59 | + { |
|
60 | + if (!$isNetworkActivation |
|
61 | + && 'cli' !== php_sapi_name() |
|
62 | + && $plugin === plugin_basename(glsr()->file)) { |
|
63 | + wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
64 | + exit; |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - * @action admin_menu |
|
71 | - */ |
|
72 | - public function registerPage() |
|
73 | - { |
|
74 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
75 | - sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
76 | - glsr()->name, |
|
77 | - glsr()->getPermission('welcome'), |
|
78 | - 'welcome', |
|
79 | - [$this, 'renderPage'] |
|
80 | - ); |
|
81 | - remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
82 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + * @action admin_menu |
|
71 | + */ |
|
72 | + public function registerPage() |
|
73 | + { |
|
74 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
75 | + sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
76 | + glsr()->name, |
|
77 | + glsr()->getPermission('welcome'), |
|
78 | + 'welcome', |
|
79 | + [$this, 'renderPage'] |
|
80 | + ); |
|
81 | + remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - * @see $this->registerPage() |
|
87 | - * @callback add_submenu_page |
|
88 | - */ |
|
89 | - public function renderPage() |
|
90 | - { |
|
91 | - $tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
92 | - 'getting-started' => __('Getting Started', 'site-reviews'), |
|
93 | - 'whatsnew' => __('What\'s New', 'site-reviews'), |
|
94 | - 'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
95 | - 'support' => __('Support', 'site-reviews'), |
|
96 | - ]); |
|
97 | - glsr()->render('pages/welcome/index', [ |
|
98 | - 'data' => ['context' => []], |
|
99 | - 'http_referer' => (string) wp_get_referer(), |
|
100 | - 'tabs' => $tabs, |
|
101 | - 'template' => glsr(Template::class), |
|
102 | - ]); |
|
103 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + * @see $this->registerPage() |
|
87 | + * @callback add_submenu_page |
|
88 | + */ |
|
89 | + public function renderPage() |
|
90 | + { |
|
91 | + $tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
92 | + 'getting-started' => __('Getting Started', 'site-reviews'), |
|
93 | + 'whatsnew' => __('What\'s New', 'site-reviews'), |
|
94 | + 'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
95 | + 'support' => __('Support', 'site-reviews'), |
|
96 | + ]); |
|
97 | + glsr()->render('pages/welcome/index', [ |
|
98 | + 'data' => ['context' => []], |
|
99 | + 'http_referer' => (string) wp_get_referer(), |
|
100 | + 'tabs' => $tabs, |
|
101 | + 'template' => glsr(Template::class), |
|
102 | + ]); |
|
103 | + } |
|
104 | 104 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | * @return array |
13 | 13 | * @filter plugin_action_links_site-reviews/site-reviews.php |
14 | 14 | */ |
15 | - public function filterActionLinks(array $links) |
|
15 | + public function filterActionLinks( array $links ) |
|
16 | 16 | { |
17 | - $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
18 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
19 | - ]); |
|
17 | + $links['welcome'] = glsr( Builder::class )->a( __( 'About', 'site-reviews' ), [ |
|
18 | + 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=welcome' ), |
|
19 | + ] ); |
|
20 | 20 | return $links; |
21 | 21 | } |
22 | 22 | |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | * @return string |
25 | 25 | * @filter admin_title |
26 | 26 | */ |
27 | - public function filterAdminTitle($title) |
|
27 | + public function filterAdminTitle( $title ) |
|
28 | 28 | { |
29 | 29 | return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
30 | - ? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
30 | + ? sprintf( __( 'Welcome to %s — WordPress', 'site-reviews' ), glsr()->name ) |
|
31 | 31 | : $title; |
32 | 32 | } |
33 | 33 | |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | * @return string |
37 | 37 | * @filter admin_footer_text |
38 | 38 | */ |
39 | - public function filterFooterText($text) |
|
39 | + public function filterFooterText( $text ) |
|
40 | 40 | { |
41 | - if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
41 | + if( Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id ) { |
|
42 | 42 | return $text; |
43 | 43 | } |
44 | 44 | $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
45 | - return wp_kses_post(sprintf( |
|
46 | - __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
45 | + return wp_kses_post( sprintf( |
|
46 | + __( 'Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews' ), |
|
47 | 47 | '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
48 | 48 | '<a href="'.$url.'" target="_blank">wordpress.org</a>' |
49 | - )); |
|
49 | + ) ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | * @return void |
56 | 56 | * @action activated_plugin |
57 | 57 | */ |
58 | - public function redirectOnActivation($plugin, $isNetworkActivation) |
|
58 | + public function redirectOnActivation( $plugin, $isNetworkActivation ) |
|
59 | 59 | { |
60 | - if (!$isNetworkActivation |
|
60 | + if( !$isNetworkActivation |
|
61 | 61 | && 'cli' !== php_sapi_name() |
62 | - && $plugin === plugin_basename(glsr()->file)) { |
|
63 | - wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
62 | + && $plugin === plugin_basename( glsr()->file ) ) { |
|
63 | + wp_safe_redirect( admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=welcome' ) ); |
|
64 | 64 | exit; |
65 | 65 | } |
66 | 66 | } |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function registerPage() |
73 | 73 | { |
74 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
75 | - sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
74 | + add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, |
|
75 | + sprintf( __( 'Welcome to %s', 'site-reviews' ), glsr()->name ), |
|
76 | 76 | glsr()->name, |
77 | - glsr()->getPermission('welcome'), |
|
77 | + glsr()->getPermission( 'welcome' ), |
|
78 | 78 | 'welcome', |
79 | 79 | [$this, 'renderPage'] |
80 | 80 | ); |
81 | - remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
81 | + remove_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, 'welcome' ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function renderPage() |
90 | 90 | { |
91 | - $tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
92 | - 'getting-started' => __('Getting Started', 'site-reviews'), |
|
93 | - 'whatsnew' => __('What\'s New', 'site-reviews'), |
|
94 | - 'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
95 | - 'support' => __('Support', 'site-reviews'), |
|
96 | - ]); |
|
97 | - glsr()->render('pages/welcome/index', [ |
|
91 | + $tabs = apply_filters( 'site-reviews/addon/welcome/tabs', [ |
|
92 | + 'getting-started' => __( 'Getting Started', 'site-reviews' ), |
|
93 | + 'whatsnew' => __( 'What\'s New', 'site-reviews' ), |
|
94 | + 'upgrade-guide' => __( 'Upgrade Guide', 'site-reviews' ), |
|
95 | + 'support' => __( 'Support', 'site-reviews' ), |
|
96 | + ] ); |
|
97 | + glsr()->render( 'pages/welcome/index', [ |
|
98 | 98 | 'data' => ['context' => []], |
99 | - 'http_referer' => (string) wp_get_referer(), |
|
99 | + 'http_referer' => (string)wp_get_referer(), |
|
100 | 100 | 'tabs' => $tabs, |
101 | - 'template' => glsr(Template::class), |
|
102 | - ]); |
|
101 | + 'template' => glsr( Template::class ), |
|
102 | + ] ); |
|
103 | 103 | } |
104 | 104 | } |
@@ -6,41 +6,41 @@ |
||
6 | 6 | |
7 | 7 | class SiteReviewsDefaults extends Defaults |
8 | 8 | { |
9 | - /** |
|
10 | - * @var array |
|
11 | - */ |
|
12 | - protected $guarded = [ |
|
13 | - 'fallback', |
|
14 | - 'title', |
|
15 | - ]; |
|
9 | + /** |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + protected $guarded = [ |
|
13 | + 'fallback', |
|
14 | + 'title', |
|
15 | + ]; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected $mapped = [ |
|
21 | - 'count' => 'display', // @deprecated since v4.1.0 |
|
22 | - 'per_page' => 'display', |
|
23 | - ]; |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected $mapped = [ |
|
21 | + 'count' => 'display', // @deprecated since v4.1.0 |
|
22 | + 'per_page' => 'display', |
|
23 | + ]; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - protected function defaults() |
|
29 | - { |
|
30 | - return [ |
|
31 | - 'assigned_to' => '', |
|
32 | - 'category' => '', |
|
33 | - 'class' => '', |
|
34 | - 'display' => 5, |
|
35 | - 'fallback' => '', |
|
36 | - 'hide' => [], |
|
37 | - 'id' => '', |
|
38 | - 'offset' => '', |
|
39 | - 'pagination' => false, |
|
40 | - 'rating' => 0, |
|
41 | - 'schema' => false, |
|
42 | - 'title' => '', |
|
43 | - 'type' => 'local', |
|
44 | - ]; |
|
45 | - } |
|
25 | + /** |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + protected function defaults() |
|
29 | + { |
|
30 | + return [ |
|
31 | + 'assigned_to' => '', |
|
32 | + 'category' => '', |
|
33 | + 'class' => '', |
|
34 | + 'display' => 5, |
|
35 | + 'fallback' => '', |
|
36 | + 'hide' => [], |
|
37 | + 'id' => '', |
|
38 | + 'offset' => '', |
|
39 | + 'pagination' => false, |
|
40 | + 'rating' => 0, |
|
41 | + 'schema' => false, |
|
42 | + 'title' => '', |
|
43 | + 'type' => 'local', |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | } |
@@ -6,31 +6,31 @@ |
||
6 | 6 | |
7 | 7 | class ReviewsDefaults extends Defaults |
8 | 8 | { |
9 | - /** |
|
10 | - * @var array |
|
11 | - */ |
|
12 | - protected $mapped = [ |
|
13 | - 'count' => 'per_page', // @deprecated since v4.1.0 |
|
14 | - 'display' => 'per_page', |
|
15 | - ]; |
|
9 | + /** |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + protected $mapped = [ |
|
13 | + 'count' => 'per_page', // @deprecated since v4.1.0 |
|
14 | + 'display' => 'per_page', |
|
15 | + ]; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - protected function defaults() |
|
21 | - { |
|
22 | - return [ |
|
23 | - 'assigned_to' => '', |
|
24 | - 'category' => '', |
|
25 | - 'offset' => '', |
|
26 | - 'order' => 'DESC', |
|
27 | - 'orderby' => 'date', |
|
28 | - 'pagination' => false, |
|
29 | - 'per_page' => 10, |
|
30 | - 'post__in' => [], |
|
31 | - 'post__not_in' => [], |
|
32 | - 'rating' => '', |
|
33 | - 'type' => '', |
|
34 | - ]; |
|
35 | - } |
|
17 | + /** |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + protected function defaults() |
|
21 | + { |
|
22 | + return [ |
|
23 | + 'assigned_to' => '', |
|
24 | + 'category' => '', |
|
25 | + 'offset' => '', |
|
26 | + 'order' => 'DESC', |
|
27 | + 'orderby' => 'date', |
|
28 | + 'pagination' => false, |
|
29 | + 'per_page' => 10, |
|
30 | + 'post__in' => [], |
|
31 | + 'post__not_in' => [], |
|
32 | + 'rating' => '', |
|
33 | + 'type' => '', |
|
34 | + ]; |
|
35 | + } |
|
36 | 36 | } |
@@ -8,137 +8,137 @@ |
||
8 | 8 | |
9 | 9 | abstract class DefaultsAbstract |
10 | 10 | { |
11 | - /** |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected $callable = [ |
|
15 | - 'defaults', 'filter', 'merge', 'restrict', 'unguarded', |
|
16 | - ]; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $guarded = []; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $mapped = []; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $name |
|
30 | - * @return void|array |
|
31 | - */ |
|
32 | - public function __call($name, array $args = []) |
|
33 | - { |
|
34 | - if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
35 | - return; |
|
36 | - } |
|
37 | - $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
38 | - $defaults = call_user_func_array([$this, $name], $args); |
|
39 | - $hookName = (new ReflectionClass($this))->getShortName(); |
|
40 | - $hookName = str_replace('Defaults', '', $hookName); |
|
41 | - $hookName = Str::dashCase($hookName); |
|
42 | - return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - abstract protected function defaults(); |
|
49 | - |
|
50 | - /** |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - protected function filter(array $values = []) |
|
54 | - { |
|
55 | - return $this->normalize($this->merge(array_filter($values)), $values); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - protected function filteredJson(array $values = []) |
|
62 | - { |
|
63 | - $defaults = $this->flattenArray( |
|
64 | - array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
65 | - ); |
|
66 | - $values = $this->flattenArray( |
|
67 | - shortcode_atts($defaults, $values) |
|
68 | - ); |
|
69 | - $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
70 | - return !$this->isEmpty($value); |
|
71 | - }); |
|
72 | - return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - protected function flattenArray(array $values) |
|
79 | - { |
|
80 | - array_walk($values, function (&$value) { |
|
81 | - if (!is_array($value)) { |
|
82 | - return; |
|
83 | - } |
|
84 | - $value = implode(',', $value); |
|
85 | - }); |
|
86 | - return $values; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param mixed $var |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - protected function isEmpty($var) |
|
94 | - { |
|
95 | - return !is_numeric($var) && !is_bool($var) && empty($var); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - protected function mapKeys(array $args) |
|
102 | - { |
|
103 | - foreach ($this->mapped as $old => $new) { |
|
104 | - if (array_key_exists($old, $args)) { |
|
105 | - $args[$new] = $args[$old]; |
|
106 | - unset($args[$old]); |
|
107 | - } |
|
108 | - } |
|
109 | - return $args; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - protected function merge(array $values = []) |
|
116 | - { |
|
117 | - return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - protected function normalize(array $values, array $originalValues) |
|
124 | - { |
|
125 | - $values['json'] = $this->filteredJson($originalValues); |
|
126 | - return $values; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - protected function restrict(array $values = []) |
|
133 | - { |
|
134 | - return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - protected function unguarded() |
|
141 | - { |
|
142 | - return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
143 | - } |
|
11 | + /** |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected $callable = [ |
|
15 | + 'defaults', 'filter', 'merge', 'restrict', 'unguarded', |
|
16 | + ]; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $guarded = []; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $mapped = []; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $name |
|
30 | + * @return void|array |
|
31 | + */ |
|
32 | + public function __call($name, array $args = []) |
|
33 | + { |
|
34 | + if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
35 | + return; |
|
36 | + } |
|
37 | + $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
38 | + $defaults = call_user_func_array([$this, $name], $args); |
|
39 | + $hookName = (new ReflectionClass($this))->getShortName(); |
|
40 | + $hookName = str_replace('Defaults', '', $hookName); |
|
41 | + $hookName = Str::dashCase($hookName); |
|
42 | + return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + abstract protected function defaults(); |
|
49 | + |
|
50 | + /** |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + protected function filter(array $values = []) |
|
54 | + { |
|
55 | + return $this->normalize($this->merge(array_filter($values)), $values); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + protected function filteredJson(array $values = []) |
|
62 | + { |
|
63 | + $defaults = $this->flattenArray( |
|
64 | + array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
65 | + ); |
|
66 | + $values = $this->flattenArray( |
|
67 | + shortcode_atts($defaults, $values) |
|
68 | + ); |
|
69 | + $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
70 | + return !$this->isEmpty($value); |
|
71 | + }); |
|
72 | + return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + protected function flattenArray(array $values) |
|
79 | + { |
|
80 | + array_walk($values, function (&$value) { |
|
81 | + if (!is_array($value)) { |
|
82 | + return; |
|
83 | + } |
|
84 | + $value = implode(',', $value); |
|
85 | + }); |
|
86 | + return $values; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param mixed $var |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + protected function isEmpty($var) |
|
94 | + { |
|
95 | + return !is_numeric($var) && !is_bool($var) && empty($var); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + protected function mapKeys(array $args) |
|
102 | + { |
|
103 | + foreach ($this->mapped as $old => $new) { |
|
104 | + if (array_key_exists($old, $args)) { |
|
105 | + $args[$new] = $args[$old]; |
|
106 | + unset($args[$old]); |
|
107 | + } |
|
108 | + } |
|
109 | + return $args; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + protected function merge(array $values = []) |
|
116 | + { |
|
117 | + return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + protected function normalize(array $values, array $originalValues) |
|
124 | + { |
|
125 | + $values['json'] = $this->filteredJson($originalValues); |
|
126 | + return $values; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + protected function restrict(array $values = []) |
|
133 | + { |
|
134 | + return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + protected function unguarded() |
|
141 | + { |
|
142 | + return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
143 | + } |
|
144 | 144 | } |
@@ -29,17 +29,17 @@ discard block |
||
29 | 29 | * @param string $name |
30 | 30 | * @return void|array |
31 | 31 | */ |
32 | - public function __call($name, array $args = []) |
|
32 | + public function __call( $name, array $args = [] ) |
|
33 | 33 | { |
34 | - if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
34 | + if( !method_exists( $this, $name ) || !in_array( $name, $this->callable ) ) { |
|
35 | 35 | return; |
36 | 36 | } |
37 | - $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
38 | - $defaults = call_user_func_array([$this, $name], $args); |
|
39 | - $hookName = (new ReflectionClass($this))->getShortName(); |
|
40 | - $hookName = str_replace('Defaults', '', $hookName); |
|
41 | - $hookName = Str::dashCase($hookName); |
|
42 | - return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
37 | + $args[0] = $this->mapKeys( Arr::get( $args, 0, [] ) ); |
|
38 | + $defaults = call_user_func_array( [$this, $name], $args ); |
|
39 | + $hookName = (new ReflectionClass( $this ))->getShortName(); |
|
40 | + $hookName = str_replace( 'Defaults', '', $hookName ); |
|
41 | + $hookName = Str::dashCase( $hookName ); |
|
42 | + return apply_filters( 'site-reviews/defaults/'.$hookName, $defaults, $name ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -50,38 +50,38 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @return array |
52 | 52 | */ |
53 | - protected function filter(array $values = []) |
|
53 | + protected function filter( array $values = [] ) |
|
54 | 54 | { |
55 | - return $this->normalize($this->merge(array_filter($values)), $values); |
|
55 | + return $this->normalize( $this->merge( array_filter( $values ) ), $values ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - protected function filteredJson(array $values = []) |
|
61 | + protected function filteredJson( array $values = [] ) |
|
62 | 62 | { |
63 | 63 | $defaults = $this->flattenArray( |
64 | - array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
64 | + array_diff_key( $this->defaults(), array_flip( $this->guarded ) ) |
|
65 | 65 | ); |
66 | 66 | $values = $this->flattenArray( |
67 | - shortcode_atts($defaults, $values) |
|
67 | + shortcode_atts( $defaults, $values ) |
|
68 | 68 | ); |
69 | - $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
70 | - return !$this->isEmpty($value); |
|
69 | + $filtered = array_filter( array_diff_assoc( $values, $defaults ), function( $value ) { |
|
70 | + return !$this->isEmpty( $value ); |
|
71 | 71 | }); |
72 | - return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
72 | + return json_encode( $filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - protected function flattenArray(array $values) |
|
78 | + protected function flattenArray( array $values ) |
|
79 | 79 | { |
80 | - array_walk($values, function (&$value) { |
|
81 | - if (!is_array($value)) { |
|
80 | + array_walk( $values, function( &$value ) { |
|
81 | + if( !is_array( $value ) ) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | - $value = implode(',', $value); |
|
84 | + $value = implode( ',', $value ); |
|
85 | 85 | }); |
86 | 86 | return $values; |
87 | 87 | } |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | * @param mixed $var |
91 | 91 | * @return bool |
92 | 92 | */ |
93 | - protected function isEmpty($var) |
|
93 | + protected function isEmpty( $var ) |
|
94 | 94 | { |
95 | - return !is_numeric($var) && !is_bool($var) && empty($var); |
|
95 | + return !is_numeric( $var ) && !is_bool( $var ) && empty($var); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @return array |
100 | 100 | */ |
101 | - protected function mapKeys(array $args) |
|
101 | + protected function mapKeys( array $args ) |
|
102 | 102 | { |
103 | - foreach ($this->mapped as $old => $new) { |
|
104 | - if (array_key_exists($old, $args)) { |
|
103 | + foreach( $this->mapped as $old => $new ) { |
|
104 | + if( array_key_exists( $old, $args ) ) { |
|
105 | 105 | $args[$new] = $args[$old]; |
106 | 106 | unset($args[$old]); |
107 | 107 | } |
@@ -112,26 +112,26 @@ discard block |
||
112 | 112 | /** |
113 | 113 | * @return array |
114 | 114 | */ |
115 | - protected function merge(array $values = []) |
|
115 | + protected function merge( array $values = [] ) |
|
116 | 116 | { |
117 | - return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
117 | + return $this->normalize( wp_parse_args( $values, $this->defaults() ), $values ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - protected function normalize(array $values, array $originalValues) |
|
123 | + protected function normalize( array $values, array $originalValues ) |
|
124 | 124 | { |
125 | - $values['json'] = $this->filteredJson($originalValues); |
|
125 | + $values['json'] = $this->filteredJson( $originalValues ); |
|
126 | 126 | return $values; |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - protected function restrict(array $values = []) |
|
132 | + protected function restrict( array $values = [] ) |
|
133 | 133 | { |
134 | - return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
134 | + return $this->normalize( shortcode_atts( $this->defaults(), $values ), $values ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,6 +139,6 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function unguarded() |
141 | 141 | { |
142 | - return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
142 | + return array_diff_key( $this->defaults(), array_flip( $this->guarded ) ); |
|
143 | 143 | } |
144 | 144 | } |
@@ -7,106 +7,106 @@ |
||
7 | 7 | |
8 | 8 | class Labels |
9 | 9 | { |
10 | - /** |
|
11 | - * @param string $translation |
|
12 | - * @param string $test |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public function filterPostStatusLabels($translation, $text) |
|
16 | - { |
|
17 | - $replacements = $this->getStatusLabels(); |
|
18 | - return array_key_exists($text, $replacements) |
|
19 | - ? $replacements[$text] |
|
20 | - : $translation; |
|
21 | - } |
|
10 | + /** |
|
11 | + * @param string $translation |
|
12 | + * @param string $test |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public function filterPostStatusLabels($translation, $text) |
|
16 | + { |
|
17 | + $replacements = $this->getStatusLabels(); |
|
18 | + return array_key_exists($text, $replacements) |
|
19 | + ? $replacements[$text] |
|
20 | + : $translation; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function filterUpdateMessages(array $messages) |
|
27 | - { |
|
28 | - $post = get_post(); |
|
29 | - if (!($post instanceof WP_Post)) { |
|
30 | - return; |
|
31 | - } |
|
32 | - $strings = $this->getReviewLabels(); |
|
33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
36 | - } |
|
37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
38 | - $messages[Application::POST_TYPE] = [ |
|
39 | - 1 => $strings['updated'], |
|
40 | - 4 => $strings['updated'], |
|
41 | - 5 => $restored, |
|
42 | - 6 => $strings['published'], |
|
43 | - 7 => $strings['saved'], |
|
44 | - 8 => $strings['submitted'], |
|
45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
46 | - 10 => $strings['draft_updated'], |
|
47 | - 50 => $strings['approved'], |
|
48 | - 51 => $strings['unapproved'], |
|
49 | - 52 => $strings['reverted'], |
|
50 | - ]; |
|
51 | - return $messages; |
|
52 | - } |
|
23 | + /** |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function filterUpdateMessages(array $messages) |
|
27 | + { |
|
28 | + $post = get_post(); |
|
29 | + if (!($post instanceof WP_Post)) { |
|
30 | + return; |
|
31 | + } |
|
32 | + $strings = $this->getReviewLabels(); |
|
33 | + $restored = filter_input(INPUT_GET, 'revision'); |
|
34 | + if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
35 | + $restored = sprintf($strings['restored'], $revisionTitle); |
|
36 | + } |
|
37 | + $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
38 | + $messages[Application::POST_TYPE] = [ |
|
39 | + 1 => $strings['updated'], |
|
40 | + 4 => $strings['updated'], |
|
41 | + 5 => $restored, |
|
42 | + 6 => $strings['published'], |
|
43 | + 7 => $strings['saved'], |
|
44 | + 8 => $strings['submitted'], |
|
45 | + 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
46 | + 10 => $strings['draft_updated'], |
|
47 | + 50 => $strings['approved'], |
|
48 | + 51 => $strings['unapproved'], |
|
49 | + 52 => $strings['reverted'], |
|
50 | + ]; |
|
51 | + return $messages; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function translatePostStatusLabels() |
|
58 | - { |
|
59 | - global $wp_scripts; |
|
60 | - $strings = [ |
|
61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
62 | - 'published' => __('Approved', 'site-reviews'), |
|
63 | - ]; |
|
64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
65 | - $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
66 | - foreach ($strings as $search => $replace) { |
|
67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function translatePostStatusLabels() |
|
58 | + { |
|
59 | + global $wp_scripts; |
|
60 | + $strings = [ |
|
61 | + 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
62 | + 'published' => __('Approved', 'site-reviews'), |
|
63 | + ]; |
|
64 | + if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
65 | + $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
66 | + foreach ($strings as $search => $replace) { |
|
67 | + $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - protected function getReviewLabels() |
|
76 | - { |
|
77 | - return [ |
|
78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
89 | - 'view' => __('View review', 'site-reviews'), |
|
90 | - ]; |
|
91 | - } |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + protected function getReviewLabels() |
|
76 | + { |
|
77 | + return [ |
|
78 | + 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
79 | + 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
80 | + 'preview' => __('Preview review', 'site-reviews'), |
|
81 | + 'published' => __('Review approved and published.', 'site-reviews'), |
|
82 | + 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
83 | + 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
84 | + 'saved' => __('Review saved.', 'site-reviews'), |
|
85 | + 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
86 | + 'submitted' => __('Review submitted.', 'site-reviews'), |
|
87 | + 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
88 | + 'updated' => __('Review updated.', 'site-reviews'), |
|
89 | + 'view' => __('View review', 'site-reviews'), |
|
90 | + ]; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Store the labels to avoid unnecessary loops. |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function getStatusLabels() |
|
98 | - { |
|
99 | - static $labels; |
|
100 | - if (empty($labels)) { |
|
101 | - $labels = [ |
|
102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
106 | - 'Published' => __('Approved', 'site-reviews'), |
|
107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
108 | - ]; |
|
109 | - } |
|
110 | - return $labels; |
|
111 | - } |
|
93 | + /** |
|
94 | + * Store the labels to avoid unnecessary loops. |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function getStatusLabels() |
|
98 | + { |
|
99 | + static $labels; |
|
100 | + if (empty($labels)) { |
|
101 | + $labels = [ |
|
102 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
103 | + 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
104 | + 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
105 | + 'Publish' => __('Approve', 'site-reviews'), |
|
106 | + 'Published' => __('Approved', 'site-reviews'), |
|
107 | + 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
108 | + ]; |
|
109 | + } |
|
110 | + return $labels; |
|
111 | + } |
|
112 | 112 | } |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | * @param string $test |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function filterPostStatusLabels($translation, $text) |
|
15 | + public function filterPostStatusLabels( $translation, $text ) |
|
16 | 16 | { |
17 | 17 | $replacements = $this->getStatusLabels(); |
18 | - return array_key_exists($text, $replacements) |
|
18 | + return array_key_exists( $text, $replacements ) |
|
19 | 19 | ? $replacements[$text] |
20 | 20 | : $translation; |
21 | 21 | } |
@@ -23,18 +23,18 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @return array |
25 | 25 | */ |
26 | - public function filterUpdateMessages(array $messages) |
|
26 | + public function filterUpdateMessages( array $messages ) |
|
27 | 27 | { |
28 | 28 | $post = get_post(); |
29 | - if (!($post instanceof WP_Post)) { |
|
29 | + if( !($post instanceof WP_Post) ) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | $strings = $this->getReviewLabels(); |
33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
33 | + $restored = filter_input( INPUT_GET, 'revision' ); |
|
34 | + if( $revisionTitle = wp_post_revision_title( intval( $restored ), false ) ) { |
|
35 | + $restored = sprintf( $strings['restored'], $revisionTitle ); |
|
36 | 36 | } |
37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
37 | + $scheduled_date = date_i18n( 'M j, Y @ H:i', strtotime( $post->post_date ) ); |
|
38 | 38 | $messages[Application::POST_TYPE] = [ |
39 | 39 | 1 => $strings['updated'], |
40 | 40 | 4 => $strings['updated'], |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | 6 => $strings['published'], |
43 | 43 | 7 => $strings['saved'], |
44 | 44 | 8 => $strings['submitted'], |
45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
45 | + 9 => sprintf( $strings['scheduled'], '<strong>'.$scheduled_date.'</strong>' ), |
|
46 | 46 | 10 => $strings['draft_updated'], |
47 | 47 | 50 => $strings['approved'], |
48 | 48 | 51 => $strings['unapproved'], |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | { |
59 | 59 | global $wp_scripts; |
60 | 60 | $strings = [ |
61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
62 | - 'published' => __('Approved', 'site-reviews'), |
|
61 | + 'savePending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
62 | + 'published' => __( 'Approved', 'site-reviews' ), |
|
63 | 63 | ]; |
64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
64 | + if( isset($wp_scripts->registered['post']->extra['data']) ) { |
|
65 | 65 | $l10n = &$wp_scripts->registered['post']->extra['data']; |
66 | - foreach ($strings as $search => $replace) { |
|
67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
66 | + foreach( $strings as $search => $replace ) { |
|
67 | + $l10n = preg_replace( '/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n ); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | } |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | protected function getReviewLabels() |
76 | 76 | { |
77 | 77 | return [ |
78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
89 | - 'view' => __('View review', 'site-reviews'), |
|
78 | + 'approved' => __( 'Review has been approved and published.', 'site-reviews' ), |
|
79 | + 'draft_updated' => __( 'Review draft updated.', 'site-reviews' ), |
|
80 | + 'preview' => __( 'Preview review', 'site-reviews' ), |
|
81 | + 'published' => __( 'Review approved and published.', 'site-reviews' ), |
|
82 | + 'restored' => __( 'Review restored to revision from %s.', 'site-reviews' ), |
|
83 | + 'reverted' => __( 'Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews' ), |
|
84 | + 'saved' => __( 'Review saved.', 'site-reviews' ), |
|
85 | + 'scheduled' => __( 'Review scheduled for: %s.', 'site-reviews' ), |
|
86 | + 'submitted' => __( 'Review submitted.', 'site-reviews' ), |
|
87 | + 'unapproved' => __( 'Review has been unapproved and is now pending.', 'site-reviews' ), |
|
88 | + 'updated' => __( 'Review updated.', 'site-reviews' ), |
|
89 | + 'view' => __( 'View review', 'site-reviews' ), |
|
90 | 90 | ]; |
91 | 91 | } |
92 | 92 | |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | protected function getStatusLabels() |
98 | 98 | { |
99 | 99 | static $labels; |
100 | - if (empty($labels)) { |
|
100 | + if( empty($labels) ) { |
|
101 | 101 | $labels = [ |
102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
106 | - 'Published' => __('Approved', 'site-reviews'), |
|
107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
102 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
103 | + 'Pending Review' => __( 'Unapproved', 'site-reviews' ), |
|
104 | + 'Privately Published' => __( 'Privately Approved', 'site-reviews' ), |
|
105 | + 'Publish' => __( 'Approve', 'site-reviews' ), |
|
106 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
107 | + 'Save as Pending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
108 | 108 | ]; |
109 | 109 | } |
110 | 110 | return $labels; |