@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | : $this->$method( $id ); |
| 24 | 24 | return glsr( Template::class )->build( 'pages/settings/'.$id, [ |
| 25 | 25 | 'context' => $context, |
| 26 | - ]); |
|
| 26 | + ] ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | protected function getFieldDefault( array $field ) |
| 33 | 33 | { |
| 34 | - return isset( $field['default'] ) |
|
| 34 | + return isset($field['default']) |
|
| 35 | 35 | ? $field['default'] |
| 36 | 36 | : ''; |
| 37 | 37 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | protected function getSettingFields( $path ) |
| 43 | 43 | { |
| 44 | 44 | $settings = glsr( DefaultsManager::class )->settings(); |
| 45 | - return array_filter( $settings, function( $key ) use( $path ) { |
|
| 45 | + return array_filter( $settings, function( $key ) use($path) { |
|
| 46 | 46 | return glsr( Helper::class )->startsWith( $path, $key ); |
| 47 | 47 | }, ARRAY_FILTER_USE_KEY ); |
| 48 | 48 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected function getTemplateContext( $id ) |
| 55 | 55 | { |
| 56 | - $fields = $this->getSettingFields( $this->normalizeSettingPath( $id )); |
|
| 56 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 57 | 57 | $rows = ''; |
| 58 | 58 | foreach( $fields as $name => $field ) { |
| 59 | 59 | $field = wp_parse_args( $field, [ |
| 60 | 60 | 'is_setting' => true, |
| 61 | 61 | 'name' => $name, |
| 62 | - ]); |
|
| 63 | - $rows.= new Field( $this->normalize( $field )); |
|
| 62 | + ] ); |
|
| 63 | + $rows .= new Field( $this->normalize( $field ) ); |
|
| 64 | 64 | } |
| 65 | 65 | return [ |
| 66 | 66 | 'rows' => $rows, |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | protected function getTemplateContextForTranslations() |
| 74 | 74 | { |
| 75 | 75 | $translations = glsr( Translator::class )->renderAll(); |
| 76 | - $class = empty( $translations ) |
|
| 76 | + $class = empty($translations) |
|
| 77 | 77 | ? 'glsr-hidden' |
| 78 | 78 | : ''; |
| 79 | 79 | return [ |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $path, |
| 95 | 95 | glsr( Helper::class )->getPathValue( $path, glsr()->defaults ) |
| 96 | 96 | ); |
| 97 | - if( is_array( $expectedValue )) { |
|
| 97 | + if( is_array( $expectedValue ) ) { |
|
| 98 | 98 | return !in_array( $optionValue, $expectedValue ); |
| 99 | 99 | } |
| 100 | 100 | return $optionValue != $expectedValue; |
@@ -116,13 +116,13 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | protected function normalizeDependsOn( array $field ) |
| 118 | 118 | { |
| 119 | - if( !empty( $field['depends_on'] ) && is_array( $field['depends_on'] )) { |
|
| 119 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
| 120 | 120 | $path = key( $field['depends_on'] ); |
| 121 | 121 | $expectedValue = $field['depends_on'][$path]; |
| 122 | - $field['data-depends'] = json_encode([ |
|
| 122 | + $field['data-depends'] = json_encode( [ |
|
| 123 | 123 | 'name' => glsr( Helper::class )->convertPathToName( $path, OptionManager::databaseKey() ), |
| 124 | 124 | 'value' => $expectedValue, |
| 125 | - ], JSON_HEX_APOS|JSON_HEX_QUOT ); |
|
| 125 | + ], JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
| 126 | 126 | $field['is_hidden'] = $this->isFieldHidden( $path, $expectedValue ); |
| 127 | 127 | } |
| 128 | 128 | return $field; |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function normalizeLabelAndLegend( array $field ) |
| 135 | 135 | { |
| 136 | - if( !empty( $field['label'] )) { |
|
| 136 | + if( !empty($field['label']) ) { |
|
| 137 | 137 | $field['legend'] = $field['label']; |
| 138 | - unset( $field['label'] ); |
|
| 138 | + unset($field['label']); |
|
| 139 | 139 | } |
| 140 | 140 | else { |
| 141 | 141 | $field['is_valid'] = false; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function normalizeValue( array $field ) |
| 151 | 151 | { |
| 152 | - if( !isset( $field['value'] )) { |
|
| 152 | + if( !isset($field['value']) ) { |
|
| 153 | 153 | $field['value'] = glsr( OptionManager::class )->get( |
| 154 | 154 | $field['name'], |
| 155 | 155 | $this->getFieldDefault( $field ) |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | 'is_valid' => true, |
| 27 | 27 | 'is_widget' => false, |
| 28 | 28 | 'path' => '', |
| 29 | - ]); |
|
| 29 | + ] ); |
|
| 30 | 30 | $this->normalize(); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | if( !$this->field['is_valid'] )return; |
| 47 | 47 | if( $this->field['is_raw'] ) { |
| 48 | - return glsr( Builder::class )->{$this->field['type']}( $this->field ); |
|
| 48 | + return glsr( Builder::class )->{$this->field['type']}($this->field); |
|
| 49 | 49 | } |
| 50 | 50 | if( !$this->field['is_setting'] ) { |
| 51 | 51 | return $this->buildField(); |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | 'context' => [ |
| 74 | 74 | 'class' => $this->getFieldClass(), |
| 75 | 75 | 'errors' => $this->getFieldErrors(), |
| 76 | - 'field' => glsr( Builder::class )->{$this->field['type']}( $this->field ), |
|
| 76 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
| 77 | 77 | ], |
| 78 | - ]); |
|
| 78 | + ] ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | return glsr( Template::class )->build( 'partials/form/table-row', [ |
| 87 | 87 | 'context' => [ |
| 88 | 88 | 'class' => $this->getFieldClass(), |
| 89 | - 'field' => glsr( Builder::class )->{$this->field['type']}( $this->field ), |
|
| 89 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
| 90 | 90 | 'label' => glsr( Builder::class )->label( $this->field['legend'], ['for' => $this->field['id']] ), |
| 91 | 91 | ], |
| 92 | - ]); |
|
| 92 | + ] ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -98,16 +98,16 @@ discard block |
||
| 98 | 98 | protected function buildSettingMultiField() |
| 99 | 99 | { |
| 100 | 100 | $dependsOn = $this->getFieldDependsOn(); |
| 101 | - unset( $this->field['data-depends'] ); |
|
| 101 | + unset($this->field['data-depends']); |
|
| 102 | 102 | return glsr( Template::class )->build( 'partials/form/table-row-multiple', [ |
| 103 | 103 | 'context' => [ |
| 104 | 104 | 'class' => $this->getFieldClass(), |
| 105 | 105 | 'depends_on' => $dependsOn, |
| 106 | - 'field' => glsr( Builder::class )->{$this->field['type']}( $this->field ), |
|
| 106 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
| 107 | 107 | 'label' => glsr( Builder::class )->label( $this->field['legend'], ['for' => $this->field['id']] ), |
| 108 | 108 | 'legend' => $this->field['legend'], |
| 109 | 109 | ], |
| 110 | - ]); |
|
| 110 | + ] ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -116,13 +116,13 @@ discard block |
||
| 116 | 116 | protected function getFieldClass() |
| 117 | 117 | { |
| 118 | 118 | $classes = []; |
| 119 | - if( !empty( $this->field['errors'] )) { |
|
| 119 | + if( !empty($this->field['errors']) ) { |
|
| 120 | 120 | $classes[] = 'glsr-has-error'; |
| 121 | 121 | } |
| 122 | 122 | if( $this->field['is_hidden'] ) { |
| 123 | 123 | $classes[] = 'hidden'; |
| 124 | 124 | } |
| 125 | - if( !empty( $this->field['required'] )) { |
|
| 125 | + if( !empty($this->field['required']) ) { |
|
| 126 | 126 | $classes[] = 'glsr-required'; |
| 127 | 127 | } |
| 128 | 128 | return implode( ' ', $classes ); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function getFieldDependsOn() |
| 135 | 135 | { |
| 136 | - return !empty( $this->field['data-depends'] ) |
|
| 136 | + return !empty($this->field['data-depends']) |
|
| 137 | 137 | ? $this->field['data-depends'] |
| 138 | 138 | : ''; |
| 139 | 139 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | protected function getFieldErrors() |
| 145 | 145 | { |
| 146 | - if( empty( $this->field['errors'] ) || !is_array( $this->field['errors'] ))return; |
|
| 146 | + if( empty($this->field['errors']) || !is_array( $this->field['errors'] ) )return; |
|
| 147 | 147 | $errors = array_reduce( $this->field['errors'], function( $carry, $error ) { |
| 148 | 148 | return $carry.glsr( Builder::class )->span( $error, ['class' => 'glsr-field-error'] ); |
| 149 | 149 | }); |
@@ -170,13 +170,13 @@ discard block |
||
| 170 | 170 | 'name', 'type', |
| 171 | 171 | ]; |
| 172 | 172 | foreach( $requiredValues as $value ) { |
| 173 | - if( isset( $this->field[$value] ))continue; |
|
| 173 | + if( isset($this->field[$value]) )continue; |
|
| 174 | 174 | $missingValues[] = $value; |
| 175 | 175 | $this->field['is_valid'] = false; |
| 176 | 176 | } |
| 177 | - if( !empty( $missingValues )) { |
|
| 177 | + if( !empty($missingValues) ) { |
|
| 178 | 178 | glsr_log() |
| 179 | - ->warning( 'Field is missing: '.implode( ', ', $missingValues )) |
|
| 179 | + ->warning( 'Field is missing: '.implode( ', ', $missingValues ) ) |
|
| 180 | 180 | ->info( $this->field ); |
| 181 | 181 | } |
| 182 | 182 | return $this->field['is_valid']; |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | if( !$this->isFieldValid() )return; |
| 191 | 191 | $this->field['path'] = $this->field['name']; |
| 192 | 192 | $className = glsr( Helper::class )->buildClassName( $this->field['type'], __NAMESPACE__.'\Fields' ); |
| 193 | - if( class_exists( $className )) { |
|
| 193 | + if( class_exists( $className ) ) { |
|
| 194 | 194 | $this->field = array_merge( |
| 195 | 195 | wp_parse_args( $this->field, $className::defaults() ), |
| 196 | 196 | $className::required() |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | protected function normalizeFieldId() |
| 207 | 207 | { |
| 208 | - if( isset( $this->field['id'] ) || $this->field['is_raw'] )return; |
|
| 208 | + if( isset($this->field['id']) || $this->field['is_raw'] )return; |
|
| 209 | 209 | $this->field['id'] = glsr( Helper::class )->convertPathToId( |
| 210 | 210 | $this->field['path'], |
| 211 | 211 | $this->getFieldPrefix() |
@@ -43,7 +43,9 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function build() |
| 45 | 45 | { |
| 46 | - if( !$this->field['is_valid'] )return; |
|
| 46 | + if( !$this->field['is_valid'] ) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | if( $this->field['is_raw'] ) { |
| 48 | 50 | return glsr( Builder::class )->{$this->field['type']}( $this->field ); |
| 49 | 51 | } |
@@ -143,7 +145,9 @@ discard block |
||
| 143 | 145 | */ |
| 144 | 146 | protected function getFieldErrors() |
| 145 | 147 | { |
| 146 | - if( empty( $this->field['errors'] ) || !is_array( $this->field['errors'] ))return; |
|
| 148 | + if( empty( $this->field['errors'] ) || !is_array( $this->field['errors'] )) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 147 | 151 | $errors = array_reduce( $this->field['errors'], function( $carry, $error ) { |
| 148 | 152 | return $carry.glsr( Builder::class )->span( $error, ['class' => 'glsr-field-error'] ); |
| 149 | 153 | }); |
@@ -170,7 +174,9 @@ discard block |
||
| 170 | 174 | 'name', 'type', |
| 171 | 175 | ]; |
| 172 | 176 | foreach( $requiredValues as $value ) { |
| 173 | - if( isset( $this->field[$value] ))continue; |
|
| 177 | + if( isset( $this->field[$value] )) { |
|
| 178 | + continue; |
|
| 179 | + } |
|
| 174 | 180 | $missingValues[] = $value; |
| 175 | 181 | $this->field['is_valid'] = false; |
| 176 | 182 | } |
@@ -187,7 +193,9 @@ discard block |
||
| 187 | 193 | */ |
| 188 | 194 | protected function normalize() |
| 189 | 195 | { |
| 190 | - if( !$this->isFieldValid() )return; |
|
| 196 | + if( !$this->isFieldValid() ) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 191 | 199 | $this->field['path'] = $this->field['name']; |
| 192 | 200 | $className = glsr( Helper::class )->buildClassName( $this->field['type'], __NAMESPACE__.'\Fields' ); |
| 193 | 201 | if( class_exists( $className )) { |
@@ -205,7 +213,9 @@ discard block |
||
| 205 | 213 | */ |
| 206 | 214 | protected function normalizeFieldId() |
| 207 | 215 | { |
| 208 | - if( isset( $this->field['id'] ) || $this->field['is_raw'] )return; |
|
| 216 | + if( isset( $this->field['id'] ) || $this->field['is_raw'] ) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 209 | 219 | $this->field['id'] = glsr( Helper::class )->convertPathToId( |
| 210 | 220 | $this->field['path'], |
| 211 | 221 | $this->getFieldPrefix() |
@@ -33,10 +33,10 @@ discard block |
||
| 33 | 33 | foreach( glsr( Database::class )->getReviews( $this->args )->reviews as $review ) { |
| 34 | 34 | $reviews[] = $this->buildReview( $review ); |
| 35 | 35 | } |
| 36 | - if( !empty( $reviews )) { |
|
| 36 | + if( !empty($reviews) ) { |
|
| 37 | 37 | array_walk( $reviews, function( &$review ) { |
| 38 | - unset( $review['@context'] ); |
|
| 39 | - unset( $review['itemReviewed'] ); |
|
| 38 | + unset($review['@context']); |
|
| 39 | + unset($review['itemReviewed']); |
|
| 40 | 40 | }); |
| 41 | 41 | $schema['review'] = $reviews; |
| 42 | 42 | } |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | public function buildReview( $review ) |
| 51 | 51 | { |
| 52 | 52 | $schema = SchemaOrg::Review() |
| 53 | - ->doIf( !in_array( 'title', $this->args['hide'] ), function( ReviewSchema $schema ) use( $review ) { |
|
| 53 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( ReviewSchema $schema ) use($review) { |
|
| 54 | 54 | $schema->name( $review->title ); |
| 55 | 55 | }) |
| 56 | - ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( ReviewSchema $schema ) use( $review ) { |
|
| 56 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( ReviewSchema $schema ) use($review) { |
|
| 57 | 57 | $schema->reviewBody( $review->content ); |
| 58 | 58 | }) |
| 59 | - ->datePublished(( new DateTime( $review->date ))->format( DateTime::ISO8601 )) |
|
| 59 | + ->datePublished( (new DateTime( $review->date ))->format( DateTime::ISO8601 ) ) |
|
| 60 | 60 | ->author( SchemaOrg::Person() |
| 61 | 61 | ->name( $review->author ) |
| 62 | 62 | ) |
| 63 | 63 | ->itemReviewed( $this->getSchemaType() |
| 64 | 64 | ->name( $this->getThingName() ) |
| 65 | 65 | ); |
| 66 | - if( !empty( $review->rating )) { |
|
| 66 | + if( !empty($review->rating) ) { |
|
| 67 | 67 | $schema->reviewRating( SchemaOrg::Rating() |
| 68 | 68 | ->ratingValue( $review->rating ) |
| 69 | 69 | ->bestRating( Rating::MAX_RATING ) |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function buildSummary( $args = null ) |
| 81 | 81 | { |
| 82 | - if( is_array( $args )) { |
|
| 82 | + if( is_array( $args ) ) { |
|
| 83 | 83 | $this->args = $args; |
| 84 | 84 | } |
| 85 | 85 | $schema = $this->getSchemaType() |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | ->image( $this->getThingImage() ) |
| 92 | 92 | ->url( $this->getThingUrl() ); |
| 93 | 93 | $count = $this->getReviewCount(); |
| 94 | - if( !empty( $count )) { |
|
| 94 | + if( !empty($count) ) { |
|
| 95 | 95 | $schema->aggregateRating( SchemaOrg::AggregateRating() |
| 96 | 96 | ->ratingValue( $this->getRatingValue() ) |
| 97 | 97 | ->reviewCount( $count ) |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function render() |
| 111 | 111 | { |
| 112 | - if( is_null( glsr()->schemas ))return; |
|
| 112 | + if( is_null( glsr()->schemas ) )return; |
|
| 113 | 113 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 114 | 114 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 115 | 115 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
| 116 | - )); |
|
| 116 | + ) ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function store( array $schema ) |
| 123 | 123 | { |
| 124 | - $schemas = (array) glsr()->schemas; |
|
| 124 | + $schemas = (array)glsr()->schemas; |
|
| 125 | 125 | $schemas[] = $schema; |
| 126 | - glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ))); |
|
| 126 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | protected function getReviews( $force = false ) |
| 150 | 150 | { |
| 151 | - if( !isset( $this->reviews ) || $force ) { |
|
| 151 | + if( !isset($this->reviews) || $force ) { |
|
| 152 | 152 | $args = wp_parse_args( ['count' => -1], $this->args ); |
| 153 | 153 | $this->reviews = glsr( Database::class )->getReviews( $args )->reviews; |
| 154 | 154 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function getSchemaOption( $option, $fallback ) |
| 164 | 164 | { |
| 165 | - if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ))) { |
|
| 165 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
| 166 | 166 | return $schemaOption; |
| 167 | 167 | } |
| 168 | 168 | $default = glsr( OptionManager::class )->get( 'settings.reviews.schema.'.$option.'.default', $fallback ); |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | switch( $option ) { |
| 187 | 187 | case 'description': |
| 188 | 188 | $post = get_post(); |
| 189 | - if( !( $post instanceof WP_Post )) { |
|
| 189 | + if( !($post instanceof WP_Post) ) { |
|
| 190 | 190 | return ''; |
| 191 | 191 | } |
| 192 | - $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt )); |
|
| 193 | - return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 )); |
|
| 192 | + $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ) ); |
|
| 193 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
| 194 | 194 | case 'image': |
| 195 | 195 | return (string)get_the_post_thumbnail_url( null, 'large' ); |
| 196 | 196 | case 'name': |
@@ -109,7 +109,9 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function render() |
| 111 | 111 | { |
| 112 | - if( is_null( glsr()->schemas ))return; |
|
| 112 | + if( is_null( glsr()->schemas )) { |
|
| 113 | + return; |
|
| 114 | + } |
|
| 113 | 115 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 114 | 116 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 115 | 117 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
@@ -182,7 +184,9 @@ discard block |
||
| 182 | 184 | if( $value != $fallback ) { |
| 183 | 185 | return $value; |
| 184 | 186 | } |
| 185 | - if( !is_single() && !is_page() )return; |
|
| 187 | + if( !is_single() && !is_page() ) { |
|
| 188 | + return; |
|
| 189 | + } |
|
| 186 | 190 | switch( $option ) { |
| 187 | 191 | case 'description': |
| 188 | 192 | $post = get_post(); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | foreach( $this->rules as $attribute => $rules ) { |
| 74 | 74 | foreach( $rules as $rule ) { |
| 75 | 75 | $this->validateAttribute( $attribute, $rule ); |
| 76 | - if( $this->shouldStopValidating( $attribute ))break; |
|
| 76 | + if( $this->shouldStopValidating( $attribute ) )break; |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | return $this->errors; |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function validateAttribute( $attribute, $rule ) |
| 90 | 90 | { |
| 91 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
| 91 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
| 92 | 92 | if( $rule == '' )return; |
| 93 | 93 | $value = $this->getValue( $attribute ); |
| 94 | - if( !method_exists( $this, $method = 'validate'.$rule )) { |
|
| 94 | + if( !method_exists( $this, $method = 'validate'.$rule ) ) { |
|
| 95 | 95 | throw new BadMethodCallException( "Method [$method] does not exist." ); |
| 96 | 96 | } |
| 97 | - if( !$this->$method( $attribute, $value, $parameters )) { |
|
| 97 | + if( !$this->$method( $attribute, $value, $parameters ) ) { |
|
| 98 | 98 | $this->addFailure( $attribute, $rule, $parameters ); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | protected function getMessage( $attribute, $rule, array $parameters ) |
| 145 | 145 | { |
| 146 | - if( in_array( $rule, $this->sizeRules )) { |
|
| 146 | + if( in_array( $rule, $this->sizeRules ) ) { |
|
| 147 | 147 | return $this->getSizeMessage( $attribute, $rule, $parameters ); |
| 148 | 148 | } |
| 149 | 149 | $lowerRule = glsr( Helper::class )->snakeCase( $rule ); |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | protected function getRule( $attribute, $rules ) |
| 160 | 160 | { |
| 161 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
| 162 | - $rules = (array) $rules; |
|
| 161 | + if( !array_key_exists( $attribute, $this->rules ) )return; |
|
| 162 | + $rules = (array)$rules; |
|
| 163 | 163 | foreach( $this->rules[$attribute] as $rule ) { |
| 164 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
| 165 | - if( in_array( $rule, $rules )) { |
|
| 164 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
| 165 | + if( in_array( $rule, $rules ) ) { |
|
| 166 | 166 | return [$rule, $parameters]; |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | if( is_numeric( $value ) && $hasNumeric ) { |
| 181 | 181 | return $value; |
| 182 | 182 | } |
| 183 | - elseif( is_array( $value )) { |
|
| 183 | + elseif( is_array( $value ) ) { |
|
| 184 | 184 | return count( $value ); |
| 185 | 185 | } |
| 186 | 186 | return mb_strlen( $value ); |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | protected function getValue( $attribute ) |
| 209 | 209 | { |
| 210 | - if( isset( $this->data[$attribute] )) { |
|
| 210 | + if( isset($this->data[$attribute]) ) { |
|
| 211 | 211 | return $this->data[$attribute]; |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | protected function hasRule( $attribute, $rules ) |
| 222 | 222 | { |
| 223 | - return !is_null( $this->getRule( $attribute, $rules )); |
|
| 223 | + return !is_null( $this->getRule( $attribute, $rules ) ); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -259,11 +259,11 @@ discard block |
||
| 259 | 259 | $parameters = []; |
| 260 | 260 | // example: {rule}:{parameters} |
| 261 | 261 | if( strpos( $rule, ':' ) !== false ) { |
| 262 | - list( $rule, $parameter ) = explode( ':', $rule, 2 ); |
|
| 262 | + list($rule, $parameter) = explode( ':', $rule, 2 ); |
|
| 263 | 263 | // example: {parameter1,parameter2,...} |
| 264 | 264 | $parameters = $this->parseParameters( $rule, $parameter ); |
| 265 | 265 | } |
| 266 | - $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ))); |
|
| 266 | + $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ) ) ); |
|
| 267 | 267 | $rule = str_replace( ' ', '', $rule ); |
| 268 | 268 | return [$rule, $parameters]; |
| 269 | 269 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | protected function shouldStopValidating( $attribute ) |
| 291 | 291 | { |
| 292 | 292 | return $this->hasRule( $attribute, $this->implicitRules ) |
| 293 | - && isset( $this->failedRules[$attribute] ) |
|
| 293 | + && isset($this->failedRules[$attribute]) |
|
| 294 | 294 | && array_intersect( array_keys( $this->failedRules[$attribute] ), $this->implicitRules ); |
| 295 | 295 | } |
| 296 | 296 | |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | 'regex' => __( 'The format is invalid.', 'site-reviews' ), |
| 316 | 316 | 'required' => __( 'This field is required.', 'site-reviews' ), |
| 317 | 317 | ]; |
| 318 | - $message = isset( $strings[$key] ) |
|
| 318 | + $message = isset($strings[$key]) |
|
| 319 | 319 | ? $strings[$key] |
| 320 | 320 | : false; |
| 321 | 321 | if( !$message )return; |
| 322 | - if( method_exists( $this, $method = 'replace'.$rule )) { |
|
| 322 | + if( method_exists( $this, $method = 'replace'.$rule ) ) { |
|
| 323 | 323 | $message = $this->$method( $message, $parameters ); |
| 324 | 324 | } |
| 325 | 325 | return $message; |
@@ -73,7 +73,9 @@ discard block |
||
| 73 | 73 | foreach( $this->rules as $attribute => $rules ) { |
| 74 | 74 | foreach( $rules as $rule ) { |
| 75 | 75 | $this->validateAttribute( $attribute, $rule ); |
| 76 | - if( $this->shouldStopValidating( $attribute ))break; |
|
| 76 | + if( $this->shouldStopValidating( $attribute )) { |
|
| 77 | + break; |
|
| 78 | + } |
|
| 77 | 79 | } |
| 78 | 80 | } |
| 79 | 81 | return $this->errors; |
@@ -89,7 +91,9 @@ discard block |
||
| 89 | 91 | public function validateAttribute( $attribute, $rule ) |
| 90 | 92 | { |
| 91 | 93 | list( $rule, $parameters ) = $this->parseRule( $rule ); |
| 92 | - if( $rule == '' )return; |
|
| 94 | + if( $rule == '' ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 93 | 97 | $value = $this->getValue( $attribute ); |
| 94 | 98 | if( !method_exists( $this, $method = 'validate'.$rule )) { |
| 95 | 99 | throw new BadMethodCallException( "Method [$method] does not exist." ); |
@@ -158,7 +162,9 @@ discard block |
||
| 158 | 162 | */ |
| 159 | 163 | protected function getRule( $attribute, $rules ) |
| 160 | 164 | { |
| 161 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
| 165 | + if( !array_key_exists( $attribute, $this->rules )) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 162 | 168 | $rules = (array) $rules; |
| 163 | 169 | foreach( $this->rules[$attribute] as $rule ) { |
| 164 | 170 | list( $rule, $parameters ) = $this->parseRule( $rule ); |
@@ -318,7 +324,9 @@ discard block |
||
| 318 | 324 | $message = isset( $strings[$key] ) |
| 319 | 325 | ? $strings[$key] |
| 320 | 326 | : false; |
| 321 | - if( !$message )return; |
|
| 327 | + if( !$message ) { |
|
| 328 | + return; |
|
| 329 | + } |
|
| 322 | 330 | if( method_exists( $this, $method = 'replace'.$rule )) { |
| 323 | 331 | $message = $this->$method( $message, $parameters ); |
| 324 | 332 | } |
@@ -102,7 +102,9 @@ discard block |
||
| 102 | 102 | protected function sendNotification( $postId ) |
| 103 | 103 | { |
| 104 | 104 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 105 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 105 | + if( !in_array( $notificationType, ['default','custom','webhook'] )) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 106 | 108 | $assignedToTitle = get_the_title( (int)$this->command->assigned_to ); |
| 107 | 109 | $notificationSubject = _nx( |
| 108 | 110 | 'New %s-star review', |
@@ -150,7 +152,9 @@ discard block |
||
| 150 | 152 | */ |
| 151 | 153 | protected function sendWebhookNotification( array $args ) |
| 152 | 154 | { |
| 153 | - if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )))return; |
|
| 155 | + if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' ))) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 154 | 158 | $notification = $this->createWebhookNotification( $args ); |
| 155 | 159 | $result = wp_remote_post( $endpoint, [ |
| 156 | 160 | 'blocking' => false, |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | $this->sendNotification( $postId ); |
| 33 | 33 | do_action( 'site-reviews/local/review/submitted', $postId, $command ); |
| 34 | - glsr( Session::class )->set( $command->form_id.'message', __( 'Your review has been submitted!', 'site-reviews' )); |
|
| 34 | + glsr( Session::class )->set( $command->form_id.'message', __( 'Your review has been submitted!', 'site-reviews' ) ); |
|
| 35 | 35 | if( $command->ajax_request ) { |
| 36 | 36 | glsr( Session::class )->clear(); |
| 37 | 37 | return; |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | if( $this->command->author ) { |
| 82 | 82 | $fields[] = ['value' => trim( $this->command->author.$this->command->email.' - '.$this->command->ip_address )]; |
| 83 | 83 | } |
| 84 | - $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ))]; |
|
| 85 | - return json_encode([ |
|
| 84 | + $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ) )]; |
|
| 85 | + return json_encode( [ |
|
| 86 | 86 | 'icon_url' => glsr()->url( 'assets/img/icon.png' ), |
| 87 | 87 | 'username' => glsr()->name, |
| 88 | 88 | 'attachments' => [[ |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | 'fallback' => $this->createEmailNotification( $args )->read( 'plaintext' ), |
| 92 | 92 | 'fields' => $fields, |
| 93 | 93 | ]], |
| 94 | - ]); |
|
| 94 | + ] ); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | protected function sendNotification( $postId ) |
| 102 | 102 | { |
| 103 | 103 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 104 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 104 | + if( !in_array( $notificationType, ['default', 'custom', 'webhook'] ) )return; |
|
| 105 | 105 | $assignedToTitle = get_the_title( (int)$this->command->assigned_to ); |
| 106 | 106 | $notificationSubject = _nx( |
| 107 | 107 | 'New %s-star review', |
| 108 | 108 | 'New %s-star review of: %s', |
| 109 | - intval( empty( $assignedToTitle )), |
|
| 109 | + intval( empty($assignedToTitle) ), |
|
| 110 | 110 | 'The text is different depending on whether or not the review has been assigned to a post.', |
| 111 | 111 | 'site-reviews' |
| 112 | 112 | ); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | sprintf( $notificationSubject, $this->command->rating, $assignedToTitle ) |
| 116 | 116 | ); |
| 117 | 117 | $args = [ |
| 118 | - 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $postId ))), |
|
| 118 | + 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $postId ) ) ), |
|
| 119 | 119 | 'notification_title' => $notificationTitle, |
| 120 | 120 | 'notification_type' => $notificationType, |
| 121 | 121 | ]; |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | $args['recipient'] = $args['notification_type'] !== 'default' |
| 134 | 134 | ? glsr( OptionManager::class )->get( 'settings.general.notification_email' ) |
| 135 | 135 | : get_option( 'admin_email' ); |
| 136 | - $result = !empty( $args['recipient'] ) |
|
| 136 | + $result = !empty($args['recipient']) |
|
| 137 | 137 | ? $this->createEmailNotification( $args )->send() |
| 138 | 138 | : false; |
| 139 | - if( !is_bool( $result )) { |
|
| 140 | - glsr_log()->error( __( 'Email notification was not sent: missing email, subject, or message.', 'site-reviews' )); |
|
| 139 | + if( !is_bool( $result ) ) { |
|
| 140 | + glsr_log()->error( __( 'Email notification was not sent: missing email, subject, or message.', 'site-reviews' ) ); |
|
| 141 | 141 | } |
| 142 | 142 | if( $result === false ) { |
| 143 | - glsr_log()->error( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' )); |
|
| 143 | + glsr_log()->error( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' ) ); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function sendWebhookNotification( array $args ) |
| 151 | 151 | { |
| 152 | - if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )))return; |
|
| 152 | + if( !($endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )) )return; |
|
| 153 | 153 | $notification = $this->createWebhookNotification( $args ); |
| 154 | 154 | $result = wp_remote_post( $endpoint, [ |
| 155 | 155 | 'blocking' => false, |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | 'redirection' => 5, |
| 161 | 161 | 'sslverify' => false, |
| 162 | 162 | 'timeout' => 45, |
| 163 | - ]); |
|
| 164 | - if( is_wp_error( $result )) { |
|
| 163 | + ] ); |
|
| 164 | + if( is_wp_error( $result ) ) { |
|
| 165 | 165 | glsr_log()->error( $result->get_error_message() ); |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | public function routeAdminPostRequest() |
| 17 | 17 | { |
| 18 | 18 | $request = $this->getRequest(); |
| 19 | - if( !$this->isValidPostRequest( $request ))return; |
|
| 19 | + if( !$this->isValidPostRequest( $request ) )return; |
|
| 20 | 20 | $this->checkAdminNonce( $request['action'] ); |
| 21 | 21 | $this->routeRequest( 'admin', $request['action'], $request ); |
| 22 | 22 | } |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | public function routeAjaxRequest() |
| 30 | 30 | { |
| 31 | 31 | $request = $this->getRequest(); |
| 32 | - if( !isset( $request['action'] )) { |
|
| 32 | + if( !isset($request['action']) ) { |
|
| 33 | 33 | glsr_log()->error( 'The AJAX request must include an action' )->info( $request ); |
| 34 | 34 | wp_die(); |
| 35 | 35 | } |
| 36 | - if( !isset( $request['nonce'] )) { |
|
| 36 | + if( !isset($request['nonce']) ) { |
|
| 37 | 37 | glsr_log()->error( 'The AJAX request must include a nonce' )->info( $request ); |
| 38 | 38 | wp_die(); |
| 39 | 39 | } |
| 40 | - if( !wp_verify_nonce( $request['nonce'], $request['action'] )) { |
|
| 40 | + if( !wp_verify_nonce( $request['nonce'], $request['action'] ) ) { |
|
| 41 | 41 | glsr_log()->error( 'Nonce check failed for ajax request' )->info( $request ); |
| 42 | 42 | wp_die( -1, 403 ); |
| 43 | 43 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | if( is_admin() )return; |
| 55 | 55 | $request = $this->getRequest(); |
| 56 | - if( !$this->isValidPostRequest( $request ))return; |
|
| 57 | - if( !wp_verify_nonce( $request['_wpnonce'], $request['action'] )) { |
|
| 56 | + if( !$this->isValidPostRequest( $request ) )return; |
|
| 57 | + if( !wp_verify_nonce( $request['_wpnonce'], $request['action'] ) ) { |
|
| 58 | 58 | glsr_log()->error( 'Nonce check failed for public request' )->info( $request ); |
| 59 | 59 | return; |
| 60 | 60 | } |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | foreach( ['request', Application::ID] as $key ) { |
| 94 | 94 | $request = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
| 95 | - if( !empty( $request ))break; |
|
| 95 | + if( !empty($request) )break; |
|
| 96 | 96 | } |
| 97 | - if( isset( $request[Application::ID]['action'] )) { |
|
| 97 | + if( isset($request[Application::ID]['action']) ) { |
|
| 98 | 98 | $request = $request[Application::ID]; |
| 99 | 99 | } |
| 100 | 100 | return (array)$request; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | protected function isValidPostRequest( array $request = [] ) |
| 107 | 107 | { |
| 108 | - return !empty( $request['action'] ) && empty( filter_input( INPUT_POST, 'ajax_request' )); |
|
| 108 | + return !empty($request['action']) && empty(filter_input( INPUT_POST, 'ajax_request' )); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | protected function routeRequest( $type, $action, array $request = [] ) |
| 117 | 117 | { |
| 118 | - $controller = glsr( glsr( Helper::class )->buildClassName( $type.'-controller', 'Controllers' )); |
|
| 118 | + $controller = glsr( glsr( Helper::class )->buildClassName( $type.'-controller', 'Controllers' ) ); |
|
| 119 | 119 | $method = glsr( Helper::class )->buildMethodName( $action, 'router' ); |
| 120 | 120 | $request = apply_filters( 'site-reviews/route/request', $request, $action, $type ); |
| 121 | - if( is_callable( [$controller, $method] )) { |
|
| 121 | + if( is_callable( [$controller, $method] ) ) { |
|
| 122 | 122 | call_user_func( [$controller, $method], $request ); |
| 123 | 123 | return; |
| 124 | 124 | } |
@@ -16,7 +16,9 @@ discard block |
||
| 16 | 16 | public function routeAdminPostRequest() |
| 17 | 17 | { |
| 18 | 18 | $request = $this->getRequest(); |
| 19 | - if( !$this->isValidPostRequest( $request ))return; |
|
| 19 | + if( !$this->isValidPostRequest( $request )) { |
|
| 20 | + return; |
|
| 21 | + } |
|
| 20 | 22 | $this->checkAdminNonce( $request['action'] ); |
| 21 | 23 | $this->routeRequest( 'admin', $request['action'], $request ); |
| 22 | 24 | } |
@@ -51,9 +53,13 @@ discard block |
||
| 51 | 53 | */ |
| 52 | 54 | public function routePublicPostRequest() |
| 53 | 55 | { |
| 54 | - if( is_admin() )return; |
|
| 56 | + if( is_admin() ) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 55 | 59 | $request = $this->getRequest(); |
| 56 | - if( !$this->isValidPostRequest( $request ))return; |
|
| 60 | + if( !$this->isValidPostRequest( $request )) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 57 | 63 | if( !wp_verify_nonce( $request['_wpnonce'], $request['action'] )) { |
| 58 | 64 | glsr_log()->error( 'Nonce check failed for public request' )->info( $request ); |
| 59 | 65 | return; |
@@ -67,7 +73,9 @@ discard block |
||
| 67 | 73 | public function routeWebhookRequest() |
| 68 | 74 | { |
| 69 | 75 | $request = filter_input( INPUT_GET, Application::PREFIX.'hook' ); |
| 70 | - if( !$request )return; |
|
| 76 | + if( !$request ) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 71 | 79 | // @todo manage webhook here |
| 72 | 80 | } |
| 73 | 81 | |
@@ -92,7 +100,9 @@ discard block |
||
| 92 | 100 | { |
| 93 | 101 | foreach( ['request', Application::ID] as $key ) { |
| 94 | 102 | $request = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
| 95 | - if( !empty( $request ))break; |
|
| 103 | + if( !empty( $request )) { |
|
| 104 | + break; |
|
| 105 | + } |
|
| 96 | 106 | } |
| 97 | 107 | if( isset( $request[Application::ID]['action'] )) { |
| 98 | 108 | $request = $request[Application::ID]; |
@@ -27,21 +27,21 @@ discard block |
||
| 27 | 27 | public function __construct( $input ) |
| 28 | 28 | { |
| 29 | 29 | $this->request = $input; |
| 30 | - $this->ajax_request = isset( $input['ajax_request'] ); |
|
| 30 | + $this->ajax_request = isset($input['ajax_request']); |
|
| 31 | 31 | $this->assigned_to = $this->getNumeric( 'assign_to' ); |
| 32 | - $this->author = sanitize_text_field( $this->get( 'name' )); |
|
| 33 | - $this->avatar = get_avatar_url( $this->get( 'email' )); |
|
| 34 | - $this->blacklisted = isset( $input['blacklisted'] ); |
|
| 35 | - $this->category = sanitize_key( $this->get( 'category' )); |
|
| 36 | - $this->content = sanitize_textarea_field( $this->get( 'content' )); |
|
| 32 | + $this->author = sanitize_text_field( $this->get( 'name' ) ); |
|
| 33 | + $this->avatar = get_avatar_url( $this->get( 'email' ) ); |
|
| 34 | + $this->blacklisted = isset($input['blacklisted']); |
|
| 35 | + $this->category = sanitize_key( $this->get( 'category' ) ); |
|
| 36 | + $this->content = sanitize_textarea_field( $this->get( 'content' ) ); |
|
| 37 | 37 | $this->custom = $this->getCustom(); |
| 38 | - $this->email = sanitize_email( $this->get( 'email' )); |
|
| 39 | - $this->form_id = sanitize_key( $this->get( 'form_id' )); |
|
| 38 | + $this->email = sanitize_email( $this->get( 'email' ) ); |
|
| 39 | + $this->form_id = sanitize_key( $this->get( 'form_id' ) ); |
|
| 40 | 40 | $this->ip_address = $this->get( 'ip_address' ); |
| 41 | - $this->rating = intval( $this->get( 'rating' )); |
|
| 41 | + $this->rating = intval( $this->get( 'rating' ) ); |
|
| 42 | 42 | $this->referrer = $this->get( 'referrer' ); |
| 43 | - $this->terms = isset( $input['terms'] ); |
|
| 44 | - $this->title = sanitize_text_field( $this->get( 'title' )); |
|
| 43 | + $this->terms = isset($input['terms']); |
|
| 44 | + $this->title = sanitize_text_field( $this->get( 'title' ) ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | protected function get( $key ) |
| 52 | 52 | { |
| 53 | - return isset( $this->request[$key] ) |
|
| 53 | + return isset($this->request[$key]) |
|
| 54 | 54 | ? (string)$this->request[$key] |
| 55 | 55 | : ''; |
| 56 | 56 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | ]; |
| 68 | 68 | $custom = $this->request; |
| 69 | 69 | foreach( $unset as $value ) { |
| 70 | - unset( $custom[$value] ); |
|
| 70 | + unset($custom[$value]); |
|
| 71 | 71 | } |
| 72 | 72 | return $custom; |
| 73 | 73 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $this->validateBlacklist(); |
| 60 | 60 | $this->validateAkismet(); |
| 61 | 61 | $this->validateRecaptcha(); |
| 62 | - if( !empty( $this->error )) { |
|
| 62 | + if( !empty($this->error) ) { |
|
| 63 | 63 | $this->setSessionValues( 'message', $this->error ); |
| 64 | 64 | } |
| 65 | 65 | return $this; |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function validateRequest( array $request ) |
| 72 | 72 | { |
| 73 | - if( !$this->isRequestValid( $request )) { |
|
| 73 | + if( !$this->isRequestValid( $request ) ) { |
|
| 74 | 74 | $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
| 75 | 75 | return $request; |
| 76 | 76 | } |
| 77 | - if( empty( $request['title'] )) { |
|
| 77 | + if( empty($request['title']) ) { |
|
| 78 | 78 | $request['title'] = __( 'No Title', 'site-reviews' ); |
| 79 | 79 | } |
| 80 | 80 | return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES ), |
| 100 | 100 | $this->getOption( 'settings.submissions.required', [] ) |
| 101 | 101 | ); |
| 102 | - $excluded = isset( $request['excluded'] ) |
|
| 102 | + $excluded = isset($request['excluded']) |
|
| 103 | 103 | ? (array)json_decode( $request['excluded'] ) |
| 104 | 104 | : []; |
| 105 | - return array_diff_key( $rules, array_flip( $excluded )); |
|
| 105 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | return true; |
| 116 | 116 | } |
| 117 | 117 | $recaptchaResponse = filter_input( INPUT_POST, 'g-recaptcha-response' ); // @todo site-reviews[g-recaptcha-response] |
| 118 | - if( empty( $recaptchaResponse )) { |
|
| 118 | + if( empty($recaptchaResponse) ) { |
|
| 119 | 119 | return null; //if response is empty we need to return null |
| 120 | 120 | } |
| 121 | 121 | if( $integration == 'custom' ) { |
| 122 | 122 | return $this->isRecaptchaValid( $recaptchaResponse ); |
| 123 | 123 | } |
| 124 | 124 | if( $integration == 'invisible-recaptcha' ) { |
| 125 | - return boolval( apply_filters( 'google_invre_is_valid_request_filter', true )); |
|
| 125 | + return boolval( apply_filters( 'google_invre_is_valid_request_filter', true ) ); |
|
| 126 | 126 | } |
| 127 | 127 | return false; |
| 128 | 128 | } |
@@ -132,17 +132,17 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | protected function isRecaptchaValid( $recaptchaResponse ) |
| 134 | 134 | { |
| 135 | - $endpoint = add_query_arg([ |
|
| 135 | + $endpoint = add_query_arg( [ |
|
| 136 | 136 | 'remoteip' => glsr( Helper::class )->getIpAddress(), |
| 137 | 137 | 'response' => $recaptchaResponse, |
| 138 | 138 | 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
| 139 | 139 | ], 'https://www.google.com/recaptcha/api/siteverify' ); |
| 140 | - if( is_wp_error( $response = wp_remote_get( $endpoint ))) { |
|
| 140 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
| 141 | 141 | glsr_log()->error( $response->get_error_message() ); |
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | - $response = json_decode( wp_remote_retrieve_body( $response )); |
|
| 145 | - if( !empty( $response->success )) { |
|
| 144 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
| 145 | + if( !empty($response->success) ) { |
|
| 146 | 146 | return boolval( $response->success ); |
| 147 | 147 | } |
| 148 | 148 | $errorCodes = [ |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $rules = $this->getValidationRules( $request ); |
| 167 | 167 | $errors = glsr( Validator::class )->validate( $request, $rules ); |
| 168 | - if( empty( $errors )) { |
|
| 168 | + if( empty($errors) ) { |
|
| 169 | 169 | return true; |
| 170 | 170 | } |
| 171 | 171 | $this->setSessionValues( 'errors', $errors ); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
| 183 | 183 | { |
| 184 | 184 | glsr( Session::class )->set( $this->form_id.$type, $value ); |
| 185 | - if( !empty( $loggedMessage )) { |
|
| 185 | + if( !empty($loggedMessage) ) { |
|
| 186 | 186 | glsr_log()->warning( $loggedMessage ); |
| 187 | 187 | glsr_log()->warning( $this->request ); |
| 188 | 188 | } |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | protected function validateAkismet() |
| 195 | 195 | { |
| 196 | - if( !empty( $this->error ))return; |
|
| 197 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 196 | + if( !empty($this->error) )return; |
|
| 197 | + if( !glsr( Akismet::class )->isSpam( $this->request ) )return; |
|
| 198 | 198 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 199 | 199 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 200 | 200 | } |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | protected function validateBlacklist() |
| 206 | 206 | { |
| 207 | - if( !empty( $this->error ))return; |
|
| 208 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 207 | + if( !empty($this->error) )return; |
|
| 208 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) )return; |
|
| 209 | 209 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
| 210 | 210 | if( $blacklistAction == 'reject' ) { |
| 211 | 211 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | protected function validateCustom() |
| 222 | 222 | { |
| 223 | - if( !empty( $this->error ))return; |
|
| 223 | + if( !empty($this->error) )return; |
|
| 224 | 224 | $validated = apply_filters( 'site-reviews/validate/review/submission', true, $this->request ); |
| 225 | 225 | if( $validated === true )return; |
| 226 | 226 | $this->setSessionValues( 'errors', [] ); |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | protected function validateHoneyPot() |
| 237 | 237 | { |
| 238 | - if( !empty( $this->error ))return; |
|
| 239 | - if( empty( $this->request['gotcha'] ))return; |
|
| 238 | + if( !empty($this->error) )return; |
|
| 239 | + if( empty($this->request['gotcha']) )return; |
|
| 240 | 240 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 241 | 241 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 242 | 242 | } |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | protected function validateRecaptcha() |
| 248 | 248 | { |
| 249 | - if( !empty( $this->error ))return; |
|
| 249 | + if( !empty($this->error) )return; |
|
| 250 | 250 | $isValid = $this->isRecaptchaResponseValid(); |
| 251 | - if( is_null( $isValid )) { |
|
| 251 | + if( is_null( $isValid ) ) { |
|
| 252 | 252 | $this->setSessionValues( 'recaptcha', true ); |
| 253 | 253 | $this->recaptchaIsUnset = true; |
| 254 | 254 | } |
@@ -193,8 +193,12 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | protected function validateAkismet() |
| 195 | 195 | { |
| 196 | - if( !empty( $this->error ))return; |
|
| 197 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 196 | + if( !empty( $this->error )) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 199 | + if( !glsr( Akismet::class )->isSpam( $this->request )) { |
|
| 200 | + return; |
|
| 201 | + } |
|
| 198 | 202 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 199 | 203 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 200 | 204 | } |
@@ -204,8 +208,12 @@ discard block |
||
| 204 | 208 | */ |
| 205 | 209 | protected function validateBlacklist() |
| 206 | 210 | { |
| 207 | - if( !empty( $this->error ))return; |
|
| 208 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 211 | + if( !empty( $this->error )) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request )) { |
|
| 215 | + return; |
|
| 216 | + } |
|
| 209 | 217 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
| 210 | 218 | if( $blacklistAction == 'reject' ) { |
| 211 | 219 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -220,9 +228,13 @@ discard block |
||
| 220 | 228 | */ |
| 221 | 229 | protected function validateCustom() |
| 222 | 230 | { |
| 223 | - if( !empty( $this->error ))return; |
|
| 231 | + if( !empty( $this->error )) { |
|
| 232 | + return; |
|
| 233 | + } |
|
| 224 | 234 | $validated = apply_filters( 'site-reviews/validate/review/submission', true, $this->request ); |
| 225 | - if( $validated === true )return; |
|
| 235 | + if( $validated === true ) { |
|
| 236 | + return; |
|
| 237 | + } |
|
| 226 | 238 | $this->setSessionValues( 'errors', [] ); |
| 227 | 239 | $this->setSessionValues( 'values', $this->request ); |
| 228 | 240 | $this->error = is_string( $validated ) |
@@ -235,8 +247,12 @@ discard block |
||
| 235 | 247 | */ |
| 236 | 248 | protected function validateHoneyPot() |
| 237 | 249 | { |
| 238 | - if( !empty( $this->error ))return; |
|
| 239 | - if( empty( $this->request['gotcha'] ))return; |
|
| 250 | + if( !empty( $this->error )) { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + if( empty( $this->request['gotcha'] )) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 240 | 256 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 241 | 257 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 242 | 258 | } |
@@ -246,7 +262,9 @@ discard block |
||
| 246 | 262 | */ |
| 247 | 263 | protected function validateRecaptcha() |
| 248 | 264 | { |
| 249 | - if( !empty( $this->error ))return; |
|
| 265 | + if( !empty( $this->error )) { |
|
| 266 | + return; |
|
| 267 | + } |
|
| 250 | 268 | $isValid = $this->isRecaptchaResponseValid(); |
| 251 | 269 | if( is_null( $isValid )) { |
| 252 | 270 | $this->setSessionValues( 'recaptcha', true ); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | wp_send_json( glsr( Html::class )->renderPartial( 'link', [ |
| 26 | 26 | 'post_id' => $request['ID'], |
| 27 | - ])); |
|
| 27 | + ] ) ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function routerChangeReviewStatus( array $request ) |
| 34 | 34 | { |
| 35 | - wp_send_json( $this->execute( new ChangeStatus( $request ))); |
|
| 35 | + wp_send_json( $this->execute( new ChangeStatus( $request ) ) ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | public function routerClearLog() |
| 42 | 42 | { |
| 43 | 43 | glsr( AdminController::class )->routerClearLog(); |
| 44 | - wp_send_json([ |
|
| 44 | + wp_send_json( [ |
|
| 45 | 45 | 'logger' => glsr( Logger::class )->get(), |
| 46 | 46 | 'notices' => glsr( Notice::class )->get(), |
| 47 | - ]); |
|
| 47 | + ] ); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $shortcode = $request['shortcode']; |
| 56 | 56 | $response = false; |
| 57 | - if( array_key_exists( $shortcode, glsr()->mceShortcodes )) { |
|
| 57 | + if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) { |
|
| 58 | 58 | $data = glsr()->mceShortcodes[$shortcode]; |
| 59 | - if( !empty( $data['errors'] )) { |
|
| 59 | + if( !empty($data['errors']) ) { |
|
| 60 | 60 | $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )]; |
| 61 | 61 | } |
| 62 | 62 | $response = [ |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | public function routerSearchPosts( array $request ) |
| 77 | 77 | { |
| 78 | 78 | $results = glsr( Database::class )->searchPosts( $request['search'] ); |
| 79 | - wp_send_json_success([ |
|
| 79 | + wp_send_json_success( [ |
|
| 80 | 80 | 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
| 81 | 81 | 'items' => $results, |
| 82 | - ]); |
|
| 82 | + ] ); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function routerSearchTranslations( array $request ) |
| 89 | 89 | { |
| 90 | - if( empty( $request['exclude'] )) { |
|
| 90 | + if( empty($request['exclude']) ) { |
|
| 91 | 91 | $request['exclude'] = []; |
| 92 | 92 | } |
| 93 | 93 | $results = glsr( Translator::class ) |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | ->exclude() |
| 96 | 96 | ->exclude( $request['exclude'] ) |
| 97 | 97 | ->renderResults(); |
| 98 | - wp_send_json_success([ |
|
| 98 | + wp_send_json_success( [ |
|
| 99 | 99 | 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
| 100 | 100 | 'items' => $results, |
| 101 | - ]); |
|
| 101 | + ] ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | public function routerSubmitReview( array $request ) |
| 108 | 108 | { |
| 109 | 109 | glsr( PublicController::class )->routerSubmitReview( $request ); |
| 110 | - wp_send_json([ |
|
| 110 | + wp_send_json( [ |
|
| 111 | 111 | 'errors' => glsr( Session::class )->get( $request['form_id'].'errors', false, true ), |
| 112 | - 'message' => wpautop( glsr( Session::class )->get( $request['form_id'].'message', '', true )), |
|
| 112 | + 'message' => wpautop( glsr( Session::class )->get( $request['form_id'].'message', '', true ) ), |
|
| 113 | 113 | 'recaptcha' => glsr( Session::class )->get( $request['form_id'].'recaptcha', false, true ), |
| 114 | - ]); |
|
| 114 | + ] ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function routerTogglePinned( array $request ) |
| 121 | 121 | { |
| 122 | - $isPinned = $this->execute( new TogglePinned( $request )); |
|
| 123 | - wp_send_json([ |
|
| 122 | + $isPinned = $this->execute( new TogglePinned( $request ) ); |
|
| 123 | + wp_send_json( [ |
|
| 124 | 124 | 'notices' => glsr( Notice::class )->get(), |
| 125 | 125 | 'pinned' => $isPinned, |
| 126 | - ]); |
|
| 126 | + ] ); |
|
| 127 | 127 | } |
| 128 | 128 | } |