@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -49,15 +49,15 @@ discard block |
||
| 49 | 49 | 'transaction_id' => '', |
| 50 | 50 | 'parent_invoice_id' => 0, |
| 51 | 51 | 'item_id' => 0, |
| 52 | - 'created' => date_i18n( 'Y-m-d H:i:s' ), |
|
| 53 | - 'expiration' => date_i18n( 'Y-m-d H:i:s' ), |
|
| 52 | + 'created' => date_i18n('Y-m-d H:i:s'), |
|
| 53 | + 'expiration' => date_i18n('Y-m-d H:i:s'), |
|
| 54 | 54 | 'status' => '', |
| 55 | 55 | 'profile_id' => '', |
| 56 | 56 | 'notes' => '', |
| 57 | 57 | ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function get_subscriptions( $args = array() ) { |
|
| 60 | + public function get_subscriptions($args = array()) { |
|
| 61 | 61 | global $wpdb; |
| 62 | 62 | |
| 63 | 63 | $defaults = array( |
@@ -69,364 +69,364 @@ discard block |
||
| 69 | 69 | 'order' => 'DESC' |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - $args = wp_parse_args( $args, $defaults ); |
|
| 72 | + $args = wp_parse_args($args, $defaults); |
|
| 73 | 73 | |
| 74 | - if ( $args['number'] < 1 ) { |
|
| 74 | + if ($args['number'] < 1) { |
|
| 75 | 75 | $args['number'] = 99999999999999; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $where = ' WHERE 1=1 '; |
| 79 | 79 | |
| 80 | - if ( ! empty( $args['id'] ) ) { |
|
| 81 | - if( is_array( $args['id'] ) ) { |
|
| 82 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
| 80 | + if (!empty($args['id'])) { |
|
| 81 | + if (is_array($args['id'])) { |
|
| 82 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
| 83 | 83 | } else { |
| 84 | - $ids = intval( $args['id'] ); |
|
| 84 | + $ids = intval($args['id']); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $where .= " AND `id` IN( " . $ids . " ) "; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( ! empty( $args['item_id'] ) ) { |
|
| 91 | - if( is_array( $args['item_id'] ) ) { |
|
| 92 | - $item_ids = implode( ',', array_map('intval', $args['item_id'] ) ); |
|
| 90 | + if (!empty($args['item_id'])) { |
|
| 91 | + if (is_array($args['item_id'])) { |
|
| 92 | + $item_ids = implode(',', array_map('intval', $args['item_id'])); |
|
| 93 | 93 | } else { |
| 94 | - $item_ids = intval( $args['item_id'] ); |
|
| 94 | + $item_ids = intval($args['item_id']); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $where .= " AND `item_id` IN( " . $item_ids . " ) "; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( ! empty( $args['parent_invoice_id'] ) ) { |
|
| 101 | - if( is_array( $args['parent_invoice_id'] ) ) { |
|
| 102 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_invoice_id'] ) ); |
|
| 100 | + if (!empty($args['parent_invoice_id'])) { |
|
| 101 | + if (is_array($args['parent_invoice_id'])) { |
|
| 102 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_invoice_id'])); |
|
| 103 | 103 | } else { |
| 104 | - $parent_payment_ids = intval( $args['parent_invoice_id'] ); |
|
| 104 | + $parent_payment_ids = intval($args['parent_invoice_id']); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $where .= " AND `parent_invoice_id` IN( " . $parent_payment_ids . " ) "; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 111 | - if( is_array( $args['transaction_id'] ) ) { |
|
| 112 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
| 110 | + if (!empty($args['transaction_id'])) { |
|
| 111 | + if (is_array($args['transaction_id'])) { |
|
| 112 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
| 113 | 113 | } else { |
| 114 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
| 114 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $where .= " AND `transaction_id` IN ( '" . $transaction_ids . "' ) "; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ( ! empty( $args['user_id'] ) ) { |
|
| 121 | - if( is_array( $args['user_id'] ) ) { |
|
| 122 | - $user_ids = implode( ',', array_map('intval', $args['user_id'] ) ); |
|
| 120 | + if (!empty($args['user_id'])) { |
|
| 121 | + if (is_array($args['user_id'])) { |
|
| 122 | + $user_ids = implode(',', array_map('intval', $args['user_id'])); |
|
| 123 | 123 | } else { |
| 124 | - $user_ids = intval( $args['user_id'] ); |
|
| 124 | + $user_ids = intval($args['user_id']); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $where .= " AND `user_id` IN( " . $user_ids . " ) "; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if ( ! empty( $args['profile_id'] ) ) { |
|
| 131 | - if( is_array( $args['profile_id'] ) ) { |
|
| 132 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
| 130 | + if (!empty($args['profile_id'])) { |
|
| 131 | + if (is_array($args['profile_id'])) { |
|
| 132 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
| 133 | 133 | } else { |
| 134 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
| 134 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $where .= " AND `profile_id` IN( '" . $profile_ids . "' ) "; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( ! empty( $args['status'] ) ) { |
|
| 141 | - if( is_array( $args['status'] ) ) { |
|
| 142 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
| 140 | + if (!empty($args['status'])) { |
|
| 141 | + if (is_array($args['status'])) { |
|
| 142 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
| 143 | 143 | } else { |
| 144 | - $statuses = sanitize_text_field( $args['status'] ); |
|
| 144 | + $statuses = sanitize_text_field($args['status']); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $where .= " AND `status` IN( '" . $statuses . "' ) "; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if ( ! empty( $args['date'] ) ) { |
|
| 151 | - if ( is_array( $args['date'] ) ) { |
|
| 152 | - if ( ! empty( $args['date']['start'] ) ) { |
|
| 153 | - $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
| 150 | + if (!empty($args['date'])) { |
|
| 151 | + if (is_array($args['date'])) { |
|
| 152 | + if (!empty($args['date']['start'])) { |
|
| 153 | + $start = date_i18n('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
| 154 | 154 | |
| 155 | 155 | $where .= " AND `created` >= '" . $start . "'"; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( ! empty( $args['date']['end'] ) ) { |
|
| 159 | - $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
| 158 | + if (!empty($args['date']['end'])) { |
|
| 159 | + $end = date_i18n('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
| 160 | 160 | |
| 161 | 161 | $where .= " AND `created` <= '" . $end . "'"; |
| 162 | 162 | } |
| 163 | 163 | } else { |
| 164 | - $year = date_i18n( 'Y', strtotime( $args['date'] ) ); |
|
| 165 | - $month = date_i18n( 'm', strtotime( $args['date'] ) ); |
|
| 166 | - $day = date_i18n( 'd', strtotime( $args['date'] ) ); |
|
| 164 | + $year = date_i18n('Y', strtotime($args['date'])); |
|
| 165 | + $month = date_i18n('m', strtotime($args['date'])); |
|
| 166 | + $day = date_i18n('d', strtotime($args['date'])); |
|
| 167 | 167 | |
| 168 | 168 | $where .= " AND " . $year . " = YEAR ( created ) AND " . $month . " = MONTH ( created ) AND " . $day . " = DAY ( created )"; |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if ( ! empty( $args['expiration'] ) ) { |
|
| 173 | - if ( is_array( $args['expiration'] ) ) { |
|
| 174 | - if ( ! empty( $args['expiration']['start'] ) ) { |
|
| 175 | - $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
| 172 | + if (!empty($args['expiration'])) { |
|
| 173 | + if (is_array($args['expiration'])) { |
|
| 174 | + if (!empty($args['expiration']['start'])) { |
|
| 175 | + $start = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
| 176 | 176 | |
| 177 | 177 | $where .= " AND `expiration` >= '" . $start . "'"; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ( ! empty( $args['expiration']['end'] ) ) { |
|
| 181 | - $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
| 180 | + if (!empty($args['expiration']['end'])) { |
|
| 181 | + $end = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
| 182 | 182 | |
| 183 | 183 | $where .= " AND `expiration` <= '" . $end . "'"; |
| 184 | 184 | } |
| 185 | 185 | } else { |
| 186 | - $year = date_i18n( 'Y', strtotime( $args['expiration'] ) ); |
|
| 187 | - $month = date_i18n( 'm', strtotime( $args['expiration'] ) ); |
|
| 188 | - $day = date_i18n( 'd', strtotime( $args['expiration'] ) ); |
|
| 186 | + $year = date_i18n('Y', strtotime($args['expiration'])); |
|
| 187 | + $month = date_i18n('m', strtotime($args['expiration'])); |
|
| 188 | + $day = date_i18n('d', strtotime($args['expiration'])); |
|
| 189 | 189 | |
| 190 | 190 | $where .= " AND " . $year . " = YEAR ( expiration ) AND " . $month . " = MONTH ( expiration ) AND " . $day . " = DAY ( expiration )"; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ( ! empty( $args['search'] ) ) { |
|
| 195 | - if ( is_email( $args['search'] ) ) { |
|
| 196 | - $user = get_user_by( 'email', $args['search'] ) |
|
| 194 | + if (!empty($args['search'])) { |
|
| 195 | + if (is_email($args['search'])) { |
|
| 196 | + $user = get_user_by('email', $args['search']) |
|
| 197 | 197 | |
| 198 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
| 199 | - $where .= " AND `user_id` = '" . esc_sql( $user->ID ) . "'"; |
|
| 198 | + if (!empty($user) && $user->ID > 0) { |
|
| 199 | + $where .= " AND `user_id` = '" . esc_sql($user->ID) . "'"; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
| 203 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
| 204 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 205 | - } else if ( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
| 206 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
| 207 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 208 | - } else if ( false !== strpos( $args['search'], 'item_id:' ) ) { |
|
| 209 | - $args['search'] = trim( str_replace( 'item_id:', '', $args['search'] ) ); |
|
| 210 | - $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 211 | - } else if ( false !== strpos( $args['search'], 'user_id:' ) ) { |
|
| 212 | - $args[ 'search' ] = trim( str_replace( 'user_id:', '', $args[ 'search' ] ) ); |
|
| 213 | - $where .= " AND `user_id` = '" . esc_sql( $args[ 'search' ] ) . "'"; |
|
| 214 | - } else if ( false !== strpos( $args['search'], 'id:' ) ) { |
|
| 215 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
| 216 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 202 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
| 203 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
| 204 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
| 205 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
| 206 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
| 207 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
| 208 | + } else if (false !== strpos($args['search'], 'item_id:')) { |
|
| 209 | + $args['search'] = trim(str_replace('item_id:', '', $args['search'])); |
|
| 210 | + $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'"; |
|
| 211 | + } else if (false !== strpos($args['search'], 'user_id:')) { |
|
| 212 | + $args['search'] = trim(str_replace('user_id:', '', $args['search'])); |
|
| 213 | + $where .= " AND `user_id` = '" . esc_sql($args['search']) . "'"; |
|
| 214 | + } else if (false !== strpos($args['search'], 'id:')) { |
|
| 215 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
| 216 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
| 217 | 217 | } else { |
| 218 | - $item = get_page_by_title( trim( $args['search'] ), OBJECT, 'wpi_item' ); |
|
| 218 | + $item = get_page_by_title(trim($args['search']), OBJECT, 'wpi_item'); |
|
| 219 | 219 | |
| 220 | - if ( $item ) { |
|
| 220 | + if ($item) { |
|
| 221 | 221 | $args['search'] = $item->ID; |
| 222 | - $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 222 | + $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'"; |
|
| 223 | 223 | } else { |
| 224 | - $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `item_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
| 224 | + $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `item_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby']; |
|
| 229 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby']; |
|
| 230 | 230 | |
| 231 | - if ( 'amount' == $args['orderby'] ) { |
|
| 231 | + if ('amount' == $args['orderby']) { |
|
| 232 | 232 | $args['orderby'] = 'amount + 0'; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) ); |
|
| 235 | + $cache_key = md5('wpinv_subscriptions_' . serialize($args)); |
|
| 236 | 236 | |
| 237 | - $subscriptions = wp_cache_get( $cache_key, 'wpi_subscriptions' ); |
|
| 237 | + $subscriptions = wp_cache_get($cache_key, 'wpi_subscriptions'); |
|
| 238 | 238 | |
| 239 | - $args['orderby'] = esc_sql( $args['orderby'] ); |
|
| 240 | - $args['order'] = esc_sql( $args['order'] ); |
|
| 239 | + $args['orderby'] = esc_sql($args['orderby']); |
|
| 240 | + $args['order'] = esc_sql($args['order']); |
|
| 241 | 241 | |
| 242 | - if ( $subscriptions === false ) { |
|
| 243 | - $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); |
|
| 242 | + if ($subscriptions === false) { |
|
| 243 | + $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); |
|
| 244 | 244 | |
| 245 | - if ( ! empty( $subscriptions ) ) { |
|
| 246 | - foreach( $subscriptions as $key => $subscription ) { |
|
| 247 | - $subscriptions[ $key ] = new EDD_Subscription( $subscription ); |
|
| 245 | + if (!empty($subscriptions)) { |
|
| 246 | + foreach ($subscriptions as $key => $subscription) { |
|
| 247 | + $subscriptions[$key] = new EDD_Subscription($subscription); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - wp_cache_set( $cache_key, $subscriptions, 'wpi_subscriptions', 3600 ); |
|
| 250 | + wp_cache_set($cache_key, $subscriptions, 'wpi_subscriptions', 3600); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | return $subscriptions; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - public function count( $args = array() ) { |
|
| 257 | + public function count($args = array()) { |
|
| 258 | 258 | global $wpdb; |
| 259 | 259 | |
| 260 | 260 | $where = ' WHERE 1=1 '; |
| 261 | 261 | |
| 262 | - if ( ! empty( $args['id'] ) ) { |
|
| 263 | - if( is_array( $args['id'] ) ) { |
|
| 264 | - $ids = implode( ',', array_map('intval', $args['id'] ) ); |
|
| 262 | + if (!empty($args['id'])) { |
|
| 263 | + if (is_array($args['id'])) { |
|
| 264 | + $ids = implode(',', array_map('intval', $args['id'])); |
|
| 265 | 265 | } else { |
| 266 | - $ids = intval( $args['id'] ); |
|
| 266 | + $ids = intval($args['id']); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | $where .= " AND `id` IN( " . $ids . " ) "; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if ( ! empty( $args['item_id'] ) ) { |
|
| 273 | - if( is_array( $args['item_id'] ) ) { |
|
| 274 | - $item_ids = implode( ',', array_map('intval', $args['item_id'] ) ); |
|
| 272 | + if (!empty($args['item_id'])) { |
|
| 273 | + if (is_array($args['item_id'])) { |
|
| 274 | + $item_ids = implode(',', array_map('intval', $args['item_id'])); |
|
| 275 | 275 | } else { |
| 276 | - $item_ids = intval( $args['item_id'] ); |
|
| 276 | + $item_ids = intval($args['item_id']); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $where .= " AND `item_id` IN( " . $item_ids . " ) "; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if ( ! empty( $args['parent_invoice_id'] ) ) { |
|
| 283 | - if( is_array( $args['parent_invoice_id'] ) ) { |
|
| 284 | - $parent_payment_ids = implode( ',', array_map('intval', $args['parent_invoice_id'] ) ); |
|
| 282 | + if (!empty($args['parent_invoice_id'])) { |
|
| 283 | + if (is_array($args['parent_invoice_id'])) { |
|
| 284 | + $parent_payment_ids = implode(',', array_map('intval', $args['parent_invoice_id'])); |
|
| 285 | 285 | } else { |
| 286 | - $parent_payment_ids = intval( $args['parent_invoice_id'] ); |
|
| 286 | + $parent_payment_ids = intval($args['parent_invoice_id']); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | $where .= " AND `parent_invoice_id` IN( " . $parent_payment_ids . " ) "; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 293 | - if( is_array( $args['transaction_id'] ) ) { |
|
| 294 | - $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); |
|
| 292 | + if (!empty($args['transaction_id'])) { |
|
| 293 | + if (is_array($args['transaction_id'])) { |
|
| 294 | + $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); |
|
| 295 | 295 | } else { |
| 296 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] ); |
|
| 296 | + $transaction_ids = sanitize_text_field($args['transaction_id']); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | $where .= " AND `transaction_id` IN ( '" . $transaction_ids . "' ) "; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if ( ! empty( $args['user_id'] ) ) { |
|
| 303 | - if( is_array( $args['user_id'] ) ) { |
|
| 304 | - $user_ids = implode( ',', array_map('intval', $args['user_id'] ) ); |
|
| 302 | + if (!empty($args['user_id'])) { |
|
| 303 | + if (is_array($args['user_id'])) { |
|
| 304 | + $user_ids = implode(',', array_map('intval', $args['user_id'])); |
|
| 305 | 305 | } else { |
| 306 | - $user_ids = intval( $args['user_id'] ); |
|
| 306 | + $user_ids = intval($args['user_id']); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $where .= " AND `user_id` IN( " . $user_ids . " ) "; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if ( ! empty( $args['profile_id'] ) ) { |
|
| 313 | - if( is_array( $args['profile_id'] ) ) { |
|
| 314 | - $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); |
|
| 312 | + if (!empty($args['profile_id'])) { |
|
| 313 | + if (is_array($args['profile_id'])) { |
|
| 314 | + $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); |
|
| 315 | 315 | } else { |
| 316 | - $profile_ids = sanitize_text_field( $args['profile_id'] ); |
|
| 316 | + $profile_ids = sanitize_text_field($args['profile_id']); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | $where .= " AND `profile_id` IN( '" . $profile_ids . "' ) "; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( ! empty( $args['status'] ) ) { |
|
| 323 | - if( is_array( $args['status'] ) ) { |
|
| 324 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) ); |
|
| 322 | + if (!empty($args['status'])) { |
|
| 323 | + if (is_array($args['status'])) { |
|
| 324 | + $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); |
|
| 325 | 325 | } else { |
| 326 | - $statuses = sanitize_text_field( $args['status'] ); |
|
| 326 | + $statuses = sanitize_text_field($args['status']); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | $where .= " AND `status` IN( '" . $statuses . "' ) "; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if ( ! empty( $args['date'] ) ) { |
|
| 333 | - if ( is_array( $args['date'] ) ) { |
|
| 334 | - if ( ! empty( $args['date']['start'] ) ) { |
|
| 335 | - $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) ); |
|
| 332 | + if (!empty($args['date'])) { |
|
| 333 | + if (is_array($args['date'])) { |
|
| 334 | + if (!empty($args['date']['start'])) { |
|
| 335 | + $start = date_i18n('Y-m-d H:i:s', strtotime($args['date']['start'])); |
|
| 336 | 336 | |
| 337 | 337 | $where .= " AND `created` >= '" . $start . "'"; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if ( ! empty( $args['date']['end'] ) ) { |
|
| 341 | - $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) ); |
|
| 340 | + if (!empty($args['date']['end'])) { |
|
| 341 | + $end = date_i18n('Y-m-d H:i:s', strtotime($args['date']['end'])); |
|
| 342 | 342 | |
| 343 | 343 | $where .= " AND `created` <= '" . $end . "'"; |
| 344 | 344 | } |
| 345 | 345 | } else { |
| 346 | - $year = date_i18n( 'Y', strtotime( $args['date'] ) ); |
|
| 347 | - $month = date_i18n( 'm', strtotime( $args['date'] ) ); |
|
| 348 | - $day = date_i18n( 'd', strtotime( $args['date'] ) ); |
|
| 346 | + $year = date_i18n('Y', strtotime($args['date'])); |
|
| 347 | + $month = date_i18n('m', strtotime($args['date'])); |
|
| 348 | + $day = date_i18n('d', strtotime($args['date'])); |
|
| 349 | 349 | |
| 350 | 350 | $where .= " AND " . $year . " = YEAR ( created ) AND " . $month . " = MONTH ( created ) AND " . $day . " = DAY ( created )"; |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - if ( ! empty( $args['expiration'] ) ) { |
|
| 355 | - if ( is_array( $args['expiration'] ) ) { |
|
| 356 | - if ( ! empty( $args['expiration']['start'] ) ) { |
|
| 357 | - $start = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) ); |
|
| 354 | + if (!empty($args['expiration'])) { |
|
| 355 | + if (is_array($args['expiration'])) { |
|
| 356 | + if (!empty($args['expiration']['start'])) { |
|
| 357 | + $start = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['start'])); |
|
| 358 | 358 | |
| 359 | 359 | $where .= " AND `expiration` >= '" . $start . "'"; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( ! empty( $args['expiration']['end'] ) ) { |
|
| 363 | - $end = date_i18n( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) ); |
|
| 362 | + if (!empty($args['expiration']['end'])) { |
|
| 363 | + $end = date_i18n('Y-m-d H:i:s', strtotime($args['expiration']['end'])); |
|
| 364 | 364 | |
| 365 | 365 | $where .= " AND `expiration` <= '" . $end . "'"; |
| 366 | 366 | } |
| 367 | 367 | } else { |
| 368 | - $year = date_i18n( 'Y', strtotime( $args['expiration'] ) ); |
|
| 369 | - $month = date_i18n( 'm', strtotime( $args['expiration'] ) ); |
|
| 370 | - $day = date_i18n( 'd', strtotime( $args['expiration'] ) ); |
|
| 368 | + $year = date_i18n('Y', strtotime($args['expiration'])); |
|
| 369 | + $month = date_i18n('m', strtotime($args['expiration'])); |
|
| 370 | + $day = date_i18n('d', strtotime($args['expiration'])); |
|
| 371 | 371 | |
| 372 | 372 | $where .= " AND " . $year . " = YEAR ( expiration ) AND " . $month . " = MONTH ( expiration ) AND " . $day . " = DAY ( expiration )"; |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if ( ! empty( $args['search'] ) ) { |
|
| 377 | - if ( is_email( $args['search'] ) ) { |
|
| 378 | - $user = get_user_by( 'email', $args['search'] ) |
|
| 376 | + if (!empty($args['search'])) { |
|
| 377 | + if (is_email($args['search'])) { |
|
| 378 | + $user = get_user_by('email', $args['search']) |
|
| 379 | 379 | |
| 380 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
| 381 | - $where .= " AND `user_id` = '" . esc_sql( $user->ID ) . "'"; |
|
| 380 | + if (!empty($user) && $user->ID > 0) { |
|
| 381 | + $where .= " AND `user_id` = '" . esc_sql($user->ID) . "'"; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - } else if( false !== strpos( $args['search'], 'txn:' ) ) { |
|
| 385 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) ); |
|
| 386 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 387 | - } else if ( false !== strpos( $args['search'], 'profile_id:' ) ) { |
|
| 388 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) ); |
|
| 389 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 390 | - } else if ( false !== strpos( $args['search'], 'item_id:' ) ) { |
|
| 391 | - $args['search'] = trim( str_replace( 'item_id:', '', $args['search'] ) ); |
|
| 392 | - $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 393 | - } else if ( false !== strpos( $args['search'], 'user_id:' ) ) { |
|
| 394 | - $args[ 'search' ] = trim( str_replace( 'user_id:', '', $args[ 'search' ] ) ); |
|
| 395 | - $where .= " AND `user_id` = '" . esc_sql( $args[ 'search' ] ) . "'"; |
|
| 396 | - } else if ( false !== strpos( $args['search'], 'id:' ) ) { |
|
| 397 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) ); |
|
| 398 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 384 | + } else if (false !== strpos($args['search'], 'txn:')) { |
|
| 385 | + $args['search'] = trim(str_replace('txn:', '', $args['search'])); |
|
| 386 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'"; |
|
| 387 | + } else if (false !== strpos($args['search'], 'profile_id:')) { |
|
| 388 | + $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); |
|
| 389 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'"; |
|
| 390 | + } else if (false !== strpos($args['search'], 'item_id:')) { |
|
| 391 | + $args['search'] = trim(str_replace('item_id:', '', $args['search'])); |
|
| 392 | + $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'"; |
|
| 393 | + } else if (false !== strpos($args['search'], 'user_id:')) { |
|
| 394 | + $args['search'] = trim(str_replace('user_id:', '', $args['search'])); |
|
| 395 | + $where .= " AND `user_id` = '" . esc_sql($args['search']) . "'"; |
|
| 396 | + } else if (false !== strpos($args['search'], 'id:')) { |
|
| 397 | + $args['search'] = trim(str_replace('id:', '', $args['search'])); |
|
| 398 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'"; |
|
| 399 | 399 | } else { |
| 400 | - $item = get_page_by_title( trim( $args['search'] ), OBJECT, 'wpi_item' ); |
|
| 400 | + $item = get_page_by_title(trim($args['search']), OBJECT, 'wpi_item'); |
|
| 401 | 401 | |
| 402 | - if ( $item ) { |
|
| 402 | + if ($item) { |
|
| 403 | 403 | $args['search'] = $item->ID; |
| 404 | - $where .= " AND `item_id` = '" . esc_sql( $args['search'] ) . "'"; |
|
| 404 | + $where .= " AND `item_id` = '" . esc_sql($args['search']) . "'"; |
|
| 405 | 405 | } else { |
| 406 | - $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `item_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )"; |
|
| 406 | + $where .= " AND ( `parent_invoice_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `item_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )"; |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - $cache_key = md5( 'wpi_subscriptions_count' . serialize( $args ) ); |
|
| 411 | + $cache_key = md5('wpi_subscriptions_count' . serialize($args)); |
|
| 412 | 412 | |
| 413 | - $count = wp_cache_get( $cache_key, 'wpi_subscriptions' ); |
|
| 413 | + $count = wp_cache_get($cache_key, 'wpi_subscriptions'); |
|
| 414 | 414 | |
| 415 | - if ( $count === false ) { |
|
| 415 | + if ($count === false) { |
|
| 416 | 416 | $sql = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; |
| 417 | - $count = $wpdb->get_var( $sql ); |
|
| 417 | + $count = $wpdb->get_var($sql); |
|
| 418 | 418 | |
| 419 | - wp_cache_set( $cache_key, $count, 'wpi_subscriptions', 3600 ); |
|
| 419 | + wp_cache_set($cache_key, $count, 'wpi_subscriptions', 3600); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - return absint( $count ); |
|
| 422 | + return absint($count); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | public function create_table() { |
| 426 | 426 | global $wpdb; |
| 427 | 427 | |
| 428 | - if ( !function_exists( 'dbDelta' ) ) { |
|
| 429 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 428 | + if (!function_exists('dbDelta')) { |
|
| 429 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | $sql = "CREATE TABLE " . $this->table_name . " ( |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | KEY user_and_status ( user_id, status) |
| 455 | 455 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
| 456 | 456 | |
| 457 | - dbDelta( $sql ); |
|
| 457 | + dbDelta($sql); |
|
| 458 | 458 | |
| 459 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
| 459 | + update_option($this->table_name . '_db_version', $this->version); |
|
| 460 | 460 | } |
| 461 | 461 | } |