PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.1
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.1
4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / opcacheBootstrap.php
wp-staging Last commit date
Backend 5 days ago Backup 5 days ago Basic 1 week ago Component 1 week ago Core 5 days ago Framework 5 days ago Frontend 1 week ago Notifications 1 week ago Staging 5 days ago assets 5 days ago languages 1 week ago resources 1 week ago vendor_wpstg 1 week ago views 5 days ago CONTRIBUTING.md 2 years ago Deactivate.php 1 week ago README.md 5 months ago SECURITY.md 1 month ago autoloader.php 1 week ago bootstrap.php 1 week ago commonBootstrap.php 1 week ago constantsFree.php 5 days ago freeBootstrap.php 1 week ago install.php 1 week ago opcacheBootstrap.php 5 days ago readme.txt 5 days ago runtimeRequirements.php 1 week ago uninstall.php 5 days ago wp-staging-error-handler.php 1 week ago wp-staging.php 5 days ago
opcacheBootstrap.php
114 lines
1 <?php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 global $wp_version, $pluginFilePath;
18
19
20 if (version_compare($wp_version, '5.5', '>=')) {
21 return;
22 }
23
24 $filename = isset($_SERVER['SCRIPT_FILENAME']) ? sanitize_text_field($_SERVER['SCRIPT_FILENAME']) : '';
25
26
27 $canInvalidate = function_exists('opcache_invalidate')
28 && (!ini_get('opcache.restrict_api') || stripos(realpath($filename), ini_get('opcache.restrict_api')) === 0);
29
30
31 if (!$canInvalidate) {
32 if (defined('WPSTG_DEBUG') && WPSTG_DEBUG) {
33 error_log('WP STAGING: Can not clear OPCache.');
34 }
35
36 return;
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50
51 $runtimeVersionDifferentFromBuildVersion = get_file_data($pluginFilePath, ['Version' => 'Version'])['Version'] !== '4.11.1';
52 $lastCheckHappenedAfterInterval = current_time('timestamp') > (int)get_site_transient('wpstg.bootstrap.opcache.lastCleared') + 5 * MINUTE_IN_SECONDS;
53
54 $shouldClearOpCache = apply_filters('wpstg.bootstrap.opcache.shouldClear', $runtimeVersionDifferentFromBuildVersion && $lastCheckHappenedAfterInterval);
55
56 if ($shouldClearOpCache) {
57 set_site_transient('wpstg.bootstrap.opcache.lastCleared', current_time('timestamp'), 1 * HOUR_IN_SECONDS);
58
59 $start = microtime(true);
60
61 clearstatcache(true);
62
63 try {
64 $it = new RecursiveDirectoryIterator(dirname($pluginFilePath));
65 } catch (Exception $e) {
66
67 if (defined('WPSTG_DEBUG') && WPSTG_DEBUG) {
68 error_log('WPSTG failed to clear OPCache because the folder does not exist or is not readable. Exception: ' . $e->getMessage());
69 }
70
71 return;
72 }
73
74 $it = new RecursiveIteratorIterator($it);
75
76 $success = 0;
77 $failures = 0;
78
79
80 foreach ($it as $fileInfo) {
81 if (
82 $fileInfo->isFile()
83 && !$fileInfo->isLink()
84 && $fileInfo->getExtension() === 'php'
85 ) {
86 if (opcache_invalidate($fileInfo->getRealPath(), false)) {
87 $success++;
88 } else {
89 $failures++;
90 }
91 }
92 }
93
94 add_action('admin_notices', function () use ($pluginFilePath, $start) {
95 echo '<div class="notice-warning notice is-dismissible">';
96 echo '<p style="font-weight: bold;">' . esc_html__('WP STAGING OPCache', 'wp-staging') . '</p>';
97 echo '<p>' . wp_kses_post(
98 sprintf(
99 __('WP STAGING detected that the OPCache was outdated and automatically cleared the OPCache for the <strong>%s</strong> folder to prevent issues. This operation took %s seconds.', 'wp-staging'),
100 plugin_basename($pluginFilePath),
101 number_format(microtime(true) - $start, 4)
102 )
103 ) . '</p>';
104 echo '</div>';
105 });
106
107 if (defined('WPSTG_DEBUG') && WPSTG_DEBUG) {
108 error_log(sprintf('%s files were cleared from OPCache in %s seconds', $success, microtime(true) - $start));
109 if (!empty($failures)) {
110 error_log(sprintf('WP STAGING could not clear %s files from the OpCache cache upon activation. There may be inconsistencies.', $failures));
111 }
112 }
113 }
114