Make WordPress Core

Ticket #27715: 27715.3.diff

File 27715.3.diff, 16.8 KB (added by GaryJ, 10 years ago)

Remaining filters and actions

  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index 3ac8b13..adc087c 100644
    function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { 
    140140                }
    141141        }
    142142        $j = @$datefunc( $dateformatstring, $i );
    143         // allow plugins to redo this entirely for languages with untypical grammars
     143
     144        /**
     145         * Filter date to allow plugins to redo this entirely for languages with untypical grammars.
     146         *
     147         * @since 2.8.0
     148         *
     149         * @param string $j          Formatted date string.
     150         * @param string $req_format Format to display the date.
     151         * @param bool   $gmt        Whether to convert to GMT for time.
     152         */
    144153        $j = apply_filters('date_i18n', $j, $req_format, $i, $gmt);
    145154        return $j;
    146155}
    function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { 
    157166function number_format_i18n( $number, $decimals = 0 ) {
    158167        global $wp_locale;
    159168        $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
     169
     170        /**
     171         * Filter number formatted based on the locale.
     172         *
     173         * @since  2.8.0
     174         *
     175         * @param string $formatted Converted number in string format.
     176         */
    160177        return apply_filters( 'number_format_i18n', $formatted );
    161178}
    162179
    function status_header( $code ) { 
    917934                $protocol = 'HTTP/1.0';
    918935        $status_header = "$protocol $code $description";
    919936        if ( function_exists( 'apply_filters' ) )
     937
     938                /**
     939                 * Filter a status header.
     940                 *
     941                 * @since 2.2.0
     942                 *
     943                 * @param string $status_header Status header.
     944                 * @param int    $code          HTTP status code.
     945                 * @param string $description   Description for the status code, empty string if not found.
     946                 * @param string $protocol      Server protocol.
     947                 */
    920948                $status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
    921949
    922950        @header( $status_header, true, $code );
    function wp_get_nocache_headers() { 
    940968        );
    941969
    942970        if ( function_exists('apply_filters') ) {
     971
     972                /**
     973                 * Filter the cache-controlling headers.
     974                 *
     975                 * @since 2.8.0
     976                 *
     977                 * @param array $headers {
     978                 *     Header names and field values.
     979                 *
     980                 *     @type string $Expires       Expires header.
     981                 *     @type string $Cache-Control Cache-Control header.
     982                 *     @type string $Pragma        Pragma header.
     983                 * }
     984                 */
    943985                $headers = (array) apply_filters('nocache_headers', $headers);
    944986        }
    945987        $headers['Last-Modified'] = false;
    function do_feed() { 
    10411083        if ( ! has_action( $hook ) )
    10421084                wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );
    10431085
     1086        /**
     1087         * Fires contextually for each feed.
     1088         *
     1089         * Hook name is `do_feed_{$feed}`.
     1090         *
     1091         * @since 2.1.0
     1092         *
     1093         * @param bool $is_comment_feed True if feed is a comment feed.
     1094         */
    10441095        do_action( $hook, $wp_query->is_comment_feed );
    10451096}
    10461097
    function do_feed_atom( $for_comments ) { 
    11021153function do_robots() {
    11031154        header( 'Content-Type: text/plain; charset=utf-8' );
    11041155
     1156        /**
     1157         * Fires when displaying the robots.txt file.
     1158         *
     1159         * @since 2.1.0
     1160         */
    11051161        do_action( 'do_robotstxt' );
    11061162
    11071163        $output = "User-agent: *\n";
    function wp_upload_dir( $time = null ) { 
    16551711        $dir .= $subdir;
    16561712        $url .= $subdir;
    16571713
     1714        /**
     1715         * Filter the uploads directory data.
     1716         *
     1717         * @since 2.0.0
     1718         *
     1719         * @param array $uploads Array of upload directory data with keys of `path`, `url`, `subdir`,
     1720         *                       `basedir` and `error`.
     1721         */
    16581722        $uploads = apply_filters( 'upload_dir',
    16591723                array(
    16601724                        'path'    => $dir,
    function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { 
    17801844        if ( $upload['error'] !== false )
    17811845                return $upload;
    17821846
     1847        /**
     1848         * Filter whether upload bits produces an error.
     1849         *
     1850         * If it is an error, then filter should not return an array.
     1851         *
     1852         * @since 3.0.0
     1853         *
     1854         * @param array $upload_bits_error Array with keys for `name`, `bits` and `time`.
     1855         */
    17831856        $upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) );
    17841857        if ( !is_array( $upload_bits_error ) ) {
    17851858                $upload[ 'error' ] = $upload_bits_error;
    function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { 
    18311904 */
    18321905function wp_ext2type( $ext ) {
    18331906        $ext = strtolower( $ext );
     1907
     1908        /**
     1909         * Filter file type based on the extension name.
     1910         *
     1911         * @since 2.5.0
     1912         *
     1913         * @param array $ext2type Multi-dimensional array with extensions for the default keys of
     1914         *                        `image`, `audio`, `video`, `document`, `spreadsheet`, `interactive`,
     1915         *                        `text`, `archive` and `code`.
     1916         */
    18341917        $ext2type = apply_filters( 'ext2type', array(
    18351918                'image'       => array( 'jpg', 'jpeg', 'jpe',  'gif',  'png',  'bmp',   'tif',  'tiff', 'ico' ),
    18361919                'audio'       => array( 'aac', 'ac3',  'aif',  'aiff', 'm3a',  'm4a',   'm4b',  'mka',  'mp1',  'mp2',  'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
    function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 
    19151998
    19161999                // If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME
    19172000                if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) {
    1918                         // This is a simplified array of MIMEs that getimagesize() can detect and their extensions
    1919                         // You shouldn't need to use this filter, but it's here just in case
     2001                        /**
     2002                         * Filter a simplified array of MIMEs that getimagesize() can detect and their extensions.
     2003                         *
     2004                         * You shouldn't need to use this filter, but it's here just in case.
     2005                         *
     2006                         * @since 3.0.0
     2007                         *
     2008                         * @param  array $mime_to_ext Array of image MIMEs to extensions.
     2009                         */
    19202010                        $mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array(
    19212011                                'image/jpeg' => 'jpg',
    19222012                                'image/png'  => 'png',
    function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 
    19422032                }
    19432033        }
    19442034
    1945         // Let plugins try and validate other types of files
    1946         // Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename )
     2035        /**
     2036         * Filter to let plugins try and validate other types of files.
     2037         *
     2038         * Should return an array in the style of:
     2039         * `array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename )`
     2040         *
     2041         * @since 3.0.0
     2042         *
     2043         * @param array  $wp_check_filetype_and_ext Array with keys of `ext`, `type` and
     2044         *                                         `proper_filename`.
     2045         * @param string $file                      Full path to the file.
     2046         * @param string $filename                  The name of the file (may differ from $file due to
     2047         *                                          `$file` being in a tmp directory).
     2048         * @param array  $mimes                     Key is the file extension with value as the mime
     2049         *                                          type.
     2050         */
    19472051        return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );
    19482052}
    19492053
    function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { 
    19582062 * @return array Array of mime types keyed by the file extension regex corresponding to those types.
    19592063 */
    19602064function wp_get_mime_types() {
    1961         // Accepted MIME types are set here as PCRE unless provided.
     2065
     2066        /**
     2067         * Filter list of MIME types and file extensions.
     2068         *
     2069         * Accepted MIME types are set here as PCRE unless provided.
     2070         *
     2071         * @since 3.5.0
     2072         *
     2073         * @param array $wp_get_mime_types MIME types keyed by the file extension regex corresponding to those types.
     2074         */
    19622075        return apply_filters( 'mime_types', array(
    19632076        // Image formats
    19642077        'jpg|jpeg|jpe' => 'image/jpeg',
    function get_allowed_mime_types( $user = null ) { 
    20752188        if ( empty( $unfiltered ) )
    20762189                unset( $t['htm|html'] );
    20772190
     2191        /**
     2192         * Filter list of allowed MIME types and file extensions.
     2193         *
     2194         * @since 2.0.0
     2195         *
     2196         * @param array            $t MIME types keyed by the file extension regex corresponding to
     2197         *                         those types. `swf` and `exe` removed from full list. `htm|html` also
     2198         *                         removed depending on `$user` capabilities.
     2199         * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current
     2200         *                         user).
     2201         */
    20782202        return apply_filters( 'upload_mimes', $t, $user );
    20792203}
    20802204
    function wp_nonce_ays( $action ) { 
    21202244 */
    21212245function wp_die( $message = '', $title = '', $args = array() ) {
    21222246        if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
     2247                /**
     2248                 * Filter callback function when in `DOING_AJAX` context during `wp_die()`.
     2249                 *
     2250                 * @since 3.4.0
     2251                 *
     2252                 * @param string $function Callback function name.
     2253                 */
    21232254                $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' );
    21242255        elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
     2256                /**
     2257                 * Filter callback function when in `XMLRPC_REQUEST` context during `wp_die()`.
     2258                 *
     2259                 * @since 3.4.0
     2260                 *
     2261                 * @param string $function Callback function name.
     2262                 */
    21252263                $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' );
    21262264        else
     2265                /**
     2266                 * Filter callback function when not in `DOING_AJAX` or `XMLRPC_REQUEST` contexts during
     2267                 * `wp_die()`.
     2268                 *
     2269                 * @since 3.0.0
     2270                 *
     2271                 * @param string $function Callback function name.
     2272                 */
    21272273                $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' );
    21282274
    21292275        call_user_func( $function, $message, $title, $args );
    function wp_list_pluck( $list, $field ) { 
    27462892 * @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value.
    27472893 */
    27482894function wp_maybe_load_widgets() {
     2895        /**
     2896         * Filter if Widgets library should be loaded.
     2897         *
     2898         * @since 2.8.0
     2899         *
     2900         * @param bool $wp_maybe_load_widgets Default is true.
     2901         */
    27492902        if ( ! apply_filters('load_default_widgets', true) )
    27502903                return;
    27512904        require_once( ABSPATH . WPINC . '/default-widgets.php' );
    function url_is_accessable_via_ssl($url) 
    29053058 */
    29063059function _deprecated_function( $function, $version, $replacement = null ) {
    29073060
     3061        /**
     3062         * Fires when a function is marked as deprecated.
     3063         *
     3064         * @since 2.5.0
     3065         *
     3066         * @param string $function    The function that was called.
     3067         * @param string $replacement The function that should have been called.
     3068         * @param string $version     The version of WordPress that deprecated the function.
     3069         */
    29083070        do_action( 'deprecated_function_run', $function, $replacement, $version );
    29093071
    2910         // Allow plugin to filter the output error trigger
     3072        /**
     3073         * Filter the deprecated function output error trigger.
     3074         *
     3075         * Allows plugins to override if just the `WP_DEBUG` being true is sufficient to trigger the
     3076         * error.
     3077         *
     3078         * @since 2.5.0
     3079         *
     3080         * @param bool $deprecated_function_trigger_error Default is true.
     3081         */
    29113082        if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
    29123083                if ( function_exists( '__' ) ) {
    29133084                        if ( ! is_null( $replacement ) )
    function _deprecated_function( $function, $version, $replacement = null ) { 
    29493120 */
    29503121function _deprecated_file( $file, $version, $replacement = null, $message = '' ) {
    29513122
     3123        /**
     3124         * Fires when a file is marked as deprecated.
     3125         *
     3126         * @since 2.5.0
     3127         *
     3128         * @param string $file        The file that was called.
     3129         * @param string $replacement The file that should have been included based on ABSPATH.
     3130         * @param string $version     The version of WordPress that deprecated the file.
     3131         * @param string $message     A message regarding the change.
     3132         */
    29523133        do_action( 'deprecated_file_included', $file, $replacement, $version, $message );
    29533134
    2954         // Allow plugin to filter the output error trigger
     3135        /**
     3136         * Filter the deprecated file output error trigger.
     3137         *
     3138         * Allows plugins to override if just the `WP_DEBUG` being true is sufficient to trigger the
     3139         * error.
     3140         *
     3141         * @since 2.5.0
     3142         *
     3143         * @param bool $deprecated_file_trigger_error Default is true.
     3144         */
    29553145        if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) {
    29563146                $message = empty( $message ) ? '' : ' ' . $message;
    29573147                if ( function_exists( '__' ) ) {
    function _deprecated_file( $file, $version, $replacement = null, $message = '' ) 
    29993189 */
    30003190function _deprecated_argument( $function, $version, $message = null ) {
    30013191
     3192        /**
     3193         * Fires when an argument is marked as deprecated.
     3194         *
     3195         * @since 3.0.0
     3196         *
     3197         * @param string $function The function that was called.
     3198         * @param string $message  A message regarding the change.
     3199         * @param string $version  The version of WordPress that deprecated the argument used.
     3200         */
    30023201        do_action( 'deprecated_argument_run', $function, $message, $version );
    30033202
    3004         // Allow plugin to filter the output error trigger
     3203        /**
     3204         * Filter the deprecated argument output error trigger.
     3205         *
     3206         * Allows plugins to override if just the `WP_DEBUG` being true is sufficient to trigger the
     3207         * error.
     3208         *
     3209         * @since 3.0.0
     3210         *
     3211         * @param bool $deprecated_argument_trigger_error Default is true.
     3212         */
    30053213        if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
    30063214                if ( function_exists( '__' ) ) {
    30073215                        if ( ! is_null( $message ) )
    function _deprecated_argument( $function, $version, $message = null ) { 
    30393247 */
    30403248function _doing_it_wrong( $function, $message, $version ) {
    30413249
     3250        /**
     3251         * Fires when something is marked as being called incorrectly.
     3252         *
     3253         * @since 3.1.0
     3254         *
     3255         * @param string $function The function that was called.
     3256         * @param string $message  A message explaining what has been done incorrectly.
     3257         * @param string $version  The version of WordPress where the message was added.
     3258         */
    30423259        do_action( 'doing_it_wrong_run', $function, $message, $version );
    30433260
    3044         // Allow plugin to filter the output error trigger
     3261        /**
     3262         * Filter the "doing it wrong" output error trigger.
     3263         *
     3264         * Allows plugins to override if just the `WP_DEBUG` being true is sufficient to trigger the
     3265         * error.
     3266         *
     3267         * @since 3.1.0
     3268         *
     3269         * @param bool $doing_it_wrong_trigger_error Default is true.
     3270         */
    30453271        if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) {
    30463272                if ( function_exists( '__' ) ) {
    30473273                        $version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version );
    function iis7_supports_permalinks() { 
    31213347                $supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' );
    31223348        }
    31233349
     3350        /**
     3351         * Filter if IIS 7+ supports pretty permalinks.
     3352     *
     3353         * @since 2.8.0
     3354         *
     3355         * @param bool $iis7_supports_permalinks True if permalinks are supported, false otherwise.
     3356         */
    31243357        return apply_filters('iis7_supports_permalinks', $supports_permalinks);
    31253358}
    31263359
    function global_terms_enabled() { 
    33783611
    33793612        static $global_terms = null;
    33803613        if ( is_null( $global_terms ) ) {
     3614
     3615                /**
     3616                 * Filter to short circuit whether global terms are enabled.
     3617                 *
     3618                 * @since 3.0.0
     3619                 *
     3620                 * @param null $global_terms_enabled Expects a filter to return a truthy or falsy value.
     3621                 */
    33813622                $filter = apply_filters( 'global_terms_enabled', null );
    33823623                if ( ! is_null( $filter ) )
    33833624                        $global_terms = (bool) $filter;
    function get_file_data( $file, $default_headers, $context = '' ) { 
    36733914        // Make sure we catch CR-only line endings.
    36743915        $file_data = str_replace( "\r", "\n", $file_data );
    36753916
     3917        /**
     3918         * Filter extra file headers by context.
     3919         *
     3920         * The dynamic part of the hook, `$context`, comes directly from the `$context` function
     3921         * argument. If the value is the default empty string, this filter will not be called.
     3922         *
     3923         * @since 2.9.0
     3924         *
     3925         * @param array $extra_context_headers Empty array by default.
     3926         */
    36763927        if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) {
    36773928                $extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values
    36783929                $all_headers = array_merge( $extra_headers, (array) $default_headers );
    function wp_allowed_protocols() { 
    38944145
    38954146        if ( empty( $protocols ) ) {
    38964147                $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp' );
     4148                /**
     4149                 * Filter the list of protocols allowed in HTML atributes.
     4150                 *
     4151                 * @since 3.0.0
     4152                 *
     4153                 * @param array $protocols Array of allowed protocols e.g. `http`, `ftp`, `tel` and more.
     4154                 */
    38974155                $protocols = apply_filters( 'kses_allowed_protocols', $protocols );
    38984156        }
    38994157
    function wp_auth_check_html() { 
    40584316        if ( $same_domain && force_ssl_login() && ! force_ssl_admin() )
    40594317                $same_domain = false;
    40604318
    4061         // Let plugins change this if they know better.
     4319        /**
     4320         * Filter the auth check same domain.
     4321         *
     4322         * @since 3.6.0
     4323         *
     4324         * @param bool $same_domain True if current domain matches login URL domain. If force SSL login
     4325         *                          is true and force SSL admin is false, this value becomes false.
     4326         */
    40624327        $same_domain = apply_filters( 'wp_auth_check_same_domain', $same_domain );
    40634328        $wrap_class = $same_domain ? 'hidden' : 'hidden fallback';
    40644329