From b76d1d366a529252d88291f96b2bd36ccef9fe00 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 14 Nov 2024 12:56:00 -0800 Subject: [PATCH] Add docs for the od_url_metric_stored action --- plugins/optimization-detective/readme.txt | 12 ++++++++++++ plugins/optimization-detective/storage/rest-api.php | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/optimization-detective/readme.txt b/plugins/optimization-detective/readme.txt index 1e16f2c8b..c04aea14b 100644 --- a/plugins/optimization-detective/readme.txt +++ b/plugins/optimization-detective/readme.txt @@ -219,6 +219,18 @@ add_filter( See also [example usage](https://github.com/WordPress/performance/blob/6bb8405c5c446e3b66c2bfa3ae03ba61b188bca2/plugins/embed-optimizer/hooks.php#L128-L144) in Embed Optimizer. Note in particular the structure of the plugin’s [detect.js](https://github.com/WordPress/performance/blob/trunk/plugins/embed-optimizer/detect.js) script module, how it exports `initialize` and `finalize` functions which Optimization Detective then calls when the page loads and when the page unloads, at which time the URL Metric is constructed and sent to the server for storage. Refer also to the [TypeScript type definitions](https://github.com/WordPress/performance/blob/trunk/plugins/optimization-detective/types.ts). +**Action:** `od_url_metric_stored` (argument: `OD_URL_Metric_Store_Request_Context`) + +Fires whenever a URL Metric was successfully stored. + +The supplied context object includes these properties: + +* `$request`: The `WP_REST_Request` for storing the URL Metric. +* `$post_id`: The post ID for the `od_url_metric` post. +* `$url_metric`: The newly-stored URL Metric. +* `$url_metric_group`: The viewport group that the URL Metric was added to. +* `$url_metric_group_collection`: The `OD_URL_Metric_Group_Collection` instance to which the URL Metric was added. + == Installation == = Installation from within WordPress = diff --git a/plugins/optimization-detective/storage/rest-api.php b/plugins/optimization-detective/storage/rest-api.php index 2b505e14f..9392d9ed4 100644 --- a/plugins/optimization-detective/storage/rest-api.php +++ b/plugins/optimization-detective/storage/rest-api.php @@ -222,7 +222,6 @@ function od_handle_rest_request( WP_REST_Request $request ) { * Fires whenever a URL Metric was successfully stored. * * @since 0.7.0 - * @todo Add this to the README as documentation. * * @param OD_URL_Metric_Store_Request_Context $context Context about the successful URL Metric collection. */