| 1 |
<?php |
| 2 |
/** |
| 3 |
* Dashboard identifier grammar shared across Premium Analytics dashboard APIs. |
| 4 |
* |
| 5 |
* These accessors are the single source of truth for the dashboard and section |
| 6 |
* identifier grammar, shared between the REST route definitions and the |
| 7 |
* registry validation so the two can never drift apart. |
| 8 |
* |
| 9 |
* @package automattic/jetpack-premium-analytics |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Automattic\Jetpack\PremiumAnalytics; |
| 13 |
|
| 14 |
/** |
| 15 |
* Dashboard identifier pattern used by REST routes and dashboard registries. |
| 16 |
* |
| 17 |
* Allows the `<plugin>_<page>` form produced by the wp-build pipeline, while |
| 18 |
* also accepting simple dashboard names for consumers that do not use a page |
| 19 |
* suffix. |
| 20 |
* |
| 21 |
* @return string Unanchored regular expression fragment. |
| 22 |
*/ |
| 23 |
function get_dashboard_name_pattern() { |
| 24 |
return '[a-z][a-z0-9-]*(?:_[a-z0-9-]+)*'; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Dashboard section identifier pattern. |
| 29 |
* |
| 30 |
* Mirrors WordPress block and Premium Analytics widget type names: a namespace |
| 31 |
* prefix followed by a section slug. |
| 32 |
* |
| 33 |
* @return string Unanchored regular expression fragment. |
| 34 |
*/ |
| 35 |
function get_dashboard_section_id_pattern() { |
| 36 |
return '[a-z0-9-]+\/[a-z0-9-]+'; |
| 37 |
} |
| 38 |
|