Skip to content

Instantly share code, notes, and snippets.

@killshot13
Last active January 12, 2022 06:23
Show Gist options
  • Save killshot13/99994f383b14511c7577dee11e680633 to your computer and use it in GitHub Desktop.
Save killshot13/99994f383b14511c7577dee11e680633 to your computer and use it in GitHub Desktop.
Six general functions that will maximize the usefulness of the WP Settings API

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) There are six primary functions that 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.

<?php
# There are six general functions that will maximize the usefulness of the WP Settings API:
settings_fields($option_group);
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());
do_settings_sections($page)
# ________________________________________________________________________________
# The variable names used to define your output are described in more detail here:
# unique group name for option set
$option_group
# name of each option (more than one option in the same register_settings() function requires an array of options)
$option_name
# section/field callback function to validate option data
$sanitize_callback=“”
# unique ID for the section/field
$id
# the title of the section/field (displayed on options page)
$title
# callback function to be executed
$callback
# options page name (use __FILE__ if creating new options page)
$page
# ID of the settings section (needs to be the same as $id in add_settings_section)
$section
# additional arguments
$args = array()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment