@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | // Load WP_List_Table if not loaded |
| 11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,326 +21,326 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class WPInv_Customers_Table extends WP_List_Table { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var int Number of items per page |
|
| 26 | - * @since 1.0.19 |
|
| 27 | - */ |
|
| 28 | - public $per_page = 10; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var int Number of items |
|
| 32 | - * @since 1.0.19 |
|
| 33 | - */ |
|
| 34 | - public $total = 0; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get things started |
|
| 38 | - * |
|
| 39 | - * @since 1.0.19 |
|
| 40 | - * @see WP_List_Table::__construct() |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - // Set parent defaults |
|
| 45 | - parent::__construct( array( |
|
| 46 | - 'singular' => 'id', |
|
| 47 | - 'plural' => 'ids', |
|
| 48 | - 'ajax' => false, |
|
| 49 | - ) ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Gets the name of the primary column. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.19 |
|
| 57 | - * @access protected |
|
| 58 | - * |
|
| 59 | - * @return string Name of the primary column. |
|
| 60 | - */ |
|
| 61 | - protected function get_primary_column_name() { |
|
| 62 | - return 'name'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * This function renders most of the columns in the list table. |
|
| 67 | - * |
|
| 68 | - * @since 1.0.19 |
|
| 69 | - * |
|
| 70 | - * @param WP_User $item |
|
| 71 | - * @param string $column_name The name of the column |
|
| 72 | - * |
|
| 73 | - * @return string Column Name |
|
| 74 | - */ |
|
| 75 | - public function column_default( $item, $column_name ) { |
|
| 76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Displays the country column. |
|
| 82 | - * |
|
| 83 | - * @since 1.0.19 |
|
| 84 | - * |
|
| 85 | - * @param WP_User $user |
|
| 86 | - * |
|
| 87 | - * @return string Column Name |
|
| 88 | - */ |
|
| 89 | - public function column_country( $user ) { |
|
| 90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | - if ( $country ) { |
|
| 92 | - $country = wpinv_country_name( $country ); |
|
| 93 | - } |
|
| 94 | - return sanitize_text_field( $country ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Displays the state column. |
|
| 99 | - * |
|
| 100 | - * @since 1.0.19 |
|
| 101 | - * |
|
| 102 | - * @param WP_User $user |
|
| 103 | - * |
|
| 104 | - * @return string Column Name |
|
| 105 | - */ |
|
| 106 | - public function column_state( $user ) { |
|
| 107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | - $state = $user->_wpinv_state; |
|
| 109 | - if ( $state ) { |
|
| 110 | - $state = wpinv_state_name( $state, $country ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return sanitize_text_field( $state ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Displays the total spent column. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * |
|
| 121 | - * @param WP_User $user |
|
| 122 | - * |
|
| 123 | - * @return string Column Name |
|
| 124 | - */ |
|
| 125 | - public function column_total( $user ) { |
|
| 126 | - |
|
| 127 | - $args = array( |
|
| 128 | - 'data' => array( |
|
| 129 | - |
|
| 130 | - 'total' => array( |
|
| 131 | - 'type' => 'invoice_data', |
|
| 132 | - 'function' => 'SUM', |
|
| 133 | - 'name' => 'total_sales', |
|
| 134 | - ) |
|
| 135 | - |
|
| 136 | - ), |
|
| 137 | - 'where' => array( |
|
| 138 | - |
|
| 139 | - 'author' => array( |
|
| 140 | - 'type' => 'post_data', |
|
| 141 | - 'value' => absint( $user->ID ), |
|
| 142 | - 'key' => 'posts.post_author', |
|
| 143 | - 'operator' => '=', |
|
| 144 | - ), |
|
| 145 | - |
|
| 146 | - ), |
|
| 147 | - 'query_type' => 'get_var', |
|
| 148 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 149 | - ); |
|
| 150 | - |
|
| 151 | - return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Displays the total spent column. |
|
| 157 | - * |
|
| 158 | - * @since 1.0.19 |
|
| 159 | - * |
|
| 160 | - * @param WP_User $user |
|
| 161 | - * |
|
| 162 | - * @return string Column Name |
|
| 163 | - */ |
|
| 164 | - public function column_invoices( $user ) { |
|
| 165 | - |
|
| 166 | - $args = array( |
|
| 167 | - 'data' => array( |
|
| 168 | - |
|
| 169 | - 'ID' => array( |
|
| 170 | - 'type' => 'post_data', |
|
| 171 | - 'function' => 'COUNT', |
|
| 172 | - 'name' => 'count', |
|
| 173 | - 'distinct' => true, |
|
| 174 | - ), |
|
| 175 | - |
|
| 176 | - ), |
|
| 177 | - 'where' => array( |
|
| 178 | - |
|
| 179 | - 'author' => array( |
|
| 180 | - 'type' => 'post_data', |
|
| 181 | - 'value' => absint( $user->ID ), |
|
| 182 | - 'key' => 'posts.post_author', |
|
| 183 | - 'operator' => '=', |
|
| 184 | - ), |
|
| 185 | - |
|
| 186 | - ), |
|
| 187 | - 'query_type' => 'get_var', |
|
| 188 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 189 | - ); |
|
| 190 | - |
|
| 191 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 192 | - |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Generates content for a single row of the table |
|
| 197 | - * @since 1.0.19 |
|
| 198 | - * |
|
| 199 | - * @param int $item The user id. |
|
| 200 | - */ |
|
| 201 | - public function single_row( $item ) { |
|
| 202 | - $item = get_user_by( 'id', $item ); |
|
| 203 | - |
|
| 204 | - if ( empty( $item ) ) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - echo '<tr>'; |
|
| 209 | - $this->single_row_columns( $item ); |
|
| 210 | - echo '</tr>'; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Displays the customers name |
|
| 215 | - * |
|
| 216 | - * @param WP_User $customer customer. |
|
| 217 | - * @return string |
|
| 218 | - */ |
|
| 219 | - public function column_name( $customer ) { |
|
| 220 | - |
|
| 221 | - // Customer view URL. |
|
| 222 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 223 | - $row_actions = $this->row_actions( |
|
| 224 | - array( |
|
| 225 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - |
|
| 229 | - // Get user's address. |
|
| 230 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 231 | - |
|
| 232 | - // Customer email address. |
|
| 233 | - $email = sanitize_email( $customer->user_email ); |
|
| 234 | - |
|
| 235 | - // Customer's avatar. |
|
| 236 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 237 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 238 | - |
|
| 239 | - // Customer's name. |
|
| 240 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 241 | - |
|
| 242 | - if ( ! empty( $name ) ) { |
|
| 243 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 247 | - |
|
| 248 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 249 | - |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Retrieve the table columns |
|
| 254 | - * |
|
| 255 | - * @since 1.0.19 |
|
| 256 | - * @return array $columns Array of all the list table columns |
|
| 257 | - */ |
|
| 258 | - public function get_columns() { |
|
| 259 | - |
|
| 260 | - $columns = array( |
|
| 261 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 262 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 263 | - 'state' => __( 'State', 'invoicing' ), |
|
| 264 | - 'city' => __( 'City', 'invoicing' ), |
|
| 265 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 266 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 267 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 268 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 269 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 270 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 271 | - ); |
|
| 272 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 273 | - |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Retrieve the current page number |
|
| 278 | - * |
|
| 279 | - * @since 1.0.19 |
|
| 280 | - * @return int Current page number |
|
| 281 | - */ |
|
| 282 | - public function get_paged() { |
|
| 283 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns bulk actions. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @return void |
|
| 291 | - */ |
|
| 292 | - public function bulk_actions( $which = '' ) { |
|
| 293 | - return array(); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Prepares the display query |
|
| 298 | - */ |
|
| 299 | - public function prepare_query() { |
|
| 300 | - global $wpdb; |
|
| 301 | - |
|
| 302 | - $post_types = 'WHERE '; |
|
| 303 | - |
|
| 304 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 305 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 309 | - |
|
| 310 | - // Users with invoices. |
|
| 311 | - $customers = $wpdb->get_col( |
|
| 312 | - $wpdb->prepare( |
|
| 313 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts $post_types LIMIT %d,%d", |
|
| 314 | - $this->get_paged() * 10 - 10, |
|
| 315 | - $this->per_page |
|
| 316 | - ) |
|
| 317 | - ); |
|
| 318 | - |
|
| 319 | - $this->items = $customers; |
|
| 320 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts $post_types" ); |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Setup the final data for the table |
|
| 326 | - * |
|
| 327 | - * @since 1.0.19 |
|
| 328 | - * @return void |
|
| 329 | - */ |
|
| 330 | - public function prepare_items() { |
|
| 331 | - $columns = $this->get_columns(); |
|
| 332 | - $hidden = array(); // No hidden columns |
|
| 333 | - $sortable = $this->get_sortable_columns(); |
|
| 334 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 335 | - $this->prepare_query(); |
|
| 336 | - |
|
| 337 | - $this->set_pagination_args( |
|
| 338 | - array( |
|
| 339 | - 'total_items' => $this->total, |
|
| 340 | - 'per_page' => $this->per_page, |
|
| 341 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 342 | - ) |
|
| 343 | - ); |
|
| 344 | - |
|
| 345 | - } |
|
| 24 | + /** |
|
| 25 | + * @var int Number of items per page |
|
| 26 | + * @since 1.0.19 |
|
| 27 | + */ |
|
| 28 | + public $per_page = 10; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var int Number of items |
|
| 32 | + * @since 1.0.19 |
|
| 33 | + */ |
|
| 34 | + public $total = 0; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get things started |
|
| 38 | + * |
|
| 39 | + * @since 1.0.19 |
|
| 40 | + * @see WP_List_Table::__construct() |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + // Set parent defaults |
|
| 45 | + parent::__construct( array( |
|
| 46 | + 'singular' => 'id', |
|
| 47 | + 'plural' => 'ids', |
|
| 48 | + 'ajax' => false, |
|
| 49 | + ) ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Gets the name of the primary column. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.19 |
|
| 57 | + * @access protected |
|
| 58 | + * |
|
| 59 | + * @return string Name of the primary column. |
|
| 60 | + */ |
|
| 61 | + protected function get_primary_column_name() { |
|
| 62 | + return 'name'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * This function renders most of the columns in the list table. |
|
| 67 | + * |
|
| 68 | + * @since 1.0.19 |
|
| 69 | + * |
|
| 70 | + * @param WP_User $item |
|
| 71 | + * @param string $column_name The name of the column |
|
| 72 | + * |
|
| 73 | + * @return string Column Name |
|
| 74 | + */ |
|
| 75 | + public function column_default( $item, $column_name ) { |
|
| 76 | + $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Displays the country column. |
|
| 82 | + * |
|
| 83 | + * @since 1.0.19 |
|
| 84 | + * |
|
| 85 | + * @param WP_User $user |
|
| 86 | + * |
|
| 87 | + * @return string Column Name |
|
| 88 | + */ |
|
| 89 | + public function column_country( $user ) { |
|
| 90 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | + if ( $country ) { |
|
| 92 | + $country = wpinv_country_name( $country ); |
|
| 93 | + } |
|
| 94 | + return sanitize_text_field( $country ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Displays the state column. |
|
| 99 | + * |
|
| 100 | + * @since 1.0.19 |
|
| 101 | + * |
|
| 102 | + * @param WP_User $user |
|
| 103 | + * |
|
| 104 | + * @return string Column Name |
|
| 105 | + */ |
|
| 106 | + public function column_state( $user ) { |
|
| 107 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | + $state = $user->_wpinv_state; |
|
| 109 | + if ( $state ) { |
|
| 110 | + $state = wpinv_state_name( $state, $country ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return sanitize_text_field( $state ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Displays the total spent column. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * |
|
| 121 | + * @param WP_User $user |
|
| 122 | + * |
|
| 123 | + * @return string Column Name |
|
| 124 | + */ |
|
| 125 | + public function column_total( $user ) { |
|
| 126 | + |
|
| 127 | + $args = array( |
|
| 128 | + 'data' => array( |
|
| 129 | + |
|
| 130 | + 'total' => array( |
|
| 131 | + 'type' => 'invoice_data', |
|
| 132 | + 'function' => 'SUM', |
|
| 133 | + 'name' => 'total_sales', |
|
| 134 | + ) |
|
| 135 | + |
|
| 136 | + ), |
|
| 137 | + 'where' => array( |
|
| 138 | + |
|
| 139 | + 'author' => array( |
|
| 140 | + 'type' => 'post_data', |
|
| 141 | + 'value' => absint( $user->ID ), |
|
| 142 | + 'key' => 'posts.post_author', |
|
| 143 | + 'operator' => '=', |
|
| 144 | + ), |
|
| 145 | + |
|
| 146 | + ), |
|
| 147 | + 'query_type' => 'get_var', |
|
| 148 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 149 | + ); |
|
| 150 | + |
|
| 151 | + return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Displays the total spent column. |
|
| 157 | + * |
|
| 158 | + * @since 1.0.19 |
|
| 159 | + * |
|
| 160 | + * @param WP_User $user |
|
| 161 | + * |
|
| 162 | + * @return string Column Name |
|
| 163 | + */ |
|
| 164 | + public function column_invoices( $user ) { |
|
| 165 | + |
|
| 166 | + $args = array( |
|
| 167 | + 'data' => array( |
|
| 168 | + |
|
| 169 | + 'ID' => array( |
|
| 170 | + 'type' => 'post_data', |
|
| 171 | + 'function' => 'COUNT', |
|
| 172 | + 'name' => 'count', |
|
| 173 | + 'distinct' => true, |
|
| 174 | + ), |
|
| 175 | + |
|
| 176 | + ), |
|
| 177 | + 'where' => array( |
|
| 178 | + |
|
| 179 | + 'author' => array( |
|
| 180 | + 'type' => 'post_data', |
|
| 181 | + 'value' => absint( $user->ID ), |
|
| 182 | + 'key' => 'posts.post_author', |
|
| 183 | + 'operator' => '=', |
|
| 184 | + ), |
|
| 185 | + |
|
| 186 | + ), |
|
| 187 | + 'query_type' => 'get_var', |
|
| 188 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 189 | + ); |
|
| 190 | + |
|
| 191 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 192 | + |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Generates content for a single row of the table |
|
| 197 | + * @since 1.0.19 |
|
| 198 | + * |
|
| 199 | + * @param int $item The user id. |
|
| 200 | + */ |
|
| 201 | + public function single_row( $item ) { |
|
| 202 | + $item = get_user_by( 'id', $item ); |
|
| 203 | + |
|
| 204 | + if ( empty( $item ) ) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + echo '<tr>'; |
|
| 209 | + $this->single_row_columns( $item ); |
|
| 210 | + echo '</tr>'; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Displays the customers name |
|
| 215 | + * |
|
| 216 | + * @param WP_User $customer customer. |
|
| 217 | + * @return string |
|
| 218 | + */ |
|
| 219 | + public function column_name( $customer ) { |
|
| 220 | + |
|
| 221 | + // Customer view URL. |
|
| 222 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 223 | + $row_actions = $this->row_actions( |
|
| 224 | + array( |
|
| 225 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + |
|
| 229 | + // Get user's address. |
|
| 230 | + $address = wpinv_get_user_address( $customer->ID ); |
|
| 231 | + |
|
| 232 | + // Customer email address. |
|
| 233 | + $email = sanitize_email( $customer->user_email ); |
|
| 234 | + |
|
| 235 | + // Customer's avatar. |
|
| 236 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 237 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 238 | + |
|
| 239 | + // Customer's name. |
|
| 240 | + $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 241 | + |
|
| 242 | + if ( ! empty( $name ) ) { |
|
| 243 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 247 | + |
|
| 248 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 249 | + |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Retrieve the table columns |
|
| 254 | + * |
|
| 255 | + * @since 1.0.19 |
|
| 256 | + * @return array $columns Array of all the list table columns |
|
| 257 | + */ |
|
| 258 | + public function get_columns() { |
|
| 259 | + |
|
| 260 | + $columns = array( |
|
| 261 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 262 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 263 | + 'state' => __( 'State', 'invoicing' ), |
|
| 264 | + 'city' => __( 'City', 'invoicing' ), |
|
| 265 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 266 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 267 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 268 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 269 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 270 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 271 | + ); |
|
| 272 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 273 | + |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Retrieve the current page number |
|
| 278 | + * |
|
| 279 | + * @since 1.0.19 |
|
| 280 | + * @return int Current page number |
|
| 281 | + */ |
|
| 282 | + public function get_paged() { |
|
| 283 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns bulk actions. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @return void |
|
| 291 | + */ |
|
| 292 | + public function bulk_actions( $which = '' ) { |
|
| 293 | + return array(); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Prepares the display query |
|
| 298 | + */ |
|
| 299 | + public function prepare_query() { |
|
| 300 | + global $wpdb; |
|
| 301 | + |
|
| 302 | + $post_types = 'WHERE '; |
|
| 303 | + |
|
| 304 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 305 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 309 | + |
|
| 310 | + // Users with invoices. |
|
| 311 | + $customers = $wpdb->get_col( |
|
| 312 | + $wpdb->prepare( |
|
| 313 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts $post_types LIMIT %d,%d", |
|
| 314 | + $this->get_paged() * 10 - 10, |
|
| 315 | + $this->per_page |
|
| 316 | + ) |
|
| 317 | + ); |
|
| 318 | + |
|
| 319 | + $this->items = $customers; |
|
| 320 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts $post_types" ); |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Setup the final data for the table |
|
| 326 | + * |
|
| 327 | + * @since 1.0.19 |
|
| 328 | + * @return void |
|
| 329 | + */ |
|
| 330 | + public function prepare_items() { |
|
| 331 | + $columns = $this->get_columns(); |
|
| 332 | + $hidden = array(); // No hidden columns |
|
| 333 | + $sortable = $this->get_sortable_columns(); |
|
| 334 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 335 | + $this->prepare_query(); |
|
| 336 | + |
|
| 337 | + $this->set_pagination_args( |
|
| 338 | + array( |
|
| 339 | + 'total_items' => $this->total, |
|
| 340 | + 'per_page' => $this->per_page, |
|
| 341 | + 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 342 | + ) |
|
| 343 | + ); |
|
| 344 | + |
|
| 345 | + } |
|
| 346 | 346 | } |
@@ -5,10 +5,10 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | // Exit if accessed directly |
| 8 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 8 | +if (!defined('ABSPATH')) exit; |
|
| 9 | 9 | |
| 10 | 10 | // Load WP_List_Table if not loaded |
| 11 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 11 | +if (!class_exists('WP_List_Table')) { |
|
| 12 | 12 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | public function __construct() { |
| 43 | 43 | |
| 44 | 44 | // Set parent defaults |
| 45 | - parent::__construct( array( |
|
| 45 | + parent::__construct(array( |
|
| 46 | 46 | 'singular' => 'id', |
| 47 | 47 | 'plural' => 'ids', |
| 48 | 48 | 'ajax' => false, |
| 49 | - ) ); |
|
| 49 | + )); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return string Column Name |
| 74 | 74 | */ |
| 75 | - public function column_default( $item, $column_name ) { |
|
| 76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 75 | + public function column_default($item, $column_name) { |
|
| 76 | + $value = sanitize_text_field(get_user_meta($item->ID, '_wpinv_' . $column_name, true)); |
|
| 77 | + return apply_filters('wpinv_customers_table_column' . $column_name, $value, $item); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return string Column Name |
| 88 | 88 | */ |
| 89 | - public function column_country( $user ) { |
|
| 90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | - if ( $country ) { |
|
| 92 | - $country = wpinv_country_name( $country ); |
|
| 89 | + public function column_country($user) { |
|
| 90 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
| 91 | + if ($country) { |
|
| 92 | + $country = wpinv_country_name($country); |
|
| 93 | 93 | } |
| 94 | - return sanitize_text_field( $country ); |
|
| 94 | + return sanitize_text_field($country); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return string Column Name |
| 105 | 105 | */ |
| 106 | - public function column_state( $user ) { |
|
| 107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 106 | + public function column_state($user) { |
|
| 107 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
| 108 | 108 | $state = $user->_wpinv_state; |
| 109 | - if ( $state ) { |
|
| 110 | - $state = wpinv_state_name( $state, $country ); |
|
| 109 | + if ($state) { |
|
| 110 | + $state = wpinv_state_name($state, $country); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - return sanitize_text_field( $state ); |
|
| 113 | + return sanitize_text_field($state); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return string Column Name |
| 124 | 124 | */ |
| 125 | - public function column_total( $user ) { |
|
| 125 | + public function column_total($user) { |
|
| 126 | 126 | |
| 127 | 127 | $args = array( |
| 128 | 128 | 'data' => array( |
@@ -138,17 +138,17 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | 'author' => array( |
| 140 | 140 | 'type' => 'post_data', |
| 141 | - 'value' => absint( $user->ID ), |
|
| 141 | + 'value' => absint($user->ID), |
|
| 142 | 142 | 'key' => 'posts.post_author', |
| 143 | 143 | 'operator' => '=', |
| 144 | 144 | ), |
| 145 | 145 | |
| 146 | 146 | ), |
| 147 | 147 | 'query_type' => 'get_var', |
| 148 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 148 | + 'invoice_status' => array('wpi-renewal', 'wpi-processing', 'publish'), |
|
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 151 | + return wpinv_price((float) GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
| 152 | 152 | |
| 153 | 153 | } |
| 154 | 154 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @return string Column Name |
| 163 | 163 | */ |
| 164 | - public function column_invoices( $user ) { |
|
| 164 | + public function column_invoices($user) { |
|
| 165 | 165 | |
| 166 | 166 | $args = array( |
| 167 | 167 | 'data' => array( |
@@ -178,17 +178,17 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | 'author' => array( |
| 180 | 180 | 'type' => 'post_data', |
| 181 | - 'value' => absint( $user->ID ), |
|
| 181 | + 'value' => absint($user->ID), |
|
| 182 | 182 | 'key' => 'posts.post_author', |
| 183 | 183 | 'operator' => '=', |
| 184 | 184 | ), |
| 185 | 185 | |
| 186 | 186 | ), |
| 187 | 187 | 'query_type' => 'get_var', |
| 188 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 188 | + 'invoice_status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 191 | + return absint(GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
| 192 | 192 | |
| 193 | 193 | } |
| 194 | 194 | |
@@ -198,15 +198,15 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @param int $item The user id. |
| 200 | 200 | */ |
| 201 | - public function single_row( $item ) { |
|
| 202 | - $item = get_user_by( 'id', $item ); |
|
| 201 | + public function single_row($item) { |
|
| 202 | + $item = get_user_by('id', $item); |
|
| 203 | 203 | |
| 204 | - if ( empty( $item ) ) { |
|
| 204 | + if (empty($item)) { |
|
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | echo '<tr>'; |
| 209 | - $this->single_row_columns( $item ); |
|
| 209 | + $this->single_row_columns($item); |
|
| 210 | 210 | echo '</tr>'; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -216,30 +216,30 @@ discard block |
||
| 216 | 216 | * @param WP_User $customer customer. |
| 217 | 217 | * @return string |
| 218 | 218 | */ |
| 219 | - public function column_name( $customer ) { |
|
| 219 | + public function column_name($customer) { |
|
| 220 | 220 | |
| 221 | 221 | // Customer view URL. |
| 222 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 222 | + $view_url = esc_url(add_query_arg('user_id', $customer->ID, admin_url('user-edit.php'))); |
|
| 223 | 223 | $row_actions = $this->row_actions( |
| 224 | 224 | array( |
| 225 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 225 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __('Edit Details', 'invoicing') . '</a>', |
|
| 226 | 226 | ) |
| 227 | 227 | ); |
| 228 | 228 | |
| 229 | 229 | // Get user's address. |
| 230 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 230 | + $address = wpinv_get_user_address($customer->ID); |
|
| 231 | 231 | |
| 232 | 232 | // Customer email address. |
| 233 | - $email = sanitize_email( $customer->user_email ); |
|
| 233 | + $email = sanitize_email($customer->user_email); |
|
| 234 | 234 | |
| 235 | 235 | // Customer's avatar. |
| 236 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 236 | + $avatar = esc_url(get_avatar_url($email)); |
|
| 237 | 237 | $avatar = "<img src='$avatar' height='32' width='32'/>"; |
| 238 | 238 | |
| 239 | 239 | // Customer's name. |
| 240 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 240 | + $name = sanitize_text_field("{$address['first_name']} {$address['last_name']}"); |
|
| 241 | 241 | |
| 242 | - if ( ! empty( $name ) ) { |
|
| 242 | + if (!empty($name)) { |
|
| 243 | 243 | $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -258,18 +258,18 @@ discard block |
||
| 258 | 258 | public function get_columns() { |
| 259 | 259 | |
| 260 | 260 | $columns = array( |
| 261 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 262 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 263 | - 'state' => __( 'State', 'invoicing' ), |
|
| 264 | - 'city' => __( 'City', 'invoicing' ), |
|
| 265 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 266 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 267 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 268 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 269 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 270 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 261 | + 'name' => __('Name', 'invoicing'), |
|
| 262 | + 'country' => __('Country', 'invoicing'), |
|
| 263 | + 'state' => __('State', 'invoicing'), |
|
| 264 | + 'city' => __('City', 'invoicing'), |
|
| 265 | + 'zip' => __('ZIP', 'invoicing'), |
|
| 266 | + 'address' => __('Address', 'invoicing'), |
|
| 267 | + 'phone' => __('Phone', 'invoicing'), |
|
| 268 | + 'company' => __('Company', 'invoicing'), |
|
| 269 | + 'invoices' => __('Invoices', 'invoicing'), |
|
| 270 | + 'total' => __('Total Spend', 'invoicing'), |
|
| 271 | 271 | ); |
| 272 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 272 | + return apply_filters('wpinv_customers_table_columns', $columns); |
|
| 273 | 273 | |
| 274 | 274 | } |
| 275 | 275 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @return int Current page number |
| 281 | 281 | */ |
| 282 | 282 | public function get_paged() { |
| 283 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 283 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @since 1.0.19 |
| 290 | 290 | * @return void |
| 291 | 291 | */ |
| 292 | - public function bulk_actions( $which = '' ) { |
|
| 292 | + public function bulk_actions($which = '') { |
|
| 293 | 293 | return array(); |
| 294 | 294 | } |
| 295 | 295 | |
@@ -301,11 +301,11 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | $post_types = 'WHERE '; |
| 303 | 303 | |
| 304 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 305 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 304 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
| 305 | + $post_types .= $wpdb->prepare("post_type=%s OR ", $post_type); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 308 | + $post_types = rtrim($post_types, ' OR'); |
|
| 309 | 309 | |
| 310 | 310 | // Users with invoices. |
| 311 | 311 | $customers = $wpdb->get_col( |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | 319 | $this->items = $customers; |
| 320 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts $post_types" ); |
|
| 320 | + $this->total = (int) $wpdb->get_var("SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts $post_types"); |
|
| 321 | 321 | |
| 322 | 322 | } |
| 323 | 323 | |
@@ -331,14 +331,14 @@ discard block |
||
| 331 | 331 | $columns = $this->get_columns(); |
| 332 | 332 | $hidden = array(); // No hidden columns |
| 333 | 333 | $sortable = $this->get_sortable_columns(); |
| 334 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 334 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 335 | 335 | $this->prepare_query(); |
| 336 | 336 | |
| 337 | 337 | $this->set_pagination_args( |
| 338 | 338 | array( |
| 339 | 339 | 'total_items' => $this->total, |
| 340 | 340 | 'per_page' => $this->per_page, |
| 341 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 341 | + 'total_pages' => ceil($this->total / $this->per_page) |
|
| 342 | 342 | ) |
| 343 | 343 | ); |
| 344 | 344 | |