| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BulkWP\BulkDelete\Core\Posts\Metabox; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BulkWP\BulkDelete\Core\Posts\PostsMetabox; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Delete Posts by Revision Metabox. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @since 6.0.0 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class DeletePostsByRevisionMetabox extends PostsMetabox { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | 	protected function initialize() { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | 		$this->item_type     = 'posts'; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | 		$this->field_slug    = 'revisions'; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 		$this->meta_box_slug = 'bd_posts_by_revision'; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | 		$this->action        = 'delete_posts_by_revision'; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 		$this->messages      = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 			'box_label' => __( 'By Post Revisions', 'bulk-delete' ), | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 		); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	public function render() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		global $wpdb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		$revisions = $wpdb->get_var( "select count(*) from $wpdb->posts where post_type = 'revision'" ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         <!-- Post Revisions start--> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         <h4><?php _e( 'Select the posts which you want to delete', 'bulk-delete' ); ?></h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         <fieldset class="options"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         <table class="optiontable"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             <tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 <td> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                     <input name="smbd_revisions" id ="smbd_revisions" value="revisions" type="checkbox"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                     <label for="smbd_revisions"><?php _e( 'All Revisions', 'bulk-delete' ); ?> (<?php echo $revisions . ' '; _e( 'Revisions', 'bulk-delete' ); ?>)</label> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 </td> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             </tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         </table> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         </fieldset> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | <?php | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  | 		$this->render_submit_button(); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	protected function convert_user_input_to_options( $request, $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$options = array( 'revisions' => bd_array_get( $request, 'smbd_revisions' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  | 		return $options; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 	public function delete( $delete_options ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 		global $wpdb; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 		// Revisions | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 		if ( 'revisions' == $delete_options['revisions'] ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  | 			$revisions = $wpdb->get_results( "select ID from $wpdb->posts where post_type = 'revision'" ); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 			foreach ( $revisions as $revision ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 				wp_delete_post( $revision->ID ); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | 			return count( $revisions ); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  | 		return 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	protected function get_success_message( $items_deleted ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		/* translators: 1 Number of pages deleted */ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  | 		return _n( 'Deleted %d post with the selected post status', 'Deleted %d posts with the selected post status', $items_deleted, 'bulk-delete' ); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                                        
                                                                
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  | 	protected function build_query( $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		// Left empty on purpose. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 78 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  |