| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BulkWP\BulkDelete\Core\Posts\Metabox; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BulkWP\BulkDelete\Core\Posts\PostsMetabox; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 | 1 |  | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Delete Posts by Category Metabox. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @since 6.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class DeletePostsByCategoryMetabox extends PostsMetabox { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 | 11 |  | 	protected function initialize() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 | 11 |  | 		$this->item_type     = 'posts'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 11 |  | 		$this->field_slug    = 'cats'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 11 |  | 		$this->meta_box_slug = 'bd_by_category'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 11 |  | 		$this->action        = 'delete_posts_by_category'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 11 |  | 		$this->cron_hook     = 'do-bulk-delete-cat'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 11 |  | 		$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-posts-by-category/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sc'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 11 |  | 		$this->messages      = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 11 |  | 			'box_label' => __( 'By Post Category', 'bulk-delete' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 11 |  | 			'scheduled' => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 11 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * Render Delete posts by category box. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	public function render() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		<!-- Category Start--> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		<h4><?php _e( 'Select the post type from which you want to delete posts by category', 'bulk-delete' ); ?></h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		<fieldset class="options"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			<table class="optiontable"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 				<?php $this->render_post_type_dropdown(); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			</table> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			<h4><?php _e( 'Select the categories from which you want to delete posts', 'bulk-delete' ); ?></h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			<p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 				<?php _e( 'Note: The post count below for each category is the total number of posts in that category, irrespective of post type', 'bulk-delete' ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			.</p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			<table class="form-table"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 				<tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 					<td scope="row"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 						<?php $this->render_category_dropdown(); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 					</td> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 				</tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			</table> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			<table class="optiontable"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 				<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				$this->render_filtering_table_header(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 				$this->render_restrict_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 				$this->render_delete_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 				$this->render_private_post_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 				$this->render_limit_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 				$this->render_cron_settings(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 				?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			</table> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		</fieldset> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->render_submit_button(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * Process delete posts user inputs by category. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 * @param array $request Request array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	 * @param array $options Options for deleting posts. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	 * @return array $options  Inputs from user for posts that were need to delete | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	protected function convert_user_input_to_options( $request, $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$options['post_type']     = bd_array_get( $request, 'smbd_' . $this->field_slug . '_post_type', 'post' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$options['selected_cats'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_category' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		$options['private']       = bd_array_get_bool( $request, 'smbd_' . $this->field_slug . '_private', false ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		return $options; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * Build query from delete options. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 * @param array $options Delete options. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 * @return array Query. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 92 | 11 |  | 	protected function build_query( $options ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 11 |  | 		$query = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 | 11 |  | 		if ( in_array( 'all', $options['selected_cats'], true ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 | 11 |  | 			$query['category__not__in'] = array( 0 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 		} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 98 | 11 |  | 			$query['category__in'] = $options['selected_cats']; | 
            
                                                                        
                            
            
                                    
            
            
                | 99 | 2 |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 101 | 9 |  | 		return $query; | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 | 11 |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 105 | 11 |  | 	 * Response message for deleting posts. | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 11 |  | 	 * @param int $items_deleted Total number of posts deleted. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * @return string Response message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	protected function get_success_message( $items_deleted ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		/* translators: 1 Number of posts deleted */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		return _n( 'Deleted %d post with the selected post category', 'Deleted %d posts with the selected post category', $items_deleted, 'bulk-delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  |