Home > DeveloperSection > Beginner > WordPress API’s

WordPress API’s


WordPress WordPress 
Ratings:
0 Comment(s)
 6238  View(s)
Rate this:

WordPress API’s

The WordPress API stands for the WordPress Application Programming Interface. It can be separated into multiple API sections or topics. Each covers the functions involved in and use of a given set of functionality.

There are lots of API’s is used with WordPress such as Dashboard Widgets API, Database API,  HTTP API, File Header API, Plugin API, Settings API, Theme Modification API etc.  Let’s see a brief description about them.

Dashboard Widgets API:

The Dashboard Widgets API makes it very simple to add new widgets to the Administration Dashboard Panel. Doing so requires working knowledge of PHP and the WordPress Plugin API, but to plugin or theme authors familiar with hooking actions and filters it only takes a few minutes and can be a great way to make your plugin even more useful.

The main tool needed to add Dashboard Widgets is the wp_add_dashboard_widget() function.

Syntax:

wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback = null) ;

Here parameters are defined as,

$widget_id -> this is used for identifying slug for your widget.

$widget_name-> this is the name your widget will display in its heading.

$callback-> this is name of a function you create that will display the actual contents of your widget.

$control_callback -> It is optional parameter which displays the name of a function you create that will handle submission of widget options forms, and will also display the form elements.

Database API:

This page lists all holistic pages of a given Database related API. Each covers the functions involved in and use of a given set of functionality. Together they form what might be called the WordPress Database API, which is the plugin/theme/add-on interface created by the entire WordPress project in respect to access data as named values stored in the database layer.

HTTP API:

Within PHP, there are different ways to send an HTTP request. For simplicity, that different ways are called 'transports' and will be used from now on. The purpose for the HTTP API is to support all of them with an API that is simple and standard for each of the transports.

The helper functions utilize the HTTP API classes to simplify the process as much as possible. You could use the classes and could use some of the methods to help process the code. The classes assume that you know what you are doing and can use the classes.

You must use the helper functions if you are modifying the core code of WordPress. It is one of the reasons for the helper API, to reduce the amount of error checking and prevent having to edit multiple places when bugs are found.

You will have to check for that after using such functions; wp_remote-get(), wp_remote_post(), wp_remote_head() and wp_remote_request().

File Header API:

The File Header API consists of all functions and hooks that are part of the WordPress API regarding the use of File Headers. In WordPress Themes and Plugins consist of one or more files of which one has plugins, custom themes, drop-Ins, so called File Headers containing meta-information such as Name, Version, Author etc regarding the concrete theme or plugin.

Setting API:

The Settings API, added in WordPress 2.7, allows admin pages containing settings forms to be managed semi-automatically. It lets you define settings pages, sections within those pages and fields within the sections.

New settings pages can be registered along with sections and fields inside them. Existing settings pages can also be added to by registering new settings sections or fields inside of them.

NB: When using the Settings API, the form posts to options.php which provides fairly strict capabilities checking. Users will need 'manage_options' capability to submit the form.

You can add new settings fields to the existing WordPress pages using this function.

Syntax:

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

Here parameters are defined as:

$id -> this is used for ‘id’ attribute tag.

$title -> title of field

$callback -> it fills the field with the desired inputs as part of the larger form. Name and id of the input should match the $id given to this function. The function should echo its output.

$page -> the type of settings page on which to show the field

$section -> the section of the settings page in which to show the box

$args -> this parameter shows the additional arguments.

Theme Modification API:

Theme Modification API consists of all functions and hooks that are part of the WordPress API regarding the use of Theme modification values.

There are some functions and hook reference are used to Theme Modification API. Let’s have a look of those functions and hooks.

Functions:

Basically three functions are used to Theme Modification API which is:

1.     get_theme_mod(): This function is used for retrieve theme modification value of current theme. If the modification name does not exist, then the $default will be passed through sprint () function.

2.     set_theme_mod():  This function is used for update theme modification value for current theme.

3.     remove_theme_mods(): This function is used for remove modification option from current theme.

Hooks References:

Only one method is used for Hooks References; theme_mod_$name() filter is part of the Theme Modification API which is used for get_theme_mod().


Don't want to miss updates? Please click the below button!

Follow MindStick