Skip to:

Opened 6 years ago

Closed 4 years ago

#7984 closed defect (bug) (fixed)

Core multisite changes require mods to BP

Reported by: boonebgorges's profile boonebgorges Owned by: imath's profile imath
Milestone: 6.0.0 Priority: normal
Severity: normal Version:
Component: Blogs Keywords: has-patch commit


In preparation for 'site' support in the core REST API, WordPress has made some internal changes surrounding site creation in Multisite. See and especially for details. Summary:

  • The new canonical way to create a site is wp_initialize_site(), and other methods (wpmu_create_blog() etc) will soon be converted to wrappers and deprecated
  • WPMU hooks like wpmu_new_blog are deprecated

In the medium term, we should migrate over to the new methods, though doing this will require some WP capability sniffing. (For example, I'm not sure of an elegant way to hook to wpmu_new_blog only if the new wp_initialize_site hook is not available.)

In the short term, we should add deprecation notices to our automated tests so that they pass.

Attachments (1)

7984.patch (23.2 KB) - added by imath 4 years ago.

Download all attachments as: .zip

Change History (14)

#1 @boonebgorges
6 years ago

In 12242:

Tests: When tearing down test fixtures, use wp_uninitialize_site() if available.

See #7984.

#2 @boonebgorges
6 years ago

In 12243:

Tests: Add deprecation notices for wpmu_new_blog and delete_blog hook usage.

See #7984.

#3 @boonebgorges
6 years ago

In 12245:

Tests: More targeted 'wpmu_new_blog' deprecation notices.

When a test could run under non-MS, the expectedDeprecated annotation
cannot apply to the entire test.

See #7984.

#4 @boonebgorges
6 years ago

In 12246:

Tests: Move wpmu_new_blog and delete_blog expectedDeprecated calls into test logic.

Use of the @expectedDeprecated annotation means that the deprecation notice is
expected across all versions of WordPress, while we in fact need to suppress the
notices only on WP 5.0+.

See #7984.

#5 @boonebgorges
6 years ago

In 12247:

Tests: More site-creation deprecation fine-tuning.

See #7984.

#6 @boonebgorges
6 years ago

  • Keywords needs-patch added
  • Milestone changed from 4.0 to Up Next

The tests improvements will ship with 4.0, but we'll need more work to use the new functionality. Since the new functionality isn't slated to land in WP until 5.1 anyway, there's no rush.

#7 @imath
5 years ago

  • Milestone changed from Up Next to 6.0.0

Let's try to stop using this deprecated hook when BuddyPress is activated on WordPress >= 5.1 before releasing BP 6.0.

#8 @espellcaste
4 years ago

@imath Are you still considering this ticket for the 6.0?

#9 @imath
4 years ago

Yes :)

4 years ago

#10 @imath
4 years ago

  • Keywords has-patch 2nd-opinion added; needs-patch removed

Hi !

I believe now WordPress is about to publish 5.4, we should really stop using hooks that were deprecated in WordPress 5.1. That's why I'd really like us to fix this ticket.

In 7984.patch I'm introducing 2 hooks that are doing the needed compatibility stuff. I'm pretty confident about this patch as I've run successfully the unit tests (Multisite and regular configs).

The 2 new hooks are :

  • 'bp_insert_site' => to mimic what was doing 'wpmu_new_blog',
  • 'bp_delete_site' => to mimic what was doing 'delete_blog'.

@boonebgorges could you take a look at it soon ☺️. I'd feel more secure about committing this after you had eyes on the patch. Thanks in advance.

#11 @boonebgorges
4 years ago

  • Keywords commit added; 2nd-opinion removed

Thanks for working on this, @imath.

It's a shame to have to introduce all of this infrastructure just so that we can support both versions without deprecation notices, when we'll probably drop support for < 5.1 in one of the next few major BP releases. Mais c'est la vie :)

I want to make the following observations clear, for the sake of posterity.

  1. The weird function signatures for the bp_insert_site() and bp_delete_site() functions help to ensure that (a) we can accept arguments from the new WP hooks, while (b) continuing to pass the legacy arguments to our new hooks. This means less internal refactoring (eg, we don't have to rewrite bp_blogs_remove_blog() to accept WP's new filter args) as well as easier swap-outs for BP plugin developers who want to move away from WP's legacy hooks.
  1. The bp_insert_site_hook() and bp_delete_site_hook() functions will, after we update the minimum WP version to 5.1, always return the new hook names. At that time, we may want to clarify the inline docs a bit - we probably won't be able to remove the functions altogether, but it'll be helpful for future developers to have clear explanations of this part of the codebase that is essentially temporary.
  1. The bp_delete_site_no_tables_drop() trick reflects the fact the old wpmu_delete_blog() function had two different users: (a) to mark a site deleted in the database, or to drop the tables from the database. In WP 5.1+, the operations are separate: wp_update_site() is used to set a site to deleted, while wp_delete_site() is used to drop database tables. For compatibility with the previous behavior of the delete_blog hook (where BP removes its blog-related data regardless of whether we're in situation (a) or (b)) we need to have two different callbacks.

#12 @imath
4 years ago

Thanks a lot for your feedback and great explanations @boonebgorges 👍. I totally agree when you say "dommage mais c'est la vie". I'm going to commit the changes asap.

#13 @imath
4 years ago

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

In 12606:

Adapt BuddyPress to WP 5.1.0 multisite changes & deprecations

Version 5.1.0 of WordPress deprecated two hooks (wpmu_new_blog & delete_blog) BuddyPress is using to run some of the BP Blogs component's features. In order to preserve these features for the versions of WordPress we support and that are older than 5.1.0 as well as start using the replacement hooks introduced in 5.1.0 (wp_initialize_site & wp_validate_site_deletion), we are introducing a compatibility mechanism to make sure BuddyPress is using the right hooks depending on the installed WordPress it's activated on.

Props boonebgorges & I ;)

Fixes #7984

Note: See TracTickets for help on using tickets.