<?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
 * Author: Chris Olbekson <chris@x-team.com>
 * Version: 1.0
 * Author URI: http://x-team.com
 */

if ( ! is_network_admin() )
	exit;

function network_site_tabs_test() {
	global $_registered_pages;
	add_filter( 'network_edit_site_tabs', 'filter_network_tabs', 10, 3 );
	$hookname = get_plugin_page_hookname( 'wp_test_tab', '' );
	$_registered_pages[$hookname] = true;
	if ( isset( $_GET['page'] ) && $_GET['page'] == 'wp_test_tab' )
		add_action( $hookname, 'test_tab_callback' );

}
add_action( 'network_admin_menu', 'network_site_tabs_test' );

function filter_network_tabs( $tabs, $id, $pagenow ) {
	$tabs['test-tab'] = array( 'label' => __( 'Test Tab' ), 'menu-slug' => 'wp_test_tab', 'callback-function' => 'test_tab_callback' );

	return $tabs;
}

function test_tab_callback() {
	$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
	$site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) );
	$title_site_url_linked = sprintf( __( 'Edit Site: <a href="%1$s">%2$s</a>' ), get_blogaddress_by_id( $id ), $site_url_no_http );
	?>
	<div class="wrap">
		<h2 id="edit-site"><?php echo $title_site_url_linked ?></h2>
		<h3 class="nav-tab-wrapper">
			<?php if ( function_exists( 'network_edit_site_tabs' ) )
				network_edit_site_tabs( $id );
			?>
		</h3>
	</div>
	<?php
}

