PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.4.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.4.2
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 / views / admin / docs-ui / classic-partials / list.php

list.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.4.2, at views/admin/docs-ui/classic-partials/list.php

314 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use WPDeveloper\BetterDocs\Admin\PostsTable;
3
4 // return;
5 global $wpdb;
6
7 set_current_screen( 'edit-docs' );
8 add_filter( 'screen_options_show_screen', '__return_true' );
9 global $post_type, $post_type_object, $typenow, $per_page;
10 $post_type = 'docs';
11 $wp_list_table = _get_list_table( 'WP_List_Table' );
12 $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
13 $wp_list_table = new PostsTable();
14 $pagenum = $wp_list_table->get_pagenum();
15 $post_type_object = get_post_type_object( $post_type );
16
17 if ( 'post' !== $post_type ) {
18 $parent_file = "edit.php?post_type=$post_type";
19 $submenu_file = "edit.php?post_type=$post_type";
20 $post_new_file = "post-new.php?post_type=$post_type";
21 } else {
22 $parent_file = 'edit.php';
23 $submenu_file = 'edit.php';
24 $post_new_file = 'post-new.php';
25 }
26
27 $doaction = $wp_list_table->current_action();
28
29 if ( $doaction ) {
30 check_admin_referer( 'bulk-posts' );
31
32 $sendback = remove_query_arg( ['trashed', 'untrashed', 'deleted', 'locked', 'ids'], wp_get_referer() );
33 if ( ! $sendback ) {
34 $sendback = admin_url( $parent_file );
35 }
36 $sendback = add_query_arg( 'paged', $pagenum, $sendback );
37 if ( strpos( $sendback, 'post.php' ) !== false ) {
38 $sendback = admin_url( $post_new_file );
39 }
40
41 if ( 'delete_all' === $doaction ) {
42 // Prepare for deletion of all posts with a specified post status (i.e. Empty Trash).
43 $post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] );
44 // Validate the post status exists.
45 if ( get_post_status_object( $post_status ) ) {
46 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
47 }
48 $doaction = 'delete';
49 } elseif ( isset( $_REQUEST['media'] ) ) {
50 $post_ids = $_REQUEST['media'];
51 } elseif ( isset( $_REQUEST['ids'] ) ) {
52 $post_ids = explode( ',', $_REQUEST['ids'] );
53 } elseif ( ! empty( $_REQUEST['post'] ) ) {
54 $post_ids = array_map( 'intval', $_REQUEST['post'] );
55 }
56
57 if ( ! isset( $post_ids ) ) {
58 wp_redirect( $sendback );
59 exit;
60 }
61
62 switch ( $doaction ) {
63 case 'trash':
64 $trashed = 0;
65 $locked = 0;
66
67 foreach ( (array) $post_ids as $post_id ) {
68 if ( ! current_user_can( 'delete_post', $post_id ) ) {
69 wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
70 }
71
72 if ( wp_check_post_lock( $post_id ) ) {
73 $locked++;
74 continue;
75 }
76
77 if ( ! wp_trash_post( $post_id ) ) {
78 wp_die( __( 'Error in moving the item to Trash.' ) );
79 }
80
81 $trashed++;
82 }
83
84 $sendback = add_query_arg(
85 [
86 'trashed' => $trashed,
87 'ids' => implode( ',', $post_ids ),
88 'locked' => $locked
89 ],
90 $sendback
91 );
92 break;
93 case 'untrash':
94 $untrashed = 0;
95
96 if ( isset( $_GET['doaction'] ) && ( 'undo' === $_GET['doaction'] ) ) {
97 add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
98 }
99
100 foreach ( (array) $post_ids as $post_id ) {
101 if ( ! current_user_can( 'delete_post', $post_id ) ) {
102 wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
103 }
104
105 if ( ! wp_untrash_post( $post_id ) ) {
106 wp_die( __( 'Error in restoring the item from Trash.' ) );
107 }
108
109 $untrashed++;
110 }
111 $sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
112
113 remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10 );
114
115 break;
116 case 'delete':
117 $deleted = 0;
118 foreach ( (array) $post_ids as $post_id ) {
119 $post_del = get_post( $post_id );
120
121 if ( ! current_user_can( 'delete_post', $post_id ) ) {
122 wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
123 }
124
125 if ( 'attachment' === $post_del->post_type ) {
126 if ( ! wp_delete_attachment( $post_id ) ) {
127 wp_die( __( 'Error in deleting the attachment.' ) );
128 }
129 } else {
130 if ( ! wp_delete_post( $post_id ) ) {
131 wp_die( __( 'Error in deleting the item.' ) );
132 }
133 }
134 $deleted++;
135 }
136 $sendback = add_query_arg( 'deleted', $deleted, $sendback );
137 break;
138 case 'edit':
139 if ( isset( $_REQUEST['bulk_edit'] ) ) {
140 $done = bulk_edit_posts( $_REQUEST );
141
142 if ( is_array( $done ) ) {
143 $done['updated'] = count( $done['updated'] );
144 $done['skipped'] = count( $done['skipped'] );
145 $done['locked'] = count( $done['locked'] );
146 $sendback = add_query_arg( $done, $sendback );
147 }
148 }
149 break;
150 default:
151 $screen = get_current_screen()->id;
152
153 /**
154 * Fires when a custom bulk action should be handled.
155 *
156 * The redirect link should be modified with success or failure feedback
157 * from the action to be used to display feedback to the user.
158 *
159 * The dynamic portion of the hook name, `$screen`, refers to the current screen ID.
160 *
161 * @since 4.7.0
162 *
163 * @param string $sendback The redirect URL.
164 * @param string $doaction The action being taken.
165 * @param array $items The items to take the action on. Accepts an array of IDs of posts,
166 * comments, terms, links, plugins, attachments, or users.
167 */
168 $sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $doaction, $post_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
169 break;
170 }
171
172 $sendback = remove_query_arg( ['action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'], $sendback );
173
174 wp_redirect( $sendback );
175 exit;
176 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
177 wp_redirect( remove_query_arg( ['_wp_http_referer', '_wpnonce'], wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
178 exit;
179 }
180
181 $wp_list_table->prepare_items();
182
183 wp_enqueue_script( 'inline-edit-post' );
184 wp_enqueue_script( 'heartbeat' );
185
186 if ( 'wp_block' === $post_type ) {
187 wp_enqueue_script( 'wp-list-reusable-blocks' );
188 wp_enqueue_style( 'wp-list-reusable-blocks' );
189 }
190
191 $title = $post_type_object->labels->name;
192
193 get_current_screen()->set_screen_reader_content(
194 [
195 'heading_views' => $post_type_object->labels->filter_items_list,
196 'heading_pagination' => $post_type_object->labels->items_list_navigation,
197 'heading_list' => $post_type_object->labels->items_list
198 ]
199 );
200
201 add_screen_option(
202 'per_page',
203 [
204 'default' => 20,
205 'option' => 'edit_' . $post_type . '_per_page'
206 ]
207 );
208
209 $bulk_counts = [
210 'updated' => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0,
211 'locked' => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0,
212 'deleted' => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0,
213 'trashed' => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0,
214 'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0
215 ];
216
217 $bulk_messages = [];
218 $bulk_messages['post'] = [
219 /* translators: %s: Number of posts. */
220 'updated' => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
221 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
222 /* translators: %s: Number of posts. */
223 _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
224 /* translators: %s: Number of posts. */
225 'deleted' => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
226 /* translators: %s: Number of posts. */
227 'trashed' => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
228 /* translators: %s: Number of posts. */
229 'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] )
230 ];
231 $bulk_messages['page'] = [
232 /* translators: %s: Number of pages. */
233 'updated' => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
234 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
235 /* translators: %s: Number of pages. */
236 _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
237 /* translators: %s: Number of pages. */
238 'deleted' => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
239 /* translators: %s: Number of pages. */
240 'trashed' => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
241 /* translators: %s: Number of pages. */
242 'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] )
243 ];
244 $bulk_messages['wp_block'] = [
245 /* translators: %s: Number of blocks. */
246 'updated' => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'] ),
247 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
248 /* translators: %s: Number of blocks. */
249 _n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'] ),
250 /* translators: %s: Number of blocks. */
251 'deleted' => _n( '%s block permanently deleted.', '%s blocks permanently deleted.', $bulk_counts['deleted'] ),
252 /* translators: %s: Number of blocks. */
253 'trashed' => _n( '%s block moved to the Trash.', '%s blocks moved to the Trash.', $bulk_counts['trashed'] ),
254 /* translators: %s: Number of blocks. */
255 'untrashed' => _n( '%s block restored from the Trash.', '%s blocks restored from the Trash.', $bulk_counts['untrashed'] )
256 ];
257
258 /**
259 * Filters the bulk action updated messages.
260 *
261 * By default, custom post types use the messages for the 'post' post type.
262 *
263 * @since 3.7.0
264 *
265 * @param array[] $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
266 * keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
267 * @param int[] $bulk_counts Array of item counts for each message, used to build internationalized strings.
268 */
269 $bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
270 $bulk_counts = array_filter( $bulk_counts );
271
272 // If we have a bulk message to issue:
273 $messages = [];
274 foreach ( $bulk_counts as $message => $count ) {
275 if ( isset( $bulk_messages[$post_type][$message] ) ) {
276 $messages[] = sprintf( $bulk_messages[$post_type][$message], number_format_i18n( $count ) );
277 } elseif ( isset( $bulk_messages['post'][$message] ) ) {
278 $messages[] = sprintf( $bulk_messages['post'][$message], number_format_i18n( $count ) );
279 }
280
281 if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) {
282 $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
283 $messages[] = '<a href="' . esc_url( wp_nonce_url( "admin.php?page=betterdocs-admin&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
284 }
285
286 if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
287 $ids = explode( ',', $_REQUEST['ids'] );
288
289 if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) {
290 $messages[] = sprintf(
291 '<a href="%1$s">%2$s</a>',
292 esc_url( get_edit_post_link( $ids[0] ) ),
293 esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item )
294 );
295 }
296 }
297 }
298
299 if ( $messages ) {
300 echo '<div id="message" class="updated notice is-dismissible"><p>' . implode( ' ', $messages ) . '</p></div>';
301 }
302 unset( $messages );
303
304 $_SERVER['REQUEST_URI'] = remove_query_arg( ['locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed'], $_SERVER['REQUEST_URI'] );
305
306 $wp_list_table->display();
307
308 if ( $wp_list_table->has_items() ) {
309 $wp_list_table->inline_edit();
310 }
311 ?>
312 <div id="ajax-response"></div>
313 <div class="clear"></div>
314