Skip to content

Commit

Permalink
Merge pull request #1177 from xwp/tests/blogs-connector
Browse files Browse the repository at this point in the history
Blog connector test implemented and connector updated.
  • Loading branch information
kidunot89 authored Jan 5, 2021
2 parents 3b79fc8 + 82b7573 commit 9a1dff0
Show file tree
Hide file tree
Showing 2 changed files with 512 additions and 24 deletions.
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'
);
}

/**
* 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

0 comments on commit 9a1dff0

Please sign in to comment.