From 88a7fe28fe86225f260d572372c02aa2b84f7279 Mon Sep 17 00:00:00 2001 From: ozh Date: Sun, 26 Oct 2014 16:34:41 +0100 Subject: [PATCH] Deprecate yourls_apply_filters (plural). Fixes #1671. --- includes/functions-deprecated.php | 19 +++++++++++++++++++ includes/functions-formatting.php | 10 +++++----- includes/functions-html.php | 16 ++++++++-------- includes/functions-l10n.php | 30 +++++++++++++++--------------- includes/functions-plugins.php | 21 ++------------------- includes/functions.php | 4 ++-- 6 files changed, 51 insertions(+), 49 deletions(-) diff --git a/includes/functions-deprecated.php b/includes/functions-deprecated.php index 71dac61..992aa14 100644 --- a/includes/functions-deprecated.php +++ b/includes/functions-deprecated.php @@ -47,3 +47,22 @@ function yourls_get_remote_content( $url, $maxlen = 4096, $timeout = 5 ) { return yourls_http_get_body( $url ); } +/** + * Alias for yourls_apply_filter because I never remember if it's _filter or _filters + * + * At first I thought it made semantically more sense but thinking about it, I was wrong. It's one filter. + * There may be several function hooked into it, but it still the same one filter. + * + * @since 1.6 + * @deprecated 1.7.1 + * + * @param string $hook the name of the YOURLS element or action + * @param mixed $value the value of the element before filtering + * @return mixed + */ +function yourls_apply_filters( $hook, $value = '' ) { + yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_apply_filter' ); + return yourls_apply_filter( $hook, $value ); +} + + diff --git a/includes/functions-formatting.php b/includes/functions-formatting.php index ea6ddc4..5c5d858 100644 --- a/includes/functions-formatting.php +++ b/includes/functions-formatting.php @@ -162,7 +162,7 @@ function yourls_escape_real( $string ) { return $ydb->escape( $string ); // YOURLS DB classes have been bypassed by a custom DB engine or a custom cache layer - return yourls_apply_filters( 'custom_escape_real', addslashes( $string ), $string ); + return yourls_apply_filter( 'custom_escape_real', addslashes( $string ), $string ); } /** @@ -434,7 +434,7 @@ function yourls_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { function yourls_esc_html( $text ) { $safe_text = yourls_check_invalid_utf8( $text ); $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); - return yourls_apply_filters( 'esc_html', $safe_text, $text ); + return yourls_apply_filter( 'esc_html', $safe_text, $text ); } /** @@ -448,7 +448,7 @@ function yourls_esc_html( $text ) { function yourls_esc_attr( $text ) { $safe_text = yourls_check_invalid_utf8( $text ); $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); - return yourls_apply_filters( 'esc_attr', $safe_text, $text ); + return yourls_apply_filter( 'esc_attr', $safe_text, $text ); } /** @@ -538,7 +538,7 @@ function yourls_esc_js( $text ) { $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); $safe_text = str_replace( "\r", '', $safe_text ); $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); - return yourls_apply_filters( 'esc_js', $safe_text, $text ); + return yourls_apply_filter( 'esc_js', $safe_text, $text ); } /** @@ -551,7 +551,7 @@ function yourls_esc_js( $text ) { */ function yourls_esc_textarea( $text ) { $safe_text = htmlspecialchars( $text, ENT_QUOTES ); - return yourls_apply_filters( 'esc_textarea', $safe_text, $text ); + return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); } diff --git a/includes/functions-html.php b/includes/functions-html.php index db5d38b..ccf15c1 100644 --- a/includes/functions-html.php +++ b/includes/functions-html.php @@ -60,7 +60,7 @@ function yourls_html_head( $context = 'index', $title = '' ) { header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' ); header( 'Cache-Control: no-cache, must-revalidate, max-age=0' ); header( 'Pragma: no-cache' ); - yourls_content_type_header( yourls_apply_filters( 'html_head_content-type', 'text/html' ) ); + yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) ); yourls_do_action( 'admin_headers', $context, $title ); } @@ -83,7 +83,7 @@ function yourls_html_head( $context = 'index', $title = '' ) { <?php echo $title ?> - + @@ -145,7 +145,7 @@ function yourls_html_footer() { YOURLS v ' . YOURLS_VERSION ); $footer .= ' – '.$num_queries; - echo yourls_apply_filters( 'html_footer_text', $footer ); + echo yourls_apply_filter( 'html_footer_text', $footer ); ?>

$text\n"; } $html .= "\n"; - $html = yourls_apply_filters( 'html_select', $html, $name, $options, $selected, $display ); + $html = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display ); if( $display ) echo $html; return $html; @@ -537,7 +537,7 @@ function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $times $protocol_warning = ''; if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) - $protocol_warning = yourls_apply_filters( 'add_row_protocol_warning', '' ); + $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '' ); // Row cells: the array $cells = array( @@ -839,7 +839,7 @@ function yourls_html_language_attributes() { $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' ); - $doctype = yourls_apply_filters( 'html_language_attributes_doctype', 'html' ); + $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' ); // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) { if( $doctype == 'xhtml' ) { @@ -850,7 +850,7 @@ function yourls_html_language_attributes() { } $output = implode( ' ', $attributes ); - $output = yourls_apply_filters( 'html_language_attributes', $output ); + $output = yourls_apply_filter( 'html_language_attributes', $output ); echo $output; } @@ -899,7 +899,7 @@ function yourls_new_core_version_notice() { */ function yourls_content_type_header( $type ) { if( !headers_sent() ) { - $charset = yourls_apply_filters( 'content_type_header_charset', 'utf-8' ); + $charset = yourls_apply_filter( 'content_type_header_charset', 'utf-8' ); header( "Content-Type: $type; charset=$charset" ); return true; } diff --git a/includes/functions-l10n.php b/includes/functions-l10n.php index ac63235..a148dd0 100644 --- a/includes/functions-l10n.php +++ b/includes/functions-l10n.php @@ -29,7 +29,7 @@ * always be filtered using the 'get_locale' hook. * * @since 1.6 - * @uses yourls_apply_filters() Calls 'get_locale' hook on locale value. + * @uses yourls_apply_filter() Calls 'get_locale' hook on locale value. * @uses $yourls_locale Gets the locale stored in the global. * * @return string The locale of the blog or from the 'get_locale' hook. @@ -46,7 +46,7 @@ function yourls_get_locale() { if ( !$yourls_locale ) $yourls_locale = ''; - return yourls_apply_filters( 'get_locale', $yourls_locale ); + return yourls_apply_filter( 'get_locale', $yourls_locale ); } /** @@ -55,7 +55,7 @@ function yourls_get_locale() { * * @see yourls__() Don't use yourls_translate() directly, use yourls__() * @since 1.6 - * @uses yourls_apply_filters() Calls 'translate' on domain translated text + * @uses yourls_apply_filter() Calls 'translate' on domain translated text * with the untranslated text as second parameter. * * @param string $text Text to translate. @@ -64,7 +64,7 @@ function yourls_get_locale() { */ function yourls_translate( $text, $domain = 'default' ) { $translations = yourls_get_translations_for_domain( $domain ); - return yourls_apply_filters( 'translate', $translations->translate( $text ), $text, $domain ); + return yourls_apply_filter( 'translate', $translations->translate( $text ), $text, $domain ); } /** @@ -85,7 +85,7 @@ function yourls_translate( $text, $domain = 'default' ) { */ function yourls_translate_with_context( $text, $context, $domain = 'default' ) { $translations = yourls_get_translations_for_domain( $domain ); - return yourls_apply_filters( 'translate_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); + return yourls_apply_filter( 'translate_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); } /** @@ -326,7 +326,7 @@ function yourls_esc_html_x( $single, $context, $domain = 'default' ) { * * @since 1.6 * @uses $yourls_l10n Gets list of domain translated string (gettext_reader) objects - * @uses yourls_apply_filters() Calls 'translate_n' hook on domains text returned, + * @uses yourls_apply_filter() Calls 'translate_n' hook on domains text returned, * along with $single, $plural, and $number parameters. Expected to return string. * * @param string $single The text that will be used if $number is 1 @@ -338,7 +338,7 @@ function yourls_esc_html_x( $single, $context, $domain = 'default' ) { function yourls_n( $single, $plural, $number, $domain = 'default' ) { $translations = yourls_get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number ); - return yourls_apply_filters( 'translate_n', $translation, $single, $plural, $number, $domain ); + return yourls_apply_filter( 'translate_n', $translation, $single, $plural, $number, $domain ); } /** @@ -352,7 +352,7 @@ function yourls_n( $single, $plural, $number, $domain = 'default' ) { function yourls_nx($single, $plural, $number, $context, $domain = 'default') { $translations = yourls_get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number, $context ); - return yourls_apply_filters( 'translate_nx', $translation, $single, $plural, $number, $context, $domain ); + return yourls_apply_filter( 'translate_nx', $translation, $single, $plural, $number, $context, $domain ); } /** @@ -444,7 +444,7 @@ function yourls_translate_nooped_plural( $nooped_plural, $count, $domain = 'defa function yourls_load_textdomain( $domain, $mofile ) { global $yourls_l10n; - $plugin_override = yourls_apply_filters( 'override_load_textdomain', false, $domain, $mofile ); + $plugin_override = yourls_apply_filter( 'override_load_textdomain', false, $domain, $mofile ); if ( true == $plugin_override ) { return true; @@ -452,7 +452,7 @@ function yourls_load_textdomain( $domain, $mofile ) { yourls_do_action( 'load_textdomain', $domain, $mofile ); - $mofile = yourls_apply_filters( 'load_textdomain_mofile', $mofile, $domain ); + $mofile = yourls_apply_filter( 'load_textdomain_mofile', $mofile, $domain ); if ( !is_readable( $mofile ) ) { trigger_error( 'Cannot read file ' . str_replace( YOURLS_ABSPATH.'/', '', $mofile ) . '.' @@ -482,7 +482,7 @@ function yourls_load_textdomain( $domain, $mofile ) { function yourls_unload_textdomain( $domain ) { global $yourls_l10n; - $plugin_override = yourls_apply_filters( 'override_unload_textdomain', false, $domain ); + $plugin_override = yourls_apply_filter( 'override_unload_textdomain', false, $domain ); if ( $plugin_override ) return true; @@ -571,7 +571,7 @@ function yourls_get_available_languages( $dir = null ) { $languages[] = basename( $lang_file, '.mo' ); } - return yourls_apply_filters( 'get_available_languages', $languages ); + return yourls_apply_filter( 'get_available_languages', $languages ); } /** @@ -589,7 +589,7 @@ function yourls_number_format_i18n( $number, $decimals = 0 ) { $yourls_locale_formats = new YOURLS_Locale_Formats(); $formatted = number_format( $number, abs( intval( $decimals ) ), $yourls_locale_formats->number_format['decimal_point'], $yourls_locale_formats->number_format['thousands_sep'] ); - return yourls_apply_filters( 'number_format_i18n', $formatted ); + return yourls_apply_filter( 'number_format_i18n', $formatted ); } /** @@ -668,7 +668,7 @@ function yourls_date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = fal } $j = @$datefunc( $dateformatstring, $i ); // allow plugins to redo this entirely for languages with untypical grammars - $j = yourls_apply_filters('date_i18n', $j, $req_format, $i, $gmt); + $j = yourls_apply_filter('date_i18n', $j, $req_format, $i, $gmt); return $j; } @@ -1044,7 +1044,7 @@ function is_rtl() { * @return bool True on success, false on failure */ function yourls_load_custom_textdomain( $domain, $path ) { - $locale = yourls_apply_filters( 'load_custom_textdomain', yourls_get_locale(), $domain ); + $locale = yourls_apply_filter( 'load_custom_textdomain', yourls_get_locale(), $domain ); $mofile = trim( $path, '/' ) . '/'. $domain . '-' . $locale . '.mo'; return yourls_load_textdomain( $domain, $mofile ); diff --git a/includes/functions-plugins.php b/includes/functions-plugins.php index 619cbd5..04bc1eb 100644 --- a/includes/functions-plugins.php +++ b/includes/functions-plugins.php @@ -154,23 +154,6 @@ function yourls_apply_filter( $hook, $value = '' ) { return $value; } -/** - * Alias for yourls_apply_filter because I never remember if it's _filter or _filters - * - * Plus, semantically, it makes more sense. There can be several filters. I should have named it - * like this from the very start. Duh. - * - * @since 1.6 - * - * @param string $hook the name of the YOURLS element or action - * @param mixed $value the value of the element before filtering - * @return mixed - */ -function yourls_apply_filters( $hook, $value = '' ) { - return yourls_apply_filter( $hook, $value ); -} - - /** * Performs an action triggered by a YOURLS event. * @@ -565,8 +548,8 @@ function yourls_plugin_admin_page( $plugin_page ) { * @return int 0, 1 or -1, see uasort() */ function yourls_plugins_sort_callback( $plugin_a, $plugin_b ) { - $orderby = yourls_apply_filters( 'plugins_sort_callback', 'Plugin Name' ); - $order = yourls_apply_filters( 'plugins_sort_callback', 'ASC' ); + $orderby = yourls_apply_filter( 'plugins_sort_callback', 'Plugin Name' ); + $order = yourls_apply_filter( 'plugins_sort_callback', 'ASC' ); $a = isset( $plugin_a[ $orderby ] ) ? $plugin_a[ $orderby ] : ''; $b = isset( $plugin_b[ $orderby ] ) ? $plugin_b[ $orderby ] : ''; diff --git a/includes/functions.php b/includes/functions.php index 2b2238e..e92e180 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2142,7 +2142,7 @@ function yourls_get_relative_url( $url, $strict = true ) { * @since 1.6 * @uses yourls_do_action() Calls 'deprecated_function' and passes the function name, what to use instead, * and the version the function was deprecated in. - * @uses yourls_apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do + * @uses yourls_apply_filter() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do * trigger or false to not trigger error. * * @param string $function The function that was called @@ -2154,7 +2154,7 @@ function yourls_deprecated_function( $function, $version, $replacement = null ) yourls_do_action( 'deprecated_function', $function, $replacement, $version ); // Allow plugin to filter the output error trigger - if ( YOURLS_DEBUG && yourls_apply_filters( 'deprecated_function_trigger_error', true ) ) { + if ( YOURLS_DEBUG && yourls_apply_filter( 'deprecated_function_trigger_error', true ) ) { if ( ! is_null( $replacement ) ) trigger_error( sprintf( yourls__('%1$s is deprecated since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); else -- 2.45.0