SLB: Notes – Admin: Option Page Building

By Sol in Lab


  • Allow Options class to handle as much of option-centric operations as possible


  • Register option building context/layouts
    • Including using callbacks
  • Pass layout/context when options->build() called
  • Retrieve context properties
  • Build options according to properties


  • add_settings_section() only works on options pages in Settings admin section



  1. Pass options instance as reference
    • So that settings are properly saved
  2. Build page
  3. Build Form
    • ? How/where should form wrapper for options be generated?
      • Options or Admin class?
      • A: Options class
        • + Validation method will work in tandem with form building
  4. Check for form submission
  5. Validate submission
  6. Save options

Passing options as reference (options)

  1. Callback/options in single parameter
    • Example
      	"options"	=> &$options,
      	"callback"	=> $this->m('callback')
    • + Flexible: Pass options and/or callback (or neither)
    • - More typing for each menu
      • Must creating associative array no matter what to pass any values
      • ~ Similar to title (title, menu, etc.)
    • + Cuts down on parameter count: by grouping parameters in array

Registering Contexts/Layouts

? Context or layout? Which to extend? (Options)

  1. Context
    • Register context-specific layouts, values, defaults, etc.
    • + Contains layouts & more
    • - Must be developed from scratch
    • ? Overlapping existing layout functionality?
  2. Layout
    • - Currently implemented for field items, not collections
      • Solution needs to allow for collection-wide processing
    • Example: Admin layout
    • ┬áNeed to register handlers for various placeholders
    • Layout passed to options->build()as argument
      $options->build(array('layout' => 'admin'));