Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to clean up my theme options because I can't keep track of everything. How can I get my page_callback to link to a file sintead of a callback?

I know that I could include the file in the callback but why if I can simply call the file here?

  add_submenu_page( 
              null            // -> Set to null - will hide menu link
            , 'Page Title'    // -> Page Title
            , 'Menu Title'    // -> Title that would otherwise appear in the menu
            , 'administrator' // -> Capability level
            , 'menu_handle'   // -> Still accessible via admin.php?page=menu_handle
            , 'page_callback' // -> To render the page
        );
share|improve this question
1  
Because no one implemented it? Open a Trac ticket with your feature request. –  toscho Oct 9 '12 at 15:55
1  
NOooooooooo kidden! I sure will! –  BenRacicot Oct 9 '12 at 15:58
add comment

2 Answers

Instead of running to trac and complaining about a missing feature, I suggest to make use of an OOP construct:

// File: base.class.php
abstract class wpse67649_admin_page_base
{
    public function add_page()
    {
        add_submenu_page( 
             null            // -> Set to null - will hide menu link
            ,'Page Title'    // -> Page Title
            ,'Menu Title'    // -> Title that would otherwise appear in the menu
            ,'administrator' // -> Capability level
            ,'menu_handle'   // -> Still accessible via admin.php?page=menu_handle
            ,array( $this, 'render_page' ) // -> To render the page
        );
    }

    // Must get defined in extending class
    abstract function render_page();
}

// File: ___sub_page.class.php
class wpse67649_render_sub_page extends wpse67649_admin_page_base
{
    public function __construct()
    {
        add_action( 'admin_init', array( $this, 'add_page' ) );
    }

    public function render_page()
    {
        // You have access to every $this->class_var from your parent class
        ?>
<div class="wrapper>
    <!-- do funky page rendering -->
</div>
        <?php
    }
}

This isn't the final thing, but it should bring you on route to get stuff better organized.

share|improve this answer
add comment

Simply put - because callback is sufficient to do anything, including loading file. :) It's not worth complicating logic for something that is already not only possible but trivial.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.