Your shopping cart is empty!
he WordPress API stands for the WordPress Application Programming Interface. It can be separated into multiple API sections / topics. Each covers the functions involved in and use of a given set of functionality. Together they form what might be called the WordPress API, which is the plugin/theme/add-on interface created by the entire WordPress project.
If you've read through all of these you should have a good sense of how to extend WordPress through Plugins.
Few APIs are discussed
WordPress Transient API
set_transient(), get_transient(), delete_transient()
This is a function set very similar to get_options() and update_options() which helps to easily store and retrieve data in your options database table. The big difference here is that you also pass a time parameter which acts as expiration date for the database entry.
Once the time has expired the data is removed. This is especially useful if you want to cache data or query results for a short amount of time. An example would be a twitter widget which retrieves data from the twitter api, but since twitter is down pretty often it would be wise to save that data for a few minutes. That also would speed up the site for subsqequent page requests since you don’t need to connect to an external API.
It works pretty easy: the function set_transient accepts 3 parameters:
set_transient($transient, $value, $expiration);
so saving a value to your database for an hour would look like this:
set_transient('the_name', $special_query_results, 60*60);
getting the value like this:
$value = get_transient('the_name');
WordPress “Cron Jobs”
wp_schedule_event(time(), 'hourly', 'my_schedule_hook');
Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed.
So if you want to execute some code on a regular base, like checking an RSS Feed, doing a database backup or reseting database values this function will do it for you. Unfortunatley its not as easy to use as transient but here is a short article on how it is done:
WordPress HTTP API
wp_remote_get( $url, $args = array() );
An easy to use function if you want to retrieve the content of a Webpage. The function stores the result within an easily accessible array. Not only do you get the result content of the webpage, you also get header informations and response codes. This function is also capable of retrieving feed content which also makes it useful if you want to create a twitter plugin or an rss reader with wordpress.
Easily Fetch an RSS Feed with WordPress
$feed = fetch_feed( $uri );
fetch_feed is another simple wordpress method to get feed content. It also has the added benefit that it uses the SimplePie and FeedCache functionality for retrieval and parsing and automatic caching.
WordPress mail function
wp_mail( $to, $subject, $message, $headers, $attachments );
$to = 'email@example.com';
$subject = 'Hello Kriesi!';
$message = 'This message was sent by wordpress'
$mail = wp_mail($to, $subject, $message);
if($mail) echo 'Mail delivered';
An incredible useful and exceptional easy to use function that also allows you to send headers and attachments, allows plain text sending and html messages and quite a few other options!
WordPress Human Time
human_time_diff( $from, $to )
A feature to mimic twitter like time display. Instead of outputting the time in a basic format you can display it like this:
Kriesi posted 13 hours ago
WordPress get comments
Sometimes its neccessary to retrieve the comments outside of the comments loop like I did with the Avia Feedback Box Plugin, where comments are displayed via ajax. This function helps you in doing so ;)
WordPress validation of strings
wp_kses($string, $allowed_html, $allowed_protocols);
wp_kses is a very usefull function when it comes to sanitizing untrusted user input. This function makes sure that only the allowed HTML element names, attribute names and attribute values plus only sane HTML entities will occur in $string.
WordPress text transformation
A text transformation function that converts commonly used strings into the typographical correct signs. Used for dashes, ellipsis etc and will also add typograpic quotes to certain phrases.
The last text transformation tool on the list is used by wordpress to ad
tags to a string by replacing double tags
WordPress Shortcode API
add_shortcode() is an easy way to create macros for your post content. for example lets say you want to wrap some content inside the post area within a div with some additional classes and ids that allows you to create multiple columns. you could of course just switch to the html editor and enter
Create WordPress comment with a php function:
Similar to wp_insert_posts this function inserts a comment. Might also come in handy ;)
WordPress Object Cache:
wp_cache_add(), wp_cache_set(), wp_cache_get(), wp_cache_delete, wp_cache_replace(), wp_cache_flush
WP_Object_Cache is WordPress’ class for caching data which may be computationally expensive to regenerate, such as the result of complex database queries. If you care for theme and plugin performance you should definitley read the wordpress codex entry for this topic!
Kill wordpress execution:
An appropriate end for this post: the wp_die function
wp_die kills the WordPress execution and display HTML message with error message.
A call to this function complements the die() PHP function. The difference is that HTML will be displayed to the user. It is recommended to use this function only when the execution should not continue any further.