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