| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Cascade cleanup of placements on entity trash. | |
| 3 | + * OpenStation — Cascade cleanup of placements on entity trash. | |
| 4 | 4 | * |
| 5 | 5 | * When a WordPress entity that a desktop shortcut points at is |
| 6 | 6 | * trashed or deleted, the matching placement rows are soft-trashed |
| 7 | 7 | * so the wallpaper stops painting tiles that resolve to nothing. |
| @@ -31,10 +31,9 @@ | ||
| 31 | 31 | * in the table. The placement surfaces in the Recycle Bin and the |
| 32 | 32 | * user can restore it from there (independent of the source entity's |
| 33 | 33 | * trash status — restoring a post does NOT auto-restore its shortcut). |
| 34 | 34 | * |
| 35 | - * @package WPDesktopMode | |
| 36 | - * @since 0.22.0 | |
| 35 | + * @package OpenStation | |
| 37 | 36 | */ |
| 38 | 37 | |
| 39 | 38 | defined( 'ABSPATH' ) || exit; |
| 40 | 39 | |
| @@ -43,9 +42,9 @@ | ||
| 43 | 42 | * |
| 44 | 43 | * Iterates `wp_desktop_mode_file_placements` for rows with the |
| 45 | 44 | * matching `file_type` + `file_ref` whose `trashed_at_ms` is |
| 46 | 45 | * unset, and stamps the trash columns. Each affected placement |
| 47 | - * fires `desktop_mode_files_after_cascade_trash_placement` so | |
| 46 | + * fires `openstation_files_after_cascade_trash_placement` so | |
| 48 | 47 | * plugins (and the live UI refresh path) can react. |
| 49 | 48 | * |
| 50 | 49 | * Idempotent: re-running with an already-trashed entity is a |
| 51 | 50 | * no-op because the `trashed_at_ms IS NULL` filter excludes |
| @@ -55,18 +54,16 @@ | ||
| 55 | 54 | * placements across many users — the affected placement count |
| 56 | 55 | * is unbounded by the API but bounded in practice by the number |
| 57 | 56 | * of users who shortcutted the same entity. |
| 58 | 57 | * |
| 59 | - * @since 0.22.0 | |
| 60 | - * | |
| 61 | 58 | * @param string $file_type File-type slug — `'post'`, |
| 62 | 59 | * `'attachment'`, `'user'`, plugin- |
| 63 | 60 | * defined. Must match |
| 64 | - * {@see Desktop_Mode_File::type()}. | |
| 61 | + * {@see OpenStation_File::type()}. | |
| 65 | 62 | * @param string|int $file_ref Entity ref (post id, user id, …). |
| 66 | 63 | * @return int Number of placements soft-trashed. |
| 67 | 64 | */ |
| 68 | -function desktop_mode_files_cascade_trash_placements_for_entity( $file_type, $file_ref ) { | |
| 65 | +function openstation_files_cascade_trash_placements_for_entity( $file_type, $file_ref ) { | |
| 69 | 66 | global $wpdb; |
| 70 | 67 | $file_type = (string) $file_type; |
| 71 | 68 | $file_ref = (string) $file_ref; |
| 72 | 69 | if ( '' === $file_type || '' === $file_ref ) { |
| @@ -71,9 +68,9 @@ | ||
| 71 | 68 | $file_ref = (string) $file_ref; |
| 72 | 69 | if ( '' === $file_type || '' === $file_ref ) { |
| 73 | 70 | return 0; |
| 74 | 71 | } |
| 75 | - $tables = desktop_mode_files_table_names(); | |
| 72 | + $tables = openstation_files_table_names(); | |
| 76 | 73 | |
| 77 | 74 | // SELECT the affected rows up front so we can fire a per-row |
| 78 | 75 | // action without a second roundtrip. Restrict to live (not yet |
| 79 | 76 | // trashed) placements — the cascade is idempotent and we don't |
| @@ -94,14 +91,14 @@ | ||
| 94 | 91 | if ( empty( $rows ) ) { |
| 95 | 92 | return 0; |
| 96 | 93 | } |
| 97 | 94 | |
| 98 | - $now = desktop_mode_files_now_ms(); | |
| 95 | + $now = openstation_files_now_ms(); | |
| 99 | 96 | $trashed = 0; |
| 100 | 97 | foreach ( $rows as $row ) { |
| 101 | 98 | $placement_id = (int) $row['id']; |
| 102 | 99 | $owner_id = (int) $row['owner_id']; |
| 103 | - $ancestry = desktop_mode_files_capture_ancestry( (int) $row['parent_id'] ); | |
| 100 | + $ancestry = openstation_files_capture_ancestry( (int) $row['parent_id'] ); | |
| 104 | 101 | // `trashed_meta` carries the ancestry (so a restore knows |
| 105 | 102 | // where to put the tile back) plus a cascade marker so the |
| 106 | 103 | // recycle-bin UI can distinguish entity-cascade rows from |
| 107 | 104 | // user-initiated trashes if a plugin ever wants to render |
| @@ -115,9 +112,9 @@ | ||
| 115 | 112 | 'file_ref' => $file_ref, |
| 116 | 113 | ), |
| 117 | 114 | ) |
| 118 | 115 | ); |
| 119 | - $ok = $wpdb->update( | |
| 116 | + $ok = $wpdb->update( | |
| 120 | 117 | $tables['placements'], |
| 121 | 118 | array( |
| 122 | 119 | 'trashed_at_ms' => $now, |
| 123 | 120 | 'trashed_by' => $owner_id, |
| @@ -136,10 +133,8 @@ | ||
| 136 | 133 | /** |
| 137 | 134 | * Fires after a placement has been cascade-trashed because |
| 138 | 135 | * its source entity was trashed. |
| 139 | 136 | * |
| 140 | - * @since 0.22.0 | |
| 141 | - * | |
| 142 | 137 | * @param int $placement_id Placement id. |
| 143 | 138 | * @param int $owner_id Placement owner. |
| 144 | 139 | * @param string $file_type Source entity file type. |
| 145 | 140 | * @param string|int $file_ref Source entity ref. |
| @@ -144,9 +139,9 @@ | ||
| 144 | 139 | * @param string $file_type Source entity file type. |
| 145 | 140 | * @param string|int $file_ref Source entity ref. |
| 146 | 141 | */ |
| 147 | 142 | do_action( |
| 148 | - 'desktop_mode_files_after_cascade_trash_placement', | |
| 143 | + 'openstation_files_after_cascade_trash_placement', | |
| 149 | 144 | $placement_id, |
| 150 | 145 | $owner_id, |
| 151 | 146 | $file_type, |
| 152 | 147 | $file_ref |
| @@ -165,13 +160,11 @@ | ||
| 165 | 160 | * hooks too — but attachment placements use `file_type='attachment'` |
| 166 | 161 | * (not `'post'`), so this wrapper would miss them. The separate |
| 167 | 162 | * `delete_attachment` hook below covers attachments. |
| 168 | 163 | * |
| 169 | - * @since 0.22.0 | |
| 170 | - * | |
| 171 | 164 | * @param int $post_id Post id. |
| 172 | 165 | */ |
| 173 | -function desktop_mode_files_cascade_on_post_trash( $post_id ) { | |
| 166 | +function openstation_files_cascade_on_post_trash( $post_id ) { | |
| 174 | 167 | $post_id = (int) $post_id; |
| 175 | 168 | if ( $post_id <= 0 ) { |
| 176 | 169 | return; |
| 177 | 170 | } |
| @@ -185,19 +178,19 @@ | ||
| 185 | 178 | // the soft-trash path for attachments (when `EMPTY_TRASH_DAYS` |
| 186 | 179 | // is non-zero) also fires `wp_trash_post` — we cover it by |
| 187 | 180 | // dispatching to the attachment cascade below. |
| 188 | 181 | if ( 'attachment' === $post->post_type ) { |
| 189 | - desktop_mode_files_cascade_trash_placements_for_entity( | |
| 182 | + openstation_files_cascade_trash_placements_for_entity( | |
| 190 | 183 | 'attachment', |
| 191 | 184 | (string) $post_id |
| 192 | 185 | ); |
| 193 | 186 | return; |
| 194 | 187 | } |
| 195 | - desktop_mode_files_cascade_trash_placements_for_entity( 'post', (string) $post_id ); | |
| 188 | + openstation_files_cascade_trash_placements_for_entity( 'post', (string) $post_id ); | |
| 196 | 189 | } |
| 197 | 190 | |
| 198 | -add_action( 'wp_trash_post', 'desktop_mode_files_cascade_on_post_trash', 10, 1 ); | |
| 199 | -add_action( 'before_delete_post', 'desktop_mode_files_cascade_on_post_trash', 10, 1 ); | |
| 191 | +add_action( 'wp_trash_post', 'openstation_files_cascade_on_post_trash', 10, 1 ); | |
| 192 | +add_action( 'before_delete_post', 'openstation_files_cascade_on_post_trash', 10, 1 ); | |
| 200 | 193 | |
| 201 | 194 | /** |
| 202 | 195 | * Force-delete path for attachments — Core's `wp_delete_attachment()` |
| 203 | 196 | * fires this BEFORE the attachment row is gone, so `get_post()` is |
| @@ -202,24 +195,22 @@ | ||
| 202 | 195 | * Force-delete path for attachments — Core's `wp_delete_attachment()` |
| 203 | 196 | * fires this BEFORE the attachment row is gone, so `get_post()` is |
| 204 | 197 | * still resolvable for any plugin that needs the metadata. |
| 205 | 198 | * |
| 206 | - * @since 0.22.0 | |
| 207 | - * | |
| 208 | 199 | * @param int $attachment_id Attachment id. |
| 209 | 200 | */ |
| 210 | -function desktop_mode_files_cascade_on_attachment_delete( $attachment_id ) { | |
| 201 | +function openstation_files_cascade_on_attachment_delete( $attachment_id ) { | |
| 211 | 202 | $attachment_id = (int) $attachment_id; |
| 212 | 203 | if ( $attachment_id <= 0 ) { |
| 213 | 204 | return; |
| 214 | 205 | } |
| 215 | - desktop_mode_files_cascade_trash_placements_for_entity( | |
| 206 | + openstation_files_cascade_trash_placements_for_entity( | |
| 216 | 207 | 'attachment', |
| 217 | 208 | (string) $attachment_id |
| 218 | 209 | ); |
| 219 | 210 | } |
| 220 | 211 | |
| 221 | -add_action( 'delete_attachment', 'desktop_mode_files_cascade_on_attachment_delete', 10, 1 ); | |
| 212 | +add_action( 'delete_attachment', 'openstation_files_cascade_on_attachment_delete', 10, 1 ); | |
| 222 | 213 | |
| 223 | 214 | /** |
| 224 | 215 | * User account removed — cascade-trash every shortcut whose |
| 225 | 216 | * `file_type='user', file_ref='<id>'` pointed at the gone user. |
| @@ -226,20 +217,18 @@ | ||
| 226 | 217 | * Fires AFTER deletion (`deleted_user`) because user-deletion in |
| 227 | 218 | * Core involves reassigning content; we don't need the live user |
| 228 | 219 | * row, only its id. |
| 229 | 220 | * |
| 230 | - * @since 0.22.0 | |
| 231 | - * | |
| 232 | 221 | * @param int $user_id Deleted user id. |
| 233 | 222 | */ |
| 234 | -function desktop_mode_files_cascade_on_user_delete( $user_id ) { | |
| 223 | +function openstation_files_cascade_on_user_delete( $user_id ) { | |
| 235 | 224 | $user_id = (int) $user_id; |
| 236 | 225 | if ( $user_id <= 0 ) { |
| 237 | 226 | return; |
| 238 | 227 | } |
| 239 | - desktop_mode_files_cascade_trash_placements_for_entity( | |
| 228 | + openstation_files_cascade_trash_placements_for_entity( | |
| 240 | 229 | 'user', |
| 241 | 230 | (string) $user_id |
| 242 | 231 | ); |
| 243 | 232 | } |
| 244 | 233 | |
| 245 | -add_action( 'deleted_user', 'desktop_mode_files_cascade_on_user_delete', 10, 1 ); | |
| 234 | +add_action( 'deleted_user', 'openstation_files_cascade_on_user_delete', 10, 1 ); | |