From b3d474a6dc59f2b7be34b4594b9ab1ddbfec2f7e Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 26 Aug 2016 18:11:39 +0000 Subject: [PATCH] Load: move `WP_MatchesMapRegex` into its own file. See #37827. Built from https://develop.svn.wordpress.org/trunk@38376 git-svn-id: http://core.svn.wordpress.org/trunk@38317 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-matchesmapregex.php | 97 ++++++++++++++++++++++++ wp-includes/class-wp.php | 90 ---------------------- wp-includes/version.php | 2 +- wp-settings.php | 1 + 4 files changed, 99 insertions(+), 91 deletions(-) create mode 100644 wp-includes/class-wp-matchesmapregex.php diff --git a/wp-includes/class-wp-matchesmapregex.php b/wp-includes/class-wp-matchesmapregex.php new file mode 100644 index 0000000000..86ebb2524a --- /dev/null +++ b/wp-includes/class-wp-matchesmapregex.php @@ -0,0 +1,97 @@ +_subject = $subject; + $this->_matches = $matches; + $this->output = $this->_map(); + } + + /** + * Substitute substring matches in subject. + * + * static helper function to ease use + * + * @static + * @access public + * + * @param string $subject subject + * @param array $matches data used for substitution + * @return string + */ + public static function apply($subject, $matches) { + $oSelf = new WP_MatchesMapRegex($subject, $matches); + return $oSelf->output; + } + + /** + * do the actual mapping + * + * @access private + * @return string + */ + private function _map() { + $callback = array($this, 'callback'); + return preg_replace_callback($this->_pattern, $callback, $this->_subject); + } + + /** + * preg_replace_callback hook + * + * @access public + * @param array $matches preg_replace regexp matches + * @return string + */ + public function callback($matches) { + $index = intval(substr($matches[0], 9, -1)); + return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' ); + } +} diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 4a9718364e..5268c15176 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -738,93 +738,3 @@ class WP { do_action_ref_array( 'wp', array( &$this ) ); } } - -/** - * Helper class to remove the need to use eval to replace $matches[] in query strings. - * - * @since 2.9.0 - */ -class WP_MatchesMapRegex { - /** - * store for matches - * - * @access private - * @var array - */ - private $_matches; - - /** - * store for mapping result - * - * @access public - * @var string - */ - public $output; - - /** - * subject to perform mapping on (query string containing $matches[] references - * - * @access private - * @var string - */ - private $_subject; - - /** - * regexp pattern to match $matches[] references - * - * @var string - */ - public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number - - /** - * constructor - * - * @param string $subject subject if regex - * @param array $matches data to use in map - */ - public function __construct($subject, $matches) { - $this->_subject = $subject; - $this->_matches = $matches; - $this->output = $this->_map(); - } - - /** - * Substitute substring matches in subject. - * - * static helper function to ease use - * - * @static - * @access public - * - * @param string $subject subject - * @param array $matches data used for substitution - * @return string - */ - public static function apply($subject, $matches) { - $oSelf = new WP_MatchesMapRegex($subject, $matches); - return $oSelf->output; - } - - /** - * do the actual mapping - * - * @access private - * @return string - */ - private function _map() { - $callback = array($this, 'callback'); - return preg_replace_callback($this->_pattern, $callback, $this->_subject); - } - - /** - * preg_replace_callback hook - * - * @access public - * @param array $matches preg_replace regexp matches - * @return string - */ - public function callback($matches) { - $index = intval(substr($matches[0], 9, -1)); - return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' ); - } -} diff --git a/wp-includes/version.php b/wp-includes/version.php index 55dac968f6..593a28d29a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38375'; +$wp_version = '4.7-alpha-38376'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index de9c0b77d8..111447d4ca 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -92,6 +92,7 @@ wp_set_lang_dir(); // Load early WordPress files. require( ABSPATH . WPINC . '/compat.php' ); require( ABSPATH . WPINC . '/functions.php' ); +require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' ); require( ABSPATH . WPINC . '/class-wp.php' ); require( ABSPATH . WPINC . '/class-wp-error.php' ); require( ABSPATH . WPINC . '/pomo/mo.php' );