@@ -21,26 +21,26 @@ discard block |
||
| 21 | 21 | * @return mixed |
| 22 | 22 | */ |
| 23 | 23 | add_filter('plugins_loaded', function () { |
| 24 | - $hooks = array( |
|
| 25 | - 'glsr_create_review' => 2, |
|
| 26 | - 'glsr_debug' => 10, |
|
| 27 | - 'glsr_get' => 4, |
|
| 28 | - 'glsr_get_option' => 4, |
|
| 29 | - 'glsr_get_options' => 1, |
|
| 30 | - 'glsr_get_rating' => 2, |
|
| 31 | - 'glsr_get_ratings' => 2, |
|
| 32 | - 'glsr_get_review' => 2, |
|
| 33 | - 'glsr_get_reviews' => 2, |
|
| 34 | - 'glsr_log' => 3, |
|
| 35 | - 'glsr_star_rating' => 2, |
|
| 36 | - ); |
|
| 37 | - foreach ($hooks as $function => $acceptedArgs) { |
|
| 38 | - add_filter($function, function () use ($function) { |
|
| 39 | - $args = func_get_args(); |
|
| 40 | - array_shift($args); // remove the fallback value |
|
| 41 | - return call_user_func_array($function, $args); |
|
| 42 | - }, 10, $acceptedArgs); |
|
| 43 | - } |
|
| 24 | + $hooks = array( |
|
| 25 | + 'glsr_create_review' => 2, |
|
| 26 | + 'glsr_debug' => 10, |
|
| 27 | + 'glsr_get' => 4, |
|
| 28 | + 'glsr_get_option' => 4, |
|
| 29 | + 'glsr_get_options' => 1, |
|
| 30 | + 'glsr_get_rating' => 2, |
|
| 31 | + 'glsr_get_ratings' => 2, |
|
| 32 | + 'glsr_get_review' => 2, |
|
| 33 | + 'glsr_get_reviews' => 2, |
|
| 34 | + 'glsr_log' => 3, |
|
| 35 | + 'glsr_star_rating' => 2, |
|
| 36 | + ); |
|
| 37 | + foreach ($hooks as $function => $acceptedArgs) { |
|
| 38 | + add_filter($function, function () use ($function) { |
|
| 39 | + $args = func_get_args(); |
|
| 40 | + array_shift($args); // remove the fallback value |
|
| 41 | + return call_user_func_array($function, $args); |
|
| 42 | + }, 10, $acceptedArgs); |
|
| 43 | + } |
|
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function glsr($alias = null, array $parameters = []) |
| 50 | 50 | { |
| 51 | - $app = Application::load(); |
|
| 52 | - return !is_null($alias) |
|
| 53 | - ? $app->make($alias, $parameters) |
|
| 54 | - : $app; |
|
| 51 | + $app = Application::load(); |
|
| 52 | + return !is_null($alias) |
|
| 53 | + ? $app->make($alias, $parameters) |
|
| 54 | + : $app; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function glsr_create_review($reviewValues = array()) |
| 61 | 61 | { |
| 62 | - $review = new CreateReview(Arr::consolidate($reviewValues)); |
|
| 63 | - return glsr(ReviewManager::class)->create($review); |
|
| 62 | + $review = new CreateReview(Arr::consolidate($reviewValues)); |
|
| 63 | + return glsr(ReviewManager::class)->create($review); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function glsr_current_screen() |
| 70 | 70 | { |
| 71 | - if (function_exists('get_current_screen')) { |
|
| 72 | - $screen = get_current_screen(); |
|
| 73 | - } |
|
| 74 | - return empty($screen) |
|
| 75 | - ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
| 76 | - : $screen; |
|
| 71 | + if (function_exists('get_current_screen')) { |
|
| 72 | + $screen = get_current_screen(); |
|
| 73 | + } |
|
| 74 | + return empty($screen) |
|
| 75 | + ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
| 76 | + : $screen; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,16 +82,16 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function glsr_debug(...$vars) |
| 84 | 84 | { |
| 85 | - if (1 == count($vars)) { |
|
| 86 | - $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
| 87 | - printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
| 88 | - } else { |
|
| 89 | - echo '<div class="glsr-debug-group">'; |
|
| 90 | - foreach ($vars as $var) { |
|
| 91 | - glsr_debug($var); |
|
| 92 | - } |
|
| 93 | - echo '</div>'; |
|
| 94 | - } |
|
| 85 | + if (1 == count($vars)) { |
|
| 86 | + $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
| 87 | + printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
| 88 | + } else { |
|
| 89 | + echo '<div class="glsr-debug-group">'; |
|
| 90 | + foreach ($vars as $var) { |
|
| 91 | + glsr_debug($var); |
|
| 92 | + } |
|
| 93 | + echo '</div>'; |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function glsr_get($array, $path = '', $fallback = '') |
| 104 | 104 | { |
| 105 | - return Arr::get($array, $path, $fallback); |
|
| 105 | + return Arr::get($array, $path, $fallback); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | function glsr_get_option($path = '', $fallback = '', $cast = '') |
| 115 | 115 | { |
| 116 | - return is_string($path) |
|
| 117 | - ? glsr(OptionManager::class)->get(Str::prefix('settings.', $path), $fallback, $cast) |
|
| 118 | - : $fallback; |
|
| 116 | + return is_string($path) |
|
| 117 | + ? glsr(OptionManager::class)->get(Str::prefix('settings.', $path), $fallback, $cast) |
|
| 118 | + : $fallback; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | function glsr_get_options() |
| 125 | 125 | { |
| 126 | - return glsr(OptionManager::class)->get('settings'); |
|
| 126 | + return glsr(OptionManager::class)->get('settings'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -131,15 +131,15 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function glsr_get_ratings($args = array()) |
| 133 | 133 | { |
| 134 | - $args = Arr::consolidate($args); |
|
| 135 | - $counts = glsr(RatingManager::class)->ratings($args); |
|
| 136 | - return new Arguments(array( |
|
| 137 | - 'average' => glsr(Rating::class)->average($counts), |
|
| 138 | - 'maximum' => glsr()->constant('MAX_RATING', Rating::class), |
|
| 139 | - 'minimum' => glsr()->constant('MIN_RATING', Rating::class), |
|
| 140 | - 'ratings' => $counts, |
|
| 141 | - 'reviews' => array_sum($counts), |
|
| 142 | - )); |
|
| 134 | + $args = Arr::consolidate($args); |
|
| 135 | + $counts = glsr(RatingManager::class)->ratings($args); |
|
| 136 | + return new Arguments(array( |
|
| 137 | + 'average' => glsr(Rating::class)->average($counts), |
|
| 138 | + 'maximum' => glsr()->constant('MAX_RATING', Rating::class), |
|
| 139 | + 'minimum' => glsr()->constant('MIN_RATING', Rating::class), |
|
| 140 | + 'ratings' => $counts, |
|
| 141 | + 'reviews' => array_sum($counts), |
|
| 142 | + )); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function glsr_get_review($postId) |
| 150 | 150 | { |
| 151 | - if (!is_numeric($postId)) { |
|
| 152 | - $postId = get_post($postId)->ID; |
|
| 153 | - } |
|
| 154 | - return glsr(ReviewManager::class)->get($postId); |
|
| 151 | + if (!is_numeric($postId)) { |
|
| 152 | + $postId = get_post($postId)->ID; |
|
| 153 | + } |
|
| 154 | + return glsr(ReviewManager::class)->get($postId); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function glsr_get_reviews($args = array()) |
| 161 | 161 | { |
| 162 | - return glsr(ReviewManager::class)->reviews(Arr::consolidate($args)); |
|
| 162 | + return glsr(ReviewManager::class)->reviews(Arr::consolidate($args)); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | function glsr_log(...$args) |
| 169 | 169 | { |
| 170 | - $console = glsr(Console::class); |
|
| 171 | - return !empty($args) |
|
| 172 | - ? call_user_func_array([$console, 'debug'], $args) |
|
| 173 | - : $console; |
|
| 170 | + $console = glsr(Console::class); |
|
| 171 | + return !empty($args) |
|
| 172 | + ? call_user_func_array([$console, 'debug'], $args) |
|
| 173 | + : $console; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -178,5 +178,5 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | function glsr_star_rating($rating) |
| 180 | 180 | { |
| 181 | - return glsr(Partial::class)->build('star-rating', ['rating' => $rating]); |
|
| 181 | + return glsr(Partial::class)->build('star-rating', ['rating' => $rating]); |
|
| 182 | 182 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use GeminiLabs\SiteReviews\Modules\Html\Partial; |
| 13 | 13 | use GeminiLabs\SiteReviews\Modules\Rating; |
| 14 | 14 | |
| 15 | -defined('WPINC') || die; |
|
| 15 | +defined( 'WPINC' ) || die; |
|
| 16 | 16 | |
| 17 | 17 | /* |
| 18 | 18 | * Alternate method of using the functions without having to use `function_exists()` |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param mixed ... |
| 21 | 21 | * @return mixed |
| 22 | 22 | */ |
| 23 | -add_filter('plugins_loaded', function () { |
|
| 23 | +add_filter( 'plugins_loaded', function() { |
|
| 24 | 24 | $hooks = array( |
| 25 | 25 | 'glsr_create_review' => 2, |
| 26 | 26 | 'glsr_debug' => 10, |
@@ -34,33 +34,33 @@ discard block |
||
| 34 | 34 | 'glsr_log' => 3, |
| 35 | 35 | 'glsr_star_rating' => 2, |
| 36 | 36 | ); |
| 37 | - foreach ($hooks as $function => $acceptedArgs) { |
|
| 38 | - add_filter($function, function () use ($function) { |
|
| 37 | + foreach( $hooks as $function => $acceptedArgs ) { |
|
| 38 | + add_filter( $function, function() use ($function) { |
|
| 39 | 39 | $args = func_get_args(); |
| 40 | - array_shift($args); // remove the fallback value |
|
| 41 | - return call_user_func_array($function, $args); |
|
| 42 | - }, 10, $acceptedArgs); |
|
| 40 | + array_shift( $args ); // remove the fallback value |
|
| 41 | + return call_user_func_array( $function, $args ); |
|
| 42 | + }, 10, $acceptedArgs ); |
|
| 43 | 43 | } |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @return mixed |
| 48 | 48 | */ |
| 49 | -function glsr($alias = null, array $parameters = []) |
|
| 49 | +function glsr( $alias = null, array $parameters = [] ) |
|
| 50 | 50 | { |
| 51 | 51 | $app = Application::load(); |
| 52 | - return !is_null($alias) |
|
| 53 | - ? $app->make($alias, $parameters) |
|
| 52 | + return !is_null( $alias ) |
|
| 53 | + ? $app->make( $alias, $parameters ) |
|
| 54 | 54 | : $app; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @return \GeminiLabs\SiteReviews\Review|false |
| 59 | 59 | */ |
| 60 | -function glsr_create_review($reviewValues = array()) |
|
| 60 | +function glsr_create_review( $reviewValues = array() ) |
|
| 61 | 61 | { |
| 62 | - $review = new CreateReview(Arr::consolidate($reviewValues)); |
|
| 63 | - return glsr(ReviewManager::class)->create($review); |
|
| 62 | + $review = new CreateReview( Arr::consolidate( $reviewValues ) ); |
|
| 63 | + return glsr( ReviewManager::class )->create( $review ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function glsr_current_screen() |
| 70 | 70 | { |
| 71 | - if (function_exists('get_current_screen')) { |
|
| 71 | + if( function_exists( 'get_current_screen' ) ) { |
|
| 72 | 72 | $screen = get_current_screen(); |
| 73 | 73 | } |
| 74 | 74 | return empty($screen) |
| 75 | - ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
| 75 | + ? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) |
|
| 76 | 76 | : $screen; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | * @param mixed ...$vars |
| 81 | 81 | * @return void |
| 82 | 82 | */ |
| 83 | -function glsr_debug(...$vars) |
|
| 83 | +function glsr_debug( ...$vars ) |
|
| 84 | 84 | { |
| 85 | - if (1 == count($vars)) { |
|
| 86 | - $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
| 87 | - printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
| 85 | + if( 1 == count( $vars ) ) { |
|
| 86 | + $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
|
| 87 | + printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
|
| 88 | 88 | } else { |
| 89 | 89 | echo '<div class="glsr-debug-group">'; |
| 90 | - foreach ($vars as $var) { |
|
| 91 | - glsr_debug($var); |
|
| 90 | + foreach( $vars as $var ) { |
|
| 91 | + glsr_debug( $var ); |
|
| 92 | 92 | } |
| 93 | 93 | echo '</div>'; |
| 94 | 94 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @param mixed $fallback |
| 101 | 101 | * @return mixed |
| 102 | 102 | */ |
| 103 | -function glsr_get($array, $path = '', $fallback = '') |
|
| 103 | +function glsr_get( $array, $path = '', $fallback = '' ) |
|
| 104 | 104 | { |
| 105 | - return Arr::get($array, $path, $fallback); |
|
| 105 | + return Arr::get( $array, $path, $fallback ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | * @param string $cast |
| 112 | 112 | * @return string|array |
| 113 | 113 | */ |
| 114 | -function glsr_get_option($path = '', $fallback = '', $cast = '') |
|
| 114 | +function glsr_get_option( $path = '', $fallback = '', $cast = '' ) |
|
| 115 | 115 | { |
| 116 | - return is_string($path) |
|
| 117 | - ? glsr(OptionManager::class)->get(Str::prefix('settings.', $path), $fallback, $cast) |
|
| 116 | + return is_string( $path ) |
|
| 117 | + ? glsr( OptionManager::class )->get( Str::prefix( 'settings.', $path ), $fallback, $cast ) |
|
| 118 | 118 | : $fallback; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -123,60 +123,60 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | function glsr_get_options() |
| 125 | 125 | { |
| 126 | - return glsr(OptionManager::class)->get('settings'); |
|
| 126 | + return glsr( OptionManager::class )->get( 'settings' ); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @return object |
| 131 | 131 | */ |
| 132 | -function glsr_get_ratings($args = array()) |
|
| 132 | +function glsr_get_ratings( $args = array() ) |
|
| 133 | 133 | { |
| 134 | - $args = Arr::consolidate($args); |
|
| 135 | - $counts = glsr(RatingManager::class)->ratings($args); |
|
| 136 | - return new Arguments(array( |
|
| 137 | - 'average' => glsr(Rating::class)->average($counts), |
|
| 138 | - 'maximum' => glsr()->constant('MAX_RATING', Rating::class), |
|
| 139 | - 'minimum' => glsr()->constant('MIN_RATING', Rating::class), |
|
| 134 | + $args = Arr::consolidate( $args ); |
|
| 135 | + $counts = glsr( RatingManager::class )->ratings( $args ); |
|
| 136 | + return new Arguments( array( |
|
| 137 | + 'average' => glsr( Rating::class )->average( $counts ), |
|
| 138 | + 'maximum' => glsr()->constant( 'MAX_RATING', Rating::class ), |
|
| 139 | + 'minimum' => glsr()->constant( 'MIN_RATING', Rating::class ), |
|
| 140 | 140 | 'ratings' => $counts, |
| 141 | - 'reviews' => array_sum($counts), |
|
| 142 | - )); |
|
| 141 | + 'reviews' => array_sum( $counts ), |
|
| 142 | + ) ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @param int|\WP_Post $postId |
| 147 | 147 | * @return \GeminiLabs\SiteReviews\Review |
| 148 | 148 | */ |
| 149 | -function glsr_get_review($postId) |
|
| 149 | +function glsr_get_review( $postId ) |
|
| 150 | 150 | { |
| 151 | - if (!is_numeric($postId)) { |
|
| 152 | - $postId = get_post($postId)->ID; |
|
| 151 | + if( !is_numeric( $postId ) ) { |
|
| 152 | + $postId = get_post( $postId )->ID; |
|
| 153 | 153 | } |
| 154 | - return glsr(ReviewManager::class)->get($postId); |
|
| 154 | + return glsr( ReviewManager::class )->get( $postId ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * @return array |
| 159 | 159 | */ |
| 160 | -function glsr_get_reviews($args = array()) |
|
| 160 | +function glsr_get_reviews( $args = array() ) |
|
| 161 | 161 | { |
| 162 | - return glsr(ReviewManager::class)->reviews(Arr::consolidate($args)); |
|
| 162 | + return glsr( ReviewManager::class )->reviews( Arr::consolidate( $args ) ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | 166 | * @return \GeminiLabs\SiteReviews\Modules\Console |
| 167 | 167 | */ |
| 168 | -function glsr_log(...$args) |
|
| 168 | +function glsr_log( ...$args ) |
|
| 169 | 169 | { |
| 170 | - $console = glsr(Console::class); |
|
| 170 | + $console = glsr( Console::class ); |
|
| 171 | 171 | return !empty($args) |
| 172 | - ? call_user_func_array([$console, 'debug'], $args) |
|
| 172 | + ? call_user_func_array( [$console, 'debug'], $args ) |
|
| 173 | 173 | : $console; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | -function glsr_star_rating($rating) |
|
| 179 | +function glsr_star_rating( $rating ) |
|
| 180 | 180 | { |
| 181 | - return glsr(Partial::class)->build('star-rating', ['rating' => $rating]); |
|
| 181 | + return glsr( Partial::class )->build( 'star-rating', ['rating' => $rating] ); |
|
| 182 | 182 | } |