| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BulkWP\BulkDelete\Core\Terms\Modules; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use BulkWP\BulkDelete\Core\Terms\TermsModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 | 1 |  | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Delete Terms by Post Count. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @since 6.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class DeleteTermsByPostCountModule extends TermsModule { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 | 4 |  | 	protected function initialize() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 | 4 |  | 		$this->item_type     = 'terms'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 4 |  | 		$this->field_slug    = 'terms_by_post_count'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 4 |  | 		$this->meta_box_slug = 'bd_delete_terms_by_post_count'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 4 |  | 		$this->action        = 'delete_terms_by_post_count'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 4 |  | 		$this->cron_hook     = 'do-bulk-delete-term-by-post-count'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 4 |  | 		$this->scheduler_url = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 4 |  | 		$this->messages      = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 4 |  | 			'box_label'  => __( 'Delete Terms by Post Count', 'bulk-delete' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 4 |  | 			'scheduled'  => __( 'The selected terms are scheduled for deletion', 'bulk-delete' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 4 |  | 			'cron_label' => __( 'Delete Terms By Post Count', 'bulk-delete' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 4 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * Render Delete terms by postfix and prefix box. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 	public function render() { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 		?> | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		<!-- Category Start--> | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		<h4><?php _e( 'Select the taxonomy from which you want to delete terms', 'bulk-delete' ); ?></h4> | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		<fieldset class="options"> | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 			<table class="optiontable"> | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 				<?php $this->render_taxonomy_dropdown(); ?> | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 			</table> | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 			<h4><?php _e( 'Select the post type', 'bulk-delete' ); ?></h4> | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 			<table class="optiontable"> | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 				<?php $this->render_post_type_dropdown(); ?> | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 			</table> | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 			<table class="optiontable"> | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 				<?php $this->render_term_options(); ?> | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 			</table> | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 		</fieldset> | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 		<?php | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 		$this->render_submit_button(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	public function filter_js_array( $js_array ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$js_array['validators'][ $this->action ] = 'validatePostTypeSelect2'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$js_array['error_msg'][ $this->action ]  = 'selectPostType'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$js_array['msg']['selectPostType']       = __( 'Please select at least one post type', 'bulk-delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$js_array['dt_iterators'][] = '_' . $this->field_slug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		return $js_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * Process delete posts user inputs by category. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @param array $request Request array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * @param array $options Options for deleting posts. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	 * @return array $options  Inputs from user for posts that were need to delete | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	protected function convert_user_input_to_options( $request, $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$options['taxonomy']      = bd_array_get( $request, 'smbd_' . $this->field_slug . '_taxonomy' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$options['post_type']     = bd_array_get( $request, 'smbd_' . $this->field_slug . '_post_type' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$options['term_opt']      = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_opt' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$options['term_text']     = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_text' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		return $options; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * Build query from delete options. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * @param array $options Delete options. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * @return array Query. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 4 |  | 	protected function build_query( $options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 4 |  | 		$query      = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 4 |  | 		$taxonomy   = $options['taxonomy']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 4 |  | 		$term_text  = $options['term_text']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 4 |  | 		if( isset( $term_text ) ){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 4 |  | 			$query['taxonomy'] = $taxonomy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 4 |  | 		$term_ids            = $this->term_count_query( $options ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 4 |  | 		$query['include']    = $term_ids; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 4 |  | 		return $query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	 * Response message for deleting posts. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	 * @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 term with the selected options', 'Deleted %d terms with the selected options', $items_deleted, 'bulk-delete' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  |