2010-01-06 05:02:57 +01:00
|
|
|
<?php
|
2010-03-03 08:04:25 +01:00
|
|
|
/**
|
|
|
|
* Sets up the default filters and actions for Multisite.
|
|
|
|
*
|
|
|
|
* If you need to remove a default hook, this file will give you the priority
|
|
|
|
* for which to use to remove the hook.
|
|
|
|
*
|
|
|
|
* Not all of the Multisite default hooks are found in ms-default-filters.php
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Multisite
|
|
|
|
* @see default-filters.php
|
2010-04-04 15:29:35 +02:00
|
|
|
* @since 3.0.0
|
2010-03-03 08:04:25 +01:00
|
|
|
*/
|
|
|
|
|
2015-05-26 23:51:31 +02:00
|
|
|
add_action( 'init', 'ms_subdomain_constants' );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Functions.
|
2015-01-12 17:40:23 +01:00
|
|
|
add_action( 'update_option_blog_public', 'update_blog_public', 10, 2 );
|
|
|
|
add_filter( 'option_users_can_register', 'users_can_register_signup_filter' );
|
|
|
|
add_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Users.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_filter( 'wpmu_validate_user_signup', 'signup_nonce_check' );
|
|
|
|
add_action( 'init', 'maybe_add_existing_user_to_blog' );
|
|
|
|
add_action( 'wpmu_new_user', 'newuser_notify_siteadmin' );
|
|
|
|
add_action( 'wpmu_activate_user', 'add_new_user_to_blog', 10, 3 );
|
2015-09-14 05:28:24 +02:00
|
|
|
add_action( 'wpmu_activate_user', 'wpmu_welcome_user_notification', 10, 3 );
|
|
|
|
add_action( 'after_signup_user', 'wpmu_signup_user_notification', 10, 4 );
|
2017-12-01 00:11:00 +01:00
|
|
|
add_action( 'network_site_new_created_user', 'wp_send_new_user_notifications' );
|
2015-09-17 00:19:24 +02:00
|
|
|
add_action( 'network_site_users_created_user', 'wp_send_new_user_notifications' );
|
2017-12-01 00:11:00 +01:00
|
|
|
add_action( 'network_user_new_created_user', 'wp_send_new_user_notifications' );
|
2013-09-25 05:14:09 +02:00
|
|
|
add_filter( 'sanitize_user', 'strtolower' );
|
2020-07-05 13:21:03 +02:00
|
|
|
add_action( 'deleted_user', 'wp_delete_signup_on_user_delete', 10, 3 );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Roles.
|
2017-09-27 23:44:44 +02:00
|
|
|
add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Blogs.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_filter( 'wpmu_validate_blog_signup', 'signup_nonce_check' );
|
2015-09-14 05:28:24 +02:00
|
|
|
add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 );
|
|
|
|
add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 );
|
Multisite: Complete the new CRUD API for managing sites.
New functions `wp_insert_site( $data )`, `wp_update_site( $id, $data )` and `wp_delete_site( $id )` are introduced to manage site rows in the `wp_blogs` table, forming the new CRUD API together with the existing `get_site()` / `get_sites()`. The new API provides various benefits over the previously existing API, fixing several cache invalidation issues and being hook-driven so that normalization and validation of the passed data can be fully customized.
New hooks introduced as part of this are the actions `wp_insert_site`, `wp_update_site`, `wp_delete_site`, `wp_validate_site_data` and the filter `wp_normalize_site_data`.
At this point, `wp_insert_site()` does not handle setting up the site's database tables, and `wp_delete_site()` does not handle dropping the site's database tables, so the two can not yet be used directly as full replacements of `wpmu_create_blog()` and `wpmu_delete_blog()`. Managing the site's database tables will be added via hooks as part of the follow-up ticket #41333.
The existing functions `wpmu_create_blog()`, `update_blog_details()`, and `wpmu_delete_blog()` make use of the respective new counterpart and will be obsolete once #41333 has been completed.
Props flixos90, jeremyfelt, spacedmonkey.
Fixes #40364.
Built from https://develop.svn.wordpress.org/trunk@43548
git-svn-id: http://core.svn.wordpress.org/trunk@43377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-08-01 15:06:26 +02:00
|
|
|
add_filter( 'wp_normalize_site_data', 'wp_normalize_site_data', 10, 1 );
|
|
|
|
add_action( 'wp_validate_site_data', 'wp_validate_site_data', 10, 3 );
|
|
|
|
add_action( 'wp_insert_site', 'wp_maybe_update_network_site_counts_on_update', 10, 1 );
|
|
|
|
add_action( 'wp_update_site', 'wp_maybe_update_network_site_counts_on_update', 10, 2 );
|
|
|
|
add_action( 'wp_delete_site', 'wp_maybe_update_network_site_counts_on_update', 10, 1 );
|
|
|
|
add_action( 'wp_insert_site', 'wp_maybe_transition_site_statuses_on_update', 10, 1 );
|
|
|
|
add_action( 'wp_update_site', 'wp_maybe_transition_site_statuses_on_update', 10, 2 );
|
|
|
|
add_action( 'wp_update_site', 'wp_maybe_clean_new_site_cache_on_update', 10, 2 );
|
Multisite: Introduce a site initialization and uninitialization API.
This changeset makes the new CRUD API for sites introduced in [43548] usable for real-world sites. A new function `wp_initialize_site()`, which takes care of creating a site's database tables and populating them with initial values, is hooked into the site insertion process that is initiated when calling `wp_insert_site()`. Similarly, a new function `wp_uninitialize_site()`, which takes care of dropping a site's database tables, is hooked into the site deletion process that is initiated when calling `wp_delete_site()`.
A new function `wp_is_site_initialized()` completes the API, allowing to check whether a site is initialized. Since this function always makes a database request in its default behavior, it should be called with caution. Plugins that would like to use site initialization in special ways can leverage a `pre_wp_is_site_initialized` filter to alter that default behavior.
The separate handling of the site's row in the `wp_blogs` database table and the actual site setup allows for more flexibility in controlling whether or how a site's data is set up. For example, a unit test that only checks data from the site's database table row can unhook the site initialization process to improve performance. At the same time, developers consuming the new sites API only need to know about the CRUD functions, since the initialization and uninitialization processes happen internally.
With this changeset, the foundation for a sites REST API endpoint is fully available. The previously recommended functions `wpmu_create_blog()` and `wpmu_delete_blog()` now call the new respective function internally. Further follow-up work to this includes replacing calls to `wpmu_create_blog()` with `wp_insert_site()`, `update_blog_details()` with `wp_update_site()` and `wpmu_delete_blog()` with `wp_delete_blog()` throughout the codebase.
As a side-effect of this work, the `wpmu_new_blog`, `delete_blog`, and `deleted_blog` actions and the `install_blog()` function have been deprecated.
Fixes #41333. See #40364.
Built from https://develop.svn.wordpress.org/trunk@43654
git-svn-id: http://core.svn.wordpress.org/trunk@43483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-09-24 17:09:26 +02:00
|
|
|
add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 );
|
|
|
|
add_action( 'wp_initialize_site', 'wpmu_log_new_registrations', 100, 2 );
|
|
|
|
add_action( 'wp_initialize_site', 'newblog_notify_siteadmin', 100, 1 );
|
|
|
|
add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
|
Multisite: Complete the new CRUD API for managing sites.
New functions `wp_insert_site( $data )`, `wp_update_site( $id, $data )` and `wp_delete_site( $id )` are introduced to manage site rows in the `wp_blogs` table, forming the new CRUD API together with the existing `get_site()` / `get_sites()`. The new API provides various benefits over the previously existing API, fixing several cache invalidation issues and being hook-driven so that normalization and validation of the passed data can be fully customized.
New hooks introduced as part of this are the actions `wp_insert_site`, `wp_update_site`, `wp_delete_site`, `wp_validate_site_data` and the filter `wp_normalize_site_data`.
At this point, `wp_insert_site()` does not handle setting up the site's database tables, and `wp_delete_site()` does not handle dropping the site's database tables, so the two can not yet be used directly as full replacements of `wpmu_create_blog()` and `wpmu_delete_blog()`. Managing the site's database tables will be added via hooks as part of the follow-up ticket #41333.
The existing functions `wpmu_create_blog()`, `update_blog_details()`, and `wpmu_delete_blog()` make use of the respective new counterpart and will be obsolete once #41333 has been completed.
Props flixos90, jeremyfelt, spacedmonkey.
Fixes #40364.
Built from https://develop.svn.wordpress.org/trunk@43548
git-svn-id: http://core.svn.wordpress.org/trunk@43377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-08-01 15:06:26 +02:00
|
|
|
add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Site meta.
|
2019-01-08 09:48:48 +01:00
|
|
|
add_action( 'added_blog_meta', 'wp_cache_set_sites_last_changed' );
|
|
|
|
add_action( 'updated_blog_meta', 'wp_cache_set_sites_last_changed' );
|
|
|
|
add_action( 'deleted_blog_meta', 'wp_cache_set_sites_last_changed' );
|
|
|
|
add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'add_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'update_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'delete_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'get_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'update_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'delete_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Register nonce.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Template.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_action( 'template_redirect', 'maybe_redirect_404' );
|
|
|
|
add_filter( 'allowed_redirect_hosts', 'redirect_this_site' );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Administration.
|
Posts, Post Types: Pass the post object to `_update_posts_count_on_delete()`.
The function checks the status of the post being deleted, and then only calls `update_posts_count()` if the deleted post was previously published, as the update query would be unnecessary otherwise.
However, by the time the function runs, the post is already deleted from the database, and the post status check fails.
This commit uses the previously retrieved post object for the status check, so that the function proceeds as expected.
Includes updating the unit test to call `wp_delete_post()` with the `$force_delete` argument, so that the post is actually deleted, not trashed, and the `after_delete_post` action is run.
Follow-up to [28835], [52207], [54760], [54762].
Fixes #57023.
Built from https://develop.svn.wordpress.org/trunk@55419
git-svn-id: http://core.svn.wordpress.org/trunk@54952 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-24 02:23:20 +01:00
|
|
|
add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 );
|
2012-04-13 19:30:37 +02:00
|
|
|
add_action( 'delete_post', '_update_blog_date_on_post_delete' );
|
2011-11-03 18:06:45 +01:00
|
|
|
add_action( 'transition_post_status', '_update_blog_date_on_post_publish', 10, 3 );
|
2017-10-02 05:09:44 +02:00
|
|
|
add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
|
2013-09-25 18:21:09 +02:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Counts.
|
2017-12-01 00:11:00 +01:00
|
|
|
add_action( 'admin_init', 'wp_schedule_update_network_counts' );
|
2017-05-09 19:15:43 +02:00
|
|
|
add_action( 'update_network_counts', 'wp_update_network_counts', 10, 0 );
|
Users: Introduce the concept of a large site to single site installations.
Currently in WordPress multisite there is a concept of large networks. The function `wp_is_large_network` is used to determine if a network has a large number of sites or users. If a network is marked as large, then
expensive queries to calculate user counts are not run on page load but deferred to scheduled events. However there are a number of places in a single site installation where this functionality would also be useful, as
expensive calls to count users and roles can make screens in the admin extremely slow.
In this change, the `get_user_count` function and related functionality around it is ported to be available in a single site context. This means that expensive calls to the `count_users` function are replaced with
calls to `get_user_count`. This change also includes a new function called `wp_is_large_user_count` and a filter of the same name, to mark if a site is large.
Props johnbillion, Spacedmonkey, Mista-Flo, lumpysimon, tharsheblows, obenland, miss_jwo, jrchamp, flixos90, macbookandrew, pento, desrosj, johnjamesjacoby, jb510, davidbaumwald, costdev.
Fixes #38741.
Built from https://develop.svn.wordpress.org/trunk@53011
git-svn-id: http://core.svn.wordpress.org/trunk@52600 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-29 14:42:13 +02:00
|
|
|
foreach ( array( 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
|
2017-05-09 19:15:43 +02:00
|
|
|
add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
Users: Introduce the concept of a large site to single site installations.
Currently in WordPress multisite there is a concept of large networks. The function `wp_is_large_network` is used to determine if a network has a large number of sites or users. If a network is marked as large, then
expensive queries to calculate user counts are not run on page load but deferred to scheduled events. However there are a number of places in a single site installation where this functionality would also be useful, as
expensive calls to count users and roles can make screens in the admin extremely slow.
In this change, the `get_user_count` function and related functionality around it is ported to be available in a single site context. This means that expensive calls to the `count_users` function are replaced with
calls to `get_user_count`. This change also includes a new function called `wp_is_large_user_count` and a filter of the same name, to mark if a site is large.
Props johnbillion, Spacedmonkey, Mista-Flo, lumpysimon, tharsheblows, obenland, miss_jwo, jrchamp, flixos90, macbookandrew, pento, desrosj, johnjamesjacoby, jb510, davidbaumwald, costdev.
Fixes #38741.
Built from https://develop.svn.wordpress.org/trunk@53011
git-svn-id: http://core.svn.wordpress.org/trunk@52600 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-29 14:42:13 +02:00
|
|
|
|
|
|
|
// These counts are handled by wp_update_network_counts() on Multisite:
|
|
|
|
remove_action( 'admin_init', 'wp_schedule_update_user_counts' );
|
|
|
|
remove_action( 'wp_update_user_counts', 'wp_schedule_update_user_counts' );
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
foreach ( array( 'make_spam_blog', 'make_ham_blog', 'archive_blog', 'unarchive_blog', 'make_delete_blog', 'make_undelete_blog' ) as $action ) {
|
2017-05-09 19:15:43 +02:00
|
|
|
add_action( $action, 'wp_maybe_update_network_site_counts', 10, 0 );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2013-09-25 18:21:09 +02:00
|
|
|
unset( $action );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Files.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_filter( 'wp_upload_bits', 'upload_is_file_too_big' );
|
|
|
|
add_filter( 'import_upload_size_limit', 'fix_import_form_size' );
|
|
|
|
add_filter( 'upload_mimes', 'check_upload_mimes' );
|
2010-05-04 00:58:04 +02:00
|
|
|
add_filter( 'upload_size_limit', 'upload_size_limit_filter' );
|
2012-07-10 15:33:44 +02:00
|
|
|
add_action( 'upload_ui_over_quota', 'multisite_over_quota_message' );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Mail.
|
2010-02-25 22:57:38 +01:00
|
|
|
add_action( 'phpmailer_init', 'fix_phpmailer_messageid' );
|
2010-02-25 22:56:28 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Disable somethings by default for multisite.
|
2010-02-25 22:56:28 +01:00
|
|
|
add_filter( 'enable_update_services_configuration', '__return_false' );
|
2020-01-29 01:45:18 +01:00
|
|
|
if ( ! defined( 'POST_BY_EMAIL' ) || ! POST_BY_EMAIL ) { // Back compat constant.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_filter( 'enable_post_by_email_configuration', '__return_false' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2020-01-29 01:45:18 +01:00
|
|
|
if ( ! defined( 'EDIT_ANY_USER' ) || ! EDIT_ANY_USER ) { // Back compat constant.
|
2010-03-03 08:04:25 +01:00
|
|
|
add_filter( 'enable_edit_any_user_configuration', '__return_false' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-09-09 04:43:18 +02:00
|
|
|
add_filter( 'force_filtered_html_on_import', '__return_true' );
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// WP_HOME and WP_SITEURL should not have any effect in MS.
|
2010-05-08 21:31:42 +02:00
|
|
|
remove_filter( 'option_siteurl', '_config_wp_siteurl' );
|
2017-12-01 00:11:00 +01:00
|
|
|
remove_filter( 'option_home', '_config_wp_home' );
|
2012-09-12 00:22:20 +02:00
|
|
|
|
2017-03-19 17:22:45 +01:00
|
|
|
// Some options changes should trigger site details refresh.
|
2017-12-01 00:11:00 +01:00
|
|
|
add_action( 'update_option_blogname', 'clean_site_details_cache', 10, 0 );
|
|
|
|
add_action( 'update_option_siteurl', 'clean_site_details_cache', 10, 0 );
|
2017-03-25 16:31:43 +01:00
|
|
|
add_action( 'update_option_post_count', 'clean_site_details_cache', 10, 0 );
|
2017-12-01 00:11:00 +01:00
|
|
|
add_action( 'update_option_home', 'clean_site_details_cache', 10, 0 );
|
2014-06-28 06:07:16 +02:00
|
|
|
|
2012-09-12 00:22:20 +02:00
|
|
|
// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used.
|
2013-07-31 08:44:57 +02:00
|
|
|
add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
|
|
|
|
|
General: Remove “whitelist” and “blacklist” in favor of more clear and inclusive language.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”
With this commit, all occurrences of “whitelist” and “blacklist” (with the single exception of the `$new_whitelist_options` global variable) are removed. A new ticket has been opened to explore renaming the `$new_whitelist_options` variable (#50434).
Changing to more specific names or rewording sentences containing these terms not only makes the code more inclusive, but also helps provide clarity. These terms are often ambiguous. What is being blocked or allowed is not always immediately clear. This can make it more difficult for non-native English speakers to read through the codebase.
Words matter. If one contributor feels more welcome because these terms are removed, this was worth the effort.
Props strangerstudios, jorbin, desrosj, joemcgill, timothyblynjacobs, ocean90, ayeshrajans, davidbaumwald, earnjam.
See #48900, #50434.
Fixes #50413.
Built from https://develop.svn.wordpress.org/trunk@48121
git-svn-id: http://core.svn.wordpress.org/trunk@47890 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-22 19:26:13 +02:00
|
|
|
// Allow multisite domains for HTTP requests.
|
2013-07-31 08:44:57 +02:00
|
|
|
add_filter( 'http_request_host_is_external', 'ms_allowed_http_request_hosts', 20, 2 );
|