| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BulkWP\BulkDelete\Core\Pages\Modules; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BulkWP\BulkDelete\Core\Pages\PagesModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 | 1 |  | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Delete Pages by Status Module. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @since 6.0.0 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class DeletePagesByStatusModule extends PagesModule { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 | 21 |  | 	protected function initialize() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 | 21 |  | 		$this->item_type     = 'pages'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 21 |  | 		$this->field_slug    = 'page_status'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 21 |  | 		$this->meta_box_slug = 'bd_pages_by_status'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 21 |  | 		$this->action        = 'delete_pages_by_status'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 21 |  | 		$this->cron_hook     = 'do-bulk-delete-pages-by-status'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 21 |  | 		$this->scheduler_url = 'https://bulkwp.com/addons/scheduler-for-deleting-pages-by-status/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sp'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 21 |  | 		$this->messages      = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 21 |  | 			'box_label'  => __( 'By Page Status', 'bulk-delete' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 21 |  | 			'scheduled'  => __( 'The selected pages are scheduled for deletion', 'bulk-delete' ), | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 | 21 |  | 			'cron_label' => __( 'Delete Pages By status', 'bulk-delete' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 | 21 |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	public function render() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		<!-- Pages start--> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		<h4><?php _e( 'Select the post statuses from which you want to delete pages', 'bulk-delete' ); ?></h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		<fieldset class="options"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 			<table class="optiontable"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 				<?php $this->render_post_status( 'page' ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			</table> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			<table class="optiontable"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 				<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 				$this->render_filtering_table_header(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 				$this->render_restrict_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 				$this->render_delete_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 				$this->render_limit_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 				$this->render_cron_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 				?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			</table> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		</fieldset> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		<?php | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  | 		$this->render_submit_button(); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	protected function append_to_js_array( $js_array ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$js_array['error_msg'][ $this->action ]      = 'selectPagePostStatus'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$js_array['pre_action_msg'][ $this->action ] = 'pagePostStatusWarning'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$js_array['msg']['selectPagePostStatus']  = __( 'Please select at least one post status from which pages should be deleted', 'bulk-delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$js_array['msg']['pagePostStatusWarning'] = __( 'Are you sure you want to delete all the pages from the selected post status?', 'bulk-delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  | 		return $js_array; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	protected function convert_user_input_to_options( $request, $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_page_status', array() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | 		return $options; | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 21 |  | 	protected function build_query( $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 21 |  | 		if ( empty( $options['post_status'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$query = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 21 |  | 			'post_type'   => 'page', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 21 |  | 			'post_status' => $options['post_status'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 | 21 |  | 		return $query; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	protected function get_success_message( $items_deleted ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		/* translators: 1 Number of pages deleted */ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  | 		return _n( 'Deleted %d page from the selected post status', 'Deleted %d pages from the selected post status', $items_deleted, 'bulk-delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  |