WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

vi:Tham Khảo Các Hàm

Bản Nháp

Trang này được đánh dấu là bản nháp. Bạn có thể giúp đỡ WordPressVN bằng cách hoàn thiện trang này.

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 are useful to Plugin and Theme developers. So, this article lists most of the core functions, excluding Template Tags. At the bottom of the page, there is a section listing other resources for finding information about WordPress functions. In addition to this information, the WordPress phpdoc site details all the WordPress functions by version since 2.6.1.

Note: This reference applies to Version 2.1 and later versions 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.

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!


Functions by category

Post, Page, and Attachment Functions

These functions are contained in formatting.php, media.php, post.php. See also Template Tags.

Posts

Post insertion and removal

Pages

Custom field/postmeta functions

Attachment functions

Others

Category, Tag and Taxonomy Functions

Functions surrounding the WordPress Terms tables, encompassing categories and tags for classifying posts, pages, links, etc.

Category functions in category.php

Tag Functions in category.php

Term Functions in taxonomy.php

Other Category Functions


User and Author Functions

These functions are in user.php, pluggable.php, registration.php. See also Template Tags.

Feed Functions

These functions are in functions.php, feed.php, rss.php

Comment, Ping, and Trackback Functions

These functions are found in comment.php, functions.php, post.php. See also Template Tags.

Action, Filter, and Plugin Functions

These functions are contained in plugin.php. See also Plugin API.

Theme-Related Functions

These functions are found in theme.php.


Formatting Functions

These functions are contained in formatting.php, functions.php, kses.php.

Miscellaneous Functions

These functions are contained in formatting.php, functions.php, bookmarks.php, cron.php, l10n.php, user.php, pluggable.php

Time/Date Functions

Serialization

Options

XMLRPC

Localization See also Translating WordPress.

Cron (Scheduling)

Miscellaneous

Classes

The following classes were created by WordPress developers, and are found in files capabilities.php, classes.php, class-snoopy.php, locale.php, query.php, rewrite.php, script-loader.php, wp-db.php:

  • WP - general request handling
  • WP_Ajax_Response - AJAX handling
  • WP_Object_Cache (formerly WP_Cache) - Object cache (and functions wp_cache_add, wp_cache_close, wp_cache_delete, wp_cache_flush, wp_cache_get, wp_cache_init, wp_cache_replace, wp_cache_set)
  • WP_Error - error handling (and function is_wp_error)
  • WP_Locale - handles date and time locales
  • WP_Query - Request parsing and manipulation, posts fetching (with functions get_query_var, query_posts, have_posts, in_the_loop, rewind_posts, the_post, wp_old_slug_redirect, setup_postdata, as well as the Conditional Tags is_*)
  • WP_Rewrite - Rewrite rules (and functions add_rewrite_rule, add_rewrite_tag, add_feed, add_rewrite_endpoint, url_to_postid)
  • WP_Roles, WP_Role, WP_User - Users and capabilities - map_meta_cap, current_user_can, get_role, add_role, remove_role
  • WP_Scripts - JavaScript loading (and functions wp_print_scripts, wp_register_script, wp_deregister_script wp_enqueue_script)
  • WP_Styles - CSS stylesheet loading (and functions wp_print_styles, wp_register_style, wp_deregister_style, wp_enqueue_style )
  • Display tree-like data - Walker, Walker_Page, Walker_PageDropdown, Walker_Category, Walker_CategoryDropdown
  • wpdb - Database interface

The following classes were created by outside developers, and are found in files class-IXR.php, class-pop3.php, class-snoopy.php, gettext.php, rss.php, streams.php:

  • 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
  • Snoopy - HTTP client
  • gettext_reader (part of PHP-gettext) - Localization Class
  • RSS Classes (MagpieRSS and RSSCache) (and functions fetch_rss, is_info, is_success, is_redirect, is_error, is_client_error, is_server_error, parse_w3cdtf, wp_rss, get_rss)
  • POP3: SquirrelMail wrapper
  • StreamReader, StringReader, FileReader, CachedFileReader

Official and Unofficial References

  • WordPress.org PHPDoc - Nearly all the functions in WordPress now have "PHPDoc" headers. This site shows all the PHPDoc.
  • Trac Browser - WordPress source code - Click on Tags to find a specific version, or Trunk to look at the latest WordPress source
  • PHPXref for WordPress - Cross reference of WordPress files, functions, and variables, which seems to point to the latest released version. This redalt.com PHPXref site has the bleeding-edge Trunk version, as well as 1.5 and 2.0, but the Trunk version may not be updating any more. So, there is now a new Trunk Xref site on ftwr.co.uk available.
  • WordPress Function History Table - List of what version each WordPress function was added in; PlanetOzh recommends: "see related WordPress Functions Implementation History Tool for more information (and for a more usable tool)"
  • WordPress Variable Report - A list of WordPress functions, listing what version of PHP every function requires (and if there's a compatible function available), what varables/arguments in functions are unused, and what functions/variables each class contains (and their default values).
  • WordPress Hooks Table - A list of WordPress actions and filters, cross-referenced to the files they are in