Skip to content

Commit

Permalink
Merge branch 'master' of github.com:stuttter/wp-multi-network
Browse files Browse the repository at this point in the history
  • Loading branch information
JJJ committed Sep 19, 2024
2 parents ae3350d + f79c395 commit 374e372
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@
"wp-coding-standards/wpcs": "^2.2",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Contributors: johnjamesjacoby, flixos90, rmccue, spacedmonkey
Tags: network, sites, domains, global, admin
Requires PHP: 5.2
Requires at least: 4.9
Tested up to: 5.9
Stable tag: 2.5.0
Tested up to: 6.1
Stable tag: 2.5.2

== Description ==

Expand Down Expand Up @@ -122,6 +122,13 @@ please follow the steps in https://paulund.co.uk/wordpress-multisite-nested-path
Not much to talk about really. Check the code for details!

== Changelog ==
= 2.5.2 =
* Use get_main_site_id function instead of get_main_site_for_network.
* Tested against WordPress 6.1.

= 2.5.1 =
* Save main site on network as network option.

= 2.5.0 =
* Fix new networks sometimes not being created.
* Fix moving sites sometimes not working.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public function __construct() {
* icon in the menu bar.
*
* @since 2.2.0
* @since 3.0.0 Prevent rendering of CSS if admin bar is not shown.
*/
public function admin_print_styles() {
if ( ! is_admin_bar_showing() ) {
return;
}
?>
<style type="text/css">
#wpadminbar #wp-admin-bar-my-networks > .ab-item:first-child:before {
Expand Down
24 changes: 19 additions & 5 deletions wp-multi-network/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function get_main_site_for_network( $network = null ) {
if ( ! empty( $network->blog_id ) ) {
$primary_id = $network->blog_id;
} else {
$primary_id = wp_cache_get( "network:{$network->id}:main_site", 'site-options' );
$primary_id = get_network_option( $network->id, 'main_site' );

if ( false === $primary_id ) {
$sites = get_sites( array(
Expand All @@ -147,7 +147,7 @@ function get_main_site_for_network( $network = null ) {
$primary_id = ! empty( $sites ) ? reset( $sites ) : 0;

if ( ! empty( $primary_id ) ) {
wp_cache_add( "network:{$network->id}:main_site", $primary_id, 'site-options' );
update_network_option( $network->id, 'main_site', $primary_id );
}
}
}
Expand All @@ -167,7 +167,7 @@ function get_main_site_for_network( $network = null ) {
*/
function is_main_site_for_network( $site_id ) {
$site = get_site( $site_id );
$main = get_main_site_for_network( $site->network_id );
$main = get_main_site_id( $site->network_id );

// Bail if no site or network was found.
if ( empty( $main ) ) {
Expand Down Expand Up @@ -254,7 +254,7 @@ function switch_to_network( $new_network = 0, $validate = false ) {

// Populate extra properties if not set already.
if ( ! isset( $current_site->blog_id ) ) {
$current_site->blog_id = get_main_site_for_network( $current_site );
$current_site->blog_id = get_main_site_id( $current_site->id );
}
if ( ! isset( $current_site->site_name ) ) {
$current_site->site_name = get_network_name();
Expand Down Expand Up @@ -576,6 +576,20 @@ function add_network( $args = array() ) {
return $new_blog_id;
}

/**
* Fires after a new network blog has been added.
*
* @param int $new_blog_id ID of the added network blog.
* @param int $new_network_id ID of the added network.
* @param array $r Full associative array of network arguments.
*
* @since 2.5.3
*/
do_action( 'added_network_blog', $new_blog_id, $new_network_id, $r );

// add new blog id as network meta data against the new network
$r['network_meta']['main_site'] = $new_blog_id;

if ( empty( $r['network_meta']['site_name'] ) ) {
$r['network_meta']['site_name'] = ! empty( $r['network_name'] )
? $r['network_name']
Expand Down Expand Up @@ -699,7 +713,7 @@ function update_network( $id, $domain, $path = '' ) {
return new WP_Error( 'network_not_exist', __( 'Network does not exist.', 'wp-multi-network' ) );
}

$site_id = get_main_site_for_network( $id );
$site_id = get_main_site_id( $id );
$path = wp_sanitize_site_path( $path );

// Bail if site URL is invalid.
Expand Down
8 changes: 8 additions & 0 deletions wp-multi-network/includes/metaboxes/edit-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function wpmn_edit_network_details_metabox( $network = null ) {
?>

<table class="edit-network form-table">
<?php do_action('wpmn_edit_network_details_metabox_before_group', $network); ?>

<tr class="form-field form-required">
<th scope="row">
<label for="domain"><?php esc_html_e( 'Domain', 'wp-multi-network' ); ?></label>
Expand All @@ -43,6 +45,8 @@ function wpmn_edit_network_details_metabox( $network = null ) {
<p class="description"><?php esc_html_e( 'Use "/" if you are unsure.', 'wp-multi-network' ); ?></p>
</td>
</tr>

<?php do_action('wpmn_edit_network_details_metabox_after_group', $network); ?>
</table>

<?php
Expand All @@ -57,6 +61,8 @@ function wpmn_edit_network_new_site_metabox() {
?>

<table class="edit-network form-table">
<?php do_action('wpmn_edit_network_new_site_metabox_before_group'); ?>

<tr class="form-field form-required">
<th scope="row">
<label for="new_site"><?php esc_html_e( 'Site Name', 'wp-multi-network' ); ?>:</label>
Expand All @@ -66,6 +72,8 @@ function wpmn_edit_network_new_site_metabox() {
<p class="description"><?php esc_html_e( 'A new site needs to be created at the root of this network.', 'wp-multi-network' ); ?></p>
</td>
</tr>

<?php do_action('wpmn_edit_network_new_site_metabox_after_group'); ?>
</table>

<?php
Expand Down
4 changes: 2 additions & 2 deletions wpmn-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* Network: true
* Requires at least: 4.9
* Requires PHP: 5.2
* Tested up to: 5.8
* Version: 2.5.0
* Tested up to: 6.1
* Version: 2.5.2
*/

// Exit if accessed directly.
Expand Down

0 comments on commit 374e372

Please sign in to comment.