@@ -27,37 +27,37 @@ discard block |
||
| 27 | 27 | public $title; |
| 28 | 28 | public $url; |
| 29 | 29 | |
| 30 | - public function __construct($input) |
|
| 30 | + public function __construct( $input ) |
|
| 31 | 31 | { |
| 32 | 32 | $this->request = $input; |
| 33 | 33 | $this->ajax_request = isset($input['_ajax_request']); |
| 34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
| 35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
| 34 | + $this->assigned_to = $this->getNumeric( 'assign_to' ); |
|
| 35 | + $this->author = sanitize_text_field( $this->getUser( 'name' ) ); |
|
| 36 | 36 | $this->avatar = $this->getAvatar(); |
| 37 | 37 | $this->blacklisted = isset($input['blacklisted']); |
| 38 | 38 | $this->category = $this->getCategory(); |
| 39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
| 39 | + $this->content = sanitize_textarea_field( $this->get( 'content' ) ); |
|
| 40 | 40 | $this->custom = $this->getCustom(); |
| 41 | - $this->date = $this->getDate('date'); |
|
| 42 | - $this->email = sanitize_email($this->getUser('email')); |
|
| 43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
| 44 | - $this->ip_address = $this->get('ip_address'); |
|
| 45 | - $this->post_id = intval($this->get('_post_id')); |
|
| 46 | - $this->rating = intval($this->get('rating')); |
|
| 47 | - $this->referer = sanitize_text_field($this->get('_referer')); |
|
| 48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
| 41 | + $this->date = $this->getDate( 'date' ); |
|
| 42 | + $this->email = sanitize_email( $this->getUser( 'email' ) ); |
|
| 43 | + $this->form_id = sanitize_key( $this->get( 'form_id' ) ); |
|
| 44 | + $this->ip_address = $this->get( 'ip_address' ); |
|
| 45 | + $this->post_id = intval( $this->get( '_post_id' ) ); |
|
| 46 | + $this->rating = intval( $this->get( 'rating' ) ); |
|
| 47 | + $this->referer = sanitize_text_field( $this->get( '_referer' ) ); |
|
| 48 | + $this->response = sanitize_textarea_field( $this->get( 'response' ) ); |
|
| 49 | 49 | $this->terms = !empty($input['terms']); |
| 50 | - $this->title = sanitize_text_field($this->get('title')); |
|
| 51 | - $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
| 50 | + $this->title = sanitize_text_field( $this->get( 'title' ) ); |
|
| 51 | + $this->url = esc_url_raw( sanitize_text_field( $this->get( 'url' ) ) ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @param string $key |
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | - protected function get($key) |
|
| 58 | + protected function get( $key ) |
|
| 59 | 59 | { |
| 60 | - return (string) Arr::get($this->request, $key); |
|
| 60 | + return (string)Arr::get( $this->request, $key ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | protected function getAvatar() |
| 67 | 67 | { |
| 68 | - $avatar = $this->get('avatar'); |
|
| 69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
| 70 | - ? (string) get_avatar_url($this->get('email')) |
|
| 68 | + $avatar = $this->get( 'avatar' ); |
|
| 69 | + return !filter_var( $avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED ) |
|
| 70 | + ? (string)get_avatar_url( $this->get( 'email' ) ) |
|
| 71 | 71 | : $avatar; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | protected function getCategory() |
| 78 | 78 | { |
| 79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
| 80 | - return sanitize_key(Arr::get($categories, 0)); |
|
| 79 | + $categories = Arr::convertStringToArray( $this->get( 'category' ) ); |
|
| 80 | + return sanitize_key( Arr::get( $categories, 0 ) ); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
| 91 | 91 | 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
| 92 | 92 | ]; |
| 93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
| 93 | + $unset = apply_filters( 'site-reviews/create/unset-keys-from-custom', $unset ); |
|
| 94 | 94 | $custom = $this->request; |
| 95 | - foreach ($unset as $key) { |
|
| 95 | + foreach( $unset as $key ) { |
|
| 96 | 96 | unset($custom[$key]); |
| 97 | 97 | } |
| 98 | - foreach ($custom as $key => $value) { |
|
| 99 | - if (is_string($value)) { |
|
| 100 | - $custom[$key] = sanitize_text_field($value); |
|
| 98 | + foreach( $custom as $key => $value ) { |
|
| 99 | + if( is_string( $value ) ) { |
|
| 100 | + $custom[$key] = sanitize_text_field( $value ); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | return $custom; |
@@ -107,29 +107,29 @@ discard block |
||
| 107 | 107 | * @param string $key |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - protected function getDate($key) |
|
| 110 | + protected function getDate( $key ) |
|
| 111 | 111 | { |
| 112 | - $date = strtotime($this->get($key)); |
|
| 113 | - if (false === $date) { |
|
| 112 | + $date = strtotime( $this->get( $key ) ); |
|
| 113 | + if( false === $date ) { |
|
| 114 | 114 | $date = time(); |
| 115 | 115 | } |
| 116 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
| 116 | + return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date ) ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * @param string $key |
| 121 | 121 | * @return string |
| 122 | 122 | */ |
| 123 | - protected function getUser($key) |
|
| 123 | + protected function getUser( $key ) |
|
| 124 | 124 | { |
| 125 | - $value = $this->get($key); |
|
| 126 | - if (empty($value)) { |
|
| 125 | + $value = $this->get( $key ); |
|
| 126 | + if( empty($value) ) { |
|
| 127 | 127 | $user = wp_get_current_user(); |
| 128 | 128 | $userValues = [ |
| 129 | 129 | 'email' => 'user_email', |
| 130 | 130 | 'name' => 'display_name', |
| 131 | 131 | ]; |
| 132 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
| 132 | + if( $user->exists() && array_key_exists( $key, $userValues ) ) { |
|
| 133 | 133 | return $user->{$userValues[$key]}; |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | * @param string $key |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - protected function getNumeric($key) |
|
| 143 | + protected function getNumeric( $key ) |
|
| 144 | 144 | { |
| 145 | - $value = $this->get($key); |
|
| 146 | - return is_numeric($value) |
|
| 145 | + $value = $this->get( $key ); |
|
| 146 | + return is_numeric( $value ) |
|
| 147 | 147 | ? $value |
| 148 | 148 | : ''; |
| 149 | 149 | } |