Make WordPress Core

Ticket #37082: 0003-Remove-unnecessary-use-of-create_function-in-PO-prep.patch

File 0003-Remove-unnecessary-use-of-create_function-in-PO-prep.patch, 1.2 KB (added by sgolemon, 8 years ago)

0003-Remove-unnecessary-use-of-create_function-in-PO-prep.patch

  • wp-includes/pomo/po.php

    diff --git wp-includes/pomo/po.php wp-includes/pomo/po.php
    index f9b1623..52dc23b 100644
    class PO extends Gettext_Translations { 
    167167         * @param string $with prepend lines with this string
    168168         */
    169169        public static function prepend_each_line($string, $with) {
    170                 $php_with = var_export($with, true);
    171170                $lines = explode("\n", $string);
    172                 // do not prepend the string on the last empty line, artefact by explode
    173                 if ("\n" == substr($string, -1)) unset($lines[count($lines) - 1]);
    174                 $res = implode("\n", array_map(create_function('$x', "return $php_with.\$x;"), $lines));
    175                 // give back the empty line, we ignored above
    176                 if ("\n" == substr($string, -1)) $res .= "\n";
    177                 return $res;
     171                $append = '';
     172                if ( '' === end($lines) ) {
     173                        // Last line might be empty because $string was terminated
     174                        // with a newline, remove it from the $lines array,
     175                        // we'll restore state by re-terminating the string at the end
     176                        array_pop($lines);
     177                        $append = "\n";
     178                }
     179                foreach ( $lines as &$line ) {
     180                        $line = $with . $line;
     181                }
     182                unset($line);
     183                return implode("\n", $lines) . $append;
    178184        }
    179185
    180186        /**