PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
← All changes | includes/recycle-bin/capture.php +37 -33 0.9.31.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Recycle Bin: capture.
3 + * OpenStation — Recycle Bin: capture.
4 4 *
5 5 * Stamps "who-deleted-what-when" metadata onto posts, pages, and
6 6 * comments as they pass through `wp_trash_post()` / `trashed_comment`,
7 7 * so the Recycle Bin window can show "deleted by Alice, 5 minutes ago"
@@ -11,18 +11,17 @@
11 11 * vanilla WordPress behavior (permanent-delete on first click). To
12 12 * enable trash for media, define `MEDIA_TRASH` as `true` in
13 13 * `wp-config.php`; the Recycle Bin window will surface trashed
14 14 * attachments automatically because `attachment` is in the default
15 - * `desktop_mode_recycle_bin_capture_post_types` list.
15 + * `openstation_recycle_bin_capture_post_types` list.
16 16 *
17 - * - `desktop_mode_recycle_bin_capture_post_types` controls which post
17 + * - `openstation_recycle_bin_capture_post_types` controls which post
18 18 * types we listen for in the first place.
19 - * - The `desktop_mode_recycle_bin_item_captured` action fires after a
19 + * - The `openstation_recycle_bin_item_captured` action fires after a
20 20 * successful capture so plugins can mirror the event (audit log,
21 21 * external storage, etc.).
22 22 *
23 - * @package WPDesktopMode
24 - * @since 0.6.0
23 + * @package OpenStation
25 24 */
26 25
27 26 defined( 'ABSPATH' ) || exit;
28 27
@@ -33,15 +32,30 @@
33 32 * here is consistency: every "deleted" thing flows through the same
34 33 * filter pipeline, so a plugin that wants a single audit log can
35 34 * subscribe once.
36 35 *
37 - * @since 0.6.0
36 + * Custom post types with an admin UI (`show_ui`, non-builtin) are
37 + * included by default — a trashed WooCommerce product or
38 + * portfolio entry belongs in the site-wide bin just as much as a
39 + * post does. Visibility stays safe because every row is still gated
40 + * per-item on `edit_post` before it is listed. Headless CPTs
41 + * (`show_ui => false`, e.g. the pinned-notes `wpd_note`) stay out
42 + * unless their owning feature opts in via the filter.
38 43 *
39 44 * @return string[]
40 45 */
41 -function desktop_mode_recycle_bin_capture_post_types() {
46 +function openstation_recycle_bin_capture_post_types() {
42 47 $types = array( 'post', 'page', 'attachment' );
43 48
49 + $custom = get_post_types(
50 + array(
51 + 'show_ui' => true,
52 + '_builtin' => false,
53 + ),
54 + 'names'
55 + );
56 + $types = array_merge( $types, array_values( (array) $custom ) );
57 +
44 58 /**
45 59 * Filter the post types the recycle bin tracks.
46 60 *
47 61 * Returning a list excluding `attachment` stops the bin from
@@ -46,16 +60,16 @@
46 60 *
47 61 * Returning a list excluding `attachment` stops the bin from
48 62 * stamping and listing trashed attachments; it does not change how
49 63 * WordPress deletes media (that is governed by `MEDIA_TRASH`).
64 + * Remove a custom post type here to keep its trash out of the bin,
65 + * or add a headless (`show_ui => false`) type to opt it in.
50 66 *
51 - * @since 0.6.0
52 - *
53 67 * @param string[] $types Post types whose deletions the recycle bin tracks.
54 68 */
55 - $types = apply_filters( 'desktop_mode_recycle_bin_capture_post_types', $types );
69 + $types = apply_filters( 'openstation_recycle_bin_capture_post_types', $types );
56 70
57 - return array_values( array_filter( array_map( 'strval', (array) $types ) ) );
71 + return array_values( array_unique( array_filter( array_map( 'strval', (array) $types ) ) ) );
58 72 }
59 73
60 74 /**
61 75 * Mirror the capture for posts/pages so the bin has a uniform record
@@ -64,36 +78,32 @@
64 78 * Core's `wp_trash_post_meta` is set on every trash but it doesn't
65 79 * include the user id — we stash that ourselves under a private meta
66 80 * key so the table can show "deleted by Alice".
67 81 *
68 - * @since 0.6.0
69 - *
70 82 * @param int $post_id Post being trashed.
71 83 */
72 -function desktop_mode_recycle_bin_on_trash_post( $post_id ) {
84 +function openstation_recycle_bin_on_trash_post( $post_id ) {
73 85 $post = get_post( $post_id );
74 86 if ( ! $post ) {
75 87 return;
76 88 }
77 - if ( ! in_array( $post->post_type, desktop_mode_recycle_bin_capture_post_types(), true ) ) {
89 + if ( ! in_array( $post->post_type, openstation_recycle_bin_capture_post_types(), true ) ) {
78 90 return;
79 91 }
80 - desktop_mode_recycle_bin_record_capture( $post_id );
92 + openstation_recycle_bin_record_capture( $post_id );
81 93 }
82 94
83 95 /**
84 96 * Persist who-deleted-what-when metadata for a single item.
85 97 *
86 - * Stored under `_desktop_mode_trash_*` postmeta on the trashed post itself —
98 + * Stored under `_openstation_trash_*` postmeta on the trashed post itself —
87 99 * survives un-trash naturally because we only consult it while in the
88 100 * bin, and gets cleaned up by core when the post is permanently
89 101 * deleted via the standard postmeta cascade.
90 102 *
91 - * @since 0.6.0
92 - *
93 103 * @param int $post_id Post id being captured.
94 104 */
95 -function desktop_mode_recycle_bin_record_capture( $post_id ) {
105 +function openstation_recycle_bin_record_capture( $post_id ) {
96 106 $user_id = get_current_user_id();
97 107 $now_gmt = current_time( 'mysql', true );
98 108
99 109 update_post_meta( $post_id, '_desktop_mode_trash_user_id', (int) $user_id );
@@ -104,32 +114,28 @@
104 114 *
105 115 * Use this to mirror the event into an external audit log or to
106 116 * extend the captured payload with custom postmeta.
107 117 *
108 - * @since 0.6.0
109 - *
110 118 * @param int $post_id Post id that was captured.
111 119 * @param int $user_id User id who triggered the capture.
112 120 * @param string $now_gmt MySQL-format GMT timestamp.
113 121 */
114 - do_action( 'desktop_mode_recycle_bin_item_captured', $post_id, $user_id, $now_gmt );
122 + do_action( 'openstation_recycle_bin_item_captured', $post_id, $user_id, $now_gmt );
115 123 }
116 124
117 -add_action( 'wp_trash_post', 'desktop_mode_recycle_bin_on_trash_post', 10, 1 );
125 +add_action( 'wp_trash_post', 'openstation_recycle_bin_on_trash_post', 10, 1 );
118 126
119 127 /**
120 128 * Capture deleted-by metadata for comments — symmetric to
121 - * `desktop_mode_recycle_bin_record_capture` but writing to `commentmeta`
129 + * `openstation_recycle_bin_record_capture` but writing to `commentmeta`
122 130 * instead of `postmeta`. Comments use `wp_set_comment_status('trash')`
123 131 * which fires `trashed_comment`; we don't need to short-circuit
124 132 * anything (core already routes to a real trash status), just
125 133 * stamp the moment so the bin can show "by Alice, 5 minutes ago".
126 134 *
127 - * @since 0.6.0
128 - *
129 135 * @param int $comment_id Comment about to be trashed.
130 136 */
131 -function desktop_mode_recycle_bin_on_trash_comment( $comment_id ) {
137 +function openstation_recycle_bin_on_trash_comment( $comment_id ) {
132 138 $comment_id = (int) $comment_id;
133 139 $user_id = get_current_user_id();
134 140 $now_gmt = current_time( 'mysql', true );
135 141
@@ -138,13 +144,11 @@
138 144
139 145 /**
140 146 * Fires after the recycle bin records a comment capture.
141 147 *
142 - * @since 0.6.0
143 - *
144 148 * @param int $comment_id Comment id that was captured.
145 149 * @param int $user_id User id who triggered the capture.
146 150 * @param string $now_gmt MySQL-format GMT timestamp.
147 151 */
148 - do_action( 'desktop_mode_recycle_bin_comment_captured', $comment_id, $user_id, $now_gmt );
152 + do_action( 'openstation_recycle_bin_comment_captured', $comment_id, $user_id, $now_gmt );
149 153 }
150 -add_action( 'trashed_comment', 'desktop_mode_recycle_bin_on_trash_comment', 10, 1 );
154 +add_action( 'trashed_comment', 'openstation_recycle_bin_on_trash_comment', 10, 1 );