@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p class="glsr-field {{ class }}"> |
4 | 4 | {{ label }} |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <table class="form-table"> |
4 | 4 | <tbody> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <table class="form-table"> |
4 | 4 | <tbody> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <table class="form-table"> |
4 | 4 | <tbody> |
@@ -8,137 +8,137 @@ |
||
8 | 8 | */ |
9 | 9 | class GL_Plugin_Check_v3 |
10 | 10 | { |
11 | - const MIN_PHP_VERSION = '5.6.0'; |
|
12 | - const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
11 | + const MIN_PHP_VERSION = '5.6.0'; |
|
12 | + const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $file; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $file; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $versions; |
|
19 | + /** |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $versions; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param string $file |
|
26 | - */ |
|
27 | - public function __construct($file, array $versions = array()) |
|
28 | - { |
|
29 | - $this->file = realpath($file); |
|
30 | - $this->versions = wp_parse_args($versions, array( |
|
31 | - 'php' => static::MIN_PHP_VERSION, |
|
32 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
33 | - )); |
|
34 | - } |
|
24 | + /** |
|
25 | + * @param string $file |
|
26 | + */ |
|
27 | + public function __construct($file, array $versions = array()) |
|
28 | + { |
|
29 | + $this->file = realpath($file); |
|
30 | + $this->versions = wp_parse_args($versions, array( |
|
31 | + 'php' => static::MIN_PHP_VERSION, |
|
32 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
33 | + )); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function canProceed() |
|
40 | - { |
|
41 | - if ($this->isValid()) { |
|
42 | - return true; |
|
43 | - } |
|
44 | - add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | - add_action('admin_notices', array($this, 'deactivate')); |
|
46 | - return false; |
|
47 | - } |
|
36 | + /** |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function canProceed() |
|
40 | + { |
|
41 | + if ($this->isValid()) { |
|
42 | + return true; |
|
43 | + } |
|
44 | + add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | + add_action('admin_notices', array($this, 'deactivate')); |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function isPhpValid() |
|
53 | - { |
|
54 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function isPhpValid() |
|
53 | + { |
|
54 | + return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function isValid() |
|
61 | - { |
|
62 | - return $this->isPhpValid() && $this->isWpValid(); |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function isValid() |
|
61 | + { |
|
62 | + return $this->isPhpValid() && $this->isWpValid(); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function isWpValid() |
|
69 | - { |
|
70 | - global $wp_version; |
|
71 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
72 | - } |
|
65 | + /** |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function isWpValid() |
|
69 | + { |
|
70 | + global $wp_version; |
|
71 | + return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $plugin |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function deactivate($plugin) |
|
79 | - { |
|
80 | - if ($this->isValid()) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $pluginSlug = plugin_basename($this->file); |
|
84 | - if ($plugin == $pluginSlug) { |
|
85 | - $this->redirect(); //exit |
|
86 | - } |
|
87 | - $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | - deactivate_plugins($pluginSlug); |
|
89 | - $this->printNotice($pluginData['name']); |
|
90 | - } |
|
74 | + /** |
|
75 | + * @param string $plugin |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function deactivate($plugin) |
|
79 | + { |
|
80 | + if ($this->isValid()) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $pluginSlug = plugin_basename($this->file); |
|
84 | + if ($plugin == $pluginSlug) { |
|
85 | + $this->redirect(); //exit |
|
86 | + } |
|
87 | + $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | + deactivate_plugins($pluginSlug); |
|
89 | + $this->printNotice($pluginData['name']); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getMessages() |
|
96 | - { |
|
97 | - return array( |
|
98 | - __('The %s plugin was deactivated.', 'site-reviews'), |
|
99 | - __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
100 | - __('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'), |
|
101 | - __('PHP version', 'site-reviews'), |
|
102 | - __('WordPress version', 'site-reviews'), |
|
103 | - __('Update WordPress', 'site-reviews'), |
|
104 | - __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | - ); |
|
106 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getMessages() |
|
96 | + { |
|
97 | + return array( |
|
98 | + __('The %s plugin was deactivated.', 'site-reviews'), |
|
99 | + __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
100 | + __('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'), |
|
101 | + __('PHP version', 'site-reviews'), |
|
102 | + __('WordPress version', 'site-reviews'), |
|
103 | + __('Update WordPress', 'site-reviews'), |
|
104 | + __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @param string $pluginName |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - protected function printNotice($pluginName) |
|
113 | - { |
|
114 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
115 | - $messages = $this->getMessages(); |
|
116 | - $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | - if (!$this->isPhpValid()) { |
|
118 | - printf($noticeTemplate, |
|
119 | - sprintf($messages[0], $pluginName), |
|
120 | - sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | - sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
122 | - ); |
|
123 | - } elseif (!$this->isWpValid()) { |
|
124 | - printf($noticeTemplate, |
|
125 | - sprintf($messages[0], $pluginName), |
|
126 | - sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
128 | - ); |
|
129 | - } |
|
130 | - } |
|
108 | + /** |
|
109 | + * @param string $pluginName |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + protected function printNotice($pluginName) |
|
113 | + { |
|
114 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
115 | + $messages = $this->getMessages(); |
|
116 | + $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | + if (!$this->isPhpValid()) { |
|
118 | + printf($noticeTemplate, |
|
119 | + sprintf($messages[0], $pluginName), |
|
120 | + sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | + sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
122 | + ); |
|
123 | + } elseif (!$this->isWpValid()) { |
|
124 | + printf($noticeTemplate, |
|
125 | + sprintf($messages[0], $pluginName), |
|
126 | + sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
128 | + ); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function redirect() |
|
136 | - { |
|
137 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | - filter_input(INPUT_GET, 'plugin_status'), |
|
139 | - filter_input(INPUT_GET, 'paged'), |
|
140 | - filter_input(INPUT_GET, 's') |
|
141 | - ))); |
|
142 | - exit; |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function redirect() |
|
136 | + { |
|
137 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | + filter_input(INPUT_GET, 'plugin_status'), |
|
139 | + filter_input(INPUT_GET, 'paged'), |
|
140 | + filter_input(INPUT_GET, 's') |
|
141 | + ))); |
|
142 | + exit; |
|
143 | + } |
|
144 | 144 | } |
@@ -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,13 +24,13 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @param string $file |
26 | 26 | */ |
27 | - public function __construct($file, array $versions = array()) |
|
27 | + public function __construct( $file, array $versions = array() ) |
|
28 | 28 | { |
29 | - $this->file = realpath($file); |
|
30 | - $this->versions = wp_parse_args($versions, array( |
|
29 | + $this->file = realpath( $file ); |
|
30 | + $this->versions = wp_parse_args( $versions, array( |
|
31 | 31 | 'php' => static::MIN_PHP_VERSION, |
32 | 32 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
33 | - )); |
|
33 | + ) ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function canProceed() |
40 | 40 | { |
41 | - if ($this->isValid()) { |
|
41 | + if( $this->isValid() ) { |
|
42 | 42 | return true; |
43 | 43 | } |
44 | - add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | - add_action('admin_notices', array($this, 'deactivate')); |
|
44 | + add_action( 'activated_plugin', array( $this, 'deactivate' ) ); |
|
45 | + add_action( 'admin_notices', array( $this, 'deactivate' ) ); |
|
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function isPhpValid() |
53 | 53 | { |
54 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
54 | + return !version_compare( PHP_VERSION, $this->versions['php'], '<' ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -68,25 +68,25 @@ discard block |
||
68 | 68 | public function isWpValid() |
69 | 69 | { |
70 | 70 | global $wp_version; |
71 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
71 | + return !version_compare( $wp_version, $this->versions['wordpress'], '<' ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @param string $plugin |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public function deactivate($plugin) |
|
78 | + public function deactivate( $plugin ) |
|
79 | 79 | { |
80 | - if ($this->isValid()) { |
|
80 | + if( $this->isValid() ) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | - $pluginSlug = plugin_basename($this->file); |
|
84 | - if ($plugin == $pluginSlug) { |
|
83 | + $pluginSlug = plugin_basename( $this->file ); |
|
84 | + if( $plugin == $pluginSlug ) { |
|
85 | 85 | $this->redirect(); //exit |
86 | 86 | } |
87 | - $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | - deactivate_plugins($pluginSlug); |
|
89 | - $this->printNotice($pluginData['name']); |
|
87 | + $pluginData = get_file_data( $this->file, array( 'name' => 'Plugin Name' ), 'plugin' ); |
|
88 | + deactivate_plugins( $pluginSlug ); |
|
89 | + $this->printNotice( $pluginData['name'] ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | protected function getMessages() |
96 | 96 | { |
97 | 97 | return array( |
98 | - __('The %s plugin was deactivated.', 'site-reviews'), |
|
99 | - __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
100 | - __('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'), |
|
101 | - __('PHP version', 'site-reviews'), |
|
102 | - __('WordPress version', 'site-reviews'), |
|
103 | - __('Update WordPress', 'site-reviews'), |
|
104 | - __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
98 | + __( 'The %s plugin was deactivated.', 'site-reviews' ), |
|
99 | + __( 'This plugin requires %s or greater in order to work properly.', 'site-reviews' ), |
|
100 | + __( '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' ), |
|
101 | + __( 'PHP version', 'site-reviews' ), |
|
102 | + __( 'WordPress version', 'site-reviews' ), |
|
103 | + __( 'Update WordPress', 'site-reviews' ), |
|
104 | + __( 'You can use the %s plugin to restore %s to the previous version.', 'site-reviews' ), |
|
105 | 105 | ); |
106 | 106 | } |
107 | 107 | |
@@ -109,22 +109,22 @@ discard block |
||
109 | 109 | * @param string $pluginName |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - protected function printNotice($pluginName) |
|
112 | + protected function printNotice( $pluginName ) |
|
113 | 113 | { |
114 | 114 | $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
115 | 115 | $messages = $this->getMessages(); |
116 | - $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | - if (!$this->isPhpValid()) { |
|
118 | - printf($noticeTemplate, |
|
119 | - sprintf($messages[0], $pluginName), |
|
120 | - sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | - sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
116 | + $rollbackMessage = sprintf( '<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName ); |
|
117 | + if( !$this->isPhpValid() ) { |
|
118 | + printf( $noticeTemplate, |
|
119 | + sprintf( $messages[0], $pluginName ), |
|
120 | + sprintf( $messages[1], $messages[3].' '.$this->versions['php'] ), |
|
121 | + sprintf( $messages[2], PHP_VERSION ).'</p><p>'.$rollbackMessage |
|
122 | 122 | ); |
123 | - } elseif (!$this->isWpValid()) { |
|
124 | - printf($noticeTemplate, |
|
125 | - sprintf($messages[0], $pluginName), |
|
126 | - sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
123 | + } elseif( !$this->isWpValid() ) { |
|
124 | + printf( $noticeTemplate, |
|
125 | + sprintf( $messages[0], $pluginName ), |
|
126 | + sprintf( $messages[1], $messages[4].' '.$this->versions['wordpress'] ), |
|
127 | + $rollbackMessage.'</p><p>'.sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages[5] ) |
|
128 | 128 | ); |
129 | 129 | } |
130 | 130 | } |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function redirect() |
136 | 136 | { |
137 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | - filter_input(INPUT_GET, 'plugin_status'), |
|
139 | - filter_input(INPUT_GET, 'paged'), |
|
140 | - filter_input(INPUT_GET, 's') |
|
141 | - ))); |
|
137 | + wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | + filter_input( INPUT_GET, 'plugin_status' ), |
|
139 | + filter_input( INPUT_GET, 'paged' ), |
|
140 | + filter_input( INPUT_GET, 's' ) |
|
141 | + ) ) ); |
|
142 | 142 | exit; |
143 | 143 | } |
144 | 144 | } |
@@ -120,7 +120,8 @@ |
||
120 | 120 | sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
121 | 121 | sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
122 | 122 | ); |
123 | - } elseif (!$this->isWpValid()) { |
|
123 | + } |
|
124 | + elseif (!$this->isWpValid()) { |
|
124 | 125 | printf($noticeTemplate, |
125 | 126 | sprintf($messages[0], $pluginName), |
126 | 127 | sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-form-wrap"> |
4 | 4 | <form class="{{ class }}" id="{{ id }}" method="post" enctype="multipart/form-data"> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-form-message {{ class }}"> |
4 | 4 | {{ message }} |
@@ -7,135 +7,135 @@ |
||
7 | 7 | |
8 | 8 | class ReviewsHtml extends ArrayObject |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - public $args; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + public $args; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var int |
|
17 | - */ |
|
18 | - public $max_num_pages; |
|
15 | + /** |
|
16 | + * @var int |
|
17 | + */ |
|
18 | + public $max_num_pages; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $pagination; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $pagination; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - public $reviews; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + public $reviews; |
|
29 | 29 | |
30 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | - { |
|
32 | - $this->args = $args; |
|
33 | - $this->max_num_pages = $maxPageCount; |
|
34 | - $this->reviews = $reviews; |
|
35 | - $this->pagination = $this->buildPagination(); |
|
36 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | - } |
|
30 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | + { |
|
32 | + $this->args = $args; |
|
33 | + $this->max_num_pages = $maxPageCount; |
|
34 | + $this->reviews = $reviews; |
|
35 | + $this->pagination = $this->buildPagination(); |
|
36 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function __toString() |
|
43 | - { |
|
44 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | - 'args' => $this->args, |
|
46 | - 'context' => [ |
|
47 | - 'assigned_to' => $this->args['assigned_to'], |
|
48 | - 'category' => $this->args['category'], |
|
49 | - 'class' => $this->getClass(), |
|
50 | - 'id' => $this->args['id'], |
|
51 | - 'pagination' => $this->getPagination(), |
|
52 | - 'reviews' => $this->getReviews(), |
|
53 | - ], |
|
54 | - ]); |
|
55 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function __toString() |
|
43 | + { |
|
44 | + return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + 'args' => $this->args, |
|
46 | + 'context' => [ |
|
47 | + 'assigned_to' => $this->args['assigned_to'], |
|
48 | + 'category' => $this->args['category'], |
|
49 | + 'class' => $this->getClass(), |
|
50 | + 'id' => $this->args['id'], |
|
51 | + 'pagination' => $this->getPagination(), |
|
52 | + 'reviews' => $this->getReviews(), |
|
53 | + ], |
|
54 | + ]); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getPagination() |
|
61 | - { |
|
62 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | - ? $this->pagination |
|
64 | - : ''; |
|
65 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getPagination() |
|
61 | + { |
|
62 | + return wp_validate_boolean($this->args['pagination']) |
|
63 | + ? $this->pagination |
|
64 | + : ''; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getReviews() |
|
71 | - { |
|
72 | - $html = empty($this->reviews) |
|
73 | - ? $this->getReviewsFallback() |
|
74 | - : implode(PHP_EOL, $this->reviews); |
|
75 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
76 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
77 | - return sprintf($wrapper, $html); |
|
78 | - } |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getReviews() |
|
71 | + { |
|
72 | + $html = empty($this->reviews) |
|
73 | + ? $this->getReviewsFallback() |
|
74 | + : implode(PHP_EOL, $this->reviews); |
|
75 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
76 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
77 | + return sprintf($wrapper, $html); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param mixed $key |
|
82 | - * @return mixed |
|
83 | - */ |
|
84 | - public function offsetGet($key) |
|
85 | - { |
|
86 | - if ('navigation' == $key) { |
|
87 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
88 | - return $this->pagination; |
|
89 | - } |
|
90 | - if (property_exists($this, $key)) { |
|
91 | - return $this->{$key}; |
|
92 | - } |
|
93 | - return array_key_exists($key, $this->reviews) |
|
94 | - ? $this->reviews[$key] |
|
95 | - : null; |
|
96 | - } |
|
80 | + /** |
|
81 | + * @param mixed $key |
|
82 | + * @return mixed |
|
83 | + */ |
|
84 | + public function offsetGet($key) |
|
85 | + { |
|
86 | + if ('navigation' == $key) { |
|
87 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
88 | + return $this->pagination; |
|
89 | + } |
|
90 | + if (property_exists($this, $key)) { |
|
91 | + return $this->{$key}; |
|
92 | + } |
|
93 | + return array_key_exists($key, $this->reviews) |
|
94 | + ? $this->reviews[$key] |
|
95 | + : null; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function buildPagination() |
|
102 | - { |
|
103 | - $html = glsr(Partial::class)->build('pagination', [ |
|
104 | - 'baseUrl' => glsr_get($this->args, 'pagedUrl'), |
|
105 | - 'current' => glsr_get($this->args, 'paged'), |
|
106 | - 'total' => $this->max_num_pages, |
|
107 | - ]); |
|
108 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
109 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
110 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
111 | - return sprintf($wrapper, $html); |
|
112 | - } |
|
98 | + /** |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function buildPagination() |
|
102 | + { |
|
103 | + $html = glsr(Partial::class)->build('pagination', [ |
|
104 | + 'baseUrl' => glsr_get($this->args, 'pagedUrl'), |
|
105 | + 'current' => glsr_get($this->args, 'paged'), |
|
106 | + 'total' => $this->max_num_pages, |
|
107 | + ]); |
|
108 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
109 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
110 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
111 | + return sprintf($wrapper, $html); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - protected function getClass() |
|
118 | - { |
|
119 | - $defaults = [ |
|
120 | - 'glsr-default', |
|
121 | - ]; |
|
122 | - if ('ajax' == $this->args['pagination']) { |
|
123 | - $defaults[] = 'glsr-ajax-pagination'; |
|
124 | - } |
|
125 | - $classes = explode(' ', $this->args['class']); |
|
126 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
127 | - return implode(' ', $classes); |
|
128 | - } |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + protected function getClass() |
|
118 | + { |
|
119 | + $defaults = [ |
|
120 | + 'glsr-default', |
|
121 | + ]; |
|
122 | + if ('ajax' == $this->args['pagination']) { |
|
123 | + $defaults[] = 'glsr-ajax-pagination'; |
|
124 | + } |
|
125 | + $classes = explode(' ', $this->args['class']); |
|
126 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
127 | + return implode(' ', $classes); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - protected function getReviewsFallback() |
|
134 | - { |
|
135 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
136 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
137 | - } |
|
138 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
139 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | - } |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + protected function getReviewsFallback() |
|
134 | + { |
|
135 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
136 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
137 | + } |
|
138 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
139 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + } |
|
141 | 141 | } |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public $reviews; |
29 | 29 | |
30 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
30 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
31 | 31 | { |
32 | 32 | $this->args = $args; |
33 | 33 | $this->max_num_pages = $maxPageCount; |
34 | 34 | $this->reviews = $reviews; |
35 | 35 | $this->pagination = $this->buildPagination(); |
36 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
36 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function __toString() |
43 | 43 | { |
44 | - return glsr(Template::class)->build('templates/reviews', [ |
|
44 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
45 | 45 | 'args' => $this->args, |
46 | 46 | 'context' => [ |
47 | 47 | 'assigned_to' => $this->args['assigned_to'], |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | 'pagination' => $this->getPagination(), |
52 | 52 | 'reviews' => $this->getReviews(), |
53 | 53 | ], |
54 | - ]); |
|
54 | + ] ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function getPagination() |
61 | 61 | { |
62 | - return wp_validate_boolean($this->args['pagination']) |
|
62 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
63 | 63 | ? $this->pagination |
64 | 64 | : ''; |
65 | 65 | } |
@@ -71,26 +71,26 @@ discard block |
||
71 | 71 | { |
72 | 72 | $html = empty($this->reviews) |
73 | 73 | ? $this->getReviewsFallback() |
74 | - : implode(PHP_EOL, $this->reviews); |
|
74 | + : implode( PHP_EOL, $this->reviews ); |
|
75 | 75 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
76 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
77 | - return sprintf($wrapper, $html); |
|
76 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
77 | + return sprintf( $wrapper, $html ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @param mixed $key |
82 | 82 | * @return mixed |
83 | 83 | */ |
84 | - public function offsetGet($key) |
|
84 | + public function offsetGet( $key ) |
|
85 | 85 | { |
86 | - if ('navigation' == $key) { |
|
86 | + if( 'navigation' == $key ) { |
|
87 | 87 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
88 | 88 | return $this->pagination; |
89 | 89 | } |
90 | - if (property_exists($this, $key)) { |
|
90 | + if( property_exists( $this, $key ) ) { |
|
91 | 91 | return $this->{$key}; |
92 | 92 | } |
93 | - return array_key_exists($key, $this->reviews) |
|
93 | + return array_key_exists( $key, $this->reviews ) |
|
94 | 94 | ? $this->reviews[$key] |
95 | 95 | : null; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function buildPagination() |
102 | 102 | { |
103 | - $html = glsr(Partial::class)->build('pagination', [ |
|
104 | - 'baseUrl' => glsr_get($this->args, 'pagedUrl'), |
|
105 | - 'current' => glsr_get($this->args, 'paged'), |
|
103 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
104 | + 'baseUrl' => glsr_get( $this->args, 'pagedUrl' ), |
|
105 | + 'current' => glsr_get( $this->args, 'paged' ), |
|
106 | 106 | 'total' => $this->max_num_pages, |
107 | - ]); |
|
108 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
107 | + ] ); |
|
108 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
109 | 109 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
110 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
111 | - return sprintf($wrapper, $html); |
|
110 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
111 | + return sprintf( $wrapper, $html ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $defaults = [ |
120 | 120 | 'glsr-default', |
121 | 121 | ]; |
122 | - if ('ajax' == $this->args['pagination']) { |
|
122 | + if( 'ajax' == $this->args['pagination'] ) { |
|
123 | 123 | $defaults[] = 'glsr-ajax-pagination'; |
124 | 124 | } |
125 | - $classes = explode(' ', $this->args['class']); |
|
126 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
127 | - return implode(' ', $classes); |
|
125 | + $classes = explode( ' ', $this->args['class'] ); |
|
126 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
127 | + return implode( ' ', $classes ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | */ |
133 | 133 | protected function getReviewsFallback() |
134 | 134 | { |
135 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
136 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
135 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
136 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
137 | 137 | } |
138 | 138 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
139 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
139 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
140 | 140 | } |
141 | 141 | } |
@@ -8,114 +8,114 @@ |
||
8 | 8 | |
9 | 9 | class Notice |
10 | 10 | { |
11 | - /** |
|
12 | - * @param string $type |
|
13 | - * @param string|array|WP_Error $message |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function add($type, $message, array $args = []) |
|
17 | - { |
|
18 | - if (empty(array_filter([$message, $type]))) { |
|
19 | - return; |
|
20 | - } |
|
21 | - $args['message'] = $message; |
|
22 | - $args['type'] = $type; |
|
23 | - add_settings_error(Application::ID, '', json_encode($this->normalize($args))); |
|
24 | - } |
|
11 | + /** |
|
12 | + * @param string $type |
|
13 | + * @param string|array|WP_Error $message |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function add($type, $message, array $args = []) |
|
17 | + { |
|
18 | + if (empty(array_filter([$message, $type]))) { |
|
19 | + return; |
|
20 | + } |
|
21 | + $args['message'] = $message; |
|
22 | + $args['type'] = $type; |
|
23 | + add_settings_error(Application::ID, '', json_encode($this->normalize($args))); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param string|array|WP_Error $message |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public function addError($message, array $args = []) |
|
31 | - { |
|
32 | - $this->add('error', $message, $args); |
|
33 | - } |
|
26 | + /** |
|
27 | + * @param string|array|WP_Error $message |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public function addError($message, array $args = []) |
|
31 | + { |
|
32 | + $this->add('error', $message, $args); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string|array|WP_Error $message |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function addSuccess($message, array $args = []) |
|
40 | - { |
|
41 | - $this->add('success', $message, $args); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @param string|array|WP_Error $message |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function addSuccess($message, array $args = []) |
|
40 | + { |
|
41 | + $this->add('success', $message, $args); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param string|array|WP_Error $message |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function addWarning($message, array $args = []) |
|
49 | - { |
|
50 | - $this->add('warning', $message, $args); |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param string|array|WP_Error $message |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function addWarning($message, array $args = []) |
|
49 | + { |
|
50 | + $this->add('warning', $message, $args); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return static |
|
55 | - */ |
|
56 | - public function clear() |
|
57 | - { |
|
58 | - global $wp_settings_errors; |
|
59 | - $wp_settings_errors = []; |
|
60 | - delete_transient('settings_errors'); |
|
61 | - return $this; |
|
62 | - } |
|
53 | + /** |
|
54 | + * @return static |
|
55 | + */ |
|
56 | + public function clear() |
|
57 | + { |
|
58 | + global $wp_settings_errors; |
|
59 | + $wp_settings_errors = []; |
|
60 | + delete_transient('settings_errors'); |
|
61 | + return $this; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function get() |
|
68 | - { |
|
69 | - $notices = array_map('unserialize', |
|
70 | - array_unique(array_map('serialize', get_settings_errors(Application::ID))) |
|
71 | - ); |
|
72 | - if (empty($notices)) { |
|
73 | - return; |
|
74 | - } |
|
75 | - return array_reduce($notices, function ($carry, $notice) { |
|
76 | - return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
77 | - }); |
|
78 | - } |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function get() |
|
68 | + { |
|
69 | + $notices = array_map('unserialize', |
|
70 | + array_unique(array_map('serialize', get_settings_errors(Application::ID))) |
|
71 | + ); |
|
72 | + if (empty($notices)) { |
|
73 | + return; |
|
74 | + } |
|
75 | + return array_reduce($notices, function ($carry, $notice) { |
|
76 | + return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - protected function buildNotice(array $args) |
|
84 | - { |
|
85 | - $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
86 | - return $carry.glsr(Builder::class)->p($message); |
|
87 | - }); |
|
88 | - $class = 'notice notice-'.$args['type']; |
|
89 | - if ($args['inline']) { |
|
90 | - $class.= ' inline'; |
|
91 | - } |
|
92 | - if ($args['dismissible']) { |
|
93 | - $class.= ' is-dismissible'; |
|
94 | - } |
|
95 | - return glsr(Builder::class)->div($messages, [ |
|
96 | - 'class' => $class, |
|
97 | - ]); |
|
98 | - } |
|
80 | + /** |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + protected function buildNotice(array $args) |
|
84 | + { |
|
85 | + $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
86 | + return $carry.glsr(Builder::class)->p($message); |
|
87 | + }); |
|
88 | + $class = 'notice notice-'.$args['type']; |
|
89 | + if ($args['inline']) { |
|
90 | + $class.= ' inline'; |
|
91 | + } |
|
92 | + if ($args['dismissible']) { |
|
93 | + $class.= ' is-dismissible'; |
|
94 | + } |
|
95 | + return glsr(Builder::class)->div($messages, [ |
|
96 | + 'class' => $class, |
|
97 | + ]); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - protected function normalize(array $args) |
|
104 | - { |
|
105 | - $defaults = [ |
|
106 | - 'dismissible' => true, |
|
107 | - 'inline' => true, |
|
108 | - 'message' => '', |
|
109 | - 'type' => '', |
|
110 | - ]; |
|
111 | - $args = shortcode_atts($defaults, $args); |
|
112 | - if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
113 | - $args['type'] = 'success'; |
|
114 | - } |
|
115 | - $args['messages'] = is_wp_error($args['message']) |
|
116 | - ? (array) $args['message']->get_error_message() |
|
117 | - : (array) $args['message']; |
|
118 | - unset($args['message']); |
|
119 | - return $args; |
|
120 | - } |
|
100 | + /** |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + protected function normalize(array $args) |
|
104 | + { |
|
105 | + $defaults = [ |
|
106 | + 'dismissible' => true, |
|
107 | + 'inline' => true, |
|
108 | + 'message' => '', |
|
109 | + 'type' => '', |
|
110 | + ]; |
|
111 | + $args = shortcode_atts($defaults, $args); |
|
112 | + if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
113 | + $args['type'] = 'success'; |
|
114 | + } |
|
115 | + $args['messages'] = is_wp_error($args['message']) |
|
116 | + ? (array) $args['message']->get_error_message() |
|
117 | + : (array) $args['message']; |
|
118 | + unset($args['message']); |
|
119 | + return $args; |
|
120 | + } |
|
121 | 121 | } |
@@ -13,41 +13,41 @@ discard block |
||
13 | 13 | * @param string|array|WP_Error $message |
14 | 14 | * @return void |
15 | 15 | */ |
16 | - public function add($type, $message, array $args = []) |
|
16 | + public function add( $type, $message, array $args = [] ) |
|
17 | 17 | { |
18 | - if (empty(array_filter([$message, $type]))) { |
|
18 | + if( empty(array_filter( [$message, $type] )) ) { |
|
19 | 19 | return; |
20 | 20 | } |
21 | 21 | $args['message'] = $message; |
22 | 22 | $args['type'] = $type; |
23 | - add_settings_error(Application::ID, '', json_encode($this->normalize($args))); |
|
23 | + add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ) ) ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param string|array|WP_Error $message |
28 | 28 | * @return void |
29 | 29 | */ |
30 | - public function addError($message, array $args = []) |
|
30 | + public function addError( $message, array $args = [] ) |
|
31 | 31 | { |
32 | - $this->add('error', $message, $args); |
|
32 | + $this->add( 'error', $message, $args ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param string|array|WP_Error $message |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function addSuccess($message, array $args = []) |
|
39 | + public function addSuccess( $message, array $args = [] ) |
|
40 | 40 | { |
41 | - $this->add('success', $message, $args); |
|
41 | + $this->add( 'success', $message, $args ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @param string|array|WP_Error $message |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function addWarning($message, array $args = []) |
|
48 | + public function addWarning( $message, array $args = [] ) |
|
49 | 49 | { |
50 | - $this->add('warning', $message, $args); |
|
50 | + $this->add( 'warning', $message, $args ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | { |
58 | 58 | global $wp_settings_errors; |
59 | 59 | $wp_settings_errors = []; |
60 | - delete_transient('settings_errors'); |
|
60 | + delete_transient( 'settings_errors' ); |
|
61 | 61 | return $this; |
62 | 62 | } |
63 | 63 | |
@@ -66,41 +66,41 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function get() |
68 | 68 | { |
69 | - $notices = array_map('unserialize', |
|
70 | - array_unique(array_map('serialize', get_settings_errors(Application::ID))) |
|
69 | + $notices = array_map( 'unserialize', |
|
70 | + array_unique( array_map( 'serialize', get_settings_errors( Application::ID ) ) ) |
|
71 | 71 | ); |
72 | - if (empty($notices)) { |
|
72 | + if( empty($notices) ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | - return array_reduce($notices, function ($carry, $notice) { |
|
76 | - return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
75 | + return array_reduce( $notices, function( $carry, $notice ) { |
|
76 | + return $carry.$this->buildNotice( json_decode( $notice['message'], true ) ); |
|
77 | 77 | }); |
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - protected function buildNotice(array $args) |
|
83 | + protected function buildNotice( array $args ) |
|
84 | 84 | { |
85 | - $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
86 | - return $carry.glsr(Builder::class)->p($message); |
|
85 | + $messages = array_reduce( $args['messages'], function( $carry, $message ) { |
|
86 | + return $carry.glsr( Builder::class )->p( $message ); |
|
87 | 87 | }); |
88 | 88 | $class = 'notice notice-'.$args['type']; |
89 | - if ($args['inline']) { |
|
90 | - $class.= ' inline'; |
|
89 | + if( $args['inline'] ) { |
|
90 | + $class .= ' inline'; |
|
91 | 91 | } |
92 | - if ($args['dismissible']) { |
|
93 | - $class.= ' is-dismissible'; |
|
92 | + if( $args['dismissible'] ) { |
|
93 | + $class .= ' is-dismissible'; |
|
94 | 94 | } |
95 | - return glsr(Builder::class)->div($messages, [ |
|
95 | + return glsr( Builder::class )->div( $messages, [ |
|
96 | 96 | 'class' => $class, |
97 | - ]); |
|
97 | + ] ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - protected function normalize(array $args) |
|
103 | + protected function normalize( array $args ) |
|
104 | 104 | { |
105 | 105 | $defaults = [ |
106 | 106 | 'dismissible' => true, |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | 'message' => '', |
109 | 109 | 'type' => '', |
110 | 110 | ]; |
111 | - $args = shortcode_atts($defaults, $args); |
|
112 | - if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
111 | + $args = shortcode_atts( $defaults, $args ); |
|
112 | + if( !in_array( $args['type'], ['error', 'warning', 'success'] ) ) { |
|
113 | 113 | $args['type'] = 'success'; |
114 | 114 | } |
115 | - $args['messages'] = is_wp_error($args['message']) |
|
116 | - ? (array) $args['message']->get_error_message() |
|
117 | - : (array) $args['message']; |
|
115 | + $args['messages'] = is_wp_error( $args['message'] ) |
|
116 | + ? (array)$args['message']->get_error_message() |
|
117 | + : (array)$args['message']; |
|
118 | 118 | unset($args['message']); |
119 | 119 | return $args; |
120 | 120 | } |