| 1 |
<?php |
| 2 |
|
| 3 |
namespace LearnPress\TemplateHooks\Order; |
| 4 |
|
| 5 |
use LearnPress\Helpers\Singleton; |
| 6 |
use LearnPress\Helpers\Template; |
| 7 |
use LP_Helper; |
| 8 |
|
| 9 |
/** |
| 10 |
* class AdminOrderListTemplate |
| 11 |
* |
| 12 |
* @since 4.3.2.8 |
| 13 |
* @version 1.0.0 |
| 14 |
*/ |
| 15 |
class AdminOrderListTemplate { |
| 16 |
|
| 17 |
use Singleton; |
| 18 |
|
| 19 |
public function init() { |
| 20 |
add_action( 'manage_posts_extra_tablenav', array( $this, 'add_export_order_button' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
public function add_export_order_button( $which ) { |
| 24 |
if ( $which !== 'top' ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
$screen = get_current_screen(); |
| 29 |
if ( ! $screen || $screen->base !== 'edit' || $screen->post_type !== LP_ORDER_CPT ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$order_data = [ |
| 34 |
'action' => 'export_order_csv', |
| 35 |
'export_id' => time() . '-' . uniqid(), |
| 36 |
]; |
| 37 |
|
| 38 |
$data_get = LP_Helper::sanitize_params_submitted( $_GET ); |
| 39 |
$order_data = array_merge( $data_get, $order_data ); |
| 40 |
|
| 41 |
$section = [ |
| 42 |
'wrap-start' => '<div class="alignleft actions">', |
| 43 |
'btn-export-start' => sprintf( |
| 44 |
'<button type="button" class="button lp-button lp-btn-export-order-to-csv" data-send="%s">', |
| 45 |
esc_attr( Template::convert_data_to_json( $order_data ) ) |
| 46 |
), |
| 47 |
'btn-text' => esc_html__( 'Export to CSV', 'learnpress' ), |
| 48 |
'btn-export-end' => '</button>', |
| 49 |
'wrap-end' => '</div>', |
| 50 |
]; |
| 51 |
|
| 52 |
echo Template::combine_components( $section ); |
| 53 |
} |
| 54 |
} |
| 55 |
|