sudar /
bulk-delete
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Utility functions for displaying form. |
||
| 4 | * |
||
| 5 | * @since 5.5 |
||
| 6 | * |
||
| 7 | * @author Sudar |
||
| 8 | * |
||
| 9 | * @package BulkDelete\Ui |
||
| 10 | */ |
||
| 11 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Render filtering table header. |
||
| 15 | * |
||
| 16 | * @since 5.5 |
||
| 17 | */ |
||
| 18 | function bd_render_filtering_table_header() { |
||
| 19 | ?> |
||
| 20 | <tr> |
||
| 21 | <td colspan="2"> |
||
| 22 | <h4><?php _e( 'Choose your filtering options', 'bulk-delete' ); ?></h4> |
||
| 23 | </td> |
||
| 24 | </tr> |
||
| 25 | <?php |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Render "restrict by created date" dropdown. |
||
| 30 | * |
||
| 31 | * @since 5.5 |
||
| 32 | * |
||
| 33 | * @param string $slug The slug to be used in field names. |
||
| 34 | * @param string $item (optional) Item for which form is displayed. Default is 'posts'. |
||
| 35 | */ |
||
| 36 | function bd_render_restrict_settings( $slug, $item = 'posts' ) { |
||
| 37 | ?> |
||
| 38 | <tr> |
||
| 39 | <td scope="row"> |
||
| 40 | <input name="smbd_<?php echo $slug; ?>_restrict" id="smbd_<?php echo $slug; ?>_restrict" value="true" type="checkbox"> |
||
| 41 | </td> |
||
| 42 | <td> |
||
| 43 | <?php printf( __( 'Only restrict to %s which are ', 'bulk-delete' ), $item );?> |
||
| 44 | <select name="smbd_<?php echo $slug; ?>_op" id="smbd_<?php echo $slug; ?>_op" disabled> |
||
| 45 | <option value="before"><?php _e( 'older than', 'bulk-delete' );?></option> |
||
| 46 | <option value="after"><?php _e( 'posted within last', 'bulk-delete' );?></option> |
||
| 47 | </select> |
||
| 48 | <input type="number" name="smbd_<?php echo $slug; ?>_days" id="smbd_<?php echo $slug; ?>_days" class="screen-per-page" disabled value="0" min="0"><?php _e( 'days', 'bulk-delete' );?> |
||
| 49 | </td> |
||
| 50 | </tr> |
||
| 51 | <?php |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Render "force delete" setting fields. |
||
| 56 | * |
||
| 57 | * @since 5.5 |
||
| 58 | * |
||
| 59 | * @param string $slug The slug to be used in field names. |
||
| 60 | */ |
||
| 61 | function bd_render_delete_settings( $slug ) { |
||
| 62 | ?> |
||
| 63 | <tr> |
||
| 64 | <td scope="row" colspan="2"> |
||
| 65 | <input name="smbd_<?php echo $slug; ?>_force_delete" value="false" type="radio" checked> <?php _e( 'Move to Trash', 'bulk-delete' ); ?> |
||
| 66 | <input name="smbd_<?php echo $slug; ?>_force_delete" value="true" type="radio"> <?php _e( 'Delete permanently', 'bulk-delete' ); ?> |
||
| 67 | </td> |
||
| 68 | </tr> |
||
| 69 | <?php |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Render the "private post" setting fields. |
||
| 74 | * |
||
| 75 | * @since 5.5 |
||
| 76 | * |
||
| 77 | * @param string $slug The slug to be used in field names. |
||
| 78 | */ |
||
| 79 | function bd_render_private_post_settings( $slug ) { |
||
| 80 | ?> |
||
| 81 | <tr> |
||
| 82 | <td scope="row" colspan="2"> |
||
| 83 | <input name="smbd_<?php echo $slug; ?>_private" value="false" type="radio" checked> <?php _e( 'Public posts', 'bulk-delete' ); ?> |
||
| 84 | <input name="smbd_<?php echo $slug; ?>_private" value="true" type="radio"> <?php _e( 'Private Posts', 'bulk-delete' ); ?> |
||
| 85 | </td> |
||
| 86 | </tr> |
||
| 87 | <?php |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Render the "limit" setting fields. |
||
| 92 | * |
||
| 93 | * @since 5.5 |
||
| 94 | * |
||
| 95 | * @param string $slug The slug to be used in field names. |
||
| 96 | * @param string $item (Optional) Item type. Possible values are 'posts', 'pages', 'users' |
||
| 97 | */ |
||
| 98 | function bd_render_limit_settings( $slug, $item = 'posts' ) { |
||
| 99 | ?> |
||
| 100 | <tr> |
||
| 101 | <td scope="row"> |
||
| 102 | <input name="smbd_<?php echo $slug; ?>_limit" id="smbd_<?php echo $slug; ?>_limit" value="true" type="checkbox"> |
||
| 103 | </td> |
||
| 104 | <td> |
||
| 105 | <?php _e( 'Only delete first ', 'bulk-delete' );?> |
||
| 106 | <input type="number" name="smbd_<?php echo $slug; ?>_limit_to" id="smbd_<?php echo $slug; ?>_limit_to" class="screen-per-page" disabled value="0" min="0"> <?php echo $item;?>. |
||
| 107 | <?php printf( __( 'Use this option if there are more than 1000 %s and the script timesout.', 'bulk-delete' ), $item ); ?> |
||
| 108 | </td> |
||
| 109 | </tr> |
||
| 110 | <?php |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Render cron setting fields. |
||
| 115 | * |
||
| 116 | * @since 5.5 |
||
| 117 | * |
||
| 118 | * @param string $slug The slug to be used in field names. |
||
| 119 | * @param string $addon_url Url for the pro addon. |
||
| 120 | */ |
||
| 121 | function bd_render_cron_settings( $slug, $addon_url ) { |
||
| 122 | $pro_class = 'bd-' . str_replace( '_', '-', $slug ) . '-pro'; |
||
| 123 | ?> |
||
| 124 | <tr> |
||
| 125 | <td scope="row" colspan="2"> |
||
| 126 | <input name="smbd_<?php echo $slug; ?>_cron" value="false" type="radio" checked="checked"> <?php _e( 'Delete now', 'bulk-delete' ); ?> |
||
| 127 | <input name="smbd_<?php echo $slug; ?>_cron" value="true" type="radio" id="smbd_<?php echo $slug; ?>_cron" disabled > <?php _e( 'Schedule', 'bulk-delete' ); ?> |
||
| 128 | <input name="smbd_<?php echo $slug; ?>_cron_start" id="smbd_<?php echo $slug; ?>_cron_start" value="now" type="text" disabled><?php _e( 'repeat ', 'bulk-delete' );?> |
||
| 129 | <select name="smbd_<?php echo $slug; ?>_cron_freq" id="smbd_<?php echo $slug; ?>_cron_freq" disabled> |
||
| 130 | <option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
||
| 131 | <?php |
||
| 132 | $schedules = wp_get_schedules(); |
||
| 133 | foreach ( $schedules as $key => $value ) { |
||
| 134 | ?> |
||
| 135 | <option value="<?php echo $key; ?>"><?php echo $value['display']; ?></option> |
||
| 136 | <?php } ?> |
||
| 137 | </select> |
||
| 138 | <span class="<?php echo sanitize_html_class( apply_filters( 'bd_pro_class', $pro_class, $slug ) ); ?>" style="color:red"><?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a href="<?php echo $addon_url; ?>">Buy now</a></span> |
||
| 139 | </td> |
||
| 140 | </tr> |
||
| 141 | |||
| 142 | <tr> |
||
| 143 | <td scope="row" colspan="2"> |
||
| 144 | <?php _e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time', 'bulk-delete' );?> |
||
| 145 | </td> |
||
| 146 | </tr> |
||
| 147 | <?php |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Render the submit button. |
||
| 152 | * |
||
| 153 | * @since 5.5 |
||
| 154 | * |
||
| 155 | * @param string $action The action attribute of the submit button. |
||
| 156 | */ |
||
| 157 | function bd_render_submit_button( $action ) { |
||
| 158 | ?> |
||
| 159 | <p class="submit"> |
||
| 160 | <button type="submit" name="bd_action" value="<?php echo esc_attr( $action ); ?>" class="button-primary"><?php _e( 'Bulk Delete ', 'bulk-delete' ); ?>»</button> |
||
| 161 | </p> |
||
| 162 | <?php |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Render the post type dropdown. |
||
| 167 | * |
||
| 168 | * @since 5.5 |
||
| 169 | * |
||
| 170 | * @param string $slug The slug to be used in field names. |
||
| 171 | * @param array $dropdown_args { |
||
| 172 | * Optional. An array of arguments. |
||
| 173 | * |
||
| 174 | * @type bool $is_multi_value_select Setting `true` renders a multi-value select box. Default `false`. |
||
| 175 | * @type bool $is_select_all_options Setting `true` renders a multi-value select box |
||
| 176 | * with all options selected. Default `false`. |
||
| 177 | * @type string $style_attribute Sets the value for the style attribute of the |
||
| 178 | * select tag. Default ''. |
||
| 179 | * } |
||
| 180 | */ |
||
| 181 | function bd_render_post_type_dropdown( $slug, $dropdown_args = array() ) { |
||
| 182 | $dropdown_args_defaults = array( |
||
|
0 ignored issues
–
show
|
|||
| 183 | 'is_multi_value_select' => false, |
||
| 184 | 'is_select_all_options' => false, |
||
| 185 | 'style_attribute' => '', |
||
| 186 | ); |
||
| 187 | |||
| 188 | $dropdown_args = wp_parse_args( $dropdown_args, $dropdown_args_defaults ); |
||
| 189 | |||
| 190 | $types = get_post_types( array( |
||
| 191 | '_builtin' => false, |
||
| 192 | ), 'names' ); |
||
| 193 | array_unshift( $types, 'page' ); |
||
| 194 | array_unshift( $types, 'post' ); |
||
| 195 | ?> |
||
| 196 | <tr class="post-type-dropdown" id="smbd_<?php echo esc_attr( $slug ); ?>-post-type-dropdown"> |
||
| 197 | <td scope="row" > |
||
| 198 | <?php _e( 'You may select/de-select post types listed below.', 'bulk-delete' ); // WPCS: XSS ok.?> |
||
| 199 | <br/><br/> |
||
| 200 | <select class="select2" name="smbd_<?php echo esc_attr( $slug ); ?>_post_type<?php if ( $dropdown_args['is_multi_value_select'] ) : ?>[]<?php endif; ?>" id="smbd_<?php echo esc_attr( $slug ); ?>_post_type" |
||
| 201 | <?php if ( $dropdown_args['is_multi_value_select'] ) : ?> multiple="multiple" <?php endif; ?> |
||
| 202 | <?php if ( $dropdown_args['style_attribute'] ) : ?> style="<?php echo esc_attr( $dropdown_args['style_attribute'] ); ?>" <?php endif; ?>> |
||
| 203 | <?php foreach ( $types as $type ) { ?> |
||
| 204 | <option value="<?php echo esc_attr( $type ); ?>" |
||
| 205 | <?php if ( $dropdown_args['is_select_all_options'] ) : ?> selected="selected" <?php endif; ?>><?php echo esc_html( $type ); ?></option> |
||
| 206 | <?php } ?> |
||
| 207 | </select> |
||
| 208 | </td> |
||
| 209 | </tr> |
||
| 210 | <?php |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Render the post status filter. |
||
| 215 | * |
||
| 216 | * @since 5.6.0 |
||
| 217 | * |
||
| 218 | * @param string $slug The slug to be used in field names. |
||
| 219 | * @param string $selected Default selected status. |
||
| 220 | */ |
||
| 221 | function bd_render_post_status_filter( $slug, $selected = 'publish' ) { |
||
| 222 | $post_statuses = get_post_stati( array(), 'object' ); |
||
| 223 | |||
| 224 | /** |
||
| 225 | * List of post statuses that should be excluded from post status filter. |
||
| 226 | * |
||
| 227 | * @since 5.6.0 |
||
| 228 | * |
||
| 229 | * @param array $post_statuses List of post statuses. |
||
| 230 | */ |
||
| 231 | $exclude_post_statuses = apply_filters( 'bd_exclude_post_statuses', array( 'inherit', 'trash', 'auto-draft' ) ); |
||
|
0 ignored issues
–
show
|
|||
| 232 | |||
| 233 | foreach ( $exclude_post_statuses as $key ) { |
||
| 234 | unset( $post_statuses[ $key ] ); |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * List of post statuses that are displayed in the post status filter. |
||
| 239 | * |
||
| 240 | * @since 5.6.0 |
||
| 241 | * |
||
| 242 | * @param array $post_statuses List of post statuses. |
||
| 243 | */ |
||
| 244 | $post_statuses = apply_filters( 'bd_post_statuses', $post_statuses ); |
||
| 245 | |||
| 246 | foreach ( $post_statuses as $key => $value ) { |
||
| 247 | ?> |
||
| 248 | <tr> |
||
| 249 | <td> |
||
| 250 | <label> |
||
| 251 | <input name="smbd_<?php echo esc_attr( $slug ); ?>_post_status" type="checkbox" |
||
| 252 | value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, $selected ); ?>> |
||
| 253 | <?php echo __( 'All', 'bulk-delete' ), ' ', esc_html( $value->label ), ' ', __( 'Posts', 'bulk-delete' ); ?> |
||
| 254 | </label> |
||
| 255 | </td> |
||
| 256 | </tr> |
||
| 257 | <?php |
||
| 258 | } |
||
| 259 | } |
||
| 260 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.