WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 19 months ago

Last modified 19 months ago

#20305 closed defect (bug) (fixed)

update_blog_status should also handle delete/undelete cases

Reported by: Kyrylo Owned by: 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 20 months ago.
20305-ut.diff (10.7 KB) - added by ryan 19 months ago.
Unit tests
20305.diff (3.3 KB) - added by ryan 19 months ago.

Download all attachments as: .zip

Change History (14)

comment:1 Kyrylo2 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 );
...

comment:2 Kyrylo2 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.

comment:3 Kyrylo2 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 2 years ago by Kyrylo (previous) (diff)

comment:4 kawauso2 years ago

Submitting patches: *nix / Windows

comment:5 helenyhou2 years ago

  • Keywords needs-patch added; has-patch removed

comment:7 wonderboymusic20 months 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.

comment:8 wonderboymusic20 months ago

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

comment:9 ryan19 months ago

The double archived came in with [15836]

ryan19 months ago

Unit tests

ryan19 months ago

comment:10 ryan19 months 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.