[ Index ]

PHP Cross Reference of Wordpress 2.9.1

title

Body

[close]

/wp-includes/ -> functions.php (summary)

Main WordPress API

File Size: 3640 lines (115 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 1 file
 wp-includes/class-IXR.php

Defines 76 functions

  mysql2date()
  current_time()
  date_i18n()
  number_format_i18n()
  size_format()
  get_weekstartend()
  maybe_unserialize()
  is_serialized()
  is_serialized_string()
  get_option()
  wp_protect_special_option()
  form_option()
  get_alloptions()
  wp_load_alloptions()
  update_option()
  add_option()
  delete_option()
  delete_transient()
  get_transient()
  set_transient()
  wp_user_settings()
  get_user_setting()
  set_user_setting()
  delete_user_setting()
  get_all_user_settings()
  wp_set_all_user_settings()
  delete_all_user_settings()
  maybe_serialize()
  xmlrpc_getposttitle()
  xmlrpc_getpostcategory()
  xmlrpc_removepostdata()
  debug_fopen()
  debug_fwrite()
  debug_fclose()
  do_enclose()
  wp_get_http()
  wp_get_http_headers()
  is_new_day()
  build_query()
  add_query_arg()
  remove_query_arg()
  add_magic_quotes()
  wp_remote_fopen()
  wp()
  get_status_header_desc()
  status_header()
  wp_get_nocache_headers()
  nocache_headers()
  cache_javascript_headers()
  get_num_queries()
  bool_from_yn()
  do_feed()
  do_feed_rdf()
  do_feed_rss()
  do_feed_rss2()
  do_feed_atom()
  do_robots()
  is_blog_installed()
  wp_nonce_url()
  wp_nonce_field()
  wp_referer_field()
  wp_original_referer_field()
  wp_get_referer()
  wp_get_original_referer()
  wp_mkdir_p()
  path_is_absolute()
  path_join()
  wp_upload_dir()
  wp_unique_filename()
  wp_upload_bits()
  wp_ext2type()
  wp_check_filetype()
  get_allowed_mime_types()
  wp_explain_nonce()
  wp_nonce_ays()
  wp_die()

Functions
Functions that are not part of a class:

mysql2date( $dateformatstring, $mysqlstring, $translate = true )   X-Ref
Converts MySQL DATETIME field to user specified date format.

If $dateformatstring has 'G' value, then gmmktime() function will be used to
make the time. If $dateformatstring is set to 'U', then mktime() function
will be used to make the time.

The $translate will only be used, if it is set to true and it is by default
and if the $wp_locale object has the month and weekday set.

param: string $dateformatstring Either 'G', 'U', or php date format.
param: string $mysqlstring Time from mysql DATETIME field.
param: bool $translate Optional. Default is true. Will switch format to locale.
return: string Date formated by $dateformatstring or locale (if available).

current_time( $type, $gmt = 0 )   X-Ref
Retrieve the current time based on specified type.

The 'mysql' type will return the time in the format for MySQL DATETIME field.
The 'timestamp' type will return the current timestamp.

If $gmt is set to either '1' or 'true', then both types will use GMT time.
if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.

param: string $type Either 'mysql' or 'timestamp'.
param: int|bool $gmt Optional. Whether to use GMT timezone. Default is false.
return: int|string String if $type is 'gmt', int if $type is 'timestamp'.

date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false )   X-Ref
Retrieve the date in localized format, based on timestamp.

If the locale specifies the locale month and weekday, then the locale will
take over the format for the date. If it isn't, then the date format string
will be used instead.

param: string $dateformatstring Format to display the date.
param: int $unixtimestamp Optional. Unix timestamp.
param: bool $gmt Optional, default is false. Whether to convert to GMT for time.
return: string The date, translated if locale specifies it.

number_format_i18n( $number, $decimals = null )   X-Ref
Convert number to format based on the locale.

param: mixed $number The number to convert based on locale.
param: int $decimals Precision of the number of decimal places.
return: string Converted number in string format.

size_format( $bytes, $decimals = null )   X-Ref
Convert number of bytes largest unit bytes will fit into.

It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts
number of bytes to human readable number by taking the number of that unit
that the bytes will go into it. Supports TB value.

Please note that integers in PHP are limited to 32 bits, unless they are on
64 bit architecture, then they have 64 bit size. If you need to place the
larger size then what PHP integer type will hold, then use a string. It will
be converted to a double, which should always have 64 bit length.

Technically the correct unit names for powers of 1024 are KiB, MiB etc.
param: int|string $bytes Number of bytes. Note max integer size for integers.
param: int $decimals Precision of number of decimal places.
return: bool|string False on failure. Number string on success.

get_weekstartend( $mysqlstring, $start_of_week = '' )   X-Ref
Get the week start and end from the datetime or date string from mysql.

param: string $mysqlstring Date or datetime field type from mysql.
param: int $start_of_week Optional. Start of the week as an integer.
return: array Keys are 'start' and 'end'.

maybe_unserialize( $original )   X-Ref
Unserialize value only if it was serialized.

param: string $original Maybe unserialized original, if is needed.
return: mixed Unserialized data can be any type.

is_serialized( $data )   X-Ref
Check value to find if it was serialized.

If $data is not an string, then returned value will always be false.
Serialized data is always a string.

param: mixed $data Value to check to see if was serialized.
return: bool False if not serialized and true if it was.

is_serialized_string( $data )   X-Ref
Check whether serialized data is of string type.

param: mixed $data Serialized data
return: bool False if not a serialized string, true if it is.

get_option( $setting, $default = false )   X-Ref
Retrieve option value based on setting name.

If the option does not exist or does not have a value, then the return value
will be false. This is useful to check whether you need to install an option
and is commonly used during installation of plugin options and to test
whether upgrading is required.

You can "short-circuit" the retrieval of the option from the database for
your plugin or core options that aren't protected. You can do so by hooking
into the 'pre_option_$option' with the $option being replaced by the option
name. You should not try to override special options, but you will not be
prevented from doing so.

There is a second filter called 'option_$option' with the $option being
replaced with the option name. This gives the value as the only parameter.

If the option was serialized, when the option was added and, or updated, then
it will be unserialized, when it is returned.

param: string $setting Name of option to retrieve. Should already be SQL-escaped
return: mixed Value set for the option.

wp_protect_special_option( $option )   X-Ref
Protect WordPress special option from being modified.

Will die if $option is in protected list. Protected options are 'alloptions'
and 'notoptions' options.

param: string $option Option name.

form_option( $option )   X-Ref
Print option value after sanitizing for forms.

param: string $option Option name.

get_alloptions()   X-Ref
Retrieve all autoload options or all options, if no autoloaded ones exist.

This is different from wp_load_alloptions() in that this function does not
cache its results and will retrieve all options from the database every time

it is called.

return: array List of all options.

wp_load_alloptions()   X-Ref
Loads and caches all autoloaded options, if available or all options.

This is different from get_alloptions(), in that this function will cache the
options and will return the cached options when called again.

return: array List all options.

update_option( $option_name, $newvalue )   X-Ref
Update the value of an option that was already added.

You do not need to serialize values, if the value needs to be serialize, then
it will be serialized before it is inserted into the database. Remember,
resources can not be serialized or added as an option.

If the option does not exist, then the option will be added with the option
value, but you will not be able to set whether it is autoloaded. If you want
to set whether an option autoloaded, then you need to use the add_option().

Before the option is updated, then the filter named
'pre_update_option_$option_name', with the $option_name as the $option_name
parameter value, will be called. The hook should accept two parameters, the
first is the new value and the second is the old value.  Whatever is
returned will be used as the new value.

After the value has been updated the action named 'update_option_$option_name'
will be called.  This action receives two parameters the first being the old
value and the second the new value.

param: string $option_name Option name. Expected to not be SQL-escaped
param: mixed $newvalue Option value.
return: bool False if value was not updated and true if value was updated.

add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' )   X-Ref
Add a new option.

You do not need to serialize values, if the value needs to be serialize, then
it will be serialized before it is inserted into the database. Remember,
resources can not be serialized or added as an option.

You can create options without values and then add values later. Does not
check whether the option has already been added, but does check that you
aren't adding a protected WordPress option. Care should be taken to not name
options, the same as the ones which are protected and to not add options
that were already added.

The filter named 'add_option_$optionname', with the $optionname being
replaced with the option's name, will be called. The hook should accept two
parameters, the first is the option name, and the second is the value.

param: string $name Option name to add. Expects to NOT be SQL escaped.
param: mixed $value Optional. Option value, can be anything.
param: mixed $deprecated Optional. Description. Not used anymore.
param: bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
return: null returns when finished.

delete_option( $name )   X-Ref
Removes option by name and prevents removal of protected WordPress options.

param: string $name Option name to remove.
return: bool True, if succeed. False, if failure.

delete_transient($transient)   X-Ref
Delete a transient

param: string $transient Transient name. Expected to not be SQL-escaped
return: bool true if successful, false otherwise

get_transient($transient)   X-Ref
Get the value of a transient

If the transient does not exist or does not have a value, then the return value
will be false.

param: string $transient Transient name. Expected to not be SQL-escaped
return: mixed Value of transient

set_transient($transient, $value, $expiration = 0)   X-Ref
Set/update the value of a transient

You do not need to serialize values, if the value needs to be serialize, then
it will be serialized before it is set.

param: string $transient Transient name. Expected to not be SQL-escaped
param: mixed $value Transient value.
param: int $expiration Time until expiration in seconds, default 0
return: bool False if value was not set and true if value was set.

wp_user_settings()   X-Ref
Saves and restores user interface settings stored in a cookie.

Checks if the current user-settings cookie is updated and stores it. When no
cookie exists (different browser used), adds the last saved cookie restoring
the settings.


get_user_setting( $name, $default = false )   X-Ref
Retrieve user interface setting value based on setting name.

param: string $name The name of the setting.
param: string $default Optional default value to return when $name is not set.
return: mixed the last saved user setting or the default value/false if it doesn't exist.

set_user_setting( $name, $value )   X-Ref
Add or update user interface setting.

Both $name and $value can contain only ASCII letters, numbers and underscores.
This function has to be used before any output has started as it calls setcookie().

param: string $name The name of the setting.
param: string $value The value for the setting.
return: bool true if set successfully/false if not.

delete_user_setting( $names )   X-Ref
Delete user interface settings.

Deleting settings would reset them to the defaults.
This function has to be used before any output has started as it calls setcookie().

param: mixed $names The name or array of names of the setting to be deleted.
return: bool true if deleted successfully/false if not.

get_all_user_settings()   X-Ref
Retrieve all user interface settings.

return: array the last saved user settings or empty array.

wp_set_all_user_settings($all)   X-Ref
Private. Set all user interface settings.


delete_all_user_settings()   X-Ref
Delete the user settings of the current user.


maybe_serialize( $data )   X-Ref
Serialize data, if needed.

param: mixed $data Data that might be serialized.
return: mixed A scalar data

xmlrpc_getposttitle( $content )   X-Ref
Retrieve post title from XMLRPC XML.

If the title element is not part of the XML, then the default post title from
the $post_default_title will be used instead.

param: string $content XMLRPC XML Request content
return: string Post title

xmlrpc_getpostcategory( $content )   X-Ref
Retrieve the post category or categories from XMLRPC XML.

If the category element is not found, then the default post category will be
used. The return type then would be what $post_default_category. If the
category is found, then it will always be an array.

param: string $content XMLRPC XML Request content
return: string|array List of categories or category name.

xmlrpc_removepostdata( $content )   X-Ref
XMLRPC XML content without title and category elements.

param: string $content XMLRPC XML Request content
return: string XMLRPC XML Request content without title and category elements.

debug_fopen( $filename, $mode )   X-Ref
Open the file handle for debugging.

This function is used for XMLRPC feature, but it is general purpose enough
to be used in anywhere.

param: string $filename File path to debug file.
param: string $mode Same as fopen() mode parameter.
return: bool|resource File handle. False on failure.

debug_fwrite( $fp, $string )   X-Ref
Write contents to the file used for debugging.

Technically, this can be used to write to any file handle when the global
$debug is set to 1 or true.

param: resource $fp File handle for debugging file.
param: string $string Content to write to debug file.

debug_fclose( $fp )   X-Ref
Close the debugging file handle.

Technically, this can be used to close any file handle when the global $debug
is set to 1 or true.

param: resource $fp Debug File handle.

do_enclose( $content, $post_ID )   X-Ref
Check content for video and audio links to add as enclosures.

Will not add enclosures that have already been added and will
remove enclosures that are no longer in the post. This is called as
pingbacks and trackbacks.

param: string $content Post Content
param: int $post_ID Post ID

wp_get_http( $url, $file_path = false, $deprecated = false )   X-Ref
Perform a HTTP HEAD or GET request.

If $file_path is a writable filename, this will do a GET request and write
the file to that path.

param: string $url URL to fetch.
param: string|bool $file_path Optional. File path to write request to.
param: bool $deprecated Deprecated. Not used.
return: bool|string False on failure and string of headers if HEAD request.

wp_get_http_headers( $url, $deprecated = false )   X-Ref
Retrieve HTTP Headers from URL.

param: string $url
param: bool $deprecated Not Used.
return: bool|string False on failure, headers on success.

is_new_day()   X-Ref
Whether today is a new day.

return: int 1 when new day, 0 if not a new day.

build_query( $data )   X-Ref
Build URL query based on an associative and, or indexed array.

This is a convenient function for easily building url queries. It sets the
separator to '&' and uses _http_build_query() function.

param: array $data URL-encode key/value pairs.
return: string URL encoded string

add_query_arg()   X-Ref
Retrieve a modified URL query string.

You can rebuild the URL and append a new query variable to the URL query by
using this function. You can also retrieve the full URL with query data.

Adding a single key & value or an associative array. Setting a key value to
emptystring removes the key. Omitting oldquery_or_uri uses the $_SERVER
value.

param: mixed $param1 Either newkey or an associative_array
param: mixed $param2 Either newvalue or oldquery or uri
param: mixed $param3 Optional. Old query or uri
return: string New URL query string.

remove_query_arg( $key, $query=false )   X-Ref
Removes an item or list from the query string.

param: string|array $key Query key or keys to remove.
param: bool $query When false uses the $_SERVER value.
return: string New URL query string.

add_magic_quotes( $array )   X-Ref
Walks the array while sanitizing the contents.

param: array $array Array to used to walk while sanitizing contents.
return: array Sanitized $array.

wp_remote_fopen( $uri )   X-Ref
HTTP request for URI to retrieve content.

param: string $uri URI/URL of web page to retrieve.
return: bool|string HTTP content. False on failure.

wp( $query_vars = '' )   X-Ref
Setup the WordPress query.

param: string $query_vars Default WP_Query arguments.

get_status_header_desc( $code )   X-Ref
Retrieve the description for the HTTP status.

param: int $code HTTP status code.
return: string Empty string if not found, or description if found.

status_header( $header )   X-Ref
Set HTTP status header.

param: int $header HTTP status code
return: null Does not return anything.

wp_get_nocache_headers()   X-Ref
Gets the header information to prevent caching.

The several different headers cover the different ways cache prevention is handled
by different browsers

return: array The associative array of header names and field values.

nocache_headers()   X-Ref
Sets the headers to prevent caching for the different browsers.

Different browsers support different nocache headers, so several headers must
be sent so that all of them get the point that no caching should occur.


cache_javascript_headers()   X-Ref
Set the headers for caching for 10 days with JavaScript content type.


get_num_queries()   X-Ref
Retrieve the number of database queries during the WordPress execution.

return: int Number of database queries

bool_from_yn( $yn )   X-Ref
Whether input is yes or no. Must be 'y' to be true.

param: string $yn Character string containing either 'y' or 'n'
return: bool True if yes, false on anything else

do_feed()   X-Ref
Loads the feed template from the use of an action hook.

If the feed action does not have a hook, then the function will die with a
message telling the visitor that the feed is not valid.

It is better to only have one hook for each feed.


do_feed_rdf()   X-Ref
Load the RDF RSS 0.91 Feed template.


do_feed_rss()   X-Ref
Load the RSS 1.0 Feed Template


do_feed_rss2( $for_comments )   X-Ref
Load either the RSS2 comment feed or the RSS2 posts feed.

param: bool $for_comments True for the comment feed, false for normal feed.

do_feed_atom( $for_comments )   X-Ref
Load either Atom comment feed or Atom posts feed.

param: bool $for_comments True for the comment feed, false for normal feed.

do_robots()   X-Ref
Display the robot.txt file content.

The echo content should be with usage of the permalinks or for creating the
robot.txt file.


is_blog_installed()   X-Ref
Test whether blog is already installed.

The cache will be checked first. If you have a cache plugin, which saves the
cache values, then this will work. If you use the default WordPress cache,
and the database goes away, then you might have problems.

Checks for the option siteurl for whether WordPress is installed.

return: bool Whether blog is already installed.

wp_nonce_url( $actionurl, $action = -1 )   X-Ref
Retrieve URL with nonce added to URL query.

param: string $actionurl URL to add nonce action
param: string $action Optional. Nonce action name
return: string URL with nonce action added.

wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true )   X-Ref
Retrieve or display nonce hidden field for forms.

The nonce field is used to validate that the contents of the form came from
the location on the current site and not somewhere else. The nonce does not
offer absolute protection, but should protect against most cases. It is very
important to use nonce field in forms.

If you set $echo to true and set $referer to true, then you will need to
retrieve the {@link wp_referer_field() wp referer field}. If you have the
$referer set to true and are echoing the nonce field, it will also echo the
referer field.

The $action and $name are optional, but if you want to have better security,
it is strongly suggested to set those two parameters. It is easier to just
call the function without any parameters, because validation of the nonce
doesn't require any parameters, but since crackers know what the default is
it won't be difficult for them to find a way around your nonce and cause
damage.

The input name will be whatever $name value you gave. The input value will be
the nonce creation value.

param: string $action Optional. Action name.
param: string $name Optional. Nonce name.
param: bool $referer Optional, default true. Whether to set the referer field for validation.
param: bool $echo Optional, default true. Whether to display or return hidden form field.
return: string Nonce field.

wp_referer_field( $echo = true)   X-Ref
Retrieve or display referer hidden field for forms.

The referer link is the current Request URI from the server super global. The
input name is '_wp_http_referer', in case you wanted to check manually.

param: bool $echo Whether to echo or return the referer field.
return: string Referer field.

wp_original_referer_field( $echo = true, $jump_back_to = 'current' )   X-Ref
Retrieve or display original referer hidden field for forms.

The input name is '_wp_original_http_referer' and will be either the same
value of {@link wp_referer_field()}, if that was posted already or it will
be the current page, if it doesn't exist.

param: bool $echo Whether to echo the original http referer
param: string $jump_back_to Optional, default is 'current'. Can be 'previous' or page you want to jump back to.
return: string Original referer field.

wp_get_referer()   X-Ref
Retrieve referer from '_wp_http_referer', HTTP referer, or current page respectively.

return: string|bool False on failure. Referer URL on success.

wp_get_original_referer()   X-Ref
Retrieve original referer that was posted, if it exists.

return: string|bool False if no original referer or original referer if set.

wp_mkdir_p( $target )   X-Ref
Recursive directory creation based on full path.

Will attempt to set permissions on folders.

param: string $target Full path to attempt to create.
return: bool Whether the path was created or not. True if path already exists.

path_is_absolute( $path )   X-Ref
Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows').

param: string $path File path
return: bool True if path is absolute, false is not absolute.

path_join( $base, $path )   X-Ref
Join two filesystem paths together (e.g. 'give me $path relative to $base').

If the $path is absolute, then it the full path is returned.

param: string $base
param: string $path
return: string The path with the base or absolute path.

wp_upload_dir( $time = null )   X-Ref
Get an array containing the current upload directory's path and url.

Checks the 'upload_path' option, which should be from the web root folder,
and if it isn't empty it will be used. If it is empty, then the path will be
'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.

The upload URL path is set either by the 'upload_url_path' option or by using
the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.

If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
the administration settings panel), then the time will be used. The format
will be year first and then month.

If the path couldn't be created, then an error will be returned with the key
'error' containing the error message. The error suggests that the parent
directory is not writable by the server.

On success, the returned array will have many indices:
'path' - base directory and sub directory or full path to upload directory.
'url' - base url and sub directory or absolute URL to upload directory.
'subdir' - sub directory if uploads use year/month folders option is on.
'basedir' - path without subdir.
'baseurl' - URL path without subdir.
'error' - set to false.

param: string $time Optional. Time formatted in 'yyyy/mm'.
return: array See above for description.

wp_unique_filename( $dir, $filename, $unique_filename_callback = null )   X-Ref
Get a filename that is sanitized and unique for the given directory.

If the filename is not unique, then a number will be added to the filename
before the extension, and will continue adding numbers until the filename is
unique.

The callback must accept two parameters, the first one is the directory and
the second is the filename. The callback must be a function.

param: string $dir
param: string $filename
param: string $unique_filename_callback Function name, must be a function.
return: string New filename, if given wasn't unique.

wp_upload_bits( $name, $deprecated, $bits, $time = null )   X-Ref
Create a file in the upload folder with given content.

If there is an error, then the key 'error' will exist with the error message.
If success, then the key 'file' will have the unique file path, the 'url' key
will have the link to the new file. and the 'error' key will be set to false.

This function will not move an uploaded file to the upload folder. It will
create a new file with the content in $bits parameter. If you move the upload
file, read the content of the uploaded file, and then you can give the
filename and content to this function, which will add it to the upload
folder.

The permissions will be set on the new file automatically by this function.

param: string $name
param: null $deprecated Not used. Set to null.
param: mixed $bits File content
param: string $time Optional. Time formatted in 'yyyy/mm'.
return: array

wp_ext2type( $ext )   X-Ref
Retrieve the file type based on the extension name.

param: string $ext The extension to search.
return: string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found.

wp_check_filetype( $filename, $mimes = null )   X-Ref
Retrieve the file type from the file name.

You can optionally define the mime array, if needed.

param: string $filename File name or path.
param: array $mimes Optional. Key is the file extension with value as the mime type.
return: array Values with extension first and mime type.

get_allowed_mime_types()   X-Ref
Retrieve list of allowed mime types and file extensions.

return: array Array of mime types keyed by the file extension regex corresponding to those types.

wp_explain_nonce( $action )   X-Ref
Retrieve nonce action "Are you sure" message.

The action is split by verb and noun. The action format is as follows:
verb-action_extra. The verb is before the first dash and has the format of
letters and no spaces and numbers. The noun is after the dash and before the
underscore, if an underscore exists. The noun is also only letters.

The filter will be called for any action, which is not defined by WordPress.
You may use the filter for your plugin to explain nonce actions to the user,
when they get the "Are you sure?" message. The filter is in the format of
'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the
$noun replaced by the found noun. The two parameters that are given to the
hook are the localized "Are you sure you want to do this?" message with the
extra text (the text after the underscore).

param: string $action Nonce action.
return: string Are you sure message.

wp_nonce_ays( $action )   X-Ref
Display "Are You Sure" message to confirm the action being taken.

If the action has the nonce explain message, then it will be displayed along
with the "Are you sure?" message.

param: string $action The nonce action.

wp_die( $message, $title = '', $args = array()   X-Ref
Kill WordPress execution and display HTML message with error message.

Call this function complements the die() PHP function. The difference is that
HTML will be displayed to the user. It is recommended to use this function
only, when the execution should not continue any further. It is not
recommended to call this function very often and try to handle as many errors
as possible siliently.

param: string $message Error message.
param: string $title Error title.
param: string|array $args Optional arguements to control behaviour.



Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7