Make WordPress Core


Ignore:
Timestamp:
12/13/2016 01:48:41 AM (8 years ago)
Author:
rmccue
Message:

General: Remove most uses of create_function()

create_function() is equivalent to eval(), and most of our uses can be refactored. This is simpler, more secure, and slightly more performant.

Props sgolemon.
Fixes #37082.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/atomlib.php

    r38883 r39591  
    9595        $this->feed = new AtomFeed();
    9696        $this->current = null;
    97         $this->map_attrs_func = create_function('$k,$v', 'return "$k=\"$v\"";');
    98         $this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');
     97        $this->map_attrs_func = array( __CLASS__, 'map_attrs' );
     98        $this->map_xmlns_func = array( __CLASS__, 'map_xmlns' );
    9999    }
    100100
     
    104104    public function AtomParser() {
    105105        self::__construct();
     106    }
     107
     108    /**
     109     * Map attributes to key="val"
     110     *
     111     * @param string $k Key
     112     * @param string $v Value
     113     * @return string
     114     */
     115    public static function map_attrs($k, $v) {
     116        return "$k=\"$v\"";
     117    }
     118
     119    /**
     120     * Map XML namespace to string.
     121     *
     122     * @param indexish $p XML Namespace element index
     123     * @param array $n Two-element array pair. [ 0 => {namespace}, 1 => {url} ]
     124     * @return string 'xmlns="{url}"' or 'xmlns:{namespace}="{url}"'
     125     */
     126    public static function map_xmlns($p, $n) {
     127        $xd = "xmlns";
     128        if( 0 < strlen($n[0]) ) {
     129            $xd .= ":{$n[0]}";
     130        }
     131        return "{$xd}=\"{$n[1]}\"";
    106132    }
    107133
Note: See TracChangeset for help on using the changeset viewer.