[theme-reviewers] add_theme_page()

Emil Uzelac emil at themeid.com
Mon Jan 24 23:55:42 UTC 2011


Good job, tweeted as well :)


*Emil Uzelac* | ThemeID | T: 224-444-0006 | Twitter:
@EmilUzelac<http://twitter.com/emiluzelac>| E:
emil at themeid.com | http://themeid.com
*Make everything as simple as possible, but not simpler.* - Albert Einstein



On Mon, Jan 24, 2011 at 5:49 PM, Chip Bennett <chip at chipbennett.net> wrote:

> *jaw drops*
>
> Now *that* is an awesome tutorial! Well done, Daniel!
>
> (Tweeted)
>
> Chip
>
>
> On Mon, Jan 24, 2011 at 5:34 PM, Daniel Tara <contact at onedesigns.com>wrote:
>
>>  I wrapped this into and article. Hope it helps you and all developers in
>> need out there:
>>
>>
>>
>>
>> http://www.onedesigns.com/tutorials/separate-multiple-theme-options-pages-using-tabs
>>
>>
>>
>>
>>
>>
>>
>> *From:* theme-reviewers-bounces at lists.wordpress.org [mailto:
>> theme-reviewers-bounces at lists.wordpress.org] *On Behalf Of *Sayontan
>> Sinha
>> *Sent:* Monday, January 24, 2011 11:24 PM
>>
>> *To:* theme-reviewers at lists.wordpress.org
>> *Subject:* Re: [theme-reviewers] add_theme_page()
>>
>>
>>
>> That would be a relief. Let me give it a try.
>>
>> On Mon, Jan 24, 2011 at 1:12 PM, Daniel Tara <contact at onedesigns.com>
>> wrote:
>>
>> Creating tabs is as easy as this:
>>
>>
>>
>> function sayontan_admin_tabs( $current = 'general' ) {
>>
>>                 $tabs = array( 'general' => 'General', 'layput' =>
>> 'Layout', 'advanced' => 'Advanced' );
>>
>>                 $links = array();
>>
>>                 foreach( $tabs as $tab => $name ) :
>>
>>                                 if ( $current == $tab ) :
>>
>>                                                 $links[] = "<a
>> class='nav-tab nav-tab-active'
>> href='?page=sayontan_options&tab=$tab'>$name</a>";
>>
>>                                 else :
>>
>>                                                 $links[] = "<a
>> class='nav-tab' href='?page=sayontan_options&tab=$tab'>$name</a>";
>>
>>                                 endif;
>>
>>                 endforeach;
>>
>>                 foreach ( $links as $link )
>>
>>                                 echo $link;
>>
>> }
>>
>>
>>
>> if ( isset ( $_GET['tab'] ) ) :
>>
>>                 $tab = $_GET['tab'];
>>
>> else:
>>
>>                 $tab = 'general';
>>
>> endif;
>>
>> switch ( $tab ) :
>>
>>                 case 'general' :
>>
>>                 // Whatever
>>
>>                 break;
>>
>>                 ...
>>
>> endswitch;
>>
>>
>>
>> *From:* theme-reviewers-bounces at lists.wordpress.org [mailto:
>> theme-reviewers-bounces at lists.wordpress.org] *On Behalf Of *Sayontan
>> Sinha
>> *Sent:* Monday, January 24, 2011 10:47 PM
>> *To:* theme-reviewers at lists.wordpress.org
>>
>>
>> *Subject:* Re: [theme-reviewers] add_theme_page()
>>
>>
>>
>> Ideally, it would still have just one Theme Options page under
>>
>>
>> appearance, and then use tabs or something else on its own page to
>> separate the options out.
>>
>>
>> This is much easier said than done. I have been working towards getting
>> tabs in place on one page (multiple calls to add_theme_page makes things
>> look quite ugly), but there are simply too many limitations with the whole
>> API to make this work effectively. Let me try to explain.
>>
>> *The Scenario:*
>> My theme has several options. Putting them all on one page causes a lot of
>> issues, like sluggishness of the back-end and interference with PHP-Suhosin
>> protection settings (though Suhosin can be tweaked). I originally had a
>> 2-level tab system, with horizontal tabs at the top for different sections
>> of settings, then vertical tabs within each section (that is similar to the
>> kind of settings that the other folks are talking about). The tabs were all
>> handled by JQuery. This works fine with a small number of options, but with
>> a large number of options, the sluggishness shows up in the back-end. That
>> was when I removed the horizontal tabs at the top level and used
>> add_menu_page and add_submenu_page.
>>
>> But with the recent enforcements of new rules and recommendations, I have
>> had to do some major rework. I first rewrote the options framework to use
>> the Settings API, but still with add_menu_page and add_submenu_page. Now I
>> am rewriting again to get rid of the additional menu and roll it back to how
>> the look was earlier, but with a difference: the entire set of options will
>> not be loaded into browser memory in JQuery tabs. Instead, I will try to
>> fetch each page as it is clicked, like the Theme Installation page in WP.
>>
>> *My attempts:*
>>
>>    1. I first simply created one options page, then included a set of
>>    links at the top.
>>    *Issue:* Getting the links to behave as belonging within WP. E.g. If
>>    your admin panel is at http://host.com/wp-admin, your theme options
>>    page could be at http://host.com/wp-admin/themes.php?page=my-options.
>>    The tabs, however cannot be given links through the admin panel. In other
>>    words, to get a URL such as
>>    http://host.com/wp-admin/themes.php?page=my-sub-options-1, I HAVE to
>>    use add_theme_page. If I don't use add_theme_page, the page isn't added to
>>    the whitelist and will not show up. I cannot use other URLs, because then I
>>    will have something like this:
>>    http://host.com/wp-content/themes/my-theme/my-sub-options-1.php, which
>>    is just not done.
>>    2. To get around the above, I decided to bundle AJAX with the options
>>    page. So I have one options page accessible through
>>    http://host.com/wp-admin/themes.php?page=my-options. In there I have 5
>>    links, each of which invokes AJAX to load the specific options page, while
>>    staying in http://host.com/wp-admin/themes.php?page=my-options. This
>>    way I only need to whitelist the main page.
>>    *Issue:* Getting settings_fields() to generate _wp_http_referer
>>    different from admin-ajax.php. This is causing options.php to return
>>    admin-ajax.php?updated=true, which is not what I want. This is where I am
>>    stuck right now, but hopefully I will get over the hurdle soon.
>>
>> I am looking forward to completing this exercise, so that other developers
>> can learn from my (rather harsh) experience here.
>>
>> Cheers,
>> Sayontan.
>>
>> On Mon, Jan 24, 2011 at 11:08 AM, Otto <otto at ottodestruct.com> wrote:
>>
>> On Mon, Jan 24, 2011 at 1:03 PM, Rahul Bansal <rahul286 at gmail.com> wrote:
>> > What if theme offers so many options that it need to contains 4-5
>> subpages?
>>
>> Ideally, it would still have just one Theme Options page under
>> appearance, and then use tabs or something else on its own page to
>> separate the options out.
>>
>> Realistically, I'd say a theme with that many options is too complex
>> to begin with. Themes should be about the look of the site, not crazy
>> functionality. Break the functionality parts out into plugins that go
>> along with the theme or something like that.
>>
>> -Otto
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>>
>>
>>
>> --
>> Sayontan Sinha
>> http://mynethome.net | http://mynethome.net/blog
>> --
>> Beating Australia in Cricket is like killing a celebrity. The death gets
>> more coverage than the crime.
>>
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>>
>>
>>
>> --
>> Sayontan Sinha
>> http://mynethome.net | http://mynethome.net/blog
>> --
>> Beating Australia in Cricket is like killing a celebrity. The death gets
>> more coverage than the crime.
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110124/ffd1eabb/attachment.htm>


More information about the theme-reviewers mailing list