@@ -6,7 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | class SiteReviewsShortcode extends Shortcode |
| 8 | 8 | { |
| 9 | - protected function hideOptions() { |
|
| 9 | + protected function hideOptions() |
|
| 10 | + { |
|
| 10 | 11 | return [ |
| 11 | 12 | 'title' => __( 'Hide the title', 'site-reviews' ), |
| 12 | 13 | 'rating' => __( 'Hide the rating', 'site-reviews' ), |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | return [[ |
| 16 | 16 | 'type' => 'container', |
| 17 | 17 | 'html' => '<p class="strong">'.esc_html__( 'All settings are optional.', 'site-reviews' ).'</p>', |
| 18 | - ],[ |
|
| 18 | + ], [ |
|
| 19 | 19 | 'label' => esc_html__( 'Title', 'site-reviews' ), |
| 20 | 20 | 'name' => 'title', |
| 21 | 21 | 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
| 22 | 22 | 'type' => 'textbox', |
| 23 | - ],[ |
|
| 23 | + ], [ |
|
| 24 | 24 | 'label' => esc_html__( 'Description', 'site-reviews' ), |
| 25 | 25 | 'minHeight' => 60, |
| 26 | 26 | 'minWidth' => 240, |
@@ -29,25 +29,25 @@ discard block |
||
| 29 | 29 | 'tooltip' => __( 'Enter a custom shortcode description.', 'site-reviews' ), |
| 30 | 30 | 'type' => 'textbox', |
| 31 | 31 | ], |
| 32 | - $this->getCategories( __( 'Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews' )), |
|
| 32 | + $this->getCategories( __( 'Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews' ) ), |
|
| 33 | 33 | [ |
| 34 | 34 | 'label' => esc_html__( 'Assign To', 'site-reviews' ), |
| 35 | 35 | 'name' => 'assign_to', |
| 36 | 36 | 'tooltip' => __( 'Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews' ), |
| 37 | 37 | 'type' => 'textbox', |
| 38 | - ],[ |
|
| 38 | + ], [ |
|
| 39 | 39 | 'label' => esc_html__( 'Classes', 'site-reviews' ), |
| 40 | 40 | 'name' => 'class', |
| 41 | 41 | 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
| 42 | 42 | 'type' => 'textbox', |
| 43 | - ],[ |
|
| 43 | + ], [ |
|
| 44 | 44 | 'columns' => 2, |
| 45 | 45 | 'items' => $this->getHideOptions(), |
| 46 | 46 | 'label' => esc_html__( 'Hide', 'site-reviews' ), |
| 47 | 47 | 'layout' => 'grid', |
| 48 | 48 | 'spacing' => 5, |
| 49 | 49 | 'type' => 'container', |
| 50 | - ],[ |
|
| 50 | + ], [ |
|
| 51 | 51 | 'hidden' => true, |
| 52 | 52 | 'name' => 'id', |
| 53 | 53 | 'type' => 'textbox', |
@@ -12,23 +12,23 @@ discard block |
||
| 12 | 12 | public function fields() |
| 13 | 13 | { |
| 14 | 14 | return [[ |
| 15 | - 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' )), |
|
| 15 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
| 16 | 16 | 'minWidth' => 320, |
| 17 | 17 | 'type' => 'container', |
| 18 | - ],[ |
|
| 18 | + ], [ |
|
| 19 | 19 | 'label' => esc_html__( 'Title', 'site-reviews' ), |
| 20 | 20 | 'name' => 'title', |
| 21 | 21 | 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
| 22 | 22 | 'type' => 'textbox', |
| 23 | 23 | ], |
| 24 | - $this->getTypes( __( 'Which type of review would you like to use?', 'site-reviews' )), |
|
| 25 | - $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' )), |
|
| 24 | + $this->getTypes( __( 'Which type of review would you like to use?', 'site-reviews' ) ), |
|
| 25 | + $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ), |
|
| 26 | 26 | [ |
| 27 | 27 | 'label' => esc_html__( 'Assigned To', 'site-reviews' ), |
| 28 | 28 | 'name' => 'assigned_to', |
| 29 | 29 | 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page.', 'site-reviews' ), |
| 30 | 30 | 'type' => 'textbox', |
| 31 | - ],[ |
|
| 31 | + ], [ |
|
| 32 | 32 | 'label' => esc_html__( 'Schema', 'site-reviews' ), |
| 33 | 33 | 'name' => 'schema', |
| 34 | 34 | 'options' => [ |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | ], |
| 38 | 38 | 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
| 39 | 39 | 'type' => 'listbox', |
| 40 | - ],[ |
|
| 40 | + ], [ |
|
| 41 | 41 | 'label' => esc_html__( 'Classes', 'site-reviews' ), |
| 42 | 42 | 'name' => 'class', |
| 43 | 43 | 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
| 44 | 44 | 'type' => 'textbox', |
| 45 | - ],[ |
|
| 45 | + ], [ |
|
| 46 | 46 | 'columns' => 2, |
| 47 | 47 | 'items' => $this->getHideOptions(), |
| 48 | 48 | 'label' => esc_html__( 'Hide', 'site-reviews' ), |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | 'class' => 'widefat', |
| 21 | 21 | 'label' => __( 'Title', 'site-reviews' ), |
| 22 | 22 | 'name' => 'title', |
| 23 | - ]); |
|
| 23 | + ] ); |
|
| 24 | 24 | $this->renderField( 'number', [ |
| 25 | 25 | 'class' => 'small-text', |
| 26 | 26 | 'default' => 5, |
| 27 | 27 | 'label' => __( 'How many reviews would you like to display?', 'site-reviews' ), |
| 28 | 28 | 'max' => 100, |
| 29 | 29 | 'name' => 'count', |
| 30 | - ]); |
|
| 30 | + ] ); |
|
| 31 | 31 | $this->renderField( 'select', [ |
| 32 | 32 | 'label' => __( 'What is the minimum rating to display?', 'site-reviews' ), |
| 33 | 33 | 'name' => 'rating', |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | '2' => sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ), |
| 39 | 39 | '1' => sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ), |
| 40 | 40 | ], |
| 41 | - ]); |
|
| 41 | + ] ); |
|
| 42 | 42 | if( count( glsr()->reviewTypes ) > 1 ) { |
| 43 | 43 | $this->renderField( 'select', [ |
| 44 | 44 | 'class' => 'widefat', |
| 45 | 45 | 'label' => __( 'Which type of review would you like to display?', 'site-reviews' ), |
| 46 | 46 | 'name' => 'type', |
| 47 | 47 | 'options' => ['' => __( 'All Reviews', 'site-reviews' )] + glsr()->reviewTypes, |
| 48 | - ]); |
|
| 48 | + ] ); |
|
| 49 | 49 | } |
| 50 | - if( !empty( $terms )) { |
|
| 50 | + if( !empty($terms) ) { |
|
| 51 | 51 | $this->renderField( 'select', [ |
| 52 | 52 | 'class' => 'widefat', |
| 53 | 53 | 'label' => __( 'Limit reviews to this category', 'site-reviews' ), |
| 54 | 54 | 'name' => 'category', |
| 55 | 55 | 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
| 56 | - ]); |
|
| 56 | + ] ); |
|
| 57 | 57 | } |
| 58 | 58 | $this->renderField( 'text', [ |
| 59 | 59 | 'class' => 'widefat', |
@@ -61,16 +61,16 @@ discard block |
||
| 61 | 61 | 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
| 62 | 62 | 'label' => __( 'Limit reviews to those assigned to this page/post ID', 'site-reviews' ), |
| 63 | 63 | 'name' => 'assigned_to', |
| 64 | - ]); |
|
| 64 | + ] ); |
|
| 65 | 65 | $this->renderField( 'text', [ |
| 66 | 66 | 'class' => 'widefat', |
| 67 | 67 | 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
| 68 | 68 | 'name' => 'class', |
| 69 | - ]); |
|
| 69 | + ] ); |
|
| 70 | 70 | $this->renderField( 'checkbox', [ |
| 71 | 71 | 'name' => 'hide', |
| 72 | 72 | 'options' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
| 73 | - ]); |
|
| 73 | + ] ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function update( $newInstance, $oldInstance ) |
| 82 | 82 | { |
| 83 | - if( !is_numeric( $newInstance['count'] )) { |
|
| 83 | + if( !is_numeric( $newInstance['count'] ) ) { |
|
| 84 | 84 | $newInstance['count'] = 10; |
| 85 | 85 | } |
| 86 | - $newInstance['count'] = min( 50, max( 0, intval( $newInstance['count'] ))); |
|
| 86 | + $newInstance['count'] = min( 50, max( 0, intval( $newInstance['count'] ) ) ); |
|
| 87 | 87 | return parent::update( $newInstance, $oldInstance ); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -20,34 +20,34 @@ |
||
| 20 | 20 | 'class' => 'widefat', |
| 21 | 21 | 'label' => __( 'Title', 'site-reviews' ), |
| 22 | 22 | 'name' => 'title', |
| 23 | - ]); |
|
| 23 | + ] ); |
|
| 24 | 24 | $this->renderField( 'textarea', [ |
| 25 | 25 | 'class' => 'widefat', |
| 26 | 26 | 'label' => __( 'Description', 'site-reviews' ), |
| 27 | 27 | 'name' => 'description', |
| 28 | - ]); |
|
| 28 | + ] ); |
|
| 29 | 29 | $this->renderField( 'select', [ |
| 30 | 30 | 'class' => 'widefat', |
| 31 | 31 | 'label' => __( 'Automatically assign a category', 'site-reviews' ), |
| 32 | 32 | 'name' => 'category', |
| 33 | 33 | 'options' => ['' => __( 'Do not assign a category', 'site-reviews' )] + $terms, |
| 34 | - ]); |
|
| 34 | + ] ); |
|
| 35 | 35 | $this->renderField( 'text', [ |
| 36 | 36 | 'class' => 'widefat', |
| 37 | 37 | 'default' => '', |
| 38 | 38 | 'description' => sprintf( __( 'You may also enter %s to assign to the current post.', 'site-reviews' ), '<code>post_id</code>' ), |
| 39 | 39 | 'label' => __( 'Assign reviews to a custom page/post ID', 'site-reviews' ), |
| 40 | 40 | 'name' => 'assign_to', |
| 41 | - ]); |
|
| 41 | + ] ); |
|
| 42 | 42 | $this->renderField( 'text', [ |
| 43 | 43 | 'class' => 'widefat', |
| 44 | 44 | 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
| 45 | 45 | 'name' => 'class', |
| 46 | - ]); |
|
| 46 | + ] ); |
|
| 47 | 47 | $this->renderField( 'checkbox', [ |
| 48 | 48 | 'name' => 'hide', |
| 49 | 49 | 'options' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
| 50 | - ]); |
|
| 50 | + ] ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -20,22 +20,22 @@ discard block |
||
| 20 | 20 | 'class' => 'widefat', |
| 21 | 21 | 'label' => __( 'Title', 'site-reviews' ), |
| 22 | 22 | 'name' => 'title', |
| 23 | - ]); |
|
| 23 | + ] ); |
|
| 24 | 24 | if( count( glsr()->reviewTypes ) > 1 ) { |
| 25 | 25 | $this->renderField( 'select', [ |
| 26 | 26 | 'class' => 'widefat', |
| 27 | 27 | 'label' => __( 'Which type of review would you like to use?', 'site-reviews' ), |
| 28 | 28 | 'name' => 'type', |
| 29 | 29 | 'options' => ['' => __( 'All review types', 'site-reviews' )] + glsr()->reviewTypes, |
| 30 | - ]); |
|
| 30 | + ] ); |
|
| 31 | 31 | } |
| 32 | - if( !empty( $terms )) { |
|
| 32 | + if( !empty($terms) ) { |
|
| 33 | 33 | $this->renderField( 'select', [ |
| 34 | 34 | 'class' => 'widefat', |
| 35 | 35 | 'label' => __( 'Limit summary to this category', 'site-reviews' ), |
| 36 | 36 | 'name' => 'category', |
| 37 | 37 | 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
| 38 | - ]); |
|
| 38 | + ] ); |
|
| 39 | 39 | } |
| 40 | 40 | $this->renderField( 'text', [ |
| 41 | 41 | 'class' => 'widefat', |
@@ -43,16 +43,16 @@ discard block |
||
| 43 | 43 | 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
| 44 | 44 | 'label' => __( 'Limit summary to reviews assigned to a page/post ID', 'site-reviews' ), |
| 45 | 45 | 'name' => 'assigned_to', |
| 46 | - ]); |
|
| 46 | + ] ); |
|
| 47 | 47 | $this->renderField( 'text', [ |
| 48 | 48 | 'class' => 'widefat', |
| 49 | 49 | 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
| 50 | 50 | 'name' => 'class', |
| 51 | - ]); |
|
| 51 | + ] ); |
|
| 52 | 52 | $this->renderField( 'checkbox', [ |
| 53 | 53 | 'name' => 'hide', |
| 54 | 54 | 'options' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
| 55 | - ]); |
|
| 55 | + ] ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function compose( Review $review, array $notification ) |
| 37 | 37 | { |
| 38 | - if( empty( $this->endpoint )) { |
|
| 38 | + if( empty($this->endpoint) ) { |
|
| 39 | 39 | return $this; |
| 40 | 40 | } |
| 41 | 41 | $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function send() |
| 62 | 62 | { |
| 63 | - if( empty( $this->endpoint )) { |
|
| 63 | + if( empty($this->endpoint) ) { |
|
| 64 | 64 | return new WP_Error( 'slack', 'Slack notification was not sent: missing endpoint' ); |
| 65 | 65 | } |
| 66 | 66 | return wp_remote_post( $this->endpoint, [ |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | 'redirection' => 5, |
| 73 | 73 | 'sslverify' => false, |
| 74 | 74 | 'timeout' => 45, |
| 75 | - ]); |
|
| 75 | + ] ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | protected function buildAuthorField() |
| 94 | 94 | { |
| 95 | - $email = !empty( $this->review->email ) |
|
| 95 | + $email = !empty($this->review->email) |
|
| 96 | 96 | ? '<'.$this->review->email.'>' |
| 97 | 97 | : ''; |
| 98 | 98 | $author = trim( rtrim( $this->review->author ).' '.$email ); |
| 99 | - return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ))]; |
|
| 99 | + return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ) )]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function buildContentField() |
| 106 | 106 | { |
| 107 | - return !empty( $this->review->content ) |
|
| 107 | + return !empty($this->review->content) |
|
| 108 | 108 | ? ['value' => $this->review->content] |
| 109 | 109 | : []; |
| 110 | 110 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | protected function buildStarsField() |
| 130 | 130 | { |
| 131 | 131 | $solidStars = str_repeat( '★', $this->review->rating ); |
| 132 | - $emptyStars = str_repeat( '☆', max( 0, Rating::MAX_RATING - $this->review->rating )); |
|
| 132 | + $emptyStars = str_repeat( '☆', max( 0, Rating::MAX_RATING - $this->review->rating ) ); |
|
| 133 | 133 | $stars = $solidStars.$emptyStars; |
| 134 | 134 | $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, Rating::MAX_RATING ); |
| 135 | 135 | return ['title' => $stars]; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | protected function buildTitleField() |
| 142 | 142 | { |
| 143 | - return !empty( $this->review->title ) |
|
| 143 | + return !empty($this->review->title) |
|
| 144 | 144 | ? ['title' => $this->review->title] |
| 145 | 145 | : []; |
| 146 | 146 | } |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | 'templates/form/submit-button', |
| 51 | 51 | 'templates/reviews-form', |
| 52 | 52 | ]; |
| 53 | - if( !preg_match( '('.implode( '|', $styledViews ).')', $view )) { |
|
| 53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
| 54 | 54 | return $view; |
| 55 | 55 | } |
| 56 | 56 | $views = $this->generatePossibleViews( $view ); |
| 57 | 57 | foreach( $views as $possibleView ) { |
| 58 | - if( !file_exists( glsr()->file( $possibleView )))continue; |
|
| 58 | + if( !file_exists( glsr()->file( $possibleView ) ) )continue; |
|
| 59 | 59 | return glsr( Helper::class )->removePrefix( 'views/', $possibleView ); |
| 60 | 60 | } |
| 61 | 61 | return $view; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function modifyField( Builder $instance ) |
| 90 | 90 | { |
| 91 | - if( !$this->isPublicInstance( $instance ) || empty( array_filter( $this->fields )))return; |
|
| 91 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) )return; |
|
| 92 | 92 | call_user_func_array( [$this, 'customize'], [&$instance] ); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | protected function customize( Builder $instance ) |
| 107 | 107 | { |
| 108 | - $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' )); |
|
| 108 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
| 109 | 109 | $key = $instance->tag.'_'.$args['type']; |
| 110 | - $classes = !isset( $this->fields[$key] ) |
|
| 110 | + $classes = !isset($this->fields[$key]) |
|
| 111 | 111 | ? $this->fields[$instance->tag] |
| 112 | 112 | : $this->fields[$key]; |
| 113 | 113 | $instance->args['class'] = trim( $args['class'].' '.$classes ); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $args = wp_parse_args( $instance->args, [ |
| 142 | 142 | 'is_public' => false, |
| 143 | 143 | 'is_raw' => false, |
| 144 | - ]); |
|
| 144 | + ] ); |
|
| 145 | 145 | if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
| 146 | 146 | return false; |
| 147 | 147 | } |
@@ -55,7 +55,9 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | $views = $this->generatePossibleViews( $view ); |
| 57 | 57 | foreach( $views as $possibleView ) { |
| 58 | - if( !file_exists( glsr()->file( $possibleView )))continue; |
|
| 58 | + if( !file_exists( glsr()->file( $possibleView ))) { |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 59 | 61 | return glsr( Helper::class )->removePrefix( 'views/', $possibleView ); |
| 60 | 62 | } |
| 61 | 63 | return $view; |
@@ -88,7 +90,9 @@ discard block |
||
| 88 | 90 | */ |
| 89 | 91 | public function modifyField( Builder $instance ) |
| 90 | 92 | { |
| 91 | - if( !$this->isPublicInstance( $instance ) || empty( array_filter( $this->fields )))return; |
|
| 93 | + if( !$this->isPublicInstance( $instance ) || empty( array_filter( $this->fields ))) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 92 | 96 | call_user_func_array( [$this, 'customize'], [&$instance] ); |
| 93 | 97 | } |
| 94 | 98 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function __construct() |
| 38 | 38 | { |
| 39 | - if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) { |
|
| 40 | - $cookie = explode( static::DELIMITER, stripslashes( $cookieId )); |
|
| 39 | + if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE ) ) { |
|
| 40 | + $cookie = explode( static::DELIMITER, stripslashes( $cookieId ) ); |
|
| 41 | 41 | $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] ); |
| 42 | 42 | $this->expiryTimestamp = absint( $cookie[1] ); |
| 43 | 43 | $this->expiryTimestampReset = absint( $cookie[2] ); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function deleteExpiredSessions( $limit = 1000 ) |
| 78 | 78 | { |
| 79 | - if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) { |
|
| 79 | + if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) { |
|
| 80 | 80 | glsr( SqlQueries::class )->deleteExpiredSessions( $expiredSessions ); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | public function get( $key, $fallback = '', $unset = false ) |
| 91 | 91 | { |
| 92 | 92 | $key = sanitize_key( $key ); |
| 93 | - $value = isset( $this->sessionData[$key] ) |
|
| 93 | + $value = isset($this->sessionData[$key]) |
|
| 94 | 94 | ? maybe_unserialize( $this->sessionData[$key] ) |
| 95 | 95 | : $fallback; |
| 96 | - if( isset( $this->sessionData[$key] ) && $unset ) { |
|
| 97 | - unset( $this->sessionData[$key] ); |
|
| 96 | + if( isset($this->sessionData[$key]) && $unset ) { |
|
| 97 | + unset($this->sessionData[$key]); |
|
| 98 | 98 | $this->updateSession(); |
| 99 | 99 | } |
| 100 | 100 | return $value; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | protected function deleteSession() |
| 129 | 129 | { |
| 130 | 130 | delete_option( $this->getSessionId() ); |
| 131 | - delete_option( $this->getSessionId( 'expires' )); |
|
| 131 | + delete_option( $this->getSessionId( 'expires' ) ); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function generateSessionId() |
| 138 | 138 | { |
| 139 | - return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 )); |
|
| 139 | + return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | protected function getExpiredSessions( $limit ) |
| 147 | 147 | { |
| 148 | 148 | $expiredSessions = []; |
| 149 | - $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit )); |
|
| 150 | - if( !empty( $sessions )) { |
|
| 149 | + $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit ) ); |
|
| 150 | + if( !empty($sessions) ) { |
|
| 151 | 151 | $now = time(); |
| 152 | 152 | foreach( $sessions as $session ) { |
| 153 | 153 | if( $now <= $session->expiration )continue; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | protected function getSessionId( $separator = '' ) |
| 166 | 166 | { |
| 167 | - return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] )); |
|
| 167 | + return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | { |
| 196 | 196 | if( headers_sent() )return; |
| 197 | 197 | $cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset; |
| 198 | - $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
|
| 198 | + $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) ); |
|
| 199 | 199 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
| 200 | 200 | } |
| 201 | 201 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | protected function updateSession() |
| 215 | 215 | { |
| 216 | - if( false === get_option( $this->getSessionId() )) { |
|
| 216 | + if( false === get_option( $this->getSessionId() ) ) { |
|
| 217 | 217 | return $this->createSession(); |
| 218 | 218 | } |
| 219 | 219 | update_option( $this->getSessionId(), $this->sessionData, false ); |
@@ -150,7 +150,9 @@ discard block |
||
| 150 | 150 | if( !empty( $sessions )) { |
| 151 | 151 | $now = time(); |
| 152 | 152 | foreach( $sessions as $session ) { |
| 153 | - if( $now <= $session->expiration )continue; |
|
| 153 | + if( $now <= $session->expiration ) { |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 154 | 156 | $expiredSessions[] = $session->name; |
| 155 | 157 | $expiredSessions[] = str_replace( '_expires_', '_', $session->name ); |
| 156 | 158 | } |
@@ -193,7 +195,9 @@ discard block |
||
| 193 | 195 | */ |
| 194 | 196 | protected function setCookie() |
| 195 | 197 | { |
| 196 | - if( headers_sent() )return; |
|
| 198 | + if( headers_sent() ) { |
|
| 199 | + return; |
|
| 200 | + } |
|
| 197 | 201 | $cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset; |
| 198 | 202 | $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
| 199 | 203 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |