-
Notifications
You must be signed in to change notification settings - Fork 333
Description
Feature Description
All links in the email template should point to a redirection proxy that maps a key to a dashboard (or documentation URL). This allows us to change destination URLs for elements of the plugin in future without breaking links in already delivered emails.
Specifically, the accept invite link/manage account links within the emails should conditionally redirect to the view-only splash page, with redirect_url set (defined in #11890) to open the email reporting panel after splash page dismissal. Otherwise, it should redirect directly to the dashboard to open the panel.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- A user clicking a golink URL (
index.php?action=googlesitekit_go&to={key}) is redirected to the registered destination viawp_safe_redirect() - A user clicking an invalid or unregistered golink receives a
wp_die()404 response with contextual links (dashboard or splash screen based on user capabilities) - Email report links (dashboard CTA, unsubscribe, email settings, "View more in dashboard", page-entity links) use golink URLs; external documentation links remain direct
- All other email templates (invitation-email, error-email and subscription-confirmation templates) use golink URLs for all plugin links
Implementation Brief
Backend (PHP) - Golinks core
-
Create file
includes/Core/Golinks/Golink_Handler_Interface.php:- Interface with single method
handle( Context $context ): string|WP_Error - Receives the
Contextinstance so consumers don't need to be constructed with it (providesInputand admin URL building) - Handler is responsible for constructing the full redirect URL, including reading and forwarding any parameters it cares about
- Interface with single method
-
Create file
includes/Core/Golinks/Golinks.php:- Constructor accepts
Contextinstance $handlersarray maps string keys toGolink_Handler_Interfaceinstancesregister()hooks intoadmin_action_googlesitekit_goregister_handler( $key, Golink_Handler_Interface $handler )registers a handler for a key; throws/dies if a handler for that key is already registeredget_url($key)returns golink URL for registered key (returnsnullfor unregistered)handle_go():- Extract
tovia$this->context->input()->filter(INPUT_GET, ...) - If key not found in
$handlers, callwp_die()with a 404 response code and a message containing contextual links: link to the Site Kit dashboard if the user can view the dashboard, otherwise link to the splash/setup screen - Call
$handler->handle( $this->context )to get destination URL - If result is
WP_Error, callwp_die()with the error message and appropriate status code wp_safe_redirect($url)andexit
- Extract
- Constructor accepts
-
Update file
includes/Plugin.php:- Instantiate
Golinkswith$this->context - Call
$golinks->register() - Register
dashboardhandler:$golinks->register_handler( 'dashboard', new Dashboard_Golink_Handler() )— handler readspermaLinkfrom$context->input()and appends it to the dashboard URL - Pass
$golinkstoEmail_Reportingconstructor
- Instantiate
Backend (PHP) - Email report template data
-
Update file
includes/Core/Email_Reporting/Email_Reporting.php:- Add
Golinksconstructor param, store as$this->golinks - In
register(), register themanage-subscription-email-reportinggolink handler:$this->golinks->register_handler( 'manage-subscription-email-reporting', new Email_Reporting_Golink_Handler() )— handler builds the dashboard URL with['panel' => 'email-reporting']via$context->admin_url() - Pass
$golinkstoEmail_Template_FormatterandEmail_Template_Renderer_Factoryconstructors
- Add
-
Update file
includes/Core/Email_Reporting/Email_Template_Formatter.php:- Add
Golinksconstructor param - In
prepare_template_data()(weekly/monthly report emails):- Replace
admin_url()calls with$this->golinks->get_url('dashboard')forprimary_call_to_action.url - Replace
admin_url()calls with$this->golinks->get_url('manage-subscription-email-reporting')forfooter.unsubscribe_urlandfooter.links[0].url(Manage subscription)
- Replace
- In
prepare_simple_email_data()(invitation/subscription-confirmation emails):- Set
$dashboard_urlto$this->golinks->get_url('dashboard') - Set
$email_settings_urlto$this->golinks->get_url('manage-subscription-email-reporting') - Populate
footer.unsubscribe_urlandfooter.linksarray (Manage subscription, Privacy Policy, Help center) - Use
$dashboard_urlforprimary_call_to_action.url
- Set
- In
build_template_payload(), pass$this->golinkstoSections_Mapconstructor
- Add
-
Update file
includes/Core/Email_Reporting/Sections_Map.php:- Add
Golinksconstructor param - Add
get_dashboard_url()helper that returns$this->golinks->get_url('dashboard') - Replace all 5 hardcoded
$this->context->admin_url('dashboard')calls in section definitions with$this->get_dashboard_url()- this feeds$section['dashboard_url']used by:templates/email-report/parts/section-page-metrics.phpfor per-pagepermaLinkdeep links and "View more in dashboard" CTAstemplates/email-report/parts/section-metrics.phpfor "View more in dashboard" CTAtemplates/email-report/parts/section-conversions.phpfor "View more in dashboard" CTA
- Add
-
Update file
includes/Core/Email_Reporting/Email_Template_Renderer_Factory.php:- Add
Golinksconstructor param - Pass
$this->golinkstoSections_Mapincreate()
- Add
Backend (PHP) - Email reporting panel param migration
- Update file
includes/Core/Email_Reporting/Email_Reporting_Pointer.php:- Change CTA link from
array('email-reporting-panel' => 1)toarray('panel' => 'email-reporting')
- Change CTA link from
Frontend (JS)
- Update file
assets/js/hooks/useOpenEmailReportingSelectionPanelEffect.js:- Replace
useQueryArg('email-reporting-panel')withuseQueryArg('panel') - Check
panel === 'email-reporting'instead ofemailReportingPanelOpen !== undefined - Clear with
setPanel(undefined)instead ofsetEmailReportingPanelOpen(undefined)
- Replace
Test Coverage
- PHPUnit:
tests/phpunit/integration/Core/Golinks/GolinksTest.php:register_handlerregisters new Golink.get_urlreturns correct format, returns null for unregistered keyhandle_goredirects to handler destination, dies with 404 for invalid linkhandle_goreturnswp_die()with error when handler returnsWP_Errorregister_handlerthrows/dies when registering a duplicate key
QA Brief
- Setup Site Kit
- Paste this path to the root website URL:
/wp-admin/index.php?action=googlesitekit_go&to=dashboard - Expect redirect to Site Kit dashboard
- Add this path
/wp-admin/index.php?action=googlesitekit_go&to=manage-subscription-email-reporting - Expect redirect to dashboard with email reporting panel open
- View only user should have same results as above when including these paths
- Login as a second admin
- Paste this path
/wp-admin/index.php?action=googlesitekit_go&to=manage-subscription-email-reporting - You should land on splash screen, and after signing in/dismissing it if going with view only dashboard you should land on Site Kit dashboard with email reporting panel open
- Otherwise, if splash screen has been passed, above paths will behave same as for main admin after SK setup
- Invalid URL
- As main admin, or secondary admin, paste this path
/wp-admin/index.php?action=googlesitekit_go&to=invalid-keyyou should land on 404 page with a link to the site kit dashboard
- As main admin, or secondary admin, paste this path
- Subscribe to email reporting and trigger an email - Existing links should still work - manage/unsubscribe should lead to dashboard with email reporting panel open, etc
Changelog entry
- Add support for stable deep links to dashboard and email subscription management.