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

Architecture? #3

Closed
cfoellmann opened this issue Nov 27, 2013 · 2 comments
Closed

Architecture? #3

cfoellmann opened this issue Nov 27, 2013 · 2 comments

Comments

@cfoellmann
Copy link
Owner

I am not sure how we should approach this.

An idea:

  • introduce a global $tabs array (like $menu)
  • add function add_page_tab (naming to be discussed) similar to function add_menu_page
    ->
  • add tabs.php similar to network/menu.php to output the tabs on pages

That's all I got for now. I am not too familiar with core development so please tell me if my idea a possible abstract idea or totally not the way to go.

Current $tabs array from network/site-info.php:

$tabs = array ( 
    [site-info] => array ( 
        [label] => Info 
        [url] => site-info.php
    ) 
    [site-users] => array ( 
        [label] => Users 
        [url] => site-users.php
    ) 
    [site-themes] => array ( 
        [label] => Themes 
        [url] => site-themes.php
    ) 
    [site-settings] => array ( 
        [label] => Settings 
        [url] => site-settings.php
    ) 
) 

We could aim for it to be used "everywhere" to output tabs. Something I wanted for so long

@cfoellmann
Copy link
Owner Author

@bueltge I had a look at your commit from 2 month ago.
How would one add a new tab? Do you have a test case at hand?

@bueltge
Copy link

bueltge commented Apr 25, 2014

Yep.

<?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() )
    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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants