Skip to content

Commit 9c9df41

Browse files
louwie17claude
andcommitted
Premium Analytics: trim dashboard sections API to the server contract
Add a derived section slug to Dashboard_Section and its REST representation, trim GET /sections to { id, slug, label, order }, retire the per-user section-layout write routes (PUT/DELETE layout, DELETE sections) and the helpers that served them, and relabel the woocommerce/store section to Store. Layout persistence stays on core @wordpress/preferences. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KKXV17Z2FVzrtTt8zK5RaF
1 parent 5c5e2a8 commit 9c9df41

4 files changed

Lines changed: 117 additions & 970 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Dashboard Sections API: expose a derived section slug and trim GET /sections to definitions only ({ id, slug, label, order }), retire the per-user section layout write routes in favor of core preferences persistence, and relabel the WooCommerce section to Store.

projects/packages/premium-analytics/src/class-dashboard-section.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ final class Dashboard_Section {
3030
*/
3131
public $id;
3232

33+
/**
34+
* URL-facing section slug, derived from the identifier.
35+
*
36+
* @var string
37+
*/
38+
public $slug;
39+
3340
/**
3441
* Display label.
3542
*
@@ -68,11 +75,24 @@ final class Dashboard_Section {
6875
public function __construct( $dashboard_name, $id, $args = array() ) {
6976
$this->dashboard_name = $dashboard_name;
7077
$this->id = $id;
78+
$this->slug = self::derive_slug( $id );
7179
$this->label = $id;
7280

7381
$this->set_props( $args );
7482
}
7583

84+
/**
85+
* Derives the URL-facing slug from a namespaced section identifier.
86+
*
87+
* @param string $id Section identifier, e.g. `analytics/traffic`.
88+
* @return string The segment after the namespace, e.g. `traffic`.
89+
*/
90+
private static function derive_slug( $id ) {
91+
$separator = strpos( (string) $id, '/' );
92+
93+
return false === $separator ? (string) $id : substr( $id, $separator + 1 );
94+
}
95+
7696
/**
7797
* Returns whether this section should be exposed.
7898
*
@@ -107,6 +127,7 @@ public function get_default_layout() {
107127
public function to_array() {
108128
return array(
109129
'id' => $this->id,
130+
'slug' => $this->slug,
110131
'label' => $this->label,
111132
'order' => (int) $this->order,
112133
);

0 commit comments

Comments
 (0)