| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace BulkWP\BulkDelete\Core\Base\Mixin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 | 1 |  | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Container of all Render methods. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Ideally this should be a Trait. Since Bulk Delete still supports PHP 5.3, this is implemented as a class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Once the minimum requirement is increased to PHP 5.3, this will be changed into a Trait. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @since 6.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | abstract class Renderer extends Fetcher { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	 * Render Post Types as radio buttons. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	protected function render_post_type_as_radios() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$field_slug = $this->field_slug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		$post_types = $this->get_post_types(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		<?php foreach ( $post_types as $post_type ) : ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 			<tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 				<td scope="row"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 					<input type="radio" name="<?php echo esc_attr( $field_slug ); ?>_post_type" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 						value="<?php echo esc_attr( $post_type->name ); ?>" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 						id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 					<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 						<?php echo esc_html( $post_type->label ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 					</label> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 				</td> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			</tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		<?php endforeach; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * Render Post type with status and post count checkboxes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	protected function render_post_type_with_status() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		$post_types_by_status = $this->get_post_types_by_status(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		<tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			<td scope="row" colspan="2"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 				<select class="enhanced-post-types-with-status" multiple="multiple" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 				<?php foreach ( $post_types_by_status as $post_type => $all_status ) : ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 					<optgroup label="<?php echo esc_html( $post_type ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 					<?php foreach ( $all_status as $status_key => $status_value ) : ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 						<option value="<?php echo esc_attr( $status_key ); ?>"><?php echo esc_html( $status_value ); ?></option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 					<?php endforeach; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 					</optgroup> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 				<?php endforeach; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 				</select> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			</td> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		</tr> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * Split post type and status. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @param string $str Post type and status combination. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * @return array Post type and status as elements of array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 9 |  | 	protected function split_post_type_and_status( $str ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 9 |  | 		$type_status = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 9 |  | 		$str_arr = explode( '-', $str ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 9 |  | 		if ( count( $str_arr ) > 1 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			$type_status['status'] = end( $str_arr ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			$type_status['type']   = implode( '-', array_slice( $str_arr, 0, - 1 ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 9 |  | 			$type_status['status'] = 'publish'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 9 |  | 			$type_status['type']   = $str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 9 |  | 		return $type_status; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	 * Render user role dropdown. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	protected function render_user_role_dropdown() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		global $wp_roles; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="select2" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 				multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			<?php foreach ( $wp_roles->roles as $role => $role_details ) : ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 				<option value="<?php echo esc_attr( $role ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 					<?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 				</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			<?php endforeach; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		</select> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * Render Post type dropdown. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	protected function render_post_type_dropdown() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		bd_render_post_type_dropdown( $this->field_slug ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 * Render Taxonomy dropdown. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	protected function render_taxonomy_dropdown() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$taxonomies = get_taxonomies( array(), 'objects' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy" class="select2" multiple="multiple" data-placeholder="<?php _e( 'Select Taxonomy', 'bulk-delete' ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 			<?php foreach ( $taxonomies as $taxonomy ) : ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 				<option value="<?php echo esc_attr( $taxonomy->name ); ?>"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 					<?php echo esc_html( $taxonomy->label ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 				</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 			<?php endforeach; ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		</select> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	 * Render term options. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	protected function render_term_options() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		<h4><?php _e( 'Delete terms that', 'bulk-delete' ); ?></h4> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_opt"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		<?php if( $this->field_slug == 'terms_by_name' ){ ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 			<option value="equal_to">equal to</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 			<option value="not_equal_to">not equal to</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			<option value="starts">starts</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 			<option value="ends">ends</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			<option value="contains">contains</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			<option value="non_contains">non contains</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		<?php }elseif( $this->field_slug == 'terms_by_post_count' ){ ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 			<option value="equal_to">equal to</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 			<option value="not_equal_to">not equal to</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 			<option value="less_than">less than</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 			<option value="greater_than">greater than</option> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 		<?php }?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		</select> With  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		<input type="text" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_text"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 		<?php  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 * Render have post settings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	protected function render_have_post_settings() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 		<p><label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_no_posts"><input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_no_posts" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_no_posts"> <?php _e( 'Only if it doesn\'t contain any post', 'bulk-delete' ); ?></label></p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		<?php  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	 * Render the "private post" setting fields. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 167 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  | 	protected function render_private_post_settings() { | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  | 		bd_render_private_post_settings( $this->field_slug ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 171 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 172 |  |  |  |