Make WordPress Core

Ticket #14424: wp-create-function-changes.diff

File wp-create-function-changes.diff, 21.2 KB (added by ScottMac, 13 years ago)
  • wp-includes/post-template.php

     
    171171        echo $content;
    172172}
    173173
     174function _convert_urlencoded_to_entities($match) {
     175  return '&#' . base_convert($match[1], 16, 10) . ';';
     176}
     177
    174178/**
    175179 * Retrieve the post content.
    176180 *
     
    225229
    226230        }
    227231        if ( $preview ) // preview fix for javascript bug with foreign languages
    228                 $output =       preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
     232                $output =       preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
    229233
    230234        return $output;
    231235}
  • wp-includes/pomo/mo.php

     
    3030        function export_to_file($filename) {
    3131                $fh = fopen($filename, 'wb');
    3232                if ( !$fh ) return false;
    33                 $entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);'));
     33                $entries = array();
     34                foreach ($this->entries AS $entry_key => $e) {
     35                  if ( empty($e->translations) )
     36                    continue;
     37
     38                  $entries[$entry_key] = $e;
     39          }
    3440                ksort($entries);
    3541                $magic = 0x950412de;
    3642                $revision = 0;
  • wp-includes/pomo/po.php

     
    151151                $lines = explode("\n", $string);
    152152                // do not prepend the string on the last empty line, artefact by explode
    153153                if ("\n" == substr($string, -1)) unset($lines[count($lines) - 1]);
    154                 $res = implode("\n", array_map(create_function('$x', "return $php_with.\$x;"), $lines));
     154                foreach ($lines AS $line => $x) {
     155                  $lines[$line] = $php_with . $x;
     156          }
     157          $res = implode("\n", $lines);
    155158                // give back the empty line, we ignored above
    156159                if ("\n" == substr($string, -1)) $res .= "\n";
    157160                return $res;
     
    218221                return $res !== false;
    219222        }
    220223
     224        function _is_context_final($context) {
     225                return $context == "msgstr" || $context == "msgstr_plural";
     226        }
     227
    221228        function read_entry($f, $lineno = 0) {
    222229                $entry = new Translation_Entry();
    223230                // where were we in the last step
    224231                // can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural
    225232                $context = '';
    226233                $msgstr_index = 0;
    227                 $is_final = create_function('$context', 'return $context == "msgstr" || $context == "msgstr_plural";');
    228234                while (true) {
    229235                        $lineno++;
    230236                        $line = PO::read_line($f);
    231237                        if (!$line)  {
    232238                                if (feof($f)) {
    233                                         if ($is_final($context))
     239                                        if ($this->_is_context_final($context))
    234240                                                break;
    235241                                        elseif (!$context) // we haven't read a line and eof came
    236242                                                return null;
     
    244250                        $line = trim($line);
    245251                        if (preg_match('/^#/', $line, $m)) {
    246252                                // the comment is the start of a new entry
    247                                 if ($is_final($context)) {
     253                                if ($this->_is_context_final($context)) {
    248254                                        PO::read_line($f, 'put-back');
    249255                                        $lineno--;
    250256                                        break;
     
    256262                                // add comment
    257263                                $this->add_comment_to_entry($entry, $line);
    258264                        } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) {
    259                                 if ($is_final($context)) {
     265                                if ($this->_is_context_final($context)) {
    260266                                        PO::read_line($f, 'put-back');
    261267                                        $lineno--;
    262268                                        break;
     
    267273                                $context = 'msgctxt';
    268274                                $entry->context .= PO::unpoify($m[1]);
    269275                        } elseif (preg_match('/^msgid\s+(".*")/', $line, $m)) {
    270                                 if ($is_final($context)) {
     276                                if ($this->_is_context_final($context)) {
    271277                                        PO::read_line($f, 'put-back');
    272278                                        $lineno--;
    273279                                        break;
     
    317323                                return false;
    318324                        }
    319325                }
    320                 if (array() == array_filter($entry->translations, create_function('$t', 'return $t || "0" === $t;'))) {
     326
     327                $array_has_values = false;
     328                foreach ($this->translations AS $t) {
     329                        if ($t || "0" === $t ) {
     330                                $array_has_values = true;
     331                                break;
     332                        }
     333                }
     334                if (!$array_has_values) {
    321335                        $entry->translations = array();
    322336                }
    323337                return array('entry' => $entry, 'lineno' => $lineno);
  • wp-includes/pomo/translations.php

     
    120120         */
    121121        function gettext_select_plural_form($count) {
    122122                if (!isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) {
    123                         list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms'));
     123                        list( $nplurals, $expression_cb ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms'));
    124124                        $this->_nplurals = $nplurals;
    125                         $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression);
     125                        $this->_gettext_select_plural_form = $expression_cb;
    126126                }
    127127                return call_user_func($this->_gettext_select_plural_form, $count);
    128128        }
    129129
     130        function _gettext_default_plural_cb($n) {
     131                $index = (int)($n != 1);
     132                return ($index < 2 ? $index : 2 - 1);
     133        }
     134
    130135        function nplurals_and_expression_from_header($header) {
    131136                if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) {
    132137                        $nplurals = (int)$matches[1];
    133138                        $expression = trim($this->parenthesize_plural_exression($matches[2]));
    134                         return array($nplurals, $expression);
     139                        return array($nplurals, $this->make_plural_form_function($nplurals, $expression));
    135140                } else {
    136                         return array(2, 'n != 1');
     141                        return array(2, array($this, '_gettext_default_plural_cb'));
    137142                }
    138143        }
    139144
     
    197202        function set_header($header, $value) {
    198203                parent::set_header($header, $value);
    199204                if ('Plural-Forms' == $header) {
    200                         list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms'));
     205                        list( $nplurals, $expression_cb ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms'));
    201206                        $this->_nplurals = $nplurals;
    202                         $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression);
     207                        $this->_gettext_select_plural_form = $expression_cb;
    203208                }
    204209        }
    205210}
  • wp-includes/post.php

     
    971971
    972972        if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
    973973                $object->labels['singular_name'] = $object->labels['name'];
     974       
     975        foreach ( $nohier_vs_hier_defaults AS $key => $value ) {
     976                if ( $object->hierarchical ) {
     977                        $defaults[$key] = $value[1];
     978                } else {
     979                        $defaults[$key] = $value[0];
     980                }
     981        }
    974982
    975         $defaults = array_map( create_function( '$x', $object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults );
    976983        $labels = array_merge( $defaults, $object->labels );
    977984        return (object)$labels;
    978985}
  • wp-includes/formatting.php

     
    164164        return $text;
    165165}
    166166
     167function _preserve_newlines_callback($matches) {
     168        return str_replace("\n", "<WPPreserveNewline />", $matches[0]);
     169}
     170
    167171/**
    168172 * Replaces double line-breaks with paragraph elements.
    169173 *
     
    208212        $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
    209213        $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
    210214        if ($br) {
    211                 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);
     215                $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_preserve_newlines_callback', $pee);
    212216                $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
    213217                $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
    214218        }
     
    15381542        return apply_filters( 'is_email', $email, $email, null );
    15391543}
    15401544
     1545function _wp_iso_unquote($match) {
     1546        return chr(hexdec(strtolower($match[1])));
     1547}
     1548
    15411549/**
    15421550 * Convert to ASCII from email subjects.
    15431551 *
     
    15531561                return $string;
    15541562        } else {
    15551563                $subject = str_replace('_', ' ', $matches[2]);
    1556                 $subject = preg_replace_callback('#\=([0-9a-f]{2})#i', create_function('$match', 'return chr(hexdec(strtolower($match[1])));'), $subject);
     1564                $subject = preg_replace_callback('#\=([0-9a-f]{2})#i', '_wp_iso_unquote', $subject);
    15571565                return $subject;
    15581566        }
    15591567}
     
    26742682        return $str;
    26752683}
    26762684
     2685function _links_add_base_with_param($m) {
     2686        global $wp_formatting_base_cb;
     2687        return _links_add_base($m, $wp_formatting_base_cb);
     2688}
     2689
    26772690/**
    26782691 * Add a Base url to relative links in passed content.
    26792692 *
     
    26882701 * @return string The processed content.
    26892702 */
    26902703function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) {
     2704        global $wp_formatting_base_cb;
    26912705        $attrs = implode('|', (array)$attrs);
    2692         return preg_replace_callback("!($attrs)=(['\"])(.+?)\\2!i",
    2693                         create_function('$m', 'return _links_add_base($m, "' . $base . '");'),
     2706        $wp_formatting_base_cb = $base;
     2707        return preg_replace_callback("!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base_with_param',
    26942708                        $content);
    26952709}
    26962710
     
    27132727                . $m[2];
    27142728}
    27152729
     2730function _links_add_target_with_param($m) {
     2731        global $wp_formatting_target_cb;
     2732        return _links_add_target($m, $wp_formatting_target_cb);
     2733}
     2734
    27162735/**
    27172736 * Adds a Target attribute to all links in passed content.
    27182737 *
     
    27292748 * @return string The processed content.
    27302749 */
    27312750function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
     2751        global $wp_formatting_target_cb;
    27322752        $tags = implode('|', (array)$tags);
    2733         return preg_replace_callback("!<($tags)(.+?)>!i",
    2734                         create_function('$m', 'return _links_add_target($m, "' . $target . '");'),
     2753        $wp_formatting_target_cb = $target;
     2754        return preg_replace_callback("!<($tags)(.+?)>!i", '_links_add_target_with_param',
    27352755                        $content);
    27362756}
    27372757
  • wp-includes/atomlib.php

     
    9191
    9292        $this->feed = new AtomFeed();
    9393        $this->current = null;
    94         $this->map_attrs_func = create_function('$k,$v', 'return "$k=\"$v\"";');
    95         $this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');
     94        $this->map_attrs_func = array('AtomParser', 'map_attrs_func');
     95        $this->map_xmlns_func = array('AtomParser', 'map_xmlns_func');
    9696    }
    9797
     98    function map_attrs_func($k, $v) {
     99      return "$k=\"$v\"";
     100    }
     101   
     102    function map_xmlns_func($p, $n) {
     103      $xd = 'xmlns';
     104      if (strlen($n[0]) > 0) {
     105        $xd .= ":{$n[0]}";
     106      }
     107      return "{$xd}=\"{$n[1]}\"";
     108    }
     109
    98110    function _p($msg) {
    99111        if($this->debug) {
    100112            print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n";
  • wp-includes/kses.php

     
    530530        return '0.2.2';
    531531}
    532532
     533function _wp_kses_split_callback($match) {
     534  global $pass_allowed_html, $pass_allowed_protocols;
     535  return wp_kses_split2($match[1], $pass_allowed_html, $pass_allowed_protocols);
     536}
     537
    533538/**
    534539 * Searches for HTML tags, no matter how malformed.
    535540 *
     
    546551        global $pass_allowed_html, $pass_allowed_protocols;
    547552        $pass_allowed_html = $allowed_html;
    548553        $pass_allowed_protocols = $allowed_protocols;
    549         return preg_replace_callback('%((<!--.*?(-->|$))|(<[^>]*(>|$)|>))%',
    550                 create_function('$match', 'global $pass_allowed_html, $pass_allowed_protocols; return wp_kses_split2($match[1], $pass_allowed_html, $pass_allowed_protocols);'), $string);
     554        return preg_replace_callback('%((<!--.*?(-->|$))|(<[^>]*(>|$)|>))%', '_wp_kses_split_callback', $string);
    551555}
    552556
    553557/**
  • wp-includes/category-template.php

     
    612612        return round(log10($count + 1) * 100);
    613613}
    614614
     615/**
     616 * Callback for comparing tags based on name
     617 *
     618 * @param object a tag object to be compared
     619 * @param object a tag object to be compared
     620 * @return integer -1 for less than, 0 for the same and 1 for greater
     621 */
     622function _wp_tag_cloud_name_sort_cb($a, $b) {
     623        return strnatcasecmp($a->name, $b->name);
     624}
    615625
    616626/**
     627 * Callback for comparing tags based on count
     628 *
     629 * @param object a tag object to be compared
     630 * @param object a tag object to be compared
     631 * @return integer -1 for less than, 0 for the same and 1 for greater
     632 */
     633function _wp_tag_cloud_count_sort_cb($a, $b) {
     634        return ($a->count > $b->count);
     635}
     636
     637class _tag_clound_topic_count_text_callback {
     638        var $single_text;
     639        var $multiple_text;
     640        function _callback($count) {
     641                return sprintf( _n( $this->single_text, $this->multiple_text, $count ), number_format_i18n( $count ) );
     642        }
     643}
     644
     645/**
    617646 * Generates a tag cloud (heatmap) from provided data.
    618647 *
    619648 * The text size is set by the 'smallest' and 'largest' arguments, which will
     
    654683        );
    655684
    656685        if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
    657                 $body = 'return sprintf (
    658                         _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
    659                         number_format_i18n( $count ));';
    660                 $args['topic_count_text_callback'] = create_function('$count', $body);
     686                $callback = new _tag_clound_topic_count_text_callback();
     687                $callback->single_text = $args['single_text'];
     688                $callback->multiple_text = $args['multiple_text'];
     689                $args['topic_count_text_callback'] = array($callback, '_callback');
    661690        }
    662691
    663692        $args = wp_parse_args( $args, $defaults );
     
    676705                } else {
    677706                        // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
    678707                        if ( 'name' == $orderby )
    679                                 uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
     708                                uasort( $tags, '_wp_tag_cloud_name_sort_cb' );
    680709                        else
    681                                 uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
     710                                uasort( $tags, '_wp_tag_cloud_count_sort_cb' );
    682711
    683712                        if ( 'DESC' == $order )
    684713                                $tags = array_reverse( $tags, true );
     
    712741                $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
    713742                $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
    714743                $tag_name = $tags[ $key ]->name;
    715                 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $real_count ) ) . "' style='font-size: " .
     744                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count ) ) . "' style='font-size: " .
    716745                        ( $smallest + ( ( $count - $min_count ) * $font_step ) )
    717746                        . "$unit;'>$tag_name</a>";
    718747        }
  • wp-admin/includes/plugin.php

     
    183183        return $plugin_files;
    184184}
    185185
     186function _plugin_sort_callback($a, $b) {
     187        return strnatcasecmp( $a['Name'], $b['Name'] );
     188}
     189
    186190/**
    187191 * Check the plugins directory and retrieve all plugin files with plugin data.
    188192 *
     
    260264                $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;
    261265        }
    262266
    263         uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
     267        uasort( $wp_plugins, '_plugin_sort_callback');
    264268
    265269        $cache_plugins[ $plugin_folder ] = $wp_plugins;
    266270        wp_cache_set('plugins', $cache_plugins, 'plugins');
     
    312316        if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden
    313317                unset( $wp_plugins['index.php'] );
    314318
    315         uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
     319        uasort( $wp_plugins, '_plugin_sort_callback');
    316320
    317321        return $wp_plugins;
    318322}
     
    353357                $dropins[ $plugin_file ] = $plugin_data;
    354358        }
    355359
    356         uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' ));
     360        uksort( $dropins, 'strnatcasecmp');
    357361
    358362        return $dropins;
    359363}
     
    401405}
    402406
    403407/**
     408 * Check whether the plugin is not active by checking the active_plugins list.
     409 *
     410 * @since 3.0.0
     411 *
     412 * @param string $plugin Base plugin path from plugins directory.
     413 * @return bool True, if not in the active plugins list. False, if in the list.
     414 */
     415function is_plugin_not_active( $plugin ) {
     416        return !is_plugin_active( $plugin );
     417}
     418
     419/**
    404420 * Check whether the plugin is active for the entire network.
    405421 *
    406422 * @since 3.0.0
  • wp-admin/includes/widgets.php

     
    66 * @subpackage Administration
    77 */
    88
     9function _sort_widgets_cb($a, $b) {
     10        return strnatcasecmp( $a["name"], $b["name"] );
     11}
     12
    913/**
    1014 * Display list of the available widgets, either all or matching search.
    1115 *
     
    2024        global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
    2125
    2226        $sort = $wp_registered_widgets;
    23         usort( $sort, create_function( '$a, $b', 'return strnatcasecmp( $a["name"], $b["name"] );' ) );
     27        usort( $sort, '_sort_widgets_cb' );
    2428        $done = array();
    2529
    2630        foreach ( $sort as $widget ) {
  • wp-admin/includes/import.php

     
    66 * @subpackage Administration
    77 */
    88
     9function _sort_importers_callback($a, $b) {
     10        return strcmp($a[0], $b[0]);
     11}
     12
    913/**
    1014 * Retrieve list of importers.
    1115 *
     
    1620function get_importers() {
    1721        global $wp_importers;
    1822        if ( is_array($wp_importers) )
    19                 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
     23                uasort($wp_importers, '_sort_importers_callback');
    2024        return $wp_importers;
    2125}
    2226
  • wp-admin/includes/media.php

     
    18371837<?php
    18381838}
    18391839
     1840class _media_post_limits_filter {
     1841        var $start = 0;
     1842        function _callback($a) {
     1843                return 'LIMIT ' . $this->start . ', 10';
     1844        }
     1845}
     1846
    18401847/**
    18411848 * {@internal Missing Short Description}}
    18421849 *
     
    18601867        $start = ( $_GET['paged'] - 1 ) * 10;
    18611868        if ( $start < 1 )
    18621869                $start = 0;
    1863         add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );
     1870        $filter = new _media_post_limits_filter();
     1871        $filter->start = $start;
    18641872
     1873        add_filter( 'post_limits', array($filter, '_callback') );
     1874
    18651875        list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
    18661876
    18671877?>
  • wp-admin/plugins.php

     
    9090                        check_admin_referer('bulk-manage-plugins');
    9191
    9292                        $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    93                         $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); // Only activate plugins which are not already active.
     93                        $plugins = array_filter($plugins, 'is_plugin_not_active' ); // Only activate plugins which are not already active.
    9494                        if ( empty($plugins) ) {
    9595                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
    9696                                exit;
     
    207207
    208208                        //$_POST = from the plugin form; $_GET = from the FTP details screen.
    209209                        $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
    210                         $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
     210                        $plugins = array_filter($plugins, 'is_plugin_not_active' ); //Do not allow to delete Activated plugins.
    211211                        if ( empty($plugins) ) {
    212212                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
    213213                                exit;
  • wp-admin/widgets.php

     
    2323        set_user_setting( 'widgets_access', $widgets_access );
    2424}
    2525
     26function _widget_filter_access_cb() {
     27        return ' widgets_access ';
     28}
     29
    2630if ( 'on' == $widgets_access )
    27         add_filter( 'admin_body_class', create_function('', '{return " widgets_access ";}') );
     31        add_filter( 'admin_body_class', '_widget_filter_access_cb' );
    2832else
    2933        wp_enqueue_script('admin-widgets');
    3034
  • wp-admin/import.php

     
    8686if (empty ($importers)) {
    8787        echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful
    8888} else {
    89         uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
     89        uasort($importers, '_sort_importers_callback');
    9090?>
    9191<table class="widefat" cellspacing="0">
    9292