| Total Complexity | 61 |
| Total Lines | 744 |
| Duplicated Lines | 0 % |
| Changes | 13 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Renderer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Renderer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | abstract class Renderer extends Fetcher { |
||
| 16 | use OperatorHelpers; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Slug for the form fields. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $field_slug; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Render post status including custom post status. |
||
| 27 | * |
||
| 28 | * @since 6.1.0 Added $class param. |
||
| 29 | * |
||
| 30 | * @param string $post_type The post type for which the post status should be displayed. |
||
| 31 | * @param string $class Class to be applied. |
||
| 32 | */ |
||
| 33 | protected function render_post_status( $post_type = 'post', $class = 'validate' ) { |
||
| 34 | $post_statuses = $this->get_post_statuses(); |
||
| 35 | $post_count = wp_count_posts( $post_type ); |
||
| 36 | |||
| 37 | foreach ( $post_statuses as $post_status ) : ?> |
||
| 38 | <tr> |
||
| 39 | <td> |
||
| 40 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>" |
||
| 41 | value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox" class="<?php echo esc_attr( $class ); ?>"> |
||
| 42 | |||
| 43 | <label for="smbd_<?php echo esc_attr( $post_status->name ); ?>"> |
||
| 44 | <?php echo esc_html( $post_status->label ), ' '; ?> |
||
| 45 | <?php if ( property_exists( $post_count, $post_status->name ) ) : ?> |
||
| 46 | (<?php echo absint( $post_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>) |
||
| 47 | <?php endif; ?> |
||
| 48 | </label> |
||
| 49 | </td> |
||
| 50 | </tr> |
||
| 51 | <?php endforeach; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Render Post Types as radio buttons. |
||
| 56 | */ |
||
| 57 | protected function render_post_type_as_radios() { |
||
| 58 | $post_types = $this->get_post_types(); |
||
| 59 | ?> |
||
| 60 | |||
| 61 | <?php foreach ( $post_types as $post_type ) : ?> |
||
| 62 | |||
| 63 | <tr> |
||
| 64 | <td scope="row"> |
||
| 65 | <input type="radio" name="<?php echo esc_attr( $this->field_slug ); ?>_post_type" |
||
| 66 | value="<?php echo esc_attr( $post_type->name ); ?>" |
||
| 67 | id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
| 68 | |||
| 69 | <label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
| 70 | <?php echo esc_html( $post_type->label ); ?> |
||
| 71 | </label> |
||
| 72 | </td> |
||
| 73 | </tr> |
||
| 74 | |||
| 75 | <?php endforeach; ?> |
||
| 76 | <?php |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Render Post type with status and post count checkboxes. |
||
| 81 | * |
||
| 82 | * @since 6.0.1 Added $multiple param. |
||
| 83 | * @since 6.1.0 Added $feature param. |
||
| 84 | * |
||
| 85 | * @param bool $multiple_select Whether multiple select should be supported. Default true. |
||
| 86 | * @param string $feature Fetches only post types that supports feature. Default empty. |
||
| 87 | */ |
||
| 88 | protected function render_post_type_with_status( $multiple_select = true, $feature = '' ) { |
||
| 89 | $post_types_by_status = $this->get_post_types_by_status( $feature ); |
||
| 90 | |||
| 91 | $name = 'smbd_' . $this->field_slug; |
||
| 92 | if ( $multiple_select ) { |
||
| 93 | $name .= '[]'; |
||
| 94 | } |
||
| 95 | ?> |
||
| 96 | |||
| 97 | <tr> |
||
| 98 | <td scope="row" colspan="2"> |
||
| 99 | <select data-placeholder="<?php esc_attr_e( 'Select Post Type', 'bulk-delete' ); ?>" |
||
| 100 | name="<?php echo esc_attr( $name ); ?>" class="enhanced-post-types-with-status" |
||
| 101 | <?php if ( $multiple_select ) : ?> |
||
| 102 | multiple |
||
| 103 | <?php endif; ?> |
||
| 104 | > |
||
| 105 | |||
| 106 | <?php foreach ( $post_types_by_status as $post_type => $all_status ) : ?> |
||
| 107 | <optgroup label="<?php echo esc_html( $post_type ); ?>"> |
||
| 108 | |||
| 109 | <?php foreach ( $all_status as $status_key => $status_value ) : ?> |
||
| 110 | <option value="<?php echo esc_attr( $status_key ); ?>"> |
||
| 111 | <?php echo esc_html( $status_value ); ?> |
||
| 112 | </option> |
||
| 113 | <?php endforeach; ?> |
||
| 114 | |||
| 115 | </optgroup> |
||
| 116 | <?php endforeach; ?> |
||
| 117 | |||
| 118 | </select> |
||
| 119 | </td> |
||
| 120 | </tr> |
||
| 121 | <?php |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Split post type and status. |
||
| 126 | * |
||
| 127 | * @param string $str Post type and status combination. |
||
| 128 | * |
||
| 129 | * @return array Post type and status as elements of array. |
||
| 130 | */ |
||
| 131 | protected function split_post_type_and_status( $str ) { |
||
| 132 | $type_status = array(); |
||
| 133 | |||
| 134 | if ( strpos( $str, '|' ) === false ) { |
||
| 135 | $str_arr = explode( '-', $str ); |
||
| 136 | } else { |
||
| 137 | $str_arr = explode( '|', $str ); |
||
| 138 | } |
||
| 139 | |||
| 140 | if ( count( $str_arr ) > 1 ) { |
||
| 141 | $type_status['status'] = end( $str_arr ); |
||
| 142 | $type_status['type'] = implode( '-', array_slice( $str_arr, 0, - 1 ) ); |
||
| 143 | } else { |
||
| 144 | $type_status['status'] = 'publish'; |
||
| 145 | $type_status['type'] = $str; |
||
| 146 | } |
||
| 147 | |||
| 148 | return $type_status; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Render post reassign settings. |
||
| 153 | */ |
||
| 154 | protected function render_post_reassign_settings() { |
||
| 155 | ?> |
||
| 156 | <tr> |
||
| 157 | <td scope="row" colspan="2"> |
||
| 158 | <label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="false" type="radio" |
||
| 159 | checked="checked" class="post-reassign"> <?php _e( 'Also delete all posts of the users', 'bulk-delete' ); ?></label> |
||
| 160 | <label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="true" type="radio" |
||
| 161 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" class="post-reassign"> <?php _e( 'Re-assign the posts to', 'bulk-delete' ); ?></label> |
||
| 162 | <?php |
||
| 163 | wp_dropdown_users( |
||
| 164 | array( |
||
| 165 | 'name' => 'smbd_' . esc_attr( $this->field_slug ) . '_reassign_user_id', |
||
| 166 | 'class' => 'reassign-user', |
||
| 167 | 'show_option_none' => __( 'Select User', 'bulk-delete' ), |
||
| 168 | ) |
||
| 169 | ); |
||
| 170 | ?> |
||
| 171 | </td> |
||
| 172 | </tr> |
||
| 173 | <?php |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Render user role dropdown. |
||
| 178 | * |
||
| 179 | * @param bool $show_users_with_no_roles Should users with no user roles be shown? Default false. |
||
| 180 | */ |
||
| 181 | protected function render_user_role_dropdown( $show_users_with_no_roles = false ) { |
||
| 182 | $roles = get_editable_roles(); |
||
| 183 | $users_count = count_users(); |
||
| 184 | ?> |
||
| 185 | |||
| 186 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="enhanced-role-dropdown" |
||
| 187 | multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>"> |
||
| 188 | |||
| 189 | <?php foreach ( $roles as $role => $role_details ) : ?> |
||
| 190 | <option value="<?php echo esc_attr( $role ); ?>"> |
||
| 191 | <?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role, $users_count ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
||
| 192 | </option> |
||
| 193 | <?php endforeach; ?> |
||
| 194 | |||
| 195 | <?php if ( $show_users_with_no_roles ) : ?> |
||
| 196 | <?php if ( isset( $users_count['avail_roles']['none'] ) && $users_count['avail_roles']['none'] > 0 ) : ?> |
||
| 197 | <option value="none"> |
||
| 198 | <?php echo __( 'No role', 'bulk-delete' ), ' (', absint( $users_count['avail_roles']['none'] ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
||
| 199 | </option> |
||
| 200 | <?php endif; ?> |
||
| 201 | <?php endif; ?> |
||
| 202 | </select> |
||
| 203 | |||
| 204 | <?php |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Render Post type dropdown. |
||
| 209 | */ |
||
| 210 | protected function render_post_type_dropdown() { |
||
| 211 | bd_render_post_type_dropdown( $this->field_slug ); |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Render Taxonomy dropdown. |
||
| 216 | */ |
||
| 217 | protected function render_taxonomy_dropdown() { |
||
| 218 | $builtin_taxonomies = get_taxonomies( array( '_builtin' => true ), 'objects' ); |
||
| 219 | $custom_taxonomies = get_taxonomies( array( '_builtin' => false ), 'objects' ); |
||
| 220 | ?> |
||
| 221 | <select class="enhanced-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy"> |
||
| 222 | <optgroup label="<?php esc_attr_e( 'Built-in Taxonomies', 'bulk-delete' ); ?>"> |
||
| 223 | <?php foreach ( $builtin_taxonomies as $taxonomy ) : ?> |
||
| 224 | <option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
||
| 225 | <?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?> |
||
| 226 | </option> |
||
| 227 | <?php endforeach; ?> |
||
| 228 | </optgroup> |
||
| 229 | |||
| 230 | <?php if ( ! empty( $custom_taxonomies ) ): ?> |
||
| 231 | <optgroup label="<?php esc_attr_e( 'Custom Taxonomies', 'bulk-delete' ); ?>"> |
||
| 232 | <?php foreach ( $custom_taxonomies as $taxonomy ) : ?> |
||
| 233 | <option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
||
| 234 | <?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?> |
||
| 235 | </option> |
||
| 236 | <?php endforeach; ?> |
||
| 237 | </optgroup> |
||
| 238 | <?php endif; ?> |
||
| 239 | </select> |
||
| 240 | <?php |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Render Category dropdown. |
||
| 245 | */ |
||
| 246 | protected function render_category_dropdown() { |
||
| 247 | $categories = $this->get_categories(); |
||
| 248 | ?> |
||
| 249 | |||
| 250 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>" |
||
| 251 | class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>" |
||
| 252 | data-taxonomy="category" multiple> |
||
| 253 | |||
| 254 | <option value="all"> |
||
| 255 | <?php _e( 'All Categories', 'bulk-delete' ); ?> |
||
| 256 | </option> |
||
| 257 | |||
| 258 | <?php foreach ( $categories as $category ) : ?> |
||
| 259 | <option value="<?php echo absint( $category->cat_ID ); ?>"> |
||
| 260 | <?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
| 261 | </option> |
||
| 262 | <?php endforeach; ?> |
||
| 263 | |||
| 264 | </select> |
||
| 265 | <?php |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Render number based comparison operators dropdown. |
||
| 270 | */ |
||
| 271 | protected function render_number_comparison_operators() { |
||
| 272 | ?> |
||
| 273 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator"> |
||
| 274 | <option value="="><?php _e( 'equal to', 'bulk-delete' ); ?></option> |
||
| 275 | <option value="!="><?php _e( 'not equal to', 'bulk-delete' ); ?></option> |
||
| 276 | <option value="<"><?php _e( 'less than', 'bulk-delete' ); ?></option> |
||
| 277 | <option value=">"><?php _e( 'greater than', 'bulk-delete' ); ?></option> |
||
| 278 | </select> |
||
| 279 | <?php |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Render data types dropdown. |
||
| 284 | */ |
||
| 285 | protected function render_data_types_dropdown() { |
||
| 286 | ?> |
||
| 287 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_type" class="meta-type"> |
||
| 288 | <option value="numeric"><?php _e( 'Number', 'bulk-delete' ); ?></option> |
||
| 289 | <option value="char"><?php _e( 'Character', 'bulk-delete' ); ?></option> |
||
| 290 | <option value="date"><?php _e( 'Date', 'bulk-delete' ); ?></option> |
||
| 291 | </select> |
||
| 292 | <?php |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Render numeric comparison operators dropdown. |
||
| 297 | * |
||
| 298 | * @param string $class Class to be applied. |
||
| 299 | * @param array $operators List of Operators needed. |
||
| 300 | */ |
||
| 301 | protected function render_numeric_operators_dropdown( $class = 'numeric', $operators = array( 'all' ) ) { |
||
| 302 | $all_numeric_operators = array( |
||
| 303 | '=' => 'equal to', |
||
| 304 | '!=' => 'not equal to', |
||
| 305 | '<' => 'less than', |
||
| 306 | '<=' => 'less than or equal to', |
||
| 307 | '>' => 'greater than', |
||
| 308 | '>=' => 'greater than or equal to', |
||
| 309 | 'IN' => 'in', |
||
| 310 | 'NOT IN' => 'not in', |
||
| 311 | 'BETWEEN' => 'between', |
||
| 312 | 'NOT BETWEEN' => 'not between', |
||
| 313 | 'EXISTS' => 'exists', |
||
| 314 | 'NOT EXISTS' => 'not exists', |
||
| 315 | ); |
||
| 316 | if ( in_array( 'all', $operators, true ) ) { |
||
| 317 | $operators = array_keys( $all_numeric_operators ); |
||
| 318 | } |
||
| 319 | ?> |
||
| 320 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class= "<?php echo esc_attr( $class ); ?>"> |
||
| 321 | <?php |
||
| 322 | foreach ( $operators as $operator ) { |
||
| 323 | echo '<option value="' . $operator . '">' . __( $all_numeric_operators[ $operator ], 'bulk-delete' ) . '</option>'; |
||
| 324 | } |
||
| 325 | ?> |
||
| 326 | </select> |
||
| 327 | <?php |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Render string comparison operators dropdown. |
||
| 332 | * |
||
| 333 | * @param string $class Class to be applied. |
||
| 334 | * @param array $operators List of Operators needed. |
||
| 335 | */ |
||
| 336 | protected function render_string_operators_dropdown( $class = 'string', $operators = array( 'all' ) ) { |
||
| 337 | // STARTS_WITH and ENDS_WITH operators needs a handler as SQL does not support these operators in queries. |
||
| 338 | $all_string_operators = array( |
||
| 339 | '=' => 'equal to', |
||
| 340 | '!=' => 'not equal to', |
||
| 341 | 'IN' => 'in', |
||
| 342 | 'NOT IN' => 'not in', |
||
| 343 | 'LIKE' => 'contains', |
||
| 344 | 'NOT LIKE' => 'not contains', |
||
| 345 | 'EXISTS' => 'exists', |
||
| 346 | 'NOT EXISTS' => 'not exists', |
||
| 347 | 'STARTS_WITH' => 'starts with', |
||
| 348 | 'ENDS_WITH' => 'ends with', |
||
| 349 | ); |
||
| 350 | if ( in_array( 'all', $operators, true ) ) { |
||
| 351 | $operators = array_keys( $all_string_operators ); |
||
| 352 | } |
||
| 353 | ?> |
||
| 354 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo esc_attr( $class ); ?>"> |
||
| 355 | <?php |
||
| 356 | foreach ( $operators as $operator ) { |
||
| 357 | echo '<option value="' . $operator . '">' . __( $all_string_operators[ $operator ], 'bulk-delete' ) . '</option>'; |
||
| 358 | } |
||
| 359 | ?> |
||
| 360 | </select> |
||
| 361 | <?php |
||
| 362 | } |
||
| 363 | |||
| 364 | protected function render_meta_value_filter( $options = [] ) { |
||
| 431 | </td> |
||
| 432 | </tr> |
||
| 433 | |||
| 434 | <?php |
||
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Render Operators dropdown. |
||
| 439 | * |
||
| 440 | * @since 6.1.0 |
||
| 441 | * |
||
| 442 | * @param array $operators List of operators. Can use placeholders as well. |
||
| 443 | * @param string $class HTML class. |
||
| 444 | * |
||
| 445 | * @see \BulkWP\BulkDelete\Core\Base\Mixin\OperatorHelpers::resolve_operator() for the list of placeholders |
||
| 446 | */ |
||
| 447 | protected function render_operators_dropdown( $operators, $class = 'operators' ) { |
||
| 448 | $operators = $this->resolve_operators( $operators ); |
||
| 449 | ?> |
||
| 450 | |||
| 451 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo sanitize_html_class( $class ); ?>"> |
||
| 452 | <?php foreach ( $operators as $operator ) : ?> |
||
| 453 | <option value="<?php echo esc_attr( $operator ); ?>"> |
||
| 454 | <?php echo esc_html( $this->get_operator_label( $operator ) ); ?> |
||
| 455 | </option> |
||
| 456 | <?php endforeach; ?> |
||
| 457 | </select> |
||
| 458 | |||
| 459 | <?php |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Render Tags dropdown. |
||
| 464 | */ |
||
| 465 | protected function render_tags_dropdown() { |
||
| 466 | $tags = $this->get_tags(); |
||
| 467 | ?> |
||
| 468 | |||
| 469 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>" |
||
| 470 | class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>" |
||
| 471 | data-taxonomy="post_tag" multiple> |
||
| 472 | |||
| 473 | <option value="all"> |
||
| 474 | <?php _e( 'All Tags', 'bulk-delete' ); ?> |
||
| 475 | </option> |
||
| 476 | |||
| 477 | <?php foreach ( $tags as $tag ) : ?> |
||
| 478 | <option value="<?php echo absint( $tag->term_id ); ?>"> |
||
| 479 | <?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
| 480 | </option> |
||
| 481 | <?php endforeach; ?> |
||
| 482 | </select> |
||
| 483 | <?php |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get the class name for select2 dropdown based on the number of items present. |
||
| 488 | * |
||
| 489 | * @param int $count The number of items present. |
||
| 490 | * @param string $class_name Primary class name. |
||
| 491 | * |
||
| 492 | * @return string Class name. |
||
| 493 | */ |
||
| 494 | protected function enable_ajax_if_needed_to_dropdown_class_name( $count, $class_name ) { |
||
| 495 | if ( $count >= $this->get_enhanced_select_threshold() ) { |
||
| 496 | $class_name .= '-ajax'; |
||
| 497 | } |
||
| 498 | |||
| 499 | return $class_name; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Render Sticky Posts dropdown. |
||
| 504 | */ |
||
| 505 | protected function render_sticky_posts_dropdown() { |
||
| 506 | $sticky_posts = $this->get_sticky_posts(); |
||
| 507 | ?> |
||
| 508 | |||
| 509 | <table class="optiontable"> |
||
| 510 | <?php if ( count( $sticky_posts ) > 1 ) : ?> |
||
| 511 | <tr> |
||
| 512 | <td scope="row"> |
||
| 513 | <label> |
||
| 514 | <input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="all"> |
||
| 515 | <?php echo __( 'All sticky posts', 'bulk-delete' ), ' (', count( $sticky_posts ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
| 516 | </label> |
||
| 517 | </td> |
||
| 518 | </tr> |
||
| 519 | <?php endif; ?> |
||
| 520 | |||
| 521 | <?php foreach ( $sticky_posts as $post ) : ?> |
||
| 522 | <?php $author = get_userdata( $post->post_author ); ?> |
||
| 523 | <tr> |
||
| 524 | <td scope="row"> |
||
| 525 | <label> |
||
| 526 | <input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>"> |
||
| 527 | <?php |
||
| 528 | echo esc_html( $post->post_title ), ' - ', |
||
| 529 | __( 'Published on', 'bulk-delete' ), ' ', get_the_date( get_option( 'date_format' ), $post->ID ), |
||
| 530 | __( ' by ', 'bulk-delete' ), esc_html( $author->display_name ); |
||
| 531 | ?> |
||
| 532 | </label> |
||
| 533 | </td> |
||
| 534 | </tr> |
||
| 535 | <?php endforeach; ?> |
||
| 536 | </table> |
||
| 537 | <?php |
||
| 538 | } |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Renders exclude sticky posts checkbox. |
||
| 542 | */ |
||
| 543 | protected function render_exclude_sticky_settings() { |
||
| 544 | if ( $this->are_sticky_posts_present() ) : // phpcs:ignore?> |
||
| 545 | <tr> |
||
| 546 | <td scope="row"> |
||
| 547 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky" value="true" type="checkbox"> |
||
| 548 | </td> |
||
| 549 | <td> |
||
| 550 | <label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky"><?php _e( 'Exclude sticky posts', 'bulk-delete' ); ?></label> |
||
| 551 | </td> |
||
| 552 | </tr> |
||
| 553 | <?php endif; // phpcs:ignore?> |
||
| 554 | <?php |
||
| 555 | } |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Render Post Types as checkboxes. |
||
| 559 | * |
||
| 560 | * @since 5.6.0 |
||
| 561 | * |
||
| 562 | * @param string $name Name of post type checkboxes. |
||
| 563 | */ |
||
| 564 | protected function render_post_type_checkboxes( $name ) { |
||
| 565 | $post_types = bd_get_post_types(); |
||
| 566 | ?> |
||
| 567 | |||
| 568 | <?php foreach ( $post_types as $post_type ) : ?> |
||
| 569 | |||
| 570 | <tr> |
||
| 571 | <td scope="row"> |
||
| 572 | <input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>" |
||
| 573 | id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked> |
||
| 574 | |||
| 575 | <label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
| 576 | <?php echo esc_html( $post_type->label ); ?> |
||
| 577 | </label> |
||
| 578 | </td> |
||
| 579 | </tr> |
||
| 580 | |||
| 581 | <?php endforeach; ?> |
||
| 582 | <?php |
||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Render the "private post" setting fields. |
||
| 587 | */ |
||
| 588 | protected function render_private_post_settings() { |
||
| 589 | bd_render_private_post_settings( $this->field_slug ); |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Render sticky settings. |
||
| 594 | */ |
||
| 595 | protected function render_sticky_action_settings() { |
||
| 596 | ?> |
||
| 597 | <tr> |
||
| 598 | <td scope="row" colspan="2"> |
||
| 599 | <label> |
||
| 600 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="unsticky" type="radio" checked> |
||
| 601 | <?php _e( 'Remove Sticky', 'bulk-delete' ); ?> |
||
| 602 | </label> |
||
| 603 | <label> |
||
| 604 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="delete" type="radio"> |
||
| 605 | <?php _e( 'Delete Post', 'bulk-delete' ); ?> |
||
| 606 | </label> |
||
| 607 | </td> |
||
| 608 | </tr> |
||
| 609 | <?php |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Render filtering table header. |
||
| 614 | */ |
||
| 615 | protected function render_filtering_table_header() { |
||
| 616 | bd_render_filtering_table_header(); |
||
| 617 | } |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Render restrict settings. |
||
| 621 | */ |
||
| 622 | protected function render_restrict_settings() { |
||
| 623 | bd_render_restrict_settings( $this->field_slug, $this->item_type ); |
||
| 624 | } |
||
| 625 | |||
| 626 | /** |
||
| 627 | * Render delete settings. |
||
| 628 | * |
||
| 629 | * @since 6.1.0 Added $hide_trash param. |
||
| 630 | * |
||
| 631 | * @param bool $hide_trash Show/Hide Move to trash radio button. Default false. |
||
| 632 | */ |
||
| 633 | protected function render_delete_settings( $hide_trash = false ) { |
||
| 634 | bd_render_delete_settings( $this->field_slug, $hide_trash ); |
||
| 635 | /** |
||
| 636 | * This action is primarily for adding delete attachment settings. |
||
| 637 | * |
||
| 638 | * @since 6.0.0 |
||
| 639 | * |
||
| 640 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule The delete module. |
||
| 641 | */ |
||
| 642 | do_action( 'bd_render_attachment_settings', $this ); |
||
| 643 | } |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Render limit settings. |
||
| 647 | * |
||
| 648 | * @param string $item_type Item Type to be displayed in label. |
||
| 649 | */ |
||
| 650 | protected function render_limit_settings( $item_type = '' ) { |
||
| 651 | if ( empty( $item_type ) ) { |
||
| 652 | $item_type = $this->item_type; |
||
| 653 | } |
||
| 654 | bd_render_limit_settings( $this->field_slug, $item_type ); |
||
| 655 | } |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Render cron settings based on whether scheduler is present or not. |
||
| 659 | */ |
||
| 660 | protected function render_cron_settings() { |
||
| 661 | $pro_class = ''; |
||
| 662 | |||
| 663 | $disabled_attr = 'disabled'; |
||
| 664 | if ( empty( $this->scheduler_url ) ) { |
||
| 665 | $disabled_attr = ''; |
||
| 666 | } |
||
| 667 | ?> |
||
| 668 | |||
| 669 | <tr> |
||
| 670 | <td scope="row" colspan="2"> |
||
| 671 | <label> |
||
| 672 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio" |
||
| 673 | checked="checked" class="schedule-deletion"> |
||
| 674 | <?php _e( 'Delete now', 'bulk-delete' ); ?> |
||
| 675 | </label> |
||
| 676 | |||
| 677 | <label> |
||
| 678 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="true" type="radio" |
||
| 679 | class="schedule-deletion" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" <?php echo esc_attr( $disabled_attr ); ?>> |
||
| 680 | <?php _e( 'Schedule', 'bulk-delete' ); ?> |
||
| 681 | </label> |
||
| 682 | |||
| 683 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" |
||
| 684 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" value="now" |
||
| 685 | type="text" <?php echo esc_attr( $disabled_attr ); ?> autocomplete="off"><?php _e( 'repeat ', 'bulk-delete' ); ?> |
||
| 686 | |||
| 687 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" |
||
| 688 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" <?php echo esc_attr( $disabled_attr ); ?>> |
||
| 689 | |||
| 690 | <option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
||
| 691 | <?php |
||
| 692 | /** |
||
| 693 | * List of cron schedules. |
||
| 694 | * |
||
| 695 | * @since 6.0.0 |
||
| 696 | * |
||
| 697 | * @param array $cron_schedules List of cron schedules. |
||
| 698 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Module. |
||
| 699 | */ |
||
| 700 | $cron_schedules = apply_filters( 'bd_cron_schedules', wp_get_schedules(), $this ); |
||
| 701 | ?> |
||
| 702 | |||
| 703 | <?php foreach ( $cron_schedules as $key => $value ) : ?> |
||
| 704 | <option |
||
| 705 | value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['display'] ); ?></option> |
||
| 706 | <?php endforeach; ?> |
||
| 707 | </select> |
||
| 708 | |||
| 709 | <?php if ( ! empty( $this->scheduler_url ) ) : ?> |
||
| 710 | <?php |
||
| 711 | $pro_class = 'bd-' . str_replace( '_', '-', $this->field_slug ) . '-pro'; |
||
| 712 | |||
| 713 | /** |
||
| 714 | * HTML class of the span that displays the 'Pro only feature' message. |
||
| 715 | * |
||
| 716 | * @since 6.0.0 |
||
| 717 | * |
||
| 718 | * @param string $pro_class HTML class. |
||
| 719 | * @param string $field_slug Field Slug of module. |
||
| 720 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Module. |
||
| 721 | */ |
||
| 722 | $pro_class = apply_filters( 'bd_pro_only_feature_class', $pro_class, $this->field_slug, $this ) |
||
| 723 | ?> |
||
| 724 | |||
| 725 | <span class="<?php echo sanitize_html_class( $pro_class ); ?>" style="color:red"> |
||
| 726 | <?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a |
||
| 727 | href="<?php echo esc_url( $this->scheduler_url ); ?>" target="_blank">Buy now</a> |
||
| 728 | </span> |
||
| 729 | <?php endif; ?> |
||
| 730 | </td> |
||
| 731 | </tr> |
||
| 732 | |||
| 733 | <tr |
||
| 734 | <?php if ( ! empty( $pro_class ) ) : ?> |
||
| 735 | class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;" |
||
| 736 | <?php endif; ?> |
||
| 737 | > |
||
| 738 | |||
| 739 | <td scope="row" colspan="2"> |
||
| 740 | <?php |
||
| 741 | _e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time.', 'bulk-delete' ); |
||
| 742 | |||
| 743 | $markup = __( 'Want to add new a Cron schedule?', 'bulk-delete' ) . ' ' . |
||
| 744 | '<a href="https://bulkwp.com/docs/add-a-new-cron-schedule/?utm_campaign=Docs&utm_medium=wpadmin&utm_source=tooltip&utm_content=cron-schedule" target="_blank" rel="noopener">' . __( 'Find out how', 'bulk-delete' ) . '</a>'; |
||
| 745 | |||
| 746 | $content = __( 'Learn how to add your desired Cron schedule.', 'bulk-delete' ); |
||
| 747 | echo ' ', bd_generate_help_tooltip( $markup, $content ); |
||
| 748 | ?> |
||
| 749 | </td> |
||
| 750 | </tr> |
||
| 751 | <?php |
||
| 752 | } |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Render submit button. |
||
| 756 | */ |
||
| 757 | protected function render_submit_button() { |
||
| 759 | } |
||
| 760 | } |
||
| 761 |