close

Make WordPress Core

Opened 2 years ago

Closed 7 months ago

#61029 closed defect (bug) (worksforme)

Multisite state 'Delete' can only have a value of 1or 0. Not 2. So why is 2 mentioned in the code?

Reported by: ignatiusjeroe's profile ignatiusjeroe Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords:
Focuses: multisite Cc:

Description

In function ms_site_check() @ 103 "if ( '2' == $blog->deleted )" the code checks if the site deleted state has a value of 2. But in wp-admin/network/site-info.php from line 74 to 82 the code checks the value of all states and either assigns them with a 1 or 0. I havent found anywhere in the source code were any site state could be assigned a value of 2.

So the snippet "if ( '2' == $blog->deleted )" makes no sense. Sure you can alter the state value using wp_update_site(). But that is not the answers since whenever the site is updated on wp-admin/network/site-info.php the values are validated prior to saving the the dB. And like i said, the only valid values are 1 or 0. ms_site_check() should be edited. The drop-in in the if-statement is rendered unusable cause the if-statement will fail every time.

Change History (3)

#1 Image @dd32
2 years ago

  • Component changed from General to Networks and Sites

The '2' state is a historical vestiage of Multisite.

While it's likely not used by Core today, it was previously used by WordPress MU (WordPress Multisite, pre WordPress 3.0)

Here's the earliest reference I can find to it:
https://mu.trac.wordpress.org/browser/trunk/wp-inst/wp-settings.php?rev=551&marks=198-203#L198

While this code branch could be removed (Combining deleted == 1 and deleted == 2), it would likely be at the disadvantage of breaking existing sites that were expecting that specific error page, or plugins which expected Core to handle it.

#2 Image @costdev
2 years ago

The drop-in in the if-statement is rendered unusable cause the if-statement will fail every time.

Note that the return value of get_site() is filterable using the get_site hook.

For example, the following can be used to set $deleted to '2' to differentiate between '1' a site that is no longer available, and '2' a site that has not been activated yet (i.e. it was never available). That branch will be hit, and either load WP_CONTENT_DIR . '/blog-inactive.php' if available, or output the default message.

add_filter(
  'get_site',
  static function ( $_site ) {
    $_site->deleted = '2';
    return $_site;
  }
);

#3 Image @jeremyfelt
7 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

While there is no default UI for assigning this value, injecting via filter is the only way to use the blog-inactive.php drop-in. I imagine a handful of larger multisites have taken advantage of this over the years.

I'm going to close as worksforme. It's nice to have this ticket here as documentation.

I'm also on the fence as to whether we should document this inline. That could be an option too if someone is inspired to write a concise explanation. Feel free to reopen if so. :)

Note: See TracTickets for help on using tickets.