Bulk_Delete_Misc::add_menu()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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