Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a launch site button to the admin bar. #41240

Merged
merged 9 commits into from
Jan 27, 2025
Merged

Conversation

youknowriad
Copy link
Contributor

@youknowriad youknowriad commented Jan 22, 2025

Closes Automattic/wp-calypso#98895.

Proposed changes:

We recently removed the "launch bar" from the frontend of wp.com websites, that said, it's important for users to know that there's site is yet to be launched for users as raised by @scruffian

The current PR adds a "launch site" button to the admin bar of both simple and atomic sites.

Screenshot 2025-01-22 at 11 17 34 AM

Testing instructions:

  • apply the PR changes
  • Open the frontend of your unlaunched site
  • Notice the "launch site" button in the admin bar
  • Click the button and launch your site
  • The button is gone from the admin bar.

Does this pull request change what data or activity we track or use?

No

@youknowriad youknowriad added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jan 22, 2025
@youknowriad youknowriad self-assigned this Jan 22, 2025
Copy link
Contributor

github-actions bot commented Jan 22, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the add/launch-button branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/launch-button
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Package] Jetpack mu wpcom WordPress.com Features [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh labels Jan 22, 2025
Copy link
Contributor

github-actions bot commented Jan 22, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

} else if ( function_exists( '\WPCOM\Lib\Launch_Site\is_launched' ) ) {
$is_launched = \WPCOM\Lib\Launch_Site\is_launched( $blog_id );
$blog_domain = preg_replace( '!^https?://!', '', get_primary_redirect( $blog_id ) );
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding the right APIs to use has been challenge. I'm not sure I'm covering all the subtle use-cases either.
I would love if we had a "codex" or "dev docs" to know which APIs are available to which sites, otherwise, it feels like we're just hacking things together.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love if we had a "codex" or "dev docs" to know which APIs are available to which sites

That would be great indeed. In practice, we currently need to do some digging or look at prior art to get familiar with newer things.

In this specific use-case, there is prior art with #36839, where as you can see, they sticked to the same option check in both environments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there's a consistent way to get the "domain name" as well (between atomic and simple) to avoid the condition.

@@ -0,0 +1,3 @@
#wpadminbar .launch-site {
background: var(--wp-admin-theme-color);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used the admin color CSS variable to try to stay consistent with the admin bar but I noticed that these variables don't contain the right values. I think this is out of scope of the current PR. I know some folks are working on making sure the right colors are used everywhere.

@youknowriad youknowriad requested a review from richtabor January 22, 2025 10:21
@jeherve jeherve added [Status] Needs Team Review and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jan 22, 2025
$is_launched = true;
$blog_id = get_current_blog_id();

if ( defined( 'IS_ATOMIC' ) && IS_ATOMIC ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you use the Status package in that file already, you could switch to using is_woa_site from Status\Host

$is_launched = get_option( 'launch-status' ) === 'launched';
$blog_domain = ( new Status() )->get_site_suffix();
} else if ( function_exists( '\WPCOM\Lib\Launch_Site\is_launched' ) ) {
$is_launched = \WPCOM\Lib\Launch_Site\is_launched( $blog_id );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you run into PhanUndeclaredFunction or other Phan errors, this can be a good help:
pdWQjU-Jb-p2

} else if ( function_exists( '\WPCOM\Lib\Launch_Site\is_launched' ) ) {
$is_launched = \WPCOM\Lib\Launch_Site\is_launched( $blog_id );
$blog_domain = preg_replace( '!^https?://!', '', get_primary_redirect( $blog_id ) );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love if we had a "codex" or "dev docs" to know which APIs are available to which sites

That would be great indeed. In practice, we currently need to do some digging or look at prior art to get familiar with newer things.

In this specific use-case, there is prior art with #36839, where as you can see, they sticked to the same option check in both environments.

*
* @param WP_Admin_Bar $admin_bar The WordPress admin bar.
*/
function wpcom_add_launch_button_to_admin_bar( WP_Admin_Bar $admin_bar ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check whether the user is the admin of the site. Currently, the launch button shows up for everyone, even logged-out users, which is unexpected.

Copy link
Contributor Author

@youknowriad youknowriad Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the admin bar only shown for logged-in users. Also if I'm not wrong, if your site is unlaunched, no one is going to see the site (it's going to show the coming soon message) no?

I guess in other words, how do I reproduce the issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we can reproduce the issue:

  1. Create a new unlaunched SIMPLE site.
  2. Patch this PR to the sandbox.
  3. Add a new user as Editor/Author.
  4. Log in to WordPress.com as that user (e.g. in another browser window).
  5. Open the site frontend as that user.
  6. You will see the admin bar with the launch button, which shouldn't be there. (Clicking the button will not launch the site)

Isn't the admin bar only shown for logged-in users.

Yeah, sorry, it won't be shown logged-out users. (Except if you're seeing an ATOMIC site frontend while PROXIED, which is a weird case and can be ignored). But the above case still applies -- we need to check for the current user's permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I was actually unable to reproduce this issue. The Editor/Author can't see the frontend of the website and only see a "coming soon" page for me, so there's no admin bar.

That said, I pushed a code to add a check. Some small defensive coding is not that bad.

@richtabor
Copy link

Nice.

We should consider adding a confirmation dialog to clarify what launching entails. This will help users determine if they’re truly ready to proceed while providing a seamless and tasteful opportunity to upgrade their site.

If launching is intentional and meaningful, it can also serve as a well-timed upsell moment (that's persistent if left "unlaunched". I'll write up some thoughts on this front.

@youknowriad
Copy link
Contributor Author

If launching is intentional and meaningful, it can also serve as a well-timed upsell moment (that's persistent if left "unlaunched". I'll write up some thoughts on this front.

I think this is already the case, launching send you to a wizard to pick a domain/plan if you didn't pick one yet.

For the confirmation, are you thinking about a regular browser confirm dialog? To be honest, I'm not entirely sure about this interaction. The launch wizard is already something you can abort at any time.

$blog_id = get_current_blog_id();
$blog_domain = preg_replace( '!^https?://!', '', get_primary_redirect( $blog_id ) );
}
if ( $is_launched ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you could return earlier.

$blog_domain = ( new Status() )->get_site_suffix();
} else {
$blog_id = get_current_blog_id();
$blog_domain = preg_replace( '!^https?://!', '', get_primary_redirect( $blog_id ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use wp_parse_url( home_url(), PHP_URL_HOST ) I think?
This is what the site management widget currently uses (untouched by me).
Also I think it's using that for both simple and atomic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this code from the previous launch bar we had in the frontend but I can try your suggestion. There's so many ways of doing the same things and no reference for these things. I think we need this reference at some point.

ellatrix
ellatrix previously approved these changes Jan 27, 2025
Copy link
Contributor

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works for me. It's a bit weird that it sends you to the same flow as the one for creating a new site, but it has nothing to do with this PR.

@youknowriad youknowriad merged commit c3f0796 into trunk Jan 27, 2025
60 checks passed
@youknowriad youknowriad deleted the add/launch-button branch January 27, 2025 11:39
@ellatrix
Copy link
Contributor

I'm seeing a little bug with the colours. Strange because previously it was correct 🤔

image

A bit later I'm seeing that's it's only temporarily this colour upon refresh, then it becomes the right colour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Jetpack mu wpcom WordPress.com Features [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add “Launch site” button to the WordPress admin bar
5 participants