@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | function glsr( $alias = null ) { |
| 8 | 8 | $app = \GeminiLabs\SiteReviews\Application::load(); |
| 9 | - return empty( $alias ) |
|
| 9 | + return empty($alias) |
|
| 10 | 10 | ? $app |
| 11 | 11 | : $app->make( $alias ); |
| 12 | 12 | } |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | * @return \WP_Screen|object |
| 17 | 17 | */ |
| 18 | 18 | function glsr_current_screen() { |
| 19 | - if( function_exists( 'get_current_screen' )) { |
|
| 19 | + if( function_exists( 'get_current_screen' ) ) { |
|
| 20 | 20 | $screen = get_current_screen(); |
| 21 | 21 | } |
| 22 | - return empty( $screen ) |
|
| 22 | + return empty($screen) |
|
| 23 | 23 | ? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) |
| 24 | 24 | : $screen; |
| 25 | 25 | } |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function glsr_log() { |
| 56 | 56 | $args = func_get_args(); |
| 57 | - $context = isset( $args[1] ) |
|
| 57 | + $context = isset($args[1]) |
|
| 58 | 58 | ? $args[1] |
| 59 | 59 | : []; |
| 60 | 60 | $logger = glsr( 'Modules\Logger' ); |
| 61 | - return empty( $args ) |
|
| 61 | + return empty($args) |
|
| 62 | 62 | ? $logger |
| 63 | 63 | : $logger->log( 'debug', $args[0], $context ); |
| 64 | 64 | } |
@@ -4,7 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * @return mixed |
| 6 | 6 | */ |
| 7 | -function glsr( $alias = null ) { |
|
| 7 | +function glsr( $alias = null ) |
|
| 8 | +{ |
|
| 8 | 9 | $app = \GeminiLabs\SiteReviews\Application::load(); |
| 9 | 10 | return empty( $alias ) |
| 10 | 11 | ? $app |
@@ -15,7 +16,8 @@ discard block |
||
| 15 | 16 | * get_current_screen() is unreliable because it is not defined on all admin pages |
| 16 | 17 | * @return \WP_Screen|object |
| 17 | 18 | */ |
| 18 | -function glsr_current_screen() { |
|
| 19 | +function glsr_current_screen() |
|
| 20 | +{ |
|
| 19 | 21 | if( function_exists( 'get_current_screen' )) { |
| 20 | 22 | $screen = get_current_screen(); |
| 21 | 23 | } |
@@ -27,7 +29,8 @@ discard block |
||
| 27 | 29 | /** |
| 28 | 30 | * @return \GeminiLabs\SiteReviews\Database |
| 29 | 31 | */ |
| 30 | -function glsr_db() { |
|
| 32 | +function glsr_db() |
|
| 33 | +{ |
|
| 31 | 34 | return glsr( 'Database' ); |
| 32 | 35 | } |
| 33 | 36 | |
@@ -35,7 +38,8 @@ discard block |
||
| 35 | 38 | * @param mixed ...$vars |
| 36 | 39 | * @return void |
| 37 | 40 | */ |
| 38 | -function glsr_debug( ...$vars ) { |
|
| 41 | +function glsr_debug( ...$vars ) |
|
| 42 | +{ |
|
| 39 | 43 | if( count( $vars ) == 1 ) { |
| 40 | 44 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
| 41 | 45 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
@@ -52,7 +56,8 @@ discard block |
||
| 52 | 56 | /** |
| 53 | 57 | * @return \GeminiLabs\SiteReviews\Modules\Logger |
| 54 | 58 | */ |
| 55 | -function glsr_log() { |
|
| 59 | +function glsr_log() |
|
| 60 | +{ |
|
| 56 | 61 | $args = func_get_args(); |
| 57 | 62 | $context = isset( $args[1] ) |
| 58 | 63 | ? $args[1] |
@@ -68,7 +73,8 @@ discard block |
||
| 68 | 73 | * @return void |
| 69 | 74 | * @callback register_taxonomy() "meta_box_cb" |
| 70 | 75 | */ |
| 71 | -function glsr_categories_meta_box( $post, $box ) { |
|
| 76 | +function glsr_categories_meta_box( $post, $box ) |
|
| 77 | +{ |
|
| 72 | 78 | glsr( 'Controllers\EditorController' )->renderTaxonomyMetabox( $post, $box ); |
| 73 | 79 | } |
| 74 | 80 | |
@@ -77,14 +83,16 @@ discard block |
||
| 77 | 83 | * @param mixed $fallback |
| 78 | 84 | * @return string|array |
| 79 | 85 | */ |
| 80 | -function glsr_get_option( $option_path = '', $fallback = '' ) { |
|
| 86 | +function glsr_get_option( $option_path = '', $fallback = '' ) |
|
| 87 | +{ |
|
| 81 | 88 | return glsr( 'Database\OptionManager' )->get( 'settings.'.$option_path, $fallback ); |
| 82 | 89 | } |
| 83 | 90 | |
| 84 | 91 | /** |
| 85 | 92 | * @return array |
| 86 | 93 | */ |
| 87 | -function glsr_get_options() { |
|
| 94 | +function glsr_get_options() |
|
| 95 | +{ |
|
| 88 | 96 | return glsr( 'Database\OptionManager' )->get( 'settings' ); |
| 89 | 97 | } |
| 90 | 98 | |
@@ -197,7 +197,7 @@ |
||
| 197 | 197 | 'type' => 'text', |
| 198 | 198 | ], |
| 199 | 199 | 'settings.submissions.required' => [ |
| 200 | - 'default' => ['title','content','name','email'], |
|
| 200 | + 'default' => ['title', 'content', 'name', 'email'], |
|
| 201 | 201 | 'label' => __( 'Required Fields', 'site-reviews' ), |
| 202 | 202 | 'options' => [ |
| 203 | 203 | 'title' => __( 'Title', 'site-reviews' ), |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function getDefaults() |
| 68 | 68 | { |
| 69 | - if( empty( $this->defaults )) { |
|
| 69 | + if( empty($this->defaults) ) { |
|
| 70 | 70 | $this->defaults = $this->make( DefaultsManager::class )->get(); |
| 71 | 71 | $this->upgrade(); |
| 72 | 72 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function hasPermission() |
| 80 | 80 | { |
| 81 | - return !$this->isAdmin() || ( $this->isAdmin() && current_user_can( static::CAPABILITY )); |
|
| 81 | + return !$this->isAdmin() || ($this->isAdmin() && current_user_can( static::CAPABILITY )); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $types = apply_filters( 'site-reviews/addon/types', [] ); |
| 134 | 134 | $this->reviewTypes = wp_parse_args( $types, [ |
| 135 | 135 | 'local' => __( 'Local', 'site-reviews' ), |
| 136 | - ]); |
|
| 136 | + ] ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function scheduleCronJob() |
| 154 | 154 | { |
| 155 | - if( wp_next_scheduled( static::CRON_EVENT ))return; |
|
| 155 | + if( wp_next_scheduled( static::CRON_EVENT ) )return; |
|
| 156 | 156 | wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function unscheduleCronJob() |
| 163 | 163 | { |
| 164 | - wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT )), static::CRON_EVENT ); |
|
| 164 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -193,6 +193,6 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | public function url( $path = '' ) |
| 195 | 195 | { |
| 196 | - return esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' )); |
|
| 196 | + return esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
| 197 | 197 | } |
| 198 | 198 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | protected function createWebhookNotification( Command $command, array $args ) |
| 62 | 62 | { |
| 63 | 63 | $fields = []; |
| 64 | - $fields[] = ['title' => str_repeat( ':star:', (int) $command->rating )]; |
|
| 64 | + $fields[] = ['title' => str_repeat( ':star:', (int)$command->rating )]; |
|
| 65 | 65 | if( $command->title ) { |
| 66 | 66 | $fields[] = ['title' => $command->title]; |
| 67 | 67 | } |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | if( $command->author ) { |
| 75 | 75 | $fields[] = ['value' => trim( $command->author.$command->email.' - '.$command->ipAddress )]; |
| 76 | 76 | } |
| 77 | - $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ))]; |
|
| 78 | - return json_encode([ |
|
| 77 | + $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ) )]; |
|
| 78 | + return json_encode( [ |
|
| 79 | 79 | 'icon_url' => glsr()->url.'assets/img/icon.png', |
| 80 | 80 | 'username' => glsr()->name, |
| 81 | 81 | 'attachments' => [[ |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | 'fallback' => $this->createEmailNotification( $command, $args )->read( 'plaintext' ), |
| 85 | 85 | 'fields' => $fields, |
| 86 | 86 | ]], |
| 87 | - ]); |
|
| 87 | + ] ); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | protected function sendNotification( $post_id, Command $command ) |
| 114 | 114 | { |
| 115 | 115 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 116 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 117 | - $assignedToTitle = get_the_title( (int) $command->assignedTo ); |
|
| 116 | + if( !in_array( $notificationType, ['default', 'custom', 'webhook'] ) )return; |
|
| 117 | + $assignedToTitle = get_the_title( (int)$command->assignedTo ); |
|
| 118 | 118 | $notificationSubject = _nx( |
| 119 | 119 | 'New %s-star review', |
| 120 | 120 | 'New %s-star review of: %s', |
| 121 | - (int) empty( $assignedToTitle ), |
|
| 121 | + (int)empty($assignedToTitle), |
|
| 122 | 122 | 'The text is different depending on whether or not the review has been assigned to a post.', |
| 123 | 123 | 'site-reviews' |
| 124 | 124 | ); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | sprintf( $notificationSubject, $command->rating, $assignedToTitle ) |
| 128 | 128 | ); |
| 129 | 129 | $args = [ |
| 130 | - 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $post_id ))), |
|
| 130 | + 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $post_id ) ) ), |
|
| 131 | 131 | 'notification_title' => $notificationTitle, |
| 132 | 132 | 'notification_type' => $notificationType, |
| 133 | 133 | ]; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $args['recipient'] = $args['notification_type'] === 'default' |
| 145 | 145 | ? get_option( 'admin_email' ) |
| 146 | 146 | : glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
| 147 | - $result = !empty( $args['recipient'] ) |
|
| 147 | + $result = !empty($args['recipient']) |
|
| 148 | 148 | ? $this->createEmailNotification( $command, $args )->send() |
| 149 | 149 | : false; |
| 150 | 150 | if( $result === null ) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | if( $result === false ) { |
| 154 | 154 | glsr_log( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' ), 'error' ); |
| 155 | 155 | } |
| 156 | - return (bool) $result; |
|
| 156 | + return (bool)$result; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | 'sslverify' => false, |
| 172 | 172 | 'headers' => ['Content-Type' => 'application/json'], |
| 173 | 173 | 'body' => apply_filters( 'site-reviews/webhook/notification', $notification, $command ), |
| 174 | - ]); |
|
| 175 | - if( is_wp_error( $result )) { |
|
| 174 | + ] ); |
|
| 175 | + if( is_wp_error( $result ) ) { |
|
| 176 | 176 | glsr_log( $result->get_error_message(), 'error' ); |
| 177 | 177 | } |
| 178 | 178 | return $result; |
@@ -113,7 +113,9 @@ |
||
| 113 | 113 | protected function sendNotification( $post_id, Command $command ) |
| 114 | 114 | { |
| 115 | 115 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 116 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 116 | + if( !in_array( $notificationType, ['default','custom','webhook'] )) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 117 | 119 | $assignedToTitle = get_the_title( (int) $command->assignedTo ); |
| 118 | 120 | $notificationSubject = _nx( |
| 119 | 121 | 'New %s-star review', |
@@ -21,14 +21,14 @@ discard block |
||
| 21 | 21 | $this->dependencies = glsr( 'Html' )->getDependencies(); |
| 22 | 22 | $ajaxNonce = wp_create_nonce( Application::ID.'-ajax-nonce' ); |
| 23 | 23 | $variables = [ |
| 24 | - 'action' => glsr()->prefix . '_action', |
|
| 25 | - 'ajaxurl' => add_query_arg( '_nonce', $ajaxNonce, admin_url( 'admin-ajax.php' )), |
|
| 24 | + 'action' => glsr()->prefix.'_action', |
|
| 25 | + 'ajaxurl' => add_query_arg( '_nonce', $ajaxNonce, admin_url( 'admin-ajax.php' ) ), |
|
| 26 | 26 | 'ajaxnonce' => $ajaxNonce, |
| 27 | - 'ajaxpagination' => ['#wpadminbar','.site-navigation-fixed'], |
|
| 27 | + 'ajaxpagination' => ['#wpadminbar', '.site-navigation-fixed'], |
|
| 28 | 28 | ]; |
| 29 | 29 | $this->enqueueAssets(); |
| 30 | 30 | |
| 31 | - wp_localize_script( Application::ID, 'site_reviews', apply_filters( 'site-reviews/enqueue/localize', $variables )); |
|
| 31 | + wp_localize_script( Application::ID, 'site_reviews', apply_filters( 'site-reviews/enqueue/localize', $variables ) ); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function enqueueAssets() |
| 38 | 38 | { |
| 39 | - $currentTheme = sanitize_title( wp_get_theme()->get( 'Name' )); |
|
| 39 | + $currentTheme = sanitize_title( wp_get_theme()->get( 'Name' ) ); |
|
| 40 | 40 | $stylesheet = file_exists( glsr()->path.'assets/css/'.$currentTheme.'.css' ) |
| 41 | 41 | ? glsr()->url.'assets/css/'.$currentTheme.'.css' |
| 42 | 42 | : glsr()->url.'assets/css/'.Application::ID.'.css'; |
| 43 | - if( apply_filters( 'site-reviews/assets/css', true )) { |
|
| 43 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
| 44 | 44 | wp_enqueue_style( |
| 45 | 45 | Application::ID, |
| 46 | 46 | $stylesheet, |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | glsr()->version |
| 49 | 49 | ); |
| 50 | 50 | } |
| 51 | - if( apply_filters( 'site-reviews/assets/js', true )) { |
|
| 51 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
| 52 | 52 | wp_enqueue_script( |
| 53 | 53 | Application::ID, |
| 54 | 54 | glsr()->url.'assets/js/'.Application::ID.'.js', |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function enqueueRecaptchaScript() |
| 69 | 69 | { |
| 70 | - wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg([ |
|
| 70 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
| 71 | 71 | 'hl' => apply_filters( 'site-reviews/recaptcha/language', get_locale() ), |
| 72 | 72 | 'onload' => 'glsr_render_recaptcha', |
| 73 | 73 | 'render' => 'explicit', |
| 74 | - ], 'https://www.google.com/recaptcha/api.js' )); |
|
| 74 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
| 75 | 75 | $inlineScript = file_get_contents( glsr()->path.'js/recaptcha.js' ); |
| 76 | 76 | wp_add_inline_script( Application::ID.'/google-recaptcha', $inlineScript, 'before' ); |
| 77 | 77 | } |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | $vars[] = Application::PAGED_QUERY_VAR; |
| 45 | 45 | // dirty hack to fix a form submission with a field that has "name" as name |
| 46 | 46 | if( filter_input( INPUT_POST, 'action' ) == 'submit-review' |
| 47 | - && !is_null( filter_input( INPUT_POST, 'gotcha' ))) { |
|
| 47 | + && !is_null( filter_input( INPUT_POST, 'gotcha' ) ) ) { |
|
| 48 | 48 | $index = array_search( 'name', $vars, true ); |
| 49 | 49 | if( false !== $index ) { |
| 50 | - unset( $vars[$index] ); |
|
| 50 | + unset($vars[$index]); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | return $vars; |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | public function postSubmitReview( array $request ) |
| 60 | 60 | { |
| 61 | 61 | $validated = glsr( ValidateReview::class )->validate( $request ); |
| 62 | - if( !empty( $validated->error )) { |
|
| 62 | + if( !empty($validated->error) ) { |
|
| 63 | 63 | return $validated->request; |
| 64 | 64 | } |
| 65 | 65 | if( $validated->recaptchaIsUnset )return; |
| 66 | - return $this->execute( new SubmitReview( $validated->request )); |
|
| 66 | + return $this->execute( new SubmitReview( $validated->request ) ); |
|
| 67 | 67 | } |
| 68 | 68 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function callbackRegisterSettings( $input ) |
| 18 | 18 | { |
| 19 | - if( !is_array( $input )) { |
|
| 19 | + if( !is_array( $input ) ) { |
|
| 20 | 20 | $input = ['settings' => []]; |
| 21 | 21 | } |
| 22 | 22 | $key = key( $input ); |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected function sanitizeSubmissions( array $input, array $options ) |
| 55 | 55 | { |
| 56 | - if( isset( $input['settings']['submissions'] )) { |
|
| 56 | + if( isset($input['settings']['submissions']) ) { |
|
| 57 | 57 | $inputForm = $input['settings']['submissions']; |
| 58 | - $options['settings']['submissions']['required'] = isset( $inputForm['required'] ) |
|
| 58 | + $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
| 59 | 59 | ? $inputForm['required'] |
| 60 | 60 | : []; |
| 61 | 61 | } |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | protected function sanitizeTranslations( array $input, array $options ) |
| 69 | 69 | { |
| 70 | - if( isset( $input['settings']['translations'] )) { |
|
| 71 | - $options['settings']['translations'] = array_values( array_filter( $input['settings']['translations'] )); |
|
| 70 | + if( isset($input['settings']['translations']) ) { |
|
| 71 | + $options['settings']['translations'] = array_values( array_filter( $input['settings']['translations'] ) ); |
|
| 72 | 72 | array_walk( $options['settings']['translations'], function( &$string ) { |
| 73 | - if( isset( $string['s2'] )) { |
|
| 73 | + if( isset($string['s2']) ) { |
|
| 74 | 74 | $string['s2'] = wp_strip_all_tags( $string['s2'] ); |
| 75 | 75 | } |
| 76 | - if( isset( $string['p2'] )) { |
|
| 76 | + if( isset($string['p2']) ) { |
|
| 77 | 77 | $string['p2'] = wp_strip_all_tags( $string['p2'] ); |
| 78 | 78 | } |
| 79 | 79 | }); |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function validateRequest( array $request ) |
| 57 | 57 | { |
| 58 | - if( !$this->isRequestValid( $request )) { |
|
| 58 | + if( !$this->isRequestValid( $request ) ) { |
|
| 59 | 59 | $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
| 60 | 60 | return $request; |
| 61 | 61 | } |
| 62 | - if( empty( $request['title'] )) { |
|
| 62 | + if( empty($request['title']) ) { |
|
| 63 | 63 | $request['title'] = __( 'No Title', 'site-reviews' ); |
| 64 | 64 | } |
| 65 | 65 | return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
@@ -73,14 +73,14 @@ discard block |
||
| 73 | 73 | $rules = array_intersect_key( |
| 74 | 74 | apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES ), |
| 75 | 75 | array_flip( array_merge( |
| 76 | - ['rating','terms'], |
|
| 76 | + ['rating', 'terms'], |
|
| 77 | 77 | glsr( OptionManager::class )->get( 'settings.reviews-form.required', [] ) |
| 78 | - )) |
|
| 78 | + ) ) |
|
| 79 | 79 | ); |
| 80 | - $excluded = isset( $request['excluded'] ) |
|
| 80 | + $excluded = isset($request['excluded']) |
|
| 81 | 81 | ? json_decode( $request['excluded'] ) |
| 82 | 82 | : []; |
| 83 | - return array_diff_key( $rules, array_flip( $excluded )); |
|
| 83 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -93,12 +93,12 @@ discard block |
||
| 93 | 93 | return true; |
| 94 | 94 | } |
| 95 | 95 | $recaptchaResponse = filter_input( INPUT_POST, 'g-recaptcha-response' ); |
| 96 | - if( empty( $recaptchaResponse ))return; //if response is empty we need to return null |
|
| 96 | + if( empty($recaptchaResponse) )return; //if response is empty we need to return null |
|
| 97 | 97 | if( $integration == 'custom' ) { |
| 98 | 98 | return $this->isRecaptchaValid( $recaptchaResponse ); |
| 99 | 99 | } |
| 100 | 100 | if( $integration == 'invisible-recaptcha' ) { |
| 101 | - return boolval( apply_filters( 'google_invre_is_valid_request_filter', true )); |
|
| 101 | + return boolval( apply_filters( 'google_invre_is_valid_request_filter', true ) ); |
|
| 102 | 102 | } |
| 103 | 103 | return false; |
| 104 | 104 | } |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | protected function isRecaptchaValid( $recaptchaResponse ) |
| 110 | 110 | { |
| 111 | - $endpoint = add_query_arg([ |
|
| 111 | + $endpoint = add_query_arg( [ |
|
| 112 | 112 | 'remoteip' => glsr( Helper::class )->getIpAddress(), |
| 113 | 113 | 'response' => $recaptchaResponse, |
| 114 | 114 | 'secret' => glsr( OptionManager::class )->get( 'settings.reviews-form.recaptcha.secret' ), |
| 115 | 115 | ], 'https://www.google.com/recaptcha/api/siteverify' ); |
| 116 | - $response = json_decode( wp_remote_retrieve_body( wp_remote_get( $endpoint ))); |
|
| 117 | - if( !empty( $response->success )) { |
|
| 116 | + $response = json_decode( wp_remote_retrieve_body( wp_remote_get( $endpoint ) ) ); |
|
| 117 | + if( !empty($response->success) ) { |
|
| 118 | 118 | return boolval( $response->success ); |
| 119 | 119 | } |
| 120 | 120 | $errorCodes = [ |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | $rules = $this->getValidationRules( $request ); |
| 139 | 139 | $errors = glsr( Validator::class )->validate( $request, $rules ); |
| 140 | - if( empty( $errors )) { |
|
| 140 | + if( empty($errors) ) { |
|
| 141 | 141 | return true; |
| 142 | 142 | } |
| 143 | 143 | $this->setSession( 'errors', $errors ); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
| 155 | 155 | { |
| 156 | 156 | glsr( Session::class )->set( $this->form_id.$type, $value ); |
| 157 | - if( !empty( $loggedMessage )) { |
|
| 157 | + if( !empty($loggedMessage) ) { |
|
| 158 | 158 | glsr_log()->warning( $loggedMessage ); |
| 159 | 159 | glsr_log()->warning( $this->request ); |
| 160 | 160 | } |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | protected function validateAkismet() |
| 167 | 167 | { |
| 168 | - if( !empty( $this->error ))return; |
|
| 169 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 168 | + if( !empty($this->error) )return; |
|
| 169 | + if( !glsr( Akismet::class )->isSpam( $this->request ) )return; |
|
| 170 | 170 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 171 | 171 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 172 | 172 | } |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | protected function validateBlacklist() |
| 178 | 178 | { |
| 179 | - if( !empty( $this->error ))return; |
|
| 180 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 179 | + if( !empty($this->error) )return; |
|
| 180 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) )return; |
|
| 181 | 181 | $blacklistAction = glsr( OptionManager::class )->get( 'settings.reviews-form.blacklist.action' ); |
| 182 | 182 | if( $blacklistAction == 'unapprove' ) { |
| 183 | 183 | $this->request['blacklisted'] = true; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | protected function validateCustom() |
| 195 | 195 | { |
| 196 | - if( !empty( $this->error ))return; |
|
| 196 | + if( !empty($this->error) )return; |
|
| 197 | 197 | $validated = apply_filters( 'site-reviews/validate/review/submission', true, $this->request ); |
| 198 | 198 | if( $validated === true )return; |
| 199 | 199 | $this->setSessionValues( 'errors', [] ); |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | protected function validateHoneyPot( array $request ) |
| 210 | 210 | { |
| 211 | - if( !empty( $this->error ))return; |
|
| 212 | - if( empty( $request['gotcha'] ))return; |
|
| 211 | + if( !empty($this->error) )return; |
|
| 212 | + if( empty($request['gotcha']) )return; |
|
| 213 | 213 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 214 | 214 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 215 | 215 | } |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | protected function validateRecaptcha( array $request ) |
| 221 | 221 | { |
| 222 | - if( !empty( $this->error ))return; |
|
| 222 | + if( !empty($this->error) )return; |
|
| 223 | 223 | $isValid = $this->isRecaptchaResponseValid(); |
| 224 | - if( is_null( $isValid )) { |
|
| 224 | + if( is_null( $isValid ) ) { |
|
| 225 | 225 | $this->setSessionValues( 'recaptcha', true ); |
| 226 | 226 | $this->recaptchaIsUnset = true; |
| 227 | 227 | } |
@@ -93,7 +93,10 @@ discard block |
||
| 93 | 93 | return true; |
| 94 | 94 | } |
| 95 | 95 | $recaptchaResponse = filter_input( INPUT_POST, 'g-recaptcha-response' ); |
| 96 | - if( empty( $recaptchaResponse ))return; //if response is empty we need to return null |
|
| 96 | + if( empty( $recaptchaResponse )) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + //if response is empty we need to return null |
|
| 97 | 100 | if( $integration == 'custom' ) { |
| 98 | 101 | return $this->isRecaptchaValid( $recaptchaResponse ); |
| 99 | 102 | } |
@@ -165,8 +168,12 @@ discard block |
||
| 165 | 168 | */ |
| 166 | 169 | protected function validateAkismet() |
| 167 | 170 | { |
| 168 | - if( !empty( $this->error ))return; |
|
| 169 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 171 | + if( !empty( $this->error )) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if( !glsr( Akismet::class )->isSpam( $this->request )) { |
|
| 175 | + return; |
|
| 176 | + } |
|
| 170 | 177 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 171 | 178 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 172 | 179 | } |
@@ -176,8 +183,12 @@ discard block |
||
| 176 | 183 | */ |
| 177 | 184 | protected function validateBlacklist() |
| 178 | 185 | { |
| 179 | - if( !empty( $this->error ))return; |
|
| 180 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 186 | + if( !empty( $this->error )) { |
|
| 187 | + return; |
|
| 188 | + } |
|
| 189 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request )) { |
|
| 190 | + return; |
|
| 191 | + } |
|
| 181 | 192 | $blacklistAction = glsr( OptionManager::class )->get( 'settings.reviews-form.blacklist.action' ); |
| 182 | 193 | if( $blacklistAction == 'unapprove' ) { |
| 183 | 194 | $this->request['blacklisted'] = true; |
@@ -193,9 +204,13 @@ discard block |
||
| 193 | 204 | */ |
| 194 | 205 | protected function validateCustom() |
| 195 | 206 | { |
| 196 | - if( !empty( $this->error ))return; |
|
| 207 | + if( !empty( $this->error )) { |
|
| 208 | + return; |
|
| 209 | + } |
|
| 197 | 210 | $validated = apply_filters( 'site-reviews/validate/review/submission', true, $this->request ); |
| 198 | - if( $validated === true )return; |
|
| 211 | + if( $validated === true ) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 199 | 214 | $this->setSessionValues( 'errors', [] ); |
| 200 | 215 | $this->setSessionValues( 'values', $this->request ); |
| 201 | 216 | $this->error = is_string( $validated ) |
@@ -208,8 +223,12 @@ discard block |
||
| 208 | 223 | */ |
| 209 | 224 | protected function validateHoneyPot( array $request ) |
| 210 | 225 | { |
| 211 | - if( !empty( $this->error ))return; |
|
| 212 | - if( empty( $request['gotcha'] ))return; |
|
| 226 | + if( !empty( $this->error )) { |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + if( empty( $request['gotcha'] )) { |
|
| 230 | + return; |
|
| 231 | + } |
|
| 213 | 232 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 214 | 233 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 215 | 234 | } |
@@ -219,7 +238,9 @@ discard block |
||
| 219 | 238 | */ |
| 220 | 239 | protected function validateRecaptcha( array $request ) |
| 221 | 240 | { |
| 222 | - if( !empty( $this->error ))return; |
|
| 241 | + if( !empty( $this->error )) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 223 | 244 | $isValid = $this->isRecaptchaResponseValid(); |
| 224 | 245 | if( is_null( $isValid )) { |
| 225 | 246 | $this->setSessionValues( 'recaptcha', true ); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $this->message = $this->buildHtmlMessage( $email ); |
| 44 | 44 | $this->subject = $email['subject']; |
| 45 | 45 | $this->to = $email['to']; |
| 46 | - add_action( 'phpmailer_init', [ $this, 'buildPlainTextMessage'] ); |
|
| 46 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
| 47 | 47 | return $this; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function buildPlainTextMessage( $phpmailer ) |
| 85 | 85 | { |
| 86 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
| 86 | + if( $phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody) )return; |
|
| 87 | 87 | $message = $this->stripHtmlTags( $phpmailer->Body ); |
| 88 | 88 | $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
| 89 | 89 | } |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | 'from', |
| 100 | 100 | 'reply-to', |
| 101 | 101 | ]; |
| 102 | - $headers = array_intersect_key( $email, array_flip( $allowed )); |
|
| 102 | + $headers = array_intersect_key( $email, array_flip( $allowed ) ); |
|
| 103 | 103 | $headers = array_filter( $headers ); |
| 104 | 104 | foreach( $headers as $key => $value ) { |
| 105 | - unset( $headers[ $key ] ); |
|
| 105 | + unset($headers[$key]); |
|
| 106 | 106 | $headers[] = "{$key}: {$value}"; |
| 107 | 107 | } |
| 108 | 108 | $headers[] = 'Content-Type: text/html'; |
@@ -114,16 +114,16 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | protected function buildHtmlMessage( $email ) |
| 116 | 116 | { |
| 117 | - $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' )); |
|
| 118 | - if( !empty( $template )) { |
|
| 117 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
| 118 | + if( !empty($template) ) { |
|
| 119 | 119 | $message = glsr( Template::class )->interpolate( $template, $email['template-tags'] ); |
| 120 | 120 | } |
| 121 | 121 | else if( $email['template'] ) { |
| 122 | 122 | $message = glsr( Template::class )->build( 'templates/'.$email['template'], [ |
| 123 | 123 | 'context' => $email['template-tags'], |
| 124 | - ]); |
|
| 124 | + ] ); |
|
| 125 | 125 | } |
| 126 | - if( !isset( $message )) { |
|
| 126 | + if( !isset($message) ) { |
|
| 127 | 127 | $message = $email['message']; |
| 128 | 128 | } |
| 129 | 129 | $message = $email['before'].$message.$email['after']; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $message = str_replace( ']]>', ']]>', $message ); |
| 135 | 135 | $message = glsr( Template::class )->build( 'email/index', [ |
| 136 | 136 | 'context' => ['message' => $message], |
| 137 | - ]); |
|
| 137 | + ] ); |
|
| 138 | 138 | return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | 'to' => '', |
| 161 | 161 | ]; |
| 162 | 162 | $email = shortcode_atts( $defaults, $email ); |
| 163 | - if( empty( $email['reply-to'] )) { |
|
| 163 | + if( empty($email['reply-to']) ) { |
|
| 164 | 164 | $email['reply-to'] = $email['from']; |
| 165 | 165 | } |
| 166 | 166 | return apply_filters( 'site-reviews/email/compose', $email, $this ); |
@@ -64,7 +64,9 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function send() |
| 66 | 66 | { |
| 67 | - if( !$this->message || !$this->subject || !$this->to )return; |
|
| 67 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 68 | 70 | $sent = wp_mail( |
| 69 | 71 | $this->to, |
| 70 | 72 | $this->subject, |
@@ -83,7 +85,9 @@ discard block |
||
| 83 | 85 | */ |
| 84 | 86 | public function buildPlainTextMessage( $phpmailer ) |
| 85 | 87 | { |
| 86 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
| 88 | + if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody )) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 87 | 91 | $message = $this->stripHtmlTags( $phpmailer->Body ); |
| 88 | 92 | $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
| 89 | 93 | } |