-
Notifications
You must be signed in to change notification settings - Fork 178
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Interface Delete_Site. | ||
* | ||
* @package Google\Web_Stories | ||
* @copyright 2019 Alain Schlesser | ||
* @license MIT | ||
* @link https://www.mwpd.io/ | ||
*/ | ||
|
||
/** | ||
* Original code modified for this project. | ||
* | ||
* @copyright 2021 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
*/ | ||
|
||
namespace Google\Web_Stories\Infrastructure; | ||
|
||
/** | ||
* Something that can be activated. | ||
* | ||
* By tagging a service with this interface, the system will automatically hook | ||
* it up to the WordPress activation hook. | ||
* | ||
* This way, we can just add the simple interface marker and not worry about how | ||
* to wire up the code to reach that part during the static activation hook. | ||
* | ||
* @since 1.8.0 | ||
* @internal | ||
*/ | ||
interface Delete_Site { | ||
|
||
/** | ||
* Delete the service on new site ( Multisite only ) | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @return void | ||
*/ | ||
public function delete_site(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Interface Initialize_Site. | ||
* | ||
* @package Google\Web_Stories | ||
* @copyright 2019 Alain Schlesser | ||
* @license MIT | ||
* @link https://www.mwpd.io/ | ||
*/ | ||
|
||
/** | ||
* Original code modified for this project. | ||
* | ||
* @copyright 2021 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
*/ | ||
|
||
namespace Google\Web_Stories\Infrastructure; | ||
|
||
/** | ||
* Something that can be activated. | ||
* | ||
* By tagging a service with this interface, the system will automatically hook | ||
* it up to the WordPress activation hook. | ||
* | ||
* This way, we can just add the simple interface marker and not worry about how | ||
* to wire up the code to reach that part during the static activation hook. | ||
* | ||
* @since 1.8.0 | ||
* @internal | ||
*/ | ||
interface Initialize_Site { | ||
|
||
/** | ||
* Initialize the service on new site ( Multisite only ) | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @return void | ||
*/ | ||
public function initialize_site(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
|
||
use Google\Web_Stories\Infrastructure\Activateable; | ||
use Google\Web_Stories\Infrastructure\Deactivateable; | ||
use Google\Web_Stories\Infrastructure\Delete_Site; | ||
use Google\Web_Stories\Infrastructure\Initialize_Site; | ||
use Google\Web_Stories\Story_Post_Type; | ||
use WP_Role; | ||
|
||
|
@@ -36,7 +38,7 @@ | |
* | ||
* @package Google\Web_Stories\User | ||
*/ | ||
class Capabilities implements Activateable, Deactivateable { | ||
class Capabilities implements Activateable, Deactivateable, Initialize_Site, Delete_Site { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will have any effect, because Since it`s not a service, there's no way the plugin can know it needs to instantiate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to just turn |
||
/** | ||
* Activate the service. | ||
* | ||
|
@@ -57,6 +59,28 @@ public function deactivate( $network_wide ) { | |
$this->remove_caps_from_roles(); | ||
} | ||
|
||
/** | ||
* Initialize the service on new site ( Multisite only ) | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @return void | ||
*/ | ||
public function initialize_site() { | ||
$this->add_caps_to_roles(); | ||
} | ||
|
||
/** | ||
* Delete the service on new site ( Multisite only ) | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @return void | ||
*/ | ||
public function delete_site() { | ||
$this->remove_caps_from_roles(); | ||
} | ||
|
||
/** | ||
* Adds story capabilities to default user roles. | ||
* | ||
|
There was a problem hiding this comment.
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 callis_admin()
inregister()
.activate()
would then run the migration directly and not callregister()
.There was a problem hiding this comment.
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.