sudar /
bulk-delete
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * Utility class for deleting Misc stuff. |
||||
| 4 | * |
||||
| 5 | * @since 5.3 |
||||
| 6 | * |
||||
| 7 | * @author Sudar |
||||
| 8 | * |
||||
| 9 | * @package BulkDelete\Misc |
||||
| 10 | */ |
||||
| 11 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
||||
| 12 | |||||
| 13 | class Bulk_Delete_Misc { |
||||
| 14 | /** |
||||
| 15 | * Slug for *misc* page. |
||||
| 16 | * |
||||
| 17 | * @since 5.3 |
||||
| 18 | */ |
||||
| 19 | const MISC_PAGE_SLUG = 'bulk-delete-misc'; |
||||
| 20 | |||||
| 21 | const VISIBLE_MISC_BOXES = 'metaboxhidden_bulk-delete_page_bulk-delete-misc'; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * Add *misc* menu. |
||||
| 25 | * |
||||
| 26 | * @static |
||||
| 27 | * |
||||
| 28 | * @since 5.3 |
||||
| 29 | */ |
||||
| 30 | public static function add_menu() { |
||||
| 31 | $bd = BULK_DELETE(); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 32 | |||||
| 33 | $bd->misc_page = add_submenu_page( |
||||
| 34 | Bulk_Delete::POSTS_PAGE_SLUG, |
||||
| 35 | __( 'Bulk Delete Miscellaneous Items', 'bulk-delete' ), |
||||
| 36 | __( 'Bulk Delete Misc', 'bulk-delete' ), |
||||
| 37 | 'delete_posts', |
||||
| 38 | self::MISC_PAGE_SLUG, |
||||
| 39 | array( __CLASS__, 'display_misc_page' ) |
||||
| 40 | ); |
||||
| 41 | |||||
| 42 | // enqueue JavaScript |
||||
| 43 | add_action( 'admin_print_scripts-' . $bd->misc_page, array( $bd, 'add_script' ) ); |
||||
| 44 | |||||
| 45 | // delete menus page |
||||
| 46 | add_action( "load-{$bd->misc_page}", array( __CLASS__, 'add_delete_misc_settings_panel' ) ); |
||||
| 47 | add_action( "add_meta_boxes_{$bd->misc_page}", array( __CLASS__, 'add_delete_misc_meta_boxes' ) ); |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | /** |
||||
| 51 | * Add settings Panel for delete misc page. |
||||
| 52 | * |
||||
| 53 | * @static |
||||
| 54 | * |
||||
| 55 | * @since 5.3 |
||||
| 56 | */ |
||||
| 57 | public static function add_delete_misc_settings_panel() { |
||||
| 58 | $bd = BULK_DELETE(); |
||||
|
0 ignored issues
–
show
The function
BULK_DELETE was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 59 | |||||
| 60 | /** |
||||
| 61 | * Add contextual help for admin screens. |
||||
| 62 | * |
||||
| 63 | * @since 5.3 |
||||
| 64 | */ |
||||
| 65 | do_action( 'bd_add_contextual_help', $bd->misc_page ); |
||||
| 66 | |||||
| 67 | /* Trigger the add_meta_boxes hooks to allow meta boxes to be added */ |
||||
| 68 | do_action( 'add_meta_boxes_' . $bd->misc_page, null ); |
||||
| 69 | |||||
| 70 | /* Enqueue WordPress' script for handling the meta boxes */ |
||||
| 71 | wp_enqueue_script( 'postbox' ); |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | /** |
||||
| 75 | * Register meta boxes for delete misc page. |
||||
| 76 | * |
||||
| 77 | * @static |
||||
| 78 | * |
||||
| 79 | * @since 5.3 |
||||
| 80 | */ |
||||
| 81 | public static function add_delete_misc_meta_boxes() { |
||||
| 82 | /** |
||||
| 83 | * Add meta box in misc page |
||||
| 84 | * This hook can be used for adding additional meta boxes in *misc* page. |
||||
| 85 | * |
||||
| 86 | * @since 5.3 |
||||
| 87 | */ |
||||
| 88 | do_action( 'bd_add_meta_box_for_misc' ); |
||||
| 89 | } |
||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * Show the delete misc page. |
||||
| 93 | * |
||||
| 94 | * @static |
||||
| 95 | * |
||||
| 96 | * @since 5.3 |
||||
| 97 | */ |
||||
| 98 | public static function display_misc_page() { |
||||
| 99 | ?> |
||||
| 100 | <div class="wrap"> |
||||
| 101 | <h2><?php _e( 'Bulk Delete Miscellaneous Items', 'bulk-delete' );?></h2> |
||||
| 102 | <?php settings_errors(); ?> |
||||
| 103 | |||||
| 104 | <form method = "post"> |
||||
| 105 | <?php |
||||
| 106 | // nonce for bulk delete |
||||
| 107 | wp_nonce_field( 'sm-bulk-delete-misc', 'sm-bulk-delete-misc-nonce' ); |
||||
| 108 | |||||
| 109 | /* Used to save closed meta boxes and their order */ |
||||
| 110 | wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); |
||||
| 111 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
||||
| 112 | ?> |
||||
| 113 | <div id = "poststuff"> |
||||
| 114 | <div id="post-body" class="metabox-holder columns-1"> |
||||
| 115 | |||||
| 116 | <div class="notice notice-warning"> |
||||
| 117 | <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p> |
||||
| 118 | </div> |
||||
| 119 | |||||
| 120 | <div id="postbox-container-2" class="postbox-container"> |
||||
| 121 | <?php do_meta_boxes( '', 'advanced', null ); ?> |
||||
| 122 | </div> <!-- #postbox-container-2 --> |
||||
| 123 | |||||
| 124 | </div> <!-- #post-body --> |
||||
| 125 | </div><!-- #poststuff --> |
||||
| 126 | </form> |
||||
| 127 | </div><!-- .wrap --> |
||||
| 128 | |||||
| 129 | <?php |
||||
| 130 | /** |
||||
| 131 | * Runs just before displaying the footer text in the "Bulk Delete Misc" admin page. |
||||
| 132 | * |
||||
| 133 | * This action is primarily for adding extra content in the footer of "Bulk Delete Misc" admin page. |
||||
| 134 | * |
||||
| 135 | * @since 5.3 |
||||
| 136 | */ |
||||
| 137 | do_action( 'bd_admin_footer_misc_page' ); |
||||
| 138 | } |
||||
| 139 | |||||
| 140 | /** |
||||
| 141 | * Check whether the meta box in misc page is hidden or not. |
||||
| 142 | * |
||||
| 143 | * @static |
||||
| 144 | * @access private |
||||
| 145 | * |
||||
| 146 | * @since 5.3 |
||||
| 147 | * |
||||
| 148 | * @param string $box The name of the box to check |
||||
| 149 | * |
||||
| 150 | * @return bool True if the box is hidden, False otherwise |
||||
| 151 | */ |
||||
| 152 | public static function is_misc_box_hidden( $box ) { |
||||
| 153 | $hidden_boxes = self::get_misc_hidden_boxes(); |
||||
| 154 | |||||
| 155 | return is_array( $hidden_boxes ) && in_array( $box, $hidden_boxes ); |
||||
| 156 | } |
||||
| 157 | |||||
| 158 | /** |
||||
| 159 | * Get the list of hidden boxes in misc page. |
||||
| 160 | * |
||||
| 161 | * @static |
||||
| 162 | * @access private |
||||
| 163 | * |
||||
| 164 | * @since 5.3 |
||||
| 165 | * |
||||
| 166 | * @return array The array of hidden meta boxes |
||||
| 167 | */ |
||||
| 168 | private static function get_misc_hidden_boxes() { |
||||
| 169 | $current_user = wp_get_current_user(); |
||||
| 170 | |||||
| 171 | return get_user_meta( $current_user->ID, self::VISIBLE_MISC_BOXES, true ); |
||||
| 172 | } |
||||
| 173 | } |
||||
| 174 | |||||
| 175 | // Add menu |
||||
| 176 | 1 | add_action( 'bd_after_primary_menus', array( 'Bulk_Delete_Misc', 'add_menu' ) ); |
|||
| 177 | |||||
| 178 | // Modify admin footer |
||||
| 179 | 1 | add_action( 'bd_admin_footer_misc_page', 'bd_modify_admin_footer' ); |
|||
| 180 | ?> |
||||
| 181 |