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.

Is there a WordPress function displaying all sections registered with add_settings_section()?

I was thinking about SQL query maybe, but have absolutely no idea how and where these are stored, couldn't find them in my database.

share|improve this question
2  
I think I may have misunderstood... - if you are after a list of section slugs see Chip's answer. If you actually just want to output the contents of all sections registered to a page see mine. The sections aren't stored in the database. –  Stephen Harris Feb 10 '12 at 14:56
1  
Yes, you did, I wanted to list all sections within the whole theme, not only certain pages. Thanks for the help! –  Wordpressor Feb 10 '12 at 14:58
    
Your pages are available/registered on every admin page UI request, so summing them up and then outputting them with the public API like @StephenHarris has shown is how it should be done. –  kaiser Feb 10 '12 at 15:06
    
The OP doesn't want to output pages. I think you're misreading the question, @kaiser. –  Chip Bennett Feb 10 '12 at 15:18
    
@Wordpressor - mind me asking what you want this for? I can't think of a scenario where you might need it and there isn't a public API alternative... –  Stephen Harris Feb 10 '12 at 15:31
show 1 more comment

3 Answers

up vote 0 down vote accepted

Use the $wp_settings_sections global. It returns an array of settings sections.

share|improve this answer
    
You shouldn't rely code on internal globals. –  kaiser Feb 10 '12 at 15:03
    
What is wrong with using the global here, when the data contained by the global is exactly what the OP wants? –  Chip Bennett Feb 10 '12 at 15:09
    
That internal globals can change content & behavior from version to version. Also: If it's about the $page, then you'll get the page as return value when registering the page. That means that you get it on every admin-UI request and can therefore reuse it without a problem. Summing different pages isn't a problem either. –  kaiser Feb 10 '12 at 15:15
    
What's changing with $wp_settings_sections? The OP wants a list of registered settings, which is only and always what $wp_settings_sections contains. –  Chip Bennett Feb 10 '12 at 15:17
1  
Just an example (like it's valid for every internal global): The name could change. –  kaiser Feb 10 '12 at 15:32
show 3 more comments

This outputs all the sections registered to the page passed in the argument:

do_settings_sections($page)

See Codex.

share|improve this answer
    
public API solution always gets +1 –  kaiser Feb 10 '12 at 15:04
    
@kaiser: except, that's not what the OP asked for. –  Chip Bennett Feb 10 '12 at 15:10
add comment

Use the core API

A) If you read the Codex about …

add_settings_section( $id, $title, $callback, $page );

… then you'll find the @param $page.

B) This is the menu page that you registered using …

add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function);

C) This is used on every admin-UI request. If it wouldn't then stuff like the screen dependend hooks wouldn't work:

$example = "admin_print_styles-{$screen}";

Solution

Sum up all your pages when registering them:

// Example:
$pages[] = add_menu/submenu_page/theme/etc_page( ... );
foreach( $pages as $page )
    do_settings_sections( $page );
share|improve this answer
    
This doesn't answer the OP's question, which is: "Is there a WordPress function displaying all sections registered with add_settings_section()?" The OP wants the names of registered settings sections, not settings pages. –  Chip Bennett Feb 10 '12 at 15:33
    
This shows "how to get all sections that were registered. By the one who writes the code". Everything else would likely crash in the first second. If the OP really wants to crash stuff than the right answer would be "Leave it!" and nothing else. –  kaiser Feb 10 '12 at 15:38
    
Based on the OP's question, and clarifying comment, he wants to display a list of sections, not output the content of those sections. –  Chip Bennett Feb 10 '12 at 15:40
    
"within the whole theme". So yes, only those that he registered himself. On the other hand: Yes, there's no public API function to far to get only the names. On the third hand (if you got that many): As he registered them himself, he could also drop the names in a custom global or write a custom personal API function to retrieve them. Trying to rely on core code for such a tasks is nonsense in my opinion. The sense of the Q seems to want to hide away from me. –  kaiser Feb 10 '12 at 15:46
    
@ChipBennett Btw: This wasn't meant to be the answer. It was meant as an explanation to you only as you can read in the comments above. –  kaiser Feb 10 '12 at 18:48
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.