Make WordPress Core

Ticket #8505: alt_fix_using_static.patch

File alt_fix_using_static.patch, 2.0 KB (added by sambauers, 17 years ago)

Alternative to patch by azaozz using a simple static variable attached

  • class.wp-scripts.php

     
    4040                if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) )
    4141                        return false;
    4242
     43                static $printed_once = false;
     44
    4345                $object_name = $this->registered[$handle]->extra['l10n'][0];
    4446
    4547                echo "<script type='text/javascript'>\n";
    4648                echo "/* <![CDATA[ */\n";
    47                 echo "function convertEntities(o) {\n";
    48                 echo "  var c = function(s) {\n";
    49                 echo "          if (/&[^;]+;/.test(s)) {\n";
    50                 echo "                  var e = document.createElement('div');\n";
    51                 echo "                  e.innerHTML = s;\n";
    52                 echo "                  return !e.firstChild ? s : e.firstChild.nodeValue;\n";
    53                 echo "          }\n";
    54                 echo "          return s;\n";
    55                 echo "  }\n";
    56                 echo "  if ( typeof o === 'string' ) {\n";
    57                 echo "          return c(o);\n";
    58                 echo "  } else if ( typeof o === 'object' ) {\n";
    59                 echo "          for (var v in o) {\n";
    60                 echo "                  if ( typeof o[v] === 'string' )\n";
    61                 echo "                          o[v] = c(o[v]);\n";
    62                 echo "          }\n";
    63                 echo "  }\n";
    64                 echo "  return o;\n";
    65                 echo "};\n";
     49
     50                if ( !$printed_once ) {
     51                        echo "function convertEntities(o) {\n";
     52                        echo "  var c = function(s) {\n";
     53                        echo "          if (/&[^;]+;/.test(s)) {\n";
     54                        echo "                  var e = document.createElement('div');\n";
     55                        echo "                  e.innerHTML = s;\n";
     56                        echo "                  return !e.firstChild ? s : e.firstChild.nodeValue;\n";
     57                        echo "          }\n";
     58                        echo "          return s;\n";
     59                        echo "  }\n";
     60                        echo "  if ( typeof o === 'string' ) {\n";
     61                        echo "          return c(o);\n";
     62                        echo "  } else if ( typeof o === 'object' ) {\n";
     63                        echo "          for (var v in o) {\n";
     64                        echo "                  if ( typeof o[v] === 'string' )\n";
     65                        echo "                          o[v] = c(o[v]);\n";
     66                        echo "          }\n";
     67                        echo "  }\n";
     68                        echo "  return o;\n";
     69                        echo "};\n";
     70
     71                        $printed_once = true;
     72                }
     73
    6674                echo "\t$object_name = {\n";
    6775                $eol = '';
    6876                foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) {