Skip to content

Commit

Permalink
Replace deprecated create_function() with Closures
Browse files Browse the repository at this point in the history
create_function() has been deprecated as of PHP 7.2

See wpsharks/comet-cache#921
  • Loading branch information
raamdev committed Feb 25, 2018
1 parent e4afd23 commit 88815c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
57 changes: 21 additions & 36 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@

add_action(
'all_admin_notices',
create_function(
'',
'if(!current_user_can(\'activate_plugins\'))'.
' return;'."\n".// User missing capability.

'echo \''.// Wrap `$notice` inside a WordPress error.

'<div class="error">'.
' '.str_replace("'", "\\'", ${__FILE__}['php54_notice']).
'</div>'.

'\';'
)
function() {
if(!current_user_can('activate_plugins')) {
return; // User missing capability.
}
// Wrap `$notice` inside a WordPress error.
echo '<div class="error">' . str_replace("'", "\\'", ${__FILE__}['php54_notice']) . '</div>';
}
);
} elseif (${__FILE__}['apc_enabled'] && is_admin()) {
${__FILE__}['apc_deprecated_notice'] = '<h3 style="margin:.5em 0 .25em 0;">'.__('<strong>NOTICE: Comet Cache + PHP APC Extension</strong></h3>', 'comet-cache');
Expand All @@ -50,19 +44,13 @@

add_action(
'all_admin_notices',
create_function(
'',
'if(!current_user_can(\'activate_plugins\'))'.
' return;'."\n".// User missing capability.

'echo \''.// Wrap `$notice` inside a WordPress error.

'<div class="error">'.
' '.str_replace("'", "\\'", ${__FILE__}['apc_deprecated_notice']).
'</div>'.

'\';'
)
function() {
if(!current_user_can('activate_plugins')) {
return; // User missing capability.
}
// Wrap `$notice` inside a WordPress error.
echo '<div class="error">' . str_replace("'", "\\'", ${__FILE__}['apc_deprecated_notice']) . '</div>';
}
);
}
} else { // Load the plugin
Expand All @@ -74,16 +62,13 @@
${__FILE__}['mbstring_deprecated_warning'] .= '<p style="margin-bottom:.5em;">'.__('<a href="'.esc_attr(add_query_arg('comet_cache_mbstring_deprecated_warning_bypass', '1')).'" onclick="if(!confirm(\'Are you sure? Press OK to continue, or Cancel to stop and read carefully.\')) return false;">Dismiss this notice.</a>', 'comet-cache').'</p>';
add_action(
'all_admin_notices',
create_function(
'',
'if(!current_user_can(\'activate_plugins\'))'.
' return;'."\n".// User missing capability.
'echo \''.// Wrap `$notice` inside a WordPress error.
'<div class="notice notice-warning">'.
' '.str_replace("'", "\\'", ${__FILE__}['mbstring_deprecated_warning']).
'</div>'.
'\';'
)
function() {
if(!current_user_can('activate_plugins')) {
return; // User missing capability.
}
// Wrap `$notice` inside a WordPress error.
echo '<div class="error">' . str_replace("'", "\\'", ${__FILE__}['mbstring_deprecated_warning']) . '</div>';
}
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Shared/FsUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false)
}
if (mb_strpos($dir_file, ':' !== false)) {
if (preg_match('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/u', $dir_file)) {
$dir_file = preg_replace_callback('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/u', create_function('$m', 'return mb_strtoupper($m[0]);'), $dir_file);
$dir_file = preg_replace_callback('/^(?P<drive_letter>[a-zA-Z])\:[\/\\\\]/u', function($m){ return mb_strtoupper($m[0]); }, $dir_file);
}
}
$dir_file = preg_replace('/\/+/u', '/', str_replace([DIRECTORY_SEPARATOR, '\\', '/'], '/', $dir_file));
Expand Down

0 comments on commit 88815c3

Please sign in to comment.