| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * The list view under WP-Admin > Donations > Donors. |
| 6 | 6 | * |
| 7 | 7 | * @package Give |
| 8 | 8 | * @subpackage Admin/Reports |
| 9 | - * @copyright Copyright (c) 2016, WordImpress | |
| 9 | + * @copyright Copyright (c) 2016, GiveWP | |
| 10 | 10 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 11 | 11 | * @since 1.0 |
| 12 | 12 | */ |
| 13 | 13 | |
| @@ -58,47 +58,122 @@ | ||
| 58 | 58 | * @since 1.0 |
| 59 | 59 | * @see WP_List_Table::__construct() |
| 60 | 60 | */ |
| 61 | 61 | public function __construct() { |
| 62 | - | |
| 63 | 62 | // Set parent defaults. |
| 64 | - parent::__construct( array( | |
| 65 | - 'singular' => __( 'Donor', 'give' ), // Singular name of the listed records. | |
| 66 | - 'plural' => __( 'Donors', 'give' ), // Plural name of the listed records. | |
| 67 | - 'ajax' => false, // Does this table support ajax?. | |
| 68 | - ) ); | |
| 63 | + parent::__construct( | |
| 64 | + [ | |
| 65 | + 'singular' => __( 'Donor', 'give' ), // Singular name of the listed records. | |
| 66 | + 'plural' => __( 'Donors', 'give' ), // Plural name of the listed records. | |
| 67 | + 'ajax' => false, // Does this table support ajax?. | |
| 68 | + ] | |
| 69 | + ); | |
| 69 | 70 | |
| 70 | 71 | } |
| 71 | - | |
| 72 | 72 | /** |
| 73 | - * Show the search field. | |
| 73 | + * Add donors search filter. | |
| 74 | 74 | * |
| 75 | - * @param string $text Label for the search box. | |
| 76 | - * @param string $input_id ID of the search box. | |
| 77 | - * | |
| 78 | - * @since 1.0 | |
| 79 | - * @access public | |
| 80 | - * | |
| 75 | + * @since 3.5.0 Escape search query string. | |
| 76 | + * @since 2.4.0 | |
| 81 | 77 | * @return void |
| 82 | 78 | */ |
| 83 | - public function search_box( $text, $input_id ) { | |
| 84 | - $input_id = $input_id . '-search-input'; | |
| 79 | + public function advanced_filters() { | |
| 80 | + $start_date = isset( $_GET['start-date'] ) ? strtotime( give_clean( $_GET['start-date'] ) ) : ''; | |
| 81 | + $end_date = isset( $_GET['end-date'] ) ? strtotime( give_clean( $_GET['end-date'] ) ) : ''; | |
| 82 | + $status = isset( $_GET['status'] ) ? give_clean( $_GET['status'] ) : ''; | |
| 83 | + $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : ''; | |
| 84 | + $search = $this->get_search(); | |
| 85 | + $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; | |
| 86 | + ?> | |
| 87 | + <div id="give-donor-filters" class="give-filters"> | |
| 88 | + <div class="give-donor-search-box"> | |
| 89 | + <input type="text" id="give-donors-search-input" placeholder="<?php | |
| 90 | + _e('Name, Email, or Donor ID', 'give'); ?>" name="s" value="<?php | |
| 91 | + echo esc_attr($search); ?>"> | |
| 92 | + <?php | |
| 93 | + submit_button( | |
| 94 | + __( 'Search', 'give' ), | |
| 95 | + 'button', | |
| 96 | + false, | |
| 97 | + false, | |
| 98 | + [ | |
| 99 | + 'ID' => 'donor-search-submit', | |
| 100 | + ] | |
| 101 | + ); | |
| 102 | + ?> | |
| 103 | + </div> | |
| 104 | + <div class="give-filter give-filter-half"> | |
| 105 | + <label for="start-date" | |
| 106 | + class="give-start-date-label"><?php _e( 'Start Date', 'give' ); ?></label> | |
| 107 | + <input type="text" | |
| 108 | + id="start-date" | |
| 109 | + name="start-date" | |
| 110 | + class="give_datepicker" | |
| 111 | + autocomplete="off" | |
| 112 | + value="<?php echo $start_date ? date_i18n( give_date_format(), $start_date ) : ''; ?>" | |
| 113 | + data-standard-date="<?php echo $start_date ? date( 'Y-m-d', $start_date ) : $start_date; ?>" | |
| 114 | + placeholder="<?php _e( 'Start Date', 'give' ); ?>" | |
| 115 | + /> | |
| 116 | + </div> | |
| 117 | + <div class="give-filter give-filter-half"> | |
| 118 | + <label for="end-date" class="give-end-date-label"><?php _e( 'End Date', 'give' ); ?></label> | |
| 119 | + <input type="text" | |
| 120 | + id="end-date" | |
| 121 | + name="end-date" | |
| 122 | + class="give_datepicker" | |
| 123 | + autocomplete="off" | |
| 124 | + value="<?php echo $end_date ? date_i18n( give_date_format(), $end_date ) : ''; ?>" | |
| 125 | + data-standard-date="<?php echo $end_date ? date( 'Y-m-d', $end_date ) : $end_date; ?>" | |
| 126 | + placeholder="<?php _e( 'End Date', 'give' ); ?>" | |
| 127 | + /> | |
| 128 | + </div> | |
| 129 | + <div id="give-payment-form-filter" class="give-filter"> | |
| 130 | + <label for="give-donation-forms-filter" | |
| 131 | + class="give-donation-forms-filter-label"><?php _e( 'Form', 'give' ); ?></label> | |
| 132 | + <?php | |
| 133 | + // Filter Donations by Donation Forms. | |
| 134 | + echo Give()->html->forms_dropdown( | |
| 135 | + [ | |
| 136 | + 'name' => 'form_id', | |
| 137 | + 'id' => 'give-donation-forms-filter', | |
| 138 | + 'class' => 'give-donation-forms-filter', | |
| 139 | + 'selected' => $form_id, // Make sure to have $form_id set to 0, if there is no selection. | |
| 140 | + 'chosen' => true, | |
| 141 | + 'number' => 30, | |
| 142 | + ] | |
| 143 | + ); | |
| 144 | + ?> | |
| 145 | + </div> | |
| 85 | 146 | |
| 86 | - if ( ! empty( $_REQUEST['orderby'] ) ) { | |
| 87 | - echo sprintf( '<input type="hidden" name="orderby" value="%1$s" />', esc_attr( $_REQUEST['orderby'] ) ); | |
| 88 | - } | |
| 147 | + <?php | |
| 148 | + /** | |
| 149 | + * Action to add hidden fields and HTML in donor search. | |
| 150 | + * | |
| 151 | + * @since 2.4.0 | |
| 152 | + */ | |
| 153 | + do_action( 'give_donor_table_advanced_filters' ); | |
| 89 | 154 | |
| 90 | - if ( ! empty( $_REQUEST['order'] ) ) { | |
| 91 | - echo sprintf( '<input type="hidden" name="order" value="%1$s" />', esc_attr( $_REQUEST['order'] ) ); | |
| 92 | - } | |
| 93 | - ?> | |
| 94 | - <p class="search-box" role="search"> | |
| 95 | - <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> | |
| 96 | - <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/> | |
| 97 | - <?php submit_button( $text, 'button', false, false, array( | |
| 98 | - 'ID' => 'search-submit', | |
| 99 | - ) ); ?> | |
| 100 | - </p> | |
| 155 | + if ( ! empty( $status ) ) { | |
| 156 | + echo sprintf( '<input type="hidden" name="status" value="%s"/>', esc_attr( $status ) ); | |
| 157 | + } | |
| 158 | + | |
| 159 | + if ( ! empty( $donor ) ) { | |
| 160 | + echo sprintf( '<input type="hidden" name="donor" value="%s"/>', absint( $donor ) ); | |
| 161 | + } | |
| 162 | + ?> | |
| 163 | + | |
| 164 | + <div class="give-filter"> | |
| 165 | + <?php submit_button( __( 'Apply', 'give' ), 'secondary', '', false ); ?> | |
| 166 | + <?php | |
| 167 | + // Clear active filters button. | |
| 168 | + if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor ) || ! empty( $search ) || ! empty( $status ) || ! empty( $form_id ) ) : | |
| 169 | + ?> | |
| 170 | + <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); ?>" | |
| 171 | + class="button give-clear-filters-button"><?php _e( 'Clear Filters', 'give' ); ?></a> | |
| 172 | + <?php endif; ?> | |
| 173 | + </div> | |
| 174 | + </div> | |
| 175 | + | |
| 101 | 176 | <?php |
| 102 | 177 | } |
| 103 | 178 | |
| 104 | 179 | /** |
| @@ -103,9 +178,9 @@ | ||
| 103 | 178 | |
| 104 | 179 | /** |
| 105 | 180 | * This function renders most of the columns in the list table. |
| 106 | 181 | * |
| 107 | - * @param array $donor Contains all the data of the donors. | |
| 182 | + * @param array $donor Contains all the data of the donors. | |
| 108 | 183 | * @param string $column_name The name of the column. |
| 109 | 184 | * |
| 110 | 185 | * @access public |
| 111 | 186 | * @since 1.0 |
| @@ -115,9 +190,9 @@ | ||
| 115 | 190 | public function column_default( $donor, $column_name ) { |
| 116 | 191 | |
| 117 | 192 | switch ( $column_name ) { |
| 118 | 193 | |
| 119 | - case 'num_donations' : | |
| 194 | + case 'num_donations': | |
| 120 | 195 | $value = sprintf( |
| 121 | 196 | '<a href="%s">%s</a>', |
| 122 | 197 | admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor['id'] ) ), |
| 123 | 198 | esc_html( $donor['num_donations'] ) |
| @@ -123,16 +198,20 @@ | ||
| 123 | 198 | esc_html( $donor['num_donations'] ) |
| 124 | 199 | ); |
| 125 | 200 | break; |
| 126 | 201 | |
| 127 | - case 'amount_spent' : | |
| 128 | - $value = give_currency_filter( give_format_amount( $donor[ $column_name ], array( 'sanitize' => false ) ) ); | |
| 202 | + case 'amount_spent': | |
| 203 | + $value = give_currency_filter( give_format_amount( $donor[ $column_name ], [ 'sanitize' => false ] ) ); | |
| 129 | 204 | break; |
| 130 | 205 | |
| 131 | - case 'date_created' : | |
| 206 | + case 'date_created': | |
| 132 | 207 | $value = date_i18n( give_date_format(), strtotime( $donor['date_created'] ) ); |
| 133 | 208 | break; |
| 134 | 209 | |
| 210 | + case 'email': | |
| 211 | + $value = esc_html( $donor[ $column_name ] ); | |
| 212 | + break; | |
| 213 | + | |
| 135 | 214 | default: |
| 136 | 215 | $value = isset( $donor[ $column_name ] ) ? $donor[ $column_name ] : null; |
| 137 | 216 | break; |
| 138 | 217 | } |
| @@ -152,12 +231,11 @@ | ||
| 152 | 231 | * @return string |
| 153 | 232 | */ |
| 154 | 233 | public function column_cb( $donor ) { |
| 155 | 234 | return sprintf( |
| 156 | - '<input class="donor-selector" type="checkbox" name="%1$s[]" value="%2$d" data-name="%3$s" />', | |
| 157 | - $this->_args['singular'], | |
| 235 | + '<input class="donor-selector" type="checkbox" name="donor[]" value="%1$d" data-name="%2$s" />', | |
| 158 | 236 | $donor['id'], |
| 159 | - $donor['name'] | |
| 237 | + esc_attr( $donor['name'] ) | |
| 160 | 238 | ); |
| 161 | 239 | } |
| 162 | 240 | |
| 163 | 241 | /** |
| @@ -170,13 +248,44 @@ | ||
| 170 | 248 | * |
| 171 | 249 | * @return string |
| 172 | 250 | */ |
| 173 | 251 | public function column_name( $donor ) { |
| 174 | - $name = ! empty( $donor['name'] ) ? $donor['name'] : '<em>' . __( 'Unnamed Donor', 'give' ) . '</em>'; | |
| 175 | - $view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] ); | |
| 252 | + | |
| 253 | + // Get donor's initials for non-gravatars | |
| 254 | + $title_prefix = Give()->donor_meta->get_meta( $donor['id'], '_give_donor_title_prefix', true ); | |
| 255 | + $donor_name_without_prefix = trim( str_replace( $title_prefix, '', $donor['name'] ) ); | |
| 256 | + $donor_name_array = explode( ' ', $donor_name_without_prefix ); | |
| 257 | + $donor_name_args['firstname'] = ! empty( $donor_name_array[0] ) ? $donor_name_array[0] : ''; | |
| 258 | + $donor_name_args['lastname'] = ! empty( $donor_name_array[1] ) ? $donor_name_array[1] : ''; | |
| 259 | + $donor_name_initial = give_get_name_initial( $donor_name_args ); | |
| 260 | + | |
| 261 | + $donation_gravatar_image = sprintf( | |
| 262 | + '<span class="give-donor__image give-donor-admin-avatar" data-donor_email="%1$s" data-has-valid-gravatar="%2$s">%3$s</span>', | |
| 263 | + md5( strtolower( trim( $donor['email'] ) ) ), | |
| 264 | + absint( give_validate_gravatar( $donor['email'] ) ), | |
| 265 | + esc_attr( $donor_name_initial ) | |
| 266 | + ); | |
| 267 | + | |
| 268 | + $name = ! empty( $donor['name'] ) | |
| 269 | + ? sprintf( | |
| 270 | + '%1$s<span class="give-donor-name-text">%2$s</span>', | |
| 271 | + $donation_gravatar_image, | |
| 272 | + esc_attr( $donor['name'] ) | |
| 273 | + ) | |
| 274 | + : sprintf( | |
| 275 | + '<em>%1$s</em>', | |
| 276 | + __( 'Unnamed Donor', 'give' ) | |
| 277 | + ); | |
| 278 | + | |
| 279 | + $view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor['id'] ); | |
| 176 | 280 | $actions = $this->get_row_actions( $donor ); |
| 177 | 281 | |
| 178 | - return '<a href="' . esc_url( $view_url ) . '">' . $name . '</a>' . $this->row_actions( $actions ); | |
| 282 | + return sprintf( | |
| 283 | + '<a href="%1$s" class="give-donor-name">%2$s</a>%3$s', | |
| 284 | + esc_url( $view_url ), | |
| 285 | + $name, | |
| 286 | + $this->row_actions( $actions ) | |
| 287 | + ); | |
| 179 | 288 | } |
| 180 | 289 | |
| 181 | 290 | /** |
| 182 | 291 | * Retrieve the table columns. |
| @@ -186,9 +295,9 @@ | ||
| 186 | 295 | * |
| 187 | 296 | * @return array $columns Array of all the list table columns. |
| 188 | 297 | */ |
| 189 | 298 | public function get_columns() { |
| 190 | - $columns = array( | |
| 299 | + $columns = [ | |
| 191 | 300 | 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
| 192 | 301 | 'name' => __( 'Name', 'give' ), |
| 193 | 302 | 'email' => __( 'Email', 'give' ), |
| 194 | 303 | 'num_donations' => __( 'Donations', 'give' ), |
| @@ -193,9 +302,9 @@ | ||
| 193 | 302 | 'email' => __( 'Email', 'give' ), |
| 194 | 303 | 'num_donations' => __( 'Donations', 'give' ), |
| 195 | 304 | 'amount_spent' => __( 'Total Donated', 'give' ), |
| 196 | 305 | 'date_created' => __( 'Date Created', 'give' ), |
| 197 | - ); | |
| 306 | + ]; | |
| 198 | 307 | |
| 199 | 308 | return apply_filters( 'give_list_donors_columns', $columns ); |
| 200 | 309 | |
| 201 | 310 | } |
| @@ -208,14 +317,14 @@ | ||
| 208 | 317 | * @return array Array of all the sortable columns. |
| 209 | 318 | */ |
| 210 | 319 | public function get_sortable_columns() { |
| 211 | 320 | |
| 212 | - $columns = array( | |
| 213 | - 'date_created' => array( 'date_created', true ), | |
| 214 | - 'name' => array( 'name', true ), | |
| 215 | - 'num_donations' => array( 'purchase_count', false ), | |
| 216 | - 'amount_spent' => array( 'purchase_value', false ), | |
| 217 | - ); | |
| 321 | + $columns = [ | |
| 322 | + 'date_created' => [ 'date_created', true ], | |
| 323 | + 'name' => [ 'name', true ], | |
| 324 | + 'num_donations' => [ 'purchase_count', false ], | |
| 325 | + 'amount_spent' => [ 'purchase_value', false ], | |
| 326 | + ]; | |
| 218 | 327 | |
| 219 | 328 | return apply_filters( 'give_list_donors_sortable_columns', $columns ); |
| 220 | 329 | } |
| 221 | 330 | |
| @@ -230,13 +339,13 @@ | ||
| 230 | 339 | * @return array An array of action links. |
| 231 | 340 | */ |
| 232 | 341 | public function get_row_actions( $donor ) { |
| 233 | 342 | |
| 234 | - $actions = array( | |
| 235 | - 'view' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor['id'] ), sprintf( esc_attr__( 'View "%s"', 'give' ), $donor['name'] ), __( 'View Donor', 'give' ) ), | |
| 236 | - 'notes' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=notes&id=' . $donor['id'] ), sprintf( esc_attr__( 'Notes for "%s"', 'give' ), $donor['name'] ), __( 'Notes', 'give' ) ), | |
| 237 | - 'delete' => sprintf( '<a class="%1$s" data-id="%2$s" href="#" aria-label="%3$s">%4$s</a>', 'give-single-donor-delete', $donor['id'],sprintf( esc_attr__( 'Delete "%s"', 'give' ), $donor['name'] ), __( 'Delete', 'give' ) ), | |
| 238 | - ); | |
| 343 | + $actions = [ | |
| 344 | + 'id' => '<span class="give-donor-id">ID: ' . $donor['id'] . ' </span>', | |
| 345 | + 'view' => sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor['id'] ), sprintf( esc_attr__( 'View "%s"', 'give' ), esc_attr( $donor['name'] ) ), __( 'View Donor', 'give' ) ), | |
| 346 | + 'delete' => sprintf( '<a class="%1$s" data-id="%2$s" href="#" aria-label="%3$s">%4$s</a>', 'give-single-donor-delete', $donor['id'], sprintf( esc_attr__( 'Delete "%s"', 'give' ), esc_attr( $donor['name'] ) ), __( 'Delete', 'give' ) ), | |
| 347 | + ]; | |
| 239 | 348 | |
| 240 | 349 | return apply_filters( 'give_donor_row_actions', $actions, $donor ); |
| 241 | 350 | |
| 242 | 351 | } |
| @@ -256,14 +365,22 @@ | ||
| 256 | 365 | /** |
| 257 | 366 | * Retrieves the search query string. |
| 258 | 367 | * |
| 259 | 368 | * @access public |
| 369 | + * @since 3.5.0 Remove escape function | |
| 260 | 370 | * @since 1.0 |
| 261 | 371 | * |
| 262 | 372 | * @return mixed string If search is present, false otherwise. |
| 263 | 373 | */ |
| 264 | 374 | public function get_search() { |
| 265 | - return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; | |
| 375 | + | |
| 376 | + if ( ! isset( $_GET['s'] ) ) { | |
| 377 | + return false; | |
| 378 | + } | |
| 379 | + | |
| 380 | + $search = urldecode(trim($_GET['s'])); | |
| 381 | + | |
| 382 | + return ! empty($search) ? $search : false; | |
| 266 | 383 | } |
| 267 | 384 | |
| 268 | 385 | /** |
| 269 | 386 | * Get the Bulk Actions. |
| @@ -273,11 +390,12 @@ | ||
| 273 | 390 | * |
| 274 | 391 | * @return array |
| 275 | 392 | */ |
| 276 | 393 | public function get_bulk_actions() { |
| 277 | - $actions = array( | |
| 394 | + $actions = [ | |
| 278 | 395 | 'delete' => __( 'Delete', 'give' ), |
| 279 | - ); | |
| 396 | + ]; | |
| 397 | + | |
| 280 | 398 | return $actions; |
| 281 | 399 | } |
| 282 | 400 | |
| 283 | 401 | /** |
| @@ -289,9 +407,9 @@ | ||
| 289 | 407 | * @since 1.8.16 |
| 290 | 408 | */ |
| 291 | 409 | protected function display_tablenav( $which ) { |
| 292 | 410 | if ( 'top' === $which ) { |
| 293 | - wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false ); | |
| 411 | + wp_nonce_field( 'bulk-donors', '_wpnonce', false ); | |
| 294 | 412 | } |
| 295 | 413 | ?> |
| 296 | 414 | <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 297 | 415 | <?php if ( $this->has_items() ) : ?> |
| @@ -297,13 +415,14 @@ | ||
| 297 | 415 | <?php if ( $this->has_items() ) : ?> |
| 298 | 416 | <div class="alignleft actions bulkactions"> |
| 299 | 417 | <?php $this->bulk_actions( $which ); ?> |
| 300 | 418 | </div> |
| 301 | - <?php endif; | |
| 419 | + <?php | |
| 420 | + endif; | |
| 302 | 421 | $this->extra_tablenav( $which ); |
| 303 | 422 | $this->pagination( $which ); |
| 304 | 423 | ?> |
| 305 | - <br class="clear" /> | |
| 424 | + <br class="clear"/> | |
| 306 | 425 | </div> |
| 307 | 426 | <?php |
| 308 | 427 | } |
| 309 | 428 | |
| @@ -309,9 +428,9 @@ | ||
| 309 | 428 | |
| 310 | 429 | /** |
| 311 | 430 | * Retrieves the donor data from db. |
| 312 | 431 | * |
| 313 | - * @access public | |
| 432 | + * @since 2.21.2 Add second param to "give_donors_column_query_data" filter hook. | |
| 314 | 433 | * @since 1.0 |
| 315 | 434 | * |
| 316 | 435 | * @return array $data The Donor data. |
| 317 | 436 | */ |
| @@ -316,9 +435,9 @@ | ||
| 316 | 435 | * @return array $data The Donor data. |
| 317 | 436 | */ |
| 318 | 437 | public function donor_data() { |
| 319 | 438 | |
| 320 | - $data = array(); | |
| 439 | + $data = []; | |
| 321 | 440 | |
| 322 | 441 | // Get donor query. |
| 323 | 442 | $args = $this->get_donor_query(); |
| 324 | 443 | $donors = Give()->donors->get_donors( $args ); |
| @@ -332,9 +451,9 @@ | ||
| 332 | 451 | |
| 333 | 452 | // If title prefix is set, then update the donor name. |
| 334 | 453 | $donor->name = give_get_donor_name_with_title_prefixes( $title_prefix, $donor->name ); |
| 335 | 454 | |
| 336 | - $data[] = array( | |
| 455 | + $data[] = [ | |
| 337 | 456 | 'id' => $donor->id, |
| 338 | 457 | 'user_id' => $user_id, |
| 339 | 458 | 'name' => $donor->name, |
| 340 | 459 | 'email' => $donor->email, |
| @@ -340,13 +459,13 @@ | ||
| 340 | 459 | 'email' => $donor->email, |
| 341 | 460 | 'num_donations' => $donor->purchase_count, |
| 342 | 461 | 'amount_spent' => $donor->purchase_value, |
| 343 | 462 | 'date_created' => $donor->date_created, |
| 344 | - ); | |
| 463 | + ]; | |
| 345 | 464 | } |
| 346 | 465 | } |
| 347 | 466 | |
| 348 | - return apply_filters( 'give_donors_column_query_data', $data ); | |
| 467 | + return apply_filters( 'give_donors_column_query_data', $data, $donors ); | |
| 349 | 468 | } |
| 350 | 469 | |
| 351 | 470 | /** |
| 352 | 471 | * Get donor count. |
| @@ -359,16 +478,17 @@ | ||
| 359 | 478 | $_donor_query = $this->get_donor_query(); |
| 360 | 479 | |
| 361 | 480 | $_donor_query['number'] = - 1; |
| 362 | 481 | $_donor_query['offset'] = 0; |
| 363 | - $donors = Give()->donors->get_donors( $_donor_query ); | |
| 482 | + $_donor_query['count'] = true; | |
| 364 | 483 | |
| 365 | - return count( $donors ); | |
| 484 | + return Give()->donors->get_donors( $_donor_query ); | |
| 366 | 485 | } |
| 367 | 486 | |
| 368 | 487 | /** |
| 369 | 488 | * Get donor query. |
| 370 | 489 | * |
| 490 | + * @since 3.5.0 Escape search query string. | |
| 371 | 491 | * @since 1.8.1 |
| 372 | 492 | * @access public |
| 373 | 493 | * |
| 374 | 494 | * @return array |
| @@ -373,30 +493,39 @@ | ||
| 373 | 493 | * |
| 374 | 494 | * @return array |
| 375 | 495 | */ |
| 376 | 496 | public function get_donor_query() { |
| 377 | - $paged = $this->get_paged(); | |
| 378 | - $offset = $this->per_page * ( $paged - 1 ); | |
| 379 | - $search = $this->get_search(); | |
| 380 | - $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC'; | |
| 381 | - $orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id'; | |
| 497 | + $per_page = $this->per_page; | |
| 498 | + $paged = $this->get_paged(); | |
| 499 | + $donor = isset( $_GET['donor'] ) ? absint( $_GET['donor'] ) : null; | |
| 500 | + $start_date = ! empty( $_GET['start-date'] ) ? strtotime( give_clean( $_GET['start-date'] ) ) : false; | |
| 501 | + $end_date = ! empty( $_GET['end-date'] ) ? strtotime( give_clean( $_GET['end-date'] ) ) : false; | |
| 502 | + $form_id = ! empty( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : null; | |
| 503 | + $offset = $this->per_page * ( $paged - 1 ); | |
| 504 | + $search = $this->get_search(); | |
| 505 | + $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC'; | |
| 506 | + $orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id'; | |
| 382 | 507 | |
| 383 | - $args = array( | |
| 384 | - 'number' => $this->per_page, | |
| 385 | - 'offset' => $offset, | |
| 386 | - 'order' => $order, | |
| 387 | - 'orderby' => $orderby, | |
| 388 | - ); | |
| 508 | + $args = [ | |
| 509 | + 'output' => 'payments', | |
| 510 | + 'number' => $per_page, | |
| 511 | + 'offset' => $offset, | |
| 512 | + 'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, | |
| 513 | + 'orderby' => $orderby, | |
| 514 | + 'order' => $order, | |
| 515 | + 'donor' => $donor, | |
| 516 | + 's' => esc_sql($search), | |
| 517 | + 'start_date' => $start_date, | |
| 518 | + 'end_date' => $end_date, | |
| 519 | + 'give_forms' => $form_id, | |
| 520 | + ]; | |
| 389 | 521 | |
| 390 | - if ( $search ) { | |
| 391 | - if ( is_email( $search ) ) { | |
| 392 | - $args['email'] = $search; | |
| 393 | - } elseif ( is_numeric( $search ) ) { | |
| 394 | - $args['id'] = $search; | |
| 395 | - } else { | |
| 396 | - $args['name'] = $search; | |
| 397 | - } | |
| 398 | - } | |
| 522 | + /** | |
| 523 | + * Filter to modify donor table argument. | |
| 524 | + * | |
| 525 | + * @since 2.4.0 | |
| 526 | + */ | |
| 527 | + $args = (array) apply_filters( 'give_donor_table_query', $args ); | |
| 399 | 528 | |
| 400 | 529 | return $args; |
| 401 | 530 | } |
| 402 | 531 | |
| @@ -408,9 +537,9 @@ | ||
| 408 | 537 | * @since 1.8.17 |
| 409 | 538 | * @access public |
| 410 | 539 | */ |
| 411 | 540 | public function single_row( $item ) { |
| 412 | - echo sprintf( '<tr id="donor-%1$d" data-id="%2$d" data-name="%3$s">', $item['id'], $item['id'], $item['name'] ); | |
| 541 | + echo sprintf( '<tr id="donor-%1$d" data-id="%2$d" data-name="%3$s">', $item['id'], $item['id'], esc_attr( $item['name'] ) ); | |
| 413 | 542 | $this->single_row_columns( $item ); |
| 414 | 543 | echo '</tr>'; |
| 415 | 544 | } |
| 416 | 545 | |
| @@ -416,9 +545,9 @@ | ||
| 416 | 545 | |
| 417 | 546 | /** |
| 418 | 547 | * Display the final donor table |
| 419 | 548 | * |
| 420 | - * @since 1.8.17 | |
| 549 | + * @since 1.8.17 | |
| 421 | 550 | * @access public |
| 422 | 551 | */ |
| 423 | 552 | public function display() { |
| 424 | 553 | $singular = $this->_args['singular']; |
| @@ -428,11 +557,10 @@ | ||
| 428 | 557 | $this->screen->render_screen_reader_content( 'heading_list' ); |
| 429 | 558 | |
| 430 | 559 | $get_data = give_clean( $_GET ); // WPCS: input var ok, sanitization ok, CSRF ok. |
| 431 | 560 | |
| 432 | - $search_keyword = ! empty( $get_data['s'] ) ? $get_data['s'] : ''; | |
| 433 | - $order = ! empty( $get_data['order'] ) ? $get_data['order'] : 'DESC'; | |
| 434 | - $order_by = ! empty( $get_data['orderby'] ) ? $get_data['orderby'] : 'id'; | |
| 561 | + $order = ! empty( $get_data['order'] ) ? $get_data['order'] : 'DESC'; | |
| 562 | + $order_by = ! empty( $get_data['orderby'] ) ? $get_data['orderby'] : 'id'; | |
| 435 | 563 | ?> |
| 436 | 564 | <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> |
| 437 | 565 | <thead> |
| 438 | 566 | <tr> |
| @@ -439,14 +567,19 @@ | ||
| 439 | 567 | <?php $this->print_column_headers(); ?> |
| 440 | 568 | </tr> |
| 441 | 569 | </thead> |
| 442 | 570 | |
| 443 | - <tbody id="the-list"<?php | |
| 571 | + <tbody id="the-list" | |
| 572 | + <?php | |
| 444 | 573 | if ( $singular ) { |
| 445 | 574 | echo " data-wp-lists='list:$singular'"; |
| 446 | - } ?>> | |
| 575 | + } | |
| 576 | + ?> | |
| 577 | + > | |
| 447 | 578 | <tr class="hidden"></tr> |
| 448 | - <tr id="give-bulk-delete" class="inline-edit-row inline-edit-row-page inline-edit-page bulk-edit-row bulk-edit-row-page bulk-edit-page inline-editor" style="display: none;" > | |
| 579 | + <tr id="give-bulk-delete" | |
| 580 | + class="inline-edit-row inline-edit-row-page inline-edit-page bulk-edit-row bulk-edit-row-page bulk-edit-page inline-editor" | |
| 581 | + style="display: none;"> | |
| 449 | 582 | <td colspan="6" class="colspanchange"> |
| 450 | 583 | |
| 451 | 584 | <fieldset class="inline-edit-col-left"> |
| 452 | 585 | <legend class="inline-edit-legend"><?php esc_attr_e( 'BULK DELETE', 'give' ); ?></legend> |
| @@ -460,13 +593,15 @@ | ||
| 460 | 593 | |
| 461 | 594 | <fieldset class="inline-edit-col-right"> |
| 462 | 595 | <div class="inline-edit-col"> |
| 463 | 596 | <label> |
| 464 | - <input class="give-donor-delete-confirm" type="checkbox" name="give-donor-delete-confirm"/> | |
| 597 | + <input class="give-donor-delete-confirm" type="checkbox" | |
| 598 | + name="give-donor-delete-confirm"/> | |
| 465 | 599 | <?php esc_attr_e( 'Are you sure you want to delete the selected donor(s)?', 'give' ); ?> |
| 466 | 600 | </label> |
| 467 | 601 | <label> |
| 468 | - <input class="give-donor-delete-records" type="checkbox" name="give-donor-delete-records"/> | |
| 602 | + <input class="give-donor-delete-records" type="checkbox" | |
| 603 | + name="give-donor-delete-records"/> | |
| 469 | 604 | <?php esc_attr_e( 'Delete all associated donations and records?', 'give' ); ?> |
| 470 | 605 | </label> |
| 471 | 606 | </div> |
| 472 | 607 | </fieldset> |
| @@ -472,13 +607,15 @@ | ||
| 472 | 607 | </fieldset> |
| 473 | 608 | |
| 474 | 609 | <p class="submit inline-edit-save"> |
| 475 | 610 | <input type="hidden" name="give_action" value="delete_bulk_donor"/> |
| 476 | - <input type="hidden" name="s" value="<?php echo esc_html( $search_keyword ); ?>"/> | |
| 477 | 611 | <input type="hidden" name="orderby" value="<?php echo esc_html( $order_by ); ?>"/> |
| 478 | 612 | <input type="hidden" name="order" value="<?php echo esc_html( $order ); ?>"/> |
| 479 | - <button type="button" id="give-bulk-delete-cancel" class="button cancel alignleft"><?php esc_attr_e( 'Cancel', 'give' ); ?></button> | |
| 480 | - <input type="submit" id="give-bulk-delete-button" disabled class="button button-primary alignright" value="<?php esc_attr_e( 'Delete', 'give' ); ?>"> | |
| 613 | + <button type="button" id="give-bulk-delete-cancel" | |
| 614 | + class="button cancel alignleft"><?php esc_attr_e( 'Cancel', 'give' ); ?></button> | |
| 615 | + <input type="submit" id="give-bulk-delete-button" disabled | |
| 616 | + class="button button-primary alignright" | |
| 617 | + value="<?php esc_attr_e( 'Delete', 'give' ); ?>"> | |
| 481 | 618 | <br class="clear"> |
| 482 | 619 | </p> |
| 483 | 620 | </td> |
| 484 | 621 | </tr> |
| @@ -506,20 +643,22 @@ | ||
| 506 | 643 | */ |
| 507 | 644 | public function prepare_items() { |
| 508 | 645 | |
| 509 | 646 | $columns = $this->get_columns(); |
| 510 | - $hidden = array(); // No hidden columns. | |
| 647 | + $hidden = []; // No hidden columns. | |
| 511 | 648 | $sortable = $this->get_sortable_columns(); |
| 512 | 649 | |
| 513 | - $this->_column_headers = array( $columns, $hidden, $sortable ); | |
| 650 | + $this->_column_headers = [ $columns, $hidden, $sortable ]; | |
| 514 | 651 | |
| 515 | 652 | $this->items = $this->donor_data(); |
| 516 | 653 | |
| 517 | 654 | $this->total = $this->get_donor_count(); |
| 518 | 655 | |
| 519 | - $this->set_pagination_args( array( | |
| 520 | - 'total_items' => $this->total, | |
| 521 | - 'per_page' => $this->per_page, | |
| 522 | - 'total_pages' => ceil( $this->total / $this->per_page ), | |
| 523 | - ) ); | |
| 656 | + $this->set_pagination_args( | |
| 657 | + [ | |
| 658 | + 'total_items' => $this->total, | |
| 659 | + 'per_page' => $this->per_page, | |
| 660 | + 'total_pages' => ceil( $this->total / $this->per_page ), | |
| 661 | + ] | |
| 662 | + ); | |
| 524 | 663 | } |
| 525 | 664 | } |