_subject = $subject; $this->_matches = $matches; $this->output = $this->_map(); } public static function apply( $subject, $matches ) { $result = new WP_MatchesMapRegex( $subject, $matches ); return $result->output; } private function _map() { $callback = array( $this, 'callback' ); return preg_replace_callback( $this->_pattern, $callback, $this->_subject ); } public function callback( $matches ) { $index = (int) substr( $matches[0], 9, -1 ); return ( isset( $this->_matches[ $index ] ) ? urlencode( $this->_matches[ $index ] ) : '' ); } }