Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#20305 closed defect (bug) (fixed)

update_blog_status should also handle delete/undelete cases

Reported by: kyrylo's profile Kyrylo Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.2.1
Component: Multisite Keywords: dev-feedback has-patch
Focuses: Cc:

Description

function update_blog_status defined in /includes/ms-blog.php fires the following actions:

...
	if ( 'spam' == $pref )
		( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) :	do_action( 'make_ham_blog', $blog_id );
	elseif ( 'mature' == $pref )
		( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
	elseif ( 'archived' == $pref )
		( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
	elseif ( 'archived' == $pref )
		( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
...

As you see 'archived' is handled twice, while 'deleted' is not handled at all.

The the code should go as follows:

...
	if ( 'spam' == $pref )
		( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) :	do_action( 'make_ham_blog', $blog_id );
	elseif ( 'mature' == $pref )
		( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
	elseif ( 'archived' == $pref )
		( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
	elseif ( 'deleted' == $pref )
		( $value == 1 ) ? do_action( 'delete_blog', $blog_id ) : do_action( 'undelete_blog', $blog_id );
...

Please include in the next release. Thank you.

Attachments (3)

delete-undelete-actions.diff (650 bytes) - added by wonderboymusic 12 years ago.
20305-ut.diff (10.7 KB) - added by ryan 12 years ago.
Unit tests
20305.diff (3.3 KB) - added by ryan 12 years ago.

Download all attachments as: .zip

Change History (14)

#1 @Kyrylo
13 years ago

Just discovered that there is already an action 'delete_blog', which is triggered in function wpmu_delete_blog defined in /wp-admin/includes/ms.php

Thus we need to come up with better and more unique names:

...
	elseif ( 'deleted' == $pref )
		( $value == 1 ) ? do_action( 'make_delete_blog', $blog_id ) : do_action( 'make_undelete_blog', $blog_id );
...

#2 @Kyrylo
13 years ago

Then function update_blog_details defined in /includes/ms-blogs.php handles only changed on spam/ham:

...
	// If spam status changed, issue actions.
	if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) {
		if ( $details[ 'spam' ] == 1 )
			do_action( "make_spam_blog", $blog_id );
		else
			do_action( "make_ham_blog", $blog_id );
	}
...

Natural.ly, to be consistent, it should also handle archive/unarchived and delete/undelete.

#3 @Kyrylo
13 years ago

Hence the corresponding code should go into function update_blog_details defined in /includes/ms-blogs.php:

...
	// If archived status changed, issue actions.
	if ( $details[ 'archived' ] != $current_details[ 'archived' ] ) {
		if ( $details[ 'archived' ] == 1 )
			do_action( "archive_blog", $blog_id );
		else
			do_action( "unarchive_blog", $blog_id );
	}
	// If deleted status changed, issue actions.
	if ( $details[ 'deleted' ] != $current_details[ 'deleted' ] ) {
		if ( $details[ 'deleted' ] == 1 )
			do_action( "make_delete_blog", $blog_id );
		else
			do_action( "make_undelete_blog", $blog_id );
	}
...
Last edited 13 years ago by Kyrylo (previous) (diff)

#4 @kawauso
13 years ago

Submitting patches: *nix / Windows

#5 @helenyhou
13 years ago

  • Keywords needs-patch added; has-patch removed

#7 @wonderboymusic
12 years ago

  • Keywords dev-feedback added

$drop has to be true for tables to drop and this to be irreversible, should users be removed if $drop is false? They are currently.

#8 @wonderboymusic
12 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 3.5

#9 @ryan
12 years ago

The double archived came in with [15836]

@ryan
12 years ago

Unit tests

@ryan
12 years ago

#10 @ryan
12 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [22185]:

Sync actions between update_blog_details() and update_blog_status(). Add make_delete_blog and make_undelete_blog actions.

Props Kyrylo, wonderboymusic
fixes #20305

Note: See TracTickets for help on using tickets.