` tag.
*
* @since 3.0
*
* @param EDD_Discount $discount Discount object.
* @return string Discount code HTML.
*/
public function column_code( $discount ) {
return '' . $discount->code . '
';
}
/**
* Message to be displayed when there are no items.
*
* @since 1.7.2
*/
public function no_items() {
esc_html_e( 'No discounts found.', 'easy-digital-downloads' );
}
/**
* Retrieve the bulk actions
*
* @since 1.4
* @return array $actions Array of the bulk actions
*/
public function get_bulk_actions() {
return array(
'activate' => __( 'Activate', 'easy-digital-downloads' ),
'deactivate' => __( 'Deactivate', 'easy-digital-downloads' ),
'delete' => __( 'Delete', 'easy-digital-downloads' )
);
}
/**
* Process bulk actions.
*
* @since 1.4
*/
public function process_bulk_action() {
// Bail if a nonce was not supplied.
if ( ! isset( $_REQUEST['_wpnonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-discounts' ) ) {
return;
}
check_admin_referer( 'bulk-discounts' );
$ids = wp_parse_id_list( (array) $this->get_request_var( 'discount', false ) );
// Bail if no IDs
if ( empty( $ids ) ) {
return;
}
foreach ( $ids as $id ) {
switch ( $this->current_action() ) {
case 'delete':
edd_delete_discount( $id );
break;
case 'cancel':
edd_update_discount_status( $id, 'cancelled' );
break;
case 'activate':
edd_update_discount_status( $id, 'active' );
break;
case 'deactivate':
edd_update_discount_status( $id, 'inactive' );
break;
}
}
}
/**
* Retrieve the discount code counts.
*
* @since 1.4
*/
public function get_counts() {
$this->counts = edd_get_discount_counts();
}
/**
* Retrieves all the data for all the discount codes.
*
* @since 1.4
* @deprecated 3.0 Use get_data()
*
* @return array Discount codes.
*/
public function discount_codes_data() {
_edd_deprecated_function( __METHOD__, '3.0', 'EDD_Discount_Codes_Table::get_data()' );
return $this->get_data();
}
/**
* Retrieves all of the table data for the discount codes.
*
* @since 3.0
*
* @return array Discount codes table data.
*/
public function get_data() {
// Parse pagination
$this->args = $this->parse_pagination_args( array(
'status' => $this->get_status(),
'search' => $this->get_search(),
) );
// Return data
return edd_get_discounts( $this->args );
}
/**
* Setup the final data for the table
*
* @since 1.4
*/
public function prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$this->items = $this->get_data();
$status = $this->get_status( 'total' );
// Setup pagination
$this->set_pagination_args( array(
'total_pages' => ceil( $this->counts[ $status ] / $this->per_page ),
'total_items' => $this->counts[ $status ],
'per_page' => $this->per_page,
) );
}
/**
* Generate the table navigation above or below the table.
* We're overriding this to turn off the referer param in `wp_nonce_field()`.
*
* @param string $which
* @since 3.1.0.4
*/
protected function display_tablenav( $which ) {
if ( 'top' === $which ) {
wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
}
?>
has_items() ) : ?>
bulk_actions( $which ); ?>
extra_tablenav( $which );
$this->pagination( $which );
?>