Create a gist now

Instantly share code, notes, and snippets.

Codex function reference to Apple Dictionary
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="utf-8"?>
<d:dictionary xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng">
<d:entry id="get_usernumposts" d:title="get usernumposts">
<d:index d:value="get usernumposts"/>
<h1>get usernumposts</h1>
<p>{{Deprecated}}
== Description ==
Returns the post count for the user whose ID is passed to it. Properties map directly to the wp_posts table in the database (see [[Database Description#Table:_wp_posts|Database Description]]).
== Replace With ==
[[Function_Reference/count_user_posts|count_user_posts()]]
== Usage ==
&lt;?php get_usernumposts(userid); ?&gt;
== Parameters ==
{{Parameter|$userid|integer|The ID of the user whose post count should be retrieved.}}
== Example ==
=== Default Usage ===
The call to &lt;tt&gt;get_usernumposts&lt;/tt&gt; returns the number of posts made by the user.
&lt;?php echo 'Posts made: ' . get_usernumposts(1); ?&gt;
&lt;div style=&quot;border:1px solid blue; width:50%; padding:10px&quot;&gt;Posts made: 143&lt;/div&gt;
== Change Log ==
* Since: 0.71
* Deprecated: 3.0.0
==Source File==
&lt;tt&gt;get usernumposts()&lt;/tt&gt; is located in {{Trac|wp-includes/deprecated.php}}. Formerly, {{Trac|wp-includes/user.php}}.
== Related ==
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="do_action" d:title="do action">
<d:index d:value="do action"/>
<h1>do action</h1>
<p>{{Languages|
{{en|Function_Reference/do_action}}
{{fax|Function_Reference/do_action}}
{{ru|Справочник по функциям/do_action}}
{{ja|関数リファレンス/do_action}}
}}
== Description ==
Execute functions hooked on a specific action hook.
This function invokes all functions attached to action hook &lt;tt&gt;$tag&lt;/tt&gt;. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the &lt;tt&gt;$tag&lt;/tt&gt; parameter. You can pass extra arguments to the hooks, much like you can with &lt;tt&gt;[[Function_Reference/apply_filters | apply_filters()]]&lt;/tt&gt;. This function works similar to &lt;tt&gt;apply_filters()&lt;/tt&gt; with the exception that nothing is returned and only the functions or methods are called.
You can hook a function to an action hook using &lt;tt&gt;[[Function Reference/add_action|add_action()]]&lt;/tt&gt;.
== Usage ==
%%% &lt;?php do_action( $tag, $arg ); ?&gt; %%%
Multiple Arguments:
%%% &lt;?php do_action( $tag, $arg_a, $arg_b, $etc ); ?&gt; %%%
== Parameters ==
{{Parameter|$tag|string|The name of the hook you wish to execute.}}
{{Parameter|$arg|mixed|The list of arguments to send to this hook.|optional|Empty string}}
== Return Values ==
This function does not return a value.
== Example ==
&lt;pre&gt;
&lt;?php
# ======= Somewhere in a (mu-)plugin, theme or the core ======= #
/**
* You can have as many arguments as you want,
* but your callback function and the add_action call need to agree in number of arguments.
* Note: `add_action` above has 2 and 'i_am_hook' accepts 2.
* You will find action hooks like these in a lot of themes &amp; plugins and in many place @core
* @see: http://codex.wordpress.org/Plugin_API/Action_Reference
*/
# ======= e.g., inside your functions.php file ======= #
/**
* Define callback function
* Inside this function you can do whatever you can imagine
* with the variables that are loaded in the do_action() call above.
*/
function who_is_hook( $a, $b )
{
echo '&lt;code&gt;';
print_r( $a ); // `print_r` the array data inside the 1st argument
echo '&lt;/code&gt;';
echo '&lt;br /&gt;'.$b; // echo linebreak and value of 2nd argument
}
// then add it to the action hook, matching the defined number (2) of arguments in do_action
// see [http://codex.wordpress.org/Function_Reference/add_action] in the Codex
// add_action( $tag, $function_to_add, $priority, $accepted_args );
add_action( 'i_am_hook', 'who_is_hook', 10, 2 );
// Define the arguments for the action hook
$a = array(
'eye patch' =&gt; 'yes'
,'parrot' =&gt; true
,'wooden leg' =&gt; (int) 1
);
$b = 'And Hook said: &quot;I ate ice cream with Peter Pan.&quot;';
// Executes the action hook named 'i_am_hook'
do_action( 'i_am_hook', $a, $b );
# ======= output that you see in the browser ======= #
Array (
['eye patch'] =&gt; 'yes'
['parrot'] =&gt; true
['wooden leg'] =&gt; 1
)
And hook said: &quot;I ate ice cream with Peter Pan.&quot;
&lt;/pre&gt;
== Notes ==
* Uses: [[Global_Variables | global]] &lt;tt&gt;$wp_filter&lt;/tt&gt; - Stores all of the filters and actions.
* Uses: [[Global_Variables | global]] &lt;tt&gt;$wp_actions&lt;/tt&gt; - Increments the amount of times the action was triggered.
== Change Log ==
Since: [[Version_1.2|1.2.0]]
== Source File ==
&lt;tt&gt;do_action()&lt;/tt&gt; is located in {{Trac|wp-includes/plugin.php}}.
== Related ==
{{Action Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="timer_stop" d:title="timer stop">
<d:index d:value="timer stop"/>
<h1>timer stop</h1>
<p>== Description ==
This function returns the amount of time (in seconds) to generate the page.
== Usage ==
%%% &lt;?php timer_stop( $display = 0, $precision = 3 ); ?&gt; %%%
== Example ==
=== Usage ===
Determine length of time to render page with a precision of 3, 5 and 10 digits.
&lt;pre&gt;
&lt;?php echo('Seconds: '.timer_stop( 0 ).'&lt;br /&gt;'); ?&gt;
&lt;?php echo('Seconds: '.timer_stop( 0, 5 ).'&lt;br /&gt;'); ?&gt;
&lt;?php echo('Seconds: '.timer_stop( 0, 10 ).'&lt;br /&gt;'; ?&gt;
&lt;/pre&gt;
&lt;div style=&quot;border:1px solid blue; width:50%; padding:10px&quot;&gt;
Seconds: 0.815&lt;br /&gt;
Seconds: 0.81551&lt;br /&gt;
Seconds: 0.8155429363
&lt;/div&gt;
== Parameters ==
; display : (''integer'') Possible values: 0 or 1. Defaults to 0.
; precision : (''integer'') Possible values: 0 or 1. Defaults to 3.
[[Category:Functions]]
== Related Functions ==
[[timer_start]]
== Further Reading ==
For a comprehensive list of functions, take a look at the [http://codex.wordpress.org/Category:Functions category Functions]
Also, see [[Function_Reference]]</p>
</d:entry>
<d:entry id="get_approved_comments" d:title="get approved comments">
<d:index d:value="get approved comments"/>
<h1>get approved comments</h1>
<p>{{Languages|
{{en|Function Reference/get_approved_comments}}
{{it|Riferimento funzioni/get_approved_comments}}
}}
==Description==
Takes post ID and returns an array of objects that represent comments that have been submitted ''and'' approved.
== Usage ==
%%%&lt;?php
$comment_array = get_approved_comments($post_id);
?&gt;%%%
== Parameters ==
{{Parameter|$post_id|integer|The ID of the post|required}}
== Return Values ==
{{Return|$comments|array|The approved comments}}
==Example==
In this example we will output a simple list of comment IDs and corresponding post IDs.
&lt;pre&gt;
&lt;?php
$postID = 1;
$comment_array = get_approved_comments($postID);
foreach($comment_array as $comment){
echo $comment-&gt;comment_ID.&quot; =&gt; &quot;.$comment-&gt;comment_post_ID.&quot;\n&quot;;
}
?&gt;
&lt;/pre&gt;
== Notes ==
== Change Log ==
Since: [[Version 2.0|2.0.0]]
== Source File ==
current_user_can_for_blog() is located in {{Trac|wp-includes/capabilities.php}}
== Related ==
&amp;nbsp;
{{Tag Footer}}
{{Copyedit}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="add_option" d:title="add option">
<d:index d:value="add option"/>
<h1>add option</h1>
<p>{{Languages|
{{en|Function_Reference/add_option}}
{{ru|Справочник_по_функциям/add_option}}
}}
== Description ==
A safe way of adding a named option/value pair to the options database table. It does nothing if the option already exists. After the option is saved, it can be accessed with [[Function_Reference/get_option|get_option()]], changed with [[Function_Reference/update_option|update_option()]], and deleted with [[Function_Reference/delete_option|delete_option()]].
You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is inserted into the database. You can create options without values and then add values later.
Calling &lt;tt&gt;add_option&lt;/tt&gt; first checks whether the option has already been added, and returns false if an option with the same name exists. Next, it checks to make sure the option name is not one of the protected names ''alloptions'' or ''notoptions'', and dies with an error message if attempting to overwrite a protected option. If the option name is not protected, and does not already exist, the option will be created.
'''''Note:''''' ''&lt;tt&gt;add_option&lt;/tt&gt; uses &lt;tt&gt;get_option&lt;/tt&gt; to determine whether the option already exists, and since &lt;tt&gt;get_option&lt;/tt&gt; returns '''false''' as the default value, if you set an option to '''false''' in the database (e.g. via &lt;tt&gt;update_option($option_name, false)&lt;/tt&gt;), then a subsequent call to &lt;tt&gt;add_option&lt;/tt&gt; will change the value, because it will seem to &lt;tt&gt;add_option&lt;/tt&gt; that the option does '''not''' exist.''
=== vs. update_option() ===
If you are trying to ensure that a given option is created, use [[Function_Reference/update_option|update_option()]] instead, which bypasses the option name check and updates the option with the desired value whether or not it exists.
NB: you cannot specify autoload='no' if you use update_option(). If you need to specify autoload='no', and you are not sure whether the option already exists, then call delete_option() first before calling add_option().
== Usage ==
%%%&lt;?php add_option( $option, $value, $deprecated, $autoload ); ?&gt;%%%
== Parameters ==
{{Parameter|$option|string|Name of the option to be added. Must not exceed 64 characters. Use underscores to separate words, and do not use uppercase&mdash;this is going to be placed into the database.}}
{{Parameter|$value|mixed|Value for this option name. Limited to 2^32 bytes of data|optional|''Empty string''}}
{{Parameter|$deprecated|string|Deprecated in WordPress [[Version 2.3]].|optional|''Empty string''}}
{{Parameter|$autoload|string|Should this option be automatically loaded by the function [[Function Reference/wp_load_alloptions|wp_load_alloptions()]] (puts options into object cache on each page load)? Valid values: '''yes''' or '''no'''.|optional|yes}}
== Return Value ==
{{Return||boolean|False if option was not added and true if option was added}}
== Example ==
&lt;pre&gt;
&lt;?php add_option( 'myhack_extraction_length', '255', '', 'yes' ); ?&gt;
&lt;/pre&gt;
== Change Log ==
Since: [[Version 1.0|1.0.0]]
== Source File ==
&lt;tt&gt;add_option()&lt;/tt&gt; is located in {{Trac|wp-includes/option.php}}.
== Related ==
{{Option Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="delete_option" d:title="delete option">
<d:index d:value="delete option"/>
<h1>delete option</h1>
<p>{{Languages|
{{en|Function_Reference/delete_option}}
{{ru|Справочник_по_функциям/delete_option}}
}}
== Description ==
A safe way of removing a named option/value pair from the options database table.
== Usage ==
%%%&lt;?php delete_option( $option ); ?&gt;%%%
== Parameters ==
{{Parameter|$option|string|Name of the option to be deleted. A list of valid default options can be found at the [[Option Reference]].}}
== Return Value ==
{{Return||boolean|True, if option is successfully deleted. False on failure, or option does not exist.}}
== Example ==
=== Delete a single option ===
This will delete 'my_option' from the options table within your MySQL database.
&lt;pre&gt;
&lt;?php delete_option( 'my_option' ); ?&gt;
&lt;/pre&gt;
== Change Log ==
Since: [[Version 1.2|1.2.0]]
== Source File ==
&lt;code&gt;delete_option()&lt;/code&gt; is located in {{Trac|wp-includes/option.php}}.
== Related ==
{{Option Tags}}
{{Tag Footer}}
[[Category:Functions]]
{{Copyedit}}</p>
</d:entry>
<d:entry id="get_rss" d:title="get rss">
<d:index d:value="get rss"/>
<h1>get rss</h1>
<p>{{Deprecated}}
==Description==
Retrieves an RSS feed and parses it, then displays it as a list of links. The get_rss() function only outputs the list items, not the surrounding list tags itself.
Uses the [http://magpierss.sourceforge.net/ MagpieRSS and RSSCache] functions for parsing and automatic caching and the [http://sourceforge.net/projects/snoopy/ Snoopy HTTP client] for the actual retrieval.
Deprecated note: Switch to using [[Function_Reference/fetch_feed|fetch_feed]] instead.
==Usage==
%%%&lt;?php
require_once(ABSPATH . WPINC . '/rss-functions.php');
get_rss($uri, $num = 5);
?&gt;%%%
==Parameters==
{{Parameter|$uri|URI|The URI of the RSS feed you want to retrieve. The resulting parsed feed is returned, with the more interesting and useful bits in the items array.}}
{{Parameter|$num|integer|The number of items to display.|optional|5}}
[[Category:Functions]]
==Example==
The get_rss() function only outputs the list items, not the surrounding list tags itself. So, to get and display an ordered list of 5 links from an existing RSS feed:
%%%&lt;?php
require_once(ABSPATH . WPINC . '/rss-functions.php');
echo '&lt;ol&gt;';
get_rss('http://example.com/rss/feed/goes/here');
echo '&lt;/ol&gt;';
?&gt;%%%
==Output==
The output from the above example will look like the following:
%%%&lt;ol&gt;
&lt;li&gt;&lt;a href='LINK FROM FEED' title='DESCRIPTION FROM FEED'&gt;TITLE FROM FEED&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;
(repeat for number of links specified)
&lt;/ol&gt;%%%
==Related==
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="User:JHodgdon/Function_Reference_2.1" d:title="User:JHodgdon/Function Reference 2.1">
<d:index d:value="User:JHodgdon/Function Reference 2.1"/>
<h1>User:JHodgdon/Function Reference 2.1</h1>
<p>__NOTOC__
NOTE: This has now been moved to [[Function Reference]]... but I could not do it as a move....
The files of WordPress define many useful PHP functions. Some of the functions, known as [[Template Tags]], are defined especially for use in WordPress themes. There are also some functions related to actions and filters (the [[Plugin API]]), which are therefore used primarily for developing plugins. The rest are used to create the core WordPress functionality.
Many of the core WordPress functions may also be useful to plugin developers, and to a lesser extent, possibly theme developers as well. So, this article lists most of the core functions, by category; some of the function names are also links to more detailed documentation in separate pages. Each category also lists the files where its functions can be found (the files are in the &lt;tt&gt;wp-includes&lt;/tt&gt; directory of WordPress).
'''Note''': This reference applies to Version 2.1 of WordPress, and does not include functions that have been deprecated as of that version of WordPress. An incomplete page for the 2.0.x versions of WordPress can be found at [[Function Reference 2.0.x]].
'''Note''': Functions specifically for templates, which are listed in the [[Template Tags]] article, and contained in files &lt;tt&gt;wp-includes/*_template.php&lt;/tt&gt;, are not listed here.
&lt;div style=&quot;border:blue 1px solid;padding:10px; background: #E6CCFF&quot;&gt;
'''You can help make this page more complete!'''
Here are some things you can do to help:
* Add documentation to un-documented functions, by creating sub-pages or at least by adding short comments in the lists below. If you create a subpage for a function, please include information and examples of usage of that function, if possible, per the examples found in [[Template Tags]].
* List more functions here, following the category structure.
* Remove functions from the list, if you think they could not possibly be useful to plugin developers, or if they have been deprecated.
* Correct errors by moving functions to better categories where appropriate, and of course fixing typos. Note that it is OK for a function to appear in more than one category.
Read [[Contributing to WordPress]] to find out more about how you can contribute to the effort!
&lt;/div&gt;
&lt;!-- remove the DIV above after there's enough example content --&gt;
==Functions by category==
{| cellspacing=&quot;10&quot; width=&quot;100%&quot;
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Post, Page, and Attachment Functions ==
These functions are contained in &lt;tt&gt;formatting.php&lt;/tt&gt;, &lt;tt&gt;post.php&lt;/tt&gt;. See also [[Template Functions]].
* &lt;tt&gt;wp_trim_excerpt&lt;/tt&gt;
* &lt;tt&gt;get_attached_file&lt;/tt&gt;
* &lt;tt&gt;update_attached_file&lt;/tt&gt;
* &lt;tt&gt;get_children&lt;/tt&gt;
* &lt;tt&gt;get_extended&lt;/tt&gt;
* [[Function Reference/get_post|get_post]] - get information on a specific post
* [[Function Reference/get_post_mime_type|get_post_mime_type($ID = &quot;&quot;)]] - takes a post ID, returns its MIME type
* &lt;tt&gt;get_post_status&lt;/tt&gt;
* &lt;tt&gt;get_post_type&lt;/tt&gt;
* &lt;tt&gt;get_posts&lt;/tt&gt;
* &lt;tt&gt;add_post_meta&lt;/tt&gt;
* &lt;tt&gt;delete_post_meta&lt;/tt&gt;
* &lt;tt&gt;get_post_meta&lt;/tt&gt;
* &lt;tt&gt;update_post_meta&lt;/tt&gt;
* &lt;tt&gt;get_post_custom&lt;/tt&gt;
* &lt;tt&gt;get_post_custom_keys&lt;/tt&gt;
* &lt;tt&gt;get_post_custom_values&lt;/tt&gt;
* [[Function Reference/wp_delete_post|wp_delete_post($postid)]] - A generic function to delete a post in the post table
* &lt;tt&gt;get_post_categories&lt;/tt&gt;
* &lt;tt&gt;get_recent_posts&lt;/tt&gt;
* &lt;tt&gt;get_single_post&lt;/tt&gt;
* [[Function Reference/wp_insert_post|wp_insert_post($postarr=array())]] - A generic function for inserting data into the post table
* [[Function Reference/wp_update_post|wp_update_post($postarr=array())]] - A generic function to update data in the post table
* [[Function Reference/wp_publish_post|wp_publish_post($post_id)]] - Set a post's post_status to published. Calls &lt;tt&gt;wp_update_post&lt;/tt&gt;.
* &lt;tt&gt;wp_set_post_categories&lt;/tt&gt;
* &lt;tt&gt;get_all_page_ids&lt;/tt&gt;
* &lt;tt&gt;get_page&lt;/tt&gt;
* &lt;tt&gt;get_page_by_path&lt;/tt&gt;
* &lt;tt&gt;get_page_by_title&lt;/tt&gt;
* &lt;tt&gt;get_page_children&lt;/tt&gt;
* &lt;tt&gt;get_page_hierarchy&lt;/tt&gt;
* &lt;tt&gt;get_page_uri&lt;/tt&gt;
* &lt;tt&gt;get_pages&lt;/tt&gt;
* &lt;tt&gt;generate_page_uri_index&lt;/tt&gt;
* &lt;tt&gt;is_local_attachment&lt;/tt&gt;
* &lt;tt&gt;wp_insert_attachment&lt;/tt&gt;
* &lt;tt&gt;wp_delete_attachment&lt;/tt&gt;
* &lt;tt&gt;wp_get_attachment_metadata&lt;/tt&gt;
* &lt;tt&gt;wp_update_attachment_metadata&lt;/tt&gt;
* &lt;tt&gt;wp_get_attachment_url&lt;/tt&gt;
* &lt;tt&gt;wp_get_attachment_thumb_file&lt;/tt&gt;
* &lt;tt&gt;wp_get_attachment_thumb_url&lt;/tt&gt;
* &lt;tt&gt;wp_attachment_is_image&lt;/tt&gt;
* &lt;tt&gt;wp_mime_type_icon&lt;/tt&gt;
* &lt;tt&gt;wp_check_for_changed_slugs&lt;/tt&gt;
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Category Functions ==
These functions are contained in &lt;tt&gt;category.php&lt;/tt&gt;. See also [[Template Functions]].
* &lt;tt&gt;get_all_category_ids&lt;/tt&gt;
* &lt;tt&gt;get_categories&lt;/tt&gt;
* &lt;tt&gt;get_category&lt;/tt&gt;
* &lt;tt&gt;get_category_by_path&lt;/tt&gt;
* [[Function Reference/get_cat_ID|get_cat_ID($cat_name='General')]] - get category ID for given category name
* [[Function Reference/get_cat_name|get_cat_name($cat_id)]] - get category name for given ID
* &lt;tt&gt;cat_is_ancestor_of&lt;/tt&gt;
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
==User and Author Functions==
These functions are in &lt;tt&gt;user.php, pluggable.php, registration.php&lt;/tt&gt;. See also [[Template Functions]].
* &lt;tt&gt;get_profile&lt;/tt&gt;
* [[Function_Reference/get_usernumposts|get_usernumposts]] &amp;mdash; get post count for a specific user
* &lt;tt&gt;delete_usermeta&lt;/tt&gt;
* [[Function_Reference/get_usermeta|get_usermeta]] &amp;mdash; get meta data for a specific user
* &lt;tt&gt;update_usermeta&lt;/tt&gt;
* &lt;tt&gt;set_current_user&lt;/tt&gt;
* &lt;tt&gt;wp_set_current_user&lt;/tt&gt;
* &lt;tt&gt;wp_get_current_user&lt;/tt&gt;
* [[Function Reference/get_currentuserinfo|get_currentuserinfo]] &amp;mdash; get information on the current user
* [[Function Reference/get_userdata|get_userdata]] &amp;mdash; get information on any user
* &lt;tt&gt;get_userdatabylogin&lt;/tt&gt;
* &lt;tt&gt;wp_login&lt;/tt&gt;
* &lt;tt&gt;is_user_logged_in&lt;/tt&gt;
* &lt;tt&gt;auth_redirect&lt;/tt&gt;
* &lt;tt&gt;username_exists&lt;/tt&gt;
* &lt;tt&gt;email_exists&lt;/tt&gt;
* &lt;tt&gt;validate_username&lt;/tt&gt;
* &lt;tt&gt;wp_insert_user&lt;/tt&gt;
* &lt;tt&gt;wp_update_user&lt;/tt&gt;
* [[Function_Reference/wp_create_user|wp_create_user]] &amp;mdash; Create a user and add it to the user database.
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Feed Functions ==
These functions are in &lt;tt&gt;functions.php&lt;/tt&gt;, &lt;tt&gt;feed.php&lt;/tt&gt;, &lt;tt&gt;rss.php&lt;/tt&gt;
* [[Function_Reference/fetch_rss|fetch_rss]] -- retrieve an RSS feed from a URL with automatic caching (included in rss_functions.php)
* [[Function_Reference/wp_rss|wp_rss]] -- retrieve and display an RSS feed as an unordered list (included in rss_functions.php)
* [[Function_Reference/get_rss|get_rss]] -- retrieve and display an RSS feed as a list (ordering optional) (included in rss_functions.php)
* &lt;tt&gt;do_feed&lt;/tt&gt;
* &lt;tt&gt;do_feed_rdf&lt;/tt&gt;
* &lt;tt&gt;do_feed_rss&lt;/tt&gt;
* &lt;tt&gt;do_feed_rss2&lt;/tt&gt;
* &lt;tt&gt;do_feed_atom&lt;/tt&gt;
* &lt;tt&gt;get_bloginfo_rss&lt;/tt&gt;
* &lt;tt&gt;bloginfo_rss&lt;/tt&gt;
* &lt;tt&gt;get_the_title_rss&lt;/tt&gt;
* &lt;tt&gt;the_title_rss&lt;/tt&gt;
* &lt;tt&gt;the_content_rss&lt;/tt&gt;
* &lt;tt&gt;the_excerpt_rss&lt;/tt&gt;
* &lt;tt&gt;permalink_single_rss&lt;/tt&gt;
* &lt;tt&gt;comment_link&lt;/tt&gt;
* &lt;tt&gt;get_comment_author_rss&lt;/tt&gt;
* &lt;tt&gt;comment_author_rss&lt;/tt&gt;
* &lt;tt&gt;comment_text_rss&lt;/tt&gt;
* &lt;tt&gt;comments_rss_link&lt;/tt&gt;
* &lt;tt&gt;comments_rss&lt;/tt&gt;
* &lt;tt&gt;get_author_rss_link&lt;/tt&gt;
* &lt;tt&gt;get_category_rss_link&lt;/tt&gt;
* &lt;tt&gt;get_the_category_rss&lt;/tt&gt;
* &lt;tt&gt;the_category_rss&lt;/tt&gt;
* &lt;tt&gt;rss_enclosure&lt;/tt&gt;
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Comment, Ping, and Trackback Functions ==
These functions are found in &lt;tt&gt;comment.php&lt;/tt&gt;, &lt;tt&gt;functions.php&lt;/tt&gt;, &lt;tt&gt;post.php&lt;/tt&gt;. See also [[Template Functions]].
* &lt;tt&gt;check_comment&lt;/tt&gt;
* [[Function Reference/get_approved_comments|get_approved_comments]]
* &lt;tt&gt;get_comment&lt;/tt&gt;
* &lt;tt&gt;get_lastcommentmodified&lt;/tt&gt;
* &lt;tt&gt;sanitize_comment_cookies&lt;/tt&gt;
* &lt;tt&gt;wp_allow_comment&lt;/tt&gt;
* &lt;tt&gt;wp_delete_comment&lt;/tt&gt;
* &lt;tt&gt;wp_get_comment_status&lt;/tt&gt;
* &lt;tt&gt;wp_get_current_commenter&lt;/tt&gt;
* &lt;tt&gt;wp_insert_comment&lt;/tt&gt;
* &lt;tt&gt;wp_filter_comment&lt;/tt&gt;
* &lt;tt&gt;wp_throttle_comment_flood&lt;/tt&gt;
* &lt;tt&gt;wp_new_comment&lt;/tt&gt;
* &lt;tt&gt;wp_set_comment_status&lt;/tt&gt;
* &lt;tt&gt;wp_update_comment&lt;/tt&gt;
* &lt;tt&gt;wp_update_comment_count&lt;/tt&gt;
* &lt;tt&gt;discover_pingback_server_uri&lt;/tt&gt;
* &lt;tt&gt;do_all_pings&lt;/tt&gt;
* &lt;tt&gt;do_trackbacks&lt;/tt&gt;
* &lt;tt&gt;generic_ping&lt;/tt&gt;
* &lt;tt&gt;pingback&lt;/tt&gt;
* &lt;tt&gt;privacy_ping_filter&lt;/tt&gt;
* &lt;tt&gt;trackback&lt;/tt&gt;
* &lt;tt&gt;weblog_ping&lt;/tt&gt;
* &lt;tt&gt;do_enclose&lt;/tt&gt;
* &lt;tt&gt;add_ping&lt;/tt&gt;
* &lt;tt&gt;get_enclosed&lt;/tt&gt;
* &lt;tt&gt;get_pung&lt;/tt&gt;
* &lt;tt&gt;get_to_ping&lt;/tt&gt;
* &lt;tt&gt;trackback_url_list&lt;/tt&gt;
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Action, Filter, and Plugin Functions ==
These functions are contained in &lt;tt&gt;plugin.php&lt;/tt&gt;. See also [[Plugin API]].
* &lt;tt&gt;add_filter&lt;/tt&gt;
* &lt;tt&gt;apply_filters&lt;/tt&gt;
* &lt;tt&gt;merge_filters&lt;/tt&gt;
* &lt;tt&gt;remove_filter&lt;/tt&gt;
* [[Function Reference/add_action|add_action]]
* [[Function Reference/do_action|do_action]]
* &lt;tt&gt;did_action&lt;/tt&gt;
* &lt;tt&gt;do_action_ref_array&lt;/tt&gt;
* &lt;tt&gt;remove_action&lt;/tt&gt;
* &lt;tt&gt;plugin_basename&lt;/tt&gt;
* &lt;tt&gt;register_activation_hook&lt;/tt&gt;
* &lt;tt&gt;register_deactivation_hook&lt;/tt&gt;
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Theme-Related Functions ==
These functions are found in &lt;tt&gt;theme.php&lt;/tt&gt;.
* &lt;tt&gt;get_stylesheet&lt;/tt&gt;
* &lt;tt&gt;get_stylesheet_directory&lt;/tt&gt;
* &lt;tt&gt;get_stylesheet_directory_uri&lt;/tt&gt;
* &lt;tt&gt;get_stylesheet_uri&lt;/tt&gt;
* &lt;tt&gt;get_locale_stylesheet_uri&lt;/tt&gt;
* &lt;tt&gt;get_template&lt;/tt&gt;
* &lt;tt&gt;get_template_directory&lt;/tt&gt;
* &lt;tt&gt;get_template_directory_uri&lt;/tt&gt;
* [[Function Reference/get_theme_data|get_theme_data]]
* &lt;tt&gt;get_themes&lt;/tt&gt;
* &lt;tt&gt;get_theme&lt;/tt&gt;
* &lt;tt&gt;get_current_theme&lt;/tt&gt;
* &lt;tt&gt;get_theme_root&lt;/tt&gt;
* &lt;tt&gt;get_theme_root_uri&lt;/tt&gt;
* &lt;tt&gt;get_query_template&lt;/tt&gt;
* &lt;tt&gt;get_404_template&lt;/tt&gt;
* &lt;tt&gt;get_archive_template&lt;/tt&gt;
* &lt;tt&gt;get_author_template&lt;/tt&gt;
* &lt;tt&gt;get_category_template&lt;/tt&gt;
* &lt;tt&gt;get_date_template&lt;/tt&gt;
* &lt;tt&gt;get_home_template&lt;/tt&gt;
* &lt;tt&gt;get_page_template&lt;/tt&gt;
* &lt;tt&gt;get_paged_template&lt;/tt&gt;
* &lt;tt&gt;get_search_template&lt;/tt&gt;
* &lt;tt&gt;get_single_template&lt;/tt&gt;
* &lt;tt&gt;get_attachment_template&lt;/tt&gt;
* &lt;tt&gt;get_comments_popup_template&lt;/tt&gt;
* &lt;tt&gt;load_template&lt;/tt&gt;
* &lt;tt&gt;locale_stylesheet&lt;/tt&gt;
* &lt;tt&gt;validate_current_theme&lt;/tt&gt;
* &lt;tt&gt;get_theme_mod&lt;/tt&gt;
* &lt;tt&gt;set_theme_mod&lt;/tt&gt;
* &lt;tt&gt;get_header_textcolor&lt;/tt&gt;
* &lt;tt&gt;get_header_image&lt;/tt&gt;
* &lt;tt&gt;header_image&lt;/tt&gt;
* &lt;tt&gt;add_custom_image_header&lt;/tt&gt;
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Formatting Functions ==
These functions are contained in &lt;tt&gt;formatting.php&lt;/tt&gt;, &lt;tt&gt;functions.php&lt;/tt&gt;, &lt;tt&gt;kses.php&lt;/tt&gt;.
* [[Function_Reference/wptexturize|wptexturize( $text )]]
* [[Function_Reference/clean_pre|clean_pre( $text )]] - Returns the text without BR tags, and with P tags turned into line-breaks
* [[Function_Reference/wpautop|wpautop( $pee, $br = 1 )]] - Returns the text with HTML formatting for paragraphs
* [[Function_Reference/seems_utf8|seems_utf8($Str)]] - Returns true if given string seems like it is UTF8-encoded
* [[Function_Reference/wp_specialchars|wp_specialchars( $text, $quotes = 0 )]] - Like the PHP function htmlspecialchars except it doesn't double-encode HTML entities
* &lt;tt&gt;utf8_uri_encode&lt;/tt&gt;
* [[Function_Reference/remove_accents|remove_accents($string)]] - Returns a string with accents or umlauts without these
* &lt;tt&gt;sanitize_file_name&lt;/tt&gt;
* [[Function_Reference/sanitize_user|sanitize_user( $username, $strict = false )]] - Makes the username more machine-readable. Strict option for pure ASCII only.
* [[Function_Reference/sanitize_title|sanitize_title($title, $fallback_title = '')]]
* [[Function_Reference/sanitize_title_with_dashes|sanitize_title_with_dashes($title)]]
* [[Function_Reference/convert_chars|convert_chars($content, $flag = 'obsolete')]] - Translation of invalid Unicode references range to valid range
* &lt;tt&gt;funky_javascript_fix&lt;/tt&gt;
* [[Function_Reference/balanceTags|balanceTags($text, $is_comment = 0)]] - Balances Tags of string using a modified stack. Can be disabled by configuration.
* &lt;tt&gt;force_balance_tags&lt;/tt&gt;
* &lt;tt&gt;format_to_edit&lt;/tt&gt;
* &lt;tt&gt;format_to_post&lt;/tt&gt;
* [[Function_Reference/zeroise|zeroise($number,$threshold)]] - Adds leading zeros when necessary
* &lt;tt&gt;backslashit&lt;/tt&gt;
* &lt;tt&gt;trailingslashit&lt;/tt&gt;
* &lt;tt&gt;addslashes_gpc&lt;/tt&gt;
* &lt;tt&gt;stripslashes_deep&lt;/tt&gt;
* &lt;tt&gt;antispambot&lt;/tt&gt; - converts email address to anti-spam version
* &lt;tt&gt;make_clickable&lt;/tt&gt;
* &lt;tt&gt;wp_rel_nofollow&lt;/tt&gt;
* &lt;tt&gt;convert_smilies&lt;/tt&gt;
* &lt;tt&gt;is_email&lt;/tt&gt;
* &lt;tt&gt;wp_iso_descrambler&lt;/tt&gt;
* &lt;tt&gt;popuplinks&lt;/tt&gt; - converts a link into a popup link that will open in a different window
* &lt;tt&gt;sanitize_email&lt;/tt&gt;
* [[Function_Reference/ent2ncr|ent2ncr($text)]] - Returns HTML entity as its number representation.
* &lt;tt&gt;wp_richedit_pre&lt;/tt&gt;
* &lt;tt&gt;clean_url&lt;/tt&gt;
* &lt;tt&gt;htmlentities2&lt;/tt&gt;
* &lt;tt&gt;js_escape&lt;/tt&gt;
* &lt;tt&gt;attribute_escape&lt;/tt&gt;
* &lt;tt&gt;wp_make_link_relative&lt;/tt&gt; - makes an absolute link into a relative link
* &lt;tt&gt;add_magic_quotes&lt;/tt&gt;
* &lt;tt&gt;wp_kses&lt;/tt&gt;
* &lt;tt&gt;wp_kses_hook&lt;/tt&gt;
* &lt;tt&gt;wp_kses_version&lt;/tt&gt;
* &lt;tt&gt;wp_kses_split&lt;/tt&gt;
* &lt;tt&gt;wp_kses_split2&lt;/tt&gt;
* &lt;tt&gt;wp_kses_attr&lt;/tt&gt;
* &lt;tt&gt;wp_kses_hair&lt;/tt&gt;
* &lt;tt&gt;wp_kses_check_attr_val&lt;/tt&gt;
* &lt;tt&gt;wp_kses_bad_protocol&lt;/tt&gt;
* &lt;tt&gt;wp_kses_no_null&lt;/tt&gt;
* &lt;tt&gt;wp_kses_strip_slashes&lt;/tt&gt;
* &lt;tt&gt;wp_kses_array_lc&lt;/tt&gt;
* &lt;tt&gt;wp_kses_js_entities&lt;/tt&gt;
* &lt;tt&gt;wp_kses_html_error&lt;/tt&gt;
* &lt;tt&gt;wp_kses_bad_protocol_once&lt;/tt&gt;
* &lt;tt&gt;wp_kses_bad_protocol_once2&lt;/tt&gt;
* &lt;tt&gt;wp_kses_normalize_entities&lt;/tt&gt;
* &lt;tt&gt;wp_kses_normalize_entities2&lt;/tt&gt;
* &lt;tt&gt;wp_kses_decode_entities&lt;/tt&gt;
* &lt;tt&gt;wp_filter_kses&lt;/tt&gt;
* &lt;tt&gt;wp_filter_post_kses&lt;/tt&gt;
* &lt;tt&gt;wp_filter_nohtml_kses&lt;/tt&gt;
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Miscellanous Functions ==
These functions are contained in &lt;tt&gt;formatting.php&lt;/tt&gt;, &lt;tt&gt;functions.php&lt;/tt&gt;, &lt;tt&gt;bookmarks.php&lt;/tt&gt;, &lt;tt&gt;cron.php&lt;/tt&gt;, &lt;tt&gt;l10n.php&lt;/tt&gt;, &lt;tt&gt;user.php&lt;/tt&gt;, &lt;tt&gt;pluggable.php&lt;/tt&gt;
Time/Date Functions
* &lt;tt&gt;get_gmt_from_date&lt;/tt&gt;
* &lt;tt&gt;get_date_from_gmt&lt;/tt&gt;
* &lt;tt&gt;iso8601_timezone_to_offset&lt;/tt&gt;
* &lt;tt&gt;iso8601_to_datetime&lt;/tt&gt;
* &lt;tt&gt;human_time_diff&lt;/tt&gt;
* &lt;tt&gt;mysql2date&lt;/tt&gt;
* [[Function Reference/current time|current_time]]
* &lt;tt&gt;date_i18n&lt;/tt&gt;
* &lt;tt&gt;get_weekendstartend&lt;/tt&gt;
* &lt;tt&gt;get_lastpostdate&lt;/tt&gt;
* &lt;tt&gt;get_lastpostmodified&lt;/tt&gt;
* &lt;tt&gt;is_new_day&lt;/tt&gt;
Serialization
* &lt;tt&gt;maybe_serialize&lt;/tt&gt;
* &lt;tt&gt;maybe_unserialize&lt;/tt&gt;
* &lt;tt&gt;is_serialized&lt;/tt&gt;
* &lt;tt&gt;is_serialized_string&lt;/tt&gt;
Options
* &lt;tt&gt;get_option&lt;/tt&gt;
* &lt;tt&gt;form_option&lt;/tt&gt; -- like &lt;tt&gt;get_option&lt;/tt&gt;, but removes attributes from result&lt;/tt&gt;
* &lt;tt&gt;get_alloptions&lt;/tt&gt;
* &lt;tt&gt;update_option&lt;/tt&gt; -- given option name and new value, it makes a safe update of given option's database row.
* [[Function Reference/add option|add_option]]
* [[Function Reference/delete option|delete_option]] -- removes row of given option name from the options database table.
* &lt;tt&gt;get_user_option&lt;/tt&gt;
* &lt;tt&gt;update_user_option&lt;/tt&gt;
XMLRPC
* &lt;tt&gt;xmlrpc_getposttitle&lt;/tt&gt;
* &lt;tt&gt;xmlrpc_getpostcategory&lt;/tt&gt;
* &lt;tt&gt;xmlrpc_removepostdata&lt;/tt&gt;
* &lt;tt&gt;user_pass_ok&lt;/tt&gt;
Localization
See also [[Translating WordPress]].
* &lt;tt&gt;get_locale&lt;/tt&gt;
* &lt;tt&gt;__&lt;/tt&gt;
* &lt;tt&gt;_e&lt;/tt&gt;
* &lt;tt&gt;_ngettext&lt;/tt&gt;
* &lt;tt&gt;load_textdomain&lt;/tt&gt;
* &lt;tt&gt;load_default_textdomain&lt;/tt&gt;
* &lt;tt&gt;load_plugin_textdomain&lt;/tt&gt;
* &lt;tt&gt;load_theme_textdomain&lt;/tt&gt;
Cron (Scheduling)
* &lt;tt&gt;wp_schedule_single_event&lt;/tt&gt;
* &lt;tt&gt;wp_schedule_event&lt;/tt&gt;
* &lt;tt&gt;wp_reschedule_event&lt;/tt&gt;
* &lt;tt&gt;wp_unschedule_event&lt;/tt&gt;
* &lt;tt&gt;wp_clear_scheduled_hook&lt;/tt&gt;
* &lt;tt&gt;wp_next_scheduled&lt;/tt&gt;
* &lt;tt&gt;spawn_cron&lt;/tt&gt;
* &lt;tt&gt;wp_cron&lt;/tt&gt;
* &lt;tt&gt;wp_get_schedules&lt;/tt&gt;
* &lt;tt&gt;wp_get_schedule&lt;/tt&gt;
Miscellaneous
* &lt;tt&gt;gzip_compression&lt;/tt&gt;
* &lt;tt&gt;make_url_footnote&lt;/tt&gt;
* &lt;tt&gt;wp_get_http_headers&lt;/tt&gt;
* &lt;tt&gt;add_query_arg&lt;/tt&gt;
* &lt;tt&gt;remove_query_arg&lt;/tt&gt;
* &lt;tt&gt;wp_remote_fopen&lt;/tt&gt;
* &lt;tt&gt;wp&lt;/tt&gt;
* &lt;tt&gt;status_header&lt;/tt&gt;
* &lt;tt&gt;nocache_headers&lt;/tt&gt;
* &lt;tt&gt;cache_javascript_headers&lt;/tt&gt;
* &lt;tt&gt;get_num_queries&lt;/tt&gt;
* &lt;tt&gt;bool_from_yn&lt;/tt&gt; - converts a &quot;Y/N&quot; variable into boolean true/false
* &lt;tt&gt;do_robots&lt;/tt&gt;
* &lt;tt&gt;is_blog_installed&lt;/tt&gt;
* &lt;tt&gt;wp_nonce_url&lt;/tt&gt;
* &lt;tt&gt;wp_nonce_field&lt;/tt&gt;
* &lt;tt&gt;wp_referer_field&lt;/tt&gt;
* &lt;tt&gt;wp_original_referer_field&lt;/tt&gt;
* &lt;tt&gt;wp_get_referer&lt;/tt&gt;
* &lt;tt&gt;wp_get_original_referer&lt;/tt&gt;
* &lt;tt&gt;wp_mkdir_p&lt;/tt&gt;
* &lt;tt&gt;wp_upload_dir&lt;/tt&gt;
* &lt;tt&gt;wp_upload_bits&lt;/tt&gt;
* &lt;tt&gt;wp_check_filetype&lt;/tt&gt;
* &lt;tt&gt;wp_explain_nonce&lt;/tt&gt;
* &lt;tt&gt;wp_nonce_ays&lt;/tt&gt;
* &lt;tt&gt;wp_die&lt;/tt&gt;
* &lt;tt&gt;get_bookmark&lt;/tt&gt;
* &lt;tt&gt;get_bookmarks&lt;/tt&gt;
* &lt;tt&gt;wp_mail&lt;/tt&gt;
* &lt;tt&gt;check_admin_referer&lt;/tt&gt;
* &lt;tt&gt;check_ajax_referer&lt;/tt&gt;
* &lt;tt&gt;wp_redirect&lt;/tt&gt;
* &lt;tt&gt;wp_get_cookie_login&lt;/tt&gt;
* &lt;tt&gt;wp_setcookie&lt;/tt&gt;
* &lt;tt&gt;wp_clearcookie&lt;/tt&gt;
* &lt;tt&gt;wp_notify_postauthor&lt;/tt&gt;
* &lt;tt&gt;wp_notify_moderator&lt;/tt&gt;
* &lt;tt&gt;wp_new_user_notification&lt;/tt&gt;
* &lt;tt&gt;wp_verify_nonce&lt;/tt&gt;
* &lt;tt&gt;wp_create_nonce&lt;/tt&gt;
* &lt;tt&gt;wp_salt&lt;/tt&gt;
* &lt;tt&gt;wp_hash&lt;/tt&gt;
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Classes ==
The following classes were created by WordPress developers, and are found in files &lt;tt&gt;capabilities.php&lt;/tt&gt;,
&lt;tt&gt;classes.php&lt;/tt&gt;, &lt;tt&gt;class-snoopy.php&lt;/tt&gt;, &lt;tt&gt;locale.php&lt;/tt&gt;, &lt;tt&gt;query.php&lt;/tt&gt;, &lt;tt&gt;rewrite.php&lt;/tt&gt;, &lt;tt&gt;script-loader.php&lt;/tt&gt;, &lt;tt&gt;wp-db.php&lt;/tt&gt;:
* WP - general request handling
* WP_Ajax_Response - AJAX handling
* [[Function_Reference/WP_Cache|WP_Object_Cache]] (formerly &lt;tt&gt;WP_Cache&lt;/tt&gt;) - Object cache (and functions &lt;tt&gt;wp_cache_add, wp_cache_close, wp_cache_delete, wp_cache_flush, wp_cache_get, wp_cache_init, wp_cache_replace, wp_cache_set&lt;/tt&gt;)
* WP_Error - error handling (and function &lt;tt&gt;is_wp_error&lt;/tt&gt;)
* &lt;tt&gt;WP_Locale&lt;/tt&gt; - handles date and time locales
* [[Function_Reference/WP_Query|WP_Query]] - Request parsing and manipulation, posts fetching (with functions &lt;tt&gt;get_query_var, query_posts, have_posts, in_the_loop, rewind_posts, the_post, wp_old_slug_redirect, setup_postdata&lt;/tt&gt;, as well as the [[Conditional Tags]] &lt;tt&gt;is_*&lt;/tt&gt;)
* [[Function_Reference/WP_Rewrite|WP_Rewrite]] - Rewrite rules (and functions &lt;tt&gt;add_rewrite_rule, add_rewrite_tag, add_feed, add_rewrite_endpoint, url_to_postid&lt;/tt&gt;)
* WP_Roles, WP_Role, WP_User - Users and capabilities (and functions &lt;tt&gt;map_meta_cap, current_user_can, get_role, add_role, remove_role&lt;/tt&gt;)
* WP_Scripts - JavaScript loading (and functions &lt;tt&gt;wp_print_scripts, wp_register_script, wp_deregister_script, wp_enqueue_script&lt;/tt&gt;)
* Walker, Walker_Page, Walker_PageDropdown, Walker_Category, Walker_CategoryDropdown - Display tree-like data
* [[Function_Reference/wpdb Class|wpdb]] - Database interface
The following classes were created by outside developers, and are found in files &lt;tt&gt;class-IXR.php&lt;/tt&gt;, &lt;tt&gt;class-pop3.php&lt;/tt&gt;, &lt;tt&gt;class-snoopy.php&lt;/tt&gt;, &lt;tt&gt;gettext.php&lt;/tt&gt;, &lt;tt&gt;rss.php&lt;/tt&gt;, &lt;tt&gt;streams.php&lt;/tt&gt;:
* [http://scripts.incutio.com/xmlrpc/ IXR] - XML-RPC Classes, including IXR_Value, IXR_Message, IXR_Server, IXR_IntrospectionServer, IXR_Request, IXR_Client, IXR_ClientMulticall, IXR_Error, IXR_Date, IXR_Base64
* [http://sourceforge.net/projects/snoopy/ Snoopy] - HTTP client
* gettext_reader (part of [http://savannah.nongnu.org/projects/php-gettext/ PHP-gettext]) - Localization Class
* [http://magpierss.sourceforge.net/ RSS Classes (MagpieRSS and RSSCache)] (and functions &lt;tt&gt;fetch_rss, is_info, is_success, is_redirect, is_error, is_client_error, is_server_error, parse_w3cdtf, wp_rss, get_rss&lt;/tt&gt;)
* POP3: SquirrelMail wrapper
* &lt;tt&gt;StreamReader, StringReader, FileReader, CachedFileReader&lt;/tt&gt;
|}
[[Category:Advanced Topics]]
[[Category:Functions]]
[[Category:WordPress Development]]</p>
</d:entry>
<d:entry id="get_theme_data" d:title="get theme data">
<d:index d:value="get theme data"/>
<h1>get theme data</h1>
<p>{{Deprecated|new_function=wp_get_theme}}
== Description ==
Returns an array of information about a theme file.
This function has been replaced with [[Function Reference/wp_get_theme|wp_get_theme]] in WordPress 3.4
== Usage ==
%%% &lt;?php get_theme_data( $theme_filename ); ?&gt; %%%
Use [[Function Reference/wp_get_theme|wp_get_theme]] instead.
== Parameters ==
{{Parameter|$theme_filename|string|Path and filename of the theme's &lt;tt&gt;style.css&lt;/tt&gt;.}}
== Return values ==
;(array)
: The function returns an array containing the following keyed information:
; 'Name' : (''string'') The Themes name.
; 'Title' : (''string'') Either the Theme's name or a HTML fragment containg the Theme's name linked to the Theme's URI if the Theme's URI is defined.
; 'URI' : (''string'') The Themes URI.
; 'Description' : (''string'') A HTML fragment containg the Themes description after it has passed through [[Function_Reference/wptexturize|wptexturize]].
; 'AuthorURI' : (''string'') The Theme's Author URI.
; 'Template' : (''string'') The name of the parent Theme if one exists.
; 'Version' : (''string'') The Theme's version number.
; 'Status' : (''string'') the Theme's Status (defaults to 'publish')
; 'Tags' : (''string'') the Theme's Tags
; 'Author' : (''string'') Either the Author's name or a HTML fragment containing the Author's name linked to the Author's URI if the Author's URI is defined.
== Example ==
=== Usage ===
Get the information from the theme's style.css and display the Theme Name and Author.
&lt;pre&gt;
&lt;?php
/*
* Assign theme folder name that you want to get information.
* make sure theme exist in wp-content/themes/ folder.
*/
$theme_name = 'twentyeleven';
/*
* Do not use get_stylesheet_uri() as $theme_filename,
* it will result in PHP fopen error if allow_url_fopen is set to Off in php.ini,
* which is what most shared hosting does. You can use get_stylesheet_directory()
* or get_template_directory() though, because they return local paths.
*/
$theme_data = get_theme_data( get_theme_root() . '/' . $theme_name . '/style.css' );
echo $theme_data['Title'];
echo $theme_data['Author'];
?&gt;
&lt;/pre&gt;
== Source File ==
&lt;tt&gt;get_theme_data()&lt;/tt&gt; is located in {{Trac|wp-includes/deprecated.php}}.
== Related ==
{{Tag Footer}}
[[Category:Functions]]
[[Category:File Header API]]</p>
</d:entry>
<d:entry id="update_option" d:title="update option">
<d:index d:value="update option"/>
<h1>update option</h1>
<p>{{Languages|
{{en|Function_Reference/update_option}}
{{ru|Справочник_по_функциям/update_option}}
}}
== Description ==
Use the function &lt;tt&gt;update_option()&lt;/tt&gt; to update a named option/value pair to the options database table. The &lt;tt&gt;$option&lt;/tt&gt; (option name) value is escaped with &lt;tt&gt;$wpdb-&gt;prepare&lt;/tt&gt; before the INSERT statement but not the option value, this value should always be properly sanitized.
This function may be used in place of [[Function Reference/add option|&lt;tt&gt;add_option&lt;/tt&gt;]], although it is not as flexible. &lt;tt&gt;update_option&lt;/tt&gt; will check to see if the option already exists. If it does not, it will be added with &lt;tt&gt;add_option('option_name', 'option_value')&lt;/tt&gt;. Unless you need to specify the optional arguments of &lt;tt&gt;add_option()&lt;/tt&gt;, &lt;tt&gt;update_option()&lt;/tt&gt; is a useful catch-all for both adding and updating options.
'''Note:''' This function cannot be used to change whether an option is to be loaded (or not loaded) by &lt;tt&gt;[[Function_Reference/wp_load_alloptions | wp_load_alloptions()]]&lt;/tt&gt;. In that case, a [[Function_Reference/delete_option|&lt;tt&gt;delete_option()&lt;/tt&gt;]] should be followed by use of the [[Function_Reference/add_option|&lt;tt&gt;add_option()&lt;/tt&gt;]] function.
== Usage ==
%%%&lt;?php update_option( $option, $new_value ); ?&gt;%%%
== Parameters ==
{{Parameter|$option|string|Name of the option to update. Must not exceed 64 characters. A list of valid default options to update can be found at the [[Option Reference]].}}
{{Parameter|$newvalue|mixed|The NEW value for this option name. This value can be an integer, string, array, or object.}}
== Return Value ==
{{Return||boolean|True if option value has changed, false if not or if update failed.}}
== Example ==
=== Updating Core Options ===
Set the default comment status to 'closed':
update_option( 'default_comment_status', 'closed' );
This option is usually set by from the Settings &gt; Discussion administration panel. See the [[Option Reference]] for a full list of options used by WordPress Core.
=== Updating Custom Options ===
You can also create your own custom options. To update the option &lt;tt&gt;'myhack_extraction_length'&lt;/tt&gt; with the value 255, we would do this:
update_option( 'myhack_extraction_length', 255 );
This will automatically add the option if it does not exist. However, if we don't want this option to be autoloaded, we have to add it with a&lt;tt&gt;dd_option()&lt;/tt&gt;. In this example, we update the option if it already exists, and if it does not exist we use &lt;tt&gt;add_option()&lt;/tt&gt; and set &lt;tt&gt;$autoload&lt;/tt&gt; to &quot;no&quot;.
&lt;pre&gt;
&lt;?php
$option_name = 'myhack_extraction_length' ;
$new_value = '255' ;
if ( get_option( $option_name ) !== false ) {
// The option already exists, so we just update it.
update_option( $option_name, $new_value );
} else {
// The option hasn't been added yet. We'll add it with $autoload set to 'no'.
$deprecated = null;
$autoload = 'no';
add_option( $option_name, $new_value, $deprecated, $autoload );
}
?&gt;
&lt;/pre&gt;
== Change Log ==
Since: [[Version 1.0|1.0.0]]
== Source File ==
&lt;tt&gt;update_option()&lt;/tt&gt; is located in {{Trac|wp-includes/option.php}}.
== Related ==
{{Option Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="Function_Reference_2.0.x" d:title="Function Reference 2.0.x">
<d:index d:value="Function Reference 2.0.x"/>
<h1>Function Reference 2.0.x</h1>
<p>__NOTOC__
'''Note: This page applies to versions of WordPress prior to WordPress 2.1, and is also incomplete. The current WordPress function reference is at [[Function Reference]]'''.
&lt;div style=&quot;border:blue 1px solid;padding:10px; text-align:center; background: #E6CCFF&quot;&gt;
'''EDITORS AND CONTRIBUTORS'''
The layout and structure of this page will follow [[Template Tags]]. Please create pages for these functions as subpages of this page. If you create a subpage for a function, please include information and examples of usage of that function, if possible, per the examples found in [[Template Tags]].
For example: &lt;nowiki&gt;[[Function_Reference/wpdb_Class|wpdb_Class]]&lt;/nowiki&gt;.
&lt;/div&gt;
WordPress defines many useful functions. Rather than reinventing the wheel, you should take advantage of the core functions whenever possible. Of course, if the slick new plugin you are designing needs a better wheel, you are on your own, but at least you can take inspiration from the following functions.
Please check out the [[Mailing Lists#Documentation|wp-docs mailing list]] to find out how you can contribute to this section. And it needs ''your'' help!.
&lt;!-- remove this after there's enough example content --&gt;
==Functions by category==
{| cellspacing=&quot;10&quot; width=&quot;100%&quot;
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== General Functions ==
'''[[Function Reference|functions.php:]]'''
* profile
* time/date
** [[Function Reference/current time|current_time]]
* options
** [[Function Reference/add option|add_option]]
** [[Function Reference/delete option|delete_option]] -- removes row of given option name from the options database table.
** form_option -- does a [[Function_Reference/get_settings|get_settings]] on given string and returns info for an option. Before calling get_settings, the indata is passed through htmlspecialchars().
** get_alloptions - no parameters
** [[Function Reference/get settings|get_settings]] (alias: get_option)
** update_option -- given option name and new value, it makes a safe update of given option's database row.
* meta
* trackpack/ping
* xmlrpc
* filters
* actions
* is_single,page,archive,time/data
* themes/templates
* htmlentities2
* cookies
* plugins
* mail (pop) access
'''[[Function Reference|complete list]]'''
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Formatting Functions ==
This list is incomplete, please contribute.
* [[Function_Reference/wptexturize|wptexturize( $text )]]
* [[Function_Reference/clean_pre|clean_pre( $text )]] - Returns the text without BR tags, and with P tags turned into line-breaks
* [[Function_Reference/wpautop|wpautop( $pee, $br = 1 )]] - Returns the text with HTML formatting for paragraphs
* [[Function_Reference/seems_utf8|seems_utf8($Str)]] - Returns true if given string seems like it is UTF8-encoded
* [[Function_Reference/wp_specialchars|wp_specialchars( $text, $quotes = 0 )]] - Like the PHP function htmlspecialchars except it doesn't double-encode HTML entities
* [[Function_Reference/remove_accents|remove_accents($string)]] - Returns a string with accents or umlauts without these
* [[Function_Reference/sanitize_user|sanitize_user( $username, $strict = false )]] - Makes the username more machine-readable. Strict option for pure ASCII only.
* [[Function_Reference/sanitize_title|sanitize_title($title, $fallback_title = '')]]
* [[Function_Reference/sanitize_title_with_dashes|sanitize_title_with_dashes($title)]]
* [[Function_Reference/convert_chars|convert_chars($content, $flag = 'obsolete')]] - Translation of invalid Unicode references range to valid range
* [[Function_Reference/balanceTags|balanceTags($text, $is_comment = 0)]] - Balances Tags of string using a modified stack. Can be disabled by configuration.
* [[Function_Reference/zeroise|zeroise($number,$threshold)]] - Adds leading zeros when necessary
* [[Function_Reference/ent2ncr|ent2ncr($text)]] - Returns HTML entity as its number representation.
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Post Functions ==
* [[Function Reference/get_post|get_post]] - get information on a specific post
* [[Function Reference/get_cat_name|get_cat_name($cat_id)]] - get category name for given ID
* [[Function Reference/get_cat_ID|get_cat_ID($cat_name='General')]] - get category ID for given category name
* [[Function Reference/get_author_name|get_author_name( $auth_id )]] - get author's preferred display name
* [[Function Reference/get_post_mime_type|get_post_mime_type($ID = &quot;&quot;)]] - takes a post ID, returns its MIME type
* [[Function Reference/wp_insert_post|wp_insert_post($postarr=array())]] - A generic function for inserting data into the post table
* [[Function Reference/wp_update_post|wp_update_post($postarr=array())]] - A generic function to update data in the post table
* [[Function Reference/wp_publish_post|wp_publish_post($post_id)]] - Set a post's post_status to 'publish'ed. Calls wp_update_post.
* [[Function Reference/wp_delete_post|wp_delete_post($postid)]] - A generic function to delete a post in the post table
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Comment Functions ==
* [[Function Reference/get_approved_comments|get_approved_comments]]
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Feed Functions ==
* is_feed -- returns a Boolean, true if the current context is within a feed (wrapper for $WP_Query-&gt;is_feed)
* [[Function_Reference/fetch_rss|fetch_rss]] -- retrieve an RSS feed from a URL with automatic caching (included in rss_functions.php)
* [[Function_Reference/wp_rss|wp_rss]] -- retrieve and display an RSS feed as an unordered list (included in rss_functions.php)
* [[Function_Reference/get_rss|get_rss]] -- retrieve and display an RSS feed as a list (ordering optional) (included in rss_functions.php)
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Link Functions ==
[[Function Reference/get category link|get_category_link]]
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Administration Functions ==
* [[Function_Reference/insert_with_markers|insert_with_markers]] -- Writes a string (e.g. rewrite rules for the .htaccess file) to a given file namne between two markers, BEGIN and END.
*Please Contribute more...
|valign=&quot;top&quot; bgcolor=&quot;#f0f0ff&quot; style=&quot;border:1px solid #c6c9ff;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
== Classes ==
===WordPress classes===
* [[Function_Reference/WP_Cache|Object Cache]]
* [[Function_Reference/wpdb Class|wpdb]] - Database Interface
* [[Function_Reference/WP_Query|WP_Query]] - Request parsing and manipulation, posts fetching
* [[Function_Reference/WP_Rewrite|WP_Rewrite]] - Rewrite rules
* retrospam_mgr - Spam management
* WP - general request handling (in [[Version 1.6]])
* Capabilities Classes (WP_Roles, WP_Role, WP_User) (in [[Version 2.0]])
===External classes===
* [http://scripts.incutio.com/xmlrpc/ IXR] - XML-RPC Classes
* [http://sourceforge.net/projects/snoopy/ Snoopy] - HTTP client
* gettext_reader (part of [http://savannah.nongnu.org/projects/php-gettext/ PHP-gettext]) - Localization Class
* [http://magpierss.sourceforge.net/ RSS Classes (Magpie and RSSCache)]
|- valign=&quot;top&quot;
|bgcolor=&quot;#fbfbef&quot; style=&quot;border:1px solid #ffc9c9;padding:1em;padding-top:0.5em; color: black;&quot; width=&quot;50%&quot;|
==User Functions==
* [[Function Reference/get_currentuserinfo|get_currentuserinfo]] &amp;mdash; get information on the current user
* [[Function Reference/get_userdata|get_userdata]] &amp;mdash; get information on any user
* [[Function_Reference/get_usernumposts|get_usernumposts]] &amp;mdash; get post count for a specific user
* [[Function_Reference/get_usermeta|get_usermeta]] &amp;mdash; get meta data for a specific user
* [[Function_Reference/wp_create_user|wp_create_user]] &amp;mdash; Create a user and add it to the user database.
|}
==Functions by file==
The functions are defined in several PHP files, nearly all residing in the &lt;tt&gt;wp-includes&lt;/tt&gt; directory:
; &lt;tt&gt;classes.php&lt;/tt&gt;, &lt;tt&gt;class-IXR.php&lt;/tt&gt;, &lt;tt&gt;class-pop3.php&lt;/tt&gt;, &lt;tt&gt;class-snoopy.php&lt;/tt&gt;, &lt;tt&gt;gettext.php&lt;/tt&gt;, &lt;tt&gt;wp-db.php&lt;/tt&gt; : [[#Classes|Classes]].
; &lt;tt&gt;comment-functions.php&lt;/tt&gt; : [[#Comment_Functions|Comment functions]].
; &lt;tt&gt;feed-functions.php&lt;/tt&gt;, &lt;tt&gt;rss-functions.php&lt;/tt&gt; : [[#Feed_Functions|Feed functions]].
; &lt;tt&gt;functions-compat.php&lt;/tt&gt; : Compatibility functions for those running lower PHP versions.
; &lt;tt&gt;functions-formatting.php&lt;/tt&gt; : [[#Formatting_Functions|Formatting functions]].
; &lt;tt&gt;functions.php&lt;/tt&gt; : [[#Basic_Functions|Basic functions]].
; &lt;tt&gt;functions-post.php&lt;/tt&gt; : [[#Post_Functions|Post functions]].
; &lt;tt&gt;links.php&lt;/tt&gt; : [[#Link_Functions|Link functions]].
; &lt;tt&gt;pluggable-functions.php&lt;/tt&gt; : Pluggable functions (1.5.1+).
; &lt;tt&gt;template-functions-*.php&lt;/tt&gt; : [[Template Tags]].
; &lt;tt&gt;registration-functions.php&lt;/tt&gt;, &lt;tt&gt;wp-admin/admin-functions.php&lt;/tt&gt; : [[#Administration_Functions|Administration functions]].
== DRAFT ==
The following functions are to be moved into their appropriate categories above.
* [[Function Reference/add_action|add_action]]
* add_filter
* add_magic_quotes
* add_post_meta
* add_query_arg
* apply_filters
* auth_redirect
* date_i18n
* debug_fclose
* debug_fopen
* delete_post_meta
* [[Function Reference/do_action|do_action]]
* do_enclose
* generic_ping
* get_404_template
* get_archive_template
* [[Function Reference/get_approved_comments|get_approved_comments]]
* get_author_template
* get_category_template
* get_catname
* get_comments_popup_template
* get_current_theme
* get_date_template
* get_home_template
* get_lastpostdate
* get_lastpostmodified
* get_page_template
* get_page_uri
* get_paged_template
* get_post_meta
* get_postdata
* get_posts
* get_profile
* get_query_template
* get_query_var
* get_search_template
* get_single_template
* get_stylesheet
* get_stylesheet_directory
* get_stylesheet_directory_uri
* get_stylesheet_uri
* get_template
* get_template_directory
* get_template_directory_uri
* get_theme
* [[Function Reference/get_theme_data|get_theme_data]]
* get_theme_root
* get_theme_root_uri
* get_themes
* get_userdatabylogin
* get_userid
* get_weekstartend
* gzip_compression
* have_posts
* htmlentities2
* is_404
* is_archive
* is_author
* is_category
* is_comments_popup
* is_date
* is_day
* is_home
* is_month
* is_new_day
* is_page
* is_paged
* is_plugn_page
* is_search
* is_single
* is_time
* is_trackback
* is_year
* load_template
* make_url_footnote
* merge_filters
* mysql2date
* query_posts
* remove_action
* remove_filter
* remove_query_arg
* rewind_posts
* setup_postdata
* start_wp
* the_post
* [[Function Reference/timer_stop|timer_stop]]
* trackback
* update_category_cache
* update_post_caches
* update_post_meta
* update_user_cache
* url_to_postid
* user_pass_ok
* weblog_ping
* wp_clearcookie
* wp_head
* wp_insert_post
* wp_login
* wp_mail
* wp_setcookie
* xmlrpc_getpostcategory
* xmlrpc_getposttitle
* xmlrpc_removepostdata
[[Category:Advanced Topics]]
[[Category:Functions]]
[[Category:WordPress Development]]
[[Category:Redundant]]</p>
</d:entry>
<d:entry id="get_settings" d:title="get settings">
<d:index d:value="get settings"/>
<h1>get settings</h1>
<p>{{Deprecated}}
== Description ==
* '''NB:''' instead of get_settings, use [[Function_Reference/get_option|get_option($optionname)]]
A safe way of getting values for a named option from the options database table.
=== Note ===
For a complete list of all options available through this function, go to
&lt;nowiki&gt; http://www.yoursite.com/wp-admin/options.php &lt;/nowiki&gt;
'''Also:''' You can modify any/all of the options from the same page.
=== Aliases ===
%%% get_option($optionname) %%%
This is a wrapper around the get_settings function, added for readability and a more humane interface.
== Usage ==
%%% &lt;?php echo get_settings('show'); ?&gt; %%%
or
%%% &lt;?php echo get_option('show'); ?&gt; %%%
== Examples ==
=== Show Blog Title ===
Displays your blog's title in a &amp;lt;h1&amp;gt; tag.
%%% &lt;h1&gt;&lt;?php echo get_settings('blogname'); ?&gt;&lt;/h1&gt; %%%
or
%%% &lt;h1&gt;&lt;?php echo get_option('blogname'); ?&gt;&lt;/h1&gt; %%%
=== Show Character Set ===
Displays the character set your blog is using (ex: UTF-8)
%%% &lt;p&gt;Character set: &lt;?php echo get_settings('blog_charset'); ?&gt; &lt;/p&gt; %%%
or
%%% &lt;p&gt;Character set: &lt;?php echo get_option('blog_charset'); ?&gt; &lt;/p&gt; %%%
===Retrieve Administrator E-mail===
Retrieve the e-mail of the blog administrator, storing it in a variable.
%%%&lt;?php $admin_email = get_settings('admin_email'); ?&gt;%%%
or
%%% &lt;?php $admin_email = get_option('admin_email'); ?&gt; %%%
== Parameters ==
; show : (''string'') Name of the option. Underscores separate words, lowercase only - this is going to be in a database. Valid values:
:* &lt;tt&gt;'admin_email'&lt;/tt&gt; - E-mail address of blog administrator.
:* &lt;tt&gt;'blogname'&lt;/tt&gt; - Weblog title; set in General Options.
:* &lt;tt&gt;'blogdescription'&lt;/tt&gt; - Tagline for your blog; set in General Options.
:* &lt;tt&gt;'blog_charset'&lt;/tt&gt; - Character encoding for your blog; set in Reading Options.
:* &lt;tt&gt;'date_format'&lt;/tt&gt; - Default date format; set in General Options.
:* &lt;tt&gt;'default_category'&lt;/tt&gt; - Default post category; set in Writing Options.
:* &lt;tt&gt;'home'&lt;/tt&gt; - The blog's home web address; set in General Options.
:* &lt;tt&gt;'siteurl'&lt;/tt&gt; - WordPress web address; set in General Options.&lt;br /&gt;'''Warning:''' This is not the same as get_bloginfo('siteurl'); which will return the homepage url. Use get_bloginfo('wpurl'), get_settings() has been deprecated.
:* &lt;tt&gt;'template'&lt;/tt&gt; - The current theme's name; set in Presentation.
:* &lt;tt&gt;'start_of_week'&lt;/tt&gt; - Day of week calendar should start on; set in General Options.
:* &lt;tt&gt;'upload_path'&lt;/tt&gt; - Default upload location; set in Miscellaneous Options.
:* &lt;tt&gt;'posts_per_page'&lt;/tt&gt; - Maximum number of posts to show on a page; set in Reading Options.
:* &lt;tt&gt;'posts_per_rss'&lt;/tt&gt; - Maximum number of most recent posts to show in the syndication feed; set in Reading Options.
:There are many more options available, a lot of which depend on what plugins you have installed. Visit the /wp-admin/options.php page for a complete list.
== Related ==
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="form_option" d:title="form option">
<d:index d:value="form option"/>
<h1>form option</h1>
<p>== Description ==
Echo option value after sanitizing for forms.
== Usage ==
%%%&lt;?php form_option( $option ) ?&gt;%%%
== Parameters ==
{{Parameter|$option|string|Option name.}}
== Return Values ==
; (Echo) : '''echos''' the value in a get_option after its passed through esc_attr()
== Examples ==
&lt;!-- Need creative examples. Feel free to link to external examples. --&gt;
== Notes ==
* Uses: [[Function_Reference/esc_attr|&lt;tt&gt;esc_attr()&lt;/tt&gt;]] to sanitize option value.
== Change Log ==
Since: 1.5.0
== Source File ==
&lt;tt&gt;form_option()&lt;/tt&gt; is located in {{Trac|wp-includes/option.php}}.
== Related ==
{{Option Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="wp_create_user" d:title="wp create user">
<d:index d:value="wp create user"/>
<h1>wp create user</h1>
<p>== Description ==
The [[Function_Reference/wp_create_user|wp_create_user]] function allows you to insert a new user into the WordPress database. It uses the $wpdb class to escape the variable values, preparing it for insertion into the database. Then the [http://php.net/compact PHP compact() function] is used to create an array with these values. To create a user with additional parameters, use [[Function_Reference/wp_insert_user|wp_insert_user()]].
== Usage ==
%%% &lt;?php wp_create_user( $username, $password, $email ); ?&gt; %%%
== Example ==
As used in wp-admin/upgrade-functions.php:
&lt;pre&gt;
$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
$random_password = __('User already exists. Password inherited.');
}
&lt;/pre&gt;
== Parameters ==
{{Parameter|$username|string|The username of the user to be created.}}
{{Parameter|$password|string|The password of the user to be created.}}
{{Parameter|$email|string|The email address of the user to be created.|optional}}
== Returns ==
When successful - this function returns the user ID of the created user.
In case of failure (username or email already exists) the function returns an [[Class_Reference/WP_Error|error object]], with these possible values and messages;
* ''empty_user_login'', Cannot create a user with an empty login name.
* ''existing_user_login'', This username is already registered.
* ''existing_user_email'', This email address is already registered.
== Source File ==
&lt;tt&gt;wp_create_user()&lt;/tt&gt; is located in {{Trac|wp-includes/user.php}}.
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="get_userdata" d:title="get userdata">
<d:index d:value="get userdata"/>
<h1>get userdata</h1>
<p>{{Languages|
{{en|Function_Reference/get_userdata}}
{{ko|Function_Reference/get_userdata}}
{{tr|Fonksiyon Listesi/get_userdata}}
}}
== Description ==
Returns a [[Class_Reference/WP_User|WP_User]] object with the information pertaining to the user whose ID is passed to it. Properties de-referenced with &quot;-&amp;gt;&quot; map directly to wp_users and wp_usermeta tables in the database (see [[Database Description#Table:_wp_users|Database Description]]).
If the user does not exist, the function returns &lt;code&gt;false&lt;/code&gt;.
An alias of [[Function_Reference/get_user_by|get_user_by('id')]].
== Usage ==
%%% &lt;?php get_userdata( $userid ); ?&gt; %%%
== Parameters ==
{{Parameter|$userid|integer|The ID of the user whose data should be retrieved.}}
== Return Values ==
; &lt;tt&gt;(bool|object)&lt;/tt&gt; : False on failure, &lt;tt&gt;[[Class_Reference/WP_User | WP_User]]&lt;/tt&gt; object on success.
== Examples ==
=== Basic Usage ===
The &lt;tt&gt;get_userdata()&lt;/tt&gt; function returns an object of the user's data. You can echo various parts of the returned object or loop through the data to display it all.
Example displaying certain parts:
&lt;?php $user_info = get_userdata(1);
echo 'Username: ' . $user_info-&gt;user_login . &quot;\n&quot;;
echo 'User roles: ' . implode(', ', $user_info-&gt;roles) . &quot;\n&quot;;
echo 'User ID: ' . $user_info-&gt;ID . &quot;\n&quot;;
?&gt;
Results in: &lt;div style=&quot;border:1px solid lightblue; display_inline-block; margin: 1em; padding: 1em;&quot;&gt;Username: admin&lt;br /&gt;User roles: administrator&lt;br /&gt;User ID: 1&lt;/div&gt;
You can also assign certain parts into individual variables for displaying later or in multiple places.
Example for extracting certain parts:
&lt;?php $user_info = get_userdata(1);
$username = $user_info-&gt;user_login;
$first_name = $user_info-&gt;first_name;
$last_name = $user_info-&gt;last_name;
echo &quot;$first_name $last_name logs into her WordPress site with the user name of $username.&quot;;
?&gt;
Results in: &lt;div style=&quot;border:1px solid lightblue; display_inline-block; margin: 1em; padding: 1em;&quot;&gt;Harriet Smith logs into her WordPress site with the user name of mrssmith.&lt;/div&gt;
=== Accessing Usermeta Data ===
&lt;?php $user_info = get_userdata(1);
echo $user_info-&gt;last_name . &quot;, &quot; . $user_info-&gt;first_name . &quot;\n&quot;;
?&gt;
Results in: &lt;div style=&quot;border:1px solid lightblue; display_inline-block; margin: 1em; padding: 1em;&quot;&gt;Doe, John&lt;/div&gt;
== Notes ==
Here are some of the useful values in the &lt;tt&gt;wp_users&lt;/tt&gt; and &lt;tt&gt;wp_usermeta&lt;/tt&gt; tables you can access with this function for use in your theme or plugin:
* '''users'''
** ID
** user_login
** user_pass
** user_nicename
** user_email
** user_url
** user_registered
** display_name
* '''user_meta'''
** user_firstname
** user_lastname
** nickname
** description
** wp_capabilities (array)
** admin_color (Theme of your admin page. Default is fresh.)
** closedpostboxes_page
** primary_blog
** rich_editing
** source_domain
&lt;b&gt;Note:&lt;/b&gt; the WP_User object uses PHP 5 &quot;magic&quot; methods to provide some of its properties. For example:&lt;br/&gt;
&lt;tt&gt;$user_info-&gt;user_login&lt;/tt&gt; is shorthand for &lt;tt&gt;$user_info-&gt;data-&gt;user_login&lt;/tt&gt;, and&lt;br/&gt;
&lt;tt&gt;$user_info-&gt;rich_editing&lt;/tt&gt; is shorthand for &lt;tt&gt;get_user_meta($user_info-&gt;ID, 'rich_editing', true)&lt;/tt&gt;.
== Source File ==
&lt;tt&gt;get_userdata()&lt;/tt&gt; is located in {{Trac|wp-includes/pluggable.php}}.
== See Also ==
* [[Author Templates]]
== Related ==
{{Get User Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="add_filter" d:title="add filter">
<d:index d:value="add filter"/>
<h1>add filter</h1>
<p>{{Languages|
{{en|Function_Reference/add_filter}}
{{it|Function_Reference/it:add_filter}}
{{ja|関数リファレンス/add_filter}}
{{ru|Справочник_по_функциям/add_filter}}
}}
== Description ==
Hook a function to a specific filter action.
* Glossary: [http://codex.wordpress.org/Glossary#Filter Filters]
== Usage ==
%%% &lt;?php add_filter( $tag, $function_to_add, $priority, $accepted_args ); ?&gt; %%%
== Parameters ==
{{Parameter|$tag|string|The name of the existing Filter to Hook the &lt;tt&gt;$function_to_add&lt;/tt&gt; argument to. You can find a [http://codex.wordpress.org/Plugin_API/Filter_Reference list of Filter Hooks here].}}
{{Parameter|$function_to_add|callback|The name of the function to be called when the custom Filter is [[Function Reference/apply_filters|applied]].}}
{{Parameter|$priority|integer|Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the filter.|optional|10}}
{{Parameter|$accepted_args|integer|The number of arguments the function(s) accept(s). In WordPress 1.5.1 and newer hooked functions can take extra arguments that are set when the matching apply_filters() call is run.|optional|1}}
== Return ==
The function returns true if the attempted function hook succeeds or false if not. There is no test that the function exists nor whether the &lt;tt&gt;$function_to_add&lt;/tt&gt; is even a string. It is up to you to take care.
This is done for optimization purposes, so everything is as quick as possible.
== Example ==
The filter &lt;tt&gt;img_caption_shortcode&lt;/tt&gt; is applied in &lt;tt&gt;media.php&lt;/tt&gt; using the following call:
&lt;pre&gt;
// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
return $output;
&lt;/pre&gt;
The target filter function will be called with three arguments:
* &amp;#39;&amp;#39; &amp;lt;= This is normally the value the filter will be modifying
* $attr
* $content
In order for the filter function to actually receive the full argument list, the call to &lt;tt&gt;add_filter()&lt;/tt&gt; must
be modified to specify there are 3 arguments on the parameter list.
&lt;pre&gt;
add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3);
/**
* Filter to replace the [caption] shortcode text with HTML5 compliant code
*
* @return text HTML content describing embedded figure
**/
function my_img_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(array(
'id' =&gt; '',
'align' =&gt; '',
'width' =&gt; '',
'caption' =&gt; ''
), $attr));
if ( 1 &gt; (int) $width || empty($caption) )
return $val;
$capid = '';
if ( $id ) {
$id = esc_attr($id);
$capid = 'id=&quot;figcaption_'. $id . '&quot; ';
$id = 'id=&quot;' . $id . '&quot; aria-labelledby=&quot;figcaption_' . $id . '&quot; ';
}
return '&lt;figure ' . $id . 'class=&quot;wp-caption ' . esc_attr($align) . '&quot; style=&quot;width: '
. (10 + (int) $width) . 'px&quot;&gt;' . do_shortcode( $content ) . '&lt;figcaption ' . $capid
. 'class=&quot;wp-caption-text&quot;&gt;' . $caption . '&lt;/figcaption&gt;&lt;/figure&gt;';
}
&lt;/pre&gt;
== Notes ==
* Hooked functions can take extra arguments that are set when the matching &lt;tt&gt;[[Function_Reference/do_action | do_action()]]&lt;/tt&gt; or &lt;tt&gt;[[Function_Reference/apply_filters | apply_filters()]]&lt;/tt&gt; call is run. For example, the action &lt;tt&gt;[[Plugin_API/Action_Reference/comment_id_not_found | 'comment_id_not_found']]&lt;/tt&gt; will pass the comment ID to each callback.
* Although you can pass the number of &lt;tt&gt;$accepted_args&lt;/tt&gt;, you can only manipulate the &lt;tt&gt;[http://codex.wordpress.org/Function_Reference/apply_filters#Parameters $value]&lt;/tt&gt;. The other arguments are only to provide context, and their values cannot be changed by the filter function.
* You can also pass a class method as a callback.
:Static class method:
:&lt;pre&gt;add_filter( 'media_upload_newtab', array( 'My_Class', 'media_upload_callback' ) );&lt;/pre&gt;
:Instance method:
:&lt;pre&gt;add_filter( 'media_upload_newtab', array( $this, 'media_upload_callback' ) );&lt;/pre&gt;
* You can also pass an an anonymous function as a callback. For example:
:&lt;pre&gt;add_filter( 'the_title', function( $title ) { return '&lt;b&gt;' . $title . '&lt;/b&gt;'; } );&lt;/pre&gt;
:[http://www.php.net/manual/functions.anonymous.php Anonymous functions] were introduced in PHP 5.3.0. Check [[Hosting WordPress]] requirements and double check your PHP version before using them.
:If your version of PHP is older than 5.3.0, you can use &lt;tt&gt;[http://www.php.net/manual/function.create-function.php create_function()]&lt;/tt&gt; instead. But keep in mind that lambda functions created by &lt;tt&gt;create_function()&lt;/tt&gt; are not [http://framework.zend.com/issues/browse/ZF-7646 cached by APC or any other optimizer]. So don't use &lt;tt&gt;create_function()&lt;/tt&gt; if callback is supposed to be used more than few times or it has complex logic.
== Change Log ==
* Since: 0.71
== Source File ==
&lt;tt&gt;add_filter()&lt;/tt&gt; is located in {{Trac|wp-includes/plugin.php}}.
== See Also ==
* [http://stackoverflow.com/questions/13797313/wordpress-how-to-return-value-when-use-add-filter/13797597#13797597 A good explanation on Filter hooks on stackoverflow.com] (2012-12-10)
== Related ==
{{Filter Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="get_currentuserinfo" d:title="get currentuserinfo">
<d:index d:value="get currentuserinfo"/>
<h1>get currentuserinfo</h1>
<p>== Description ==
Retrieves the information pertaining to the currently logged in user, and places it in the global variable &lt;tt&gt;$current_user&lt;/tt&gt;. Properties map directly to the wp_users table in the database (see [[Database Description#Table:_wp_users|Database Description]]).
Also places the individual attributes into the following separate global variables:
:* &lt;tt&gt;$user_login&lt;/tt&gt;
:* &lt;tt&gt;$user_ID&lt;/tt&gt; (Equal $current_user-&gt;ID, not $current_user-&gt;user_ID)
:* &lt;tt&gt;$user_email&lt;/tt&gt;
:* &lt;tt&gt;$user_url&lt;/tt&gt; (User's website, as entered in the user's Profile)
:* &lt;tt&gt;$user_pass&lt;/tt&gt; (The phpass hash of the user password - useful for comparing input at a password prompt with the actual user password.)
:* &lt;tt&gt;$display_name&lt;/tt&gt; (User's name, displayed according to the 'How to display name' User option)
:* &lt;tt&gt;$user_identity&lt;/tt&gt; (User's name, displayed according to the 'How to display name' User option (since 3.0))
== Usage ==
%%% &lt;?php get_currentuserinfo(); ?&gt; %%%
== Examples ==
=== Default Usage ===
The call to &lt;tt&gt;get_currentuserinfo()&lt;/tt&gt; places the current user's info into &lt;tt&gt;$current_user&lt;/tt&gt;, where it can be retrieved using member variables.
&lt;?php global $current_user;
get_currentuserinfo();
echo 'Username: ' . $current_user-&gt;user_login . &quot;\n&quot;;
echo 'User email: ' . $current_user-&gt;user_email . &quot;\n&quot;;
echo 'User first name: ' . $current_user-&gt;user_firstname . &quot;\n&quot;;
echo 'User last name: ' . $current_user-&gt;user_lastname . &quot;\n&quot;;
echo 'User display name: ' . $current_user-&gt;display_name . &quot;\n&quot;;
echo 'User ID: ' . $current_user-&gt;ID . &quot;\n&quot;;
?&gt;
&lt;div style=&quot;border:1px solid blue; width:70%; padding:10px&quot;&gt;Username: Zedd&lt;br /&gt;
User email: my@email.com&lt;br /&gt;
User first name: John&lt;br /&gt;
User last name: Doe&lt;br /&gt;
User display name: John Doe&lt;br /&gt;
User ID: 1&lt;/div&gt;
=== Using Separate Globals ===
Much of the user data is placed in separate global variables, which can be accessed directly.
&lt;?php global $display_name , $user_email;
get_currentuserinfo();
echo $display_name . &quot;'s email address is: &quot; . $user_email;
?&gt;
&lt;div style=&quot;border:1px solid blue; width:50%; padding:10px&quot;&gt;Zedd's email address is: john@example.com&lt;/div&gt;
''' NOTE:''' $display_name does not appear to work in 2.5+? Use $user_identity
&lt;?php global $user_login , $user_email;
get_currentuserinfo();
echo($user_login . &quot;'s email address is: &quot; . $user_email;
?&gt;
== Parameters ==
This function does not accept any parameters.
To determine if there is a user currently logged in, do this:
&lt;?php
if(!is_user_logged_in()) {
//no user logged in
}
?&gt;
Here is another example:
&lt;pre&gt;
&lt;?php if ( is_user_logged_in() ) { ?&gt;
&lt;!-- text that logged in users will see --&gt;
&lt;?php } else { ?&gt;
&lt;!-- here is a paragraph that is shown to anyone not logged in --&gt;
&lt;p&gt;By &lt;a href=&quot;&lt;?php home_url(); ?&gt;/wp-register.php&quot;&gt;registering&lt;/a&gt;, you can save your favorite posts for future reference.&lt;/p&gt;
&lt;?php } ?&gt;
&lt;/pre&gt;
Here is yet another example using logical conditionals to restrict access to pages:
&lt;pre&gt;
&lt;?php if ($current_user-&gt;user_login == 'the_username') { ?&gt;
&lt;!-- Welcome the user or show the page content --&gt;
&lt;h1&gt;Welcome &lt;?php echo $current_user-&gt;user_firstname ?&gt;&lt;/h1&gt;
&lt;?php } else { ?&gt;
&lt;!-- Let the visitor know access is denied --&gt;
&lt;h1&gt;Go away!&lt;/h1&gt;
&lt;?php } ?&gt;
&lt;/pre&gt;
== Source File ==
&lt;tt&gt;get_currentuserinfo()&lt;/tt&gt; is located in {{Trac|wp-includes/pluggable.php}}.
== Related ==
{{Get User Tags}}
{{Current User Tags}}
{{Tag Footer}}
{{Copyedit}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="get_all_category_ids" d:title="get all category ids">
<d:index d:value="get all category ids"/>
<h1>get all category ids</h1>
<p>{{Languages|
{{en|Function Reference/get_all_category_ids}}
{{it|Riferimento_funzioni/get_all_category_ids}}
}}
== Description ==
Retrieves all category IDs.
== Usage ==
%%%&lt;?php get_all_category_ids() ?&gt;%%%
== Parameters ==
None.
== Return Values ==
; (array) : A list of all of the category IDs.
== Examples ==
To print a list of categories by id: name
&lt;pre&gt;&lt;?php
$category_ids = get_all_category_ids();
foreach($category_ids as $cat_id) {
$cat_name = get_cat_name($cat_id);
echo $cat_id . ': ' . $cat_name;
}
?&gt;&lt;/pre&gt;
== Notes ==
== Change Log ==
Since: 2.0.0
== Source File ==
&lt;!-- Need links to current source code files --&gt;
&lt;tt&gt;get_all_category_ids()&lt;/tt&gt; is located in {{Trac|wp-includes/category.php}}.
== Related ==
&lt;!--
To Do:
Need to find related functions.
Need to create groups of functions and create templates to add them to a page quickly.
Some functions may be related to many groups of functions.
--&gt;
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="Category:Template_Tags" d:title="Category:Template Tags">
<d:index d:value="Category:Template Tags"/>
<h1>Category:Template Tags</h1>
<p>Articles in the Template Tags Category document the proper use and syntax of the Template Tags used in WordPress
[[Category:Advanced Topics]]
[[Category:Design and Layout]]
[[Category:WordPress Development]]
[[Category:Functions]]</p>
</d:entry>
<d:entry id="fetch_rss" d:title="fetch rss">
<d:index d:value="fetch rss"/>
<h1>fetch rss</h1>
<p>{{Deprecated}}
==Description==
Retrieves an RSS feed and parses it. Uses the [http://magpierss.sourceforge.net/ MagpieRSS and RSSCache] functions for parsing and automatic caching and the [http://sourceforge.net/projects/snoopy/ Snoopy HTTP client] for the actual retrieval.
Deprecated note: Switch to using [[Function_Reference/fetch_feed|fetch_feed]] instead.
==Usage==
%%% &lt;?php
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss($uri);
?&gt; %%%
==Parameters==
{{Parameter|$uri|URI|The URI of the RSS feed you want to retrieve. The resulting parsed feed is returned, with the more interesting and useful bits in the items array.}}rray.
==Example==
To get and display a list of links for an existing RSS feed, limiting the selection to the most recent 5 items:
%%%
&lt;h2&gt;&lt;?php _e('Headlines from AP News'); ?&gt;&lt;/h2&gt;
&lt;?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://example.com/rss/feed/goes/here');
$maxitems = 5;
$items = array_slice($rss-&gt;items, 0, $maxitems);
?&gt;
&lt;ul&gt;
&lt;?php if (empty($items)): ?&gt;
&lt;li&gt;No items&lt;/li&gt;
&lt;?php else:
foreach ( $items as $item ):
?&gt;
&lt;li&gt;
&lt;a href='&lt;?php echo $item['link']; ?&gt;' title='&lt;?php echo $item['title']; ?&gt;'&gt;
&lt;?php echo $item['title']; ?&gt;
&lt;/a&gt;
&lt;/li&gt;
&lt;?php
endforeach;
endif;
?&gt;
&lt;/ul&gt;
%%%
== Change Log ==
* Since [[Version 1.5]]
* Deprecated in [[Version 3.0]]
== Source File ==
&lt;code&gt;fetch_rss&lt;/code&gt; is defined in {{Trac|wp-includes/rss.php}}.
== Related ==
* [[Function_Reference/fetch_feed|fetch_feed]]
* [[Function_Reference/wp_rss|wp_rss()]]
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="add_action" d:title="add action">
<d:index d:value="add action"/>
<h1>add action</h1>
<p>{{Languages|
{{en|Function_Reference/add_action}}
{{ja|関数リファレンス/add_action}}
{{zh-hans|函数参考/add_action}}
{{ko|한국어/add_action}}
}}
== Description ==
Hooks a function on to a specific [http://codex.wordpress.org/Glossary#Action action].
More specifically, this function will run the function &lt;tt&gt;$function_to_add&lt;/tt&gt; when the event &lt;tt&gt;$hook&lt;/tt&gt; occurs.
This function is an alias to [[Function_Reference/add_filter|add_filter()]].
See [[Plugin_API/Action_Reference|Plugin API/Action Reference]] for a list of action hooks. Actions are (usually) triggered when the WordPress core calls [[Function_Reference/do_action|do_action()]].
== Usage ==
%%%&lt;?php add_action( $hook, $function_to_add, $priority, $accepted_args ); ?&gt;%%%
==Parameters==
{{Parameter|$hook|string|The name of the action to which $function_to_add is hooked. (See [[Plugin_API/Action_Reference|Plugin API/Action Reference]] for a list of action hooks). Can also be the name of an action inside a theme or plugin file, or the special tag &quot;all&quot;, in which case the function will be called for all hooks)}}
{{Parameter|$function_to_add|callback|The name of the function you wish to be hooked.}}
{{Parameter|$priority|int|Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.|optional|10}}
{{Parameter|$accepted_args|int|The number of arguments the hooked function accepts. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching [[Function_Reference/do_action|do_action()]] or [[Function_Reference/apply_filters|apply_filters()]] call is run. For example, the action &lt;tt&gt;comment_id_not_found&lt;/tt&gt; will pass any functions that hook onto it the ID of the requested comment.|optional|1}}
== Return Values ==
; &lt;tt&gt;(boolean)&lt;/tt&gt; : Always True.
== Examples ==
=== Simple Hook ===
To email some friends whenever an entry is posted on your blog:
&lt;pre&gt;
function email_friends( $post_ID ) {
$friends = 'bob@example.org, susie@example.org';
wp_mail( $friends, &quot;sally's blog updated&quot;, 'I just put something on my blog: http://blog.example.com' );
return $post_ID;
}
add_action( 'publish_post', 'email_friends' );
&lt;/pre&gt;
=== Accepted Arguments ===
A hooked function can optionally accept arguments from the action call, if any are set to be passed. In this simplistic example, the &lt;tt&gt;echo_comment_id&lt;/tt&gt; function takes the &lt;tt&gt;$comment_id&lt;/tt&gt; argument, which is automatically passed to when the [[Function_Reference/do_action|do_action()]] call using the &lt;tt&gt;comment_id_not_found&lt;/tt&gt; filter hook is run.
&lt;pre&gt;
function echo_comment_id( $comment_id ) {
echo 'Comment ID ' . $comment_id . ' could not be found';
}
add_action( 'comment_id_not_found', 'echo_comment_id', 10, 1 );
&lt;/pre&gt;
=== Using with a Class ===
To use &lt;tt&gt;add_action()&lt;/tt&gt; when your plugin or theme is built using classes, you need to use [http://www.php.net/manual/en/language.types.callable.php#language.types.callable.passing the array callable syntax]. You would pass the function to &lt;tt&gt;add_action()&lt;/tt&gt; as an array, with $this as the first element, then the name of the class method, like so:
&lt;pre&gt;
class MyPluginClass {
public function __construct() {
add_action( 'save_post', array( $this, 'myplugin_save_posts' ) );
}
public function myplugin_save_posts() {
// do stuff here...
}
}
&lt;/pre&gt;
== Notes ==
To find out the number and name of arguments for an action, simply search the code base for the matching do_action() call. For example, if you are hooking into 'save_post', you would find it in post.php:
%%% &lt;?php do_action( 'save_post', $post_ID, $post, $update ); ?&gt; %%%
Your add_action call would look like:
%%% &lt;?php add_action( 'save_post', 'my_save_post', 10, 3 ); ?&gt; %%%
And your function would be:
&lt;pre&gt;
function my_save_post( $post_ID, $post, $update ) {
// do stuff here
}
&lt;/pre&gt;
== Change Log ==
Since [[Version 1.2|1.2.0]]
== Source File ==
&lt;tt&gt;add_action()&lt;/tt&gt; is located in {{Trac|wp-includes/plugin.php}}.
== Related ==
{{Action Tags}}
{{Tag Footer}}
[[Category:Functions]]
{{Copyedit}}</p>
</d:entry>
<d:entry id="wp_rss" d:title="wp rss">
<d:index d:value="wp rss"/>
<h1>wp rss</h1>
<p>{{Deprecated}}
==Description==
Retrieves an RSS feed and parses it, then displays it as an unordered list of links. Uses the [http://magpierss.sourceforge.net/ MagpieRSS and RSSCache] functions for parsing and automatic caching and the [http://sourceforge.net/projects/snoopy/ Snoopy HTTP client] for the actual retrieval.
Deprecated note: Switch to using [[Function_Reference/fetch_feed|fetch_feed]] instead.
==Usage==
%%%&lt;?php
include_once(ABSPATH . WPINC . '/rss.php');
wp_rss($uri, $num);
?&gt;%%%
==Parameters==
{{Parameter|$uri|URI|The URI of the RSS feed you want to retrieve. The resulting parsed feed is returned, with the more interesting and useful bits in the items array.}}
{{Parameter|$num|integer|The number of items to display.}}
==Output==
The output will look like the following:
%%%&lt;ul&gt;
&lt;li&gt;
&lt;a href='LINK FROM FEED' title='DESCRIPTION FROM FEED'&gt;TITLE FROM FEED&lt;/a&gt;
&lt;/li&gt;
(repeat for number of links specified)
&lt;/ul&gt;%%%
==Example==
To get and display a list of 5 links from an existing RSS feed:
%%%&lt;?php
include_once(ABSPATH . WPINC . '/rss.php');
wp_rss('http://example.com/rss/feed/goes/here', 5);
?&gt;%%%
== Related ==
[[Function_Reference/fetch_rss|fetch_rss]], [[Function_Reference/get_rss|get_rss]]
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="wptexturize" d:title="wptexturize">
<d:index d:value="wptexturize"/>
<h1>wptexturize</h1>
<p>{{Languages|
{{en|Function Reference/wptexturize}}
{{it|Riferimento funzioni/wptexturize}}
}}
{{Stub}}
== Description ==
This returns given text with transformations of quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol. Text enclosed in the tags &lt;tt&gt;&lt;nowiki&gt;&lt;pre&gt;&lt;/nowiki&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;nowiki&gt;&lt;code&gt;&lt;/nowiki&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;nowiki&gt;&lt;kbd&gt;&lt;/nowiki&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;nowiki&gt;&lt;style&gt;&lt;/nowiki&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;nowiki&gt;&lt;script&gt;&lt;/nowiki&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;nowiki&gt; and &lt;tt&gt;&lt;/nowiki&gt;&lt;/tt&gt; will be skipped.
== Usage ==
%%% &lt;?php wptexturize( $text ); ?&gt; %%%
== Parameters ==
{{Parameter|$text|string|The text to be formatted.}}
== Return Values ==
; (string) : The string replaced with html numeric character references.
== Notes ==
Opening and closing quotes can be customized in a WordPress translation file. Here are some of the text transformations:
{|
! source text !! transformed text !! symbol name
|-
| &quot;---&quot; || &quot;&amp;#8212;&quot; || em-dash
|-
| &quot; -- &quot; || &quot;&amp;#8212;&quot; || em-dash
|-
| &quot;--&quot; || &quot;&amp;#8211;&quot; || en-dash
|-
| &quot; - &quot; || &quot;&amp;#8211;&quot; || en-dash
|-
| &quot;xn&amp;#8211;&quot; || &quot;xn--&quot; ||
|-
| &quot;...&quot; || &quot;&amp;#8230;&quot; || ellipsis
|-
| `` || &amp;#8220; || opening quote
|-
| &lt;nowiki&gt;''&lt;/nowiki&gt; || &amp;#8221; || closing quote
|-
| &quot; (tm)&quot; || &quot; &amp;#8482;&quot; || trademark symbol
|-
| 1234&quot; || 1234&amp;#8243; || double prime symbol
|-
| 1234' || 1234&amp;#8242; || prime symbol
|-
| 1234x1234 || 1234&amp;#215;1234 || multiplication symbol
|-
|}
There is a small &quot;cockney&quot; list of transformations, as well. They can be replaced if the variable &lt;tt&gt;$wp_cockneyreplace&lt;/tt&gt; is defined and contains an associative array with the keys containing the source strings and the values containing the transformed strings. By default the following strings will be transformed:
* 'tain't
* 'twere
* 'twas
* 'tis
* 'twill
* 'til
* 'bout
* 'nuff
* 'round
* 'cause
== Change Log ==
Since: 0.71
== Source File ==
&lt;tt&gt;wptexturize()&lt;/tt&gt; is located in {{Trac|wp-includes/formatting.php}}.
== Related ==
* Function: [[Function_Reference/wpautop|wpautop()]]
* Filter: [[Plugin API/Filter Reference/no_texturize_shortcodes|no_texturize_shortcodes]]
{{Tag Footer}}
[[Category:Functions]]
[[Category:New page created]]</p>
</d:entry>
<d:entry id="wpautop" d:title="wpautop">
<d:index d:value="wpautop"/>
<h1>wpautop</h1>
<p>{{Languages|
{{en|Function Reference/wpautop}}
{{it|Riferimento funzioni/wpautop}}
}}
== Description ==
Changes double line-breaks in the text into HTML paragraphs (&lt;tt&gt;&lt;nowiki&gt;&lt;p&gt;...&lt;/p&gt;&lt;/nowiki&gt;&lt;/tt&gt;).
WordPress uses it to filter [[Template_Tags/the_content|the content]] and [[Template_Tags/the_excerpt|the excerpt]].
== Usage ==
%%% &lt;?php wpautop( $foo, $br ); ?&gt; %%%
== Parameters ==
{{Parameter|$foo|string|The text to be formatted.}}
{{Parameter|$br|boolean| Preserve line breaks. When set to true, any line breaks remaining after paragraph conversion are converted to HTML &lt;tt&gt;&lt;nowiki&gt;&lt;br /&gt;&lt;/nowiki&gt;&lt;/tt&gt;. Line breaks within &lt;tt&gt;script&lt;/tt&gt; and &lt;tt&gt;style&lt;/tt&gt; sections are not affected.|optional|true}}
== Return Values ==
; (string) : Text which has been converted into correct paragraph tags.
== Examples ==
=== Basic usage ===
&lt;?php
$some_long_text = // Start Text
Some long text
that has many lines
and paragraphs in it.
// end text
echo wpautop( $some_long_text );
?&gt;
This should echo the string with &lt;nowiki&gt;&lt;p&gt;&lt;/nowiki&gt; tags around the paragraphs, like this:
&lt;nowiki&gt;&lt;p&gt;Some long text&lt;br/&gt;
that has many lines&lt;/p&gt;
&lt;p&gt;and paragraphs in it.&lt;/p&gt;&lt;/nowiki&gt;
== Notes ==
=== Disabling the filter ===
Some people choose to disable the wpautop filter from within their theme's &lt;tt&gt;functions.php&lt;/tt&gt;:
&lt;pre&gt;
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
&lt;/pre&gt;
There's also a [http://wordpress.org/extend/plugins/wpautop-control/ plugin] available to enable/disable the filter on a post-by-post basis.
== Changelog ==
Since: 0.71
== Source File ==
&lt;tt&gt;wpautop()&lt;/tt&gt; is located in {{Trac|wp-includes/formatting.php}}.
== Resources ==
http://ma.tt/scripts/autop/
== Related ==
{{Tag Footer}}
[[Category:Functions]]
[[Category:New page created]]</p>
</d:entry>
<d:entry id="wp_reschedule_event" d:title="wp reschedule event">
<d:index d:value="wp reschedule event"/>
<h1>wp reschedule event</h1>
<p>== Description ==
This function is used internally by WordPress to reschedule a recurring event. You'll likely never need to use this function manually, it is documented here for completeness.
== Usage ==
%%% &lt;?php wp_reschedule_event( $timestamp, $recurrence, $hook, $args); ?&gt;%%%
== Parameters ==
{{Parameter|$timestamp|integer|The time the scheduled event will occur (unix timestamp)|required}}
{{Parameter|$recurrence|string|How often the event recurs, either 'hourly' or 'daily'|required}}
{{Parameter|$hook|string|Name of action hook to fire (string)|required}}
{{Parameter|$args|array|Arguments to pass into the hook function(s)|optional|array()}}
== Return Value ==
{{Return||boolean&amp;#124;null|False on failure. Null when event is rescheduled.}}
== Examples ==
== Notes ==
== Change Log ==
Since: [[Version 2.1|2.1.0]]
== Source File ==
&lt;tt&gt;wp_reschedule_event()&lt;/tt&gt; is located in {{Trac|wp-includes/cron.php}}
== Related ==
For a comprehensive list of functions, take a look at the [http://codex.wordpress.org/Category:Functions category Functions]
* [[Function_Reference]]
{{Tag Footer}}
[[Category:Functions]]
[[Category:New page created]]
[[Category:WP-Cron Functions]]</p>
</d:entry>
<d:entry id="wp_insert_post" d:title="wp insert post">
<d:index d:value="wp insert post"/>
<h1>wp insert post</h1>
<p>{{Languages|
{{en|Function_Reference/wp_insert_post}}
{{ru|Справочник по функциям/wp insert post}}
{{ja|関数リファレンス/wp insert post}}
{{tr|Fonksiyon Listesi/wp insert post}}
{{zh-cn|函数参考/wp_insert_post}}
}}
==Description==
This function inserts posts (and pages) in the database. It sanitizes variables, does some checks, fills in missing variables like date/time, etc. It takes an array as its argument and returns the post ID of the created post (or &lt;tt&gt;0&lt;/tt&gt; if there is an error).
== Usage ==
%%% &lt;?php wp_insert_post( $post, $wp_error ); ?&gt; %%%
==Parameters==
{{Parameter|$post|array|An array representing the elements that make up a post. There is a one-to-one relationship between these elements and the names of columns in the wp_posts table in the database.}}
'''IMPORTANT''': Setting a value for $post['ID'] WILL NOT create a post with that ID number. Setting this value will cause the function to update the post with that ID number with the other values specified in $post. In short, to insert a new post, $post['ID'] must be blank or not set at all.
The contents of the post array can depend on how much (or little) you want to trust the defaults. Here is a list with a short description of all the keys you can set for a post:
&lt;pre&gt;
$post = array(
'ID' =&gt; [ &lt;post id&gt; ] // Are you updating an existing post?
'post_content' =&gt; [ &lt;string&gt; ] // The full text of the post.
'post_name' =&gt; [ &lt;string&gt; ] // The name (slug) for your post
'post_title' =&gt; [ &lt;string&gt; ] // The title of your post.
'post_status' =&gt; [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ] // Default 'draft'.
'post_type' =&gt; [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ] // Default 'post'.
'post_author' =&gt; [ &lt;user ID&gt; ] // The user ID number of the author. Default is the current user ID.
'ping_status' =&gt; [ 'closed' | 'open' ] // Pingbacks or trackbacks allowed. Default is the option 'default_ping_status'.
'post_parent' =&gt; [ &lt;post ID&gt; ] // Sets the parent of the new post, if any. Default 0.
'menu_order' =&gt; [ &lt;order&gt; ] // If new post is a page, sets the order in which it should appear in supported menus. Default 0.
'to_ping' =&gt; // Space or carriage return-separated list of URLs to ping. Default empty string.
'pinged' =&gt; // Space or carriage return-separated list of URLs that have been pinged. Default empty string.
'post_password' =&gt; [ &lt;string&gt; ] // Password for post, if any. Default empty string.
'guid' =&gt; // Skip this and let Wordpress handle it, usually.
'post_content_filtered' =&gt; // Skip this and let Wordpress handle it, usually.
'post_excerpt' =&gt; [ &lt;string&gt; ] // For all your post excerpt needs.
'post_date' =&gt; [ Y-m-d H:i:s ] // The time post was made.
'post_date_gmt' =&gt; [ Y-m-d H:i:s ] // The time post was made, in GMT.
'comment_status' =&gt; [ 'closed' | 'open' ] // Default is the option 'default_comment_status', or 'closed'.
'post_category' =&gt; [ array(&lt;category id&gt;, ...) ] // Default empty.
'tags_input' =&gt; [ '&lt;tag&gt;, &lt;tag&gt;, ...' | array ] // Default empty.
'tax_input' =&gt; [ array( &lt;taxonomy&gt; =&gt; &lt;array | string&gt; ) ] // For custom taxonomies. Default empty.
'page_template' =&gt; [ &lt;string&gt; ] // Requires name of template file, eg template.php. Default empty.
);
&lt;/pre&gt;
'''Notes'''
* 'post_status': If providing a post_status of 'future' you must specify the post_date in order for WordPress to know when to publish your post. See also [[Post Status Transitions]].
* 'post_category': Equivalent to calling [[Function Reference/wp_set_post_categories|wp_set_post_categories()]].
* 'tags_input': Equivalent to calling [[Function Reference/wp_set_post_tags|wp_set_post_tags()]].
* 'tax_input': Equivalent to calling [[Function Reference/wp_set_post_terms|wp_set_post_terms()]] for each custom taxonomy in the array. If the current user doesn't have the capability to work a taxonomy, the you must use wp_set_object_terms() instead.
* 'page_template': If post_type is 'page', will attempt to set the [[Page_Templates|page template]]. On failure, the function will return either a WP_Error or 0, and stop before the final actions are called. If the post_type is not 'page', the parameter is ignored. You can set the page template for a non-page by calling [[Function Reference/update_post_meta|update_post_meta()]] with a key of '_wp_page_template'.
{{Parameter|$wp_error|bool|Allow return of [[Class Reference/WP_Error|WP_Error]] object on failure|optional|false}}
==Return==
The ID of the post if the post is successfully added to the database. On failure, it returns &lt;tt&gt;0&lt;/tt&gt; if $wp_error is set to false, or a [[Class Reference/WP_Error|WP_Error]] object if $wp_error is set to true.
==Usage==
%%% &lt;?php wp_insert_post( $post, $wp_error ); ?&gt; %%%
==Example==
Before calling wp_insert_post() it is necessary to create an array to pass the necessary elements that make up a post. The wp_insert_post() will fill out a default list of these but the user is required to provide the title and content otherwise the database write will fail.
The next example shows the post title, content, status, author, and post categories being set. You can add further key-value pairs, making sure the keys match the names of the columns in the wp_posts table in the database.
&lt;pre&gt;
// Create post object
$my_post = array(
'post_title' =&gt; 'My post',
'post_content' =&gt; 'This is my post.',
'post_status' =&gt; 'publish',
'post_author' =&gt; 1,
'post_category' =&gt; array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
&lt;/pre&gt;
Insert a new post and return the new post id.
&lt;pre&gt;
$post_id = wp_insert_post( $post, $wp_error );
//now you can use $post_id withing add_post_meta or update_post_meta
&lt;/pre&gt;
The default list referred to above is defined in the function body. It is as follows:
&lt;pre&gt;
$defaults = array(
'post_status' =&gt; 'draft',
'post_type' =&gt; 'post',
'post_author' =&gt; $user_ID,
'ping_status' =&gt; get_option('default_ping_status'),
'post_parent' =&gt; 0,
'menu_order' =&gt; 0,
'to_ping' =&gt; '',
'pinged' =&gt; '',
'post_password' =&gt; '',
'guid' =&gt; '',
'post_content_filtered' =&gt; '',
'post_excerpt' =&gt; '',
'import_id' =&gt; 0
);
&lt;/pre&gt;
===Categories===
Categories need to be passed as an array of integers that match the category IDs in the database. This is the case even where only one category is assigned to the post.
See also: [[Function_Reference/wp_set_post_terms|wp_set_post_terms()]]
==Security==
&lt;tt&gt;wp_insert_post()&lt;/tt&gt; passes data through sanitize_post(), which itself handles all necessary sanitization and validation (kses, etc.).
As such, you don't need to worry about that.
You may wish, however, to remove HTML, JavaScript, and PHP tags from the post_title and any other fields. Surprisingly, WordPress does not do this automatically. This can be easily done by using the wp_strip_all_tags() function (as of 2.9) and is especially useful when building front-end post submission forms.
&lt;pre&gt;
// Create post object
$my_post = array(
'post_title' =&gt; wp_strip_all_tags( $_POST['post_title'] ),
'post_content' =&gt; $_POST['post_content'],
'post_status' =&gt; 'publish',
'post_author' =&gt; 1,
'post_category' =&gt; array( 8,39 )
);
// Insert the post into the database
wp_insert_post( $my_post );
&lt;/pre&gt;
==Change Log==
* Since: [[Version 1.0|1.0]]
== Source File ==
&lt;!-- Need links to current source code files --&gt;
&lt;tt&gt;wp_insert_post()&lt;/tt&gt; is located in {{Trac|wp-includes/post.php}}.
==Related==
[[Function Reference/wp update post|wp_update_post()]],
[[Function Reference/wp delete post|wp_delete_post()]],
[[Function Reference/wp publish post|wp_publish_post()]],
[[Function Reference/wp delete attachment|wp_delete_attachment()]],
[[Function Reference/wp get attachment url|wp_get_attachment_url()]],
[[Function Reference/wp insert attachment|wp_insert_attachment()]],
[[Plugin API/Filter Reference/wp insert post data|wp_insert_post_data()]]
{{Tag Footer}}
{{Copyedit}}
[[Category:Functions]]
[[Category:New page created]]</p>
</d:entry>
<d:entry id="wp_clear_scheduled_hook" d:title="wp clear scheduled hook">
<d:index d:value="wp clear scheduled hook"/>
<h1>wp clear scheduled hook</h1>
<p>== Description ==
Un-schedules all previously-scheduled cron jobs using a particular hook name or a specific combination of hook name and arguments.
== Usage ==
%%% &lt;?php wp_clear_scheduled_hook( $hook, $args ); ?&gt; %%%
== Parameters ==
{{Parameter|$hook|string|The name of an action hook to execute.}}
{{Parameter|$args|array|Arguments to pass to the hook function(s)|optional}}
== Return Value ==
No value is returned by this function.
== Examples ==
=== Clear a scheduled event ===
&lt;pre&gt;
// If you previously added for example
// wp_schedule_single_event( time() + 3600, 'my_new_event' );
wp_clear_scheduled_hook( 'my_new_event' );
// or this if you created something like
// wp_schedule_single_event( time() + 3600, 'my_new_event', array( 'some_arg' ) );
wp_clear_scheduled_hook( 'my_new_event', array( 'some_arg' ) );
&lt;/pre&gt;
== Notes ==
If you created a scheduled job using a hook and arguments you cannot delete it by supplying only the hook. Similarly if you created a set of scheduled jobs that share a hook but have different arguments you cannot delete them using only the hook name, you have to delete them all individually using the hook name and arguments.
== Change Log ==
Since: [[Version 2.1|2.1.0]]
== Source File ==
&lt;tt&gt;wp_clear_scheduled_hook()&lt;/tt&gt; is located in {{Trac|wp-includes/cron.php}}
== Related ==
{{Cron Tags}}
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="wp_unschedule_event" d:title="wp unschedule event">
<d:index d:value="wp unschedule event"/>
<h1>wp unschedule event</h1>
<p>== Description ==
Unschedules a previously-scheduled cron job.
Note that you need to know the exact time of the next occurrence when scheduled hook was set to run, and the function arguments it was supposed to have, in order to unschedule it. All future occurrences are unscheduled by calling this function.
== Usage ==
%%% &lt;?php wp_unschedule_event( $timestamp, $hook, $args ); ?&gt; %%%
== Parameters ==
{{Parameter|$timestamp|integer|Timestamp originally provided for when to run the event.|required}}
{{Parameter|$hook|string|Action hook originally provided, the execution of which will be unscheduled.|required}}
{{Parameter|$args|array|Arguments to pass to the hook's callback function. These arguments are used to uniquely identify the scheduled event, so they must be the same as those used when originally scheduling the event.|optional|&lt;tt&gt;array()&lt;/tt&gt;}}
== Return Value ==
This function does not return a value.
== Example ==
&lt;pre&gt;
&lt;?php
// Get the timestamp for the next event.
$timestamp = wp_next_scheduled( 'my_schedule_hook' );
// If this event was created with any special arguments, you need to get those too.
$original_args = array();
wp_unschedule_event( $timestamp, 'my_schedule_hook', $original_args );
?&gt;
&lt;/pre&gt;
== Notes ==
== Change Log ==
Since: [[Version 2.1|2.1.0]]
== Source File ==
&lt;tt&gt;wp_unschedule_event()&lt;/tt&gt; is located in {{Trac|wp-includes/cron.php}}
== Related ==
* [[Function_Reference/wp_schedule_event|wp_schedule_event]]
* [[Function_Reference/wp_reschedule_event | wp_reschedule_event]]
* [[Function_Reference/wp_schedule_single_event|wp_schedule_single_event]]
* [[Function_Reference/wp_clear_scheduled_hook|wp_clear_scheduled_hook]]
* [[Function_Reference/wp_next_scheduled|wp_next_scheduled]]
{{Tag Footer}}
[[Category:Functions]]
[[Category:WP-Cron Functions]]</p>
</d:entry>
<d:entry id="wp_next_scheduled" d:title="wp next scheduled">
<d:index d:value="wp next scheduled"/>
<h1>wp next scheduled</h1>
<p>== Description ==
Returns the next timestamp for a cron event.
== Usage ==
%%%&lt;?php $timestamp = wp_next_scheduled( $hook, $args ); ?&gt;%%%
== Parameters ==
{{Parameter|$hook|string|Name of the action hook for event.}}
{{Parameter|$args|array|Arguments to pass to the hook function(s).|optional}}
== Return Value ==
{{Return||string&amp;#124;boolean|Timestamp, the time the scheduled event will next occur (unix timestamp). False, if the event isn't scheduled.}}
== Notes ==
* Cron is named after a unix program which runs unattended scheduled tasks.
== Change Log ==
Since: 2.1.0
== Source File ==
&lt;tt&gt;wp_next_scheduled()&lt;/tt&gt; is located in {{Trac|wp-includes/cron.php}}
== Related ==
* [[Function_Reference/wp_schedule_event|wp_schedule_event]]
* [[Function_Reference/wp_schedule_single_event|wp_schedule_single_event]]
* [[Function_Reference/wp_clear_scheduled_hook|wp_clear_scheduled_hook]]
* [[Function_Reference/wp_unschedule_event|wp_unschedule_event]]
{{Tag Footer}}
[[Category:Functions]]
[[Category:New page created]]
[[Category:WP-Cron Functions]]</p>
</d:entry>
<d:entry id="wp_schedule_event" d:title="wp schedule event">
<d:index d:value="wp schedule event"/>
<h1>wp schedule event</h1>
<p>== Description ==
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. See the [[Plugin API]] for a list of hooks.
== Usage ==
%%% &lt;?php wp_schedule_event($timestamp, $recurrence, $hook, $args); ?&gt; %%%
== Parameters ==
{{Parameter|$timestamp|integer|The first time that you want the event to occur. This must be in a UNIX timestamp format. WP cron uses UTC/GMT time, not local time. Use &lt;tt&gt;[http://php.net/manual/en/function.time.php time()]&lt;/tt&gt;, which is always GMT in WordPress. (&lt;tt&gt;[[Function_Reference/current_time|current_time( 'timestamp' )]]&lt;/tt&gt; is local time in WordPress.)}}
{{Parameter|$recurrence|string|How often the event should reoccur. Valid values are below. You can create custom intervals using the &lt;tt&gt;cron_schedules&lt;/tt&gt; filter in &lt;tt&gt;[[Function_Reference/wp_get_schedules|wp_get_schedules()]]&lt;/tt&gt;. &lt;ul&gt;&lt;li&gt;&lt;tt&gt;hourly&lt;/tt&gt;&lt;/li&gt;&lt;li&gt;&lt;tt&gt;twicedaily&lt;/tt&gt;&lt;/li&gt;&lt;li&gt;&lt;tt&gt;daily&lt;/tt&gt;&lt;/li&gt;&lt;/ul&gt;}}
{{Parameter|$hook|string|The name of an action hook to execute. For some reason there seems to be a problem on some systems where the hook must not contain underscores or uppercase characters.}}
{{Parameter|$args|array|Arguments to pass to the hook function(s).|optional}}
== Return Value ==
{{Return||boolean&amp;#124;null|False on failure, null when complete with scheduling event.}}
== Examples ==
=== Schedule an hourly event ===
To schedule an hourly event in a plugin, call &lt;tt&gt;wp_schedule_event&lt;/tt&gt; on activation (otherwise you will end up with a lot of scheduled events!):
&lt;pre&gt;
register_activation_hook( __FILE__, 'prefix_activation' );
/**
* On activation, set a time, frequency and name of an action hook to be scheduled.
*/
function prefix_activation() {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event_hook' );
}
add_action( 'prefix_hourly_event_hook', 'prefix_do_this_hourly' );
/**
* On the scheduled action hook, run the function.
*/
function prefix_do_this_hourly() {
// do something every hour
}
&lt;/pre&gt;
Don't forget to clean the scheduler on deactivation:
&lt;pre&gt;
register_deactivation_hook( __FILE__, 'prefix_deactivation' );
/**
* On deactivation, remove all functions from the scheduled action hook.
*/
function prefix_deactivation() {
wp_clear_scheduled_hook( 'prefix_hourly_event_hook' );
}
&lt;/pre&gt;
=== A simple way to schedule an hourly event ===
This example doesn't rely on plugin activation (via the plugins directory) rather it simply adds the event if it is missing.
&lt;pre&gt;
add_action( 'wp', 'prefix_setup_schedule' );
/**
* On an early action hook, check if the hook is scheduled - if not, schedule it.
*/
function prefix_setup_schedule() {
if ( ! wp_next_scheduled( 'prefix_hourly_event' ) ) {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event');
}
}
add_action( 'prefix_hourly_event', 'prefix_do_this_hourly' );
/**
* On the scheduled action hook, run a function.
*/
function prefix_do_this_hourly() {
// do something every hour
}
&lt;/pre&gt;
== Notes ==
The array passed as the &lt;tt&gt;$args&lt;/tt&gt; parameter needs to be an indexed array. Each element in the array is sliced into a separate argument in the &lt;tt&gt;do_action_ref_array()&lt;/tt&gt; call. Despite the name, your array is not passed by reference.
When you add the action that calls your scheduled function, you must specify a priority and the number of elements in the array. Your scheduled function declaration must accept each array element as individual parameters
Example passing multiple arguments
&lt;pre&gt;add_action('wp', 'prefix_setup_schedule');
function prefix_setup_schedule() {
if ( ! wp_next_scheduled('prefix_hourly_event')) {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event',
array( 'example', 'values')
);
}
}
add_action('prefix_hourly_event', 'prefix_do_this_hourly', 10 ,2 );
function prefix_do_this_hourly( $parm1, $parm2 ) {
error_log(&quot;Function prefix_do_this_hourly() received '$parm1' and '$parm2' as parameters.&quot;);
}
// PHP error log will have this line entered every hour:
// Function prefix_do_this_hourly() received 'example' and 'values' as parameters.&lt;/pre&gt;
= Cron Data =
Cron data is saved to the options table. Use &lt;tt&gt;get_option('cron');&lt;/tt&gt; to get the cron array from the database.
== Change Log ==
Since: [[Version 2.1|2.1.0]]
== Source File ==
&lt;tt&gt;wp_schedule_event()&lt;/tt&gt; is located in {{Trac|wp-includes/cron.php}}
== Related ==
* [[Function_Reference/wp_schedule_event|wp_schedule_event]]
* [[Function_Reference/wp_schedule_single_event|wp_schedule_single_event]]
* [[Function_Reference/wp_clear_scheduled_hook|wp_clear_scheduled_hook]]
* [[Function_Reference/wp_next_scheduled|wp_next_scheduled]]
* [[Function_Reference/wp_unschedule_event|wp_unschedule_event]]
* [[Function_Reference/wp_get_schedule|wp_get_schedule]]
== Further Reading ==
For a comprehensive list of functions, take a look at the [http://codex.wordpress.org/Category:Functions category Functions]
Also, see [[Function_Reference]]
{{Tag Footer}}
[[Category:Functions]]
[[Category:New page created]]
[[Category:WP-Cron Functions]]</p>
</d:entry>
<d:entry id="wp_schedule_single_event" d:title="wp schedule single event">
<d:index d:value="wp schedule single event"/>
<h1>wp schedule single event</h1>
<p>== Description ==
Schedules a hook which will be executed once by the WordPress actions core at a time which you specify. The action will fire off when someone visits your WordPress site, if the schedule time has passed.
== Usage ==
%%% &lt;?php wp_schedule_single_event( $timestamp, $hook, $args ); ?&gt; %%%
Note that scheduling an event to occur before 10 minutes after an existing event of the same name will be ignored, unless you pass unique values for &lt;tt&gt;$args&lt;/tt&gt; to each scheduled event. See &lt;tt&gt;[[Function_Reference/wp_next_scheduled | wp_next_scheduled()]]&lt;/tt&gt; for more information.
&lt;i&gt;This behavior is subject to change, as the [https://core.trac.wordpress.org/ticket/6966 original intention] of the code was to prevent scheduling two identical events within ten minutes of each other, not preventing scheduling of identical events until ten minutes after the next scheduled occurrence.&lt;/i&gt;
Attempts to schedule an event after an event of the same name and &lt;tt&gt;$args&lt;/tt&gt; will also be ignored.
== Parameters ==
{{Parameter|$timestamp|integer|The time you want the event to occur. This must be in a UNIX timestamp format.}}
{{Parameter|$hook|string|The name of an action hook to execute.}}
{{Parameter|$args|array|Arguments to pass to the hook function(s)|optional|&lt;tt&gt;array()&lt;/tt&gt;}}
== Return Value ==
{{Return||boolean&amp;#124;null|False if the event was cancelled by a plugin, &lt;tt&gt;null&lt;/tt&gt; otherwise.}}
== Examples ==
=== Schedule an event one hour from now ===
&lt;pre&gt;
function do_this_in_an_hour() {
// do something
}
add_action( 'my_new_event','do_this_in_an_hour' );
// put this line inside a function,
// presumably in response to something the user does
// otherwise it will schedule a new event on every page visit
wp_schedule_single_event( time() + 3600, 'my_new_event' );
// time() + 3600 = one hour from now.
&lt;/pre&gt;
=== Schedule an event one hour from now with arguments ===
&lt;pre&gt;
function do_this_in_an_hour( $arg1, $arg2, $arg3 ) {
// do something
}
add_action( 'my_new_event', 'do_this_in_an_hour', 10, 3 );
// put this line inside a function,
// presumably in response to something the user does
// otherwise it will schedule a new event on every page visit
wp_schedule_single_event( time() + 3600, 'my_new_event', array( $arg1, $arg2, $arg3 ) );
// time() + 3600 = one hour from now.
&lt;/pre&gt;
== Notes ==
== Change Log ==
Since: [[Version 2.1|2.1.0]]
== Source File ==
&lt;tt&gt;wp_schedule_single_event()&lt;/tt&gt; is located in {{Trac|wp-includes/cron.php}}
== Related ==
{{Cron Tags}}
{{Tag Footer}}
[[Category:Functions]]
[[Category:WP-Cron Functions]]</p>
</d:entry>
<d:entry id="get_tag_link" d:title="get tag link">
<d:index d:value="get tag link"/>
<h1>get tag link</h1>
<p>{{Languages|
{{en|Function Reference/get_tag_link}}
{{it|Riferimento funzioni/get_tag_link}}
{{ja|関数リファレンス/get_tag_link}}
}}
== Description ==
Returns the correct link url for a given Tag ID.
== Usage ==
&lt;a href=&quot;&lt;?php echo get_tag_link($tag_id); ?&gt;&quot;&gt;tag name&lt;/a&gt;
== Parameters ==
{{Parameter|$tag_id|integer|The Tag ID.}}
== Return Values ==
{{Return|URL|string|URL with a link to the tag.}}
== Filters ==
Output from this function is [[Plugin_API/Filter_Reference | filtered]] by the 'tag_link' filter. The first argument ($taglink) is the url as the function would normally output it, the second is the ID passed into the function.
[[Function Reference/apply_filters|apply_filters]]('tag_link', $taglink, $tag_id);
== Source File ==
&lt;tt&gt;get_tag_link()&lt;/tt&gt; is located in {{Trac|wp-includes/category-template.php}}.
== Related ==
{{Tag Tags}}
[[Function_Reference/get_the_terms|get_the_terms()]],
[[Function_Reference/get_term_link|get_term_link()]],
[[Function_Reference/wp_get_object_terms|wp_get_object_terms()]]
{{Tag Footer}}
[[Category:Functions]]
{{Copyedit}}</p>
</d:entry>
<d:entry id="get_categories" d:title="get categories">
<d:index d:value="get categories"/>
<h1>get categories</h1>
<p>{{Languages|
{{en|Function Reference/get_categories}}
{{ja|関数リファレンス/get_categories}}
}}
== Description ==
Returns an array of category objects matching the query parameters.
Arguments are pretty much the same as [[Template_Tags/wp_list_categories|wp_list_categories]] and can be passed as either array or in query syntax. &lt;!--The array returned seems to be always flat (no nesting for subcategories) but I'm not sure yet.--&gt;
== Usage ==
%%% &lt;?php $categories = get_categories( $args ); ?&gt; %%%
=== Default Usage ===
&lt;pre&gt;&lt;?php
$args = array(
'type' =&gt; 'post',
'child_of' =&gt; 0,
'parent' =&gt; '',
'orderby' =&gt; 'name',
'order' =&gt; 'ASC',
'hide_empty' =&gt; 1,
'hierarchical' =&gt; 1,
'exclude' =&gt; '',
'include' =&gt; '',
'number' =&gt; '',
'taxonomy' =&gt; 'category',
'pad_counts' =&gt; false
);
?&gt;&lt;/pre&gt;
== Parameters ==
; '''type''' : (''string'') Type of category to retrieve
:* &lt;tt&gt;post&lt;/tt&gt; - default
:* &lt;tt&gt;link&lt;/tt&gt;
''&lt;span style=&quot;color:red;&quot;&gt;Note:&lt;/span&gt;'' '''&lt;tt&gt;type=link&lt;/tt&gt;''' has been deprecated from WordPress 3.0 onwards. Use '''&lt;tt&gt;taxonomy=link_category&lt;/tt&gt;''' instead.
; '''child_of''' : (''integer'') Display all categories that are descendants (i.e. children &amp; grandchildren) of the category identified by its ID. There is no default for this parameter. If the parameter is used, the '''hide_empty''' parameter is set to ''false''.
; '''parent''' : (''integer'') Display only categories that are direct descendants (i.e. children only) of the category identified by its ID. This does NOT work like the 'child_of' parameter. There is no default for this parameter. [In 2.8.4]
; '''orderby''' : (''string'') Sort categories alphabetically or by unique category ID. The default is ''sort by name''. Valid values:
:* &lt;tt&gt;id&lt;/tt&gt;
:* &lt;tt&gt;name&lt;/tt&gt; - default
:* &lt;tt&gt;slug&lt;/tt&gt;
:* &lt;tt&gt;count&lt;/tt&gt;
:* &lt;tt&gt;term_group&lt;/tt&gt;
; '''order''' : (''string'') Sort order for categories (either ascending or descending). The default is ''ascending''. Valid values:
:* &lt;tt&gt;asc&lt;/tt&gt; - default
:* &lt;tt&gt;desc&lt;/tt&gt;
; '''hide_empty''' : (''boolean'') Toggles the display of categories with no posts. The default is ''1'' for true or you can add '0' for false (show empty categories). Valid values:
:* &lt;tt&gt;1&lt;/tt&gt; - default
:* &lt;tt&gt;0&lt;/tt&gt;
; '''hierarchical''' : (''boolean'') When ''true'', the results will include sub-categories that are empty, as long as those sub-categories have sub-categories that are not empty. The default is ''true''. Valid values:
:* &lt;tt&gt;1 (true)&lt;/tt&gt; - default
:* &lt;tt&gt;0 (false)&lt;/tt&gt;
; '''exclude''' : (''string'') Excludes one or more categories from the list generated by ''wp_list_categories''. This parameter takes a comma-separated list of categories by unique ID, in ascending order. See [[Template_Tags/wp_list_categories#Include_or_Exclude_Categories|the example]].
; '''include''' : (''string'') Only include certain categories in the list generated by ''wp_list_categories''. This parameter takes a comma-separated list of categories by unique ID, in ascending order. See [[Template_Tags/wp_list_categories#Include_or_Exclude_Categories|the example]].
:* &lt;tt&gt;list&lt;/tt&gt; - default.
:* &lt;tt&gt;none&lt;/tt&gt;
; '''number''' : (''string'') The number of categories to return
; '''taxonomy''' : (''string or array'') Taxonomy to return. This parameter added at [[Version 3.0]] Valid values:
:* &lt;tt&gt;category&lt;/tt&gt; - default
:* &lt;tt&gt;taxonomy&lt;/tt&gt; - or any registered taxonomy
; '''pad_counts''' : (''boolean'') Calculates link or post counts by including items from child categories. Valid values:
:* &lt;tt&gt;1 (true)&lt;/tt&gt;
:* &lt;tt&gt;0 (false)&lt;/tt&gt; - default
== Return values ==
; (array) : Returns an array of category objects matching the query parameters.
The complete content of $category is:
&lt;pre&gt;
$category-&gt;term_id
$category-&gt;name
$category-&gt;slug
$category-&gt;term_group
$category-&gt;term_taxonomy_id
$category-&gt;taxonomy
$category-&gt;description
$category-&gt;parent
$category-&gt;count
$category-&gt;cat_ID
$category-&gt;category_count
$category-&gt;category_description
$category-&gt;cat_name
$category-&gt;category_nicename
$category-&gt;category_parent
&lt;/pre&gt;
== Examples ==
=== Dropdown Box as used in Parent category at post category page ===
This is the code used in the build in category page.
Code from 3.0.1
&lt;pre&gt;
wp_dropdown_categories(array('hide_empty' =&gt; 0, 'name' =&gt; 'category_parent', 'orderby' =&gt; 'name', 'selected' =&gt; $category-&gt;parent, 'hierarchical' =&gt; true, 'show_option_none' =&gt; __('None')));&lt;/pre&gt;
This slightly altered code will grab all categories and display them with indent for a new level (child category). The select box will have a name= and id= called 'select_name'.
This select will not display a default &quot;none&quot; as the original code was used to attach a category as a child to another category (or none).
&lt;pre&gt;
wp_dropdown_categories(array('hide_empty' =&gt; 0, 'name' =&gt; 'select_name', 'hierarchical' =&gt; true));
&lt;/pre&gt;
=== Dropdown Box ===
Here's how to create a dropdown box of the subcategories of, say, a category that archives information on past events. This mirrors the example of the dropdown example of [[Template_Tags/wp_get_archives | wp_get_archives]] which shows how to create a dropdown box for monthly archives.
Suppose the category whose subcategories you want to show is category 10, and that its category &quot;nicename&quot; is &quot;archives&quot;.
&lt;pre&gt;
&lt;select name=&quot;event-dropdown&quot; onchange='document.location.href=this.options[this.selectedIndex].value;'&gt;
&lt;option value=&quot;&quot;&gt;&lt;?php echo esc_attr(__('Select Event')); ?&gt;&lt;/option&gt;
&lt;?php
$categories = get_categories('child_of=10');
foreach ($categories as $category) {
$option = '&lt;option value=&quot;/category/archives/'.$category-&gt;category_nicename.'&quot;&gt;';
$option .= $category-&gt;cat_name;
$option .= ' ('.$category-&gt;category_count.')';
$option .= '&lt;/option&gt;';
echo $option;
}
?&gt;
&lt;/select&gt;
&lt;/pre&gt;
===List Categories and Descriptions===
This example will list in alphabetic order, all categories presented as links to the corresponding category archive. Each category descripition is listed after the category link.
&lt;pre&gt;
&lt;?php
$args = array(
'orderby' =&gt; 'name',
'order' =&gt; 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '&lt;p&gt;Category: &lt;a href=&quot;' . get_category_link( $category-&gt;term_id ) . '&quot; title=&quot;' . sprintf( __( &quot;View all posts in %s&quot; ), $category-&gt;name ) . '&quot; ' . '&gt;' . $category-&gt;name.'&lt;/a&gt; &lt;/p&gt; ';
echo '&lt;p&gt; Description:'. $category-&gt;description . '&lt;/p&gt;';
echo '&lt;p&gt; Post Count: '. $category-&gt;count . '&lt;/p&gt;'; }
?&gt;
&lt;/pre&gt;
===Get only top level categories ===
To get the top level categories only, set parent value to zero. This example gets link and name of top level categories.
&lt;pre&gt;
&lt;?php
$args = array(
'orderby' =&gt; 'name',
'parent' =&gt; 0
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
echo '&lt;a href=&quot;' . get_category_link( $category-&gt;term_id ) . '&quot;&gt;' . $category-&gt;name . '&lt;/a&gt;&lt;br/&gt;';
}
?&gt;
&lt;/pre&gt;
== Source File ==
&lt;tt&gt;get_categories()&lt;/tt&gt; is located in {{Trac|wp-includes/category.php}}.
{{Tag Footer}}
[[Category:Functions]]</p>
</d:entry>
<d:entry id="wp_enqueue_script" d:title="wp enqueue script">
<d:index d:value="wp enqueue script"/>
<h1>wp enqueue script</h1>
<p>__TOC__
{{Languages|
{{en|Function Reference/wp_enqueue_script}}
{{es|Referencia de Funciones/wp_enqueue_script}}
{{ja|関数リファレンス/wp_enqueue_script}}
{{ko|Function Reference/wp_enqueue_script}}
{{ru|Справочник по функциям/wp_enqueue_script}}
{{zh-cn|函数参考/wp_enqueue_script}}
}}
== Description ==
Links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered. You could either link a script with a handle previously registered using the &lt;tt&gt;[[Function Reference/wp_register_script|wp_register_script()]]&lt;/tt&gt; function, or provide this function with all the parameters necessary to link a script.
This is the recommended method of linking JavaScript to a WordPress generated page.
== Usage ==
%%%&lt;?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?&gt;%%%
See [[#Notes|Notes]] for information about what action [[Glossary#Hook|hooks]] should be used to call the function.
== Parameters ==
{{Parameter|$handle|string|Name used as a handle for the script. As a special case, if the string contains a '?' character, the preceding part of the string refers to the registered handle, and the succeeding part is appended to the URL as a query string. A version must be used with this special case.}}
{{Parameter|$src|string|URL to the script, e.g. ''http://&lt;nowiki/&gt;example.com/wp-content/themes/my-theme/my-theme-script.js''. You should never hardcode URLs to local scripts. To get a&nbsp;proper URL to local scripts, use &lt;tt&gt;[[Function Reference/plugins_url|plugins_url()]]&lt;/tt&gt; for [[Glossary#Plugin|plugins]] and &lt;tt&gt;[[Function Reference/get_template_directory_uri|get_template_directory_uri()]]&lt;/tt&gt; for [[Glossary#Themes|themes]]. Remote scripts can be specified with a protocol-agnostic URL, e.g.&nbsp;''//otherdomain.com/js/their-script.js''. This parameter is only required when the script with the given &lt;tt&gt;$handle&lt;/tt&gt; has not been already registered using &lt;tt&gt;[[Function Reference/wp_register_script|wp_register_script()]]&lt;/tt&gt;. See [[#Default Scripts Included and Registered by WordPress|Default Scripts Included and Registered by WordPress]].|optional|false}}
{{Parameter|$deps|array|Array of the handles of all the registered scripts that this script depends on, that is the scripts that must be loaded before this script. This parameter is only required when the script with the given &lt;tt&gt;$handle&lt;/tt&gt; has not been already registered using &lt;tt&gt;[[Function Reference/wp_register_script|wp_register_script()]]&lt;/tt&gt;. Default handles are all in lower case.|optional|array()}}
{{Parameter|$ver|string|String specifying the script version number, if it has one, which is concatenated to the end of the path as a query string. If no version is specified or set to ''false'', then WordPress automatically adds a version number equal to the current version of WordPress you are running. If set to ''null'' no version is added. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script.|optional|false}}
{{Parameter|$in_footer|boolean|Normally, scripts are placed in &lt;tt&gt;&lt;head&gt;&lt;/tt&gt; of the HTML document. If this parameter is ''true'', the script is placed before the &lt;tt&gt;&lt;/body&gt;&lt;/tt&gt; end tag. This requires the theme to have the &lt;tt&gt;[[Plugin API/Action Reference/wp footer|wp_footer()]]&lt;/tt&gt; template tag in the appropriate place.|optional|false}}
== Return Values ==
{{Return||void|This function does not return a value.}}
== Examples ==
== Using a Hook ==
Scripts and styles from a single action hook
&lt;pre&gt;
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
&lt;/pre&gt;
=== Link the script.aculo.us Library ===
The following is an example of basic usage which links the script.aculo.us library [[#Default_Scripts_Included_and_Registered_by_WordPress|already included and registered]] by WordPress with the ''scriptaculous'' handle.
&lt;pre&gt;
&lt;?php
function my_scripts_method() {
wp_enqueue_script( 'scriptaculous' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); // wp_enqueue_scripts action hook to link only on the front-end
?&gt;
&lt;/pre&gt;
The above example links the script.aculo.us library only on the front-end. If the library was needed within the [[Administration Screens|administration screens]], you could use the [[Plugin_API/Action_Reference/admin_enqueue_scripts|admin_enqueue_scripts]] action [[Glossary#Hook|hook]] instead, however, this would enqueue it on ''all'' the administration screens, which often leads to plugin/core conflicts, ultimately breaking the WordPress administration screens experience. Instead, you should only link it on the individual screens you need it, see the [[#Link_Scripts_Only_on_a_Plugin_Administration_Screen|Link Scripts Only on a Plugin Administration Screen]] section for an example of that.
=== Link a Theme Script Which Depends on jQuery ===
JavaScript files included in themes often require another JavaScript file to be loaded in advance to use its functions or variables. [[#Parameters|Using the &lt;tt&gt;$deps&lt;/tt&gt; parameter]], the &lt;tt&gt;wp_enqueue_script()&lt;/tt&gt; and &lt;tt&gt;[[Function Reference/wp_register_script|wp_register_script()]]&lt;/tt&gt; functions allows you to mark dependencies when registering a new script. This will cause WordPress to automatically link these dependencies to the HTML page before the new script is linked. If the [[#Default_Scripts_Included_and_Registered_by_WordPress|handles]] of these dependencies are [[Function Reference/wp_deregister_script|not registered]], WordPress will not link the new script. This example requires the jQuery library for the ''custom_script.js'' theme script:
&lt;pre&gt;
&lt;?php
function my_scripts_method() {
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/js/custom_script.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
?&gt;
&lt;/pre&gt;
=== Link a Plugin Script That Depends on script.aculo.us ===
This example is intended to be used within a [[Writing a Plugin#Plugin_Files|plugin file]] to register and link a new plugin script that depends on the script.aculo.us library. See the [[#Link_a_Theme_Script_Which_Depends_on_jQuery|example above]] for information about dependencies.
&lt;pre&gt;
&lt;?php
function my_scripts_method() {
wp_enqueue_script(
'newscript',
plugins_url( '/js/newscript.js' , __FILE__ ),
array( 'scriptaculous' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
?&gt;
&lt;/pre&gt;
=== Link Scripts Only on a Plugin Administration Screen ===
This example links a script only on a specific [[Administration Screens|administration screen]], as opposed to the scenario described in the paragraph below the code of the [[#Link_the_script.aculo.us_Library|first example]].
&lt;pre&gt;
&lt;?php
add_action( 'admin_init', 'my_plugin_admin_init' );
add_action( 'admin_menu', 'my_plugin_admin_menu' );
function my_plugin_admin_init() {
/* Register our script. */
wp_register_script( 'my-plugin-script', plugins_url( '/script.js', __FILE__ ) );
}
function my_plugin_admin_menu() {
/* Add our plugin submenu and administration screen */
$page_hook_suffix = add_submenu_page( 'edit.php', // The parent page of this submenu
__( 'My Plugin', 'myPlugin' ), // The submenu title
__( 'My Plugin', 'myPlugin' ), // The screen title