Make WordPress Core


Ignore:
Timestamp:
03/29/2007 02:45:34 AM (18 years ago)
Author:
rob1n
Message:

PHPdoc for plugin.php. Props Martin10. fixes #3852

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/plugin.php

    r4955 r5142  
    11<?php
    22
    3 //
    4 // Filter functions, the core of the WP plugin architecture.
    5 //
    6 
     3/**
     4 * Hooks a function to a specific filter action.
     5 *
     6 * Filters are the hooks that WordPress launches to modify text of various types
     7 * before adding it to the database or sending it to the browser screen. Plugins
     8 * can specify that one or more of its PHP functions is executed to
     9 * modify specific types of text at these times, using the Filter API.
     10 * See the [Plugin API] for a list of filter hooks.
     11 *
     12 * @param string $tag The name of the filter to hook the <tt>$function_to_add</tt> to.
     13 * @param callback $function_to_add The name of the function to be called when the filter is applied.
     14 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). 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.
     15 * @param int $accepted_args optional. The number of arguments the function accept (default 1). In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run.
     16 * @return boolean true if the <tt>$function_to_add</tt> is added succesfully to filter <tt>$tag</tt>. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching <tt>do_action()</tt> or <tt>apply_filters()</tt> call is run. For example, the action <tt>comment_id_not_found</tt> will pass any functions that hook onto it the ID of the requested comment.
     17 */
    718function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    819    global $wp_filter;
     
    1324}
    1425
     26/**
     27 * Call the functions added to a filter hook.
     28 *
     29 * The callback functions attached to filter hook <tt>$tag</tt> are invoked by
     30 * calling this function. This function can be used to create a new filter hook
     31 * by simply calling this function with the name of the new hook specified using
     32 * the <tt>$tag</a> parameter.
     33 * @uses merge_filters Merges the filter hooks using this function.
     34 * @param string $tag The name of the filter hook.
     35 * @param string $string The text on which the filters hooked to <tt>$tag</tt> are applied on.
     36 * @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
     37 * @return string The text in <tt>$string</tt> after all hooked functions are applied to it.
     38 */
    1539function apply_filters($tag, $string) {
    1640    global $wp_filter;
     
    3559}
    3660
     61/**
     62 * Merge the filter functions of a specific filter hook with generic filter functions.
     63 *
     64 * It is possible to defined generic filter functions using the filter hook
     65 * <em>all</e>. These functions are called for every filter tag. This function
     66 * merges the functions attached to the <em>all</em> hook with the functions
     67 * of a specific hoook defined by <tt>$tag</tt>.
     68 * @param string $tag The filter hook of which the functions should be merged.
     69 */
    3770function merge_filters($tag) {
    3871    global $wp_filter;
     
    4780}
    4881
     82/**
     83 * Removes a function from a specified filter hook.
     84 *
     85 * This function removes a function attached to a specified filter hook. This
     86 * method can be used to remove default functions attached to a specific filter
     87 * hook and possibly replace them with a substitute.
     88 * @param string $tag The filter hook to which the function to be removed is hooked.
     89 * @param callback $function_to_remove The name of the function which should be removed.
     90 * @param int $priority optional. The priority of the function (default: 10).
     91 * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
     92 * @return boolean Whether the function is removed.
     93 */
    4994function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    5095    global $wp_filter;
     
    55100}
    56101
    57 //
    58 // Action functions
    59 //
    60 
     102/**
     103 * Hooks a function on to a specific action.
     104 *
     105 * Actions are the hooks that the WordPress core launches at specific points
     106 * during execution, or when specific events occur. Plugins can specify that
     107 * one or more of its PHP functions are executed at these points, using the
     108 * Action API.
     109 *
     110 * @param string $tag The name of the action to which the <tt>$function_to-add</tt> is hooked.
     111 * @param callback $function_to_add The name of the function you wish to be called. Note: any of the syntaxes explained in the PHP documentation for the 'callback' type (http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback) are valid.
     112 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). 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.
     113 * @param int $accepted_args optional. The number of arguments the function accept (default 1). In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run.
     114 * @return boolean Always true.
     115 */
    61116function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    62117    add_filter($tag, $function_to_add, $priority, $accepted_args);
    63118}
    64119
     120/**
     121 * Execute functions hooked on a specific action hook.
     122 *
     123 * This function invokes all functions attached to action hook <tt>$tag</tt>.
     124 * It is possible to create new action hooks by simply calling this function,
     125 * specifying the name of the new hook using the <tt>$tag</tt> parameter.
     126 * @uses merge_filters
     127 * @param string $tag The name of the action to be executed.
     128 * @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
     129 */
    65130function do_action($tag, $arg = '') {
    66131    global $wp_filter, $wp_actions;
     
    92157}
    93158
    94 // Returns the number of times an action has been done
     159/**
     160 * Return the number of functions hooked to a specific action hook.
     161 * @param string $tag The name of the action hook.
     162 * @return int The number of functions hooked to action hook <tt>$tag</tt>
     163 */
    95164function did_action($tag) {
    96165    global $wp_actions;
     
    99168}
    100169
     170/**
     171 * Execute functions hooked on a specific action hook, specifying arguments in a array.
     172 *
     173 * This function is identical to {@link do_action}, but the argumetns passe to
     174 * the functions hooked to <tt>$tag</tt> are supplied using an array.
     175 * @param string $tag The name of the action to be executed.
     176 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
     177 */
    101178function do_action_ref_array($tag, $args) {
    102179    global $wp_filter, $wp_actions;
     
    121198}
    122199
     200/**
     201 * Removes a function from a specified action hook.
     202 *
     203 * This function removes a function attached to a specified action hook. This
     204 * method can be used to remove default functions attached to a specific filter
     205 * hook and possibly replace them with a substitute.
     206 * @param string $tag The action hook to which the function to be removed is hooked.
     207 * @param callback $function_to_remove The name of the function which should be removed.
     208 * @param int $priority optional The priority of the function (default: 10).
     209 * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
     210 * @return boolean Whether the function is removed.
     211 */
    123212function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    124213    remove_filter($tag, $function_to_remove, $priority, $accepted_args);
     
    129218//
    130219
     220/**
     221 * Gets the basename of a plugin.
     222 *
     223 * This method extract the name of a plugin from its filename.
     224 * @param string $file The filename of plugin.
     225 * @return string The name of a plugin.
     226 */
    131227function plugin_basename($file) {
    132228    $file = preg_replace('|\\\\+|', '\\\\', $file);
     
    135231}
    136232
     233/**
     234 * Hook a function on a plugin activation action hook.
     235 *
     236 * When a plugin is activated, the action 'activate_PLUGINNAME' hook is
     237 * activated. In the name of this hook, PLUGINNAME is replaced with the name of
     238 * the plugin, including the optional subdirectory. For example, when the plugin
     239 * is located in <tt>wp-content/plugin/sampleplugin/sample.php</tt>, then the
     240 * name of this hook will become 'activate_sampleplugin/sample.php'.
     241 * When the plugin consists of only one file and is (as by default) located at
     242 * <tt>wp-content/plugin/sample.php</tt> the name of this hook will be
     243 * 'activate_sample.php'.
     244 * @param string $file The filename of the plugin including the path.
     245 * @param string $function the function hooked to the 'activate_PLUGIN' action.
     246 */
    137247function register_activation_hook($file, $function) {
    138248    $file = plugin_basename($file);
     
    140250}
    141251
     252/**
     253 * Hook a function on a plugin deactivation action hook.
     254 *
     255 * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
     256 * deactivated. In the name of this hook, PLUGINNAME is replaced with the name of
     257 * the plugin, including the optional subdirectory. For example, when the plugin
     258 * is located in <tt>wp-content/plugin/sampleplugin/sample.php</tt>, then the
     259 * name of this hook will become 'activate_sampleplugin/sample.php'.
     260 * When the plugin consists of only one file and is (as by default) located at
     261 * <tt>wp-content/plugin/sample.php</tt> the name of this hook will be
     262 * 'activate_sample.php'.
     263 * @param string $file The filename of the plugin including the path.
     264 * @param string $function the function hooked to the 'activate_PLUGIN' action.
     265 */
    142266function register_deactivation_hook($file, $function) {
    143267    $file = plugin_basename($file);
Note: See TracChangeset for help on using the changeset viewer.