<?php
/**
 * Plugin Name: Network Tab Patch Test Case
 * Plugin URI:  https://core.trac.wordpress.org/ticket/15800
 * Description: Test use case for the patch to allow extension of network site tabs
 */

if ( ! is_network_admin() ) {
	return NULL;
}

add_action( 'network_admin_menu', 'ticket15800_network_site_tabs' );
function ticket15800_network_site_tabs() {

	add_filter( 'network_edit_site_tabs', 'ticket15800_filter_network_site_tabs', 10, 3 );

	if ( isset( $_GET[ 'page' ] ) && 'test_tab' === $_GET[ 'page' ] ) {
		global $_registered_pages;
		// Set true, that you have the rights to see the content
		$_registered_pages[ 'admin_page_test_tab' ] = TRUE;

		add_action( 'admin_page_test_tab', 'ticket15800_callback' );
	}
}

/**
 * Add new tab
 *
 * @param $tabs
 * @param $id
 * @param $pagenow
 *
 * @return mixed
 */
function ticket15800_filter_network_site_tabs( $tabs, $id, $pagenow ) {

	$tabs[ 'test15800-tab' ] = array(
		'label'             => __( 'Test', 'textdomain' ),
		'menu-slug'         => 'test_tab',
		'callback-function' => 'ticket15800_callback',
	);

	return $tabs;
}

/**
 * Get the new site settings page
 *
 * @return void
 */
function ticket15800_callback() {

	if ( isset( $_REQUEST[ 'id' ] ) ) {
		$id = intval( $_REQUEST[ 'id' ] );
	} else {
		$id = 0;
	}

	?>
	<div class="wrap">
		<h2>Test for Ticket 15800</h2>

		<h3 class="nav-tab-wrapper">
			<?php network_edit_site_tabs( $id ); ?>
		</h3>

		<p>Content ...</p>
	</div>
<?php
}