PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.0.14
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.0.14
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / admin / partials / betterdocs-admin-screen.php

betterdocs-admin-screen.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.0.14, at admin/partials/betterdocs-admin-screen.php

390 lines 23.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 global $wpdb;
3
4 set_current_screen('edit-docs');
5 add_filter( 'screen_options_show_screen', '__return_true' );
6 global $post_type, $post_type_object, $typenow;
7 $post_type = 'docs';
8 $wp_list_table = _get_list_table( 'WP_List_Table' );
9 $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
10 $wp_list_table = new BetterDocs_WP_Posts_List_Table();
11 $pagenum = $wp_list_table->get_pagenum();
12 $post_type_object = get_post_type_object( $post_type );
13 ?>
14 <div class="wrap">
15 <hr class="wp-header-end">
16 <div class="betterdocs-listing-wrapper">
17 <?php do_action('betterdocs_listing_header'); ?>
18 </div>
19 <div class="tabs-content">
20 <div class="betterdocs-tab-content tab-content-1">
21 <div class="betterdocs-settings-header betterdocs-settings-filter">
22 <div class="betterdocs-header-full">
23 <div class="betterdocs-header-filter">
24 <?php
25 global $wp;
26 $form_action = home_url( $wp->request ) . '/wp-admin/admin.php';
27 ?>
28 <form id="posts-filter" method="get" action="<?php echo $form_action; ?>">
29 <input type="hidden" name="page" class="post_type_page" value="betterdocs-admin" />
30 <input id="post-search-input" class="dashboard-search-field" type="text" placeholder="<?php esc_html_e('Search', 'betterdocs'); ?>" name="s" value="<?php echo (isset($_REQUEST['s'])) ? esc_attr($_REQUEST['s']) : '' ?>">
31 <?php $order = (isset($_GET['order'])) ? $_GET['order'] : ''; ?>
32 <select id="dashboard-select-order" class="dashboard-search-field dashboard-select-order" name="order">
33 <option value=""><?php esc_html_e('Order', 'betterdocs') ?></option>
34 <option value="ASC"<?php echo ('ASC' === $order) ? ' selected' : '' ?>><?php esc_html_e('Ascending', 'betterdocs') ?></option>
35 <option value="DESC"<?php echo ('DESC' === $order) ? ' selected' : '' ?>><?php esc_html_e('Descending', 'betterdocs') ?></option>
36 </select>
37 <?php $date = (isset($_GET['date'])) ? $_GET['date'] : ''; ?>
38 <select id="dashboard-select-date" class="dashboard-search-field dashboard-select-date" name="date">
39 <option value=""><?php esc_html_e('All Dates', 'betterdocs') ?></option>
40 <option value="most_recent"<?php echo ('most_recent' === $date) ? ' selected' : '' ?>><?php esc_html_e('Most Recent', 'betterdocs') ?></option>
41 <option value="least_recent"<?php echo ('least_recent' === $date) ? ' selected' : '' ?>><?php esc_html_e('Least Recent', 'betterdocs') ?></option>
42 <option value="custom_date"<?php echo ('custom_date' === $date) ? ' selected' : '' ?>><?php esc_html_e('Custom', 'betterdocs') ?></option>
43 </select>
44 <input id="reportrange" class="dashboard-select-date-custom" type="text" name="date_range" title="<?php echo (isset($_GET['date_range'])) ? esc_attr($_GET['date_range']) : ''; ?>" value="<?php echo (isset($_GET['date_range'])) ? esc_attr($_GET['date_range']) : ''; ?>" />
45 <select id="dashboard-select-author" class="dashboard-search-field dashboard-select-author" name="author">
46 <option value="all"><?php esc_html_e('All Authors', 'betterdocs') ?></option>
47 <?php
48 $author = (isset($_GET['author'])) ? $_GET['author'] : '';
49 $users = get_users();
50 foreach ($users as $user) {
51 ?>
52 <option value="<?php echo esc_attr($user->data->ID) ?>"<?php echo ($author == $user->data->ID) ? " selected" : "" ?>><?php echo $user->data->display_name ?></option>
53 <?php
54 }
55 ?>
56 </select>
57 <select id="dashboard-select-doc_category" class="dashboard-search-field dashboard-select-category" name="doc_category">
58 <option value="all"><?php esc_html_e('All Categories', 'betterdocs') ?></option>
59 <?php
60 $selected = (isset($_GET['doc_category'])) ? $_GET['doc_category'] : '';
61 echo BetterDocs_Helper::term_options('doc_category', $selected);
62 ?>
63 </select>
64 <?php do_action('betterdocs_admin_filter_after_category'); ?>
65 <?php $post_status = (isset($_GET['post_status'])) ? $_GET['post_status'] : ''; ?>
66 <select id="dashboard-select-status" class="dashboard-search-field dashboard-select-status" name="post_status">
67 <option value="any"<?php echo ('any' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Doc Status', 'betterdocs') ?></option>
68 <option value="publish"<?php echo ('publish' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Publish', 'betterdocs') ?></option>
69 <option value="pending"<?php echo ('pending' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Pending', 'betterdocs') ?></option>
70 <option value="draft"<?php echo ('draft' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Draft', 'betterdocs') ?></option>
71 <option value="auto-draft"<?php echo ('auto-draft' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Auto Draft', 'betterdocs') ?></option>
72 <option value="future"<?php echo ('future' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Future', 'betterdocs') ?></option>
73 <option value="private"<?php echo ('private' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Private', 'betterdocs') ?></option>
74 <option value="inherit"<?php echo ('inherit' === $post_status) ? ' selected' : '' ?>><?php esc_html_e('Inherit', 'betterdocs') ?></option>
75 </select>
76 <?php do_action('betterdocs_admin_filter_before_submit'); ?>
77 <input class="betterdocs-button betterdocs-button-primary betterdocs-search-filter-btn" type="submit" id="search-submit" class="button" value="<?php esc_html_e('Search','betterdocs') ?>">
78 </form>
79 </div>
80 </div>
81 </div>
82 <div class="betterdocs-listing-table-content">
83 <?php
84 if ( 'post' !== $post_type ) {
85 $parent_file = "edit.php?post_type=$post_type";
86 $submenu_file = "edit.php?post_type=$post_type";
87 $post_new_file = "post-new.php?post_type=$post_type";
88 } else {
89 $parent_file = 'edit.php';
90 $submenu_file = 'edit.php';
91 $post_new_file = 'post-new.php';
92 }
93
94 $doaction = $wp_list_table->current_action();
95
96 if ( $doaction ) {
97 check_admin_referer( 'bulk-posts' );
98
99 $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids' ), wp_get_referer() );
100 if ( ! $sendback ) {
101 $sendback = admin_url( $parent_file );
102 }
103 $sendback = add_query_arg( 'paged', $pagenum, $sendback );
104 if ( strpos( $sendback, 'post.php' ) !== false ) {
105 $sendback = admin_url( $post_new_file );
106 }
107
108 if ( 'delete_all' === $doaction ) {
109 // Prepare for deletion of all posts with a specified post status (i.e. Empty Trash).
110 $post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] );
111 // Validate the post status exists.
112 if ( get_post_status_object( $post_status ) ) {
113 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
114 }
115 $doaction = 'delete';
116 } elseif ( isset( $_REQUEST['media'] ) ) {
117 $post_ids = $_REQUEST['media'];
118 } elseif ( isset( $_REQUEST['ids'] ) ) {
119 $post_ids = explode( ',', $_REQUEST['ids'] );
120 } elseif ( ! empty( $_REQUEST['post'] ) ) {
121 $post_ids = array_map( 'intval', $_REQUEST['post'] );
122 }
123
124 if ( ! isset( $post_ids ) ) {
125 wp_redirect( $sendback );
126 exit;
127 }
128
129 switch ( $doaction ) {
130 case 'trash':
131 $trashed = 0;
132 $locked = 0;
133
134 foreach ( (array) $post_ids as $post_id ) {
135 if ( ! current_user_can( 'delete_post', $post_id ) ) {
136 wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
137 }
138
139 if ( wp_check_post_lock( $post_id ) ) {
140 $locked++;
141 continue;
142 }
143
144 if ( ! wp_trash_post( $post_id ) ) {
145 wp_die( __( 'Error in moving the item to Trash.' ) );
146 }
147
148 $trashed++;
149 }
150
151 $sendback = add_query_arg(
152 array(
153 'trashed' => $trashed,
154 'ids' => implode( ',', $post_ids ),
155 'locked' => $locked,
156 ),
157 $sendback
158 );
159 break;
160 case 'untrash':
161 $untrashed = 0;
162
163 if ( isset( $_GET['doaction'] ) && ( 'undo' === $_GET['doaction'] ) ) {
164 add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
165 }
166
167 foreach ( (array) $post_ids as $post_id ) {
168 if ( ! current_user_can( 'delete_post', $post_id ) ) {
169 wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
170 }
171
172 if ( ! wp_untrash_post( $post_id ) ) {
173 wp_die( __( 'Error in restoring the item from Trash.' ) );
174 }
175
176 $untrashed++;
177 }
178 $sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
179
180 remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
181
182 break;
183 case 'delete':
184 $deleted = 0;
185 foreach ( (array) $post_ids as $post_id ) {
186 $post_del = get_post( $post_id );
187
188 if ( ! current_user_can( 'delete_post', $post_id ) ) {
189 wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
190 }
191
192 if ( 'attachment' === $post_del->post_type ) {
193 if ( ! wp_delete_attachment( $post_id ) ) {
194 wp_die( __( 'Error in deleting the attachment.' ) );
195 }
196 } else {
197 if ( ! wp_delete_post( $post_id ) ) {
198 wp_die( __( 'Error in deleting the item.' ) );
199 }
200 }
201 $deleted++;
202 }
203 $sendback = add_query_arg( 'deleted', $deleted, $sendback );
204 break;
205 case 'edit':
206 if ( isset( $_REQUEST['bulk_edit'] ) ) {
207 $done = bulk_edit_posts( $_REQUEST );
208
209 if ( is_array( $done ) ) {
210 $done['updated'] = count( $done['updated'] );
211 $done['skipped'] = count( $done['skipped'] );
212 $done['locked'] = count( $done['locked'] );
213 $sendback = add_query_arg( $done, $sendback );
214 }
215 }
216 break;
217 default:
218 $screen = get_current_screen()->id;
219
220 /**
221 * Fires when a custom bulk action should be handled.
222 *
223 * The redirect link should be modified with success or failure feedback
224 * from the action to be used to display feedback to the user.
225 *
226 * The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
227 *
228 * @since 4.7.0
229 *
230 * @param string $sendback The redirect URL.
231 * @param string $doaction The action being taken.
232 * @param array $items The items to take the action on. Accepts an array of IDs of posts,
233 * comments, terms, links, plugins, attachments, or users.
234 */
235 $sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $doaction, $post_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
236 break;
237 }
238
239 $sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view' ), $sendback );
240
241 wp_redirect( $sendback );
242 exit;
243 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
244 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
245 exit;
246 }
247
248 $wp_list_table->prepare_items();
249
250 wp_enqueue_script( 'inline-edit-post' );
251 wp_enqueue_script( 'heartbeat' );
252
253 if ( 'wp_block' === $post_type ) {
254 wp_enqueue_script( 'wp-list-reusable-blocks' );
255 wp_enqueue_style( 'wp-list-reusable-blocks' );
256 }
257
258 $title = $post_type_object->labels->name;
259
260 get_current_screen()->set_screen_reader_content(
261 array(
262 'heading_views' => $post_type_object->labels->filter_items_list,
263 'heading_pagination' => $post_type_object->labels->items_list_navigation,
264 'heading_list' => $post_type_object->labels->items_list,
265 )
266 );
267
268 add_screen_option(
269 'per_page',
270 array(
271 'default' => 20,
272 'option' => 'edit_' . $post_type . '_per_page',
273 )
274 );
275
276 $bulk_counts = array(
277 'updated' => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0,
278 'locked' => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0,
279 'deleted' => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0,
280 'trashed' => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0,
281 'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0,
282 );
283
284 $bulk_messages = array();
285 $bulk_messages['post'] = array(
286 /* translators: %s: Number of posts. */
287 'updated' => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
288 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
289 /* translators: %s: Number of posts. */
290 _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
291 /* translators: %s: Number of posts. */
292 'deleted' => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
293 /* translators: %s: Number of posts. */
294 'trashed' => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
295 /* translators: %s: Number of posts. */
296 'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ),
297 );
298 $bulk_messages['page'] = array(
299 /* translators: %s: Number of pages. */
300 'updated' => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
301 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
302 /* translators: %s: Number of pages. */
303 _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
304 /* translators: %s: Number of pages. */
305 'deleted' => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
306 /* translators: %s: Number of pages. */
307 'trashed' => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
308 /* translators: %s: Number of pages. */
309 'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
310 );
311 $bulk_messages['wp_block'] = array(
312 /* translators: %s: Number of blocks. */
313 'updated' => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'] ),
314 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
315 /* translators: %s: Number of blocks. */
316 _n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'] ),
317 /* translators: %s: Number of blocks. */
318 'deleted' => _n( '%s block permanently deleted.', '%s blocks permanently deleted.', $bulk_counts['deleted'] ),
319 /* translators: %s: Number of blocks. */
320 'trashed' => _n( '%s block moved to the Trash.', '%s blocks moved to the Trash.', $bulk_counts['trashed'] ),
321 /* translators: %s: Number of blocks. */
322 'untrashed' => _n( '%s block restored from the Trash.', '%s blocks restored from the Trash.', $bulk_counts['untrashed'] ),
323 );
324
325 /**
326 * Filters the bulk action updated messages.
327 *
328 * By default, custom post types use the messages for the 'post' post type.
329 *
330 * @since 3.7.0
331 *
332 * @param array[] $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
333 * keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
334 * @param int[] $bulk_counts Array of item counts for each message, used to build internationalized strings.
335 */
336 $bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
337 $bulk_counts = array_filter( $bulk_counts );
338
339 ?>
340 <div class="wrap">
341 <?php
342 // If we have a bulk message to issue:
343 $messages = array();
344 foreach ( $bulk_counts as $message => $count ) {
345 if ( isset( $bulk_messages[ $post_type ][ $message ] ) ) {
346 $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) );
347 } elseif ( isset( $bulk_messages['post'][ $message ] ) ) {
348 $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
349 }
350
351 if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) {
352 $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
353 $messages[] = '<a href="' . esc_url( wp_nonce_url( "admin.php?page=betterdocs-admin&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
354 }
355
356 if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
357 $ids = explode( ',', $_REQUEST['ids'] );
358
359 if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) {
360 $messages[] = sprintf(
361 '<a href="%1$s">%2$s</a>',
362 esc_url( get_edit_post_link( $ids[0] ) ),
363 esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item )
364 );
365 }
366 }
367 }
368
369 if ( $messages ) {
370 echo '<div id="message" class="updated notice is-dismissible"><p>' . implode( ' ', $messages ) . '</p></div>';
371 }
372 unset( $messages );
373
374 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
375
376 $wp_list_table->display();
377
378 if ( $wp_list_table->has_items() ) {
379 $wp_list_table->inline_edit();
380 }
381
382 ?>
383 <div id="ajax-response"></div>
384 <div class="clear" /></div>
385 </div>
386 </div>
387 </div>
388 <?php do_action('betterdocs_sorting_grid_view'); ?>
389 </div>
390 </div>