| Total Complexity | 58 |
| Total Lines | 647 |
| Duplicated Lines | 0 % |
| Changes | 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 | /** |
||
| 17 | * Slug for the form fields. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $field_slug; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Render post status including custom post status. |
||
| 25 | * |
||
| 26 | * @param string $post_type The post type for which the post status should be displayed. |
||
| 27 | */ |
||
| 28 | protected function render_post_status( $post_type = 'post' ) { |
||
| 29 | $post_statuses = $this->get_post_statuses(); |
||
| 30 | $post_count = wp_count_posts( $post_type ); |
||
| 31 | |||
| 32 | foreach ( $post_statuses as $post_status ) : ?> |
||
| 33 | <tr> |
||
| 34 | <td> |
||
| 35 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>" |
||
| 36 | value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox"> |
||
| 37 | |||
| 38 | <label for="smbd_<?php echo esc_attr( $post_status->name ); ?>"> |
||
| 39 | <?php echo esc_html( $post_status->label ), ' '; ?> |
||
| 40 | <?php if ( property_exists( $post_count, $post_status->name ) ) : ?> |
||
| 41 | (<?php echo absint( $post_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>) |
||
| 42 | <?php endif; ?> |
||
| 43 | </label> |
||
| 44 | </td> |
||
| 45 | </tr> |
||
| 46 | <?php endforeach; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Render Post Types as radio buttons. |
||
| 51 | */ |
||
| 52 | protected function render_post_type_as_radios() { |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Render Post type with status and post count checkboxes. |
||
| 76 | * |
||
| 77 | * @since 6.0.1 Added $multiple param. |
||
| 78 | * |
||
| 79 | * @param bool $multiple_select Whether multiple select should be supported. Default true. |
||
| 80 | */ |
||
| 81 | protected function render_post_type_with_status( $multiple_select = true ) { |
||
| 111 | </select> |
||
| 112 | </td> |
||
| 113 | </tr> |
||
| 114 | <?php |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Split post type and status. |
||
| 119 | * |
||
| 120 | * @param string $str Post type and status combination. |
||
| 121 | * |
||
| 122 | * @return array Post type and status as elements of array. |
||
| 123 | */ |
||
| 124 | protected function split_post_type_and_status( $str ) { |
||
| 125 | $type_status = array(); |
||
| 126 | |||
| 127 | if ( strpos( $str, '|' ) === false ) { |
||
| 128 | $str_arr = explode( '-', $str ); |
||
| 129 | } else { |
||
| 130 | $str_arr = explode( '|', $str ); |
||
| 131 | } |
||
| 132 | |||
| 133 | if ( count( $str_arr ) > 1 ) { |
||
| 134 | $type_status['status'] = end( $str_arr ); |
||
| 135 | $type_status['type'] = implode( '-', array_slice( $str_arr, 0, - 1 ) ); |
||
| 136 | } else { |
||
| 137 | $type_status['status'] = 'publish'; |
||
| 138 | $type_status['type'] = $str; |
||
| 139 | } |
||
| 140 | |||
| 141 | return $type_status; |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Render post reassign settings. |
||
| 146 | */ |
||
| 147 | protected function render_post_reassign_settings() { |
||
| 148 | ?> |
||
| 149 | <tr> |
||
| 150 | <td scope="row" colspan="2"> |
||
| 151 | <label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="false" type="radio" |
||
| 152 | checked="checked" class="post-reassign"> <?php _e( 'Also delete all posts of the users', 'bulk-delete' ); ?></label> |
||
| 153 | <label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="true" type="radio" |
||
| 154 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" class="post-reassign"> <?php _e( 'Re-assign the posts to', 'bulk-delete' ); ?></label> |
||
| 155 | <?php |
||
| 156 | wp_dropdown_users( |
||
| 157 | array( |
||
| 158 | 'name' => 'smbd_' . esc_attr( $this->field_slug ) . '_reassign_user_id', |
||
| 159 | 'class' => 'reassign-user', |
||
| 160 | 'show_option_none' => __( 'Select User', 'bulk-delete' ), |
||
| 161 | ) |
||
| 162 | ); |
||
| 163 | ?> |
||
| 164 | </td> |
||
| 165 | </tr> |
||
| 166 | <?php |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Render user role dropdown. |
||
| 171 | * |
||
| 172 | * @param bool $show_users_with_no_roles Should users with no user roles be shown? Default false. |
||
| 173 | */ |
||
| 174 | protected function render_user_role_dropdown( $show_users_with_no_roles = false ) { |
||
| 175 | $roles = get_editable_roles(); |
||
| 176 | $users_count = count_users(); |
||
| 177 | ?> |
||
| 178 | |||
| 179 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="enhanced-role-dropdown" |
||
| 180 | multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>"> |
||
| 181 | |||
| 182 | <?php foreach ( $roles as $role => $role_details ) : ?> |
||
| 183 | <option value="<?php echo esc_attr( $role ); ?>"> |
||
| 184 | <?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role, $users_count ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
||
| 185 | </option> |
||
| 186 | <?php endforeach; ?> |
||
| 187 | |||
| 188 | <?php if ( $show_users_with_no_roles ) : ?> |
||
| 189 | <?php if ( isset( $users_count['avail_roles']['none'] ) && $users_count['avail_roles']['none'] > 0 ) : ?> |
||
| 190 | <option value="none"> |
||
| 191 | <?php echo __( 'No role', 'bulk-delete' ), ' (', absint( $users_count['avail_roles']['none'] ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
||
| 192 | </option> |
||
| 193 | <?php endif; ?> |
||
| 194 | <?php endif; ?> |
||
| 195 | </select> |
||
| 196 | |||
| 197 | <?php |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Render Post type dropdown. |
||
| 202 | */ |
||
| 203 | protected function render_post_type_dropdown() { |
||
| 204 | bd_render_post_type_dropdown( $this->field_slug ); |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Render Taxonomy dropdown. |
||
| 209 | */ |
||
| 210 | protected function render_taxonomy_dropdown() { |
||
| 211 | $builtin_taxonomies = get_taxonomies( array( '_builtin' => true ), 'objects' ); |
||
| 212 | $custom_taxonomies = get_taxonomies( array( '_builtin' => false ), 'objects' ); |
||
| 213 | ?> |
||
| 214 | <select class="enhanced-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy"> |
||
| 215 | <optgroup label="<?php esc_attr_e( 'Built-in Taxonomies', 'bulk-delete' ); ?>"> |
||
| 216 | <?php foreach ( $builtin_taxonomies as $taxonomy ) : ?> |
||
| 217 | <option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
||
| 218 | <?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?> |
||
| 219 | </option> |
||
| 220 | <?php endforeach; ?> |
||
| 221 | </optgroup> |
||
| 222 | |||
| 223 | <optgroup label="<?php esc_attr_e( 'Custom Taxonomies', 'bulk-delete' ); ?>"> |
||
| 224 | <?php foreach ( $custom_taxonomies as $taxonomy ) : ?> |
||
| 225 | <option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
||
| 226 | <?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?> |
||
| 227 | </option> |
||
| 228 | <?php endforeach; ?> |
||
| 229 | </optgroup> |
||
| 230 | </select> |
||
| 231 | <?php |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Render Category dropdown. |
||
| 236 | */ |
||
| 237 | protected function render_category_dropdown() { |
||
| 238 | $categories = $this->get_categories(); |
||
| 239 | ?> |
||
| 240 | |||
| 241 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>" |
||
| 242 | class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>" |
||
| 243 | data-taxonomy="category" multiple> |
||
| 244 | |||
| 245 | <option value="all"> |
||
| 246 | <?php _e( 'All Categories', 'bulk-delete' ); ?> |
||
| 247 | </option> |
||
| 248 | |||
| 249 | <?php foreach ( $categories as $category ) : ?> |
||
| 250 | <option value="<?php echo absint( $category->cat_ID ); ?>"> |
||
| 251 | <?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
| 252 | </option> |
||
| 253 | <?php endforeach; ?> |
||
| 254 | |||
| 255 | </select> |
||
| 256 | <?php |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Render String based comparison operators dropdown. |
||
| 261 | */ |
||
| 262 | protected function render_string_comparison_operators() { |
||
| 263 | ?> |
||
| 264 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator"> |
||
| 265 | <option value="equal_to"><?php _e( 'equal to', 'bulk-delete' ); ?></option> |
||
| 266 | <option value="not_equal_to"><?php _e( 'not equal to', 'bulk-delete' ); ?></option> |
||
| 267 | <option value="starts_with"><?php _e( 'starts with', 'bulk-delete' ); ?></option> |
||
| 268 | <option value="ends_with"><?php _e( 'ends with', 'bulk-delete' ); ?></option> |
||
| 269 | <option value="contains"><?php _e( 'contains', 'bulk-delete' ); ?></option> |
||
| 270 | <option value="not_contains"><?php _e( 'not contains', 'bulk-delete' ); ?></option> |
||
| 271 | </select> |
||
| 272 | <?php |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Render number based comparison operators dropdown. |
||
| 277 | */ |
||
| 278 | protected function render_number_comparison_operators() { |
||
| 279 | ?> |
||
| 280 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator"> |
||
| 281 | <option value="="><?php _e( 'equal to', 'bulk-delete' ); ?></option> |
||
| 282 | <option value="!="><?php _e( 'not equal to', 'bulk-delete' ); ?></option> |
||
| 283 | <option value="<"><?php _e( 'less than', 'bulk-delete' ); ?></option> |
||
| 284 | <option value=">"><?php _e( 'greater than', 'bulk-delete' ); ?></option> |
||
| 285 | </select> |
||
| 286 | <?php |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Render data types dropdown. |
||
| 291 | */ |
||
| 292 | protected function render_data_types_dropdown() { |
||
| 298 | </select> |
||
| 299 | <?php |
||
| 300 | } |
||
| 301 | /** |
||
| 302 | * Render numeric comparison operators dropdown. |
||
| 303 | * |
||
| 304 | * @param string $class Class to be applied. |
||
| 305 | * @param array $operators List of Operators needed. |
||
| 306 | */ |
||
| 307 | protected function render_numeric_operators_dropdown( $class = 'numeric', $operators = array( 'all' ) ) { |
||
| 308 | $all_numeric_operators = array( |
||
| 309 | '=' => 'equal to', |
||
| 310 | '!=' => 'not equal to', |
||
| 311 | '<' => 'less than', |
||
| 312 | '<=' => 'less than or equal to', |
||
| 313 | '>' => 'greater than', |
||
| 314 | '>=' => 'greater than or equal to', |
||
| 315 | 'IN' => 'in', |
||
| 316 | 'NOT IN' => 'not in', |
||
| 317 | 'BETWEEN' => 'between', |
||
| 318 | 'NOT BETWEEN' => 'not between', |
||
| 319 | 'EXISTS' => 'exists', |
||
| 320 | 'NOT EXISTS' => 'not exists', |
||
| 321 | ); |
||
| 322 | if ( in_array( 'all', $operators, true ) ) { |
||
| 323 | $operators = array_keys( $all_numeric_operators ); |
||
| 324 | } |
||
| 325 | ?> |
||
| 326 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class= "<?php echo esc_attr( $class ); ?>"> |
||
| 327 | <?php |
||
| 328 | foreach ( $operators as $operator ) { |
||
| 329 | echo '<option value="' . $operator . '">' . __( $all_numeric_operators[ $operator ], 'bulk-delete' ) . '</option>'; |
||
| 330 | } |
||
| 331 | ?> |
||
| 332 | </select> |
||
| 333 | <?php |
||
| 334 | } |
||
| 335 | /** |
||
| 336 | * Render string comparison operators dropdown. |
||
| 337 | * |
||
| 338 | * @param string $class Class to be applied. |
||
| 339 | * @param array $operators List of Operators needed. |
||
| 340 | */ |
||
| 341 | protected function render_string_operators_dropdown( $class = 'string', $operators = array( 'all' ) ) { |
||
| 342 | // STARTS_WITH and ENDS_WITH operators needs a handler as SQL does not support these operators in queries. |
||
| 343 | $all_string_operators = array( |
||
| 344 | '=' => 'equal to', |
||
| 345 | '!=' => 'not equal to', |
||
| 346 | 'IN' => 'in', |
||
| 347 | 'NOT IN' => 'not in', |
||
| 348 | 'LIKE' => 'contains', |
||
| 349 | 'NOT LIKE' => 'not contains', |
||
| 350 | 'EXISTS' => 'exists', |
||
| 351 | 'NOT EXISTS' => 'not exists', |
||
| 352 | 'STARTS_WITH' => 'starts with', |
||
| 353 | 'ENDS_WITH' => 'ends with', |
||
| 354 | ); |
||
| 355 | if ( in_array( 'all', $operators, true ) ) { |
||
| 356 | $operators = array_keys( $all_string_operators ); |
||
| 357 | } |
||
| 358 | ?> |
||
| 359 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo esc_attr( $class ); ?>"> |
||
| 360 | <?php |
||
| 361 | foreach ( $operators as $operator ) { |
||
| 362 | echo '<option value="' . $operator . '">' . __( $all_string_operators[ $operator ], 'bulk-delete' ) . '</option>'; |
||
| 363 | } |
||
| 364 | ?> |
||
| 365 | </select> |
||
| 366 | <?php |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Render Tags dropdown. |
||
| 371 | */ |
||
| 372 | protected function render_tags_dropdown() { |
||
| 373 | $tags = $this->get_tags(); |
||
| 374 | ?> |
||
| 375 | |||
| 376 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>" |
||
| 377 | class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>" |
||
| 378 | data-taxonomy="post_tag" multiple> |
||
| 379 | |||
| 380 | <option value="all"> |
||
| 381 | <?php _e( 'All Tags', 'bulk-delete' ); ?> |
||
| 382 | </option> |
||
| 383 | |||
| 384 | <?php foreach ( $tags as $tag ) : ?> |
||
| 385 | <option value="<?php echo absint( $tag->term_id ); ?>"> |
||
| 386 | <?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
| 387 | </option> |
||
| 388 | <?php endforeach; ?> |
||
| 389 | </select> |
||
| 390 | <?php |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Get the class name for select2 dropdown based on the number of items present. |
||
| 395 | * |
||
| 396 | * @param int $count The number of items present. |
||
| 397 | * @param string $class_name Primary class name. |
||
| 398 | * |
||
| 399 | * @return string Class name. |
||
| 400 | */ |
||
| 401 | protected function enable_ajax_if_needed_to_dropdown_class_name( $count, $class_name ) { |
||
| 402 | if ( $count >= $this->get_enhanced_select_threshold() ) { |
||
| 403 | $class_name .= '-ajax'; |
||
| 404 | } |
||
| 405 | |||
| 406 | return $class_name; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Render Sticky Posts dropdown. |
||
| 411 | */ |
||
| 412 | protected function render_sticky_posts_dropdown() { |
||
| 413 | $sticky_posts = $this->get_sticky_posts(); |
||
| 414 | ?> |
||
| 415 | |||
| 416 | <table class="optiontable"> |
||
| 417 | <?php if ( count( $sticky_posts ) > 1 ) : ?> |
||
| 418 | <tr> |
||
| 419 | <td scope="row"> |
||
| 420 | <label> |
||
| 421 | <input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="all"> |
||
| 422 | <?php echo __( 'All sticky posts', 'bulk-delete' ), ' (', count( $sticky_posts ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
| 423 | </label> |
||
| 424 | </td> |
||
| 425 | </tr> |
||
| 426 | <?php endif; ?> |
||
| 427 | |||
| 428 | <?php foreach ( $sticky_posts as $post ) : ?> |
||
| 429 | <?php $author = get_userdata( $post->post_author ); ?> |
||
| 430 | <tr> |
||
| 431 | <td scope="row"> |
||
| 432 | <label> |
||
| 433 | <input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>"> |
||
| 434 | <?php |
||
| 435 | echo esc_html( $post->post_title ), ' - ', |
||
| 436 | __( 'Published on', 'bulk-delete' ), ' ', get_the_date( get_option( 'date_format' ), $post->ID ), |
||
| 437 | __( ' by ', 'bulk-delete' ), esc_html( $author->display_name ); |
||
| 438 | ?> |
||
| 439 | </label> |
||
| 440 | </td> |
||
| 441 | </tr> |
||
| 442 | <?php endforeach; ?> |
||
| 443 | </table> |
||
| 444 | <?php |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Renders exclude sticky posts checkbox. |
||
| 449 | */ |
||
| 450 | protected function render_exclude_sticky_settings() { |
||
| 451 | if ( $this->are_sticky_posts_present() ) : // phpcs:ignore?> |
||
| 452 | <tr> |
||
| 453 | <td scope="row"> |
||
| 454 | <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"> |
||
| 455 | </td> |
||
| 456 | <td> |
||
| 457 | <label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky"><?php _e( 'Exclude sticky posts', 'bulk-delete' ); ?></label> |
||
| 458 | </td> |
||
| 459 | </tr> |
||
| 460 | <?php endif; // phpcs:ignore?> |
||
| 461 | <?php |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Render Post Types as checkboxes. |
||
| 466 | * |
||
| 467 | * @since 5.6.0 |
||
| 468 | * |
||
| 469 | * @param string $name Name of post type checkboxes. |
||
| 470 | */ |
||
| 471 | protected function render_post_type_checkboxes( $name ) { |
||
| 472 | $post_types = bd_get_post_types(); |
||
| 473 | ?> |
||
| 474 | |||
| 475 | <?php foreach ( $post_types as $post_type ) : ?> |
||
| 476 | |||
| 477 | <tr> |
||
| 478 | <td scope="row"> |
||
| 479 | <input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>" |
||
| 480 | id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked> |
||
| 481 | |||
| 482 | <label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
| 483 | <?php echo esc_html( $post_type->label ); ?> |
||
| 484 | </label> |
||
| 485 | </td> |
||
| 486 | </tr> |
||
| 487 | |||
| 488 | <?php endforeach; ?> |
||
| 489 | <?php |
||
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Render the "private post" setting fields. |
||
| 494 | */ |
||
| 495 | protected function render_private_post_settings() { |
||
| 496 | bd_render_private_post_settings( $this->field_slug ); |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Render sticky settings. |
||
| 501 | */ |
||
| 502 | protected function render_sticky_action_settings() { |
||
| 503 | ?> |
||
| 504 | <tr> |
||
| 505 | <td scope="row" colspan="2"> |
||
| 506 | <label> |
||
| 507 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="unsticky" type="radio" checked> |
||
| 508 | <?php _e( 'Remove Sticky', 'bulk-delete' ); ?> |
||
| 509 | </label> |
||
| 510 | <label> |
||
| 511 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="delete" type="radio"> |
||
| 512 | <?php _e( 'Delete Post', 'bulk-delete' ); ?> |
||
| 513 | </label> |
||
| 514 | </td> |
||
| 515 | </tr> |
||
| 516 | <?php |
||
| 517 | } |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Render filtering table header. |
||
| 521 | */ |
||
| 522 | protected function render_filtering_table_header() { |
||
| 523 | bd_render_filtering_table_header(); |
||
| 524 | } |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Render restrict settings. |
||
| 528 | */ |
||
| 529 | protected function render_restrict_settings() { |
||
| 530 | bd_render_restrict_settings( $this->field_slug, $this->item_type ); |
||
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Render delete settings. |
||
| 535 | */ |
||
| 536 | protected function render_delete_settings() { |
||
| 537 | bd_render_delete_settings( $this->field_slug ); |
||
| 538 | /** |
||
| 539 | * This action is primarily for adding delete attachment settings. |
||
| 540 | * |
||
| 541 | * @since 6.0.0 |
||
| 542 | * |
||
| 543 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule The delete module. |
||
| 544 | */ |
||
| 545 | do_action( 'bd_render_attachment_settings', $this ); |
||
| 546 | } |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Render limit settings. |
||
| 550 | * |
||
| 551 | * @param string $item_type Item Type to be displayed in label. |
||
| 552 | */ |
||
| 553 | protected function render_limit_settings( $item_type = '' ) { |
||
| 554 | if ( empty( $item_type ) ) { |
||
| 555 | $item_type = $this->item_type; |
||
| 556 | } |
||
| 557 | bd_render_limit_settings( $this->field_slug, $item_type ); |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Render cron settings based on whether scheduler is present or not. |
||
| 562 | */ |
||
| 563 | protected function render_cron_settings() { |
||
| 564 | $pro_class = ''; |
||
| 565 | |||
| 566 | $disabled_attr = 'disabled'; |
||
| 567 | if ( empty( $this->scheduler_url ) ) { |
||
| 568 | $disabled_attr = ''; |
||
| 569 | } |
||
| 570 | ?> |
||
| 571 | |||
| 572 | <tr> |
||
| 573 | <td scope="row" colspan="2"> |
||
| 574 | <label> |
||
| 575 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio" |
||
| 576 | checked="checked" class="schedule-deletion"> |
||
| 577 | <?php _e( 'Delete now', 'bulk-delete' ); ?> |
||
| 578 | </label> |
||
| 579 | |||
| 580 | <label> |
||
| 581 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="true" type="radio" |
||
| 582 | class="schedule-deletion" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" <?php echo esc_attr( $disabled_attr ); ?>> |
||
| 583 | <?php _e( 'Schedule', 'bulk-delete' ); ?> |
||
| 584 | </label> |
||
| 585 | |||
| 586 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" |
||
| 587 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" value="now" |
||
| 588 | type="text" <?php echo esc_attr( $disabled_attr ); ?> autocomplete="off"><?php _e( 'repeat ', 'bulk-delete' ); ?> |
||
| 589 | |||
| 590 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" |
||
| 591 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" <?php echo esc_attr( $disabled_attr ); ?>> |
||
| 592 | |||
| 593 | <option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
||
| 594 | <?php |
||
| 595 | /** |
||
| 596 | * List of cron schedules. |
||
| 597 | * |
||
| 598 | * @since 6.0.0 |
||
| 599 | * |
||
| 600 | * @param array $cron_schedules List of cron schedules. |
||
| 601 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Module. |
||
| 602 | */ |
||
| 603 | $cron_schedules = apply_filters( 'bd_cron_schedules', wp_get_schedules(), $this ); |
||
| 604 | ?> |
||
| 605 | |||
| 606 | <?php foreach ( $cron_schedules as $key => $value ) : ?> |
||
| 607 | <option |
||
| 608 | value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['display'] ); ?></option> |
||
| 609 | <?php endforeach; ?> |
||
| 610 | </select> |
||
| 611 | |||
| 612 | <?php if ( ! empty( $this->scheduler_url ) ) : ?> |
||
| 613 | <?php |
||
| 614 | $pro_class = 'bd-' . str_replace( '_', '-', $this->field_slug ) . '-pro'; |
||
| 615 | |||
| 616 | /** |
||
| 617 | * HTML class of the span that displays the 'Pro only feature' message. |
||
| 618 | * |
||
| 619 | * @since 6.0.0 |
||
| 620 | * |
||
| 621 | * @param string $pro_class HTML class. |
||
| 622 | * @param string $field_slug Field Slug of module. |
||
| 623 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Module. |
||
| 624 | */ |
||
| 625 | $pro_class = apply_filters( 'bd_pro_only_feature_class', $pro_class, $this->field_slug, $this ) |
||
| 626 | ?> |
||
| 627 | |||
| 628 | <span class="<?php echo sanitize_html_class( $pro_class ); ?>" style="color:red"> |
||
| 629 | <?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a |
||
| 630 | href="<?php echo esc_url( $this->scheduler_url ); ?>" target="_blank">Buy now</a> |
||
| 631 | </span> |
||
| 632 | <?php endif; ?> |
||
| 633 | </td> |
||
| 634 | </tr> |
||
| 635 | |||
| 636 | <tr |
||
| 637 | <?php if ( ! empty( $pro_class ) ) : ?> |
||
| 638 | class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;" |
||
| 639 | <?php endif; ?> |
||
| 640 | > |
||
| 641 | |||
| 642 | <td scope="row" colspan="2"> |
||
| 643 | <?php |
||
| 644 | _e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time.', 'bulk-delete' ); |
||
| 645 | |||
| 646 | $markup = __( 'Want to add new a Cron schedule?', 'bulk-delete' ) . ' ' . |
||
| 647 | '<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>'; |
||
| 648 | |||
| 649 | $content = __( 'Learn how to add your desired Cron schedule.', 'bulk-delete' ); |
||
| 650 | echo ' ', bd_generate_help_tooltip( $markup, $content ); |
||
| 651 | ?> |
||
| 652 | </td> |
||
| 653 | </tr> |
||
| 654 | <?php |
||
| 655 | } |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Render submit button. |
||
| 659 | */ |
||
| 660 | protected function render_submit_button() { |
||
| 662 | } |
||
| 663 | } |
||
| 664 |