PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.11
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.11
1.1.11 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 All 35 releases
← All changes | includes/living-tree/snapshot.php +39 -30 0.9.8 → 1.1.11 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Living Tree: REST snapshot endpoint.
3 + * OpenStation — Living Tree: REST snapshot endpoint.
4 4 *
5 5 * One route: `GET desktop-mode/v1/living-tree/snapshot`. Returns the
6 6 * compact site DNA (`TreeSnapshot` in the JS types) — aggregate counts
7 7 * and branch hints — never the full post list. The client turns this
@@ -14,18 +14,27 @@
14 14 *
15 15 * The response is cached in a transient (TTL 6h) and invalidated whenever
16 16 * content changes (`save_post` / `deleted_post` / `comment_post`).
17 17 *
18 - * @package WPDesktopMode
18 + * @package OpenStation
19 19 */
20 20
21 21 defined( 'ABSPATH' ) || exit;
22 22
23 -/** Transient key the built snapshot is cached under. */
24 -const DESKTOP_MODE_LIVING_TREE_CACHE_KEY = 'desktop_mode_living_tree_snapshot';
23 +/**
24 + * Transient key the built snapshot is cached under.
25 + *
26 + * The VALUE keeps its pre-rebrand spelling on purpose, so live caches
27 + * stay addressable. The mismatch between this constant's name and its
28 + * value is deliberate — it is NOT a half-finished rename.
29 + *
30 + * Not to be confused with the `openstation_living_tree_snapshot` filter,
31 + * which once shared this string and is now deliberately decoupled.
32 + */
33 +const OPENSTATION_LIVING_TREE_CACHE_KEY = 'desktop_mode_living_tree_snapshot';
25 34
26 35 /** Cache lifetime for the snapshot. */
27 -const DESKTOP_MODE_LIVING_TREE_CACHE_TTL = 6 * HOUR_IN_SECONDS;
36 +const OPENSTATION_LIVING_TREE_CACHE_TTL = 6 * HOUR_IN_SECONDS;
28 37
29 38 /**
30 39 * Whether the current user may read the Living Tree snapshot.
31 40 *
@@ -33,9 +42,9 @@
33 42 * of their own site. Filterable so a site can widen or restrict it.
34 43 *
35 44 * @return bool
36 45 */
37 -function desktop_mode_living_tree_user_can_use() {
46 +function openstation_living_tree_user_can_use() {
38 47 $can = current_user_can( 'read' );
39 48
40 49 /**
41 50 * Filter whether the current user can read the Living Tree snapshot.
@@ -41,26 +50,26 @@
41 50 * Filter whether the current user can read the Living Tree snapshot.
42 51 *
43 52 * @param bool $can Default: the `read` capability.
44 53 */
45 - return (bool) apply_filters( 'desktop_mode_living_tree_user_can_use', $can );
54 + return (bool) apply_filters( 'openstation_living_tree_user_can_use', $can );
46 55 }
47 56
48 57 /**
49 58 * Register the snapshot route.
50 59 */
51 -function desktop_mode_living_tree_register_routes() {
60 +function openstation_living_tree_register_routes() {
52 61 register_rest_route(
53 62 'desktop-mode/v1',
54 63 '/living-tree/snapshot',
55 64 array(
56 65 'methods' => WP_REST_Server::READABLE,
57 - 'callback' => 'desktop_mode_living_tree_rest_snapshot',
58 - 'permission_callback' => 'desktop_mode_living_tree_user_can_use',
66 + 'callback' => 'openstation_living_tree_rest_snapshot',
67 + 'permission_callback' => 'openstation_living_tree_user_can_use',
59 68 )
60 69 );
61 70 }
62 -add_action( 'rest_api_init', 'desktop_mode_living_tree_register_routes' );
71 +add_action( 'rest_api_init', 'openstation_living_tree_register_routes' );
63 72
64 73 /**
65 74 * GET /living-tree/snapshot — cached snapshot response.
66 75 *
@@ -65,19 +74,19 @@
65 74 * GET /living-tree/snapshot — cached snapshot response.
66 75 *
67 76 * @return WP_REST_Response
68 77 */
69 -function desktop_mode_living_tree_rest_snapshot() {
70 - $cached = get_transient( DESKTOP_MODE_LIVING_TREE_CACHE_KEY );
78 +function openstation_living_tree_rest_snapshot() {
79 + $cached = get_transient( OPENSTATION_LIVING_TREE_CACHE_KEY );
71 80 if ( is_array( $cached ) ) {
72 81 return rest_ensure_response( $cached );
73 82 }
74 83
75 - $snapshot = desktop_mode_living_tree_build_snapshot();
84 + $snapshot = openstation_living_tree_build_snapshot();
76 85 set_transient(
77 - DESKTOP_MODE_LIVING_TREE_CACHE_KEY,
86 + OPENSTATION_LIVING_TREE_CACHE_KEY,
78 87 $snapshot,
79 - DESKTOP_MODE_LIVING_TREE_CACHE_TTL
88 + OPENSTATION_LIVING_TREE_CACHE_TTL
80 89 );
81 90
82 91 return rest_ensure_response( $snapshot );
83 92 }
@@ -85,14 +94,14 @@
85 94 /**
86 95 * Invalidate the cached snapshot. Wired to the content-mutation hooks so
87 96 * the tree re-DNAs on the next load after the site changes.
88 97 */
89 -function desktop_mode_living_tree_flush_cache() {
90 - delete_transient( DESKTOP_MODE_LIVING_TREE_CACHE_KEY );
98 +function openstation_living_tree_flush_cache() {
99 + delete_transient( OPENSTATION_LIVING_TREE_CACHE_KEY );
91 100 }
92 -add_action( 'save_post', 'desktop_mode_living_tree_flush_cache' );
93 -add_action( 'deleted_post', 'desktop_mode_living_tree_flush_cache' );
94 -add_action( 'comment_post', 'desktop_mode_living_tree_flush_cache' );
101 +add_action( 'save_post', 'openstation_living_tree_flush_cache' );
102 +add_action( 'deleted_post', 'openstation_living_tree_flush_cache' );
103 +add_action( 'comment_post', 'openstation_living_tree_flush_cache' );
95 104
96 105 /**
97 106 * Build the compact site DNA snapshot.
98 107 *
@@ -102,9 +111,9 @@
102 111 * per-post coordinate or identity into the payload.
103 112 *
104 113 * @return array The snapshot, matching the JS `TreeSnapshot` shape.
105 114 */
106 -function desktop_mode_living_tree_build_snapshot() {
115 +function openstation_living_tree_build_snapshot() {
107 116 $posts = wp_count_posts( 'post' );
108 117 $pages = wp_count_posts( 'page' );
109 118 $comments = wp_count_comments();
110 119
@@ -113,20 +122,20 @@
113 122
114 123 $snapshot = array(
115 124 'siteUrl' => (string) home_url(),
116 125 'siteName' => (string) get_bloginfo( 'name' ),
117 - 'installEpoch' => desktop_mode_living_tree_install_epoch(),
118 - 'siteAgeDays' => desktop_mode_living_tree_site_age_days(),
126 + 'installEpoch' => openstation_living_tree_install_epoch(),
127 + 'siteAgeDays' => openstation_living_tree_site_age_days(),
119 128 'totalPosts' => isset( $posts->publish ) ? (int) $posts->publish : 0,
120 129 'totalPages' => isset( $pages->publish ) ? (int) $pages->publish : 0,
121 130 'totalCategories' => is_wp_error( $categories ) ? 0 : (int) $categories,
122 131 'totalTags' => is_wp_error( $tags ) ? 0 : (int) $tags,
123 132 'totalComments' => isset( $comments->approved ) ? (int) $comments->approved : 0,
124 - 'activeUsers' => desktop_mode_living_tree_active_users(),
125 - 'traffic' => desktop_mode_living_tree_traffic(),
126 - 'seoHealth' => desktop_mode_living_tree_seo_health(),
127 - 'performance' => desktop_mode_living_tree_performance(),
128 - 'branches' => desktop_mode_living_tree_branch_dna(),
133 + 'activeUsers' => openstation_living_tree_active_users(),
134 + 'traffic' => openstation_living_tree_traffic(),
135 + 'seoHealth' => openstation_living_tree_seo_health(),
136 + 'performance' => openstation_living_tree_performance(),
137 + 'branches' => openstation_living_tree_branch_dna(),
129 138 );
130 139
131 140 /**
132 141 * Filter the Living Tree snapshot before it is cached and served.
@@ -135,6 +144,6 @@
135 144 * coordinates (the golden rule).
136 145 *
137 146 * @param array $snapshot The compact site DNA.
138 147 */
139 - return apply_filters( 'desktop_mode_living_tree_snapshot', $snapshot );
148 + return apply_filters( 'openstation_living_tree_snapshot', $snapshot );
140 149 }