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 hooks for create and delete sites. #7494

Closed
wants to merge 1 commit into from
Closed

Conversation

spacedmonkey
Copy link
Contributor

Context

Summary

Tweak, the base plugin template to hook in on new site creation and deletion in multisite context. The pattern of having a method run on new site / delete follows the pattern of activation / deactivation.

Relevant Technical Choices

To-do

User-facing changes

Testing Instructions

QA

  • This is a non-user-facing change and requires no QA

This PR can be tested by following these steps:

UAT

  • UAT should use the same steps as above.

This PR can be tested by following these steps:

Reviews

Does this PR have a security-related impact?

Does this PR change what data or activity we track or use?

Does this PR have a legal-related impact?

Checklist

  • This PR addresses an existing issue and I have linked this PR to it in ZenHub
  • I have tested this code to the best of my abilities
  • I have verified accessibility to the best of my abilities (docs)
  • I have verified i18n and l10n (translation, right-to-left layout) to the best of my abilities
  • This PR contains automated tests (unit, integration, and/or e2e) to verify the code works as intended (docs)
  • I have added documentation where necessary
  • I have added a matching Type: XYZ label to the PR

Fixes #

@spacedmonkey
Copy link
Contributor Author

CC @schlessera and @westonruter as this change could be ported back to the amp plugin. I am interested to know the amp plugin handles multisite.

@github-actions
Copy link
Contributor

Size Change: 0 B

Total Size: 2.12 MB

ℹ️ View Unchanged
Filename Size Change
assets/css/carousel-view-rtl.css 715 B 0 B
assets/css/carousel-view.css 716 B 0 B
assets/css/edit-story-rtl.css 278 B 0 B
assets/css/edit-story.css 278 B 0 B
assets/css/stories-dashboard-rtl.css 276 B 0 B
assets/css/stories-dashboard.css 276 B 0 B
assets/css/vendors-edit-story-rtl.css 702 B 0 B
assets/css/vendors-edit-story.css 702 B 0 B
assets/css/web-stories-block-rtl.css 3.23 kB 0 B
assets/css/web-stories-block.css 3.26 kB 0 B
assets/css/web-stories-embed-rtl.css 284 B 0 B
assets/css/web-stories-embed.css 284 B 0 B
assets/css/web-stories-list-styles-rtl.css 2.26 kB 0 B
assets/css/web-stories-list-styles.css 2.27 kB 0 B
assets/css/web-stories-theme-style-twentyeleven-rtl.css 102 B 0 B
assets/css/web-stories-theme-style-twentyeleven.css 102 B 0 B
assets/css/web-stories-theme-style-twentyfifteen-rtl.css 252 B 0 B
assets/css/web-stories-theme-style-twentyfifteen.css 252 B 0 B
assets/css/web-stories-theme-style-twentyfourteen-rtl.css 286 B 0 B
assets/css/web-stories-theme-style-twentyfourteen.css 286 B 0 B
assets/css/web-stories-theme-style-twentyseventeen-rtl.css 311 B 0 B
assets/css/web-stories-theme-style-twentyseventeen.css 311 B 0 B
assets/css/web-stories-theme-style-twentysixteen-rtl.css 239 B 0 B
assets/css/web-stories-theme-style-twentysixteen.css 239 B 0 B
assets/css/web-stories-theme-style-twentyten-rtl.css 144 B 0 B
assets/css/web-stories-theme-style-twentyten.css 145 B 0 B
assets/css/web-stories-theme-style-twentytwelve-rtl.css 263 B 0 B
assets/css/web-stories-theme-style-twentytwelve.css 263 B 0 B
assets/css/web-stories-theme-style-twentytwenty-rtl.css 86 B 0 B
assets/css/web-stories-theme-style-twentytwenty.css 86 B 0 B
assets/css/web-stories-theme-style-twentytwentyone-rtl.css 263 B 0 B
assets/css/web-stories-theme-style-twentytwentyone.css 265 B 0 B
assets/css/web-stories-widget-rtl.css 489 B 0 B
assets/css/web-stories-widget.css 489 B 0 B
assets/js/carousel-view.js 3.72 kB 0 B
assets/js/chunk-fonts-********************.js 45.4 kB 0 B
assets/js/chunk-web-stories-template-0-********************.js 7.01 kB 0 B
assets/js/chunk-web-stories-template-1-********************.js 8.58 kB 0 B
assets/js/chunk-web-stories-template-2-********************.js 7.89 kB 0 B
assets/js/chunk-web-stories-template-3-********************.js 8.68 kB 0 B
assets/js/chunk-web-stories-template-4-********************.js 9.76 kB 0 B
assets/js/chunk-web-stories-template-5-********************.js 6.08 kB 0 B
assets/js/chunk-web-stories-template-6-********************.js 8.13 kB 0 B
assets/js/chunk-web-stories-template-7-********************.js 7.89 kB 0 B
assets/js/chunk-web-stories-textset-0-********************.js 5.29 kB 0 B
assets/js/chunk-web-stories-textset-1-********************.js 6.87 kB 0 B
assets/js/chunk-web-stories-textset-2-********************.js 7.92 kB 0 B
assets/js/chunk-web-stories-textset-3-********************.js 15.4 kB 0 B
assets/js/chunk-web-stories-textset-4-********************.js 4.43 kB 0 B
assets/js/chunk-web-stories-textset-5-********************.js 5.71 kB 0 B
assets/js/chunk-web-stories-textset-6-********************.js 5.5 kB 0 B
assets/js/chunk-web-stories-textset-7-********************.js 10.4 kB 0 B
assets/js/edit-story.js 516 kB 0 B
assets/js/lightbox.js 986 B 0 B
assets/js/stories-dashboard.js 433 kB 0 B
assets/js/tinymce-button.js 3.48 kB 0 B
assets/js/vendors-chunk-ffmpeg-********************.js 5.61 kB 0 B
assets/js/vendors-edit-story-********************.js 61.4 kB 0 B
assets/js/vendors-edit-story-stories-dashboard-********************.js 258 kB 0 B
assets/js/web-stories-activation-notice.js 65.1 kB 0 B
assets/js/web-stories-block.js 582 kB 0 B
assets/js/web-stories-embed.js 493 B 0 B
assets/js/web-stories-widget.js 984 B 0 B

compressed-size-action

@westonruter
Copy link
Collaborator

I am interested to know the amp plugin handles multisite.

As of AMP 2.1 we actually no longer rely on rewrite rules at all. We didn't have a good multisite solution before. Users would have to manually flush their rewrite rules for each site on the network since we only flushed rules at the activation hook, which would only work in a non-multisite context.

In 2.1, we do our own rewrite logic which allows us much more flexibility to add /amp/ or ?amp=1 to any URL, or to use entirely custom paired URL schemes, including use of subdomains or path prefixes. This was introduced in ampproject/amp-wp#5558.

@@ -36,7 +38,7 @@
*
* @package Google\Web_Stories\User
*/
class Capabilities implements Activateable, Deactivateable {
class Capabilities implements Activateable, Deactivateable, Initialize_Site, Delete_Site {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this will have any effect, because Capabilities is not a service, and these interfaces are all meant to be used on services.

Since it`s not a service, there's no way the plugin can know it needs to instantiate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was looking into this last night. You are right as the unit tests failed. It is a nice pattern, so I would like to use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to just turn Capabilities into a Service without much work. Just make sure you check all the places where you're using it to ensure it still works, and keep in mind that it will be shared by default if retrieved through the Services container, so it might make sense to just build it as a shared service right away.

@@ -35,7 +36,7 @@
*
* @package Google\Web_Stories
*/
class Database_Upgrader extends Service_Base implements Activateable {
class Database_Upgrader extends Service_Base implements Activateable, Initialize_Site {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this runs on admin_init, it won't necessarily be available during activation or initialization (think WP-CLI context).

We could change the registration action to init though and call is_admin() in register().
activate() would then run the migration directly and not call register().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, this is what I get for developing something at 11pm without testing it.

@spacedmonkey
Copy link
Contributor Author

As of AMP 2.1 we actually no longer rely on rewrite rules at all. We didn't have a good multisite solution before. Users would have to manually flush their rewrite rules for each site on the network since we only flushed rules at the activation hook, which would only work in a non-multisite context.

This is less about flushing rewrite rules. To be honest, switch_to_site and then a rewrite rule flush, would like not work anyway. It is more about running activation / decactivation hooks when site is deleted/created. In our case, creating user roles and running database migrations.

Surprised to hear a lack of multisite support. I willing to help in this context as maintainer of multisite in core.

@schlessera
Copy link
Contributor

We do have multisite support for some parts of the plugin. The lack of multisite support was for the rewrite rules, which are not used anymore.

We have code in place for clean up on deactivation across multisites, for example: https://github.com/ampproject/amp-wp/blob/develop/src/BackgroundTask/BackgroundTaskDeactivator.php

What we are missing though is actual tests for multisite: ampproject/amp-wp#5701

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants