Requesting Second Opinion from a Senior Dev — Recently Wrote a Gist to Quantify the Function Calls of the Settings API


I was hoping to respectfully show a gist I have created to help myself and hopefully others understand the basic functionality of the Settings API and what call can be made with it. I am trying to become more proficient in WP Core, PHP, etc, but I was hoping someone with a bit more experience could give a πŸ‘.

Settings API Functions

(1) Use this gist to reference the principal applications of the Settings API provided by WordPress as an aid to website and plugin development.
(2) six primary functions allow you to maximize the benefits of the Settings API.
(3) A list of the function parameters and a brief description of each follows after.
A good point of reference to further build out your options page is David’s exhaustive PressCoders article.


# There are six general functions that will maximize the usefulness of the WP Settings API:


register_setting($option_group, $option_name, $sanitize_callback=β€œβ€);

unregister_setting($option_group, $option_name, $sanitize_callback=β€œβ€);

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

add_settings_field($id, $title, $callback, $page, $section, $args = array());


# ________________________________________________________________________________

# The variable names used to define your output are described in more detail here:

# unique group name for the option set

# name of each option (more than one option in the same register_settings() function requires an 
# array of options)

# section/field callback function to validate option data

# unique ID for the section/field

# the title of the section/field (displayed on options page)

# callback function to be executed

# options page name (use __FILE__ if creating new options page)

# ID of the settings section (needs to be the same as $id in add_settings_section)

# additional arguments
$args = array()

Obviously, I have this on GitHub so I don’t want to be a source of inaccurate information. Also happy to add and give credit for any tips or clarification provided to make this gist more thorough. Many thanks.

killshot13 3 months 0 Answers 7 views 0

Leave an answer