Make WordPress Core

Ticket #3852: plugin.php.diff

File plugin.php.diff, 10.2 KB (added by Martin10, 18 years ago)

Patch adding PHPdoc to plugin.php

  • wp-includes/plugin.php

     
    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;
    920
     
    2233        return true;
    2334}
    2435
     36/**
     37 * Call the functions added to a filter hook.
     38 *
     39 * The callback functions attached to filter hook <tt>$tag</tt> are invoked by
     40 * calling this function. This function can be used to create a new filter hook
     41 * by simply calling this function with the name of the new hook specified using
     42 * the <tt>$tag</a> parameter.
     43 * @uses merge_filters Merges the filter hooks using this function.
     44 * @param string $tag The name of the filter hook.
     45 * @param string $string The text on which the filters hooked to <tt>$tag</tt> are applied on.
     46 * @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
     47 * @return string The text in <tt>$string</tt> after all hooked functions are applied to it.
     48 */
    2549function apply_filters($tag, $string) {
    2650        global $wp_filter;
    2751
     
    5276        return $string;
    5377}
    5478
     79/**
     80 * Merge the filter functions of a specific filter hook with generic filter functions.
     81 *
     82 * It is possible to defined generic filter functions using the filter hook
     83 * <em>all</e>. These functions are called for every filter tag. This function
     84 * merges the functions attached to the <em>all</em> hook with the functions
     85 * of a specific hoook defined by <tt>$tag</tt>.
     86 * @param string $tag The filter hook of which the functions should be merged.
     87 */
    5588function merge_filters($tag) {
    5689        global $wp_filter;
    5790        if ( isset($wp_filter['all']) ) {
     
    68101                uksort( $wp_filter[$tag], "strnatcasecmp" );
    69102}
    70103
     104/**
     105 * Removes a function from a specified filter hook.
     106 *
     107 * This function removes a function attached to a specified filter hook. This
     108 * method can be used to remove default functions attached to a specific filter
     109 * hook and possibly replace them with a substitute.
     110 * @param string $tag The filter hook to which the function to be removed is hooked.
     111 * @param callback $function_to_remove The name of the function which should be removed.
     112 * @param int $priority optional. The priority of the function (default: 10).
     113 * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
     114 * @return boolean Whether the function is removed.
     115 */
    71116function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    72117        global $wp_filter;
    73118
     
    83128        return true;
    84129}
    85130
    86 //
    87 // Action functions
    88 //
    89 
     131/**
     132 * Hooks a function on to a specific action.
     133 *
     134 * Actions are the hooks that the WordPress core launches at specific points
     135 * during execution, or when specific events occur. Plugins can specify that
     136 * one or more of its PHP functions are executed at these points, using the
     137 * Action API.
     138 *
     139 * @param string $tag The name of the action to which the <tt>$function_to-add</tt> is hooked.
     140 * @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.
     141 * @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.
     142 * @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.
     143 * @return boolean Always true.
     144 */
    90145function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    91146        add_filter($tag, $function_to_add, $priority, $accepted_args);
    92147}
    93148
     149/**
     150 * Execute functions hooked on a specific action hook.
     151 *
     152 * This function invokes all functions attached to action hook <tt>$tag</tt>.
     153 * It is possible to create new action hooks by simply calling this function,
     154 * specifying the name of the new hook using the <tt>$tag</tt> parameter.
     155 * @uses merge_filters
     156 * @param string $tag The name of the action to be executed.
     157 * @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
     158 */
    94159function do_action($tag, $arg = '') {
    95160        global $wp_filter, $wp_actions;
    96161
     
    131196                $wp_actions = array($tag);
    132197}
    133198
    134 // Returns the number of times an action has been done
     199/**
     200 * Return the number of functions hooked to a specific action hook.
     201 * @param string $tag The name of the action hook.
     202 * @return int The number of functions hooked to action hook <tt>$tag</tt>
     203 */
    135204function did_action($tag) {
    136205        global $wp_actions;
    137206
    138207        return count(array_keys($wp_actions, $tag));
    139208}
    140209
     210/**
     211 * Execute functions hooked on a specific action hook, specifying arguments in a array.
     212 *
     213 * This function is identical to {@link do_action}, but the argumetns passe to
     214 * the functions hooked to <tt>$tag</tt> are supplied using an array.
     215 * @param string $tag The name of the action to be executed.
     216 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
     217 */
    141218function do_action_ref_array($tag, $args) {
    142219        global $wp_filter, $wp_actions;
    143220
     
    169246        }
    170247}
    171248
     249/**
     250 * Removes a function from a specified action hook.
     251 *
     252 * This function removes a function attached to a specified action hook. This
     253 * method can be used to remove default functions attached to a specific filter
     254 * hook and possibly replace them with a substitute.
     255 * @param string $tag The action hook to which the function to be removed is hooked.
     256 * @param callback $function_to_remove The name of the function which should be removed.
     257 * @param int $priority optional The priority of the function (default: 10).
     258 * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
     259 * @return boolean Whether the function is removed.
     260 */
    172261function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    173262        remove_filter($tag, $function_to_remove, $priority, $accepted_args);
    174263}
     
    177266// Functions for handling plugins.
    178267//
    179268
     269/**
     270 * Gets the basename of a plugin.
     271 *
     272 * This method extract the name of a plugin from its filename.
     273 * @param string $file The filename of plugin.
     274 * @return string The name of a plugin.
     275 */
    180276function plugin_basename($file) {
    181277        $file = preg_replace('|\\\\+|', '\\\\', $file);
    182278        $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
    183279        return $file;
    184280}
    185281
     282/**
     283 * Hook a function on a plugin activation action hook.
     284 *
     285 * When a plugin is activated, the action 'activate_PLUGINNAME' hook is
     286 * activated. In the name of this hook, PLUGINNAME is replaced with the name of
     287 * the plugin, including the optional subdirectory. For example, when the plugin
     288 * is located in <tt>wp-content/plugin/sampleplugin/sample.php</tt>, then the
     289 * name of this hook will become 'activate_sampleplugin/sample.php'.
     290 * When the plugin consists of only one file and is (as by default) located at
     291 * <tt>wp-content/plugin/sample.php</tt> the name of this hook will be
     292 * 'activate_sample.php'.
     293 * @param string $file The filename of the plugin including the path.
     294 * @param string $function the function hooked to the 'activate_PLUGIN' action.
     295 */
    186296function register_activation_hook($file, $function) {
    187297        $file = plugin_basename($file);
    188298        add_action('activate_' . $file, $function);
    189299}
    190300
     301/**
     302 * Hook a function on a plugin deactivation action hook.
     303 *
     304 * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
     305 * deactivated. In the name of this hook, PLUGINNAME is replaced with the name of
     306 * the plugin, including the optional subdirectory. For example, when the plugin
     307 * is located in <tt>wp-content/plugin/sampleplugin/sample.php</tt>, then the
     308 * name of this hook will become 'activate_sampleplugin/sample.php'.
     309 * When the plugin consists of only one file and is (as by default) located at
     310 * <tt>wp-content/plugin/sample.php</tt> the name of this hook will be
     311 * 'activate_sample.php'.
     312 * @param string $file The filename of the plugin including the path.
     313 * @param string $function the function hooked to the 'activate_PLUGIN' action.
     314 */
    191315function register_deactivation_hook($file, $function) {
    192316        $file = plugin_basename($file);
    193317        add_action('deactivate_' . $file, $function);