@@ -38,11 +38,9 @@ public function load_admin_hooks() {
3838 add_action ( 'woocommerce_admin_order_actions_end ' , array ( $ this , 'add_listing_actions ' ) );
3939 add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'add_scripts ' ) );
4040 add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'add_styles ' ) );
41-
4241 add_action ( 'add_meta_boxes_shop_order ' , array ( $ this , 'add_box ' ) );
43-
44- add_action ( 'admin_footer-edit.php ' , array ( $ this , 'add_bulk_actions ' ) );
45- add_action ( 'load-edit.php ' , array ( $ this , 'load_bulk_actions ' ) );
42+ add_filter ( 'bulk_actions-edit-shop_order ' , array ( $ this , 'register_my_bulk_actions ' ) );
43+ add_filter ( 'handle_bulk_actions-edit-shop_order ' , array ( $ this , 'my_bulk_action_handler ' ), 10 , 3 );
4644 add_action ( 'admin_notices ' , array ( $ this , 'confirm_bulk_actions ' ) );
4745 }
4846
@@ -115,105 +113,88 @@ public function add_listing_actions( $order ) {
115113 }
116114
117115 /**
118- * Add bulk actions with javascript to the dropdown.
119- * This is not so pretty but WordPress does not yet
120- * offer any better solution. The JS code is inline
121- * because we can't determine the page without
122- * checking the post_type.
123- * https://core.trac.wordpress.org/ticket/16031
116+ * Add bulk actions to the dropdown.
117+ *
118+ * @param array $bulk_actions Array of the list in dropdown.
124119 */
125- public function add_bulk_actions () {
126- if ( $ this ->is_order_edit_page () ) :
127- ?>
128- <script type="text/javascript">
129- jQuery(document).ready(function($) {
130- <?php foreach ( WCDN_Print::$ template_registrations as $ template_registration ) : ?>
131- <?php if ( 'yes ' === get_option ( 'wcdn_template_type_ ' . $ template_registration ['type ' ] ) && 'order ' !== $ template_registration ['type ' ] ) : ?>
132- <?php //phpcs:disable ?>
133- $('<option>').val('wcdn_print_<?php echo esc_attr ( $ template_registration ['type ' ] ); ?> ').attr('title', '<?php echo esc_attr ( $ template_registration ['type ' ] ); ?> ').text('<?php echo esc_js ( __ ( $ template_registration ['labels ' ]['print ' ], 'woocommerce-delivery-notes ' ) ); ?> ').appendTo('select[name="action"]');
134- $('<option>').val('wcdn_print_<?php echo esc_attr ( $ template_registration ['type ' ] ); ?> ').attr('title', '<?php echo esc_attr ( $ template_registration ['type ' ] ); ?> ').text('<?php echo esc_js ( __ ( $ template_registration ['labels ' ]['print ' ], 'woocommerce-delivery-notes ' ) ); ?> ').appendTo('select[name="action2"]');
135- <?php //phpcs:enable ?>
136- <?php endif ; ?>
137- <?php endforeach ; ?>
138- });
139- </script>
140- <?php
141- endif ;
120+ public function register_my_bulk_actions ( $ bulk_actions ) {
121+ $ bulk_actions ['wcdn_print_invoice ' ] = __ ( 'Print Invoice ' , 'woocommerce-delivery-notes ' );
122+ $ bulk_actions ['wcdn_print_delivery-note ' ] = __ ( 'Print Delivery Note ' , 'woocommerce-delivery-notes ' );
123+ $ bulk_actions ['wcdn_print_receipt ' ] = __ ( 'Print Receipt ' , 'woocommerce-delivery-notes ' );
124+ return $ bulk_actions ;
142125 }
143126
144127 /**
145128 * Add bulk print actions to the orders listing
129+ *
130+ * @param string $redirect_to The redirect URL.
131+ * @param string $doaction The action being taken.
132+ * @param array $post_ids Array of an IDs.
146133 */
147- public function load_bulk_actions () {
148- if ( $ this ->is_order_edit_page () ) {
149- // get the action that should be started.
150- $ wp_list_table = _get_list_table ( 'WP_Posts_List_Table ' );
151- $ action = $ wp_list_table ->current_action ();
152-
153- // stop if there are no post ids.
154- if ( ! isset ( $ _REQUEST ['post ' ] ) ) {
155- return ;
156- }
157-
158- // only for specified actions.
159- foreach ( WCDN_Print::$ template_registrations as $ template_registration ) {
160- if ( 'wcdn_print_ ' . $ template_registration ['type ' ] === $ action ) {
161- $ template_type = $ template_registration ['type ' ];
162- $ report_action = 'printed_ ' . $ template_registration ['type ' ];
163- break ;
164- }
165- }
166- if ( ! isset ( $ report_action ) ) {
167- return ;
168- }
169-
170- // security check.
171- check_admin_referer ( 'bulk-posts ' );
134+ public function my_bulk_action_handler ( $ redirect_to , $ doaction , $ post_ids ) {
135+ // stop if there are no post ids.
136+ if ( ! isset ( $ _REQUEST ['post ' ] ) ) {
137+ return ;
138+ }
172139
173- // get referrer.
174- if ( ! wp_get_referer () ) {
175- return ;
140+ // only for specified actions.
141+ foreach ( WCDN_Print::$ template_registrations as $ template_registration ) {
142+ if ( 'wcdn_print_ ' . $ template_registration ['type ' ] === $ doaction ) {
143+ $ template_type = $ template_registration ['type ' ];
144+ $ report_action = 'printed_ ' . $ template_registration ['type ' ];
145+ break ;
176146 }
147+ }
148+ if ( ! isset ( $ report_action ) ) {
149+ return ;
150+ }
177151
178- // filter the referer args.
179- $ referer_args = array ();
180- parse_str ( wp_parse_url ( wp_get_referer (), PHP_URL_QUERY ), $ referer_args );
152+ // security check.
153+ check_admin_referer ( 'bulk-posts ' );
181154
182- // set the basic args for the sendback.
183- $ args = array (
184- 'post_type ' => $ referer_args ['post_type ' ],
185- );
186- if ( isset ( $ referer_args ['post_status ' ] ) ) {
187- $ args = wp_parse_args ( array ( 'post_status ' => $ referer_args ['post_status ' ] ), $ args );
188- }
189- if ( isset ( $ referer_args ['paged ' ] ) ) {
190- $ args = wp_parse_args ( array ( 'paged ' => $ referer_args ['paged ' ] ), $ args );
191- }
192- if ( isset ( $ referer_args ['orderby ' ] ) ) {
193- $ args = wp_parse_args ( array ( 'orderby ' => $ referer_args ['orderby ' ] ), $ args );
194- }
195- if ( isset ( $ referer_args ['order ' ] ) ) {
196- $ args = wp_parse_args ( array ( 'orderby ' => $ referer_args ['order ' ] ), $ args );
197- }
155+ // get referrer.
156+ if ( ! wp_get_referer () ) {
157+ return ;
158+ }
198159
199- // do the action.
200- $ post_ids = array_map ( 'absint ' , (array ) $ _REQUEST ['post ' ] );
201- $ total = count ( $ post_ids );
202- $ url = wcdn_get_print_link ( $ post_ids , $ template_type );
160+ // filter the referer args.
161+ $ referer_args = array ();
162+ parse_str ( wp_parse_url ( wp_get_referer (), PHP_URL_QUERY ), $ referer_args );
203163
204- // generate more args and the sendback string.
205- $ args = wp_parse_args (
206- array (
207- $ report_action => true ,
208- 'total ' => $ total ,
209- 'print_url ' => rawurlencode ( $ url ),
210- ),
211- $ args
212- );
213- $ sendback = add_query_arg ( $ args , '' );
214- wp_safe_redirect ( $ sendback );
215- exit ;
164+ // set the basic args for the sendback.
165+ $ args = array (
166+ 'post_type ' => $ referer_args ['post_type ' ],
167+ );
168+ if ( isset ( $ referer_args ['post_status ' ] ) ) {
169+ $ args = wp_parse_args ( array ( 'post_status ' => $ referer_args ['post_status ' ] ), $ args );
170+ }
171+ if ( isset ( $ referer_args ['paged ' ] ) ) {
172+ $ args = wp_parse_args ( array ( 'paged ' => $ referer_args ['paged ' ] ), $ args );
216173 }
174+ if ( isset ( $ referer_args ['orderby ' ] ) ) {
175+ $ args = wp_parse_args ( array ( 'orderby ' => $ referer_args ['orderby ' ] ), $ args );
176+ }
177+ if ( isset ( $ referer_args ['order ' ] ) ) {
178+ $ args = wp_parse_args ( array ( 'orderby ' => $ referer_args ['order ' ] ), $ args );
179+ }
180+
181+ // do the action.
182+ $ post_ids = array_map ( 'absint ' , (array ) $ _REQUEST ['post ' ] );
183+ $ total = count ( $ post_ids );
184+ $ url = wcdn_get_print_link ( $ post_ids , $ template_type );
185+
186+ // generate more args and the sendback string.
187+ $ args = wp_parse_args (
188+ array (
189+ $ report_action => true ,
190+ 'total ' => $ total ,
191+ 'print_url ' => rawurlencode ( $ url ),
192+ ),
193+ $ args
194+ );
195+ $ sendback = add_query_arg ( $ args , '' );
196+ wp_safe_redirect ( $ sendback );
197+ exit ;
217198 }
218199
219200 /**
0 commit comments