Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: Remove usage of create_function() in stats_convert_image_urls() #8240

Merged
merged 2 commits into from
Nov 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions modules/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,19 @@ function stats_convert_image_urls( $html ) {
return $html;
}

/**
* Callback for preg_replace_callback used in stats_convert_chart_urls()
*
* @since 5.6.0
*
* @param array $matches The matches resulting from the preg_replace_callback call.
* @return string The admin url for the chart.
*/
function jetpack_stats_convert_chart_urls_callback( $matches ) {
// If there is a query string, change the beginning '?' to a '&' so it fits into the middle of this query string.
return 'admin.php?page=stats&noheader&chart=' . $matches[1] . str_replace( '?', '&', $matches[2] );
}

/**
* Stats Convert Chart URLs.
*
Expand All @@ -662,13 +675,11 @@ function stats_convert_image_urls( $html ) {
* @return string
*/
function stats_convert_chart_urls( $html ) {
$html = preg_replace_callback( '|https?://[-.a-z0-9]+/wp-includes/charts/([-.a-z0-9]+).php(\??)|',
create_function(
'$matches',
// If there is a query string, change the beginning '?' to a '&' so it fits into the middle of this query string.
'return "admin.php?page=stats&noheader&chart=" . $matches[1] . str_replace( "?", "&", $matches[2] );'
),
$html );
$html = preg_replace_callback(
'|https?://[-.a-z0-9]+/wp-includes/charts/([-.a-z0-9]+).php(\??)|',
'jetpack_stats_convert_chart_urls_callback',
$html
);
return $html;
}

Expand Down