@@ -16,19 +16,19 @@ discard block |
||
| 16 | 16 | * Build a WP_Query meta_query/tax_query. |
| 17 | 17 | * @return array |
| 18 | 18 | */ |
| 19 | - public function buildQuery(array $keys = [], array $values = []) |
|
| 19 | + public function buildQuery( array $keys = [], array $values = [] ) |
|
| 20 | 20 | { |
| 21 | 21 | $queries = []; |
| 22 | - foreach ($keys as $key) { |
|
| 23 | - if (!array_key_exists($key, $values)) { |
|
| 22 | + foreach( $keys as $key ) { |
|
| 23 | + if( !array_key_exists( $key, $values ) ) { |
|
| 24 | 24 | continue; |
| 25 | 25 | } |
| 26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
| 27 | - if (!method_exists($this, $methodName)) { |
|
| 26 | + $methodName = Helper::buildMethodName( $key, __FUNCTION__ ); |
|
| 27 | + if( !method_exists( $this, $methodName ) ) { |
|
| 28 | 28 | continue; |
| 29 | 29 | } |
| 30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
| 31 | - if (is_array($query)) { |
|
| 30 | + $query = call_user_func( [$this, $methodName], $values[$key] ); |
|
| 31 | + if( is_array( $query ) ) { |
|
| 32 | 32 | $queries[] = $query; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | /** |
| 39 | 39 | * @return string |
| 40 | 40 | */ |
| 41 | - public function buildSqlLines(array $values, array $conditions) |
|
| 41 | + public function buildSqlLines( array $values, array $conditions ) |
|
| 42 | 42 | { |
| 43 | 43 | $string = ''; |
| 44 | - $values = array_filter($values); |
|
| 45 | - foreach ($conditions as $key => $value) { |
|
| 46 | - if (!isset($values[$key])) { |
|
| 44 | + $values = array_filter( $values ); |
|
| 45 | + foreach( $conditions as $key => $value ) { |
|
| 46 | + if( !isset($values[$key]) ) { |
|
| 47 | 47 | continue; |
| 48 | 48 | } |
| 49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
| 50 | - $string.= Str::contains($value, '%s') |
|
| 51 | - ? sprintf($value, strval($values[$key])) |
|
| 49 | + $values[$key] = implode( ',', (array)$values[$key] ); |
|
| 50 | + $string .= Str::contains( $value, '%s' ) |
|
| 51 | + ? sprintf( $value, strval( $values[$key] ) ) |
|
| 52 | 52 | : $value; |
| 53 | 53 | } |
| 54 | 54 | return $string; |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | * @param string $sprintfFormat |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - public function buildSqlOr($values, $sprintfFormat) |
|
| 63 | + public function buildSqlOr( $values, $sprintfFormat ) |
|
| 64 | 64 | { |
| 65 | - if (!is_array($values)) { |
|
| 66 | - $values = explode(',', $values); |
|
| 65 | + if( !is_array( $values ) ) { |
|
| 66 | + $values = explode( ',', $values ); |
|
| 67 | 67 | } |
| 68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
| 69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
| 70 | - return sprintf($sprintfFormat, $value); |
|
| 71 | - }, $values); |
|
| 72 | - return implode(' OR ', $values); |
|
| 68 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
| 69 | + $values = array_map( function( $value ) use ($sprintfFormat) { |
|
| 70 | + return sprintf( $sprintfFormat, $value ); |
|
| 71 | + }, $values ); |
|
| 72 | + return implode( ' OR ', $values ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -79,23 +79,23 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | * @filter posts_search |
| 81 | 81 | */ |
| 82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
| 82 | + public function filterSearchByTitle( $search, WP_Query $query ) |
|
| 83 | 83 | { |
| 84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
| 84 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
| 85 | 85 | return $search; |
| 86 | 86 | } |
| 87 | 87 | global $wpdb; |
| 88 | - $n = empty($query->get('exact')) |
|
| 88 | + $n = empty($query->get( 'exact' )) |
|
| 89 | 89 | ? '%' |
| 90 | 90 | : ''; |
| 91 | 91 | $search = []; |
| 92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
| 93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
| 92 | + foreach( (array)$query->get( 'search_terms' ) as $term ) { |
|
| 93 | + $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n ); |
|
| 94 | 94 | } |
| 95 | - if (!is_user_logged_in()) { |
|
| 95 | + if( !is_user_logged_in() ) { |
|
| 96 | 96 | $search[] = "{$wpdb->posts}.post_password = ''"; |
| 97 | 97 | } |
| 98 | - return ' AND '.implode(' AND ', $search); |
|
| 98 | + return ' AND '.implode( ' AND ', $search ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,10 +103,10 @@ discard block |
||
| 103 | 103 | * @param bool $isEnabled |
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | - public function getPaged($isEnabled = true) |
|
| 106 | + public function getPaged( $isEnabled = true ) |
|
| 107 | 107 | { |
| 108 | 108 | return $isEnabled |
| 109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
| 109 | + ? max( 1, intval( filter_input( INPUT_GET, glsr()->constant( 'PAGED_QUERY_VAR' ) ) ) ) |
|
| 110 | 110 | : 1; |
| 111 | 111 | } |
| 112 | 112 | |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | * @param string $value |
| 115 | 115 | * @return void|array |
| 116 | 116 | */ |
| 117 | - protected function buildQueryAssignedTo($value) |
|
| 117 | + protected function buildQueryAssignedTo( $value ) |
|
| 118 | 118 | { |
| 119 | - if (!empty($value)) { |
|
| 120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
| 119 | + if( !empty($value) ) { |
|
| 120 | + $postIds = Arr::convertStringToArray( $value, 'is_numeric' ); |
|
| 121 | 121 | return [ |
| 122 | 122 | 'compare' => 'IN', |
| 123 | 123 | 'key' => '_assigned_to', |
| 124 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
| 124 | + 'value' => glsr( Polylang::class )->getPostIds( $postIds ), |
|
| 125 | 125 | ]; |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | * @param array $value |
| 131 | 131 | * @return void|array |
| 132 | 132 | */ |
| 133 | - protected function buildQueryCategory($value) |
|
| 133 | + protected function buildQueryCategory( $value ) |
|
| 134 | 134 | { |
| 135 | - if (!empty($value)) { |
|
| 135 | + if( !empty($value) ) { |
|
| 136 | 136 | return [ |
| 137 | 137 | 'field' => 'term_id', |
| 138 | 138 | 'taxonomy' => Application::TAXONOMY, |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | * @param string $value |
| 146 | 146 | * @return void|array |
| 147 | 147 | */ |
| 148 | - protected function buildQueryEmail($value) |
|
| 148 | + protected function buildQueryEmail( $value ) |
|
| 149 | 149 | { |
| 150 | - if (!empty($value)) { |
|
| 150 | + if( !empty($value) ) { |
|
| 151 | 151 | return [ |
| 152 | 152 | 'key' => '_email', |
| 153 | 153 | 'value' => $value, |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | * @param string $value |
| 160 | 160 | * @return void|array |
| 161 | 161 | */ |
| 162 | - protected function buildQueryIpAddress($value) |
|
| 162 | + protected function buildQueryIpAddress( $value ) |
|
| 163 | 163 | { |
| 164 | - if (!empty($value)) { |
|
| 164 | + if( !empty($value) ) { |
|
| 165 | 165 | return [ |
| 166 | 166 | 'key' => '_ip_address', |
| 167 | 167 | 'value' => $value, |
@@ -173,10 +173,10 @@ discard block |
||
| 173 | 173 | * @param string $value |
| 174 | 174 | * @return void|array |
| 175 | 175 | */ |
| 176 | - protected function buildQueryRating($value) |
|
| 176 | + protected function buildQueryRating( $value ) |
|
| 177 | 177 | { |
| 178 | - if (is_numeric($value) |
|
| 179 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
| 178 | + if( is_numeric( $value ) |
|
| 179 | + && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) { |
|
| 180 | 180 | return [ |
| 181 | 181 | 'compare' => '>=', |
| 182 | 182 | 'key' => '_rating', |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | * @param string $value |
| 190 | 190 | * @return void|array |
| 191 | 191 | */ |
| 192 | - protected function buildQueryType($value) |
|
| 192 | + protected function buildQueryType( $value ) |
|
| 193 | 193 | { |
| 194 | - if (!in_array($value, ['', 'all'])) { |
|
| 194 | + if( !in_array( $value, ['', 'all'] ) ) { |
|
| 195 | 195 | return [ |
| 196 | 196 | 'key' => '_review_type', |
| 197 | 197 | 'value' => $value, |