1 | <?php |
||
16 | class BD_Util { |
||
17 | // Meta boxes |
||
18 | const VISIBLE_POST_BOXES = 'metaboxhidden_toplevel_page_bulk-delete-posts'; |
||
19 | const VISIBLE_PAGE_BOXES = 'metaboxhidden_bulk-delete_page_bulk-delete-pages'; |
||
20 | const VISIBLE_USER_BOXES = 'metaboxhidden_bulk-delete_page_bulk-delete-users'; |
||
21 | |||
22 | /** |
||
23 | * Check whether the meta box in posts page is hidden or not. |
||
24 | * |
||
25 | * @static |
||
26 | * @access public |
||
27 | * |
||
28 | * @param string $box The name of the box |
||
29 | * |
||
30 | * @return bool True if the box is hidden, False otherwise |
||
31 | */ |
||
32 | public static function is_posts_box_hidden( $box ) { |
||
33 | $hidden_boxes = self::get_posts_hidden_boxes(); |
||
34 | |||
35 | return is_array( $hidden_boxes ) && in_array( $box, $hidden_boxes ); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Get the list of hidden boxes in posts page. |
||
40 | * |
||
41 | * @static |
||
42 | * @access public |
||
43 | * |
||
44 | * @return array The list of hidden meta boxes |
||
45 | */ |
||
46 | public static function get_posts_hidden_boxes() { |
||
47 | $current_user = wp_get_current_user(); |
||
48 | |||
49 | return get_user_meta( $current_user->ID, self::VISIBLE_POST_BOXES, true ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Check whether the meta box in pages page is hidden or not. |
||
54 | * |
||
55 | * @since 5.0 |
||
56 | * @static |
||
57 | * @access public |
||
58 | * |
||
59 | * @param string $box The name of the box to check |
||
60 | * |
||
61 | * @return bool True if the box is hidden, False otherwise |
||
62 | */ |
||
63 | public static function is_pages_box_hidden( $box ) { |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Get the list of hidden boxes in posts page. |
||
71 | * |
||
72 | * @since 5.0 |
||
73 | * @static |
||
74 | * @access public |
||
75 | * |
||
76 | * @return the array of hidden meta boxes |
||
77 | */ |
||
78 | public static function get_pages_hidden_boxes() { |
||
79 | $current_user = wp_get_current_user(); |
||
80 | |||
81 | return get_user_meta( $current_user->ID, self::VISIBLE_PAGE_BOXES, true ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Check whether the meta box in users page is hidden or not. |
||
86 | * |
||
87 | * @static |
||
88 | * @access public |
||
89 | * |
||
90 | * @param string $box The name of the box to check |
||
91 | * |
||
92 | * @return bool True if the box is hidden, False otherwise |
||
93 | */ |
||
94 | public static function is_users_box_hidden( $box ) { |
||
95 | $hidden_boxes = self::get_users_hidden_boxes(); |
||
96 | |||
97 | return is_array( $hidden_boxes ) && in_array( $box, $hidden_boxes ); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Get the list of hidden boxes in users page. |
||
102 | * |
||
103 | * @static |
||
104 | * @access public |
||
105 | * |
||
106 | * @return array The array of hidden meta boxes |
||
107 | */ |
||
108 | public static function get_users_hidden_boxes() { |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get the list of cron schedules. |
||
116 | * |
||
117 | * @static |
||
118 | * @access public |
||
119 | * |
||
120 | * @return array The list of cron schedules |
||
121 | */ |
||
122 | public static function get_cron_schedules() { |
||
123 | $cron_items = array(); |
||
124 | $cron = _get_cron_array(); |
||
125 | $date_format = _x( 'M j, Y @ G:i', 'Cron table date format', 'bulk-delete' ); |
||
126 | $i = 0; |
||
127 | |||
128 | foreach ( $cron as $timestamp => $cronhooks ) { |
||
129 | foreach ( (array) $cronhooks as $hook => $events ) { |
||
130 | if ( 'do-bulk-delete-' == substr( $hook, 0, 15 ) ) { |
||
131 | $cron_item = array(); |
||
132 | |||
133 | foreach ( (array) $events as $key => $event ) { |
||
134 | $cron_item['timestamp'] = $timestamp; |
||
135 | $cron_item['due'] = date_i18n( $date_format, $timestamp + ( get_option( 'gmt_offset' ) * 60 * 60 ) ); |
||
136 | $cron_item['schedule'] = $event['schedule']; |
||
137 | $cron_item['type'] = $hook; |
||
138 | $cron_item['args'] = $event['args']; |
||
139 | $cron_item['id'] = $i; |
||
140 | } |
||
141 | |||
142 | $cron_items[ $i ] = $cron_item; |
||
143 | $i++; |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | |||
148 | return $cron_items; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Generate display name from post type and status. |
||
153 | * |
||
154 | * @static |
||
155 | * |
||
156 | * @param string $str |
||
157 | * |
||
158 | * @return string Label |
||
159 | */ |
||
160 | public static function display_post_type_status( $str ) { |
||
161 | $type_status = self::split_post_type_status( $str ); |
||
162 | |||
163 | $status = $type_status['status']; |
||
164 | $type = $type_status['type']; |
||
165 | $label = ''; |
||
166 | |||
167 | switch ( $status ) { |
||
168 | case 'private': |
||
169 | $label = $type . ' - Private Posts'; |
||
170 | break; |
||
171 | case 'future': |
||
172 | $label = $type . ' - Scheduled Posts'; |
||
173 | break; |
||
174 | case 'draft': |
||
175 | $label = $type . ' - Draft Posts'; |
||
176 | break; |
||
177 | case 'pending': |
||
178 | $label = $type . ' - Pending Posts'; |
||
179 | break; |
||
180 | case 'publish': |
||
181 | $label = $type . ' - Published Posts'; |
||
182 | break; |
||
183 | } |
||
184 | |||
185 | return $label; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Split post type and status. |
||
190 | * |
||
191 | * @static |
||
192 | * @access public |
||
193 | * |
||
194 | * @param string $str |
||
195 | * |
||
196 | * @return array |
||
197 | */ |
||
198 | public static function split_post_type_status( $str ) { |
||
212 | } |
||
213 | } |
||
214 | |||
369 |