Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/161 - Edit: refresh "Site Assignment" metabox contents. #174

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 53 additions & 20 deletions wp-multi-network/includes/metaboxes/edit-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ function wpmn_edit_network_new_site_metabox() {
* @param WP_Network $network Optional. Network object. Default null.
*/
function wpmn_edit_network_assign_sites_metabox( $network = null ) {

// Get sites in this Network.
$to = get_sites(
array(
'site__not_in' => get_main_site_id( $network->id ),
'network_id' => $network->id,
'network_id' => $network->id,
)
);

// Get sites not in this Network.
$from = get_sites(
array(
'network__not_in' => array( $network->id ),
Expand All @@ -97,48 +99,79 @@ function wpmn_edit_network_assign_sites_metabox( $network = null ) {
<table class="assign-sites widefat">
<thead>
<tr>
<th><?php esc_html_e( 'Available Subsites', 'wp-multi-network' ); ?></th>
<th><?php esc_html_e( 'Sites in this Network', 'wp-multi-network' ); ?></th>
<th>&nbsp;</th>
<th><?php esc_html_e( 'Network Subsites', 'wp-multi-network' ); ?></th>
<th><?php esc_html_e( 'Sites not in this Network', 'wp-multi-network' ); ?></th>
</tr>
</thead>
<tr>
<td class="column-available">
<select name="from[]" id="from" multiple>
<td class="column-assigned">
<select name="to[]" id="to" multiple>
<?php

<?php foreach ( $from as $site ) : ?>
// Loop through to sites.
foreach ( $to as $site ) :

<?php if ( ( (int) $site->network_id !== (int) $network->id ) && ! is_main_site_for_network( $site->id ) ) : ?>
// Is main?
$is_main = is_main_site_for_network( $site->id );

<option value="<?php echo esc_attr( $site->id ); ?>">
<?php echo esc_html( sprintf( '%1$s (%2$s%3$s)', $site->name, $site->domain, $site->path ) ); ?>
// Get main helper text.
$main_text = ! empty( $is_main )
? esc_attr__( ' (Primary)', 'wp-multi-network' )
: '';

if ( (int) $site->network_id === (int) $network->id ) :

?>

<option value="<?php echo esc_attr( $site->id ); ?>" <?php disabled( $is_main ); ?>>
<?php echo esc_html( sprintf( '%1$s - %2$s%3$s%4$s', get_blog_option( $site->id, 'blogname' ), $site->domain, $site->path, $main_text ) ); ?>
</option>

<?php endif; ?>
<?php

endif;

<?php endforeach; ?>
endforeach;

?>
</select>
</td>
<td class="column-actions">
<input type="button" name="assign" id="assign" class="button assign" value="&rarr;">
<input type="button" name="unassign" id="unassign" class="button unassign" value="&larr;">
</td>
<td class="column-assigned">
<select name="to[]" id="to" multiple>
<td class="column-available">
<select name="from[]" id="from" multiple>
<?php

// Loop through from sites.
foreach ( $from as $site ) :

// Is main?
$is_main = is_main_site_for_network( $site->id );

<?php foreach ( $to as $site ) : ?>
// Get main helper text.
$main_text = ! empty( $is_main )
? esc_attr__( ' (Primary)', 'wp-multi-network' )
: '';

<?php if ( (int) $site->network_id === (int) $network->id ) : ?>
// Omit main sites for now.
if ( ( (int) $site->network_id !== (int) $network->id ) && empty( $is_main ) ) :

<option value="<?php echo esc_attr( $site->id ); ?>" <?php disabled( is_main_site_for_network( $site->id ) ); ?>>
<?php echo esc_html( sprintf( '%1$s (%2$s%3$s)', $site->name, $site->domain, $site->path ) ); ?>
?>

<option value="<?php echo esc_attr( $site->id ); ?>">
<?php echo esc_html( sprintf( '%1$s - %2$s%3$s%4$s', get_blog_option( $site->id, 'blog_ame' ), $site->domain, $site->path, $main_text ) ); ?>
</option>

<?php endif; ?>
<?php

endif;

<?php endforeach; ?>
endforeach;

?>
</select>
</td>
</tr>
Expand Down