@@ -15,7 +15,9 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function add( $type, $message, array $args = [] ) |
| 17 | 17 | { |
| 18 | - if( empty( array_filter( [$message, $type] )))return; |
|
| 18 | + if( empty( array_filter( [$message, $type] ))) { |
|
| 19 | + return; |
|
| 20 | + } |
|
| 19 | 21 | $args['message'] = $message; |
| 20 | 22 | $args['type'] = $type; |
| 21 | 23 | add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ))); |
@@ -56,7 +58,9 @@ discard block |
||
| 56 | 58 | $notices = array_map( 'unserialize', |
| 57 | 59 | array_unique( array_map( 'serialize', get_settings_errors( Application::ID ))) |
| 58 | 60 | ); |
| 59 | - if( empty( $notices ))return; |
|
| 61 | + if( empty( $notices )) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 60 | 64 | return array_reduce( $notices, function( $carry, $notice ) { |
| 61 | 65 | return $carry.$this->buildNotice( json_decode( $notice['message'], true )); |
| 62 | 66 | }); |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function add( $type, $message, array $args = [] ) |
| 17 | 17 | { |
| 18 | - if( empty( array_filter( [$message, $type] )))return; |
|
| 18 | + if( empty(array_filter( [$message, $type] )) )return; |
|
| 19 | 19 | $args['message'] = $message; |
| 20 | 20 | $args['type'] = $type; |
| 21 | - add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ))); |
|
| 21 | + add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ) ) ); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | public function get() |
| 55 | 55 | { |
| 56 | 56 | $notices = array_map( 'unserialize', |
| 57 | - array_unique( array_map( 'serialize', get_settings_errors( Application::ID ))) |
|
| 57 | + array_unique( array_map( 'serialize', get_settings_errors( Application::ID ) ) ) |
|
| 58 | 58 | ); |
| 59 | - if( empty( $notices ))return; |
|
| 59 | + if( empty($notices) )return; |
|
| 60 | 60 | return array_reduce( $notices, function( $carry, $notice ) { |
| 61 | - return $carry.$this->buildNotice( json_decode( $notice['message'], true )); |
|
| 61 | + return $carry.$this->buildNotice( json_decode( $notice['message'], true ) ); |
|
| 62 | 62 | }); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | return glsr( Builder::class )->div( $messages, [ |
| 81 | 81 | 'class' => $class, |
| 82 | - ]); |
|
| 82 | + ] ); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | 'type' => '', |
| 95 | 95 | ]; |
| 96 | 96 | $args = shortcode_atts( $defaults, $args ); |
| 97 | - if( !in_array( $args['type'], ['error', 'warning', 'success'] )) { |
|
| 97 | + if( !in_array( $args['type'], ['error', 'warning', 'success'] ) ) { |
|
| 98 | 98 | $args['type'] = 'success'; |
| 99 | 99 | } |
| 100 | 100 | $args['messages'] = is_wp_error( $args['message'] ) |
| 101 | 101 | ? (array)$args['message']->get_error_message() |
| 102 | 102 | : (array)$args['message']; |
| 103 | - unset( $args['message'] ); |
|
| 103 | + unset($args['message']); |
|
| 104 | 104 | return $args; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -83,7 +83,9 @@ discard block |
||
| 83 | 83 | get_mu_plugins(), |
| 84 | 84 | get_plugins( '/../'.basename( WPMU_PLUGIN_DIR )) |
| 85 | 85 | ); |
| 86 | - if( empty( $plugins ))return; |
|
| 86 | + if( empty( $plugins )) { |
|
| 87 | + return; |
|
| 88 | + } |
|
| 87 | 89 | return $this->normalizePluginList( $plugins ); |
| 88 | 90 | } |
| 89 | 91 | |
@@ -92,7 +94,9 @@ discard block |
||
| 92 | 94 | */ |
| 93 | 95 | public function getMultisitePluginDetails() |
| 94 | 96 | { |
| 95 | - if( !is_multisite() || empty( get_site_option( 'active_sitewide_plugins', [] )))return; |
|
| 97 | + if( !is_multisite() || empty( get_site_option( 'active_sitewide_plugins', [] ))) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 96 | 100 | return $this->normalizePluginList( wp_get_active_network_plugins() ); |
| 97 | 101 | } |
| 98 | 102 | |
@@ -146,12 +150,16 @@ discard block |
||
| 146 | 150 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 147 | 151 | $settings = $helper->flattenArray( $settings ); |
| 148 | 152 | foreach( ['submissions.recaptcha.key', 'submissions.recaptcha.secret'] as $key ) { |
| 149 | - if( empty( $settings[$key] ))continue; |
|
| 153 | + if( empty( $settings[$key] )) { |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 150 | 156 | $settings[$key] = str_repeat( '*', 10 ); |
| 151 | 157 | } |
| 152 | 158 | $details = []; |
| 153 | 159 | foreach( $settings as $key => $value ) { |
| 154 | - if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key ))continue; |
|
| 160 | + if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key )) { |
|
| 161 | + continue; |
|
| 162 | + } |
|
| 155 | 163 | $value = htmlspecialchars( trim( preg_replace('/\s\s+/', '\\n', $value )), ENT_QUOTES, 'UTF-8' ); |
| 156 | 164 | $details[$key] = $value; |
| 157 | 165 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | 'inactive-plugin' => 'Inactive Plugins', |
| 30 | 30 | 'setting' => 'Plugin Settings', |
| 31 | 31 | ]; |
| 32 | - $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use( $details ) { |
|
| 32 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use($details) { |
|
| 33 | 33 | $methodName = glsr( Helper::class )->buildMethodName( 'get-'.$key.'-details' ); |
| 34 | 34 | if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
| 35 | 35 | return $carry.$this->implode( $details[$key], $systemDetails ); |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $plugins = get_plugins(); |
| 48 | 48 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
| 49 | - $inactive = array_diff_key( $plugins, array_flip( $activePlugins )); |
|
| 50 | - return $this->normalizePluginList( array_diff_key( $plugins, $inactive )); |
|
| 49 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
| 50 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | public function getInactivePluginDetails() |
| 72 | 72 | { |
| 73 | 73 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
| 74 | - return $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ))); |
|
| 74 | + return $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $plugins = array_merge( |
| 83 | 83 | get_mu_plugins(), |
| 84 | - get_plugins( '/../'.basename( WPMU_PLUGIN_DIR )) |
|
| 84 | + get_plugins( '/../'.basename( WPMU_PLUGIN_DIR ) ) |
|
| 85 | 85 | ); |
| 86 | - if( empty( $plugins ))return; |
|
| 86 | + if( empty($plugins) )return; |
|
| 87 | 87 | return $this->normalizePluginList( $plugins ); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function getMultisitePluginDetails() |
| 94 | 94 | { |
| 95 | - if( !is_multisite() || empty( get_site_option( 'active_sitewide_plugins', [] )))return; |
|
| 95 | + if( !is_multisite() || empty(get_site_option( 'active_sitewide_plugins', [] )) )return; |
|
| 96 | 96 | return $this->normalizePluginList( wp_get_active_network_plugins() ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | 'Max Input Vars' => ini_get( 'max_input_vars' ), |
| 115 | 115 | 'Memory Limit' => ini_get( 'memory_limit' ), |
| 116 | 116 | 'Post Max Size' => ini_get( 'post_max_size' ), |
| 117 | - 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' )), |
|
| 118 | - 'Session Name' => esc_html( ini_get( 'session.name' )), |
|
| 119 | - 'Session Save Path' => esc_html( ini_get( 'session.save_path' )), |
|
| 120 | - 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' )), true ), |
|
| 121 | - 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' )), true ), |
|
| 117 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
| 118 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
| 119 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
| 120 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
| 121 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
| 122 | 122 | 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
| 123 | 123 | ]; |
| 124 | 124 | } |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 147 | 147 | $settings = $helper->flattenArray( $settings ); |
| 148 | 148 | foreach( ['submissions.recaptcha.key', 'submissions.recaptcha.secret'] as $key ) { |
| 149 | - if( empty( $settings[$key] ))continue; |
|
| 149 | + if( empty($settings[$key]) )continue; |
|
| 150 | 150 | $settings[$key] = str_repeat( '*', 10 ); |
| 151 | 151 | } |
| 152 | 152 | $details = []; |
| 153 | 153 | foreach( $settings as $key => $value ) { |
| 154 | - if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key ))continue; |
|
| 155 | - $value = htmlspecialchars( trim( preg_replace('/\s\s+/', '\\n', $value )), ENT_QUOTES, 'UTF-8' ); |
|
| 154 | + if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key ) )continue; |
|
| 155 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
| 156 | 156 | $details[$key] = $value; |
| 157 | 157 | } |
| 158 | 158 | return $details; |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | return $value; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | - return implode( ',', array_filter( [DB_HOST, $serverName] )); |
|
| 235 | + return implode( ',', array_filter( [DB_HOST, $serverName] ) ); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | $plugins = get_plugins(); |
| 255 | 255 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
| 256 | - $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ))); |
|
| 257 | - $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive )); |
|
| 256 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
| 257 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
| 258 | 258 | return $active + $inactive; |
| 259 | 259 | } |
| 260 | 260 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | protected function implode( $title, array $details ) |
| 266 | 266 | { |
| 267 | 267 | $strings = ['['.$title.']']; |
| 268 | - $padding = max( array_map( 'strlen', array_keys( $details )) ); |
|
| 268 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
| 269 | 269 | $padding = max( [$padding, static::PAD] ); |
| 270 | 270 | foreach( $details as $key => $value ) { |
| 271 | 271 | $strings[] = is_string( $key ) |
@@ -294,8 +294,8 @@ discard block |
||
| 294 | 294 | { |
| 295 | 295 | $response = wp_remote_post( static::WP_API_URL ); |
| 296 | 296 | return !is_wp_error( $response ) |
| 297 | - && !empty( $response['response']['code'] ) |
|
| 298 | - && in_array( $response['response']['code'], range( 200, 299 )) |
|
| 297 | + && !empty($response['response']['code']) |
|
| 298 | + && in_array( $response['response']['code'], range( 200, 299 ) ) |
|
| 299 | 299 | ? 'Works' |
| 300 | 300 | : 'Does not work'; |
| 301 | 301 | } |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | use PasswordHash; |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * This class is derived from WP Session Manager (1.2.0) |
|
| 9 | - */ |
|
| 8 | + * This class is derived from WP Session Manager (1.2.0) |
|
| 9 | + */ |
|
| 10 | 10 | class Session |
| 11 | 11 | { |
| 12 | 12 | const SESSION_COOKIE = '_glsr_session'; |
@@ -153,7 +153,7 @@ |
||
| 153 | 153 | $expiredSessions = []; |
| 154 | 154 | $sessions = $wpdb->get_results( |
| 155 | 155 | "SELECT option_name AS name, option_value AS expiration " . |
| 156 | - "FROM {$wpdb->options} " . |
|
| 156 | + "from {$wpdb->options} " . |
|
| 157 | 157 | "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' " . |
| 158 | 158 | "ORDER BY option_value ASC " . |
| 159 | 159 | "LIMIT 0, ".absint( $limit ) |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function __construct() |
| 35 | 35 | { |
| 36 | - if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) { |
|
| 37 | - $cookie = explode( '||', stripslashes( $cookieId )); |
|
| 36 | + if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE ) ) { |
|
| 37 | + $cookie = explode( '||', stripslashes( $cookieId ) ); |
|
| 38 | 38 | $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] ); |
| 39 | 39 | $this->expiryTimestamp = absint( $cookie[1] ); |
| 40 | 40 | $this->expiryTimestampReset = absint( $cookie[2] ); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | public function deleteExpiredSessions( $limit = 1000 ) |
| 79 | 79 | { |
| 80 | 80 | global $wpdb; |
| 81 | - if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) { |
|
| 81 | + if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) { |
|
| 82 | 82 | $wpdb->query( |
| 83 | 83 | "DELETE FROM {$wpdb->options} WHERE option_name IN ('{$expiredSessions}')" |
| 84 | 84 | ); |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | public function get( $key, $fallback = '', $unset = false ) |
| 95 | 95 | { |
| 96 | 96 | $key = sanitize_key( $key ); |
| 97 | - $value = isset( $this->sessionData[$key] ) |
|
| 97 | + $value = isset($this->sessionData[$key]) |
|
| 98 | 98 | ? maybe_unserialize( $this->sessionData[$key] ) |
| 99 | 99 | : $fallback; |
| 100 | - if( isset( $this->sessionData[$key] ) && $unset ) { |
|
| 101 | - unset( $this->sessionData[$key] ); |
|
| 100 | + if( isset($this->sessionData[$key]) && $unset ) { |
|
| 101 | + unset($this->sessionData[$key]); |
|
| 102 | 102 | $this->updateSession(); |
| 103 | 103 | } |
| 104 | 104 | return $value; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | protected function deleteSession() |
| 133 | 133 | { |
| 134 | 134 | delete_option( $this->getSessionId() ); |
| 135 | - delete_option( $this->getSessionId( 'expires' )); |
|
| 135 | + delete_option( $this->getSessionId( 'expires' ) ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | protected function generateSessionId() |
| 142 | 142 | { |
| 143 | - return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 )); |
|
| 143 | + return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | global $wpdb; |
| 153 | 153 | $expiredSessions = []; |
| 154 | 154 | $sessions = $wpdb->get_results( |
| 155 | - "SELECT option_name AS name, option_value AS expiration " . |
|
| 156 | - "FROM {$wpdb->options} " . |
|
| 157 | - "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' " . |
|
| 158 | - "ORDER BY option_value ASC " . |
|
| 155 | + "SELECT option_name AS name, option_value AS expiration ". |
|
| 156 | + "FROM {$wpdb->options} ". |
|
| 157 | + "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' ". |
|
| 158 | + "ORDER BY option_value ASC ". |
|
| 159 | 159 | "LIMIT 0, ".absint( $limit ) |
| 160 | 160 | ); |
| 161 | - if( !empty( $sessions )) { |
|
| 161 | + if( !empty($sessions) ) { |
|
| 162 | 162 | $now = time(); |
| 163 | 163 | foreach( $sessions as $session ) { |
| 164 | 164 | if( $now <= $session->expiration )continue; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | protected function getSessionId( $separator = '' ) |
| 177 | 177 | { |
| 178 | - return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] )); |
|
| 178 | + return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) ); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | { |
| 207 | 207 | if( headers_sent() )return; |
| 208 | 208 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
| 209 | - $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
|
| 209 | + $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) ); |
|
| 210 | 210 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | protected function updateSession() |
| 226 | 226 | { |
| 227 | - if( false === get_option( $this->getSessionId() )) { |
|
| 227 | + if( false === get_option( $this->getSessionId() ) ) { |
|
| 228 | 228 | $this->createSession(); |
| 229 | 229 | } |
| 230 | 230 | else { |
@@ -161,7 +161,9 @@ discard block |
||
| 161 | 161 | if( !empty( $sessions )) { |
| 162 | 162 | $now = time(); |
| 163 | 163 | foreach( $sessions as $session ) { |
| 164 | - if( $now <= $session->expiration )continue; |
|
| 164 | + if( $now <= $session->expiration ) { |
|
| 165 | + continue; |
|
| 166 | + } |
|
| 165 | 167 | $expiredSessions[] = $session->name; |
| 166 | 168 | $expiredSessions[] = str_replace( '_expires_', '_', $session->name ); |
| 167 | 169 | } |
@@ -204,7 +206,9 @@ discard block |
||
| 204 | 206 | */ |
| 205 | 207 | protected function setCookie() |
| 206 | 208 | { |
| 207 | - if( headers_sent() )return; |
|
| 209 | + if( headers_sent() ) { |
|
| 210 | + return; |
|
| 211 | + } |
|
| 208 | 212 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
| 209 | 213 | $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
| 210 | 214 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
@@ -108,7 +108,9 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function render() |
| 110 | 110 | { |
| 111 | - if( is_null( glsr()->schemas ))return; |
|
| 111 | + if( is_null( glsr()->schemas )) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 112 | 114 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 113 | 115 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 114 | 116 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
@@ -181,7 +183,9 @@ discard block |
||
| 181 | 183 | if( $value != $fallback ) { |
| 182 | 184 | return $value; |
| 183 | 185 | } |
| 184 | - if( !is_single() && !is_page() )return; |
|
| 186 | + if( !is_single() && !is_page() ) { |
|
| 187 | + return; |
|
| 188 | + } |
|
| 185 | 189 | switch( $option ) { |
| 186 | 190 | case 'description': |
| 187 | 191 | return get_the_excerpt(); |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | foreach( glsr( Database::class )->getReviews( $this->args )->reviews as $review ) { |
| 33 | 33 | $reviews[] = $this->buildReview( $review ); |
| 34 | 34 | } |
| 35 | - if( !empty( $reviews )) { |
|
| 35 | + if( !empty($reviews) ) { |
|
| 36 | 36 | array_walk( $reviews, function( &$review ) { |
| 37 | - unset( $review['@context'] ); |
|
| 38 | - unset( $review['itemReviewed'] ); |
|
| 37 | + unset($review['@context']); |
|
| 38 | + unset($review['itemReviewed']); |
|
| 39 | 39 | }); |
| 40 | 40 | $schema['review'] = $reviews; |
| 41 | 41 | } |
@@ -49,20 +49,20 @@ discard block |
||
| 49 | 49 | public function buildReview( $review ) |
| 50 | 50 | { |
| 51 | 51 | $schema = SchemaOrg::Review() |
| 52 | - ->doIf( !in_array( 'title', $this->args['hide'] ), function( ReviewSchema $schema ) use( $review ) { |
|
| 52 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( ReviewSchema $schema ) use($review) { |
|
| 53 | 53 | $schema->name( $review->title ); |
| 54 | 54 | }) |
| 55 | - ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( ReviewSchema $schema ) use( $review ) { |
|
| 55 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( ReviewSchema $schema ) use($review) { |
|
| 56 | 56 | $schema->reviewBody( $review->content ); |
| 57 | 57 | }) |
| 58 | - ->datePublished(( new DateTime( $review->date ))->format( DateTime::ISO8601 )) |
|
| 58 | + ->datePublished( (new DateTime( $review->date ))->format( DateTime::ISO8601 ) ) |
|
| 59 | 59 | ->author( SchemaOrg::Person() |
| 60 | 60 | ->name( $review->author ) |
| 61 | 61 | ) |
| 62 | 62 | ->itemReviewed( $this->getSchemaType() |
| 63 | 63 | ->name( $this->getThingName() ) |
| 64 | 64 | ); |
| 65 | - if( !empty( $review->rating )) { |
|
| 65 | + if( !empty($review->rating) ) { |
|
| 66 | 66 | $schema->reviewRating( SchemaOrg::Rating() |
| 67 | 67 | ->ratingValue( $review->rating ) |
| 68 | 68 | ->bestRating( Rating::MAX_RATING ) |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function buildSummary( $args = null ) |
| 80 | 80 | { |
| 81 | - if( is_array( $args )) { |
|
| 81 | + if( is_array( $args ) ) { |
|
| 82 | 82 | $this->args = $args; |
| 83 | 83 | } |
| 84 | 84 | $schema = $this->getSchemaType() |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | ->image( $this->getThingImage() ) |
| 91 | 91 | ->url( $this->getThingUrl() ); |
| 92 | 92 | $count = $this->getReviewCount(); |
| 93 | - if( !empty( $count )) { |
|
| 93 | + if( !empty($count) ) { |
|
| 94 | 94 | $schema->aggregateRating( SchemaOrg::AggregateRating() |
| 95 | 95 | ->ratingValue( $this->getRatingValue() ) |
| 96 | 96 | ->reviewCount( $count ) |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function render() |
| 110 | 110 | { |
| 111 | - if( is_null( glsr()->schemas ))return; |
|
| 111 | + if( is_null( glsr()->schemas ) )return; |
|
| 112 | 112 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 113 | 113 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 114 | 114 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
| 115 | - )); |
|
| 115 | + ) ); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function store( array $schema ) |
| 122 | 122 | { |
| 123 | - $schemas = (array) glsr()->schemas; |
|
| 123 | + $schemas = (array)glsr()->schemas; |
|
| 124 | 124 | $schemas[] = $schema; |
| 125 | - glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ))); |
|
| 125 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | protected function getSchemaOption( $option, $fallback ) |
| 163 | 163 | { |
| 164 | - if( $schemaOption = trim( get_post_meta( get_the_ID(), 'schema_'.$option, true ))) { |
|
| 164 | + if( $schemaOption = trim( get_post_meta( get_the_ID(), 'schema_'.$option, true ) ) ) { |
|
| 165 | 165 | return $schemaOption; |
| 166 | 166 | } |
| 167 | 167 | $default = glsr( OptionManager::class )->get( 'settings.reviews.schema.'.$option.'.default', $fallback ); |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | // 'is_test' => 1, |
| 31 | 31 | ]; |
| 32 | 32 | foreach( $_SERVER as $key => $value ) { |
| 33 | - if( is_array( $value ) || in_array( $key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'] ))continue; |
|
| 33 | + if( is_array( $value ) || in_array( $key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'] )) { |
|
| 34 | + continue; |
|
| 35 | + } |
|
| 34 | 36 | $submission[$key] = $value; |
| 35 | 37 | } |
| 36 | 38 | return $this->check( apply_filters( 'site-reviews/akismet/submission', $submission, $review )); |
@@ -56,12 +58,16 @@ discard block |
||
| 56 | 58 | { |
| 57 | 59 | $query = []; |
| 58 | 60 | foreach( $data as $key => $value ) { |
| 59 | - if( is_array( $value ) || is_object( $value ))continue; |
|
| 61 | + if( is_array( $value ) || is_object( $value )) { |
|
| 62 | + continue; |
|
| 63 | + } |
|
| 60 | 64 | if( $value === false ) { |
| 61 | 65 | $value = '0'; |
| 62 | 66 | } |
| 63 | 67 | $value = trim( $value ); |
| 64 | - if( !strlen( $value ))continue; |
|
| 68 | + if( !strlen( $value )) { |
|
| 69 | + continue; |
|
| 70 | + } |
|
| 65 | 71 | $query[] = urlencode( $key ).'='.urlencode( $value ); |
| 66 | 72 | } |
| 67 | 73 | return implode( '&', $query ); |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | // 'is_test' => 1, |
| 32 | 32 | ]; |
| 33 | 33 | foreach( $_SERVER as $key => $value ) { |
| 34 | - if( is_array( $value ) || in_array( $key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'] ))continue; |
|
| 34 | + if( is_array( $value ) || in_array( $key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'] ) )continue; |
|
| 35 | 35 | $submission[$key] = $value; |
| 36 | 36 | } |
| 37 | - return $this->check( apply_filters( 'site-reviews/akismet/submission', $submission, $review )); |
|
| 37 | + return $this->check( apply_filters( 'site-reviews/akismet/submission', $submission, $review ) ); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $query = []; |
| 59 | 59 | foreach( $data as $key => $value ) { |
| 60 | - if( is_array( $value ) || is_object( $value ))continue; |
|
| 60 | + if( is_array( $value ) || is_object( $value ) )continue; |
|
| 61 | 61 | if( $value === false ) { |
| 62 | 62 | $value = '0'; |
| 63 | 63 | } |
| 64 | 64 | $value = trim( $value ); |
| 65 | - if( !strlen( $value ))continue; |
|
| 65 | + if( !strlen( $value ) )continue; |
|
| 66 | 66 | $query[] = urlencode( $key ).'='.urlencode( $value ); |
| 67 | 67 | } |
| 68 | 68 | return implode( '&', $query ); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | || !is_callable( ['Akismet', 'get_api_key'] ) |
| 78 | 78 | || !is_callable( ['Akismet', 'http_post'] ) |
| 79 | 79 | ? false |
| 80 | - : (bool) AkismetPlugin::get_api_key(); |
|
| 80 | + : (bool)AkismetPlugin::get_api_key(); |
|
| 81 | 81 | return apply_filters( 'site-reviews/akismet/is-active', $check ); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -63,7 +63,9 @@ discard block |
||
| 63 | 63 | $counts = array_fill_keys( [5,4,3,2,1], [] ); |
| 64 | 64 | array_walk( $counts, function( &$count, $key ) use( $reviews ) { |
| 65 | 65 | $count = count( array_filter( $reviews, function( $review ) use( $key ) { |
| 66 | - if( !isset( $review->rating ))return; |
|
| 66 | + if( !isset( $review->rating )) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 67 | 69 | return $review->rating == $key; |
| 68 | 70 | })); |
| 69 | 71 | }); |
@@ -83,7 +85,9 @@ discard block |
||
| 83 | 85 | public function getLowerBound( array $upDownRatings, $confidencePercentage = 95 ) |
| 84 | 86 | { |
| 85 | 87 | $numRatings = count( $upDownRatings ); |
| 86 | - if( !$numRatings )return 0; |
|
| 88 | + if( !$numRatings ) { |
|
| 89 | + return 0; |
|
| 90 | + } |
|
| 87 | 91 | $positiveRatings = count( array_filter( $upDownRatings, function( $value ) { |
| 88 | 92 | return $value > 0; |
| 89 | 93 | })); |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $average = count( $reviews ); |
| 52 | 52 | if( $average > 0 ) { |
| 53 | - $average = round( $this->getTotal( $reviews ) / $average, intval( $roundBy )); |
|
| 53 | + $average = round( $this->getTotal( $reviews ) / $average, intval( $roundBy ) ); |
|
| 54 | 54 | } |
| 55 | - return floatval( apply_filters( 'site-reviews/rating/average', $average, $reviews )); |
|
| 55 | + return floatval( apply_filters( 'site-reviews/rating/average', $average, $reviews ) ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function getCounts( array $reviews ) |
| 62 | 62 | { |
| 63 | - $counts = array_fill_keys( [5,4,3,2,1], [] ); |
|
| 64 | - array_walk( $counts, function( &$count, $key ) use( $reviews ) { |
|
| 65 | - $count = count( array_filter( $reviews, function( $review ) use( $key ) { |
|
| 66 | - if( !isset( $review->rating ))return; |
|
| 63 | + $counts = array_fill_keys( [5, 4, 3, 2, 1], [] ); |
|
| 64 | + array_walk( $counts, function( &$count, $key ) use($reviews) { |
|
| 65 | + $count = count( array_filter( $reviews, function( $review ) use($key) { |
|
| 66 | + if( !isset($review->rating) )return; |
|
| 67 | 67 | return $review->rating == $key; |
| 68 | - })); |
|
| 68 | + }) ); |
|
| 69 | 69 | }); |
| 70 | 70 | return $counts; |
| 71 | 71 | } |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | if( !$numRatings )return 0; |
| 87 | 87 | $positiveRatings = count( array_filter( $upDownRatings, function( $value ) { |
| 88 | 88 | return $value > 0; |
| 89 | - })); |
|
| 89 | + }) ); |
|
| 90 | 90 | $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
| 91 | 91 | $phat = 1 * $positiveRatings / $numRatings; |
| 92 | - return ( $phat + $z * $z / ( 2 * $numRatings ) - $z * sqrt(( $phat * ( 1 - $phat ) + $z * $z / ( 4 * $numRatings )) / $numRatings )) / ( 1 + $z * $z / $numRatings ); |
|
| 92 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | public function getPercentages( array $reviews ) |
| 109 | 109 | { |
| 110 | 110 | $counts = $this->getCounts( $reviews ); |
| 111 | - array_walk( $counts, function( &$count, $rating ) use( $counts ) { |
|
| 111 | + array_walk( $counts, function( &$count, $rating ) use($counts) { |
|
| 112 | 112 | $total = array_sum( $counts ); |
| 113 | - $count = !empty( $total ) && !empty( $counts[$rating] ) |
|
| 113 | + $count = !empty($total) && !empty($counts[$rating]) |
|
| 114 | 114 | ? $counts[$rating] / array_sum( $counts ) * 100 |
| 115 | 115 | : 0; |
| 116 | 116 | }); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $this->getRankingUsingImdb( $reviews ), |
| 128 | 128 | $reviews, |
| 129 | 129 | $this |
| 130 | - )); |
|
| 130 | + ) ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | $bayesMinimal = 10; // confidence |
| 158 | 158 | // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
| 159 | 159 | // This could also be the average score of all items instead of a fixed value. |
| 160 | - $bayesMean = ( $confidencePercentage / 100 ) * static::MAX_RATING; // prior, 70% = 3.5 |
|
| 160 | + $bayesMean = ($confidencePercentage / 100) * static::MAX_RATING; // prior, 70% = 3.5 |
|
| 161 | 161 | $numOfReviews = count( $reviews ); |
| 162 | 162 | $avgRating = $this->getAverage( $reviews ); |
| 163 | 163 | return $avgRating > 0 |
| 164 | - ? (( $bayesMinimal * $bayesMean ) + ( $avgRating * $numOfReviews )) / ( $bayesMinimal + $numOfReviews ) |
|
| 164 | + ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
| 165 | 165 | : 0; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $weight = $this->getWeight( $ratingCounts, $ratingCountsSum ); |
| 183 | 183 | $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true ); |
| 184 | 184 | $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
| 185 | - return $weight - $zScore * sqrt(( $weightPow2 - pow( $weight, 2 )) / ( $ratingCountsSum + 1 )); |
|
| 185 | + return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -202,14 +202,14 @@ discard block |
||
| 202 | 202 | $remainders = array_column( $percentages, 'remainder' ); |
| 203 | 203 | array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages ); |
| 204 | 204 | $i = 0; |
| 205 | - if( array_sum( array_column( $percentages, 'percent' )) > 0 ) { |
|
| 206 | - while( array_sum( array_column( $percentages, 'percent' )) < $target ) { |
|
| 205 | + if( array_sum( array_column( $percentages, 'percent' ) ) > 0 ) { |
|
| 206 | + while( array_sum( array_column( $percentages, 'percent' ) ) < $target ) { |
|
| 207 | 207 | $percentages[$i]['percent']++; |
| 208 | 208 | $i++; |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | array_multisort( $indexes, SORT_DESC, $percentages ); |
| 212 | - return array_combine( $indexes, array_column( $percentages, 'percent' )); |
|
| 212 | + return array_combine( $indexes, array_column( $percentages, 'percent' ) ); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false ) |
| 221 | 221 | { |
| 222 | 222 | return array_reduce( array_keys( $ratingCounts ), |
| 223 | - function( $count, $rating ) use( $ratingCounts, $ratingCountsSum, $powerOf2 ) { |
|
| 223 | + function( $count, $rating ) use($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
| 224 | 224 | $ratingLevel = $powerOf2 ? pow( $rating, 2 ) : $rating; |
| 225 | - return $count + ( $ratingLevel * ( $ratingCounts[$rating] + 1 )) / $ratingCountsSum; |
|
| 225 | + return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
| 226 | 226 | } |
| 227 | 227 | ); |
| 228 | 228 | } |
@@ -42,7 +42,9 @@ |
||
| 42 | 42 | $options = $this->all(); |
| 43 | 43 | $pointer = &$options; |
| 44 | 44 | foreach( $keys as $key ) { |
| 45 | - if( !isset( $pointer[$key] ) || !is_array( $pointer[$key] ))continue; |
|
| 45 | + if( !isset( $pointer[$key] ) || !is_array( $pointer[$key] )) { |
|
| 46 | + continue; |
|
| 47 | + } |
|
| 46 | 48 | $pointer = &$pointer[$key]; |
| 47 | 49 | } |
| 48 | 50 | unset( $pointer[$last] ); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public function all() |
| 25 | 25 | { |
| 26 | 26 | $options = get_option( static::databaseKey(), [] ); |
| 27 | - if( !is_array( $options )) { |
|
| 27 | + if( !is_array( $options ) ) { |
|
| 28 | 28 | delete_option( static::databaseKey() ); |
| 29 | 29 | $options = []; |
| 30 | 30 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | $options = $this->all(); |
| 43 | 43 | $pointer = &$options; |
| 44 | 44 | foreach( $keys as $key ) { |
| 45 | - if( !isset( $pointer[$key] ) || !is_array( $pointer[$key] ))continue; |
|
| 45 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) )continue; |
|
| 46 | 46 | $pointer = &$pointer[$key]; |
| 47 | 47 | } |
| 48 | - unset( $pointer[$last] ); |
|
| 48 | + unset($pointer[$last]); |
|
| 49 | 49 | return $this->set( $options ); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | public function get( $path = '', $fallback = '' ) |
| 58 | 58 | { |
| 59 | 59 | $options = $this->all(); |
| 60 | - if( empty( $options )) { |
|
| 60 | + if( empty($options) ) { |
|
| 61 | 61 | $options = [ |
| 62 | 62 | 'settings' => glsr( DefaultsManager::class )->get(), |
| 63 | 63 | ]; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function set( $pathOrOptions, $value = '' ) |
| 74 | 74 | { |
| 75 | - if( is_string( $pathOrOptions )) { |
|
| 75 | + if( is_string( $pathOrOptions ) ) { |
|
| 76 | 76 | $pathOrOptions = glsr( Helper::class )->setPathValue( $pathOrOptions, $value, $this->all() ); |
| 77 | 77 | } |
| 78 | 78 | return update_option( static::databaseKey(), (array)$pathOrOptions ); |
@@ -16,9 +16,13 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | $queries = []; |
| 18 | 18 | foreach( $keys as $key ) { |
| 19 | - if( !array_key_exists( $key, $values ))continue; |
|
| 19 | + if( !array_key_exists( $key, $values )) { |
|
| 20 | + continue; |
|
| 21 | + } |
|
| 20 | 22 | $methodName = glsr( Helper::class )->buildMethodName( $key, $prefix = __METHOD__ ); |
| 21 | - if( !method_exists( $this, $methodName ))continue; |
|
| 23 | + if( !method_exists( $this, $methodName )) { |
|
| 24 | + continue; |
|
| 25 | + } |
|
| 22 | 26 | $query = call_user_func( [$this, $methodName], $values[$key] ); |
| 23 | 27 | if( is_array( $query )) { |
| 24 | 28 | $queries[] = $query; |
@@ -90,7 +94,9 @@ discard block |
||
| 90 | 94 | */ |
| 91 | 95 | protected function buildQueryAssignedTo( $value ) |
| 92 | 96 | { |
| 93 | - if( empty( $value ))return; |
|
| 97 | + if( empty( $value )) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 94 | 100 | return [ |
| 95 | 101 | 'compare' => 'IN', |
| 96 | 102 | 'key' => 'assigned_to', |
@@ -104,7 +110,9 @@ discard block |
||
| 104 | 110 | */ |
| 105 | 111 | protected function buildQueryCategory( $value ) |
| 106 | 112 | { |
| 107 | - if( empty( $value ))return; |
|
| 113 | + if( empty( $value )) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 108 | 116 | return [ |
| 109 | 117 | 'field' => 'term_id', |
| 110 | 118 | 'taxonomy' => Application::TAXONOMY, |
@@ -118,7 +126,9 @@ discard block |
||
| 118 | 126 | */ |
| 119 | 127 | protected function buildQueryRating( $value ) |
| 120 | 128 | { |
| 121 | - if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 )))return; |
|
| 129 | + if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 ))) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 122 | 132 | return [ |
| 123 | 133 | 'compare' => '>=', |
| 124 | 134 | 'key' => 'rating', |
@@ -132,7 +142,9 @@ discard block |
||
| 132 | 142 | */ |
| 133 | 143 | protected function buildQueryType( $value ) |
| 134 | 144 | { |
| 135 | - if( in_array( $value, ['','all'] ))return; |
|
| 145 | + if( in_array( $value, ['','all'] )) { |
|
| 146 | + return; |
|
| 147 | + } |
|
| 136 | 148 | return [ |
| 137 | 149 | 'key' => 'review_type', |
| 138 | 150 | 'value' => $value, |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | $queries = []; |
| 18 | 18 | foreach( $keys as $key ) { |
| 19 | - if( !array_key_exists( $key, $values ))continue; |
|
| 19 | + if( !array_key_exists( $key, $values ) )continue; |
|
| 20 | 20 | $methodName = glsr( Helper::class )->buildMethodName( $key, $prefix = __METHOD__ ); |
| 21 | - if( !method_exists( $this, $methodName ))continue; |
|
| 21 | + if( !method_exists( $this, $methodName ) )continue; |
|
| 22 | 22 | $query = call_user_func( [$this, $methodName], $values[$key] ); |
| 23 | - if( is_array( $query )) { |
|
| 23 | + if( is_array( $query ) ) { |
|
| 24 | 24 | $queries[] = $query; |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function buildSqlOr( $values, $sprintfFormat ) |
| 37 | 37 | { |
| 38 | - if( !is_array( $values )) { |
|
| 38 | + if( !is_array( $values ) ) { |
|
| 39 | 39 | $values = explode( ',', $values ); |
| 40 | 40 | } |
| 41 | - $values = array_filter( array_map( 'trim', (array)$values )); |
|
| 42 | - $values = array_map( function( $value ) use( $sprintfFormat ) { |
|
| 41 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
| 42 | + $values = array_map( function( $value ) use($sprintfFormat) { |
|
| 43 | 43 | return sprintf( $sprintfFormat, $value ); |
| 44 | 44 | }, $values ); |
| 45 | 45 | return implode( ' OR ', $values ); |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function filterSearchByTitle( $search, WP_Query $query ) |
| 56 | 56 | { |
| 57 | - if( empty( $search ) || empty( $query->get( 'search_terms' ))) { |
|
| 57 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
| 58 | 58 | return $search; |
| 59 | 59 | } |
| 60 | 60 | global $wpdb; |
| 61 | - $n = empty( $query->get( 'exact' )) |
|
| 61 | + $n = empty($query->get( 'exact' )) |
|
| 62 | 62 | ? '%' |
| 63 | 63 | : ''; |
| 64 | 64 | $search = []; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | public function getPaged( $isEnabled = true ) |
| 80 | 80 | { |
| 81 | 81 | $paged = $isEnabled |
| 82 | - ? intval( get_query_var( is_front_page() ? 'page' : Application::PAGED_QUERY_VAR )) |
|
| 82 | + ? intval( get_query_var( is_front_page() ? 'page' : Application::PAGED_QUERY_VAR ) ) |
|
| 83 | 83 | : 1; |
| 84 | 84 | return max( 1, $paged ); |
| 85 | 85 | } |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | protected function buildQueryAssignedTo( $value ) |
| 92 | 92 | { |
| 93 | - if( empty( $value ))return; |
|
| 93 | + if( empty($value) )return; |
|
| 94 | 94 | return [ |
| 95 | 95 | 'compare' => 'IN', |
| 96 | 96 | 'key' => 'assigned_to', |
| 97 | - 'value' => array_filter( array_map( 'trim', explode( ',', $value )), 'is_numeric' ), |
|
| 97 | + 'value' => array_filter( array_map( 'trim', explode( ',', $value ) ), 'is_numeric' ), |
|
| 98 | 98 | ]; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function buildQueryCategory( $value ) |
| 106 | 106 | { |
| 107 | - if( empty( $value ))return; |
|
| 107 | + if( empty($value) )return; |
|
| 108 | 108 | return [ |
| 109 | 109 | 'field' => 'term_id', |
| 110 | 110 | 'taxonomy' => Application::TAXONOMY, |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | protected function buildQueryRating( $value ) |
| 120 | 120 | { |
| 121 | - if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 )))return; |
|
| 121 | + if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 ) ) )return; |
|
| 122 | 122 | return [ |
| 123 | 123 | 'compare' => '>=', |
| 124 | 124 | 'key' => 'rating', |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | protected function buildQueryType( $value ) |
| 134 | 134 | { |
| 135 | - if( in_array( $value, ['','all'] ))return; |
|
| 135 | + if( in_array( $value, ['', 'all'] ) )return; |
|
| 136 | 136 | return [ |
| 137 | 137 | 'key' => 'review_type', |
| 138 | 138 | 'value' => $value, |
@@ -38,7 +38,9 @@ |
||
| 38 | 38 | protected function normalize( array $settings ) |
| 39 | 39 | { |
| 40 | 40 | array_walk( $settings, function( &$setting ) { |
| 41 | - if( isset( $setting['default'] ))return; |
|
| 41 | + if( isset( $setting['default'] )) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 42 | 44 | $setting['default'] = null; |
| 43 | 45 | }); |
| 44 | 46 | return $settings; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | $settings = include glsr()->path( 'config/settings.php' ); |
| 16 | 16 | $settings = apply_filters( 'site-reviews/addon/settings', $settings ); |
| 17 | 17 | $settings = $this->normalize( $settings ); |
| 18 | - $defaults = array_combine( array_keys( $settings ), array_column( $settings, 'default' )); |
|
| 18 | + $defaults = array_combine( array_keys( $settings ), array_column( $settings, 'default' ) ); |
|
| 19 | 19 | return glsr( Helper::class )->convertDotNotationArray( $defaults ); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | protected function normalize( array $settings ) |
| 39 | 39 | { |
| 40 | 40 | array_walk( $settings, function( &$setting ) { |
| 41 | - if( isset( $setting['default'] ))return; |
|
| 41 | + if( isset($setting['default']) )return; |
|
| 42 | 42 | $setting['default'] = null; |
| 43 | 43 | }); |
| 44 | 44 | return $settings; |