@@ -17,18 +17,18 @@ discard block |
||
17 | 17 | * @return array |
18 | 18 | * @callback register_setting |
19 | 19 | */ |
20 | - public function callbackRegisterSettings($input) |
|
20 | + public function callbackRegisterSettings( $input ) |
|
21 | 21 | { |
22 | - $settings = Arr::consolidateArray($input); |
|
23 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
24 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
25 | - $options = $this->sanitizeGeneral($input, $options); |
|
26 | - $options = $this->sanitizeLicenses($input, $options); |
|
27 | - $options = $this->sanitizeSubmissions($input, $options); |
|
28 | - $options = $this->sanitizeTranslations($input, $options); |
|
29 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
30 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
31 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
22 | + $settings = Arr::consolidateArray( $input ); |
|
23 | + if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) { |
|
24 | + $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input ); |
|
25 | + $options = $this->sanitizeGeneral( $input, $options ); |
|
26 | + $options = $this->sanitizeLicenses( $input, $options ); |
|
27 | + $options = $this->sanitizeSubmissions( $input, $options ); |
|
28 | + $options = $this->sanitizeTranslations( $input, $options ); |
|
29 | + $options = apply_filters( 'site-reviews/settings/callback', $options, $settings ); |
|
30 | + if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
|
31 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
32 | 32 | } |
33 | 33 | return $options; |
34 | 34 | } |
@@ -41,77 +41,77 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function registerSettings() |
43 | 43 | { |
44 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
44 | + register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
45 | 45 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
46 | - ]); |
|
46 | + ] ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - protected function sanitizeGeneral(array $input, array $options) |
|
52 | + protected function sanitizeGeneral( array $input, array $options ) |
|
53 | 53 | { |
54 | 54 | $key = 'settings.general'; |
55 | - $inputForm = Arr::get($input, $key); |
|
56 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
57 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
55 | + $inputForm = Arr::get( $input, $key ); |
|
56 | + if( !$this->hasMultilingualIntegration( Arr::get( $inputForm, 'multilingual' ) ) ) { |
|
57 | + $options = Arr::set( $options, $key.'.multilingual', '' ); |
|
58 | 58 | } |
59 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
60 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
61 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
59 | + if( '' == trim( Arr::get( $inputForm, 'notification_message' ) ) ) { |
|
60 | + $defaultValue = Arr::get( glsr()->defaults, $key.'.notification_message' ); |
|
61 | + $options = Arr::set( $options, $key.'.notification_message', $defaultValue ); |
|
62 | 62 | } |
63 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
64 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
63 | + $defaultValue = Arr::get( $inputForm, 'notifications', [] ); |
|
64 | + $options = Arr::set( $options, $key.'.notifications', $defaultValue ); |
|
65 | 65 | return $options; |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @return array |
70 | 70 | */ |
71 | - protected function sanitizeLicenses(array $input, array $options) |
|
71 | + protected function sanitizeLicenses( array $input, array $options ) |
|
72 | 72 | { |
73 | 73 | $key = 'settings.licenses'; |
74 | - $licenses = Arr::consolidateArray(Arr::get($input, $key)); |
|
75 | - foreach ($licenses as $slug => &$license) { |
|
76 | - $license = $this->verifyLicense($license, $slug); |
|
74 | + $licenses = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
75 | + foreach( $licenses as $slug => &$license ) { |
|
76 | + $license = $this->verifyLicense( $license, $slug ); |
|
77 | 77 | } |
78 | - $options = Arr::set($options, $key, $licenses); |
|
78 | + $options = Arr::set( $options, $key, $licenses ); |
|
79 | 79 | return $options; |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - protected function sanitizeSubmissions(array $input, array $options) |
|
85 | + protected function sanitizeSubmissions( array $input, array $options ) |
|
86 | 86 | { |
87 | 87 | $key = 'settings.submissions'; |
88 | - $inputForm = Arr::get($input, $key); |
|
88 | + $inputForm = Arr::get( $input, $key ); |
|
89 | 89 | $defaultValue = isset($inputForm['required']) |
90 | 90 | ? $inputForm['required'] |
91 | 91 | : []; |
92 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
92 | + $options = Arr::set( $options, $key.'.required', $defaultValue ); |
|
93 | 93 | return $options; |
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - protected function sanitizeTranslations(array $input, array $options) |
|
99 | + protected function sanitizeTranslations( array $input, array $options ) |
|
100 | 100 | { |
101 | 101 | $key = 'settings.strings'; |
102 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
103 | - if (!empty($inputForm)) { |
|
104 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
102 | + $inputForm = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
103 | + if( !empty($inputForm) ) { |
|
104 | + $options = Arr::set( $options, $key, array_values( array_filter( $inputForm ) ) ); |
|
105 | 105 | $allowedTags = [ |
106 | 106 | 'a' => ['class' => [], 'href' => [], 'target' => []], |
107 | 107 | 'span' => ['class' => []], |
108 | 108 | ]; |
109 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
110 | - if (isset($string['s2'])) { |
|
111 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
109 | + array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) { |
|
110 | + if( isset($string['s2']) ) { |
|
111 | + $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
|
112 | 112 | } |
113 | - if (isset($string['p2'])) { |
|
114 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
113 | + if( isset($string['p2']) ) { |
|
114 | + $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
|
115 | 115 | } |
116 | 116 | }); |
117 | 117 | } |
@@ -122,24 +122,24 @@ discard block |
||
122 | 122 | * @param string $integrationSlug |
123 | 123 | * @return bool |
124 | 124 | */ |
125 | - protected function hasMultilingualIntegration($integrationSlug) |
|
125 | + protected function hasMultilingualIntegration( $integrationSlug ) |
|
126 | 126 | { |
127 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
128 | - if (!$integration) { |
|
127 | + $integration = glsr( Multilingual::class )->getIntegration( $integrationSlug ); |
|
128 | + if( !$integration ) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | - if (!$integration->isActive()) { |
|
132 | - glsr(Notice::class)->addError(sprintf( |
|
133 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
131 | + if( !$integration->isActive() ) { |
|
132 | + glsr( Notice::class )->addError( sprintf( |
|
133 | + __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ), |
|
134 | 134 | $integration->pluginName |
135 | - )); |
|
135 | + ) ); |
|
136 | 136 | return false; |
137 | - } elseif (!$integration->isSupported()) { |
|
138 | - glsr(Notice::class)->addError(sprintf( |
|
139 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
137 | + } elseif( !$integration->isSupported() ) { |
|
138 | + glsr( Notice::class )->addError( sprintf( |
|
139 | + __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ), |
|
140 | 140 | $integration->pluginName, |
141 | 141 | $integration->supportedVersion |
142 | - )); |
|
142 | + ) ); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | return true; |
@@ -150,21 +150,21 @@ discard block |
||
150 | 150 | * @param string $slug |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - protected function verifyLicense($license, $slug) |
|
153 | + protected function verifyLicense( $license, $slug ) |
|
154 | 154 | { |
155 | 155 | try { |
156 | - $addon = glsr($slug); |
|
157 | - $updater = new Updater($addon->update_url, $addon->file, [ |
|
156 | + $addon = glsr( $slug ); |
|
157 | + $updater = new Updater( $addon->update_url, $addon->file, [ |
|
158 | 158 | 'license' => $license, |
159 | 159 | 'testedTo' => $addon->testedTo, |
160 | - ]); |
|
161 | - if (!$updater->isLicenseValid()) { |
|
162 | - throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
160 | + ] ); |
|
161 | + if( !$updater->isLicenseValid() ) { |
|
162 | + throw new Exception( 'Invalid license: '.$license.' ('.$addon->id.')' ); |
|
163 | 163 | } |
164 | - } catch (Exception $e) { |
|
164 | + } catch( Exception $e ) { |
|
165 | 165 | $license = ''; |
166 | - glsr_log()->debug($e->getMessage()); |
|
167 | - glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
166 | + glsr_log()->debug( $e->getMessage() ); |
|
167 | + glsr( Notice::class )->addError( __( 'A license you entered was invalid.', 'site-reviews' ) ); |
|
168 | 168 | } |
169 | 169 | return $license; |
170 | 170 | } |
@@ -24,12 +24,12 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public $reviews; |
26 | 26 | |
27 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
27 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
28 | 28 | { |
29 | 29 | $this->args = $args; |
30 | 30 | $this->max_num_pages = $maxPageCount; |
31 | 31 | $this->reviews = $reviews; |
32 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
32 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __toString() |
39 | 39 | { |
40 | - return (string) $this->build(); |
|
40 | + return (string)$this->build(); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,20 +45,20 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function build() |
47 | 47 | { |
48 | - $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
49 | - return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
48 | + $args = glsr( SiteReviewsDefaults::class )->merge( $this->args ); |
|
49 | + return glsr( SiteReviewsPartial::class )->build( $args, $this ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param mixed $key |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function offsetGet($key) |
|
56 | + public function offsetGet( $key ) |
|
57 | 57 | { |
58 | - if (array_key_exists($key, $this->reviews)) { |
|
58 | + if( array_key_exists( $key, $this->reviews ) ) { |
|
59 | 59 | return $this->reviews[$key]; |
60 | 60 | } |
61 | - return property_exists($this, $key) |
|
61 | + return property_exists( $this, $key ) |
|
62 | 62 | ? $this->$key |
63 | 63 | : null; |
64 | 64 | } |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | * @param string $templatePath |
12 | 12 | * @return void|string |
13 | 13 | */ |
14 | - public function build($templatePath, array $data = []) |
|
14 | + public function build( $templatePath, array $data = [] ) |
|
15 | 15 | { |
16 | - $data = $this->normalize($data); |
|
17 | - $path = Str::removePrefix('templates/', $templatePath); |
|
18 | - $template = glsr()->build($templatePath, $data); |
|
19 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
20 | - $template = $this->interpolate($template, $data, $path); |
|
21 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
22 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
16 | + $data = $this->normalize( $data ); |
|
17 | + $path = Str::removePrefix( 'templates/', $templatePath ); |
|
18 | + $template = glsr()->build( $templatePath, $data ); |
|
19 | + $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data ); |
|
20 | + $template = $this->interpolate( $template, $data, $path ); |
|
21 | + $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data ); |
|
22 | + $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data ); |
|
23 | 23 | return $template; |
24 | 24 | } |
25 | 25 | |
@@ -29,37 +29,37 @@ discard block |
||
29 | 29 | * @param string $templatePath |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function interpolate($template, array $data = [], $templatePath) |
|
32 | + public function interpolate( $template, array $data = [], $templatePath ) |
|
33 | 33 | { |
34 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
35 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
36 | - foreach ($context as $key => $value) { |
|
34 | + $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) ); |
|
35 | + $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data ); |
|
36 | + foreach( $context as $key => $value ) { |
|
37 | 37 | $template = strtr( |
38 | 38 | $template, |
39 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
39 | + array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value ) |
|
40 | 40 | ); |
41 | 41 | } |
42 | - return trim($template); |
|
42 | + return trim( $template ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @param string $templatePath |
47 | 47 | * @return void|string |
48 | 48 | */ |
49 | - public function render($templatePath, array $data = []) |
|
49 | + public function render( $templatePath, array $data = [] ) |
|
50 | 50 | { |
51 | - echo $this->build($templatePath, $data); |
|
51 | + echo $this->build( $templatePath, $data ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function normalize(array $data) |
|
57 | + protected function normalize( array $data ) |
|
58 | 58 | { |
59 | 59 | $arrayKeys = ['context', 'globals']; |
60 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
61 | - foreach ($arrayKeys as $key) { |
|
62 | - if (is_array($data[$key])) { |
|
60 | + $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) ); |
|
61 | + foreach( $arrayKeys as $key ) { |
|
62 | + if( is_array( $data[$key] ) ) { |
|
63 | 63 | continue; |
64 | 64 | } |
65 | 65 | $data[$key] = []; |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - protected function normalizeContext(array $context) |
|
73 | + protected function normalizeContext( array $context ) |
|
74 | 74 | { |
75 | - $context = array_filter($context, function ($value) { |
|
76 | - return !is_array($value) && !is_object($value); |
|
75 | + $context = array_filter( $context, function( $value ) { |
|
76 | + return !is_array( $value ) && !is_object( $value ); |
|
77 | 77 | }); |
78 | - return array_map(function ($value) { |
|
79 | - return (string) $value; |
|
80 | - }, $context); |
|
78 | + return array_map( function( $value ) { |
|
79 | + return (string)$value; |
|
80 | + }, $context ); |
|
81 | 81 | } |
82 | 82 | } |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public function build(array $args = []) |
|
21 | + public function build( array $args = [] ) |
|
22 | 22 | { |
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
23 | + $this->args = $this->normalize( $args ); |
|
24 | + if( $this->args['total'] < 2 ) { |
|
25 | 25 | return ''; |
26 | 26 | } |
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
27 | + return glsr( Template::class )->build( 'templates/pagination', [ |
|
28 | 28 | 'context' => [ |
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
29 | + 'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ), |
|
30 | 30 | 'loader' => '<div class="glsr-loader"></div>', |
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
31 | + 'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ), |
|
32 | 32 | ], |
33 | - ]); |
|
33 | + ] ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,24 +38,24 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function buildLinks() |
40 | 40 | { |
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if ('array' == $args['type']) { |
|
41 | + $args = glsr( Style::class )->paginationArgs( $this->args ); |
|
42 | + if( 'array' == $args['type'] ) { |
|
43 | 43 | $args['type'] = 'plain'; |
44 | 44 | } |
45 | - return paginate_links($args); |
|
45 | + return paginate_links( $args ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @return array |
50 | 50 | */ |
51 | - protected function normalize(array $args) |
|
51 | + protected function normalize( array $args ) |
|
52 | 52 | { |
53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
53 | + if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) { |
|
54 | 54 | $args['base'] = $baseUrl.'%_%'; |
55 | 55 | } |
56 | - return wp_parse_args(array_filter($args), [ |
|
57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
56 | + return wp_parse_args( array_filter( $args ), [ |
|
57 | + 'current' => glsr( QueryBuilder::class )->getPaged(), |
|
58 | 58 | 'total' => 1, |
59 | - ]); |
|
59 | + ] ); |
|
60 | 60 | } |
61 | 61 | } |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public $values; |
19 | 19 | |
20 | - public function __construct(Review $review, array $values = []) |
|
20 | + public function __construct( Review $review, array $values = [] ) |
|
21 | 21 | { |
22 | 22 | $this->review = $review; |
23 | 23 | $this->values = $values; |
24 | - parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
24 | + parent::__construct( $values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,25 +29,25 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function __toString() |
31 | 31 | { |
32 | - if (empty($this->values)) { |
|
32 | + if( empty($this->values) ) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | - return glsr(Template::class)->build('templates/review', [ |
|
35 | + return glsr( Template::class )->build( 'templates/review', [ |
|
36 | 36 | 'context' => $this->values, |
37 | 37 | 'review' => $this->review, |
38 | - ]); |
|
38 | + ] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @param mixed $key |
43 | 43 | * @return mixed |
44 | 44 | */ |
45 | - public function offsetGet($key) |
|
45 | + public function offsetGet( $key ) |
|
46 | 46 | { |
47 | - if (array_key_exists($key, $this->values)) { |
|
47 | + if( array_key_exists( $key, $this->values ) ) { |
|
48 | 48 | return $this->values[$key]; |
49 | 49 | } |
50 | - return property_exists($this, $key) |
|
50 | + return property_exists( $this, $key ) |
|
51 | 51 | ? $this->$key |
52 | 52 | : null; |
53 | 53 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public $reviews; |
30 | 30 | |
31 | - public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
31 | + public function __construct( array $renderedReviews, $maxPageCount, array $args ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | 34 | $this->max_num_pages = $maxPageCount; |
35 | 35 | $this->reviews = $renderedReviews; |
36 | 36 | $this->pagination = $this->buildPagination(); |
37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + parent::__construct( $renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __toString() |
44 | 44 | { |
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
46 | 46 | 'args' => $this->args, |
47 | 47 | 'context' => [ |
48 | 48 | 'assigned_to' => $this->args['assigned_to'], |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'pagination' => $this->getPagination(), |
53 | 53 | 'reviews' => $this->getReviews(), |
54 | 54 | ], |
55 | - ]); |
|
55 | + ] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getPagination() |
62 | 62 | { |
63 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
64 | 64 | ? $this->pagination |
65 | 65 | : ''; |
66 | 66 | } |
@@ -72,26 +72,26 @@ discard block |
||
72 | 72 | { |
73 | 73 | $html = empty($this->reviews) |
74 | 74 | ? $this->getReviewsFallback() |
75 | - : implode(PHP_EOL, $this->reviews); |
|
75 | + : implode( PHP_EOL, $this->reviews ); |
|
76 | 76 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
77 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
78 | + return sprintf( $wrapper, $html ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - public function offsetGet($key) |
|
85 | + public function offsetGet( $key ) |
|
86 | 86 | { |
87 | - if ('navigation' == $key) { |
|
87 | + if( 'navigation' == $key ) { |
|
88 | 88 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
89 | 89 | return $this->pagination; |
90 | 90 | } |
91 | - if (array_key_exists($key, $this->reviews)) { |
|
91 | + if( array_key_exists( $key, $this->reviews ) ) { |
|
92 | 92 | return $this->reviews[$key]; |
93 | 93 | } |
94 | - return property_exists($this, $key) |
|
94 | + return property_exists( $this, $key ) |
|
95 | 95 | ? $this->$key |
96 | 96 | : null; |
97 | 97 | } |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function buildPagination() |
103 | 103 | { |
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
104 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
105 | + 'baseUrl' => Arr::get( $this->args, 'pagedUrl' ), |
|
106 | + 'current' => Arr::get( $this->args, 'paged' ), |
|
107 | 107 | 'total' => $this->max_num_pages, |
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
108 | + ] ); |
|
109 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
110 | 110 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
111 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
112 | + return sprintf( $wrapper, $html ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | $defaults = [ |
121 | 121 | 'glsr-default', |
122 | 122 | ]; |
123 | - if ('ajax' == $this->args['pagination']) { |
|
123 | + if( 'ajax' == $this->args['pagination'] ) { |
|
124 | 124 | $defaults[] = 'glsr-ajax-pagination'; |
125 | 125 | } |
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
126 | + $classes = explode( ' ', $this->args['class'] ); |
|
127 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
128 | + return implode( ' ', $classes ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getReviewsFallback() |
135 | 135 | { |
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
136 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
137 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
138 | 138 | } |
139 | 139 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
141 | 141 | } |
142 | 142 | } |
@@ -7,5 +7,5 @@ |
||
7 | 7 | /** |
8 | 8 | * @return string |
9 | 9 | */ |
10 | - public function build(array $args = []); |
|
10 | + public function build( array $args = [] ); |
|
11 | 11 | } |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function build(array $args = []) |
|
17 | + public function build( array $args = [] ) |
|
18 | 18 | { |
19 | - $this->setProperties($args); |
|
20 | - $fullStars = intval(floor($this->rating)); |
|
21 | - $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | - $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | - return glsr(Template::class)->build('templates/rating/stars', [ |
|
19 | + $this->setProperties( $args ); |
|
20 | + $fullStars = intval( floor( $this->rating ) ); |
|
21 | + $halfStars = intval( ceil( $this->rating - $fullStars ) ); |
|
22 | + $emptyStars = max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $fullStars - $halfStars ); |
|
23 | + return glsr( Template::class )->build( 'templates/rating/stars', [ |
|
24 | 24 | 'context' => [ |
25 | - 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | - 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | - 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
25 | + 'empty_stars' => $this->getTemplate( 'empty-star', $emptyStars ), |
|
26 | + 'full_stars' => $this->getTemplate( 'full-star', $fullStars ), |
|
27 | + 'half_stars' => $this->getTemplate( 'half-star', $halfStars ), |
|
28 | 28 | 'prefix' => $this->prefix, |
29 | - 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
29 | + 'title' => sprintf( __( '%s rating', 'site-reviews' ), number_format_i18n( $this->rating, 1 ) ), |
|
30 | 30 | ], |
31 | - ]); |
|
31 | + ] ); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -36,26 +36,26 @@ discard block |
||
36 | 36 | * @param int $timesRepeated |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - protected function getTemplate($templateName, $timesRepeated) |
|
39 | + protected function getTemplate( $templateName, $timesRepeated ) |
|
40 | 40 | { |
41 | - $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
41 | + $template = glsr( Template::class )->build( 'templates/rating/'.$templateName, [ |
|
42 | 42 | 'context' => [ |
43 | 43 | 'prefix' => $this->prefix, |
44 | 44 | ], |
45 | - ]); |
|
46 | - return str_repeat($template, $timesRepeated); |
|
45 | + ] ); |
|
46 | + return str_repeat( $template, $timesRepeated ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - protected function setProperties(array $args) |
|
52 | + protected function setProperties( array $args ) |
|
53 | 53 | { |
54 | - $args = wp_parse_args($args, [ |
|
54 | + $args = wp_parse_args( $args, [ |
|
55 | 55 | 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
56 | 56 | 'rating' => 0, |
57 | - ]); |
|
57 | + ] ); |
|
58 | 58 | $this->prefix = $args['prefix']; |
59 | - $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
59 | + $this->rating = (float)str_replace( ',', '.', $args['rating'] ); |
|
60 | 60 | } |
61 | 61 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Check for minimum system requirments on plugin activation. |
@@ -24,17 +24,17 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @param string $file |
26 | 26 | */ |
27 | - public function __construct($file) |
|
27 | + public function __construct( $file ) |
|
28 | 28 | { |
29 | - $this->file = realpath($file); |
|
30 | - $versionRequirements = get_file_data($this->file, [ |
|
29 | + $this->file = realpath( $file ); |
|
30 | + $versionRequirements = get_file_data( $this->file, [ |
|
31 | 31 | 'php' => 'Requires PHP', |
32 | 32 | 'wordpress' => 'Requires at least', |
33 | - ]); |
|
34 | - $this->versions = wp_parse_args(array_filter($versionRequirements), [ |
|
33 | + ] ); |
|
34 | + $this->versions = wp_parse_args( array_filter( $versionRequirements ), [ |
|
35 | 35 | 'php' => static::MIN_PHP_VERSION, |
36 | 36 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
37 | - ]); |
|
37 | + ] ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function canProceed() |
44 | 44 | { |
45 | - if ($this->isValid()) { |
|
45 | + if( $this->isValid() ) { |
|
46 | 46 | return true; |
47 | 47 | } |
48 | - add_action('activated_plugin', [$this, 'deactivate']); |
|
49 | - add_action('admin_notices', [$this, 'deactivate']); |
|
48 | + add_action( 'activated_plugin', [$this, 'deactivate'] ); |
|
49 | + add_action( 'admin_notices', [$this, 'deactivate'] ); |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function isPhpValid() |
57 | 57 | { |
58 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
58 | + return !version_compare( PHP_VERSION, $this->versions['php'], '<' ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -72,25 +72,25 @@ discard block |
||
72 | 72 | public function isWpValid() |
73 | 73 | { |
74 | 74 | global $wp_version; |
75 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
75 | + return !version_compare( $wp_version, $this->versions['wordpress'], '<' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $plugin |
80 | 80 | * @return void |
81 | 81 | */ |
82 | - public function deactivate($plugin) |
|
82 | + public function deactivate( $plugin ) |
|
83 | 83 | { |
84 | - if ($this->isValid()) { |
|
84 | + if( $this->isValid() ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - $pluginSlug = plugin_basename($this->file); |
|
88 | - if ($plugin == $pluginSlug) { |
|
87 | + $pluginSlug = plugin_basename( $this->file ); |
|
88 | + if( $plugin == $pluginSlug ) { |
|
89 | 89 | $this->redirect(); //exit |
90 | 90 | } |
91 | - $pluginData = get_file_data($this->file, ['name' => 'Plugin Name'], 'plugin'); |
|
92 | - deactivate_plugins($pluginSlug); |
|
93 | - $this->printNotice($pluginData['name']); |
|
91 | + $pluginData = get_file_data( $this->file, ['name' => 'Plugin Name'], 'plugin' ); |
|
92 | + deactivate_plugins( $pluginSlug ); |
|
93 | + $this->printNotice( $pluginData['name'] ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | protected function getMessages() |
100 | 100 | { |
101 | 101 | return [ |
102 | - 'notice' => __('The %s plugin was deactivated.', 'site-reviews'), |
|
103 | - 'php_version' => __('PHP version', 'site-reviews'), |
|
104 | - 'rollback' => __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | - 'update_php' => __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
106 | - 'update_wp' => __('Update WordPress', 'site-reviews'), |
|
107 | - 'wp_version' => __('WordPress version', 'site-reviews'), |
|
108 | - 'wrong_version' => __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
102 | + 'notice' => __( 'The %s plugin was deactivated.', 'site-reviews' ), |
|
103 | + 'php_version' => __( 'PHP version', 'site-reviews' ), |
|
104 | + 'rollback' => __( 'You can use the %s plugin to restore %s to the previous version.', 'site-reviews' ), |
|
105 | + 'update_php' => __( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews' ), |
|
106 | + 'update_wp' => __( 'Update WordPress', 'site-reviews' ), |
|
107 | + 'wp_version' => __( 'WordPress version', 'site-reviews' ), |
|
108 | + 'wrong_version' => __( 'This plugin requires %s or greater in order to work properly.', 'site-reviews' ), |
|
109 | 109 | ]; |
110 | 110 | } |
111 | 111 | |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | * @param string $pluginName |
114 | 114 | * @return void |
115 | 115 | */ |
116 | - protected function printNotice($pluginName) |
|
116 | + protected function printNotice( $pluginName ) |
|
117 | 117 | { |
118 | 118 | $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
119 | 119 | $messages = $this->getMessages(); |
120 | - $rollbackMessage = sprintf('<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
121 | - if (!$this->isPhpValid()) { |
|
122 | - printf($noticeTemplate, |
|
123 | - sprintf($messages['notice'], $pluginName), |
|
124 | - sprintf($messages['wrong_version'], $messages['php_version'].' '.$this->versions['php']), |
|
125 | - sprintf($messages['update_php'], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
120 | + $rollbackMessage = sprintf( '<strong>'.$messages['rollback'].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName ); |
|
121 | + if( !$this->isPhpValid() ) { |
|
122 | + printf( $noticeTemplate, |
|
123 | + sprintf( $messages['notice'], $pluginName ), |
|
124 | + sprintf( $messages['wrong_version'], $messages['php_version'].' '.$this->versions['php'] ), |
|
125 | + sprintf( $messages['update_php'], PHP_VERSION ).'</p><p>'.$rollbackMessage |
|
126 | 126 | ); |
127 | - } elseif (!$this->isWpValid()) { |
|
128 | - printf($noticeTemplate, |
|
129 | - sprintf($messages['notice'], $pluginName), |
|
130 | - sprintf($messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress']), |
|
131 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages['update_wp']) |
|
127 | + } elseif( !$this->isWpValid() ) { |
|
128 | + printf( $noticeTemplate, |
|
129 | + sprintf( $messages['notice'], $pluginName ), |
|
130 | + sprintf( $messages['wrong_version'], $messages['wp_version'].' '.$this->versions['wordpress'] ), |
|
131 | + $rollbackMessage.'</p><p>'.sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages['update_wp'] ) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | } |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function redirect() |
140 | 140 | { |
141 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | - filter_input(INPUT_GET, 'plugin_status'), |
|
143 | - filter_input(INPUT_GET, 'paged'), |
|
144 | - filter_input(INPUT_GET, 's') |
|
145 | - ))); |
|
141 | + wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
142 | + filter_input( INPUT_GET, 'plugin_status' ), |
|
143 | + filter_input( INPUT_GET, 'paged' ), |
|
144 | + filter_input( INPUT_GET, 's' ) |
|
145 | + ) ) ); |
|
146 | 146 | exit; |
147 | 147 | } |
148 | 148 | } |