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

Blog connector test implemented and connector updated. #1177

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions connectors/class-connector-blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Connector_Blogs extends Connector {
* @var array
*/
public $actions = array(
'wpmu_new_blog',
'wp_initialize_site',
'wp_delete_site',
'wpmu_activate_blog',
'wpmu_new_user',
'add_user_to_blog',
Expand Down Expand Up @@ -127,14 +128,16 @@ public function action_links( $links, $record ) {
}

/**
* Blog created
* Blog created.
*
* @action wpmu_new_blog
* @action wp_initialize_site
*
* @param int $blog_id Blog ID.
* @param WP_Site $new_site New site object.
* @param array $args Arguments for the initialization.
*/
public function callback_wpmu_new_blog( $blog_id ) {
$blog = get_blog_details( $blog_id );
public function callback_wp_initialize_site( $new_site, $args ) {
$blogname = ! empty( $args['title'] ) ? $args['title'] : $new_site->blogname;
$blog_id = $new_site->blog_id;

$this->log(
/* translators: %s: site name (e.g. "FooBar Blog") */
Expand All @@ -144,14 +147,42 @@ public function callback_wpmu_new_blog( $blog_id ) {
'stream'
),
array(
'site_name' => $blog->blogname,
'site_name' => ! empty( $blogname ) ? $blogname : 'Site %d',
'siteurl' => $new_site->siteurl,
'id' => $new_site->blog_id,
),
$blog_id,
sanitize_key( $blog->blogname ),
sanitize_key( $blogname ),
'created'
);
}

/**
* A site has been deleted from the database.
*
* @action wp_deleted_site
*
* @param WP_Site $old_site Deleted site object.
*/
public function callback_wp_delete_site( $old_site ) {
$this->log(
/* translators: %s: site name (e.g. "FooBar Blog") */
_x(
'"%s" site was deleted',
'1. Site name',
'stream'
),
array(
'site_name' => $old_site->blogname,
'siteurl' => $old_site->siteurl,
'id' => $old_site->blog_id,
),
$old_site->blog_id,
sanitize_key( $old_site->blogname ),
'deleted'
);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dero @johnbillion This callback was added to resolve #1175. Please take a look.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @kidunot89 -- this callback will add an appropriate log entry, but AFAICT won't prevent the related "User removed" etc. entries from being logged, which can really clutter the log when a blog with dozens of users is removed.

I'm OK approving this PR as is, but I think we should keep #1175 open until we're able to bundle up those excessive individual log entries somehow. I'm thinking perhaps we find a way to just log "XYZ users were removed from the ABC site."?

What do you guys think?

/**
* Blog registered
*
Expand All @@ -161,7 +192,7 @@ public function callback_wpmu_new_blog( $blog_id ) {
* @param int $user_id User ID.
*/
public function callback_wpmu_activate_blog( $blog_id, $user_id ) {
$blog = get_blog_details( $blog_id );
$blog = get_site( $blog_id );

$this->log(
/* translators: %s: site name (e.g. "FooBar Blog") */
Expand All @@ -172,6 +203,8 @@ public function callback_wpmu_activate_blog( $blog_id, $user_id ) {
),
array(
'site_name' => $blog->blogname,
'siteurl' => $blog->siteurl,
'id' => $blog->blog_id,
),
$blog_id,
sanitize_key( $blog->blogname ),
Expand All @@ -190,7 +223,7 @@ public function callback_wpmu_activate_blog( $blog_id, $user_id ) {
* @param int $blog_id Blog ID.
*/
public function callback_add_user_to_blog( $user_id, $role, $blog_id ) {
$blog = get_blog_details( $blog_id );
$blog = get_site( $blog_id );
$user = get_user_by( 'id', $user_id );

if ( ! is_a( $user, 'WP_User' ) ) {
Expand All @@ -207,6 +240,8 @@ public function callback_add_user_to_blog( $user_id, $role, $blog_id ) {
array(
'user_name' => $user->display_name,
'site_name' => $blog->blogname,
'siteurl' => $blog->siteurl,
'id' => $blog->blog_id,
'role_name' => $role,
),
$blog_id,
Expand All @@ -224,7 +259,7 @@ public function callback_add_user_to_blog( $user_id, $role, $blog_id ) {
* @param int $blog_id Blog ID.
*/
public function callback_remove_user_from_blog( $user_id, $blog_id ) {
$blog = get_blog_details( $blog_id );
$blog = get_site( $blog_id );
$user = get_user_by( 'id', $user_id );

if ( ! is_a( $user, 'WP_User' ) ) {
Expand All @@ -241,6 +276,8 @@ public function callback_remove_user_from_blog( $user_id, $blog_id ) {
array(
'user_name' => $user->display_name,
'site_name' => $blog->blogname,
'siteurl' => $blog->siteurl,
'id' => $blog->blog_id,
),
$blog_id,
sanitize_key( $blog->blogname ),
Expand Down Expand Up @@ -322,7 +359,7 @@ public function callback_unarchive_blog( $blog_id ) {
* @param int $blog_id Blog ID.
*/
public function callback_make_delete_blog( $blog_id ) {
$this->callback_update_blog_status( $blog_id, esc_html__( 'deleted', 'stream' ), 'deleted' );
$this->callback_update_blog_status( $blog_id, esc_html__( 'trashed', 'stream' ), 'trashed' );
}

/**
Expand All @@ -333,7 +370,7 @@ public function callback_make_delete_blog( $blog_id ) {
* @param int $blog_id Blog ID.
*/
public function callback_make_undelete_blog( $blog_id ) {
$this->callback_update_blog_status( $blog_id, esc_html__( 'restored', 'stream' ), 'updated' );
$this->callback_update_blog_status( $blog_id, esc_html__( 'restored', 'stream' ), 'restored' );
}

/**
Expand All @@ -345,7 +382,7 @@ public function callback_make_undelete_blog( $blog_id ) {
* @param string $value Status flag.
*/
public function callback_update_blog_public( $blog_id, $value ) {
if ( $value ) {
if ( absint( $value ) ) {
$status = esc_html__( 'marked as public', 'stream' );
} else {
$status = esc_html__( 'marked as private', 'stream' );
Expand All @@ -364,8 +401,7 @@ public function callback_update_blog_public( $blog_id, $value ) {
* @param string $action Action.
*/
public function callback_update_blog_status( $blog_id, $status, $action ) {
$blog = get_blog_details( $blog_id );

$blog = get_site( $blog_id );
$this->log(
/* translators: %1$s: a site name, %2$s: a blog status (e.g. "FooBar Blog", "archived") */
_x(
Expand All @@ -375,6 +411,8 @@ public function callback_update_blog_status( $blog_id, $status, $action ) {
),
array(
'site_name' => $blog->blogname,
'siteurl' => $blog->siteurl,
'id' => $blog->blog_id,
'status' => $status,
),
$blog_id,
Expand Down
Loading