WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#14149 closed enhancement (wontfix)

Introduce register_settings()

Reported by: nacin Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

Introduce register_settings() as a wrapper for register_setting().

Currently, you need to loop on register_setting(), or some try to use the add_option_whitelist function or filters (which was originally introduced partially as a private helper and partially for bulk adds -- http://mu.wordpress.org/forums/topic/7415, #11730). It's ugly. We can make it better.

Untested patch. It takes either array( option, option, option ) or array( option => callback, option => callback ).

Attachments (2)

14149.diff (1.3 KB) - added by nacin 5 years ago.
141419-2.diff (964 bytes) - added by blepoxp 5 years ago.
Takes a mixed array to allow some options have callbacks while others dont'

Download all attachments as: .zip

Change History (7)

@nacin5 years ago

comment:1 follow-up: @blepoxp5 years ago

I'll test this momentarily. If this is introduced we probably should introduce an unregister_settings function at the same time.

comment:2 in reply to: ↑ 1 @nacin5 years ago

Replying to blepoxp:

I'll test this momentarily. If this is introduced we probably should introduce an unregister_settings function at the same time.

Yep. Didn't get that far.

comment:3 @blepoxp5 years ago

What do you think about the attached .diff? It would allow for options array to be a mixed index / associative array where indexed == no callback and associative == callback. ie:

$options = array( 'option_one', 'option_two' => 'option_two_callback', 'option_three' );

@blepoxp5 years ago

Takes a mixed array to allow some options have callbacks while others dont'

comment:4 @nacin5 years ago

Tempted to wontfix. Bulk adds should be relatively rare as most people are going to use a single option and serialize it.

If someone wants to loop through using an array and foreach, that seems amenable and allows for customization.

Especially with the callback, register_settings() only looks unnecessarily complex. Better for someone to loop themselves.

comment:5 @nacin4 years ago

  • Milestone 3.1 deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.