@@ -7,79 +7,79 @@ |
||
7 | 7 | |
8 | 8 | class Polylang implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'Polylang'; |
|
11 | - const SUPPORTED_VERSION = '2.3'; |
|
10 | + const PLUGIN_NAME = 'Polylang'; |
|
11 | + const SUPPORTED_VERSION = '2.3'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | - } |
|
25 | - if (!empty($polylangPostId)) { |
|
26 | - $postId = $polylangPostId; |
|
27 | - } |
|
28 | - return get_post(intval($postId)); |
|
29 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + } |
|
25 | + if (!empty($polylangPostId)) { |
|
26 | + $postId = $polylangPostId; |
|
27 | + } |
|
28 | + return get_post(intval($postId)); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - public function getPostIds(array $postIds) |
|
35 | - { |
|
36 | - if (!$this->isEnabled()) { |
|
37 | - return $postIds; |
|
38 | - } |
|
39 | - $newPostIds = []; |
|
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | - $newPostIds = array_merge( |
|
42 | - $newPostIds, |
|
43 | - array_values(pll_get_post_translations($postId)) |
|
44 | - ); |
|
45 | - } |
|
46 | - return $this->cleanIds($newPostIds); |
|
47 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + public function getPostIds(array $postIds) |
|
35 | + { |
|
36 | + if (!$this->isEnabled()) { |
|
37 | + return $postIds; |
|
38 | + } |
|
39 | + $newPostIds = []; |
|
40 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | + $newPostIds = array_merge( |
|
42 | + $newPostIds, |
|
43 | + array_values(pll_get_post_translations($postId)) |
|
44 | + ); |
|
45 | + } |
|
46 | + return $this->cleanIds($newPostIds); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isActive() |
|
53 | - { |
|
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isActive() |
|
53 | + { |
|
54 | + return function_exists('PLL') |
|
55 | + && function_exists('pll_get_post') |
|
56 | + && function_exists('pll_get_post_language') |
|
57 | + && function_exists('pll_get_post_translations'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function isEnabled() |
|
64 | - { |
|
65 | - return $this->isActive() |
|
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function isEnabled() |
|
64 | + { |
|
65 | + return $this->isActive() |
|
66 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function isSupported() |
|
73 | - { |
|
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | - } |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function isSupported() |
|
73 | + { |
|
74 | + return defined('POLYLANG_VERSION') |
|
75 | + && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function cleanIds(array $postIds) |
|
82 | - { |
|
83 | - return array_filter(array_unique($postIds)); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function cleanIds(array $postIds) |
|
82 | + { |
|
83 | + return array_filter(array_unique($postIds)); |
|
84 | + } |
|
85 | 85 | } |
@@ -13,37 +13,37 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@inheritdoc} |
15 | 15 | */ |
16 | - public function getPost($postId) |
|
16 | + public function getPost( $postId ) |
|
17 | 17 | { |
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
18 | + $postId = trim( $postId ); |
|
19 | + if( !is_numeric( $postId ) ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
22 | + if( $this->isEnabled() ) { |
|
23 | + $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) ); |
|
24 | 24 | } |
25 | - if (!empty($polylangPostId)) { |
|
25 | + if( !empty($polylangPostId) ) { |
|
26 | 26 | $postId = $polylangPostId; |
27 | 27 | } |
28 | - return get_post(intval($postId)); |
|
28 | + return get_post( intval( $postId ) ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * {@inheritdoc} |
33 | 33 | */ |
34 | - public function getPostIds(array $postIds) |
|
34 | + public function getPostIds( array $postIds ) |
|
35 | 35 | { |
36 | - if (!$this->isEnabled()) { |
|
36 | + if( !$this->isEnabled() ) { |
|
37 | 37 | return $postIds; |
38 | 38 | } |
39 | 39 | $newPostIds = []; |
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
40 | + foreach( $this->cleanIds( $postIds ) as $postId ) { |
|
41 | 41 | $newPostIds = array_merge( |
42 | 42 | $newPostIds, |
43 | - array_values(pll_get_post_translations($postId)) |
|
43 | + array_values( pll_get_post_translations( $postId ) ) |
|
44 | 44 | ); |
45 | 45 | } |
46 | - return $this->cleanIds($newPostIds); |
|
46 | + return $this->cleanIds( $newPostIds ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function isActive() |
53 | 53 | { |
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
54 | + return function_exists( 'PLL' ) |
|
55 | + && function_exists( 'pll_get_post' ) |
|
56 | + && function_exists( 'pll_get_post_language' ) |
|
57 | + && function_exists( 'pll_get_post_translations' ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function isEnabled() |
64 | 64 | { |
65 | 65 | return $this->isActive() |
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
66 | + && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,15 +71,15 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function isSupported() |
73 | 73 | { |
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
74 | + return defined( 'POLYLANG_VERSION' ) |
|
75 | + && version_compare( POLYLANG_VERSION, static::SUPPORTED_VERSION, '>=' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - protected function cleanIds(array $postIds) |
|
81 | + protected function cleanIds( array $postIds ) |
|
82 | 82 | { |
83 | - return array_filter(array_unique($postIds)); |
|
83 | + return array_filter( array_unique( $postIds ) ); |
|
84 | 84 | } |
85 | 85 | } |
@@ -4,206 +4,206 @@ |
||
4 | 4 | |
5 | 5 | class Rating |
6 | 6 | { |
7 | - /** |
|
8 | - * The more sure we are of the confidence interval (the higher the confidence level), the less |
|
9 | - * precise the estimation will be as the margin for error will be higher. |
|
10 | - * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf |
|
11 | - * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html |
|
12 | - * @see https://www.youtube.com/watch?v=grodoLzThy4 |
|
13 | - * @see https://en.wikipedia.org/wiki/Standard_score |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - const CONFIDENCE_LEVEL_Z_SCORES = [ |
|
17 | - 50 => 0.67449, |
|
18 | - 70 => 1.04, |
|
19 | - 75 => 1.15035, |
|
20 | - 80 => 1.282, |
|
21 | - 85 => 1.44, |
|
22 | - 90 => 1.64485, |
|
23 | - 92 => 1.75, |
|
24 | - 95 => 1.95996, |
|
25 | - 96 => 2.05, |
|
26 | - 97 => 2.17009, |
|
27 | - 98 => 2.326, |
|
28 | - 99 => 2.57583, |
|
29 | - '99.5' => 2.81, |
|
30 | - '99.8' => 3.08, |
|
31 | - '99.9' => 3.29053, |
|
32 | - ]; |
|
7 | + /** |
|
8 | + * The more sure we are of the confidence interval (the higher the confidence level), the less |
|
9 | + * precise the estimation will be as the margin for error will be higher. |
|
10 | + * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf |
|
11 | + * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html |
|
12 | + * @see https://www.youtube.com/watch?v=grodoLzThy4 |
|
13 | + * @see https://en.wikipedia.org/wiki/Standard_score |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + const CONFIDENCE_LEVEL_Z_SCORES = [ |
|
17 | + 50 => 0.67449, |
|
18 | + 70 => 1.04, |
|
19 | + 75 => 1.15035, |
|
20 | + 80 => 1.282, |
|
21 | + 85 => 1.44, |
|
22 | + 90 => 1.64485, |
|
23 | + 92 => 1.75, |
|
24 | + 95 => 1.95996, |
|
25 | + 96 => 2.05, |
|
26 | + 97 => 2.17009, |
|
27 | + 98 => 2.326, |
|
28 | + 99 => 2.57583, |
|
29 | + '99.5' => 2.81, |
|
30 | + '99.8' => 3.08, |
|
31 | + '99.9' => 3.29053, |
|
32 | + ]; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var int |
|
36 | - */ |
|
37 | - const MAX_RATING = 5; |
|
34 | + /** |
|
35 | + * @var int |
|
36 | + */ |
|
37 | + const MAX_RATING = 5; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - const MIN_RATING = 1; |
|
39 | + /** |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + const MIN_RATING = 1; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int $roundBy |
|
46 | - * @return float |
|
47 | - */ |
|
48 | - public function getAverage(array $ratingCounts, $roundBy = 1) |
|
49 | - { |
|
50 | - $average = array_sum($ratingCounts); |
|
51 | - if ($average > 0) { |
|
52 | - $average = round($this->getTotalSum($ratingCounts) / $average, intval($roundBy)); |
|
53 | - } |
|
54 | - return floatval(apply_filters('site-reviews/rating/average', $average, $ratingCounts)); |
|
55 | - } |
|
44 | + /** |
|
45 | + * @param int $roundBy |
|
46 | + * @return float |
|
47 | + */ |
|
48 | + public function getAverage(array $ratingCounts, $roundBy = 1) |
|
49 | + { |
|
50 | + $average = array_sum($ratingCounts); |
|
51 | + if ($average > 0) { |
|
52 | + $average = round($this->getTotalSum($ratingCounts) / $average, intval($roundBy)); |
|
53 | + } |
|
54 | + return floatval(apply_filters('site-reviews/rating/average', $average, $ratingCounts)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get the lower bound for up/down ratings |
|
59 | - * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1]. |
|
60 | - * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html |
|
61 | - * @see https://news.ycombinator.com/item?id=10481507 |
|
62 | - * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments |
|
63 | - * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
64 | - * @param int $confidencePercentage |
|
65 | - * @return int|float |
|
66 | - */ |
|
67 | - public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95) |
|
68 | - { |
|
69 | - $numRatings = array_sum($upDownCounts); |
|
70 | - if ($numRatings < 1) { |
|
71 | - return 0; |
|
72 | - } |
|
73 | - $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
74 | - $phat = 1 * $upDownCounts[1] / $numRatings; |
|
75 | - return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings); |
|
76 | - } |
|
57 | + /** |
|
58 | + * Get the lower bound for up/down ratings |
|
59 | + * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1]. |
|
60 | + * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html |
|
61 | + * @see https://news.ycombinator.com/item?id=10481507 |
|
62 | + * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments |
|
63 | + * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
64 | + * @param int $confidencePercentage |
|
65 | + * @return int|float |
|
66 | + */ |
|
67 | + public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95) |
|
68 | + { |
|
69 | + $numRatings = array_sum($upDownCounts); |
|
70 | + if ($numRatings < 1) { |
|
71 | + return 0; |
|
72 | + } |
|
73 | + $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
74 | + $phat = 1 * $upDownCounts[1] / $numRatings; |
|
75 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return int|float |
|
80 | - */ |
|
81 | - public function getOverallPercentage(array $ratingCounts) |
|
82 | - { |
|
83 | - return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return int|float |
|
80 | + */ |
|
81 | + public function getOverallPercentage(array $ratingCounts) |
|
82 | + { |
|
83 | + return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function getPercentages(array $ratingCounts) |
|
90 | - { |
|
91 | - $total = array_sum($ratingCounts); |
|
92 | - foreach ($ratingCounts as $index => $count) { |
|
93 | - if (empty($count)) { |
|
94 | - continue; |
|
95 | - } |
|
96 | - $ratingCounts[$index] = $count / $total * 100; |
|
97 | - } |
|
98 | - return $this->getRoundedPercentages($ratingCounts); |
|
99 | - } |
|
86 | + /** |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function getPercentages(array $ratingCounts) |
|
90 | + { |
|
91 | + $total = array_sum($ratingCounts); |
|
92 | + foreach ($ratingCounts as $index => $count) { |
|
93 | + if (empty($count)) { |
|
94 | + continue; |
|
95 | + } |
|
96 | + $ratingCounts[$index] = $count / $total * 100; |
|
97 | + } |
|
98 | + return $this->getRoundedPercentages($ratingCounts); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return float |
|
103 | - */ |
|
104 | - public function getRanking(array $ratingCounts) |
|
105 | - { |
|
106 | - return floatval(apply_filters('site-reviews/rating/ranking', |
|
107 | - $this->getRankingUsingImdb($ratingCounts), |
|
108 | - $ratingCounts, |
|
109 | - $this |
|
110 | - )); |
|
111 | - } |
|
101 | + /** |
|
102 | + * @return float |
|
103 | + */ |
|
104 | + public function getRanking(array $ratingCounts) |
|
105 | + { |
|
106 | + return floatval(apply_filters('site-reviews/rating/ranking', |
|
107 | + $this->getRankingUsingImdb($ratingCounts), |
|
108 | + $ratingCounts, |
|
109 | + $this |
|
110 | + )); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get the bayesian ranking for an array of reviews |
|
115 | - * This formula is the same one used by IMDB to rank their top 250 films. |
|
116 | - * @see https://www.xkcd.com/937/ |
|
117 | - * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means |
|
118 | - * @see http://fulmicoton.com/posts/bayesian_rating/ |
|
119 | - * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va |
|
120 | - * @param int $confidencePercentage |
|
121 | - * @return int|float |
|
122 | - */ |
|
123 | - public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70) |
|
124 | - { |
|
125 | - $avgRating = $this->getAverage($ratingCounts); |
|
126 | - // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
|
127 | - // This could also be the average score of all items instead of a fixed value. |
|
128 | - $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5 |
|
129 | - // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
|
130 | - $bayesMinimal = 10; // confidence |
|
131 | - $numOfReviews = array_sum($ratingCounts); |
|
132 | - return $avgRating > 0 |
|
133 | - ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
134 | - : 0; |
|
135 | - } |
|
113 | + /** |
|
114 | + * Get the bayesian ranking for an array of reviews |
|
115 | + * This formula is the same one used by IMDB to rank their top 250 films. |
|
116 | + * @see https://www.xkcd.com/937/ |
|
117 | + * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means |
|
118 | + * @see http://fulmicoton.com/posts/bayesian_rating/ |
|
119 | + * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va |
|
120 | + * @param int $confidencePercentage |
|
121 | + * @return int|float |
|
122 | + */ |
|
123 | + public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70) |
|
124 | + { |
|
125 | + $avgRating = $this->getAverage($ratingCounts); |
|
126 | + // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
|
127 | + // This could also be the average score of all items instead of a fixed value. |
|
128 | + $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5 |
|
129 | + // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
|
130 | + $bayesMinimal = 10; // confidence |
|
131 | + $numOfReviews = array_sum($ratingCounts); |
|
132 | + return $avgRating > 0 |
|
133 | + ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
134 | + : 0; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * The quality of a 5 star rating depends not only on the average number of stars but also on |
|
139 | - * the number of reviews. This method calculates the bayesian ranking of a page by its number |
|
140 | - * of reviews and their rating. |
|
141 | - * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html |
|
142 | - * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268 |
|
143 | - * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
144 | - * @param int $confidencePercentage |
|
145 | - * @return float |
|
146 | - */ |
|
147 | - public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90) |
|
148 | - { |
|
149 | - $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__); |
|
150 | - $weight = $this->getWeight($ratingCounts, $ratingCountsSum); |
|
151 | - $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true); |
|
152 | - $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
153 | - return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1)); |
|
154 | - } |
|
137 | + /** |
|
138 | + * The quality of a 5 star rating depends not only on the average number of stars but also on |
|
139 | + * the number of reviews. This method calculates the bayesian ranking of a page by its number |
|
140 | + * of reviews and their rating. |
|
141 | + * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html |
|
142 | + * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268 |
|
143 | + * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
144 | + * @param int $confidencePercentage |
|
145 | + * @return float |
|
146 | + */ |
|
147 | + public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90) |
|
148 | + { |
|
149 | + $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__); |
|
150 | + $weight = $this->getWeight($ratingCounts, $ratingCountsSum); |
|
151 | + $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true); |
|
152 | + $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
153 | + return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1)); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param int $target |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - protected function getRoundedPercentages(array $percentages, $totalPercent = 100) |
|
161 | - { |
|
162 | - array_walk($percentages, function (&$percent, $index) { |
|
163 | - $percent = [ |
|
164 | - 'index' => $index, |
|
165 | - 'percent' => floor($percent), |
|
166 | - 'remainder' => fmod($percent, 1), |
|
167 | - ]; |
|
168 | - }); |
|
169 | - $indexes = glsr_array_column($percentages, 'index'); |
|
170 | - $remainders = glsr_array_column($percentages, 'remainder'); |
|
171 | - array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages); |
|
172 | - $i = 0; |
|
173 | - if (array_sum(glsr_array_column($percentages, 'percent')) > 0) { |
|
174 | - while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) { |
|
175 | - ++$percentages[$i]['percent']; |
|
176 | - ++$i; |
|
177 | - } |
|
178 | - } |
|
179 | - array_multisort($indexes, SORT_DESC, $percentages); |
|
180 | - return array_combine($indexes, glsr_array_column($percentages, 'percent')); |
|
181 | - } |
|
156 | + /** |
|
157 | + * @param int $target |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + protected function getRoundedPercentages(array $percentages, $totalPercent = 100) |
|
161 | + { |
|
162 | + array_walk($percentages, function (&$percent, $index) { |
|
163 | + $percent = [ |
|
164 | + 'index' => $index, |
|
165 | + 'percent' => floor($percent), |
|
166 | + 'remainder' => fmod($percent, 1), |
|
167 | + ]; |
|
168 | + }); |
|
169 | + $indexes = glsr_array_column($percentages, 'index'); |
|
170 | + $remainders = glsr_array_column($percentages, 'remainder'); |
|
171 | + array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages); |
|
172 | + $i = 0; |
|
173 | + if (array_sum(glsr_array_column($percentages, 'percent')) > 0) { |
|
174 | + while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) { |
|
175 | + ++$percentages[$i]['percent']; |
|
176 | + ++$i; |
|
177 | + } |
|
178 | + } |
|
179 | + array_multisort($indexes, SORT_DESC, $percentages); |
|
180 | + return array_combine($indexes, glsr_array_column($percentages, 'percent')); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return int |
|
185 | - */ |
|
186 | - protected function getTotalSum(array $ratingCounts) |
|
187 | - { |
|
188 | - return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) { |
|
189 | - return $carry + ($index * $ratingCounts[$index]); |
|
190 | - }); |
|
191 | - } |
|
183 | + /** |
|
184 | + * @return int |
|
185 | + */ |
|
186 | + protected function getTotalSum(array $ratingCounts) |
|
187 | + { |
|
188 | + return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) { |
|
189 | + return $carry + ($index * $ratingCounts[$index]); |
|
190 | + }); |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * @param int|float $ratingCountsSum |
|
195 | - * @param bool $powerOf2 |
|
196 | - * @return float |
|
197 | - */ |
|
198 | - protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false) |
|
199 | - { |
|
200 | - return array_reduce(array_keys($ratingCounts), |
|
201 | - function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
202 | - $ratingLevel = $powerOf2 |
|
203 | - ? pow($rating, 2) |
|
204 | - : $rating; |
|
205 | - return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
206 | - } |
|
207 | - ); |
|
208 | - } |
|
193 | + /** |
|
194 | + * @param int|float $ratingCountsSum |
|
195 | + * @param bool $powerOf2 |
|
196 | + * @return float |
|
197 | + */ |
|
198 | + protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false) |
|
199 | + { |
|
200 | + return array_reduce(array_keys($ratingCounts), |
|
201 | + function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
202 | + $ratingLevel = $powerOf2 |
|
203 | + ? pow($rating, 2) |
|
204 | + : $rating; |
|
205 | + return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
206 | + } |
|
207 | + ); |
|
208 | + } |
|
209 | 209 | } |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @param int $roundBy |
46 | 46 | * @return float |
47 | 47 | */ |
48 | - public function getAverage(array $ratingCounts, $roundBy = 1) |
|
48 | + public function getAverage( array $ratingCounts, $roundBy = 1 ) |
|
49 | 49 | { |
50 | - $average = array_sum($ratingCounts); |
|
51 | - if ($average > 0) { |
|
52 | - $average = round($this->getTotalSum($ratingCounts) / $average, intval($roundBy)); |
|
50 | + $average = array_sum( $ratingCounts ); |
|
51 | + if( $average > 0 ) { |
|
52 | + $average = round( $this->getTotalSum( $ratingCounts ) / $average, intval( $roundBy ) ); |
|
53 | 53 | } |
54 | - return floatval(apply_filters('site-reviews/rating/average', $average, $ratingCounts)); |
|
54 | + return floatval( apply_filters( 'site-reviews/rating/average', $average, $ratingCounts ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -64,50 +64,50 @@ discard block |
||
64 | 64 | * @param int $confidencePercentage |
65 | 65 | * @return int|float |
66 | 66 | */ |
67 | - public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95) |
|
67 | + public function getLowerBound( array $upDownCounts = [0, 0], $confidencePercentage = 95 ) |
|
68 | 68 | { |
69 | - $numRatings = array_sum($upDownCounts); |
|
70 | - if ($numRatings < 1) { |
|
69 | + $numRatings = array_sum( $upDownCounts ); |
|
70 | + if( $numRatings < 1 ) { |
|
71 | 71 | return 0; |
72 | 72 | } |
73 | 73 | $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
74 | 74 | $phat = 1 * $upDownCounts[1] / $numRatings; |
75 | - return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings); |
|
75 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return int|float |
80 | 80 | */ |
81 | - public function getOverallPercentage(array $ratingCounts) |
|
81 | + public function getOverallPercentage( array $ratingCounts ) |
|
82 | 82 | { |
83 | - return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2); |
|
83 | + return round( $this->getAverage( $ratingCounts ) * 100 / glsr()->constant( 'MAX_RATING', __CLASS__ ), 2 ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * @return array |
88 | 88 | */ |
89 | - public function getPercentages(array $ratingCounts) |
|
89 | + public function getPercentages( array $ratingCounts ) |
|
90 | 90 | { |
91 | - $total = array_sum($ratingCounts); |
|
92 | - foreach ($ratingCounts as $index => $count) { |
|
93 | - if (empty($count)) { |
|
91 | + $total = array_sum( $ratingCounts ); |
|
92 | + foreach( $ratingCounts as $index => $count ) { |
|
93 | + if( empty($count) ) { |
|
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | $ratingCounts[$index] = $count / $total * 100; |
97 | 97 | } |
98 | - return $this->getRoundedPercentages($ratingCounts); |
|
98 | + return $this->getRoundedPercentages( $ratingCounts ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | 102 | * @return float |
103 | 103 | */ |
104 | - public function getRanking(array $ratingCounts) |
|
104 | + public function getRanking( array $ratingCounts ) |
|
105 | 105 | { |
106 | - return floatval(apply_filters('site-reviews/rating/ranking', |
|
107 | - $this->getRankingUsingImdb($ratingCounts), |
|
106 | + return floatval( apply_filters( 'site-reviews/rating/ranking', |
|
107 | + $this->getRankingUsingImdb( $ratingCounts ), |
|
108 | 108 | $ratingCounts, |
109 | 109 | $this |
110 | - )); |
|
110 | + ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | * @param int $confidencePercentage |
121 | 121 | * @return int|float |
122 | 122 | */ |
123 | - public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70) |
|
123 | + public function getRankingUsingImdb( array $ratingCounts, $confidencePercentage = 70 ) |
|
124 | 124 | { |
125 | - $avgRating = $this->getAverage($ratingCounts); |
|
125 | + $avgRating = $this->getAverage( $ratingCounts ); |
|
126 | 126 | // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
127 | 127 | // This could also be the average score of all items instead of a fixed value. |
128 | - $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5 |
|
128 | + $bayesMean = ($confidencePercentage / 100) * glsr()->constant( 'MAX_RATING', __CLASS__ ); // prior, 70% = 3.5 |
|
129 | 129 | // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
130 | 130 | $bayesMinimal = 10; // confidence |
131 | - $numOfReviews = array_sum($ratingCounts); |
|
131 | + $numOfReviews = array_sum( $ratingCounts ); |
|
132 | 132 | return $avgRating > 0 |
133 | 133 | ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
134 | 134 | : 0; |
@@ -144,48 +144,48 @@ discard block |
||
144 | 144 | * @param int $confidencePercentage |
145 | 145 | * @return float |
146 | 146 | */ |
147 | - public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90) |
|
147 | + public function getRankingUsingZScores( array $ratingCounts, $confidencePercentage = 90 ) |
|
148 | 148 | { |
149 | - $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__); |
|
150 | - $weight = $this->getWeight($ratingCounts, $ratingCountsSum); |
|
151 | - $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true); |
|
149 | + $ratingCountsSum = array_sum( $ratingCounts ) + glsr()->constant( 'MAX_RATING', __CLASS__ ); |
|
150 | + $weight = $this->getWeight( $ratingCounts, $ratingCountsSum ); |
|
151 | + $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true ); |
|
152 | 152 | $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
153 | - return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1)); |
|
153 | + return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @param int $target |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - protected function getRoundedPercentages(array $percentages, $totalPercent = 100) |
|
160 | + protected function getRoundedPercentages( array $percentages, $totalPercent = 100 ) |
|
161 | 161 | { |
162 | - array_walk($percentages, function (&$percent, $index) { |
|
162 | + array_walk( $percentages, function( &$percent, $index ) { |
|
163 | 163 | $percent = [ |
164 | 164 | 'index' => $index, |
165 | - 'percent' => floor($percent), |
|
166 | - 'remainder' => fmod($percent, 1), |
|
165 | + 'percent' => floor( $percent ), |
|
166 | + 'remainder' => fmod( $percent, 1 ), |
|
167 | 167 | ]; |
168 | 168 | }); |
169 | - $indexes = glsr_array_column($percentages, 'index'); |
|
170 | - $remainders = glsr_array_column($percentages, 'remainder'); |
|
171 | - array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages); |
|
169 | + $indexes = glsr_array_column( $percentages, 'index' ); |
|
170 | + $remainders = glsr_array_column( $percentages, 'remainder' ); |
|
171 | + array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages ); |
|
172 | 172 | $i = 0; |
173 | - if (array_sum(glsr_array_column($percentages, 'percent')) > 0) { |
|
174 | - while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) { |
|
173 | + if( array_sum( glsr_array_column( $percentages, 'percent' ) ) > 0 ) { |
|
174 | + while( array_sum( glsr_array_column( $percentages, 'percent' ) ) < $totalPercent ) { |
|
175 | 175 | ++$percentages[$i]['percent']; |
176 | 176 | ++$i; |
177 | 177 | } |
178 | 178 | } |
179 | - array_multisort($indexes, SORT_DESC, $percentages); |
|
180 | - return array_combine($indexes, glsr_array_column($percentages, 'percent')); |
|
179 | + array_multisort( $indexes, SORT_DESC, $percentages ); |
|
180 | + return array_combine( $indexes, glsr_array_column( $percentages, 'percent' ) ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | 184 | * @return int |
185 | 185 | */ |
186 | - protected function getTotalSum(array $ratingCounts) |
|
186 | + protected function getTotalSum( array $ratingCounts ) |
|
187 | 187 | { |
188 | - return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) { |
|
188 | + return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use ($ratingCounts) { |
|
189 | 189 | return $carry + ($index * $ratingCounts[$index]); |
190 | 190 | }); |
191 | 191 | } |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @param bool $powerOf2 |
196 | 196 | * @return float |
197 | 197 | */ |
198 | - protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false) |
|
198 | + protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false ) |
|
199 | 199 | { |
200 | - return array_reduce(array_keys($ratingCounts), |
|
201 | - function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
200 | + return array_reduce( array_keys( $ratingCounts ), |
|
201 | + function( $count, $rating ) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
202 | 202 | $ratingLevel = $powerOf2 |
203 | - ? pow($rating, 2) |
|
203 | + ? pow( $rating, 2 ) |
|
204 | 204 | : $rating; |
205 | 205 | return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
206 | 206 | } |
@@ -7,40 +7,40 @@ |
||
7 | 7 | |
8 | 8 | class EmailDefaults extends Defaults |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - protected function defaults() |
|
14 | - { |
|
15 | - return [ |
|
16 | - 'after' => '', |
|
17 | - 'attachments' => [], |
|
18 | - 'bcc' => '', |
|
19 | - 'before' => '', |
|
20 | - 'cc' => '', |
|
21 | - 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
22 | - 'message' => '', |
|
23 | - 'reply-to' => '', |
|
24 | - 'subject' => '', |
|
25 | - 'template' => '', |
|
26 | - 'template-tags' => [], |
|
27 | - 'to' => '', |
|
28 | - ]; |
|
29 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + protected function defaults() |
|
14 | + { |
|
15 | + return [ |
|
16 | + 'after' => '', |
|
17 | + 'attachments' => [], |
|
18 | + 'bcc' => '', |
|
19 | + 'before' => '', |
|
20 | + 'cc' => '', |
|
21 | + 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
22 | + 'message' => '', |
|
23 | + 'reply-to' => '', |
|
24 | + 'subject' => '', |
|
25 | + 'template' => '', |
|
26 | + 'template-tags' => [], |
|
27 | + 'to' => '', |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - protected function getFromEmail() |
|
35 | - { |
|
36 | - return glsr(OptionManager::class)->getWP('admin_email'); |
|
37 | - } |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + protected function getFromEmail() |
|
35 | + { |
|
36 | + return glsr(OptionManager::class)->getWP('admin_email'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function getFromName() |
|
43 | - { |
|
44 | - return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function getFromName() |
|
43 | + { |
|
44 | + return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
45 | + } |
|
46 | 46 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function getFromEmail() |
35 | 35 | { |
36 | - return glsr(OptionManager::class)->getWP('admin_email'); |
|
36 | + return glsr( OptionManager::class )->getWP( 'admin_email' ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,6 +41,6 @@ discard block |
||
41 | 41 | */ |
42 | 42 | protected function getFromName() |
43 | 43 | { |
44 | - return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
44 | + return wp_specialchars_decode( glsr( OptionManager::class )->getWP( 'blogname' ), ENT_QUOTES ); |
|
45 | 45 | } |
46 | 46 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p class="about-description">We think you'll love the changes in this new release!</p> |
4 | 4 | <div class="is-fullwidth"> |
@@ -1,23 +1,23 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-welcome wrap about-wrap about-wrap-content"> |
4 | 4 | <h1>Welcome to <?= glsr()->name; ?></h1> |
5 | 5 | <div class="about-text">Site Reviews is a free WordPress review plugin with advanced features that makes it easy to manage reviews on your website. Follow the instructions below to get started!</div> |
6 | 6 | <div class="wp-badge">Version <?= glsr()->version; ?></div> |
7 | 7 | <p class="about-buttons"> |
8 | - <a class="button" href="<?= admin_url('edit.php?post_type=site-review&page=documentation'); ?>">Documentation</a> |
|
8 | + <a class="button" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation' ); ?>">Documentation</a> |
|
9 | 9 | <a class="button" href="https://wordpress.org/support/plugin/site-reviews/">Support</a> |
10 | 10 | <a target="_blank" class="button" href="https://www.facebook.com/sharer/sharer.php?u=https%3A//geminilabs.io/site-reviews"><span class="dashicons dashicons-facebook-alt"></span> Share</a> |
11 | 11 | <a target="_blank" class="button" href="https://twitter.com/intent/tweet?text=Site Reviews is a fantastic WordPress review plugin with advanced features that makes it easy to manage reviews on your website.&url=https://geminilabs.io/site-reviews&hashtags=WordPress,reviewplugins,"><span class="dashicons dashicons-twitter"></span> Tweet</a> |
12 | 12 | </p> |
13 | 13 | <nav class="glsr-nav-tab-wrapper nav-tab-wrapper"> |
14 | - <?php foreach ($tabs as $id => $title) : ?> |
|
14 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
15 | 15 | <a class="glsr-nav-tab nav-tab" href="#<?= $id; ?>"><?= $title; ?></a> |
16 | 16 | <?php endforeach; ?> |
17 | 17 | </nav> |
18 | - <?php foreach ($tabs as $id => $title) : ?> |
|
18 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
19 | 19 | <div class="glsr-nav-view ui-tabs-hide" id="<?= $id; ?>"> |
20 | - <?php $template->render('pages/welcome/'.$id, $data); ?> |
|
20 | + <?php $template->render( 'pages/welcome/'.$id, $data ); ?> |
|
21 | 21 | </div> |
22 | 22 | <?php endforeach; ?> |
23 | 23 | <input type="hidden" name="_active_tab"> |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p>Hooks (also known as <a href="https://developer.wordpress.org/plugins/hooks/index.html">Actions and Filters</a>) are used in your theme's <code>functions.php</code> file to make changes to the plugin.</p> |
4 | 4 | |
@@ -6,13 +6,13 @@ discard block |
||
6 | 6 | <div class="glsr-card-header"> |
7 | 7 | <h3>Customise the order of the fields in the review submission form</h3> |
8 | 8 | <button type="button" class="handlediv" aria-expanded="true"> |
9 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
9 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
10 | 10 | <span class="toggle-indicator" aria-hidden="true"></span> |
11 | 11 | </button> |
12 | 12 | </div> |
13 | 13 | <div class="inside"> |
14 | 14 | <p>Use this hook to customise the order of the fields in the review submission form used by Site Reviews.</p> |
15 | - <p>See the <code><a data-expand="#faq-07" href="<?= admin_url('edit.php?post_type=site-review&page=documentation#!faq'); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
15 | + <p>See the <code><a data-expand="#faq-07" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation#!faq' ); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
16 | 16 | <pre><code class="php">/** |
17 | 17 | * Customises the order of the fields used in the Site Reviews submission form. |
18 | 18 | * Paste this in your active theme's functions.php file. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | <div class="glsr-card-header"> |
31 | 31 | <h3>Customise the star images</h3> |
32 | 32 | <button type="button" class="handlediv" aria-expanded="true"> |
33 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
33 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
34 | 34 | <span class="toggle-indicator" aria-hidden="true"></span> |
35 | 35 | </button> |
36 | 36 | </div> |
37 | 37 | <div class="inside"> |
38 | 38 | <p>Use this hook to customise the star images used by Site Reviews.</p> |
39 | - <p>See the <code><a data-expand="#faq-11" href="<?= admin_url('edit.php?post_type=site-review&page=documentation#!faq'); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
39 | + <p>See the <code><a data-expand="#faq-11" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation#!faq' ); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
40 | 40 | <pre><code class="php">/** |
41 | 41 | * Customises the stars used by Site Reviews. |
42 | 42 | * Paste this in your active theme's functions.php file. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | <div class="glsr-card-header"> |
55 | 55 | <h3>Disable the plugin javascript</h3> |
56 | 56 | <button type="button" class="handlediv" aria-expanded="true"> |
57 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
57 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
58 | 58 | <span class="toggle-indicator" aria-hidden="true"></span> |
59 | 59 | </button> |
60 | 60 | </div> |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | <div class="glsr-card-header"> |
74 | 74 | <h3>Disable the plugin stylesheet</h3> |
75 | 75 | <button type="button" class="handlediv" aria-expanded="true"> |
76 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
76 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
77 | 77 | <span class="toggle-indicator" aria-hidden="true"></span> |
78 | 78 | </button> |
79 | 79 | </div> |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | <div class="glsr-card-header"> |
93 | 93 | <h3>Disable the polyfill.io script</h3> |
94 | 94 | <button type="button" class="handlediv" aria-expanded="true"> |
95 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
95 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
96 | 96 | <span class="toggle-indicator" aria-hidden="true"></span> |
97 | 97 | </button> |
98 | 98 | </div> |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | <div class="glsr-card-header"> |
113 | 113 | <h3>Do something immediately after a review has been submitted</h3> |
114 | 114 | <button type="button" class="handlediv" aria-expanded="true"> |
115 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
115 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
116 | 116 | <span class="toggle-indicator" aria-hidden="true"></span> |
117 | 117 | </button> |
118 | 118 | </div> |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | <div class="glsr-card-header"> |
137 | 137 | <h3>Modify the schema</h3> |
138 | 138 | <button type="button" class="handlediv" aria-expanded="true"> |
139 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
139 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
140 | 140 | <span class="toggle-indicator" aria-hidden="true"></span> |
141 | 141 | </button> |
142 | 142 | </div> |
143 | 143 | <div class="inside"> |
144 | 144 | <p>Use this hook if you would like to modify the schema type properties.</p> |
145 | 145 | <p>This hook is specific to the schema type. For example, to modify the schema properties for the LocalBusiness schema type you would use the <code>site-reviews/schema/LocalBusiness</code> hook, but to modify the schema properties for the Product schema type you would use the <code>site-reviews/schema/Product</code> hook.</p> |
146 | - <p>See the <code><a data-expand="#faq-01" href="<?= admin_url('edit.php?post_type=site-review&page=documentation#!faq'); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
146 | + <p>See the <code><a data-expand="#faq-01" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation#!faq' ); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
147 | 147 | <p>Make sure to use Google's <a href="https://search.google.com/structured-data/testing-tool">Structured Data Testing Tool</a> to test the schema after any custom modifications have been made.</p> |
148 | 148 | <pre><code class="php">/** |
149 | 149 | * Modifies the properties of the schema created by Site Reviews. |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | <div class="glsr-card-header"> |
164 | 164 | <h3>Modify the submitted review before it is saved</h3> |
165 | 165 | <button type="button" class="handlediv" aria-expanded="true"> |
166 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
166 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
167 | 167 | <span class="toggle-indicator" aria-hidden="true"></span> |
168 | 168 | </button> |
169 | 169 | </div> |
@@ -1,7 +1,7 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | -<p><?= __('The JSON-LD schema is disabled by default. To use it, please enable the option in your blocks or shortcodes. The schema appears in Google\'s search results and shows the star rating and other information about your reviews. If the schema has been enabled, you can use Google\'s <a href="https://search.google.com/structured-data/testing-tool">Structured Data Testing Tool</a> to test your pages for valid schema data.', 'site-reviews'); ?></p> |
|
4 | -<p><?= __('You may override any of these options on a per-post/page basis by using its Custom Field name and adding a custom value using the <a href="https://codex.wordpress.org/Using_Custom_Fields#Usage">Custom Fields</a> metabox.', 'site-reviews'); ?></p> |
|
3 | +<p><?= __( 'The JSON-LD schema is disabled by default. To use it, please enable the option in your blocks or shortcodes. The schema appears in Google\'s search results and shows the star rating and other information about your reviews. If the schema has been enabled, you can use Google\'s <a href="https://search.google.com/structured-data/testing-tool">Structured Data Testing Tool</a> to test your pages for valid schema data.', 'site-reviews' ); ?></p> |
|
4 | +<p><?= __( 'You may override any of these options on a per-post/page basis by using its Custom Field name and adding a custom value using the <a href="https://codex.wordpress.org/Using_Custom_Fields#Usage">Custom Fields</a> metabox.', 'site-reviews' ); ?></p> |
|
5 | 5 | <table class="form-table"> |
6 | 6 | <tbody> |
7 | 7 | {{ rows }} |
@@ -18,11 +18,11 @@ |
||
18 | 18 | defined('WPINC') || die; |
19 | 19 | |
20 | 20 | if (!class_exists('GL_Plugin_Check_v3')) { |
21 | - require_once __DIR__.'/activate.php'; |
|
21 | + require_once __DIR__.'/activate.php'; |
|
22 | 22 | } |
23 | 23 | $check = new GL_Plugin_Check_v3(__FILE__); |
24 | 24 | if (!$check->canProceed()) { |
25 | - return; |
|
25 | + return; |
|
26 | 26 | } |
27 | 27 | require_once __DIR__.'/autoload.php'; |
28 | 28 | require_once __DIR__.'/compatibility.php'; |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | * Text Domain: site-reviews |
16 | 16 | * Domain Path: languages |
17 | 17 | */ |
18 | -defined('WPINC') || die; |
|
18 | +defined( 'WPINC' ) || die; |
|
19 | 19 | |
20 | -if (!class_exists('GL_Plugin_Check_v3')) { |
|
20 | +if( !class_exists( 'GL_Plugin_Check_v3' ) ) { |
|
21 | 21 | require_once __DIR__.'/activate.php'; |
22 | 22 | } |
23 | -$check = new GL_Plugin_Check_v3(__FILE__); |
|
24 | -if (!$check->canProceed()) { |
|
23 | +$check = new GL_Plugin_Check_v3( __FILE__ ); |
|
24 | +if( !$check->canProceed() ) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | require_once __DIR__.'/autoload.php'; |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | require_once __DIR__.'/helpers.php'; |
31 | 31 | |
32 | 32 | $app = new GeminiLabs\SiteReviews\Application(); |
33 | -$app->make('Provider')->register($app); |
|
34 | -register_activation_hook(__FILE__, array($app, 'activate')); |
|
35 | -register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
36 | -register_shutdown_function(array($app, 'catchFatalError')); |
|
33 | +$app->make( 'Provider' )->register( $app ); |
|
34 | +register_activation_hook( __FILE__, array( $app, 'activate' ) ); |
|
35 | +register_deactivation_hook( __FILE__, array( $app, 'deactivate' ) ); |
|
36 | +register_shutdown_function( array( $app, 'catchFatalError' ) ); |
|
37 | 37 | $app->init(); |
@@ -8,112 +8,112 @@ |
||
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 | - $notices = array_reduce($notices, function ($carry, $notice) { |
|
73 | - return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
74 | - }); |
|
75 | - return apply_filters('site-reviews/notices', $notices); |
|
76 | - } |
|
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 | + $notices = array_reduce($notices, function ($carry, $notice) { |
|
73 | + return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
74 | + }); |
|
75 | + return apply_filters('site-reviews/notices', $notices); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - protected function buildNotice(array $args) |
|
82 | - { |
|
83 | - $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
84 | - return $carry.glsr(Builder::class)->p($message); |
|
85 | - }); |
|
86 | - $class = 'notice notice-'.$args['type']; |
|
87 | - if ($args['inline']) { |
|
88 | - $class.= ' inline'; |
|
89 | - } |
|
90 | - if ($args['dismissible']) { |
|
91 | - $class.= ' is-dismissible'; |
|
92 | - } |
|
93 | - return glsr(Builder::class)->div($messages, [ |
|
94 | - 'class' => $class, |
|
95 | - ]); |
|
96 | - } |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + protected function buildNotice(array $args) |
|
82 | + { |
|
83 | + $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
84 | + return $carry.glsr(Builder::class)->p($message); |
|
85 | + }); |
|
86 | + $class = 'notice notice-'.$args['type']; |
|
87 | + if ($args['inline']) { |
|
88 | + $class.= ' inline'; |
|
89 | + } |
|
90 | + if ($args['dismissible']) { |
|
91 | + $class.= ' is-dismissible'; |
|
92 | + } |
|
93 | + return glsr(Builder::class)->div($messages, [ |
|
94 | + 'class' => $class, |
|
95 | + ]); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - protected function normalize(array $args) |
|
102 | - { |
|
103 | - $defaults = [ |
|
104 | - 'dismissible' => true, |
|
105 | - 'inline' => true, |
|
106 | - 'message' => '', |
|
107 | - 'type' => '', |
|
108 | - ]; |
|
109 | - $args = shortcode_atts($defaults, $args); |
|
110 | - if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
111 | - $args['type'] = 'success'; |
|
112 | - } |
|
113 | - $args['messages'] = is_wp_error($args['message']) |
|
114 | - ? (array) $args['message']->get_error_message() |
|
115 | - : (array) $args['message']; |
|
116 | - unset($args['message']); |
|
117 | - return $args; |
|
118 | - } |
|
98 | + /** |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + protected function normalize(array $args) |
|
102 | + { |
|
103 | + $defaults = [ |
|
104 | + 'dismissible' => true, |
|
105 | + 'inline' => true, |
|
106 | + 'message' => '', |
|
107 | + 'type' => '', |
|
108 | + ]; |
|
109 | + $args = shortcode_atts($defaults, $args); |
|
110 | + if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
111 | + $args['type'] = 'success'; |
|
112 | + } |
|
113 | + $args['messages'] = is_wp_error($args['message']) |
|
114 | + ? (array) $args['message']->get_error_message() |
|
115 | + : (array) $args['message']; |
|
116 | + unset($args['message']); |
|
117 | + return $args; |
|
118 | + } |
|
119 | 119 | } |
@@ -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,39 +66,39 @@ 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 | - $notices = array_reduce($notices, function ($carry, $notice) { |
|
73 | - return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
72 | + $notices = array_reduce( $notices, function( $carry, $notice ) { |
|
73 | + return $carry.$this->buildNotice( json_decode( $notice['message'], true ) ); |
|
74 | 74 | }); |
75 | - return apply_filters('site-reviews/notices', $notices); |
|
75 | + return apply_filters( 'site-reviews/notices', $notices ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - protected function buildNotice(array $args) |
|
81 | + protected function buildNotice( array $args ) |
|
82 | 82 | { |
83 | - $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
84 | - return $carry.glsr(Builder::class)->p($message); |
|
83 | + $messages = array_reduce( $args['messages'], function( $carry, $message ) { |
|
84 | + return $carry.glsr( Builder::class )->p( $message ); |
|
85 | 85 | }); |
86 | 86 | $class = 'notice notice-'.$args['type']; |
87 | - if ($args['inline']) { |
|
88 | - $class.= ' inline'; |
|
87 | + if( $args['inline'] ) { |
|
88 | + $class .= ' inline'; |
|
89 | 89 | } |
90 | - if ($args['dismissible']) { |
|
91 | - $class.= ' is-dismissible'; |
|
90 | + if( $args['dismissible'] ) { |
|
91 | + $class .= ' is-dismissible'; |
|
92 | 92 | } |
93 | - return glsr(Builder::class)->div($messages, [ |
|
93 | + return glsr( Builder::class )->div( $messages, [ |
|
94 | 94 | 'class' => $class, |
95 | - ]); |
|
95 | + ] ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @return array |
100 | 100 | */ |
101 | - protected function normalize(array $args) |
|
101 | + protected function normalize( array $args ) |
|
102 | 102 | { |
103 | 103 | $defaults = [ |
104 | 104 | 'dismissible' => true, |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | 'message' => '', |
107 | 107 | 'type' => '', |
108 | 108 | ]; |
109 | - $args = shortcode_atts($defaults, $args); |
|
110 | - if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
109 | + $args = shortcode_atts( $defaults, $args ); |
|
110 | + if( !in_array( $args['type'], ['error', 'warning', 'success'] ) ) { |
|
111 | 111 | $args['type'] = 'success'; |
112 | 112 | } |
113 | - $args['messages'] = is_wp_error($args['message']) |
|
114 | - ? (array) $args['message']->get_error_message() |
|
115 | - : (array) $args['message']; |
|
113 | + $args['messages'] = is_wp_error( $args['message'] ) |
|
114 | + ? (array)$args['message']->get_error_message() |
|
115 | + : (array)$args['message']; |
|
116 | 116 | unset($args['message']); |
117 | 117 | return $args; |
118 | 118 | } |