From 5f4a583fb1ab89a7e8324dfe2e1eec998fa0c780 Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 11 Nov 2010 22:50:36 +0000 Subject: [PATCH] Remove more create_function calls. props huichen, see #14424. git-svn-id: http://svn.automattic.com/wordpress/trunk@16313 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 16 +++++++++++++--- wp-admin/includes/widgets.php | 12 +++++++++++- wp-includes/category-template.php | 22 +++++++++++++++++++++- wp-includes/formatting.php | 8 ++++---- wp-includes/kses.php | 14 ++++++++++++-- wp-includes/post-template.php | 6 +++--- wp-includes/post.php | 4 +++- 7 files changed, 67 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 90b835fb7a..2e75fb5c2c 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -260,7 +260,7 @@ function get_plugins($plugin_folder = '') { $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; } - uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); + uasort( $wp_plugins, '_sort_uname_callback' ); $cache_plugins[ $plugin_folder ] = $wp_plugins; wp_cache_set('plugins', $cache_plugins, 'plugins'); @@ -312,11 +312,21 @@ function get_mu_plugins() { if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden unset( $wp_plugins['index.php'] ); - uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); + uasort( $wp_plugins, '_sort_uname_callback' ); return $wp_plugins; } +/** + * Callback to sort array by a 'Name' key. + * + * @since 3.1.0 + * @access private + */ +function _sort_uname_callback( $a, $b ) { + return strnatcasecmp( $a['Name'], $b['Name'] ); +} + /** * Check the wp-content directory and retrieve all drop-ins with any plugin data. * @@ -353,7 +363,7 @@ function get_dropins() { $dropins[ $plugin_file ] = $plugin_data; } - uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' )); + uksort( $dropins, 'strnatcasecmp' ); return $dropins; } diff --git a/wp-admin/includes/widgets.php b/wp-admin/includes/widgets.php index 447ee46d43..b332b05a52 100644 --- a/wp-admin/includes/widgets.php +++ b/wp-admin/includes/widgets.php @@ -15,7 +15,7 @@ function wp_list_widgets() { global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls; $sort = $wp_registered_widgets; - usort( $sort, create_function( '$a, $b', 'return strnatcasecmp( $a["name"], $b["name"] );' ) ); + usort( $sort, '_sort_name_callback' ); $done = array(); foreach ( $sort as $widget ) { @@ -46,6 +46,16 @@ function wp_list_widgets() { } } +/** + * Callback to sort array by a 'name' key. + * + * @since 3.1.0 + * @access private + */ +function _sort_name_callback( $a, $b ) { + return strnatcasecmp( $a['name'], $b['name'] ); +} + /** * Show the widgets and their settings for a sidebar. * Used in the the admin widget config screen. diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index d2e6dceaae..94753a1dc7 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -677,7 +677,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#'; $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; $tag_name = $tags[ $key ]->name; - $a[] = "$tag_name"; } @@ -702,6 +702,26 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { return $return; } +/** + * Callback for comparing tags based on name + * + * @since 3.1.0 + * @access private + */ +function _wp_tag_cloud_name_sort_cb( $a, $b ) { + return strnatcasecmp( $a->name, $b->name ); +} + +/** + * Callback for comparing tags based on count + * + * @since 3.1.0 + * @access private + */ +function _wp_tag_cloud_count_sort_cb( $a, $b ) { + return ( $a->count > $b->count ); +} + // // Helper functions // diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index d15d744c1a..880f2c4d57 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -236,7 +236,7 @@ function wpautop($pee, $br = 1) { $pee = preg_replace('!

\s*(]*>)!', "$1", $pee); $pee = preg_replace('!(]*>)\s*

!', "$1", $pee); if ($br) { - $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '__autop_newline_preservation_helper', $pee); + $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks $pee = str_replace('', "\n", $pee); } @@ -257,7 +257,7 @@ function wpautop($pee, $br = 1) { * @param array $matches preg_replace_callback matches array * @returns string */ -function __autop_newline_preservation_helper( $matches ) { +function _autop_newline_preservation_helper( $matches ) { return str_replace("\n", "", $matches[0]); } @@ -1595,7 +1595,7 @@ function wp_iso_descrambler($string) { return $string; } else { $subject = str_replace('_', ' ', $matches[2]); - $subject = preg_replace_callback('#\=([0-9a-f]{2})#i', '__wp_iso_convert', $subject); + $subject = preg_replace_callback('#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject); return $subject; } } @@ -1607,7 +1607,7 @@ function wp_iso_descrambler($string) { * @access private * @param $match the preg_replace_callback matches array */ -function __wp_iso_convert( $match ) { +function _wp_iso_convert( $match ) { return chr( hexdec( strtolower( $match[1] ) ) ); } diff --git a/wp-includes/kses.php b/wp-includes/kses.php index 4a0a67901c..b04bacea83 100644 --- a/wp-includes/kses.php +++ b/wp-includes/kses.php @@ -546,8 +546,18 @@ function wp_kses_split($string, $allowed_html, $allowed_protocols) { global $pass_allowed_html, $pass_allowed_protocols; $pass_allowed_html = $allowed_html; $pass_allowed_protocols = $allowed_protocols; - return preg_replace_callback('%((|$))|(<[^>]*(>|$)|>))%', - create_function('$match', 'global $pass_allowed_html, $pass_allowed_protocols; return wp_kses_split2($match[1], $pass_allowed_html, $pass_allowed_protocols);'), $string); + return preg_replace_callback( '%((|$))|(<[^>]*(>|$)|>))%', '_wp_kses_split_callback', $string ); +} + +/** + * Callback for wp_kses_split. + * + * @since 3.1.0 + * @access private + */ +function _wp_kses_split_callback( $match ) { + global $pass_allowed_html, $pass_allowed_protocols; + return wp_kses_split2( $match[1], $pass_allowed_html, $pass_allowed_protocols ); } /** diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 6f1a24bbd2..5642d931bb 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -223,7 +223,7 @@ function get_the_content($more_link_text = null, $stripteaser = 0) { } if ( $preview ) // preview fix for javascript bug with foreign languages - $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '__convert_urlencoded_to_entities', $output); + $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output); return $output; } @@ -236,8 +236,8 @@ function get_the_content($more_link_text = null, $stripteaser = 0) { * @param array $match Match array from preg_replace_callback * @returns string */ -function __convert_urlencoded_to_entities($match) { - return '&#' . base_convert($match[1], 16, 10) . ';'; +function _convert_urlencoded_to_entities( $match ) { + return '&#' . base_convert( $match[1], 16, 10 ) . ';'; } /** diff --git a/wp-includes/post.php b/wp-includes/post.php index 8920dc10e4..a7fd0b63b5 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1162,7 +1162,9 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) $object->labels['menu_name'] = $object->labels['name']; - $defaults = array_map( create_function( '$x', $object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults ); + foreach ( $nohier_vs_hier_defaults as $key => $value ) + $defaults[$key] = $object->hierarchical ? $value[1] : $value[0]; + $labels = array_merge( $defaults, $object->labels ); return (object)$labels; }