site-kit-wp
site-kit-wp copied to clipboard
Add WP admin pointer for view-only dashboard access "Site Kit" menu item
A WordPress admin pointer should be added that informs users that have received view-only access to the dashboard about the new "Site Kit" admin menu item available to them.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- A new WP admin pointer should be added that points to the "Site Kit" menu if all of the following circumstances apply:
- The user is currently on the WordPress dashboard (
index.php). - The user has only shared / view-only access to Site Kit (i.e. cannot authenticate).
- The user has dismissed neither that WP admin pointer nor the shared splash dismissal.
- The user is currently on the WordPress dashboard (
- The wording for the pointer should be as follows:
- Title: You now have access to Site Kit
- Content: Check Site Kit's dashboard to find out how much traffic your site is getting, your most popular pages, top keywords people use to find your site on Search, and more.
- When the pointer is dismissed, it should be dismissed permanently, i.e. no transient or so.
Implementation Brief
A good reference and starting point would be e.g. https://github.com/WordPress/performance/blob/1.2.0/admin/load.php#L342-L418, copy this code into a more Site Kit-appropriate class structure and tweak it based on the ACs (e.g. add the Site Kit-specific checks).
- The idea is to create a Admin
Pointersystem in similar way to howNoticesare handled in Site Kit source code. Most of the inspiration were drawn from the following classes. Feel free to refer to these classes when something seems unclear.Google\Site_Kit\Core\Admin\NoticeGoogle\Site_Kit\Core\Admin\NoticesGoogle\Site_Kit\Core\Util\Activation_Notice
- Create a new class
Google\Site_Kit\Core\Admin\Pointerthat represents a Pointer.- Have
slugandargsas private property.slugis the unique Pointer slug.argsshould contain the following:title: pointer title.contentpointer content.target_id: the id where the pointer will be attached. ie. a menu item.active_callback: function to determine whether the pointer should be active. ie. shown.
- Initialize
slugandargsin theconstructor.- Use
wp_parse_argsto parse the args.
- Use
- Add a public method
is_activethat:- Takes
hook_suffixas an argument. - Return
falseif eithertitleorcontentis empty. - Return
trueifactive_callbackis not set. ie. null or falsy. - Otherwise, return the boolean result of calling
avtive_callbackwithhook_suffixas an argument using thecall_user_func.
- Takes
- Add a public method
enqueue_script:- that adds
print_scripttoadmin_print_footer_scriptsaction usingadd_action.
- that adds
- Add
print_scriptmethod:- Get
headingby escapingtitlewithesc_js. - Get
contentby:- If
contentis callable, call it usingcall_user_func. - Otherwise, wrap it in a
ptag and escape it usingwp_kses.
- If
- Print out the
pointerinline script using theBC_Functions::wp_print_inline_script_tagmethod.- Get the script from the link above.
- Print it as a formatted string using
sprintfand interpolateheading,content,slugandtarget_idaccordingly.
- Get
- Have
- Create a new class
Google\Site_Kit\Core\Admin\Pointerswhich will register and manage all the pointers.- Create a public method
register:- That adds
enqueue_pointersto toadmin_enqueue_scriptsaction usingadd_action.
- That adds
- Create
enqueue_pointersmethod:- It takes one argument,
hook_suffix. - Return early if
hook_suffixis empty. - Get all the pointers using
$this->get_pointersfunction. - Return early if there is no pointers.
- Filter out
active_pointersby callingis_activeon every pointer and passinghook_suffixto it. - Return early if there is no
active_pointers. - Otherwise, enqueue
wp-pointerscript and style usingwp_enqueue_scriptandwp_enqueue_stylerespectively. - Call
enqueue_scripton all active pointers.
- It takes one argument,
- Create
get_pointersmethod:- Get all the registered
pointersby callingapply_filterswithgooglesitekit_admin_pointersfilter with an empty array as the default value. - Only return
pointersthat are an instance ofPointer.
- Get all the registered
- Create a public method
- Create
Google\Site_Kit\Core\Util\View_Only_Pointerclass that will register the View Only Pointer.- create a
SLUGconstant with the valuegooglesitekit-view-only-pointer. - Have
dismissed_itemsand initialize them in theconstructor. - Create a public
registermethod:- Add the view only pointer to the
googlesitekit_admin_pointersusingadd_filterhook. - Use
get_view_only_pointerto get thePointer.
- Add the view only pointer to the
- Create
get_view_only_pointermethod:- It will return a new Pointer with the following:
slug=>self::SLUG.args=>title=> See AC. It should be translated.content=> See AC. It should be translated.target_id=>toplevel_page_googlesitekit-dashboardactive_callback=> Should be a function that takeshook_suffixas a parameter and:- Returns
falseif either of the following istruehook_suffixis notindex.php.dashboardSharingis not enabled.- current user can Authenticate.
- current user can not view splash.
shared_dashboard_splashis dismissed.
- Get
dismissed_wp_pointersusingget_user_meta. - Return
trueifdismissed_wp_pointersis empty. - Otherwise, explode the
dismissed_wp_pointerswith,to create an array. - Return
falseifself::slugis in the array. - Otherwise, return
true.
- Returns
- create a
- In
Google\Site_Kit\Pluginclass:- Instantiate and register the newly added
PointersandView_Only_Pointerclass.
- Instantiate and register the newly added
Test Coverage
- Add Unit Test for
Pointer.- Check the enqueued inline script.
- Add Unit Test for
Pointers.- Register a pointer and see if the inline script and the
wp-pointerscripts are added to the admin screens.
- Register a pointer and see if the inline script and the
- Add a Unit Test for the
active_callbackfunction ofView_Only_Pointer.
QA Brief
- Enable
dashboardSharing. - Share some modules with non-admin role to give them shared access.
- Log in to a account of aforementioned role.
- You should see a Admin Pointer pointing to the Site Kit menu.
- Match title and content with the AC.
Changelog entry
@eclarke1 @FlicHollis Would be great if we could get this added to the upcoming sprint.
@marrrmarrr still needs to add wording to the ACs, but the IB could technically already be written at this point.
Thanks @felixarntz I have moved this over to IB so the team know it can be picked up, but will keep assigned to @marrrmarrr as well to finalise the wording there please.
Following comms with @marrrmarrr confirming this is a 'Nice to Have' for launch, so dropping down to a P1
@eclarke1 I've updated the text here, so this can move forward.
Just a polite ping on this one please @aaemnnosttv as it's for this sprint 82 and has been in IBR 8 days. Thanks so much. cc @FlicHollis
Thanks @eclarke1 – apologies for the delay here. I hadn't forgotten about it 👍
@kuasha420, nice work here – I like the idea to model this after Notices, that should work well I think.
- Get
dismissed_wp_pointersusinguser_options->get.
@kuasha420, while I think using User_Options would work for this, this is not technically a user option and so we should use user meta directly like core does.
Otherwise, the IB looks good, but we should make sure to add test cases for Pointer as well, not just the class for all pointers.
@aaemnnosttv Thank you for the review. Glad to know that the idea to model it like Notices was a good idea after all! Initially it kind of felt overkill but my rational was that we may use pointers more in the future, specially with having more of site kit in other places of dashboard (Widget areas, editor etc).
I have updated the IB with your suggestions. Please have a look. Cheers. :smile:
IB ✅
QA Update ⚠️
@kuasha420
- I found that Pointer Title is getting cut in desktop and laptops. Verified on chrome, safari and edge browser.

- Currently Pointer is not showing in all mobile devices - iPad, iPhone and android mobile/tablets. Is this expected ?
@mohitwp Hi, I have done some investigation on why the title is cut off. Looks like the WP pointer puts the arrow in the 50% of the height of the Pointer Content. As the Site Kit Menu is situated very top, the title goes under the Admin Bar. Without messing about too much with the CSS, we need to chose either of the following solution.
Put the Pointer under the menu. (Supported in wp-pointer script)

Increase the z-index of Pointer so it shows up over the Admin Bar. (Need custom CSS)

Which one looks better to you?
As for your second question, I think wp-pointer does not ~~work~~ show up ~~on mobile~~ below a certain viewport resolution, so it not appearing on mobile is expected behavior
CC @wpdarren @felixarntz
@kuasha420 I like the second design (increase the z-index) but it requires custom CSS work. @felixarntz @wpdarren can you please provide your suggestions here ?
@kuasha420 I feel the call needs to come from @felixarntz because he created the ticket, but I agree with Mohit. I'll post a link in the open Slack channel so we can get this moved forward.
@kuasha420 let's opt to go with the alternate placement, putting it under the menu instead. I'm sure core probably has its own pointers that could end up below the admin bar and it was probably an intentional choice at some point to keep these below it (although maybe not). I also think increasing the z-index could make part of it unreadable if the content were longer (due to translation perhaps), because the content is centered on the arrow.
@kuasha420 +1 to Evan's point, regardless of which UI we visually prefer, I agree we should follow what WP core already offers us here to avoid risk of other "overlap" issues, so let's go with adjusting the position via what is supported by wp-pointer.
QA Admin ✅
Verified :
-
Verified A new pointer is added and show up in below listed cases-
- The user is currently on the WordPress dashboard (index.php).
- The user has only shared / view-only access to Site Kit (i.e. cannot authenticate).
- The user has dismissed neither that WP admin pointer nor the shared splash dismissal.
-
When the pointer is dismissed, it gets dismissed permanently, i.e. no transient or so.
-
Verified content and title.
