Completed
Push — dev/6.0.0 ( 79f74e...ca9332 )
by Sudar
24:17 queued 20:56
created

Bulk_Delete_Misc::is_misc_box_hidden()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
rs 10
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();
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' ) );
0 ignored issues
show
Bug introduced by
Are you sure $bd->misc_page of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
		add_action( 'admin_print_scripts-' . /** @scrutinizer ignore-type */ $bd->misc_page, array( $bd, 'add_script' ) );
Loading history...
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
		// hooks
50
		add_action( 'bd_add_meta_box_for_misc'  , array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'add_delete_jetpack_messages_meta_box' ) );
51
		add_action( 'bd_delete_jetpack_messages', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'do_delete_jetpack_messages' ) );
52
53
		add_filter( 'bd_javascript_array', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'filter_js_array' ) );
54
		add_action( 'bd_delete_jetpack_messages_form', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'add_filtering_options' ) );
55
56
		add_filter( 'bd_delete_jetpack_messages_delete_options', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'process_filtering_options' ), 10, 2 );
57
		add_filter( 'bd_delete_jetpack_messages_can_delete', array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'can_delete' ), 10, 2 );
58
59
		// cron hooks
60
		add_action( Bulk_Delete_Jetpack_Contact_Form_Message::CRON_HOOK, array( 'Bulk_Delete_Jetpack_Contact_Form_Message', 'do_delete_jetpack_messages_cron' ), 10, 1 );
61
62
	}
63
64
	/**
65
	 * Add settings Panel for delete misc page.
66
	 *
67
	 * @static
68
	 *
69
	 * @since  5.3
70
	 */
71
	public static function add_delete_misc_settings_panel() {
72
		$bd = BULK_DELETE();
73
74
		/**
75
		 * Add contextual help for admin screens.
76
		 *
77
		 * @since 5.3
78
		 */
79
		do_action( 'bd_add_contextual_help', $bd->misc_page );
80
81
		/* Trigger the add_meta_boxes hooks to allow meta boxes to be added */
82
		do_action( 'add_meta_boxes_' . $bd->misc_page, null );
83
84
		/* Enqueue WordPress' script for handling the meta boxes */
85
		wp_enqueue_script( 'postbox' );
86
	}
87
88
	/**
89
	 * Register meta boxes for delete misc page.
90
	 *
91
	 * @static
92
	 *
93
	 * @since 5.3
94
	 */
95
	public static function add_delete_misc_meta_boxes() {
96
		/**
97
		 * Add meta box in misc page
98
		 * This hook can be used for adding additional meta boxes in *misc* page.
99
		 *
100
		 * @since 5.3
101
		 */
102
		do_action( 'bd_add_meta_box_for_misc' );
103
	}
104
105
	/**
106
	 * Show the delete misc page.
107
	 *
108
	 * @static
109
	 *
110
	 * @since 5.3
111
	 */
112
	public static function display_misc_page() {
113
?>
114
<div class="wrap">
115
    <h2><?php _e( 'Bulk Delete Miscellaneous Items', 'bulk-delete' );?></h2>
116
    <?php settings_errors(); ?>
117
118
    <form method = "post">
119
<?php
120
		// nonce for bulk delete
121
		wp_nonce_field( 'sm-bulk-delete-misc', 'sm-bulk-delete-misc-nonce' );
122
123
		/* Used to save closed meta boxes and their order */
124
		wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
125
		wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
126
?>
127
    <div id = "poststuff">
128
        <div id="post-body" class="metabox-holder columns-1">
129
130
            <div class="notice notice-warning">
131
                <p><strong><?php _e( 'WARNING: Posts deleted once cannot be retrieved back. Use with caution.', 'bulk-delete' ); ?></strong></p>
132
            </div>
133
134
            <div id="postbox-container-2" class="postbox-container">
135
                <?php do_meta_boxes( '', 'advanced', null ); ?>
136
            </div> <!-- #postbox-container-2 -->
137
138
        </div> <!-- #post-body -->
139
    </div><!-- #poststuff -->
140
    </form>
141
</div><!-- .wrap -->
142
143
<?php
144
		/**
145
		 * Runs just before displaying the footer text in the "Bulk Delete Misc" admin page.
146
		 *
147
		 * This action is primarily for adding extra content in the footer of "Bulk Delete Misc" admin page.
148
		 *
149
		 * @since 5.3
150
		 */
151
		do_action( 'bd_admin_footer_misc_page' );
152
	}
153
154
	/**
155
	 * Check whether the meta box in misc page is hidden or not.
156
	 *
157
	 * @static
158
	 * @access private
159
	 *
160
	 * @since  5.3
161
	 *
162
	 * @param string $box The name of the box to check
163
	 *
164
	 * @return bool True if the box is hidden, False otherwise
165
	 */
166
	public static function is_misc_box_hidden( $box ) {
167
		$hidden_boxes = self::get_misc_hidden_boxes();
168
169
		return is_array( $hidden_boxes ) && in_array( $box, $hidden_boxes );
170
	}
171
172
	/**
173
	 * Get the list of hidden boxes in misc page.
174
	 *
175
	 * @static
176
	 * @access private
177
	 *
178
	 * @since  5.3
179
	 *
180
	 * @return array The array of hidden meta boxes
181
	 */
182
	private static function get_misc_hidden_boxes() {
183
		$current_user = wp_get_current_user();
184
185
		return get_user_meta( $current_user->ID, self::VISIBLE_MISC_BOXES, true );
186
	}
187
}
188
189
// Modify admin footer
190
add_action( 'bd_admin_footer_misc_page', 'bd_modify_admin_footer' );
191
?>
192