From 023d6568800bcffbc59bf772b3152e8d3f0ab08e Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 2 Feb 2021 02:32:24 -0600 Subject: [PATCH 1/2] Add Jetpack codesniffing ruleset (#752) * Add Jetpack codesniffing ruleset * Add .phpcs.xml.dist --- .gitignore | 1 + .phpcs.xml.dist | 42 +++ composer.json | 11 + composer.lock | 673 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 727 insertions(+) create mode 100644 .gitignore create mode 100644 .phpcs.xml.dist create mode 100644 composer.json create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..57872d0f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 000000000..78960a422 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,42 @@ + + + + + + + + + + . + + + + + + + + /.git/* + + + /node_modules/* + /vendor/* + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..05df04fae --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "automattic/wp-super-cache", + "description": "Very fast caching plugin for WordPress.", + "type": "wordpress-plugin", + "require-dev": { + "automattic/jetpack-codesniffer": "^2.1" + }, + "license": "GPL-2.0-or-later", + "minimum-stability": "stable", + "require": {} +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..2918d1782 --- /dev/null +++ b/composer.lock @@ -0,0 +1,673 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "2c2064bca069277ab5c4bb4905ea8195", + "packages": [], + "packages-dev": [ + { + "name": "automattic/jetpack-codesniffer", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-codesniffer.git", + "reference": "3d5dc0b88d5a8acf9f21b0d59c46e373a16b77c3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-codesniffer/zipball/3d5dc0b88d5a8acf9f21b0d59c46e373a16b77c3", + "reference": "3d5dc0b88d5a8acf9f21b0d59c46e373a16b77c3", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "mediawiki/mediawiki-codesniffer": "^34.0", + "phpcompatibility/phpcompatibility-wp": "^2.1", + "sirbrillig/phpcs-variable-analysis": "^2.10", + "wp-coding-standards/wpcs": "^2.3" + }, + "require-dev": { + "yoast/phpunit-polyfills": "0.2.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "mirror-repo": "Automattic/jetpack-codesniffer" + }, + "autoload": { + "psr-4": { + "Automattic\\Jetpack\\Sniffs\\": "Jetpack/Sniffs" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Jetpack Coding Standards. Based on the WordPress Coding Standards, with some additions.", + "support": { + "source": "https://github.com/Automattic/jetpack-codesniffer/tree/v2.1.1" + }, + "time": "2021-01-19T14:24:56+00:00" + }, + { + "name": "composer/semver", + "version": "3.2.4", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "a02fdf930a3c1c3ed3a49b5f63859c0c20e10464" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/a02fdf930a3c1c3ed3a49b5f63859c0c20e10464", + "reference": "a02fdf930a3c1c3ed3a49b5f63859c0c20e10464", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.54", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.2.4" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-11-13T08:59:24+00:00" + }, + { + "name": "composer/spdx-licenses", + "version": "1.5.5", + "source": { + "type": "git", + "url": "https://github.com/composer/spdx-licenses.git", + "reference": "de30328a7af8680efdc03e396aad24befd513200" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/de30328a7af8680efdc03e396aad24befd513200", + "reference": "de30328a7af8680efdc03e396aad24befd513200", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Spdx\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "SPDX licenses list and validation library.", + "keywords": [ + "license", + "spdx", + "validator" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/spdx-licenses/issues", + "source": "https://github.com/composer/spdx-licenses/tree/1.5.5" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-12-03T16:04:16+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.1", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2020-12-07T18:04:37+00:00" + }, + { + "name": "mediawiki/mediawiki-codesniffer", + "version": "v34.0.0", + "source": { + "type": "git", + "url": "https://github.com/wikimedia/mediawiki-tools-codesniffer.git", + "reference": "a7f2480d022e288d9d8b2db827111996bb53e598" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wikimedia/mediawiki-tools-codesniffer/zipball/a7f2480d022e288d9d8b2db827111996bb53e598", + "reference": "a7f2480d022e288d9d8b2db827111996bb53e598", + "shasum": "" + }, + "require": { + "composer/semver": "^1.5.2|^3.0.1", + "composer/spdx-licenses": "~1.5.2", + "ext-mbstring": "*", + "php": ">=7.2.0", + "squizlabs/php_codesniffer": "3.5.8" + }, + "require-dev": { + "mediawiki/mediawiki-phan-config": "0.10.4", + "mediawiki/minus-x": "1.1.0", + "php-parallel-lint/php-console-highlighter": "0.5.0", + "php-parallel-lint/php-parallel-lint": "1.2.0", + "phpunit/phpunit": "^8.5" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "MediaWiki\\": "MediaWiki" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "MediaWiki CodeSniffer Standards", + "homepage": "https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP", + "keywords": [ + "codesniffer", + "mediawiki" + ], + "support": { + "source": "https://github.com/wikimedia/mediawiki-tools-codesniffer/tree/v34.0.0" + }, + "time": "2020-12-05T07:12:58+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "b862bc32f7e860d0b164b199bd995e690b4b191c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/b862bc32f7e860d0b164b199bd995e690b4b191c", + "reference": "b862bc32f7e860d0b164b199bd995e690b4b191c", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "time": "2019-11-04T15:17:54+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "41bef18ba688af638b7310666db28e1ea9158b2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/41bef18ba688af638b7310666db28e1ea9158b2f", + "reference": "41bef18ba688af638b7310666db28e1ea9158b2f", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2019-08-28T14:22:28+00:00" + }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.10.2", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "0775e0c683badad52c03b11c2cd86a9fdecb937a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/0775e0c683badad52c03b11c2cd86a9fdecb937a", + "reference": "0775e0c683badad52c03b11c2cd86a9fdecb937a", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "limedeck/phpunit-detailed-printer": "^3.1 || ^4.0 || ^5.0", + "phpstan/phpstan": "^0.11.8", + "phpunit/phpunit": "^5.0 || ^6.5 || ^7.0 || ^8.0", + "sirbrillig/phpcs-import-detection": "^1.1" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2021-01-08T16:31:05+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.5.8", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", + "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2020-10-23T02:01:07+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "7da1894633f168fe244afc6de00d141f27517b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", + "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.3.1" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "time": "2020-05-13T23:57:56+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.0.0" +} From 3af33c4f38c24f776934c60ada00d797eafc201e Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 2 Feb 2021 08:50:18 -0600 Subject: [PATCH 2/2] PHPCBF v2 --- admin/class-wp-super-cache-admin.php | 3 +- includes/class-wp-super-cache-debug.php | 3 +- includes/class-wp-super-cache-file-cache.php | 53 +- includes/class-wp-super-cache-i18n.php | 2 - includes/class-wp-super-cache-page.php | 4 +- includes/class-wp-super-cache-setup.php | 5 +- includes/class-wp-super-cache-user.php | 1 - includes/class-wp-super-cache.php | 12 +- ossdl-cdn.php | 42 +- plugins/awaitingmoderation.php | 16 +- plugins/jetpack.php | 18 +- plugins/multisite.php | 22 +- plugins/wptouch.php | 14 +- public/class-wp-super-cache-public.php | 6 +- ...class.wp-super-cache-rest-delete-cache.php | 6 +- rest/class.wp-super-cache-rest-get-cache.php | 23 +- ...class.wp-super-cache-rest-get-settings.php | 47 +- rest/class.wp-super-cache-rest-get-stats.php | 4 +- rest/class.wp-super-cache-rest-get-status.php | 38 +- rest/class.wp-super-cache-rest-preload.php | 4 +- rest/class.wp-super-cache-rest-test-cache.php | 47 +- ...ss.wp-super-cache-rest-update-settings.php | 69 +- rest/class.wp-super-cache-settings-map.php | 166 +- rest/load.php | 180 +- wp-cache-config-sample.php | 138 +- wp-cache-phase1.php | 8 +- wp-cache-phase2.php | 980 +++--- wp-cache.php | 2701 ++++++++++------- 28 files changed, 2614 insertions(+), 1998 deletions(-) diff --git a/admin/class-wp-super-cache-admin.php b/admin/class-wp-super-cache-admin.php index f493a9b47..45b671473 100755 --- a/admin/class-wp-super-cache-admin.php +++ b/admin/class-wp-super-cache-admin.php @@ -12,8 +12,7 @@ /** * The class responsible for setting up required files for caching. */ -require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-super-cache-setup.php'; - +require_once plugin_dir_path( __DIR__ ) . 'includes/class-wp-super-cache-setup.php'; /** * The admin-specific functionality of the plugin. diff --git a/includes/class-wp-super-cache-debug.php b/includes/class-wp-super-cache-debug.php index f6510dff8..de4eb5563 100644 --- a/includes/class-wp-super-cache-debug.php +++ b/includes/class-wp-super-cache-debug.php @@ -98,7 +98,7 @@ private function get_debug_username() { * @param string $username username and password used to protect the log file. */ public function create_debug_log( $filename = '', $username = '' ) { - $debug_setting = $this->config->config['wp_super_cache_debug']; + $debug_setting = $this->config->config['wp_super_cache_debug']; $this->config->config['wp_super_cache_debug'] = false; if ( '' !== $filename ) { @@ -207,7 +207,6 @@ public function create_debug_log( $filename = '', $username = '' ) { ); } - /** * Return an instance of the current class, create one if it doesn't exist * diff --git a/includes/class-wp-super-cache-file-cache.php b/includes/class-wp-super-cache-file-cache.php index e89eb6d19..f607090bc 100644 --- a/includes/class-wp-super-cache-file-cache.php +++ b/includes/class-wp-super-cache-file-cache.php @@ -329,7 +329,6 @@ public function get_response_headers() { return $headers; } - /** * Get meta information about new cache file. * @@ -347,7 +346,7 @@ private function get_cache_meta_information() { wp_cache_debug( 'wp_cache_shutdown_callback: Plugin not loaded. Setting feed ttl to 60 seconds.' ); } - $wp_cache_meta['uri'] = WPSC_HTTP_HOST . preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', WPSC_URI ); // To avoid XSS attacks + $wp_cache_meta['uri'] = WPSC_HTTP_HOST . preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', WPSC_URI ); // To avoid XSS attacks $wp_cache_meta['blog_id'] = $blog_id; $wp_cache_meta['post'] = $this->config->config['post_id']; $wp_cache_meta['key'] = $wp_cache_key; @@ -355,32 +354,33 @@ private function get_cache_meta_information() { $wp_cache_meta = apply_filters( 'wp_cache_meta', $wp_cache_meta ); $response = $this->get_response_headers(); - foreach( $response as $key => $value ) { + foreach ( $response as $key => $value ) { $wp_cache_meta['headers'][ $key ] = "$key: $value"; } wp_cache_debug( 'wp_cache_shutdown_callback: collecting meta data.', 2 ); - if (!isset( $response['Last-Modified'] )) { - $value = gmdate('D, d M Y H:i:s') . ' GMT'; - /* Dont send this the first time */ + if ( ! isset( $response['Last-Modified'] ) ) { + $value = gmdate( 'D, d M Y H:i:s' ) . ' GMT'; + /* + Dont send this the first time */ /* @header('Last-Modified: ' . $value); */ $wp_cache_meta['headers']['Last-Modified'] = "Last-Modified: $value"; } $is_feed = false; - if ( !isset( $response['Content-Type'] ) && !isset( $response['Content-type'] ) ) { + if ( ! isset( $response['Content-Type'] ) && ! isset( $response['Content-type'] ) ) { // On some systems, headers set by PHP can't be fetched from // the output buffer. This is a last ditch effort to set the // correct Content-Type header for feeds, if we didn't see // it in the response headers already. -- dougal if ( isset( $this->config->query_vars['is_feed'] ) ) { - if ( isset( $this->config->query_vars['is_sitemap'] ) ) { + if ( isset( $this->config->query_vars['is_sitemap'] ) ) { $type = 'sitemap'; $value = 'text/xml'; } else { $type = get_query_var( 'feed' ); - $type = str_replace('/','',$type); - switch ($type) { + $type = str_replace( '/', '', $type ); + switch ( $type ) { case 'atom': $value = 'application/atom+xml'; break; @@ -405,18 +405,19 @@ private function get_cache_meta_information() { $value = 'application/json'; } else { // not a feed $value = get_option( 'html_type' ); - if( $value == '' ) + if ( $value == '' ) { $value = 'text/html'; + } } if ( defined( 'WPSC_BLOG_CHARSET' ) ) { - $value .= "; charset=\"" . constant( 'WPSC_BLOG_CHARSET' ) . "\""; + $value .= '; charset="' . constant( 'WPSC_BLOG_CHARSET' ) . '"'; } $wp_cache_meta['headers']['Content-Type'] = "Content-Type: $value"; } - if ( $cache_enabled && !$supercacheonly && $new_cache ) { - if( !isset( $wp_cache_meta['dynamic'] ) && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta['headers'] ) ) { + if ( $cache_enabled && ! $supercacheonly && $new_cache ) { + if ( ! isset( $wp_cache_meta['dynamic'] ) && $wp_cache_gzip_encoding && ! in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta['headers'] ) ) { wp_cache_debug( 'Sending gzip headers.', 2 ); $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; if ( defined( 'WPSC_VARY_HEADER' ) ) { @@ -434,21 +435,22 @@ private function get_cache_meta_information() { } $serial = '' . json_encode( $wp_cache_meta ); - $dir = get_current_url_supercache_dir(); - if( @is_dir( $dir ) == false ) + $dir = get_current_url_supercache_dir(); + if ( @is_dir( $dir ) == false ) { @wp_mkdir_p( $dir ); + } - if( wp_cache_writers_entry() ) { + if ( wp_cache_writers_entry() ) { wp_cache_debug( "Writing meta file: {$dir}meta-{$meta_file}", 2 ); - $tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; - $final_meta_filename = $dir . "meta-" . $meta_file; - $fr = @fopen( $tmp_meta_filename, 'w'); + $tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp'; + $final_meta_filename = $dir . 'meta-' . $meta_file; + $fr = @fopen( $tmp_meta_filename, 'w' ); if ( $fr ) { - fputs($fr, $serial); - fclose($fr); - @chmod( $tmp_meta_filename, 0666 & ~umask()); - if( !@rename( $tmp_meta_filename, $final_meta_filename ) ) { + fputs( $fr, $serial ); + fclose( $fr ); + @chmod( $tmp_meta_filename, 0666 & ~umask() ); + if ( ! @rename( $tmp_meta_filename, $final_meta_filename ) ) { @unlink( $dir . $final_meta_filename ); @rename( $tmp_meta_filename, $final_meta_filename ); } @@ -533,7 +535,7 @@ public function ob_handler( $buffer ) { $buffer = $this->write_buffer_to_file( $buffer ); // TODO. - //wp_cache_shutdown_callback(); + // wp_cache_shutdown_callback(); $meta_info = $this->get_cache_meta_information(); $this->send_cache_headers( $meta_info ); @@ -868,7 +870,6 @@ private function wp_cache_writers_exit() { } } - /** * Count the micro seconds between $a and $b * diff --git a/includes/class-wp-super-cache-i18n.php b/includes/class-wp-super-cache-i18n.php index 0730ca156..63f771905 100755 --- a/includes/class-wp-super-cache-i18n.php +++ b/includes/class-wp-super-cache-i18n.php @@ -41,6 +41,4 @@ public function load_plugin_textdomain() { } - - } diff --git a/includes/class-wp-super-cache-page.php b/includes/class-wp-super-cache-page.php index d152f3dc3..9828e2035 100644 --- a/includes/class-wp-super-cache-page.php +++ b/includes/class-wp-super-cache-page.php @@ -52,7 +52,7 @@ public function __construct() { } if ( ! defined( 'WPCACHEHOME' ) ) { - define( 'WPCACHEHOME', dirname( dirname( __FILE__ ) ) . '/' ); + define( 'WPCACHEHOME', dirname( __DIR__ ) . '/' ); } // In the future we might have different caching engines. @@ -287,7 +287,6 @@ public function make_anonymous() { } } - /** * Return true if in wp-admin or other admin non cacheable page. * @@ -478,7 +477,6 @@ public function post_cache_checks() { return $cache_this_page; } - /** * Return an instance of the current class, create one if it doesn't exist * diff --git a/includes/class-wp-super-cache-setup.php b/includes/class-wp-super-cache-setup.php index fba792e15..e6a21ba33 100644 --- a/includes/class-wp-super-cache-setup.php +++ b/includes/class-wp-super-cache-setup.php @@ -275,7 +275,6 @@ public function set_home_path() { return true; } - /** * Add WP_CACHE to wp-config.php * @@ -296,9 +295,9 @@ public function add_wp_cache_constant() { */ public function add_wpcachehome_constant() { if ( ! defined( 'WPCACHEHOME' ) ) { - define( 'WPCACHEHOME', trailingslashit( dirname( __FILE__ ) ) ); + define( 'WPCACHEHOME', trailingslashit( __DIR__ ) ); } - $line = "define( 'WPCACHEHOME', '" . trailingslashit( dirname( dirname( __FILE__ ) ) ) . "' );"; + $line = "define( 'WPCACHEHOME', '" . trailingslashit( dirname( __DIR__ ) ) . "' );"; return $this->config->replace_line_in_file( 'define *\( *\'WPCACHEHOME\'', $line, $this->config_filename ); } diff --git a/includes/class-wp-super-cache-user.php b/includes/class-wp-super-cache-user.php index f7c707f08..a84feed50 100644 --- a/includes/class-wp-super-cache-user.php +++ b/includes/class-wp-super-cache-user.php @@ -22,7 +22,6 @@ class Wp_Super_Cache_User { */ public $config = array(); - /** * Constructor * diff --git a/includes/class-wp-super-cache.php b/includes/class-wp-super-cache.php index 0fea57c69..525f2bb58 100755 --- a/includes/class-wp-super-cache.php +++ b/includes/class-wp-super-cache.php @@ -111,35 +111,35 @@ private function load_dependencies() { * Basic functions that are used everywhere, before and after * WordPress is loaded. */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pre-wp-functions.php'; + require_once plugin_dir_path( __DIR__ ) . 'includes/pre-wp-functions.php'; /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-super-cache-loader.php'; + require_once plugin_dir_path( __DIR__ ) . 'includes/class-wp-super-cache-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-super-cache-i18n.php'; + require_once plugin_dir_path( __DIR__ ) . 'includes/class-wp-super-cache-i18n.php'; /** * The class responsible for defining all actions that occur in the admin area. */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-super-cache-admin.php'; + require_once plugin_dir_path( __DIR__ ) . 'admin/class-wp-super-cache-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-super-cache-public.php'; + require_once plugin_dir_path( __DIR__ ) . 'public/class-wp-super-cache-public.php'; /** * The class responsible for defining configuration functions used by the plugin. */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-super-cache-config.php'; + require_once plugin_dir_path( __DIR__ ) . 'includes/class-wp-super-cache-config.php'; $this->config = Wp_Super_cache_Config::instance(); $this->loader = new Wp_Super_Cache_Loader(); diff --git a/ossdl-cdn.php b/ossdl-cdn.php index 2c2c62ead..31fb710ba 100755 --- a/ossdl-cdn.php +++ b/ossdl-cdn.php @@ -278,42 +278,64 @@ function scossdl_off_options() { $example_cdn_uri .= '/wp-includes/js/jquery/jquery-migrate.js'; $example_cdn_uri = esc_url( $example_cdn_uri ); ?> -

-

+

+ ', '', '' - ); ?>

+ ); + ?> +

+

+ ', '' - ); ?>

+

+

+

+ ', '', '' - ); ?>

+

+

+

+ ', '', '' - ); ?>

+

+ -

+

wp-content and wp-includes directories (except for PHP files) on your site with the URL you provide below. That way you can either copy all the static content to a dedicated host or mirror the files to a CDN by origin pull.', 'wp-super-cache' ); ?>

WARNING: Test some static urls e.g., %s to ensure your CDN service is fully working before saving changes.', 'wp-super-cache' ), '' . esc_html( $example_cdn_uri ) . '' ); ?>

diff --git a/plugins/awaitingmoderation.php b/plugins/awaitingmoderation.php index e5087e949..b29cc66d6 100644 --- a/plugins/awaitingmoderation.php +++ b/plugins/awaitingmoderation.php @@ -31,8 +31,18 @@ function wp_supercache_awaitingmoderation_admin() {

- - + +

'; wp_nonce_field( 'wp-cache' ); - ?> + ?>
' . sprintf( __( 'Jetpack not found in %s. Install it and enable the mobile theme and this helper plugin to cache visits by mobile visitors.', 'wp-super-cache' ), dirname( WPCACHEHOME ) ) . ''; } else { - ?> + ?>
- - + + ' . __( 'Provides support for the Jetpack mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ) . '

'; if ( isset( $changed ) && $changed ) { @@ -64,7 +74,7 @@ function wp_super_cache_jetpack_cookie_check( $cache_key ) { } } - if ( isset ( $_COOKIE['akm_mobile'] ) ) { + if ( isset( $_COOKIE['akm_mobile'] ) ) { if ( $_COOKIE['akm_mobile'] == 'true' ) { return 'mobile'; } elseif ( $_COOKIE['akm_mobile'] == 'false' ) { diff --git a/plugins/multisite.php b/plugins/multisite.php index df71f9ac4..96f9ae937 100644 --- a/plugins/multisite.php +++ b/plugins/multisite.php @@ -34,9 +34,25 @@ function wp_super_cache_blogs_field( $name, $blog_id ) { } if ( 1 === (int) get_blog_option( $blog_id, 'wp_super_cache_disabled' ) ) { - echo '' . __( 'Enable', 'wp-super-cache' ) . ''; + echo '' . __( 'Enable', 'wp-super-cache' ) . ''; } else { - echo '' . __( 'Disable', 'wp-super-cache' ) . ''; + echo '' . __( 'Disable', 'wp-super-cache' ) . ''; } } @@ -53,7 +69,7 @@ function wp_super_cache_override_on_flag() { } if ( 1 === (int) get_option( 'wp_super_cache_disabled' ) ) { - $cache_enabled = false; + $cache_enabled = false; $super_cache_enabled = false; define( 'DONOTCACHEPAGE', 1 ); define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' ); diff --git a/plugins/wptouch.php b/plugins/wptouch.php index 9f2209a62..271d99ba2 100644 --- a/plugins/wptouch.php +++ b/plugins/wptouch.php @@ -19,8 +19,18 @@ function wp_super_cache_wptouch_admin() {

- - + + ' . __( 'Provides support for WPTouch mobile theme and plugin.', 'wp-super-cache' ) . '

'; if ( isset( $changed ) && $changed ) { diff --git a/public/class-wp-super-cache-public.php b/public/class-wp-super-cache-public.php index edc4bcf70..f68d3f29d 100755 --- a/public/class-wp-super-cache-public.php +++ b/public/class-wp-super-cache-public.php @@ -44,13 +44,13 @@ class Wp_Super_Cache_Public { * Initialize the class and set its properties. * * @since 2.0.0 - * @param string $plugin_name The name of the plugin. - * @param string $version The version of this plugin. + * @param string $plugin_name The name of the plugin. + * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; - $this->version = $version; + $this->version = $version; } diff --git a/rest/class.wp-super-cache-rest-delete-cache.php b/rest/class.wp-super-cache-rest-delete-cache.php index 255458f2c..6c3ceefa6 100644 --- a/rest/class.wp-super-cache-rest-delete-cache.php +++ b/rest/class.wp-super-cache-rest-delete-cache.php @@ -14,20 +14,20 @@ public function callback( $request ) { if ( isset( $params['id'] ) && is_numeric( $params['id'] ) ) { wpsc_delete_post_cache( $params['id'] ); - } elseif ( !empty( $params['expired'] ) ) { + } elseif ( ! empty( $params['expired'] ) ) { global $file_prefix; wp_cache_clean_expired( $file_prefix ); } elseif ( isset( $params['url'] ) ) { global $cache_path; - $directory = $cache_path . 'supercache/' . $params[ 'url' ]; + $directory = $cache_path . 'supercache/' . $params['url']; wpsc_delete_files( $directory ); prune_super_cache( $directory . '/page', true ); } else { global $file_prefix; - wp_cache_clean_cache( $file_prefix, !empty( $params['all'] ) ); + wp_cache_clean_cache( $file_prefix, ! empty( $params['all'] ) ); } return rest_ensure_response( array( 'Cache Cleared' => true ) ); diff --git a/rest/class.wp-super-cache-rest-get-cache.php b/rest/class.wp-super-cache-rest-get-cache.php index 2cad9eddb..83993f372 100644 --- a/rest/class.wp-super-cache-rest-get-cache.php +++ b/rest/class.wp-super-cache-rest-get-cache.php @@ -11,29 +11,30 @@ class WP_Super_Cache_Rest_Get_Cache extends WP_REST_Controller { public function callback( $request ) { global $valid_nonce; - $valid_nonce = true; - $_GET[ 'listfiles' ] = 1; - $sizes = wpsc_generate_sizes_array(); - $supercachedir = get_supercache_dir(); - $list = wpsc_dirsize( $supercachedir, $sizes ); - $return_list = array(); + $valid_nonce = true; + $_GET['listfiles'] = 1; + $sizes = wpsc_generate_sizes_array(); + $supercachedir = get_supercache_dir(); + $list = wpsc_dirsize( $supercachedir, $sizes ); + $return_list = array(); - foreach( $list as $type => $file_list ) { + foreach ( $list as $type => $file_list ) { foreach ( $file_list as $state => $value ) { if ( is_array( $value ) ) { - foreach( $value as $filenames ) { - foreach( $filenames as $filename => $t ) { + foreach ( $value as $filenames ) { + foreach ( $filenames as $filename => $t ) { if ( $type == 'wpcache' ) { $filename = dirname( $filename ); } - if ( false == isset( $return_list[ $type ][ $state ] ) || false == in_array( $filename, $return_list[ $type ][ $state ] ) ) + if ( false == isset( $return_list[ $type ][ $state ] ) || false == in_array( $filename, $return_list[ $type ][ $state ] ) ) { $return_list[ $type ][ $state ][] = $filename; + } } } } } - if ( isset ( $return_list[ $type ] ) ) { + if ( isset( $return_list[ $type ] ) ) { $list[ $type ] = $return_list[ $type ]; } diff --git a/rest/class.wp-super-cache-rest-get-settings.php b/rest/class.wp-super-cache-rest-get-settings.php index af708f946..588d79e0e 100644 --- a/rest/class.wp-super-cache-rest-get-settings.php +++ b/rest/class.wp-super-cache-rest-get-settings.php @@ -1,6 +1,6 @@ get_is_lock_down_enabled() . " );", $wp_cache_config_file ); + wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', " . $this->get_is_lock_down_enabled() . ' );', $wp_cache_config_file ); } } - if ( function_exists( "opcache_invalidate" ) ) { + if ( function_exists( 'opcache_invalidate' ) ) { @opcache_invalidate( $wp_cache_config_file ); } - include( $wp_cache_config_file ); + include $wp_cache_config_file; foreach ( WP_Super_Cache_Settings_Map::$map as $name => $map ) { - if ( isset ( $map['get'] ) ) { + if ( isset( $map['get'] ) ) { $get_method = $map['get']; if ( method_exists( $this, $get_method ) ) { @@ -37,15 +37,14 @@ public function callback( $request ) { } elseif ( function_exists( $get_method ) ) { $settings[ $name ] = $get_method(); } - - } else if ( isset ( $map['option'] ) ) { + } elseif ( isset( $map['option'] ) ) { $settings[ $name ] = get_option( $map['option'] ); } elseif ( isset( $map['global'] ) ) { - if ( false == isset( $GLOBALS[ $map[ 'global' ] ] ) ) { + if ( false == isset( $GLOBALS[ $map['global'] ] ) ) { $settings[ $name ] = false; } else { - $settings[ $name ] = $GLOBALS[ $map[ 'global' ] ]; + $settings[ $name ] = $GLOBALS[ $map['global'] ]; } } } @@ -58,8 +57,9 @@ public function callback( $request ) { */ public function get_ossdl_off_blog_url() { $url = get_option( 'ossdl_off_blog_url' ); - if ( ! $url ) + if ( ! $url ) { $url = apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) ); + } return $url; } @@ -77,10 +77,10 @@ public function get_cache_path_url() { */ public function get_cache_type() { global $wp_cache_config_file; - if ( function_exists( "opcache_invalidate" ) ) { + if ( function_exists( 'opcache_invalidate' ) ) { @opcache_invalidate( $wp_cache_config_file ); } - include( $wp_cache_config_file ); + include $wp_cache_config_file; if ( $wp_cache_mod_rewrite == 1 ) { return 'mod_rewrite'; @@ -92,31 +92,36 @@ public function get_cache_type() { /** * Prepare the item for the REST response * - * @param mixed $item WordPress representation of the item. + * @param mixed $item WordPress representation of the item. * @param WP_REST_Request $request Request object. * @return mixed */ public function prepare_item_for_response( $item, $request ) { $settings = array(); - $integers = array( 'cache_max_time', 'preload_interval' ); - $string_arrays = array( 'cache_stats', 'cache_acceptable_files', 'cache_rejected_uri', 'cache_rejected_user_agent', - 'cache_direct_pages' ); - foreach( $item as $key => $value ) { + $integers = array( 'cache_max_time', 'preload_interval' ); + $string_arrays = array( + 'cache_stats', + 'cache_acceptable_files', + 'cache_rejected_uri', + 'cache_rejected_user_agent', + 'cache_direct_pages', + ); + foreach ( $item as $key => $value ) { if ( is_array( $value ) && false == in_array( $key, $string_arrays ) ) { array_walk( $value, array( $this, 'make_array_bool' ) ); } elseif ( ( $value === 0 || $value === 1 ) && false == in_array( $key, $integers ) ) { - $value = (bool)$value; + $value = (bool) $value; } $settings[ $key ] = $value; } $strings_to_bool = array( 'ossdl_https', 'refresh_current_only_on_comments' ); - foreach( $strings_to_bool as $key ) { + foreach ( $strings_to_bool as $key ) { if ( isset( $settings[ $key ] ) ) { - $settings[ $key ] = (bool)$settings[ $key ]; + $settings[ $key ] = (bool) $settings[ $key ]; } } @@ -124,7 +129,7 @@ public function prepare_item_for_response( $item, $request ) { } /** - * @param mixed $value + * @param mixed $value * @param string $key */ public function make_array_bool( &$value, $key ) { diff --git a/rest/class.wp-super-cache-rest-get-stats.php b/rest/class.wp-super-cache-rest-get-stats.php index 811f5a567..03891cc8d 100644 --- a/rest/class.wp-super-cache-rest-get-stats.php +++ b/rest/class.wp-super-cache-rest-get-stats.php @@ -10,8 +10,8 @@ class WP_Super_Cache_Rest_Get_Stats extends WP_REST_Controller { */ public function callback( $request ) { global $valid_nonce; - $_GET[ 'listfiles' ] = 1; - $valid_nonce = true; + $_GET['listfiles'] = 1; + $valid_nonce = true; return rest_ensure_response( wp_cache_regenerate_cache_file_stats() ); } diff --git a/rest/class.wp-super-cache-rest-get-status.php b/rest/class.wp-super-cache-rest-get-status.php index f0a4ae407..2f43dc1e6 100644 --- a/rest/class.wp-super-cache-rest-get-status.php +++ b/rest/class.wp-super-cache-rest-get-status.php @@ -11,8 +11,8 @@ class WP_Super_Cache_Rest_Get_Status extends WP_REST_Controller { public function callback( $request ) { $status = array(); - include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path() - include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers() + include_once ABSPATH . 'wp-admin/includes/file.php'; // get_home_path() + include_once ABSPATH . 'wp-admin/includes/misc.php'; // extract_from_markers() $this->add_rewrite_status( $status ); $this->add_cache_disabled_status( $status ); $this->add_compression_status( $status ); @@ -29,34 +29,34 @@ public function callback( $request ) { /** * @param array $status */ - protected function add_preload_status( & $status ) { + protected function add_preload_status( &$status ) { global $wp_cache_config_file; - include( $wp_cache_config_file ); + include $wp_cache_config_file; if ( false == $cache_enabled ) { - $status[ 'preload_disabled_cache_off' ] = true; + $status['preload_disabled_cache_off'] = true; } if ( false == $super_cache_enabled ) { - $status[ 'preload_disabled_supercache_off' ] = true; + $status['preload_disabled_supercache_off'] = true; } if ( true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) { - $status[ 'preload_disabled_by_admin' ] = true; + $status['preload_disabled_by_admin'] = true; } } /** * @param array $status */ - protected function add_php_mod_rewrite_status( & $status ) { + protected function add_php_mod_rewrite_status( &$status ) { global $wp_cache_config_file; - include( $wp_cache_config_file ); + include $wp_cache_config_file; - if ( $cache_enabled && !$wp_cache_mod_rewrite ) { + if ( $cache_enabled && ! $wp_cache_mod_rewrite ) { $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) ); if ( $scrules != '' ) { - $status[ 'php_mod_rewrite' ] = true; + $status['php_mod_rewrite'] = true; } } } @@ -64,7 +64,7 @@ protected function add_php_mod_rewrite_status( & $status ) { /** * @param array $status */ - protected function add_cache_disabled_status( & $status ) { + protected function add_cache_disabled_status( &$status ) { global $wp_cache_config_file; if ( ! is_writeable_ACLSafe( $wp_cache_config_file ) ) { @@ -75,7 +75,7 @@ protected function add_cache_disabled_status( & $status ) { /** * @param array $status */ - protected function add_compression_status( & $status ) { + protected function add_compression_status( &$status ) { if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) { $status['compression_disabled_by_admin'] = true; } elseif ( false == function_exists( 'gzencode' ) ) { @@ -86,10 +86,10 @@ protected function add_compression_status( & $status ) { /** * @param array $status */ - protected function add_rewrite_status( & $status ) { + protected function add_rewrite_status( &$status ) { global $home_path, $wp_cache_config_file; - include( $wp_cache_config_file ); + include $wp_cache_config_file; // Return if the rewrite caching is disabled. if ( ! $cache_enabled || ! $super_cache_enabled || ! $wp_cache_mod_rewrite ) { @@ -100,15 +100,15 @@ protected function add_rewrite_status( & $status ) { extract( wpsc_get_htaccess_info() ); if ( $scrules != $rules ) { - $status[ 'mod_rewrite_rules' ] = true; + $status['mod_rewrite_rules'] = true; } $got_rewrite = apache_mod_loaded( 'mod_rewrite', true ); if ( $wp_cache_mod_rewrite && false == apply_filters( 'got_rewrite', $got_rewrite ) ) { - $status[ 'mod_rewrite_missing' ] = true; + $status['mod_rewrite_missing'] = true; } - if ( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) { - $status[ 'htaccess_ro' ] = true; + if ( ! is_writeable_ACLSafe( $home_path . '.htaccess' ) ) { + $status['htaccess_ro'] = true; } } } diff --git a/rest/class.wp-super-cache-rest-preload.php b/rest/class.wp-super-cache-rest-preload.php index 3e0214e4f..f2c3ff0de 100644 --- a/rest/class.wp-super-cache-rest-preload.php +++ b/rest/class.wp-super-cache-rest-preload.php @@ -16,8 +16,8 @@ public function callback( $request ) { return rest_ensure_response( array( 'error' => 'preload disabled by admin' ) ); } - if ( isset( $parameters[ 'enable' ] ) ) { - if ( $parameters[ 'enable' ] == true ) { + if ( isset( $parameters['enable'] ) ) { + if ( $parameters['enable'] == true ) { wp_cache_debug( 'WP_Super_Cache_Rest_Preload: enable' ); wpsc_enable_preload(); return( rest_ensure_response( array( 'enabled' => true ) ) ); diff --git a/rest/class.wp-super-cache-rest-test-cache.php b/rest/class.wp-super-cache-rest-test-cache.php index b79f621a5..3042be280 100644 --- a/rest/class.wp-super-cache-rest-test-cache.php +++ b/rest/class.wp-super-cache-rest-test-cache.php @@ -13,35 +13,41 @@ public function callback( $request ) { $url = trailingslashit( get_bloginfo( 'url' ) ); - $response = array( 'status' => 'UNKNOWN' ); + $response = array( 'status' => 'UNKNOWN' ); $has_errors = false; $attempts = array( 'prime', 'first', 'second' ); $c = 0; foreach ( $attempts as $attempt_name ) { - $attempt = array(); - $page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) ); + $attempt = array(); + $page[ $c ] = wp_remote_get( + $url, + array( + 'timeout' => 60, + 'blocking' => true, + ) + ); if ( ! is_wp_error( $page[ $c ] ) ) { - $fp = fopen( $cache_path . $c . ".html", "w" ); - fwrite( $fp, $page[ $c ][ 'body' ] ); + $fp = fopen( $cache_path . $c . '.html', 'w' ); + fwrite( $fp, $page[ $c ]['body'] ); fclose( $fp ); } if ( is_wp_error( $page[ $c ] ) ) { - $has_errors = true; + $has_errors = true; $attempt['status'] = false; $attempt['errors'] = $this->format_error( $page[ $c ] ); } elseif ( $page[ $c ]['response']['code'] != 200 ) { - $has_errors = true; + $has_errors = true; $attempt['status'] = false; $attempt['errors'] = array( $page[ $c ]['response']['message'] ); - // Don't run this step on prime cache. + // Don't run this step on prime cache. } elseif ( 0 !== $c && 0 === preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ $c ]['body'], $matches2 ) ) { - $has_errors = true; + $has_errors = true; $attempt['status'] = false; $attempt['errors'] = array( __( 'Timestamps not found', 'wp-super-cache' ) ); @@ -49,30 +55,29 @@ public function callback( $request ) { $attempt['status'] = true; } - - $response[ 'attempts' ][ $attempt_name ] = $attempt; + $response['attempts'][ $attempt_name ] = $attempt; $c++; } if ( false == $has_errors && - preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 1 ][ 'body' ], $matches1 ) && - preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 2 ][ 'body' ], $matches2 ) && + preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[1]['body'], $matches1 ) && + preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[2]['body'], $matches2 ) && $matches1[2] == $matches2[2] ) { - $response[ 'status' ] = true; + $response['status'] = true; } else { - $response[ 'status' ] = false; - $response[ 'error' ] = array( __( 'Timestamps do not match', 'wp-super-cache' ) ); + $response['status'] = false; + $response['error'] = array( __( 'Timestamps do not match', 'wp-super-cache' ) ); } $error = ''; - if ( $response[ 'status' ] == false ) { - if ( isset( $response[ 'error' ] ) ) { - $error = $response[ 'error' ]; + if ( $response['status'] == false ) { + if ( isset( $response['error'] ) ) { + $error = $response['error']; } else { - foreach( $response[ 'attempts' ] as $attempt ) { - $error .= $attempt[ 'errors' ] . "\n"; + foreach ( $response['attempts'] as $attempt ) { + $error .= $attempt['errors'] . "\n"; } } return new WP_Error( 'test_error', $error, array( 'status' => 500 ) ); diff --git a/rest/class.wp-super-cache-rest-update-settings.php b/rest/class.wp-super-cache-rest-update-settings.php index 7d4c9f8a4..7735fe84e 100644 --- a/rest/class.wp-super-cache-rest-update-settings.php +++ b/rest/class.wp-super-cache-rest-update-settings.php @@ -1,6 +1,6 @@ toggle_easy_caching( $parameters['easy'] ); - } elseif ( isset( $parameters[ 'reset' ] ) ) { + } elseif ( isset( $parameters['reset'] ) ) { $errors = $this->restore_default_settings( $parameters ); } else { @@ -59,7 +59,7 @@ public function callback( $request ) { * Given a key and a value, set the value for that key, based on * the configuration in the settings map. * - * @param mixed $value + * @param mixed $value * @param string $key * * @return string|null @@ -88,9 +88,9 @@ protected function set_value_by_key( $value, $key ) { $set_method = method_exists( $this, 'set_' . $map['global'] ) ? 'set_' . $map['global'] : 'set_global'; if ( $set_method == 'set_global' ) { - $has_error = call_user_func( array( $this, $set_method ), $key, $value ); + $has_error = call_user_func( array( $this, $set_method ), $key, $value ); } else { - $has_error = call_user_func( array( $this, $set_method ), $value ); + $has_error = call_user_func( array( $this, $set_method ), $value ); } } @@ -107,7 +107,7 @@ protected function set_value_by_key( $value, $key ) { * The setting must be added to the whitelist in order to be set this way. * * @param string $global_name - * @param mixed $value + * @param mixed $value */ protected function set_global( $global_name, $value ) { $whitelist = array( @@ -131,7 +131,7 @@ protected function set_global( $global_name, $value ) { return false; } - wp_cache_setting( $global_name, (int)$value ); + wp_cache_setting( $global_name, (int) $value ); } @@ -147,10 +147,15 @@ protected function set_wp_cache_location( $value ) { $dir = WP_CONTENT_DIR . '/cache/'; } else { - $dir = trailingslashit( $dir ) . trailingslashit( wpsc_deep_replace( array( - '..', - '\\' - ), basename( $value ) ) ); + $dir = trailingslashit( $dir ) . trailingslashit( + wpsc_deep_replace( + array( + '..', + '\\', + ), + basename( $value ) + ) + ); } $new_cache_path = $dir; @@ -186,7 +191,7 @@ protected function set_cache_enabled( $value ) { * @param mixed $value */ protected function set_lock_down( $value ) { - $_POST[ 'wp_lock_down' ] = (int)$value; + $_POST['wp_lock_down'] = (int) $value; wp_update_lock_down(); } @@ -197,7 +202,11 @@ protected function set_super_cache_enabled( $value ) { global $wp_cache_mod_rewrite; if ( is_numeric( $value ) == false ) { - $types = array( 'wpcache' => 0, 'mod_rewrite' => 1, 'PHP' => 2 ); + $types = array( + 'wpcache' => 0, + 'mod_rewrite' => 1, + 'PHP' => 2, + ); if ( isset( $types[ $value ] ) ) { $value = $types[ $value ]; } else { @@ -216,7 +225,7 @@ protected function set_super_cache_enabled( $value ) { $wp_cache_mod_rewrite = 1; add_mod_rewrite_rules(); - } elseif( $value == 2 ) { // PHP + } elseif ( $value == 2 ) { // PHP $wp_cache_mod_rewrite = 0; remove_mod_rewrite_rules(); @@ -309,8 +318,8 @@ protected function set_cache_compression( $value ) { $new_cache_compression = 1; } - if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) { - return __( "You attempted to enable compression but `zlib.output_compression` is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ); + if ( 1 == ini_get( 'zlib.output_compression' ) || 'on' == strtolower( ini_get( 'zlib.output_compression' ) ) ) { + return __( 'You attempted to enable compression but `zlib.output_compression` is enabled. See #21 in the Troubleshooting section of the readme file.', 'wp-super-cache' ); } if ( $new_cache_compression != $cache_compression ) { @@ -423,7 +432,7 @@ protected function set_ossdlcdn( $value ) { } /** - * @param mixed $value + * @param mixed $value * @param string $name */ protected function set_time_setting( $value, $name ) { @@ -432,7 +441,7 @@ protected function set_time_setting( $value, $name ) { } /** - * @param mixed $value + * @param mixed $value * @param string $name */ protected function set_preload_setting( $value, $name ) { @@ -494,7 +503,7 @@ protected function toggle_easy_caching( $enabled = true ) { 'wp_cache_object_cache', 'wp_cache_refresh_single_only', 'cache_compression', - 'wp_cache_mutex_disabled' + 'wp_cache_mutex_disabled', ); foreach ( $advanced_settings as $setting ) { @@ -519,7 +528,7 @@ protected function save_time_settings( $parameters ) { 'cache_scheduled_time', 'cache_schedule_interval', 'cache_time_interval', - 'cache_gc_email_me' + 'cache_gc_email_me', ); foreach ( $all_time_settings as $time_setting ) { @@ -531,12 +540,11 @@ protected function save_time_settings( $parameters ) { if ( isset( $parameters['cache_gc_email_me'] ) && $parameters['cache_gc_email_me'] == 0 ) { unset( $_POST['cache_gc_email_me'] ); } - $_POST[ 'wp_max_time' ] = $_POST[ 'cache_max_time' ]; + $_POST['wp_max_time'] = $_POST['cache_max_time']; wp_cache_time_update(); } - /** * set the cached direct pages list. */ @@ -545,7 +553,7 @@ protected function set_cache_direct_pages( $list ) { return false; } - $_POST[ 'direct_pages' ] = $list; + $_POST['direct_pages'] = $list; wpsc_update_direct_pages(); } @@ -555,11 +563,11 @@ protected function set_cache_direct_pages( $list ) { protected function new_direct_page( $value ) { global $cached_direct_pages; - if ( isset( $_POST[ 'direct_pages' ] ) == false ) { - $_POST[ 'direct_pages' ] = $cached_direct_pages; + if ( isset( $_POST['direct_pages'] ) == false ) { + $_POST['direct_pages'] = $cached_direct_pages; } - $_POST[ 'new_direct_page' ] = $value; + $_POST['new_direct_page'] = $value; wpsc_update_direct_pages(); } @@ -589,7 +597,6 @@ protected function save_preload_settings() { if ( $key !== 'preload_interval' && ( $_POST[ $key ] === 0 || $_POST[ $key ] === false ) ) { unset( $_POST[ $original ] ); } - } } @@ -607,7 +614,7 @@ protected function restore_default_settings( $parameters ) { $cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() ); wp_cache_setting( 'cache_page_secret', $cache_page_secret ); - if ( function_exists( "opcache_invalidate" ) ) { + if ( function_exists( 'opcache_invalidate' ) ) { @opcache_invalidate( $wp_cache_config_file ); } } @@ -623,7 +630,7 @@ protected function restore_default_settings( $parameters ) { */ public function set_debug_settings( $parameters ) { - $settings = array ( + $settings = array( 'wp_super_cache_debug', 'wp_cache_debug_ip', 'wp_super_cache_comments', @@ -634,12 +641,12 @@ public function set_debug_settings( $parameters ) { 'wpsc_delete_log', ); - foreach( $settings as $setting ) { + foreach ( $settings as $setting ) { if ( isset( $parameters[ $setting ] ) ) { if ( $parameters[ $setting ] != false ) { $_POST[ $setting ] = $parameters[ $setting ]; } - $_POST[ 'wp_cache_debug' ] = 1; + $_POST['wp_cache_debug'] = 1; } else { if ( ! isset( $GLOBALS[ $setting ] ) ) { $GLOBALS[ $setting ] = 0; diff --git a/rest/class.wp-super-cache-settings-map.php b/rest/class.wp-super-cache-settings-map.php index 4eec197c3..1bbd96855 100644 --- a/rest/class.wp-super-cache-settings-map.php +++ b/rest/class.wp-super-cache-settings-map.php @@ -15,245 +15,245 @@ class WP_Super_Cache_Settings_Map { * @var array */ public static $map = array( - 'is_submit_enabled' => array( + 'is_submit_enabled' => array( 'get' => 'get_is_submit_enabled', 'set' => '', ), - 'is_preload_enabled' => array( + 'is_preload_enabled' => array( 'get' => 'get_is_preload_enabled', 'set' => '', ), - 'cache_lock_down' => array( + 'cache_lock_down' => array( 'get' => 'get_is_lock_down_enabled', 'set' => 'set_lock_down', ), - 'cache_next_gc' => array( + 'cache_next_gc' => array( 'get' => 'get_next_gc', 'set' => '', ), - 'cache_gc_email_me' => array( + 'cache_gc_email_me' => array( 'global' => 'cache_gc_email_me', - 'set' => 'set_time_setting', + 'set' => 'set_time_setting', ), - 'cache_path_url' => array( + 'cache_path_url' => array( 'get' => 'get_cache_path_url', ), - 'cache_type' => array( + 'cache_type' => array( 'get' => 'get_cache_type', 'set' => 'set_super_cache_enabled', ), - 'is_preloading' => array( + 'is_preloading' => array( 'get' => 'wpsc_is_preloading', 'set' => '', ), - 'post_count' => array( + 'post_count' => array( 'get' => 'get_post_count', 'set' => '', ), - 'is_cache_enabled' => array( + 'is_cache_enabled' => array( 'global' => 'cache_enabled', 'set' => 'set_cache_enabled', ), - 'is_super_cache_enabled' => array( + 'is_super_cache_enabled' => array( 'global' => 'super_cache_enabled', 'set' => 'set_super_cache_enabled', ), - 'is_mobile_enabled' => array( + 'is_mobile_enabled' => array( 'global' => 'wp_cache_mobile_enabled', ), - 'is_mfunc_enabled' => array( + 'is_mfunc_enabled' => array( 'global' => 'wp_cache_mfunc_enabled', ), - 'cache_list' => array( + 'cache_list' => array( 'global' => 'wp_supercache_cache_list', ), - 'clear_cache_on_post_edit' => array( + 'clear_cache_on_post_edit' => array( 'global' => 'wp_cache_clear_on_post_edit', ), - 'wpsc_save_headers' => array( + 'wpsc_save_headers' => array( 'global' => 'wpsc_save_headers', ), - 'cache_rebuild' => array( + 'cache_rebuild' => array( 'global' => 'cache_rebuild_files', ), - 'dont_cache_logged_in' => array( + 'dont_cache_logged_in' => array( 'global' => 'wp_cache_not_logged_in', ), - 'make_known_anon' => array( + 'make_known_anon' => array( 'global' => 'wp_cache_make_known_anon', ), - 'cache_path' => array( + 'cache_path' => array( 'global' => 'cache_path', 'set' => 'set_wp_cache_location', ), - 'default_cache_path' => array( + 'default_cache_path' => array( 'get' => 'get_default_cache_path', ), - 'use_object_cache' => array( + 'use_object_cache' => array( 'global' => 'wp_cache_object_cache', ), - 'refresh_current_only_on_comments' => array( + 'refresh_current_only_on_comments' => array( 'global' => 'wp_cache_refresh_single_only', ), - 'cache_compression' => array( + 'cache_compression' => array( 'global' => 'cache_compression', 'set' => 'set_cache_compression', ), - 'cache_mod_rewrite' => array( + 'cache_mod_rewrite' => array( 'global' => 'wp_cache_mod_rewrite', ), - 'use_304_headers' => array( + 'use_304_headers' => array( 'global' => 'wp_supercache_304', ), - 'cache_late_init' => array( + 'cache_late_init' => array( 'global' => 'wp_super_cache_late_init', ), - 'front_page_checks' => array( + 'front_page_checks' => array( 'global' => 'wp_cache_front_page_checks', ), - 'cache_page_secret' => array( + 'cache_page_secret' => array( 'global' => 'cache_page_secret', ), - 'disable_utf8' => array( + 'disable_utf8' => array( 'global' => 'wp_cache_disable_utf8', ), - 'no_cache_for_get' => array( + 'no_cache_for_get' => array( 'global' => 'wp_cache_no_cache_for_get', ), - 'cache_schedule_type' => array( + 'cache_schedule_type' => array( 'global' => 'cache_schedule_type', - 'set' => 'set_time_setting', + 'set' => 'set_time_setting', ), - 'cache_scheduled_time' => array( + 'cache_scheduled_time' => array( 'global' => 'cache_scheduled_time', - 'set' => 'set_time_setting', + 'set' => 'set_time_setting', ), - 'cache_max_time' => array( + 'cache_max_time' => array( 'global' => 'cache_max_time', - 'set' => 'set_time_setting', + 'set' => 'set_time_setting', ), - 'cache_time_interval' => array( + 'cache_time_interval' => array( 'global' => 'cache_time_interval', - 'set' => 'set_time_setting', + 'set' => 'set_time_setting', ), - 'shutdown_garbage_collector' => array( + 'shutdown_garbage_collector' => array( 'global' => 'wp_cache_shutdown_gc', ), - 'pages' => array( + 'pages' => array( 'global' => 'wp_cache_pages', ), - 'minimum_preload_interval' => array( + 'minimum_preload_interval' => array( 'get' => 'get_minimum_preload_interval', ), - 'preload_interval' => array( + 'preload_interval' => array( 'global' => 'wp_cache_preload_interval', - 'set' => 'set_preload_setting', + 'set' => 'set_preload_setting', ), - 'preload_posts' => array( + 'preload_posts' => array( 'global' => 'wp_cache_preload_posts', - 'set' => 'set_preload_setting', + 'set' => 'set_preload_setting', ), - 'preload_on' => array( + 'preload_on' => array( 'global' => 'wp_cache_preload_on', - 'set' => 'set_preload_setting', + 'set' => 'set_preload_setting', ), - 'preload_active' => array( + 'preload_active' => array( 'get' => 'get_is_preload_active', ), - 'preload_taxonomies' => array( + 'preload_taxonomies' => array( 'global' => 'wp_cache_preload_taxonomies', - 'set' => 'set_preload_setting', + 'set' => 'set_preload_setting', ), - 'preload_email_me' => array( + 'preload_email_me' => array( 'global' => 'wp_cache_preload_email_me', - 'set' => 'set_preload_setting', + 'set' => 'set_preload_setting', ), - 'preload_email_volume' => array( + 'preload_email_volume' => array( 'global' => 'wp_cache_preload_email_volume', - 'set' => 'set_preload_setting', + 'set' => 'set_preload_setting', ), - 'cache_mobile_browsers' => array( + 'cache_mobile_browsers' => array( 'global' => 'wp_cache_mobile_browsers', ), - 'cache_mobile_prefixes' => array( + 'cache_mobile_prefixes' => array( 'global' => 'wp_cache_mobile_prefixes', ), - 'cache_disable_locking' => array( + 'cache_disable_locking' => array( 'global' => 'wp_cache_mutex_disabled', ), - 'cache_hello_world' => array( + 'cache_hello_world' => array( 'global' => 'wp_cache_hello_world', ), - 'cache_schedule_interval' => array( + 'cache_schedule_interval' => array( 'global' => 'cache_schedule_interval', - 'set' => 'set_time_setting', + 'set' => 'set_time_setting', ), - 'cache_acceptable_files' => array( + 'cache_acceptable_files' => array( 'global' => 'cache_acceptable_files', ), - 'cache_rejected_uri' => array( + 'cache_rejected_uri' => array( 'global' => 'cache_rejected_uri', ), - 'cache_rejected_user_agent' => array( + 'cache_rejected_user_agent' => array( 'global' => 'cache_rejected_user_agent', ), - 'cache_direct_pages' => array( + 'cache_direct_pages' => array( 'global' => 'cached_direct_pages', 'set' => 'set_cache_direct_pages', ), - 'new_direct_page' => array( + 'new_direct_page' => array( 'set' => 'new_direct_page', ), - 'ossdl_cname' => array( + 'ossdl_cname' => array( 'option' => 'ossdl_cname', 'set' => 'set_ossdl_cname', ), - 'ossdl_https' => array( + 'ossdl_https' => array( 'option' => 'ossdl_https', 'set' => 'set_ossdl_https', ), - 'ossdl_off_cdn_url' => array( + 'ossdl_off_cdn_url' => array( 'option' => 'ossdl_off_cdn_url', 'set' => 'set_ossdl_off_cdn_url', ), - 'ossdl_off_blog_url' => array( + 'ossdl_off_blog_url' => array( 'option' => 'ossdl_off_blog_url', 'set' => 'set_ossdl_off_blog_url', ), - 'ossdl_off_exclude' => array( + 'ossdl_off_exclude' => array( 'option' => 'ossdl_off_exclude', 'set' => 'set_ossdl_off_exclude', ), - 'ossdl_off_include_dirs' => array( + 'ossdl_off_include_dirs' => array( 'option' => 'ossdl_off_include_dirs', 'set' => 'set_ossdl_off_include_dirs', ), - 'ossdlcdn' => array( + 'ossdlcdn' => array( 'global' => 'ossdlcdn', 'set' => 'set_ossdlcdn', ), - 'wp_super_cache_debug' => array( + 'wp_super_cache_debug' => array( 'global' => 'wp_super_cache_debug', ), - 'wp_cache_debug_username' => array( + 'wp_cache_debug_username' => array( 'get' => 'wpsc_debug_username', ), - 'wp_cache_debug_log' => array( - 'global' => 'wp_cache_debug_log', + 'wp_cache_debug_log' => array( + 'global' => 'wp_cache_debug_log', ), - 'wp_cache_debug_ip' => array( + 'wp_cache_debug_ip' => array( 'global' => 'wp_cache_debug_ip', ), - 'wp_super_cache_comments' => array( + 'wp_super_cache_comments' => array( 'global' => 'wp_super_cache_comments', ), - 'wp_super_cache_front_page_check' => array( + 'wp_super_cache_front_page_check' => array( 'global' => 'wp_super_cache_front_page_check', ), - 'wp_super_cache_front_page_clear' => array( + 'wp_super_cache_front_page_clear' => array( 'global' => 'wp_super_cache_front_page_clear', ), - 'wp_super_cache_front_page_text' => array( + 'wp_super_cache_front_page_text' => array( 'global' => 'wp_super_cache_front_page_text', ), 'wp_super_cache_front_page_notification' => array( diff --git a/rest/load.php b/rest/load.php index 8f2f171b2..bedf315d8 100644 --- a/rest/load.php +++ b/rest/load.php @@ -1,15 +1,15 @@ WP_REST_Server::READABLE, - 'callback' => array( $get_settings, 'callback' ), - 'permission_callback' => __CLASS__ . '::get_item_permissions_check', - 'args' => array(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $update_settings, 'callback' ), - 'permission_callback' => __CLASS__ . '::update_item_permissions_check', - 'args' => array(), - ), - ) ); - - register_rest_route( $namespace, '/status', array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $get_status, 'callback' ), - 'permission_callback' => __CLASS__ . '::get_item_permissions_check', - ) ); - - register_rest_route( $namespace, '/stats', array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $get_stats, 'callback' ), - 'permission_callback' => __CLASS__ . '::get_item_permissions_check', - ) ); - - register_rest_route( $namespace, '/cache', array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $get_settings, 'callback' ), + 'permission_callback' => __CLASS__ . '::get_item_permissions_check', + 'args' => array(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $update_settings, 'callback' ), + 'permission_callback' => __CLASS__ . '::update_item_permissions_check', + 'args' => array(), + ), + ) + ); + + register_rest_route( + $namespace, + '/status', array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $get_cache, 'callback' ), + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $get_status, 'callback' ), 'permission_callback' => __CLASS__ . '::get_item_permissions_check', - 'args' => array(), - ), - array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $delete_cache, 'callback' ), - 'permission_callback' => __CLASS__ . '::delete_item_permissions_check', - 'args' => array(), - ), - ) ); - - register_rest_route( $namespace, '/preload', array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $preload_cache, 'callback' ), - 'permission_callback' => __CLASS__ . '::update_item_permissions_check', - ) ); - - register_rest_route( $namespace, '/cache/test', array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $test_cache, 'callback' ), - 'permission_callback' => __CLASS__ . '::create_item_permissions_check', - ) ); - - register_rest_route( $namespace, '/plugins', array( + ) + ); + + register_rest_route( + $namespace, + '/stats', array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $get_plugins, 'callback' ), + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $get_stats, 'callback' ), 'permission_callback' => __CLASS__ . '::get_item_permissions_check', - 'args' => array(), - ), + ) + ); + + register_rest_route( + $namespace, + '/cache', + array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $get_cache, 'callback' ), + 'permission_callback' => __CLASS__ . '::get_item_permissions_check', + 'args' => array(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $delete_cache, 'callback' ), + 'permission_callback' => __CLASS__ . '::delete_item_permissions_check', + 'args' => array(), + ), + ) + ); + + register_rest_route( + $namespace, + '/preload', array( - 'methods' => WP_REST_Server::CREATABLE, - 'callback' => array( $update_plugins, 'callback' ), + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $preload_cache, 'callback' ), 'permission_callback' => __CLASS__ . '::update_item_permissions_check', - 'args' => array(), - ), - ) ); + ) + ); + + register_rest_route( + $namespace, + '/cache/test', + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $test_cache, 'callback' ), + 'permission_callback' => __CLASS__ . '::create_item_permissions_check', + ) + ); + + register_rest_route( + $namespace, + '/plugins', + array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $get_plugins, 'callback' ), + 'permission_callback' => __CLASS__ . '::get_item_permissions_check', + 'args' => array(), + ), + array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => array( $update_plugins, 'callback' ), + 'permission_callback' => __CLASS__ . '::update_item_permissions_check', + 'args' => array(), + ), + ) + ); } @@ -161,7 +189,7 @@ public static function delete_item_permissions_check( $request ) { } function wpsc_load_rest_api() { - $wpsupercache_route = new WP_Super_Cache_Router; + $wpsupercache_route = new WP_Super_Cache_Router(); $wpsupercache_route->register_routes(); }; diff --git a/wp-cache-config-sample.php b/wp-cache-config-sample.php index 87ed823ae..66f63eb87 100644 --- a/wp-cache-config-sample.php +++ b/wp-cache-config-sample.php @@ -5,23 +5,31 @@ See wp-cache.php for author details. */ -if ( ! defined('WPCACHEHOME') ) +if ( ! defined( 'WPCACHEHOME' ) ) { define( 'WPCACHEHOME', WP_PLUGIN_DIR . '/wp-super-cache/' ); +} -$cache_compression = 0; // Super cache compression -$cache_enabled = false; +$cache_compression = 0; // Super cache compression +$cache_enabled = false; $super_cache_enabled = true; -$cache_max_time = 3600; //in seconds -//$use_flock = true; // Set it true or false if you know what to use -$cache_path = WP_CONTENT_DIR . '/cache/'; +$cache_max_time = 3600; // in seconds +// $use_flock = true; // Set it true or false if you know what to use +$cache_path = WP_CONTENT_DIR . '/cache/'; $file_prefix = 'wp-cache-'; -$ossdlcdn = 0; +$ossdlcdn = 0; // Array of files that have 'wp-' but should still be cached $cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' ); -$cache_rejected_uri = array('wp-.*\\.php', 'index\\.php'); -$cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider', 5 => 'Yandex' ); +$cache_rejected_uri = array( 'wp-.*\\.php', 'index\\.php' ); +$cache_rejected_user_agent = array( + 0 => 'bot', + 1 => 'ia_archive', + 2 => 'slurp', + 3 => 'crawl', + 4 => 'spider', + 5 => 'Yandex', +); $cache_rebuild_files = 1; @@ -33,73 +41,73 @@ // Just modify it if you have conflicts with semaphores $sem_id = 5419; -if ( '/' != substr($cache_path, -1)) { +if ( '/' != substr( $cache_path, -1 ) ) { $cache_path .= '/'; } -$wp_cache_mobile = 0; +$wp_cache_mobile = 0; $wp_cache_mobile_whitelist = 'Stand Alone/QNws'; -$wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP'; +$wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP'; // change to relocate the supercache plugins directory $wp_cache_plugins_dir = WPCACHEHOME . 'plugins'; // set to 1 to do garbage collection during normal process shutdown instead of wp-cron -$wp_cache_shutdown_gc = 0; +$wp_cache_shutdown_gc = 0; $wp_super_cache_late_init = 0; // uncomment the next line to enable advanced debugging features -$wp_super_cache_advanced_debug = 0; -$wp_super_cache_front_page_text = ''; -$wp_super_cache_front_page_clear = 0; -$wp_super_cache_front_page_check = 0; +$wp_super_cache_advanced_debug = 0; +$wp_super_cache_front_page_text = ''; +$wp_super_cache_front_page_clear = 0; +$wp_super_cache_front_page_check = 0; $wp_super_cache_front_page_notification = '0'; -$wp_cache_anon_only = 0; -$wp_supercache_cache_list = 0; -$wp_cache_debug_to_file = 0; -$wp_super_cache_debug = 0; -$wp_cache_debug_level = 5; -$wp_cache_debug_ip = ''; -$wp_cache_debug_log = ''; -$wp_cache_debug_email = ''; -$wp_cache_pages[ "search" ] = 0; -$wp_cache_pages[ "feed" ] = 0; -$wp_cache_pages[ "category" ] = 0; -$wp_cache_pages[ "home" ] = 0; -$wp_cache_pages[ "frontpage" ] = 0; -$wp_cache_pages[ "tag" ] = 0; -$wp_cache_pages[ "archives" ] = 0; -$wp_cache_pages[ "pages" ] = 0; -$wp_cache_pages[ "single" ] = 0; -$wp_cache_pages[ "author" ] = 0; -$wp_cache_hide_donation = 0; -$wp_cache_not_logged_in = 0; -$wp_cache_clear_on_post_edit = 0; -$wp_cache_hello_world = 0; -$wp_cache_mobile_enabled = 0; -$wp_cache_cron_check = 0; -$wp_cache_mfunc_enabled = 0; -$wp_cache_make_known_anon = 0; -$wp_cache_refresh_single_only = 0; -$wp_cache_mod_rewrite = 0; -$wp_supercache_304 = 0; -$wp_cache_front_page_checks = 0; -$wp_cache_disable_utf8 = 0; -$wp_cache_no_cache_for_get = 0; -$cache_scheduled_time = "00:00"; -$wp_cache_preload_interval = 600; -$cache_schedule_type = 'interval'; -$wp_cache_preload_posts = 0; -$wp_cache_preload_on = 0; -$wp_cache_preload_taxonomies = 0; -$wp_cache_preload_email_me = 0; +$wp_cache_anon_only = 0; +$wp_supercache_cache_list = 0; +$wp_cache_debug_to_file = 0; +$wp_super_cache_debug = 0; +$wp_cache_debug_level = 5; +$wp_cache_debug_ip = ''; +$wp_cache_debug_log = ''; +$wp_cache_debug_email = ''; +$wp_cache_pages['search'] = 0; +$wp_cache_pages['feed'] = 0; +$wp_cache_pages['category'] = 0; +$wp_cache_pages['home'] = 0; +$wp_cache_pages['frontpage'] = 0; +$wp_cache_pages['tag'] = 0; +$wp_cache_pages['archives'] = 0; +$wp_cache_pages['pages'] = 0; +$wp_cache_pages['single'] = 0; +$wp_cache_pages['author'] = 0; +$wp_cache_hide_donation = 0; +$wp_cache_not_logged_in = 0; +$wp_cache_clear_on_post_edit = 0; +$wp_cache_hello_world = 0; +$wp_cache_mobile_enabled = 0; +$wp_cache_cron_check = 0; +$wp_cache_mfunc_enabled = 0; +$wp_cache_make_known_anon = 0; +$wp_cache_refresh_single_only = 0; +$wp_cache_mod_rewrite = 0; +$wp_supercache_304 = 0; +$wp_cache_front_page_checks = 0; +$wp_cache_disable_utf8 = 0; +$wp_cache_no_cache_for_get = 0; +$cache_scheduled_time = '00:00'; +$wp_cache_preload_interval = 600; +$cache_schedule_type = 'interval'; +$wp_cache_preload_posts = 0; +$wp_cache_preload_on = 0; +$wp_cache_preload_taxonomies = 0; +$wp_cache_preload_email_me = 0; $wp_cache_preload_email_volume = 'none'; -$wp_cache_mobile_prefixes = ''; -$cached_direct_pages = array(); -$wpsc_served_header = false; -$cache_gc_email_me = 0; -$wpsc_save_headers = 0; -$cache_schedule_interval = 'daily'; -$wp_super_cache_comments = 1; -$wpsc_version = 169; -?> +$wp_cache_mobile_prefixes = ''; +$cached_direct_pages = array(); +$wpsc_served_header = false; +$cache_gc_email_me = 0; +$wpsc_save_headers = 0; +$cache_schedule_interval = 'daily'; +$wp_super_cache_comments = 1; +$wpsc_version = 169; + diff --git a/wp-cache-phase1.php b/wp-cache-phase1.php index d638f351a..4429c93e7 100644 --- a/wp-cache-phase1.php +++ b/wp-cache-phase1.php @@ -1,7 +1,7 @@ 0 && ( filemtime( $file ) + $cache_max_time ) < time() ) { - wp_cache_debug( sprintf( "Cache has expired and is older than %d seconds old.", $cache_max_time ) ); + wp_cache_debug( sprintf( 'Cache has expired and is older than %d seconds old.', $cache_max_time ) ); return false; } - if ( isset( $wp_cache_mfunc_enabled ) == false ) + if ( isset( $wp_cache_mfunc_enabled ) == false ) { $wp_cache_mfunc_enabled = 0; + } - if ( false == isset( $wp_cache_home_path ) ) + if ( false == isset( $wp_cache_home_path ) ) { $wp_cache_home_path = '/'; + } // make sure ending slashes are ok if ( $wp_cache_request_uri == $wp_cache_home_path || ( $wp_cache_slash_check && substr( $wp_cache_request_uri, -1 ) == '/' ) || ( $wp_cache_slash_check == 0 && substr( $wp_cache_request_uri, -1 ) != '/' ) ) { @@ -147,53 +153,54 @@ function wp_cache_serve_cache_file() { } } - if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) - header( "Content-type: text/html; charset=UTF-8" ); + if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) { + header( 'Content-type: text/html; charset=UTF-8' ); + } if ( defined( 'WPSC_VARY_HEADER' ) ) { if ( WPSC_VARY_HEADER != '' ) { - header( "Vary: " . WPSC_VARY_HEADER ); + header( 'Vary: ' . WPSC_VARY_HEADER ); } } else { - header( "Vary: Accept-Encoding, Cookie" ); + header( 'Vary: Accept-Encoding, Cookie' ); } if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) ) { if ( WPSC_CACHE_CONTROL_HEADER != '' ) { - header( "Cache-Control: " . WPSC_CACHE_CONTROL_HEADER ); + header( 'Cache-Control: ' . WPSC_CACHE_CONTROL_HEADER ); } } else { - header( "Cache-Control: max-age=3, must-revalidate" ); + header( 'Cache-Control: max-age=3, must-revalidate' ); } $size = function_exists( 'mb_strlen' ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata ); if ( $wp_cache_gzip_encoding ) { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { - header( "X-WP-Super-Cache: Served supercache gzip file from PHP" ); + header( 'X-WP-Super-Cache: Served supercache gzip file from PHP' ); } header( 'Content-Encoding: ' . $wp_cache_gzip_encoding ); header( 'Content-Length: ' . $size ); } elseif ( $wp_supercache_304 ) { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { - header( "X-WP-Super-Cache: Served supercache 304 file from PHP" ); + header( 'X-WP-Super-Cache: Served supercache 304 file from PHP' ); } header( 'Content-Length: ' . $size ); } else { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { - header( "X-WP-Super-Cache: Served supercache file from PHP" ); + header( 'X-WP-Super-Cache: Served supercache file from PHP' ); } } // don't try to match modified dates if using dynamic code. if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) { $headers = apache_request_headers(); - $remote_mod_time = isset ( $headers['If-Modified-Since'] ) ? $headers['If-Modified-Since'] : null; + $remote_mod_time = isset( $headers['If-Modified-Since'] ) ? $headers['If-Modified-Since'] : null; if ( is_null( $remote_mod_time ) && isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { $remote_mod_time = $_SERVER['HTTP_IF_MODIFIED_SINCE']; } - $local_mod_time = gmdate("D, d M Y H:i:s",filemtime( $file )).' GMT'; + $local_mod_time = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ) . ' GMT'; if ( ! is_null( $remote_mod_time ) && $remote_mod_time == $local_mod_time ) { - header( $_SERVER[ 'SERVER_PROTOCOL' ] . " 304 Not Modified" ); + header( $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified' ); exit(); } header( 'Last-Modified: ' . $local_mod_time ); @@ -208,13 +215,13 @@ function wp_cache_serve_cache_file() { $cache_file = do_cacheaction( 'wp_cache_served_cache_file', $cache_file ); // Sometimes the gzip headers are lost. Make sure html returned isn't compressed! - if ( $cache_compression && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta[ 'headers' ] ) ) { + if ( $cache_compression && $wp_cache_gzip_encoding && ! in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $meta['headers'] ) ) { $ungzip = true; wp_cache_debug( 'GZIP headers not found. Force uncompressed output.', 1 ); } else { $ungzip = false; } - foreach ( $meta[ 'headers' ] as $t => $header) { + foreach ( $meta['headers'] as $t => $header ) { // godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/ if ( strpos( $header, 'Last-Modified:' ) === false ) { header( $header ); @@ -223,11 +230,11 @@ function wp_cache_serve_cache_file() { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { header( 'X-WP-Super-Cache: Served WPCache cache file' ); } - if ( isset( $meta[ 'dynamic' ] ) ) { + if ( isset( $meta['dynamic'] ) ) { wp_cache_debug( 'Serving wp-cache dynamic file', 5 ); if ( $ungzip ) { // attempt to uncompress the cached file just in case it's gzipped - $cache = wp_cache_get_legacy_cache( $cache_file ); + $cache = wp_cache_get_legacy_cache( $cache_file ); $uncompressed = @gzuncompress( $cache ); if ( $uncompressed ) { wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); @@ -242,7 +249,7 @@ function wp_cache_serve_cache_file() { } else { wp_cache_debug( 'Serving wp-cache static file', 5 ); if ( $ungzip ) { - $cache = wp_cache_get_legacy_cache( $cache_file ); + $cache = wp_cache_get_legacy_cache( $cache_file ); $uncompressed = gzuncompress( $cache ); if ( $uncompressed ) { wp_cache_debug( 'Uncompressed gzipped cache file from wp-cache', 1 ); @@ -267,8 +274,9 @@ function wp_cache_get_legacy_cache( $cache_file ) { function wp_cache_postload() { global $cache_enabled, $wp_super_cache_late_init; - if ( !$cache_enabled ) + if ( ! $cache_enabled ) { return true; + } if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) { wp_cache_debug( 'Supercache Late Init: add wp_cache_serve_cache_file to init', 3 ); @@ -379,24 +387,26 @@ function wp_cache_get_cookies_values() { return $string; } - if ( defined( 'COOKIEHASH' ) ) + if ( defined( 'COOKIEHASH' ) ) { $cookiehash = preg_quote( constant( 'COOKIEHASH' ) ); - else + } else { $cookiehash = ''; + } $regex = "/^wp-postpass_$cookiehash|^comment_author_$cookiehash"; - if ( defined( 'LOGGED_IN_COOKIE' ) ) - $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) ); - else + if ( defined( 'LOGGED_IN_COOKIE' ) ) { + $regex .= '|^' . preg_quote( constant( 'LOGGED_IN_COOKIE' ) ); + } else { $regex .= "|^wordpress_logged_in_$cookiehash"; - $regex .= "/"; - while ($key = key($_COOKIE)) { + } + $regex .= '/'; + while ( $key = key( $_COOKIE ) ) { if ( preg_match( $regex, $key ) ) { - wp_cache_debug( "wp_cache_get_cookies_values: Login/postpass cookie detected" ); - $string .= $_COOKIE[ $key ] . ","; + wp_cache_debug( 'wp_cache_get_cookies_values: Login/postpass cookie detected' ); + $string .= $_COOKIE[ $key ] . ','; } - next($_COOKIE); + next( $_COOKIE ); } - reset($_COOKIE); + reset( $_COOKIE ); // If you use this hook, make sure you update your .htaccess rules with the same conditions $string = do_cacheaction( 'wp_cache_get_cookies_values', $string ); @@ -406,16 +416,17 @@ function wp_cache_get_cookies_values() { is_array( $wpsc_cookies ) && ! empty( $wpsc_cookies ) ) { - foreach( $wpsc_cookies as $name ) { + foreach ( $wpsc_cookies as $name ) { if ( isset( $_COOKIE[ $name ] ) ) { wp_cache_debug( "wp_cache_get_cookies_values - found extra cookie: $name" ); - $string .= $name . "=" . $_COOKIE[ $name ] . ","; + $string .= $name . '=' . $_COOKIE[ $name ] . ','; } } } - if ( $string != '' ) + if ( $string != '' ) { $string = md5( $string ); + } wp_cache_debug( "wp_cache_get_cookies_values: return: $string", 5 ); return $string; @@ -429,12 +440,13 @@ function add_cacheaction( $action, $func ) { function do_cacheaction( $action, $value = '' ) { global $wp_supercache_actions; - if ( !isset( $wp_supercache_actions ) || !is_array( $wp_supercache_actions ) ) + if ( ! isset( $wp_supercache_actions ) || ! is_array( $wp_supercache_actions ) ) { return $value; + } - if( array_key_exists($action, $wp_supercache_actions) && is_array( $wp_supercache_actions[ $action ] ) ) { + if ( array_key_exists( $action, $wp_supercache_actions ) && is_array( $wp_supercache_actions[ $action ] ) ) { $actions = $wp_supercache_actions[ $action ]; - foreach( $actions as $func ) { + foreach ( $actions as $func ) { $value = call_user_func_array( $func, array( $value ) ); } } @@ -444,38 +456,39 @@ function do_cacheaction( $action, $value = '' ) { function wp_cache_mobile_group( $user_agent ) { global $wp_cache_mobile_groups; - foreach( (array)$wp_cache_mobile_groups as $name => $group ) { - foreach( (array)$group as $browser ) { + foreach ( (array) $wp_cache_mobile_groups as $name => $group ) { + foreach ( (array) $group as $browser ) { $browser = trim( strtolower( $browser ) ); if ( $browser != '' && strstr( $user_agent, $browser ) ) { return $browser; } } } - return "mobile"; + return 'mobile'; } // From https://wordpress.org/plugins/wordpress-mobile-edition/ by Alex King function wp_cache_check_mobile( $cache_key ) { global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes; - if ( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled ) + if ( ! isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled ) { return $cache_key; + } wp_cache_debug( "wp_cache_check_mobile: $cache_key" ); // allow plugins to short circuit mobile check. Cookie, extra UA checks? - switch( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) { - case "normal": - wp_cache_debug( 'wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action' ); - return $cache_key; + switch ( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) { + case 'normal': + wp_cache_debug( 'wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action' ); + return $cache_key; break; - case "mobile": - wp_cache_debug( 'wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action' ); - return $cache_key . "-mobile"; + case 'mobile': + wp_cache_debug( 'wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action' ); + return $cache_key . '-mobile'; break; } - if ( !isset( $_SERVER[ "HTTP_USER_AGENT" ] ) ) { + if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { return $cache_key; } @@ -484,34 +497,36 @@ function wp_cache_check_mobile( $cache_key ) { return $cache_key; } - $browsers = explode( ',', $wp_cache_mobile_browsers ); + $browsers = explode( ',', $wp_cache_mobile_browsers ); $user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); - foreach ($browsers as $browser) { + foreach ( $browsers as $browser ) { if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) { wp_cache_debug( 'mobile browser detected: ' . $browser ); return $cache_key . '-' . wp_cache_mobile_group( $user_agent ); } } - if (isset($_SERVER['HTTP_X_WAP_PROFILE']) ) + if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) { return $cache_key . '-' . $_SERVER['HTTP_X_WAP_PROFILE']; - if (isset($_SERVER['HTTP_PROFILE']) ) + } + if ( isset( $_SERVER['HTTP_PROFILE'] ) ) { return $cache_key . '-' . $_SERVER['HTTP_PROFILE']; + } if ( isset( $wp_cache_mobile_prefixes ) ) { $browsers = explode( ',', $wp_cache_mobile_prefixes ); - foreach ($browsers as $browser_prefix) { - if ( substr($user_agent, 0, 4) == $browser_prefix ) { + foreach ( $browsers as $browser_prefix ) { + if ( substr( $user_agent, 0, 4 ) == $browser_prefix ) { wp_cache_debug( 'mobile browser (prefix) detected: ' . $browser_prefix ); return $cache_key . '-' . $browser_prefix; } } } - $accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : ''; - if (strpos($accept, 'wap') !== false) { + $accept = isset( $_SERVER['HTTP_ACCEPT'] ) ? strtolower( $_SERVER['HTTP_ACCEPT'] ) : ''; + if ( strpos( $accept, 'wap' ) !== false ) { return $cache_key . '-' . 'wap'; } - if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) { + if ( isset( $_SERVER['ALL_HTTP'] ) && strpos( strtolower( $_SERVER['ALL_HTTP'] ), 'operamini' ) !== false ) { return $cache_key . '-' . 'operamini'; } @@ -534,26 +549,29 @@ function wp_cache_debug( $message, $level = 1 ) { $last_message = $message; // If either of the debug or log globals aren't set, then we can stop - if ( !isset($wp_super_cache_debug) - || !isset($wp_cache_debug_log) ) + if ( ! isset( $wp_super_cache_debug ) + || ! isset( $wp_cache_debug_log ) ) { return false; + } // If either the debug or log globals are false or empty, we can stop if ( $wp_super_cache_debug == false - || $wp_cache_debug_log == '' ) + || $wp_cache_debug_log == '' ) { return false; + } // If the debug_ip has been set, but it doesn't match the ip of the requester // then we can stop. - if ( isset($wp_cache_debug_ip) + if ( isset( $wp_cache_debug_ip ) && $wp_cache_debug_ip != '' - && $wp_cache_debug_ip != $_SERVER[ 'REMOTE_ADDR' ] ) + && $wp_cache_debug_ip != $_SERVER['REMOTE_ADDR'] ) { return false; + } // Log message: Date URI Message - $log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL; + $log_message = date( 'H:i:s' ) . ' ' . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL; // path to the log file in the cache folder - $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); + $log_file = $cache_path . str_replace( '/', '', str_replace( '..', '', $wp_cache_debug_log ) ); if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) { global $wp_cache_debug_username; @@ -570,7 +588,7 @@ function wp_cache_debug( $message, $level = 1 ) { function wpsc_dump_get_request() { static $string; - if ( isset( $string) ) { + if ( isset( $string ) ) { return $string; } @@ -628,7 +646,7 @@ function get_current_url_supercache_dir( $post_id = 0 ) { $DONOTREMEMBER = 0; if ( $post_id != 0 ) { - $site_url = site_url(); + $site_url = site_url(); $permalink = get_permalink( $post_id ); if ( false === strpos( $permalink, $site_url ) ) { /* @@ -651,32 +669,34 @@ function get_current_url_supercache_dir( $post_id = 0 ) { } } else { $uri = str_replace( $site_url, '', $permalink ); - if ( strpos( $uri, $wp_cache_home_path ) !== 0 ) + if ( strpos( $uri, $wp_cache_home_path ) !== 0 ) { $uri = rtrim( $wp_cache_home_path, '/' ) . $uri; + } } } else { $uri = strtolower( $wp_cache_request_uri ); } - $uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?(#.*)?$/", '', $uri ) ) ); + $uri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( '/(\?.*)?(#.*)?$/', '', $uri ) ) ); $hostname = $WPSC_HTTP_HOST; // Get hostname from wp options for wp-cron, wp-cli and similar requests. if ( empty( $hostname ) && function_exists( 'get_option' ) ) { $hostname = (string) parse_url( get_option( 'home' ), PHP_URL_HOST ); } $dir = preg_replace( '/:.*$/', '', $hostname ) . $uri; // To avoid XSS attacks - if ( function_exists( "apply_filters" ) ) { + if ( function_exists( 'apply_filters' ) ) { $dir = apply_filters( 'supercache_dir', $dir ); } else { $dir = do_cacheaction( 'supercache_dir', $dir ); } $dir = $cache_path . 'supercache/' . $dir . '/'; - if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) { + if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages ) ) { $dir = ABSPATH . $uri . '/'; } $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) ); wp_cache_debug( "supercache dir: $dir", 5 ); - if ( $DONOTREMEMBER == 0 ) + if ( $DONOTREMEMBER == 0 ) { $saved_supercache_dir[ $post_id ] = $dir; + } return $dir; } @@ -699,7 +719,7 @@ function wpsc_get_realpath( $directory ) { } $original_dir = $directory; - $directory = realpath( $directory ); + $directory = realpath( $directory ); if ( ! $directory ) { wp_cache_debug( "wpsc_get_realpath: directory does not exist - $original_dir" ); @@ -763,14 +783,14 @@ function wpsc_delete_files( $dir, $delete = true ) { // only do this once, this function will be called many times if ( $protected == '' ) { - $protected = array( $cache_path, $cache_path . "blogs/", $cache_path . 'supercache' ); - foreach( $protected as $id => $directory ) { + $protected = array( $cache_path, $cache_path . 'blogs/', $cache_path . 'supercache' ); + foreach ( $protected as $id => $directory ) { $protected[ $id ] = trailingslashit( wpsc_get_realpath( $directory ) ); } } $orig_dir = $dir; - $dir = wpsc_get_realpath( $dir ); + $dir = wpsc_get_realpath( $dir ); if ( ! $dir ) { wp_cache_debug( 'wpsc_delete_files: directory does not exist: ' . $orig_dir ); return false; @@ -791,7 +811,7 @@ function wpsc_delete_files( $dir, $delete = true ) { if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { wp_cache_debug( 'wpsc_delete_files: reading files: ' . $file ); - if ( $file != '.' && $file != '..' && $file != '.htaccess' && is_file( $dir . $file ) ) + if ( $file != '.' && $file != '..' && $file != '.htaccess' && is_file( $dir . $file ) ) { if ( $delete ) { wp_cache_debug( 'wpsc_delete_files: deleting ' . $dir . $file ); @unlink( $dir . $file ); @@ -799,6 +819,7 @@ function wpsc_delete_files( $dir, $delete = true ) { wp_cache_debug( 'wpsc_delete_files: rebuild or delete ' . $dir . $file ); @wp_cache_rebuild_or_delete( $dir . $file ); } + } } closedir( $dh ); @@ -831,20 +852,21 @@ function get_all_supercache_filenames( $dir = '' ) { // open directory and look for index-*.html files if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { - if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) ) + if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) ) { $filenames[] = $file; + } } closedir( $dh ); } } - if ( function_exists( "apply_filters" ) ) { + if ( function_exists( 'apply_filters' ) ) { $filenames = apply_filters( 'all_supercache_filenames', $filenames ); } else { $filenames = do_cacheaction( 'all_supercache_filenames', $filenames ); } - foreach( $filenames as $file ) { + foreach ( $filenames as $file ) { $out[] = $file; $out[] = $file . '.gz'; } @@ -855,17 +877,17 @@ function get_all_supercache_filenames( $dir = '' ) { function supercache_filename() { global $cached_direct_pages; - //Add support for https and http caching - $is_https = ( ( isset( $_SERVER[ 'HTTPS' ] ) && 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) || ( isset( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) && 'https' == strtolower( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) ) ); //Also supports https requests coming from an nginx reverse proxy + // Add support for https and http caching + $is_https = ( ( isset( $_SERVER['HTTPS'] ) && 'on' == strtolower( $_SERVER['HTTPS'] ) ) || ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ); // Also supports https requests coming from an nginx reverse proxy $extra_str = $is_https ? '-https' : ''; - if ( function_exists( "apply_filters" ) ) { + if ( function_exists( 'apply_filters' ) ) { $extra_str = apply_filters( 'supercache_filename_str', $extra_str ); } else { $extra_str = do_cacheaction( 'supercache_filename_str', $extra_str ); } - if ( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) { + if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages ) ) { $extra_str = ''; } $filename = 'index' . $extra_str . '.html'; @@ -874,18 +896,32 @@ function supercache_filename() { } function get_oc_version() { - $wp_cache_oc_key = wp_cache_get( "wp_cache_oc_key" ); + $wp_cache_oc_key = wp_cache_get( 'wp_cache_oc_key' ); if ( ! $wp_cache_oc_key ) { - $wp_cache_oc_key[ 'key' ] = reset_oc_version(); - } elseif ( $wp_cache_oc_key[ 'ts' ] < time() - 600 ) - wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $wp_cache_oc_key[ 'key' ] ) ); - return $wp_cache_oc_key[ 'key' ]; + $wp_cache_oc_key['key'] = reset_oc_version(); + } elseif ( $wp_cache_oc_key['ts'] < time() - 600 ) { + wp_cache_set( + 'wp_cache_oc_key', + array( + 'ts' => time(), + 'key' => $wp_cache_oc_key['key'], + ) + ); + } + return $wp_cache_oc_key['key']; } function reset_oc_version( $version = 1 ) { - if ( $version == 1 ) + if ( $version == 1 ) { $version = mt_rand(); - wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $version ) ); + } + wp_cache_set( + 'wp_cache_oc_key', + array( + 'ts' => time(), + 'key' => $version, + ) + ); return $version; } @@ -894,7 +930,7 @@ function get_oc_key( $url = false ) { global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST; if ( $url ) { - $key = intval( $_SERVER[ 'SERVER_PORT' ] ) . preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $url; + $key = intval( $_SERVER['SERVER_PORT'] ) . preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $url; } else { $key = get_current_url_supercache_dir(); } @@ -976,8 +1012,8 @@ function wp_cache_confirm_delete( $dir ) { $dir == '' || $dir == $rp_cache_path || $dir == wpsc_get_realpath( $blog_cache_dir ) || - $dir == wpsc_get_realpath( $blog_cache_dir . "meta/" ) || - $dir == wpsc_get_realpath( $cache_path . "supercache" ) + $dir == wpsc_get_realpath( $blog_cache_dir . 'meta/' ) || + $dir == wpsc_get_realpath( $cache_path . 'supercache' ) ) { return false; } else { @@ -999,16 +1035,19 @@ function wpsc_deep_replace( $search, $subject ) { function wpsc_get_protected_directories() { global $cache_path, $blog_cache_dir; - return apply_filters( 'wpsc_protected_directories', array( - $cache_path . '.htaccess', - $cache_path . "index.html", - $blog_cache_dir, - $blog_cache_dir . "index.html", - $blog_cache_dir . 'meta', - $blog_cache_dir . 'meta/index.html', - $cache_path . 'supercache/index.html', - $cache_path . 'supercache' ) - ); + return apply_filters( + 'wpsc_protected_directories', + array( + $cache_path . '.htaccess', + $cache_path . 'index.html', + $blog_cache_dir, + $blog_cache_dir . 'index.html', + $blog_cache_dir . 'meta', + $blog_cache_dir . 'meta/index.html', + $cache_path . 'supercache/index.html', + $cache_path . 'supercache', + ) + ); } function wpsc_debug_username() { @@ -1024,7 +1063,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { if ( $filename != '' ) { $wp_cache_debug_log = $filename; } else { - $wp_cache_debug_log = md5( time() + mt_rand() ) . ".php"; + $wp_cache_debug_log = md5( time() + mt_rand() ) . '.php'; } if ( $username != '' ) { $wp_cache_debug_username = $username; @@ -1033,11 +1072,11 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) { } $msg = 'die( "Please use the viewer" );' . PHP_EOL; - $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' ); + $fp = fopen( $cache_path . $wp_cache_debug_log, 'w' ); if ( $fp ) { fwrite( $fp, '<' . "?php\n" ); fwrite( $fp, $msg ); - fwrite( $fp, '?' . ">
" . PHP_EOL );
+		fwrite( $fp, '?' . '>
' . PHP_EOL );
 		fwrite( $fp, '<' . '?php // END HEADER ?' . '>' . PHP_EOL );
 		fclose( $fp );
 		wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
@@ -1054,7 +1093,7 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
 
 	$fp = fopen( $cache_path . 'view_' . $wp_cache_debug_log, 'w' );
 	if ( $fp ) {
-		fwrite( $fp, '<' . "?php" . PHP_EOL );
+		fwrite( $fp, '<' . '?php' . PHP_EOL );
 		$msg .= '$debug_log = file( "./' . $wp_cache_debug_log . '" );
 $start_log = 1 + array_search( "<" . "?php // END HEADER ?" . ">" . PHP_EOL, $debug_log );
 if ( $start_log > 1 ) {
@@ -1119,7 +1158,10 @@ function wpsc_create_debug_log( $filename = '', $username = '' ) {
 		fclose( $fp );
 	}
 
-	return array( 'wp_cache_debug_log' => $wp_cache_debug_log, 'wp_cache_debug_username' => $wp_cache_debug_username );
+	return array(
+		'wp_cache_debug_log'      => $wp_cache_debug_log,
+		'wp_cache_debug_username' => $wp_cache_debug_username,
+	);
 }
 
 function wpsc_delete_url_cache( $url ) {
@@ -1159,9 +1201,10 @@ function is_writeable_ACLSafe( $path ) {
 
 	// check tmp file for read/write capabilities
 	$rm = file_exists( $path );
-	$f = @fopen( $path, 'a' );
-	if ( $f === false )
+	$f  = @fopen( $path, 'a' );
+	if ( $f === false ) {
 		return false;
+	}
 	fclose( $f );
 	if ( ! $rm ) {
 		unlink( $path );
@@ -1195,7 +1238,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 		}
 		return false;
 	}
-	if (!is_writeable_ACLSafe($my_file)) {
+	if ( ! is_writeable_ACLSafe( $my_file ) ) {
 		if ( function_exists( 'set_transient' ) ) {
 			set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
 		}
@@ -1203,11 +1246,11 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 		return false;
 	}
 
-	$found = false;
+	$found  = false;
 	$loaded = false;
-	$c = 0;
-	$lines = array();
-	while( ! $loaded ) {
+	$c      = 0;
+	$lines  = array();
+	while ( ! $loaded ) {
 		$lines = file( $my_file );
 		if ( ! empty( $lines ) && is_array( $lines ) ) {
 			$loaded = true;
@@ -1222,7 +1265,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 			}
 		}
 	}
-	foreach( (array) $lines as $line ) {
+	foreach ( (array) $lines as $line ) {
 		if (
 			trim( $new ) != '' &&
 			trim( $new ) == trim( $line )
@@ -1230,14 +1273,14 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 			wp_cache_debug( "wp_cache_replace_line: setting not changed - $new" );
 			return true;
 		} elseif ( preg_match( "/$old/", $line ) ) {
-			wp_cache_debug( "wp_cache_replace_line: changing line " . trim( $line ) . " to *$new*" );
+			wp_cache_debug( 'wp_cache_replace_line: changing line ' . trim( $line ) . " to *$new*" );
 			$found = true;
 		}
 	}
 
 	$tmp_config_filename = tempnam( $GLOBALS['cache_path'], 'wpsc' );
-	rename( $tmp_config_filename, $tmp_config_filename . ".php" );
-	$tmp_config_filename .= ".php";
+	rename( $tmp_config_filename, $tmp_config_filename . '.php' );
+	$tmp_config_filename .= '.php';
 	wp_cache_debug( 'wp_cache_replace_line: writing to ' . $tmp_config_filename );
 	$fd = fopen( $tmp_config_filename, 'w' );
 	if ( ! $fd ) {
@@ -1248,7 +1291,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 		return false;
 	}
 	if ( $found ) {
-		foreach( (array) $lines as $line ) {
+		foreach ( (array) $lines as $line ) {
 			if ( ! preg_match( "/$old/", $line ) ) {
 				fputs( $fd, $line );
 			} elseif ( $new != '' ) {
@@ -1257,12 +1300,12 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 		}
 	} else {
 		$done = false;
-		foreach( (array) $lines as $line ) {
+		foreach ( (array) $lines as $line ) {
 			if ( $done || ! preg_match( '/^(if\ \(\ \!\ )?define|\$|\?>/', $line ) ) {
-				fputs($fd, $line);
+				fputs( $fd, $line );
 			} else {
-				fputs($fd, "$new\n");
-				fputs($fd, $line);
+				fputs( $fd, "$new\n" );
+				fputs( $fd, $line );
 				$done = true;
 			}
 		}
@@ -1271,7 +1314,7 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
 	rename( $tmp_config_filename, $my_file );
 	wp_cache_debug( 'wp_cache_replace_line: moved ' . $tmp_config_filename . ' to ' . $my_file );
 
-	if ( function_exists( "opcache_invalidate" ) ) {
+	if ( function_exists( 'opcache_invalidate' ) ) {
 		@opcache_invalidate( $my_file );
 	}
 
@@ -1282,7 +1325,7 @@ function wpsc_shutdown_message() {
 	static $did_wp_footer = false;
 	global $wp_super_cache_comments;
 
-	if ( ! defined( 'WPSCSHUTDOWNMESSAGE' ) || ( isset( $wp_super_cache_comments) && ! $wp_super_cache_comments ) ) {
+	if ( ! defined( 'WPSCSHUTDOWNMESSAGE' ) || ( isset( $wp_super_cache_comments ) && ! $wp_super_cache_comments ) ) {
 		return;
 	}
 
@@ -1311,7 +1354,7 @@ function wp_cache_phase2() {
 
 	wp_cache_debug( 'In WP Cache Phase 2', 5 );
 
-	$wp_cache_gmt_offset = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
+	$wp_cache_gmt_offset   = get_option( 'gmt_offset' ); // caching for later use when wpdb is gone. https://wordpress.org/support/topic/224349
 	$wp_cache_blog_charset = get_option( 'blog_charset' );
 
 	wp_cache_mutex_init();
@@ -1353,7 +1396,7 @@ function wp_cache_phase2() {
 	if ( ( $_SERVER['REQUEST_METHOD'] !== 'POST' && empty( $_POST ) ) && $super_cache_enabled && $cache_rebuild_files ) {
 		$user_info = wp_cache_get_cookies_values();
 
-		if( empty( $user_info )
+		if ( empty( $user_info )
 			|| true === apply_filters( 'do_createsupercache', $user_info )
 		) {
 			wpcache_do_rebuild( get_current_url_supercache_dir() );
@@ -1399,7 +1442,7 @@ function wpsc_register_post_hooks() {
 	add_action( 'transition_post_status', 'wpsc_post_transition', 10, 3 );
 
 	// Cron hooks
-	add_action( 'wp_cache_gc','wp_cache_gc_cron' );
+	add_action( 'wp_cache_gc', 'wp_cache_gc_cron' );
 	add_action( 'wp_cache_gc_watcher', 'wp_cache_gc_watcher' );
 
 	$done = true;
@@ -1409,7 +1452,7 @@ function wpcache_do_rebuild( $dir ) {
 	global $do_rebuild_list, $cache_path, $wpsc_file_mtimes;
 	wp_cache_debug( "wpcache_do_rebuild: doing rebuild for $dir" );
 
-	if ( !is_dir( $dir ) ) {
+	if ( ! is_dir( $dir ) ) {
 		wp_cache_debug( "wpcache_do_rebuild: exiting as directory is not a directory: $dir" );
 		return false;
 	}
@@ -1426,7 +1469,7 @@ function wpcache_do_rebuild( $dir ) {
 	}
 
 	$protected = wpsc_get_protected_directories();
-	foreach( $protected as $id => $directory ) {
+	foreach ( $protected as $id => $directory ) {
 		$protected[ $id ] = wpsc_get_realpath( $directory );
 	}
 
@@ -1440,7 +1483,7 @@ function wpcache_do_rebuild( $dir ) {
 		return false;
 	}
 
-	if ( !is_dir( $dir ) ) {
+	if ( ! is_dir( $dir ) ) {
 		wp_cache_debug( "wpcache_do_rebuild: exiting as directory is not a directory: $dir" );
 		return false;
 	}
@@ -1451,7 +1494,7 @@ function wpcache_do_rebuild( $dir ) {
 		return false;
 	}
 
-	$dir = trailingslashit( $dir );
+	$dir              = trailingslashit( $dir );
 	$wpsc_file_mtimes = array();
 	while ( ( $file = readdir( $dh ) ) !== false ) {
 		if ( $file == '.' || $file == '..' || false == is_file( $dir . $file ) ) {
@@ -1485,7 +1528,7 @@ function wpcache_do_rebuild( $dir ) {
 				@unlink( $cache_file );
 				wp_cache_debug( "wpcache_do_rebuild: rebuild file rename failed. Deleted rebuild file: $cache_file" );
 			} else {
-				$do_rebuild_list[ $dir ] = 1;
+				$do_rebuild_list[ $dir ]        = 1;
 				$wpsc_file_mtimes[ $base_file ] = $mtime;
 				wp_cache_debug( "wpcache_do_rebuild: rebuild file renamed: $base_file" );
 			}
@@ -1606,19 +1649,22 @@ function wp_cache_get_response_headers() {
 	return $headers;
 }
 
-function wp_cache_is_rejected($uri) {
+function wp_cache_is_rejected( $uri ) {
 	global $cache_rejected_uri;
 
 	$auto_rejected = array( '/wp-admin/', 'xmlrpc.php', 'wp-app.php' );
-	foreach( $auto_rejected as $u ) {
-		if( strstr( $uri, $u ) )
+	foreach ( $auto_rejected as $u ) {
+		if ( strstr( $uri, $u ) ) {
 			return true; // we don't allow caching of wp-admin for security reasons
+		}
 	}
-	if ( false == is_array( $cache_rejected_uri ) )
+	if ( false == is_array( $cache_rejected_uri ) ) {
 		return false;
+	}
 	foreach ( $cache_rejected_uri as $expr ) {
-		if( $expr != '' && @preg_match( "~$expr~", $uri ) )
+		if ( $expr != '' && @preg_match( "~$expr~", $uri ) ) {
 			return true;
+		}
 	}
 	return false;
 }
@@ -1626,18 +1672,20 @@ function wp_cache_is_rejected($uri) {
 function wp_cache_mutex_init() {
 	global $mutex, $wp_cache_mutex_disabled, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id;
 
-	if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
+	if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) {
 		return true;
+	}
 
-	if( !is_bool( $use_flock ) ) {
-		if(function_exists('sem_get'))
+	if ( ! is_bool( $use_flock ) ) {
+		if ( function_exists( 'sem_get' ) ) {
 			$use_flock = false;
-		else
+		} else {
 			$use_flock = true;
+		}
 	}
 
 	$mutex = false;
-	if ($use_flock )  {
+	if ( $use_flock ) {
 		setup_blog_cache_dir();
 		wp_cache_debug( "Created mutex lock on filename: {$blog_cache_dir}{$mutex_filename}", 5 );
 		$mutex = @fopen( $blog_cache_dir . $mutex_filename, 'w' );
@@ -1650,20 +1698,21 @@ function wp_cache_mutex_init() {
 function wp_cache_writers_entry() {
 	global $mutex, $wp_cache_mutex_disabled, $use_flock;
 
-	if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
+	if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) {
 		return true;
+	}
 
-	if( !$mutex ) {
+	if ( ! $mutex ) {
 		wp_cache_debug( '(writers entry) mutex lock not created. not caching.', 2 );
 		return false;
 	}
 
 	if ( $use_flock ) {
 		wp_cache_debug( 'grabbing lock using flock()', 5 );
-		flock($mutex,  LOCK_EX);
+		flock( $mutex, LOCK_EX );
 	} else {
 		wp_cache_debug( 'grabbing lock using sem_acquire()', 5 );
-		@sem_acquire($mutex);
+		@sem_acquire( $mutex );
 	}
 
 	return true;
@@ -1672,79 +1721,92 @@ function wp_cache_writers_entry() {
 function wp_cache_writers_exit() {
 	global $mutex, $wp_cache_mutex_disabled, $use_flock;
 
-	if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
+	if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) ) {
 		return true;
+	}
 
-	if( !$mutex ) {
+	if ( ! $mutex ) {
 		wp_cache_debug( '(writers exit) mutex lock not created. not caching.', 2 );
 		return false;
 	}
 
 	if ( $use_flock ) {
 		wp_cache_debug( 'releasing lock using flock()', 5 );
-		flock( $mutex,  LOCK_UN );
+		flock( $mutex, LOCK_UN );
 	} else {
 		wp_cache_debug( 'releasing lock using sem_release() and sem_remove()', 5 );
 		@sem_release( $mutex );
-		if ( defined( "WPSC_REMOVE_SEMAPHORE" ) )
+		if ( defined( 'WPSC_REMOVE_SEMAPHORE' ) ) {
 			@sem_remove( $mutex );
+		}
 	}
 }
 
 function wp_super_cache_query_vars() {
 	global $wp_super_cache_query;
 
-	if ( is_search() )
-		$wp_super_cache_query[ 'is_search' ] = 1;
-	if ( is_page() )
-		$wp_super_cache_query[ 'is_page' ] = 1;
-	if ( is_archive() )
-		$wp_super_cache_query[ 'is_archive' ] = 1;
-	if ( is_tag() )
-		$wp_super_cache_query[ 'is_tag' ] = 1;
-	if ( is_single() )
-		$wp_super_cache_query[ 'is_single' ] = 1;
-	if ( is_category() )
-		$wp_super_cache_query[ 'is_category' ] = 1;
-	if ( is_front_page() )
-		$wp_super_cache_query[ 'is_front_page' ] = 1;
-	if ( is_home() )
-		$wp_super_cache_query[ 'is_home' ] = 1;
-	if ( is_author() )
-		$wp_super_cache_query[ 'is_author' ] = 1;
+	if ( is_search() ) {
+		$wp_super_cache_query['is_search'] = 1;
+	}
+	if ( is_page() ) {
+		$wp_super_cache_query['is_page'] = 1;
+	}
+	if ( is_archive() ) {
+		$wp_super_cache_query['is_archive'] = 1;
+	}
+	if ( is_tag() ) {
+		$wp_super_cache_query['is_tag'] = 1;
+	}
+	if ( is_single() ) {
+		$wp_super_cache_query['is_single'] = 1;
+	}
+	if ( is_category() ) {
+		$wp_super_cache_query['is_category'] = 1;
+	}
+	if ( is_front_page() ) {
+		$wp_super_cache_query['is_front_page'] = 1;
+	}
+	if ( is_home() ) {
+		$wp_super_cache_query['is_home'] = 1;
+	}
+	if ( is_author() ) {
+		$wp_super_cache_query['is_author'] = 1;
+	}
 
 	// REST API
-	if ( ( defined( 'REST_REQUEST' )   && REST_REQUEST ) ||
-	     ( defined( 'JSON_REQUEST' )   && JSON_REQUEST ) ||
-	     ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST )
+	if ( ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
+		 ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) ||
+		 ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST )
 	) {
-		$wp_super_cache_query[ 'is_rest' ] = 1;
+		$wp_super_cache_query['is_rest'] = 1;
 	}
 
 	// Feeds, sitemaps and robots.txt
 	if ( is_feed() ) {
-		$wp_super_cache_query[ 'is_feed' ] = 1;
+		$wp_super_cache_query['is_feed'] = 1;
 		if ( get_query_var( 'feed' ) == 'sitemap' ) {
-			$wp_super_cache_query[ 'is_sitemap' ] = 1;
+			$wp_super_cache_query['is_sitemap'] = 1;
 		}
 	} elseif ( get_query_var( 'sitemap' ) || get_query_var( 'xsl' ) || get_query_var( 'xml_sitemap' ) ) {
-		$wp_super_cache_query[ 'is_feed' ] = 1;
-		$wp_super_cache_query[ 'is_sitemap' ] = 1;
+		$wp_super_cache_query['is_feed']    = 1;
+		$wp_super_cache_query['is_sitemap'] = 1;
 	} elseif ( is_robots() ) {
-		$wp_super_cache_query[ 'is_robots' ] = 1;
+		$wp_super_cache_query['is_robots'] = 1;
 	}
 
 	// Reset everything if it's 404
-	if ( is_404() )
+	if ( is_404() ) {
 		$wp_super_cache_query = array( 'is_404' => 1 );
+	}
 
 	return $wp_super_cache_query;
 }
 
 function wpsc_catch_status_header( $status_header, $code ) {
 
-	if ( $code != 200 )
+	if ( $code != 200 ) {
 		wpsc_catch_http_status_code( $code );
+	}
 
 	return $status_header;
 }
@@ -1753,11 +1815,11 @@ function wpsc_catch_http_status_code( $status ) {
 	global $wp_super_cache_query;
 
 	if ( in_array( intval( $status ), array( 301, 302, 303, 307 ) ) ) {
-		$wp_super_cache_query[ 'is_redirect' ] = 1;
+		$wp_super_cache_query['is_redirect'] = 1;
 	} elseif ( $status == 304 ) {
-		$wp_super_cache_query[ 'is_304' ] = 1;
+		$wp_super_cache_query['is_304'] = 1;
 	} elseif ( $status == 404 ) {
-		$wp_super_cache_query[ 'is_404' ] = 1;
+		$wp_super_cache_query['is_404'] = 1;
 	}
 
 	return $status;
@@ -1771,7 +1833,7 @@ function wpsc_is_fatal_error() {
 	}
 
 	if ( $error['type'] & ( E_ERROR | E_CORE_ERROR | E_PARSE | E_COMPILE_ERROR | E_USER_ERROR ) ) {
-		$wp_super_cache_query[ 'is_fatal_error' ] = 1;
+		$wp_super_cache_query['is_fatal_error'] = 1;
 		return true;
 	}
 
@@ -1780,7 +1842,7 @@ function wpsc_is_fatal_error() {
 
 function wp_cache_ob_callback( $buffer ) {
 	global $wp_cache_pages, $wp_query, $wp_super_cache_query, $cache_acceptable_files, $wp_cache_no_cache_for_get, $wp_cache_request_uri, $do_rebuild_list, $wpsc_file_mtimes, $wpsc_save_headers, $super_cache_enabled;
-	$script = basename( $_SERVER[ 'PHP_SELF' ] );
+	$script = basename( $_SERVER['PHP_SELF'] );
 
 	// All the things that can stop a page being cached
 	$cache_this_page = true;
@@ -1788,7 +1850,7 @@ function wp_cache_ob_callback( $buffer ) {
 	if ( wpsc_is_fatal_error() ) {
 		wp_cache_debug( 'wp_cache_ob_callback: PHP Fatal error occurred. Not caching incomplete page.' );
 		$cache_this_page = false;
-	} elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && is_object( $wp_query ) && method_exists( $wp_query, 'get' ) ) {
+	} elseif ( empty( $wp_super_cache_query ) && ! empty( $buffer ) && is_object( $wp_query ) && method_exists( $wp_query, 'get' ) ) {
 		$wp_super_cache_query = wp_super_cache_query_vars();
 	} elseif ( empty( $wp_super_cache_query ) && function_exists( 'http_response_code' ) ) {
 		wpsc_catch_http_status_code( http_response_code() );
@@ -1802,67 +1864,67 @@ function wp_cache_ob_callback( $buffer ) {
 	} elseif ( $wp_cache_no_cache_for_get && ! empty( $_GET ) ) {
 		wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
 		$cache_this_page = false;
-	} elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
+	} elseif ( $_SERVER['REQUEST_METHOD'] == 'POST' || ! empty( $_POST ) || get_option( 'gzipcompression' ) ) {
 		wp_cache_debug( 'Not caching POST request.', 5 );
 		$cache_this_page = false;
-	} elseif ( $_SERVER["REQUEST_METHOD"] == 'PUT' ) {
+	} elseif ( $_SERVER['REQUEST_METHOD'] == 'PUT' ) {
 		wp_cache_debug( 'Not caching PUT request.', 5 );
 		$cache_this_page = false;
-	} elseif ( $_SERVER["REQUEST_METHOD"] == 'DELETE' ) {
+	} elseif ( $_SERVER['REQUEST_METHOD'] == 'DELETE' ) {
 		wp_cache_debug( 'Not caching DELETE request.', 5 );
 		$cache_this_page = false;
-	} elseif ( isset( $_GET[ 'preview' ] ) ) {
+	} elseif ( isset( $_GET['preview'] ) ) {
 		wp_cache_debug( 'Not caching preview post.', 2 );
 		$cache_this_page = false;
-	} elseif ( !in_array( $script, (array) $cache_acceptable_files ) && wp_cache_is_rejected( $wp_cache_request_uri ) ) {
+	} elseif ( ! in_array( $script, (array) $cache_acceptable_files ) && wp_cache_is_rejected( $wp_cache_request_uri ) ) {
 		wp_cache_debug( 'URI rejected. Not Caching', 2 );
 		$cache_this_page = false;
 	} elseif ( wp_cache_user_agent_is_rejected() ) {
 		wp_cache_debug( "USER AGENT ({$_SERVER[ 'HTTP_USER_AGENT' ]}) rejected. Not Caching", 4 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'single' ] ) && $wp_cache_pages[ 'single' ] == 1 && isset( $wp_super_cache_query[ 'is_single' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['single'] ) && $wp_cache_pages['single'] == 1 && isset( $wp_super_cache_query['is_single'] ) ) {
 		wp_cache_debug( 'Not caching single post.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'pages' ] ) && $wp_cache_pages[ 'pages' ] == 1 && isset( $wp_super_cache_query[ 'is_page' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['pages'] ) && $wp_cache_pages['pages'] == 1 && isset( $wp_super_cache_query['is_page'] ) ) {
 		wp_cache_debug( 'Not caching single page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'archives' ] ) && $wp_cache_pages[ 'archives' ] == 1 && isset( $wp_super_cache_query[ 'is_archive' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['archives'] ) && $wp_cache_pages['archives'] == 1 && isset( $wp_super_cache_query['is_archive'] ) ) {
 		wp_cache_debug( 'Not caching archive page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'tag' ] ) && $wp_cache_pages[ 'tag' ] == 1 && isset( $wp_super_cache_query[ 'is_tag' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['tag'] ) && $wp_cache_pages['tag'] == 1 && isset( $wp_super_cache_query['is_tag'] ) ) {
 		wp_cache_debug( 'Not caching tag page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'category' ] ) && $wp_cache_pages[ 'category' ] == 1 && isset( $wp_super_cache_query[ 'is_category' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['category'] ) && $wp_cache_pages['category'] == 1 && isset( $wp_super_cache_query['is_category'] ) ) {
 		wp_cache_debug( 'Not caching category page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'frontpage' ] ) && $wp_cache_pages[ 'frontpage' ] == 1 && isset( $wp_super_cache_query[ 'is_front_page' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['frontpage'] ) && $wp_cache_pages['frontpage'] == 1 && isset( $wp_super_cache_query['is_front_page'] ) ) {
 		wp_cache_debug( 'Not caching front page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'home' ] ) && $wp_cache_pages[ 'home' ] == 1 && isset( $wp_super_cache_query[ 'is_home' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['home'] ) && $wp_cache_pages['home'] == 1 && isset( $wp_super_cache_query['is_home'] ) ) {
 		wp_cache_debug( 'Not caching home page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'search' ] ) && $wp_cache_pages[ 'search' ] == 1 && isset( $wp_super_cache_query[ 'is_search' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['search'] ) && $wp_cache_pages['search'] == 1 && isset( $wp_super_cache_query['is_search'] ) ) {
 		wp_cache_debug( 'Not caching search page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'author' ] ) && $wp_cache_pages[ 'author' ] == 1 && isset( $wp_super_cache_query[ 'is_author' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['author'] ) && $wp_cache_pages['author'] == 1 && isset( $wp_super_cache_query['is_author'] ) ) {
 		wp_cache_debug( 'Not caching author page.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_cache_pages[ 'feed' ] ) && $wp_cache_pages[ 'feed' ] == 1 && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
+	} elseif ( isset( $wp_cache_pages['feed'] ) && $wp_cache_pages['feed'] == 1 && isset( $wp_super_cache_query['is_feed'] ) ) {
 		wp_cache_debug( 'Not caching feed.', 2 );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_super_cache_query[ 'is_rest' ] ) ) {
+	} elseif ( isset( $wp_super_cache_query['is_rest'] ) ) {
 		wp_cache_debug( 'REST API detected. Caching disabled.' );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_super_cache_query[ 'is_robots' ] ) ) {
+	} elseif ( isset( $wp_super_cache_query['is_robots'] ) ) {
 		wp_cache_debug( 'robots.txt detected. Caching disabled.' );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_super_cache_query[ 'is_redirect' ] ) ) {
+	} elseif ( isset( $wp_super_cache_query['is_redirect'] ) ) {
 		wp_cache_debug( 'Redirect detected. Caching disabled.' );
 		$cache_this_page = false;
-	} elseif ( isset( $wp_super_cache_query[ 'is_304' ] ) ) {
+	} elseif ( isset( $wp_super_cache_query['is_304'] ) ) {
 		wp_cache_debug( 'HTTP 304 (Not Modified) sent. Caching disabled.' );
 		$cache_this_page = false;
-	} elseif ( empty( $wp_super_cache_query ) && !empty( $buffer ) && apply_filters( 'wpsc_only_cache_known_pages', 1 ) ) {
+	} elseif ( empty( $wp_super_cache_query ) && ! empty( $buffer ) && apply_filters( 'wpsc_only_cache_known_pages', 1 ) ) {
 		wp_cache_debug( 'wp_cache_ob_callback: wp_super_cache_query is empty. Not caching unknown page type. Return 0 to the wpsc_only_cache_known_pages filter to cache this page.' );
 		$cache_this_page = false;
 	} elseif ( wpsc_is_caching_user_disabled() ) {
@@ -1873,8 +1935,9 @@ function wp_cache_ob_callback( $buffer ) {
 		$cache_this_page = false;
 	}
 
-	if ( isset( $wpsc_save_headers ) && $wpsc_save_headers )
+	if ( isset( $wpsc_save_headers ) && $wpsc_save_headers ) {
 		$super_cache_enabled = false; // use standard caching to record headers
+	}
 
 	if ( $cache_this_page ) {
 
@@ -1883,8 +1946,8 @@ function wp_cache_ob_callback( $buffer ) {
 		$buffer = wp_cache_get_ob( $buffer );
 		wp_cache_shutdown_callback();
 
-		if ( !empty( $wpsc_file_mtimes ) && is_array( $wpsc_file_mtimes ) ) {
-			foreach( $wpsc_file_mtimes as $cache_file => $old_mtime ) {
+		if ( ! empty( $wpsc_file_mtimes ) && is_array( $wpsc_file_mtimes ) ) {
+			foreach ( $wpsc_file_mtimes as $cache_file => $old_mtime ) {
 				if ( $old_mtime == @filemtime( $cache_file ) ) {
 					wp_cache_debug( "wp_cache_ob_callback deleting unmodified rebuilt cache file: $cache_file" );
 					if ( wp_cache_confirm_delete( $cache_file ) ) {
@@ -1895,8 +1958,8 @@ function wp_cache_ob_callback( $buffer ) {
 		}
 		return $buffer;
 	} else {
-		if ( !empty( $do_rebuild_list ) && is_array( $do_rebuild_list ) ) {
-			foreach( $do_rebuild_list as $dir => $n ) {
+		if ( ! empty( $do_rebuild_list ) && is_array( $do_rebuild_list ) ) {
+			foreach ( $do_rebuild_list as $dir => $n ) {
 				if ( wp_cache_confirm_delete( $dir ) ) {
 					wp_cache_debug( 'wp_cache_ob_callback clearing rebuilt files in ' . $dir );
 					wpsc_delete_files( $dir );
@@ -1911,13 +1974,15 @@ function wp_cache_append_tag( &$buffer ) {
 	global $wp_cache_gmt_offset, $wp_super_cache_comments;
 	global $cache_enabled, $super_cache_enabled;
 
-	if ( false == isset( $wp_super_cache_comments ) )
+	if ( false == isset( $wp_super_cache_comments ) ) {
 		$wp_super_cache_comments = 1;
+	}
 
-	if ( $wp_super_cache_comments == 0 )
+	if ( $wp_super_cache_comments == 0 ) {
 		return false;
+	}
 
-	$timestamp = gmdate('Y-m-d H:i:s', (time() + ( $wp_cache_gmt_offset * 3600)));
+	$timestamp = gmdate( 'Y-m-d H:i:s', ( time() + ( $wp_cache_gmt_offset * 3600 ) ) );
 	if ( $cache_enabled || $super_cache_enabled ) {
 		$msg = "Cached page generated by WP-Super-Cache on $timestamp";
 	} else {
@@ -1925,7 +1990,7 @@ function wp_cache_append_tag( &$buffer ) {
 	}
 
 	if ( strpos( $buffer, '|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
+	if ( ! preg_match( apply_filters( 'wp_cache_eof_tags', '/(<\/html>|<\/rss>|<\/feed>|<\/urlset|<\?xml)/i' ), $buffer ) ) {
 		$new_cache = false;
-		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) {
+		if ( isset( $GLOBALS['wp_super_cache_debug'] ) && $GLOBALS['wp_super_cache_debug'] ) {
 			wp_cache_debug( 'No closing html tag. Not caching.', 2 );
-			wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. No closing HTML tag. Check your theme." );
+			wp_cache_add_to_buffer( $buffer, 'Page not cached by WP Super Cache. No closing HTML tag. Check your theme.' );
 		}
 	}
 
-	if( !$new_cache )
+	if ( ! $new_cache ) {
 		return wp_cache_maybe_dynamic( $buffer );
+	}
 
-	$duration = wp_cache_microtime_diff($wp_start_time, microtime());
-	$duration = sprintf("%0.3f", $duration);
+	$duration = wp_cache_microtime_diff( $wp_start_time, microtime() );
+	$duration = sprintf( '%0.3f', $duration );
 	wp_cache_add_to_buffer( $buffer, "Dynamic page generated in $duration seconds." );
 
-	if( !wp_cache_writers_entry() ) {
-		wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Could not get mutex lock." );
+	if ( ! wp_cache_writers_entry() ) {
+		wp_cache_add_to_buffer( $buffer, 'Page not cached by WP Super Cache. Could not get mutex lock.' );
 		wp_cache_debug( 'Could not get mutex lock. Not caching.', 1 );
 		return wp_cache_maybe_dynamic( $buffer );
 	}
 
-	if ( $wp_cache_not_logged_in && isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
+	if ( $wp_cache_not_logged_in && isset( $wp_super_cache_query['is_feed'] ) ) {
 		wp_cache_debug( 'Feed detected. Writing wpcache cache files.', 5 );
 		$wp_cache_not_logged_in = false;
 	}
 
 	$home_url = parse_url( trailingslashit( get_bloginfo( 'url' ) ) );
 
-	$dir = get_current_url_supercache_dir();
-	$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '',  $home_url[ 'host' ]);
-	if ( ! empty( $_GET ) || isset( $wp_super_cache_query[ 'is_feed' ] ) || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
+	$dir           = get_current_url_supercache_dir();
+	$supercachedir = $cache_path . 'supercache/' . preg_replace( '/:.*$/', '', $home_url['host'] );
+	if ( ! empty( $_GET ) || isset( $wp_super_cache_query['is_feed'] ) || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
 		wp_cache_debug( 'Supercache disabled: GET or feed detected or disabled by config.', 2 );
 		$super_cache_enabled = false;
 	}
@@ -2042,7 +2111,7 @@ function wp_cache_get_ob(&$buffer) {
 		$supercacheonly = false;
 	}
 
-	if( $super_cache_enabled ) {
+	if ( $super_cache_enabled ) {
 		if ( wp_cache_get_cookies_values() == '' && empty( $_GET ) ) {
 			wp_cache_debug( 'Anonymous user detected. Only creating Supercache file.', 3 );
 			$supercacheonly = true;
@@ -2052,26 +2121,28 @@ function wp_cache_get_ob(&$buffer) {
 	$cache_error = '';
 	if ( wpsc_is_caching_user_disabled() ) {
 		$super_cache_enabled = false;
-		$cache_enabled = false;
-		$cache_error = 'Not caching requests by known users. (See Advanced Settings page)';
+		$cache_enabled       = false;
+		$cache_error         = 'Not caching requests by known users. (See Advanced Settings page)';
 		wp_cache_debug( 'Not caching for known user.', 5 );
 	}
 
-	if ( !$cache_enabled ) {
+	if ( ! $cache_enabled ) {
 		wp_cache_debug( 'Cache is not enabled. Sending buffer to browser.', 5 );
 		wp_cache_writers_exit();
 		wp_cache_add_to_buffer( $buffer, "Page not cached by WP Super Cache. Check your settings page. $cache_error" );
 		if ( $wp_cache_mfunc_enabled == 1 ) {
 			global $wp_super_cache_late_init;
-			if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) )
+			if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) {
 				wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but $wp_super_cache_late_init not set. See the readme.txt for further details.' );
+			}
 		}
 
 		return wp_cache_maybe_dynamic( $buffer );
 	}
 
-	if( @is_dir( $dir ) == false )
+	if ( @is_dir( $dir ) == false ) {
 		@wp_mkdir_p( $dir );
+	}
 	$dir = wpsc_get_realpath( $dir );
 
 	if ( ! $dir ) {
@@ -2098,7 +2169,7 @@ function wp_cache_get_ob(&$buffer) {
 		}
 	} else {
 		$user_info = wp_cache_get_cookies_values();
-		$do_cache = apply_filters( 'do_createsupercache', $user_info );
+		$do_cache  = apply_filters( 'do_createsupercache', $user_info );
 		if (
 			$super_cache_enabled &&
 			(
@@ -2106,10 +2177,10 @@ function wp_cache_get_ob(&$buffer) {
 				$do_cache === true
 			)
 		) {
-			$cache_fname = $dir . supercache_filename();
+			$cache_fname        = $dir . supercache_filename();
 			$tmp_cache_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
-			$fr2 = @fopen( $tmp_cache_filename, 'w' );
-			if ( !$fr2 ) {
+			$fr2                = @fopen( $tmp_cache_filename, 'w' );
+			if ( ! $fr2 ) {
 				wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 );
 				wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) );
 				@fclose( $fr );
@@ -2123,10 +2194,10 @@ function wp_cache_get_ob(&$buffer) {
 					$wp_cache_mfunc_enabled == 0
 				)
 			) { // don't want to store compressed files if using dynamic content
-				$gz = @fopen( $tmp_cache_filename . ".gz", 'w');
-				if ( !$gz ) {
-					wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz", 1 );
-					wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . ".gz" );
+				$gz = @fopen( $tmp_cache_filename . '.gz', 'w' );
+				if ( ! $gz ) {
+					wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz', 1 );
+					wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz' );
 					@fclose( $fr );
 					@unlink( $tmp_wpcache_filename );
 					@fclose( $fr2 );
@@ -2139,8 +2210,8 @@ function wp_cache_get_ob(&$buffer) {
 	}
 
 	$added_cache = 0;
-	$oc_key = get_oc_key();
-	$buffer = apply_filters( 'wpsupercache_buffer', $buffer );
+	$oc_key      = get_oc_key();
+	$buffer      = apply_filters( 'wpsupercache_buffer', $buffer );
 	wp_cache_append_tag( $buffer );
 
 	/*
@@ -2148,32 +2219,33 @@ function wp_cache_get_ob(&$buffer) {
 	 * the wpsc_cachedata filter. Buffer is then returned to the visitor.
 	 */
 	if ( $wp_cache_mfunc_enabled == 1 ) {
-		if ( preg_match( '//', $buffer ) ) { //Dynamic content
+		if ( preg_match( '//', $buffer ) ) { // Dynamic content
 			wp_cache_debug( 'mfunc/mclude/dynamic-cached-content tags have been retired. Please update your theme. See docs for updates.' );
-			wp_cache_add_to_buffer( $buffer, "Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information." );
+			wp_cache_add_to_buffer( $buffer, 'Warning! Obsolete mfunc/mclude/dynamic-cached-content tags found. Please update your theme. See http://ocaoimh.ie/y/5b for more information.' );
 		}
 
 		global $wp_super_cache_late_init;
-		if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) )
+		if ( false == isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && $wp_super_cache_late_init == 0 ) ) {
 			wp_cache_add_to_buffer( $buffer, 'Super Cache dynamic page detected but late init not set. See the readme.txt for further details.' );
+		}
 
 		if ( $fr ) { // wpcache caching
 			wp_cache_debug( 'Writing dynamic buffer to wpcache file.' );
-			wp_cache_add_to_buffer( $buffer, "Dynamic WPCache Super Cache" );
+			wp_cache_add_to_buffer( $buffer, 'Dynamic WPCache Super Cache' );
 			fputs( $fr, '' . $buffer );
 		} elseif ( isset( $fr2 ) ) { // supercache active
 			wp_cache_debug( 'Writing dynamic buffer to supercache file.' );
-			wp_cache_add_to_buffer( $buffer, "Dynamic Super Cache" );
+			wp_cache_add_to_buffer( $buffer, 'Dynamic Super Cache' );
 			fputs( $fr2, $buffer );
 		}
-		$wp_cache_meta[ 'dynamic' ] = true;
+		$wp_cache_meta['dynamic'] = true;
 		if ( $wp_cache_mfunc_enabled == 1 && do_cacheaction( 'wpsc_cachedata_safety', 0 ) === 1 ) {
 			$buffer = do_cacheaction( 'wpsc_cachedata', $buffer ); // dynamic content for display
 		}
 
 		if ( $cache_compression && $wp_cache_gzip_encoding ) {
 			wp_cache_debug( 'Gzipping dynamic buffer for display.', 5 );
-			wp_cache_add_to_buffer( $buffer, "Compression = gzip" );
+			wp_cache_add_to_buffer( $buffer, 'Compression = gzip' );
 			$gzdata = gzencode( $buffer, 6, FORCE_GZIP );
 			$gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata );
 		}
@@ -2188,34 +2260,34 @@ function wp_cache_get_ob(&$buffer) {
 			$vary_header = 'Accept-Encoding, Cookie';
 		}
 		if ( $vary_header ) {
-			$wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: ' . $vary_header;
+			$wp_cache_meta['headers']['Vary'] = 'Vary: ' . $vary_header;
 		}
 		if ( $gz || $wp_cache_gzip_encoding ) {
 			wp_cache_debug( 'Gzipping buffer.', 5 );
-			wp_cache_add_to_buffer( $buffer, "Compression = gzip" );
+			wp_cache_add_to_buffer( $buffer, 'Compression = gzip' );
 			$gzdata = gzencode( $buffer, 6, FORCE_GZIP );
 			$gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata );
 
-			$wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
+			$wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
 			// Return uncompressed data & store compressed for later use
 			if ( $fr ) {
 				wp_cache_debug( 'Writing gzipped buffer to wp-cache cache file.', 5 );
-				fputs($fr, '' . $gzdata);
+				fputs( $fr, '' . $gzdata );
 			}
 		} else { // no compression
 			if ( $fr ) {
 				wp_cache_debug( 'Writing non-gzipped buffer to wp-cache cache file.' );
-				fputs($fr, '' . $buffer);
+				fputs( $fr, '' . $buffer );
 			}
 		}
 		if ( $fr2 ) {
 			wp_cache_debug( 'Writing non-gzipped buffer to supercache file.' );
-			wp_cache_add_to_buffer( $buffer, "super cache" );
-			fputs($fr2, $buffer );
+			wp_cache_add_to_buffer( $buffer, 'super cache' );
+			fputs( $fr2, $buffer );
 		}
 		if ( isset( $gzdata ) && $gz ) {
 			wp_cache_debug( 'Writing gzipped buffer to supercache file.' );
-			fwrite($gz, $gzdata );
+			fwrite( $gz, $gzdata );
 		}
 	}
 
@@ -2245,7 +2317,7 @@ function wp_cache_get_ob(&$buffer) {
 
 	if ( $fr2 ) {
 		fclose( $fr2 );
-		if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url[ 'path' ] . supercache_filename() && !( $wp_cache_is_home ) ) {
+		if ( $wp_cache_front_page_checks && $cache_fname == $supercachedir . $home_url['path'] . supercache_filename() && ! ( $wp_cache_is_home ) ) {
 			wp_cache_writers_exit();
 			wp_cache_debug( 'Warning! Not writing another page to front page cache.', 1 );
 			return $buffer;
@@ -2278,14 +2350,18 @@ function wp_cache_get_ob(&$buffer) {
 
 	if ( $added_cache && isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
 		update_option( 'wpsupercache_count', ( get_option( 'wpsupercache_count' ) + 1 ) );
-		$last_urls = (array)get_option( 'supercache_last_cached' );
-		if ( count( $last_urls ) >= 10 )
+		$last_urls = (array) get_option( 'supercache_last_cached' );
+		if ( count( $last_urls ) >= 10 ) {
 			$last_urls = array_slice( $last_urls, 1, 9 );
-		$last_urls[] = array( 'url' => preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ), 'date' => date( 'Y-m-d H:i:s' ) );
+		}
+		$last_urls[] = array(
+			'url'  => preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ),
+			'date' => date( 'Y-m-d H:i:s' ),
+		);
 		update_option( 'supercache_last_cached', $last_urls );
 	}
 	wp_cache_writers_exit();
-	if ( !headers_sent() && $wp_cache_gzip_encoding && $gzdata) {
+	if ( ! headers_sent() && $wp_cache_gzip_encoding && $gzdata ) {
 		wp_cache_debug( 'Writing gzip content headers. Sending buffer to browser', 5 );
 		header( 'Content-Encoding: ' . $wp_cache_gzip_encoding );
 		if ( defined( 'WPSC_VARY_HEADER' ) ) {
@@ -2308,30 +2384,31 @@ function wp_cache_get_ob(&$buffer) {
 	}
 }
 
-function wp_cache_phase2_clean_cache($file_prefix) {
+function wp_cache_phase2_clean_cache( $file_prefix ) {
 	global $wpdb, $blog_cache_dir;
 
-	if( !wp_cache_writers_entry() )
+	if ( ! wp_cache_writers_entry() ) {
 		return false;
+	}
 	wp_cache_debug( "wp_cache_phase2_clean_cache: Cleaning cache in $blog_cache_dir" );
 	if ( $handle = @opendir( $blog_cache_dir ) ) {
-		while ( false !== ($file = @readdir($handle))) {
+		while ( false !== ( $file = @readdir( $handle ) ) ) {
 			if ( strpos( $file, $file_prefix ) !== false ) {
 				if ( strpos( $file, '.html' ) ) {
 					// delete old wpcache files immediately
 					wp_cache_debug( "wp_cache_phase2_clean_cache: Deleting obsolete wpcache cache+meta files: $file" );
-					@unlink( $blog_cache_dir . $file);
+					@unlink( $blog_cache_dir . $file );
 					@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
 				} else {
 					$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
-					if ( $meta[ 'blog_id' ] == $wpdb->blogid ) {
+					if ( $meta['blog_id'] == $wpdb->blogid ) {
 						@unlink( $blog_cache_dir . $file );
 						@unlink( $blog_cache_dir . 'meta/' . $file );
 					}
 				}
 			}
 		}
-		closedir($handle);
+		closedir( $handle );
 		do_action( 'wp_cache_cleared' );
 	}
 	wp_cache_writers_exit();
@@ -2346,10 +2423,10 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
 	}
 
 	global $cache_max_time, $cache_path, $blog_cache_dir;
-	static $log = 0;
+	static $log                   = 0;
 	static $protected_directories = '';
 
-	$dir = $directory;
+	$dir       = $directory;
 	$directory = wpsc_get_realpath( $directory );
 	if ( $directory == '' ) {
 		wp_cache_debug( "prune_super_cache: exiting as file/directory does not exist : $dir" );
@@ -2364,8 +2441,9 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
 		wp_cache_debug( "prune_super_cache: exiting as file/dir does not exist: $directory" );
 		return $log;
 	}
-	if( !isset( $cache_max_time ) )
+	if ( ! isset( $cache_max_time ) ) {
 		$cache_max_time = 3600;
+	}
 
 	$now = time();
 
@@ -2373,30 +2451,33 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
 		$protected_directories = wpsc_get_protected_directories();
 	}
 
-	if (is_dir($directory)) {
-		if( $dh = @opendir( $directory ) ) {
+	if ( is_dir( $directory ) ) {
+		if ( $dh = @opendir( $directory ) ) {
 			$directory = trailingslashit( $directory );
-			while( ( $entry = @readdir( $dh ) ) !== false ) {
-				if ($entry == '.' || $entry == '..')
+			while ( ( $entry = @readdir( $dh ) ) !== false ) {
+				if ( $entry == '.' || $entry == '..' ) {
 					continue;
+				}
 				$entry = $directory . $entry;
 				prune_super_cache( $entry, $force, $rename );
 				// If entry is a directory, AND it's not a protected one, AND we're either forcing the delete, OR the file is out of date,
-				if( is_dir( $entry ) && !in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
+				if ( is_dir( $entry ) && ! in_array( $entry, $protected_directories ) && ( $force || @filemtime( $entry ) + $cache_max_time <= $now ) ) {
 					// if the directory isn't empty can't delete it
-					if( $handle = @opendir( $entry ) ) {
+					if ( $handle = @opendir( $entry ) ) {
 						$donotdelete = false;
-						while( !$donotdelete && ( $file = @readdir( $handle ) ) !== false ) {
-							if ($file == '.' || $file == '..')
+						while ( ! $donotdelete && ( $file = @readdir( $handle ) ) !== false ) {
+							if ( $file == '.' || $file == '..' ) {
 								continue;
+							}
 							$donotdelete = true;
 							wp_cache_debug( "gc: could not delete $entry as it's not empty: $file", 2 );
 						}
-						closedir($handle);
+						closedir( $handle );
 					}
-					if( $donotdelete )
+					if ( $donotdelete ) {
 						continue;
-					if( !$rename ) {
+					}
+					if ( ! $rename ) {
 						@rmdir( $entry );
 						$log++;
 						if ( $force ) {
@@ -2409,19 +2490,19 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
 					wp_cache_debug( "gc: could not delete $entry as it's protected.", 2 );
 				}
 			}
-			closedir($dh);
+			closedir( $dh );
 		}
-	} elseif( is_file($directory) && ($force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
+	} elseif ( is_file( $directory ) && ( $force || @filemtime( $directory ) + $cache_max_time <= $now ) ) {
 		$oktodelete = true;
 		if ( in_array( $directory, $protected_directories ) ) {
 			wp_cache_debug( "gc: could not delete $directory as it's protected.", 2 );
 			$oktodelete = false;
 		}
-		if( $oktodelete && !$rename ) {
+		if ( $oktodelete && ! $rename ) {
 			wp_cache_debug( "prune_super_cache: deleted $directory", 5 );
 			@unlink( $directory );
 			$log++;
-		} elseif( $oktodelete && $rename ) {
+		} elseif ( $oktodelete && $rename ) {
 			wp_cache_debug( "prune_super_cache: wp_cache_rebuild_or_delete( $directory )", 5 );
 			wp_cache_rebuild_or_delete( $directory );
 			$log++;
@@ -2437,9 +2518,9 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
 function wp_cache_rebuild_or_delete( $file ) {
 	global $cache_rebuild_files, $cache_path, $file_prefix;
 
-
-	if ( strpos( $file, '?' ) !== false )
+	if ( strpos( $file, '?' ) !== false ) {
 		$file = substr( $file, 0, strpos( $file, '?' ) );
+	}
 
 	$file = wpsc_get_realpath( $file );
 
@@ -2454,7 +2535,7 @@ function wp_cache_rebuild_or_delete( $file ) {
 	}
 
 	$protected = wpsc_get_protected_directories();
-	foreach( $protected as $id => $directory ) {
+	foreach ( $protected as $id => $directory ) {
 		$protected[ $id ] = wpsc_get_realpath( $directory );
 	}
 
@@ -2479,8 +2560,8 @@ function wp_cache_rebuild_or_delete( $file ) {
 		wp_cache_debug( "rebuild_or_gc: file has disappeared: $file" );
 		return false;
 	}
-	if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
-		if( @rename($file, $file . '.needs-rebuild') ) {
+	if ( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
+		if ( @rename( $file, $file . '.needs-rebuild' ) ) {
 			@touch( $file . '.needs-rebuild' );
 			wp_cache_debug( "rebuild_or_gc: rename file to {$file}.needs-rebuild", 2 );
 		} else {
@@ -2500,35 +2581,36 @@ function wp_cache_phase2_clean_expired( $file_prefix, $force = false ) {
 	global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
 
 	if ( $cache_max_time == 0 ) {
-		wp_cache_debug( "wp_cache_phase2_clean_expired: disabled because GC disabled.", 2 );
+		wp_cache_debug( 'wp_cache_phase2_clean_expired: disabled because GC disabled.', 2 );
 		return false;
 	}
 
 	clearstatcache();
-	if( !wp_cache_writers_entry() )
+	if ( ! wp_cache_writers_entry() ) {
 		return false;
+	}
 	$now = time();
 	wp_cache_debug( "Cleaning expired cache files in $blog_cache_dir", 2 );
 	$deleted = 0;
 	if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
-		while ( false !== ($file = readdir($handle))) {
-			if ( preg_match("/^$file_prefix/", $file) &&
-				(@filemtime( $blog_cache_dir . $file) + $cache_max_time) <= $now  ) {
+		while ( false !== ( $file = readdir( $handle ) ) ) {
+			if ( preg_match( "/^$file_prefix/", $file ) &&
+				( @filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
 				@unlink( $blog_cache_dir . $file );
 				@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
 				wp_cache_debug( "wp_cache_phase2_clean_expired: Deleting obsolete wpcache cache+meta files: $file" );
 				continue;
 			}
-			if($file != '.' && $file != '..') {
-				if( is_dir( $blog_cache_dir . $file ) == false && (@filemtime($blog_cache_dir . $file) + $cache_max_time) <= $now  ) {
+			if ( $file != '.' && $file != '..' ) {
+				if ( is_dir( $blog_cache_dir . $file ) == false && ( @filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
 					if ( substr( $file, -9 ) != '.htaccess' && $file != 'index.html' ) {
-						@unlink($blog_cache_dir . $file);
+						@unlink( $blog_cache_dir . $file );
 						wp_cache_debug( "Deleting $blog_cache_dir{$file}, older than $cache_max_time seconds", 5 );
 					}
 				}
 			}
 		}
-		closedir($handle);
+		closedir( $handle );
 		if ( false == $wp_cache_preload_on || true == $force ) {
 			wp_cache_debug( "Doing GC on supercache dir: {$cache_path}supercache", 2 );
 			$deleted = prune_super_cache( $cache_path . 'supercache', false, false );
@@ -2554,45 +2636,45 @@ function wp_cache_shutdown_callback() {
 		wp_cache_debug( 'wp_cache_shutdown_callback: Plugin not loaded. Setting feed ttl to 60 seconds.' );
 	}
 
-
 	if ( false == $new_cache ) {
 		wp_cache_debug( 'wp_cache_shutdown_callback: No cache file created. Returning.' );
 		return false;
 	}
 
-	$wp_cache_meta[ 'uri' ] = $WPSC_HTTP_HOST . preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $wp_cache_request_uri); // To avoid XSS attacks
-	$wp_cache_meta[ 'blog_id' ] = $blog_id;
-	$wp_cache_meta[ 'post' ] = wp_cache_post_id();
-	$wp_cache_meta[ 'key' ] = $wp_cache_key;
-	$wp_cache_meta = apply_filters( 'wp_cache_meta', $wp_cache_meta );
+	$wp_cache_meta['uri']     = $WPSC_HTTP_HOST . preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $wp_cache_request_uri ); // To avoid XSS attacks
+	$wp_cache_meta['blog_id'] = $blog_id;
+	$wp_cache_meta['post']    = wp_cache_post_id();
+	$wp_cache_meta['key']     = $wp_cache_key;
+	$wp_cache_meta            = apply_filters( 'wp_cache_meta', $wp_cache_meta );
 
 	$response = wp_cache_get_response_headers();
-	foreach( $response as $key => $value ) {
-		$wp_cache_meta[ 'headers' ][ $key ] = "$key: $value";
+	foreach ( $response as $key => $value ) {
+		$wp_cache_meta['headers'][ $key ] = "$key: $value";
 	}
 
 	wp_cache_debug( 'wp_cache_shutdown_callback: collecting meta data.', 2 );
 
-	if (!isset( $response['Last-Modified'] )) {
-		$value = gmdate('D, d M Y H:i:s') . ' GMT';
-		/* Dont send this the first time */
+	if ( ! isset( $response['Last-Modified'] ) ) {
+		$value = gmdate( 'D, d M Y H:i:s' ) . ' GMT';
+		/*
+		 Dont send this the first time */
 		/* @header('Last-Modified: ' . $value); */
-		$wp_cache_meta[ 'headers' ][ 'Last-Modified' ] = "Last-Modified: $value";
+		$wp_cache_meta['headers']['Last-Modified'] = "Last-Modified: $value";
 	}
 	$is_feed = false;
-	if ( !isset( $response[ 'Content-Type' ] ) && !isset( $response[ 'Content-type' ] ) ) {
+	if ( ! isset( $response['Content-Type'] ) && ! isset( $response['Content-type'] ) ) {
 		// On some systems, headers set by PHP can't be fetched from
 		// the output buffer. This is a last ditch effort to set the
 		// correct Content-Type header for feeds, if we didn't see
 		// it in the response headers already. -- dougal
-		if ( isset( $wp_super_cache_query[ 'is_feed' ] ) ) {
-			if ( isset( $wp_super_cache_query[ 'is_sitemap' ] ) )  {
+		if ( isset( $wp_super_cache_query['is_feed'] ) ) {
+			if ( isset( $wp_super_cache_query['is_sitemap'] ) ) {
 				$type  = 'sitemap';
 				$value = 'text/xml';
 			} else {
 				$type = get_query_var( 'feed' );
-				$type = str_replace('/','',$type);
-				switch ($type) {
+				$type = str_replace( '/', '', $type );
+				switch ( $type ) {
 					case 'atom':
 						$value = 'application/atom+xml';
 						break;
@@ -2608,29 +2690,30 @@ function wp_cache_shutdown_callback() {
 			$is_feed = true;
 
 			if ( isset( $wpsc_feed_ttl ) && $wpsc_feed_ttl == 1 ) {
-				$wp_cache_meta[ 'ttl' ] = 60;
+				$wp_cache_meta['ttl'] = 60;
 			}
 			$is_feed = true;
 
 			wp_cache_debug( "wp_cache_shutdown_callback: feed is type: $type - $value" );
-		} elseif ( isset( $wp_super_cache_query[ 'is_rest' ] ) ) { // json
+		} elseif ( isset( $wp_super_cache_query['is_rest'] ) ) { // json
 			$value = 'application/json';
 		} else { // not a feed
 			$value = get_option( 'html_type' );
-			if( $value == '' )
+			if ( $value == '' ) {
 				$value = 'text/html';
+			}
 		}
-		$value .=  "; charset=\"" . $wp_cache_blog_charset . "\"";
+		$value .= '; charset="' . $wp_cache_blog_charset . '"';
 
 		wp_cache_debug( "Sending 'Content-Type: $value' header.", 2 );
-		@header("Content-Type: $value");
-		$wp_cache_meta[ 'headers' ][ 'Content-Type' ] = "Content-Type: $value";
+		@header( "Content-Type: $value" );
+		$wp_cache_meta['headers']['Content-Type'] = "Content-Type: $value";
 	}
 
-	if ( $cache_enabled && !$supercacheonly && $new_cache ) {
-		if( !isset( $wp_cache_meta[ 'dynamic' ] ) && $wp_cache_gzip_encoding && !in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta[ 'headers' ] ) ) {
+	if ( $cache_enabled && ! $supercacheonly && $new_cache ) {
+		if ( ! isset( $wp_cache_meta['dynamic'] ) && $wp_cache_gzip_encoding && ! in_array( 'Content-Encoding: ' . $wp_cache_gzip_encoding, $wp_cache_meta['headers'] ) ) {
 			wp_cache_debug( 'Sending gzip headers.', 2 );
-			$wp_cache_meta[ 'headers' ][ 'Content-Encoding' ] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
+			$wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding;
 			if ( defined( 'WPSC_VARY_HEADER' ) ) {
 				if ( WPSC_VARY_HEADER != '' ) {
 					$vary_header = WPSC_VARY_HEADER;
@@ -2641,26 +2724,27 @@ function wp_cache_shutdown_callback() {
 				$vary_header = 'Accept-Encoding, Cookie';
 			}
 			if ( $vary_header ) {
-				$wp_cache_meta[ 'headers' ][ 'Vary' ] = 'Vary: ' . $vary_header;
+				$wp_cache_meta['headers']['Vary'] = 'Vary: ' . $vary_header;
 			}
 		}
 
 		$serial = '' . json_encode( $wp_cache_meta );
-		$dir = get_current_url_supercache_dir();
-		if( @is_dir( $dir ) == false )
+		$dir    = get_current_url_supercache_dir();
+		if ( @is_dir( $dir ) == false ) {
 			@wp_mkdir_p( $dir );
+		}
 
-		if( wp_cache_writers_entry() ) {
+		if ( wp_cache_writers_entry() ) {
 			wp_cache_debug( "Writing meta file: {$dir}meta-{$meta_file}", 2 );
 
-			$tmp_meta_filename = $dir . uniqid( mt_rand(), true ) . '.tmp';
-			$final_meta_filename = $dir . "meta-" . $meta_file;
-			$fr = @fopen( $tmp_meta_filename, 'w');
+			$tmp_meta_filename   = $dir . uniqid( mt_rand(), true ) . '.tmp';
+			$final_meta_filename = $dir . 'meta-' . $meta_file;
+			$fr                  = @fopen( $tmp_meta_filename, 'w' );
 			if ( $fr ) {
-				fputs($fr, $serial);
-				fclose($fr);
-				@chmod( $tmp_meta_filename, 0666 & ~umask());
-				if( !@rename( $tmp_meta_filename, $final_meta_filename ) ) {
+				fputs( $fr, $serial );
+				fclose( $fr );
+				@chmod( $tmp_meta_filename, 0666 & ~umask() );
+				if ( ! @rename( $tmp_meta_filename, $final_meta_filename ) ) {
 					@unlink( $dir . $final_meta_filename );
 					@rename( $tmp_meta_filename, $final_meta_filename );
 				}
@@ -2671,7 +2755,7 @@ function wp_cache_shutdown_callback() {
 
 			// record locations of archive feeds to be updated when the site is updated.
 			// Only record a maximum of 50 feeds to avoid bloating database.
-			if ( ( isset( $wp_super_cache_query[ 'is_feed' ] ) || $is_feed ) && ! isset( $wp_super_cache_query[ 'is_single' ] ) ) {
+			if ( ( isset( $wp_super_cache_query['is_feed'] ) || $is_feed ) && ! isset( $wp_super_cache_query['is_single'] ) ) {
 				$wpsc_feed_list = (array) get_option( 'wpsc_feed_list' );
 				if ( count( $wpsc_feed_list ) <= 50 ) {
 					$wpsc_feed_list[] = $dir . $meta_file;
@@ -2683,14 +2767,14 @@ function wp_cache_shutdown_callback() {
 		wp_cache_debug( "Did not write meta file: meta-{$meta_file}\nsupercacheonly: $supercacheonly\nwp_cache_not_logged_in: $wp_cache_not_logged_in\nnew_cache:$new_cache" );
 	}
 	global $time_to_gc_cache;
-	if( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 ) {
+	if ( isset( $time_to_gc_cache ) && $time_to_gc_cache == 1 ) {
 		wp_cache_debug( 'Executing wp_cache_gc action.', 3 );
 		do_action( 'wp_cache_gc' );
 	}
 }
 
-function wp_cache_no_postid($id) {
-	return wp_cache_post_change(wp_cache_post_id());
+function wp_cache_no_postid( $id ) {
+	return wp_cache_post_change( wp_cache_post_id() );
 }
 
 function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
@@ -2701,7 +2785,7 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
 	}
 
 	// Check is it "Empty Spam" or "Empty Trash"
-	if ( isset( $GLOBALS[ 'pagenow' ] ) && $GLOBALS[ 'pagenow' ] === 'edit-comments.php' &&
+	if ( isset( $GLOBALS['pagenow'] ) && $GLOBALS['pagenow'] === 'edit-comments.php' &&
 		( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
 	) {
 		wp_cache_debug( "Delete all SPAM or Trash comments. Don't delete any cache files.", 4 );
@@ -2709,23 +2793,23 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
 		return;
 	}
 
-	$comment = get_comment($comment_id, ARRAY_A);
+	$comment = get_comment( $comment_id, ARRAY_A );
 	if ( $status != 'NA' ) {
-		$comment[ 'old_comment_approved' ] = $comment[ 'comment_approved' ];
-		$comment[ 'comment_approved' ] = $status;
+		$comment['old_comment_approved'] = $comment['comment_approved'];
+		$comment['comment_approved']     = $status;
 	}
 
-	if ( ( $status == 'trash' || $status == 'spam' ) && $comment[ 'old_comment_approved' ] != 1 ) {
+	if ( ( $status == 'trash' || $status == 'spam' ) && $comment['old_comment_approved'] != 1 ) {
 		// don't modify cache if moderated comments are trashed or spammed
 		wp_cache_debug( "Moderated comment deleted or spammed. Don't delete any cache files.", 4 );
 		define( 'DONOTDELETECACHE', 1 );
 		return wp_cache_post_id();
 	}
-	$postid = isset( $comment[ 'comment_post_ID' ] ) ? (int) $comment[ 'comment_post_ID' ] : 0;
+	$postid = isset( $comment['comment_post_ID'] ) ? (int) $comment['comment_post_ID'] : 0;
 	// Do nothing if comment is not moderated
 	// http://ocaoimh.ie/2006/12/05/caching-wordpress-with-wp-cache-in-a-spam-filled-world
-	if ( !preg_match('/wp-admin\//', $wp_cache_request_uri) ) {
-		if ( $comment['comment_approved'] == 'delete' && ( isset( $comment[ 'old_comment_approved' ] ) && $comment[ 'old_comment_approved' ] == 0 ) ) { // do nothing if moderated comments are deleted
+	if ( ! preg_match( '/wp-admin\//', $wp_cache_request_uri ) ) {
+		if ( $comment['comment_approved'] == 'delete' && ( isset( $comment['old_comment_approved'] ) && $comment['old_comment_approved'] == 0 ) ) { // do nothing if moderated comments are deleted
 			wp_cache_debug( "Moderated comment deleted. Don't delete any cache files.", 4 );
 			define( 'DONOTDELETECACHE', 1 );
 			return $postid;
@@ -2733,8 +2817,8 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
 			wp_cache_debug( "Spam comment. Don't delete any cache files.", 4 );
 			define( 'DONOTDELETECACHE', 1 );
 			return $postid;
-		} elseif( $comment['comment_approved'] == '0' ) {
-			if ( $comment[ 'comment_type' ] == '' ) {
+		} elseif ( $comment['comment_approved'] == '0' ) {
+			if ( $comment['comment_type'] == '' ) {
 				wp_cache_debug( "Moderated comment. Don't delete supercache file until comment approved.", 4 );
 				$super_cache_enabled = 0; // don't remove the super cache static file until comment is approved
 				define( 'DONOTDELETECACHE', 1 );
@@ -2748,7 +2832,7 @@ function wp_cache_get_postid_from_comment( $comment_id, $status = 'NA' ) {
 	// We must check it up again due to WP bugs calling two different actions
 	// for delete, for example both wp_set_comment_status and delete_comment
 	// are called when deleting a comment
-	if ($postid > 0)  {
+	if ( $postid > 0 ) {
 		wp_cache_debug( "Post $postid changed. Update cache.", 4 );
 		return wp_cache_post_change( $postid );
 	} else {
@@ -2787,7 +2871,7 @@ function wpsc_delete_post_archives( $post ) {
 	}
 
 	// Taxonomies - categories, tags, custom taxonomies
-	foreach( get_object_taxonomies( $post, 'objects' ) as $taxonomy ) {
+	foreach ( get_object_taxonomies( $post, 'objects' ) as $taxonomy ) {
 
 		if ( ! $taxonomy->public || ! $taxonomy->rewrite ) {
 			continue;
@@ -2798,7 +2882,7 @@ function wpsc_delete_post_archives( $post ) {
 			continue;
 		}
 
-		foreach( $terms as $term ) {
+		foreach ( $terms as $term ) {
 
 			$term_url = get_term_link( $term, $taxonomy->name );
 			if ( is_wp_error( $term_url ) ) {
@@ -2837,25 +2921,27 @@ function wpsc_delete_cats_tags( $post ) {
 		_deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.3', 'wpsc_delete_post_archives' );
 	}
 
-	$post = get_post($post);
-	$categories = get_the_category($post->ID);
+	$post       = get_post( $post );
+	$categories = get_the_category( $post->ID );
 	if ( $categories ) {
-		$category_base = get_option( 'category_base');
-		if ( $category_base == '' )
+		$category_base = get_option( 'category_base' );
+		if ( $category_base == '' ) {
 			$category_base = '/category/';
+		}
 		$category_base = trailingslashit( $category_base ); // paranoid much?
-		foreach ($categories as $cat) {
-			prune_super_cache ( get_supercache_dir() . $category_base . $cat->slug . '/', true );
+		foreach ( $categories as $cat ) {
+			prune_super_cache( get_supercache_dir() . $category_base . $cat->slug . '/', true );
 			wp_cache_debug( 'wpsc_post_transition: deleting category: ' . get_supercache_dir() . $category_base . $cat->slug . '/' );
 		}
 	}
-	$posttags = get_the_tags($post->ID);
+	$posttags = get_the_tags( $post->ID );
 	if ( $posttags ) {
 		$tag_base = get_option( 'tag_base' );
-		if ( $tag_base == '' )
+		if ( $tag_base == '' ) {
 			$tag_base = '/tag/';
+		}
 		$tag_base = trailingslashit( str_replace( '..', '', $tag_base ) ); // maybe!
-		foreach ($posttags as $tag) {
+		foreach ( $posttags as $tag ) {
 			prune_super_cache( get_supercache_dir() . $tag_base . $tag->slug . '/', true );
 			wp_cache_debug( 'wpsc_post_transition: deleting tag: ' . get_supercache_dir() . $tag_base . $tag->slug . '/' );
 		}
@@ -2871,12 +2957,11 @@ function wpsc_post_transition( $new_status, $old_status, $post ) {
 
 	if ( $old_status === 'publish' && $new_status !== 'publish' ) { // post unpublished
 		if ( ! function_exists( 'get_sample_permalink' ) ) {
-			require_once( ABSPATH . 'wp-admin/includes/post.php' );
+			require_once ABSPATH . 'wp-admin/includes/post.php';
 		}
 		list( $permalink, $post_name ) = get_sample_permalink( $post );
-		$post_url = str_replace( array( "%postname%", "%pagename%" ), $post->post_name, $permalink );
-	}
-	elseif ( $old_status !== 'publish' && $new_status === 'publish' ) { // post published
+		$post_url                      = str_replace( array( '%postname%', '%pagename%' ), $post->post_name, $permalink );
+	} elseif ( $old_status !== 'publish' && $new_status === 'publish' ) { // post published
 		wp_cache_post_edit( $post->ID );
 		return;
 	}
@@ -2913,7 +2998,7 @@ function wp_cache_post_edit( $post_id ) {
 
 	// we want to process the post again just in case it becomes published before the second time this function is called.
 	$last_post_edited = $post_id;
-	if( $wp_cache_clear_on_post_edit ) {
+	if ( $wp_cache_clear_on_post_edit ) {
 		wp_cache_debug( "wp_cache_post_edit: Clearing cache $blog_cache_dir and {$cache_path}supercache/ on post edit per config.", 2 );
 		prune_super_cache( $blog_cache_dir, true );
 		prune_super_cache( get_supercache_dir(), true );
@@ -2928,8 +3013,9 @@ function wp_cache_post_edit( $post_id ) {
 function wp_cache_post_id_gc( $post_id, $all = 'all' ) {
 
 	$post_id = intval( $post_id );
-	if( $post_id == 0 )
+	if ( $post_id == 0 ) {
 		return true;
+	}
 
 	$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
 	if ( false !== strpos( $permalink, '?' ) ) {
@@ -3003,9 +3089,10 @@ function wp_cache_post_change( $post_id ) {
 	}
 
 	$all_backup = $all;
-	$all = apply_filters( 'wpsc_delete_related_pages_on_edit', $all ); // return 0 to disable deleting homepage and other pages.
-	if ( $all != $all_backup )
+	$all        = apply_filters( 'wpsc_delete_related_pages_on_edit', $all ); // return 0 to disable deleting homepage and other pages.
+	if ( $all != $all_backup ) {
 		wp_cache_debug( 'wp_cache_post_change: $all changed by wpsc_delete_related_pages_on_edit filter: ' . intval( $all ) );
+	}
 
 	// Delete supercache files whenever a post change event occurs, even if supercache is currently disabled.
 	$dir = get_supercache_dir();
@@ -3041,17 +3128,17 @@ function wp_cache_post_change( $post_id ) {
 	wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 );
 	$supercache_files_deleted = false;
 	if ( $handle = @opendir( $blog_cache_dir ) ) {
-		while ( false !== ($file = readdir($handle))) {
+		while ( false !== ( $file = readdir( $handle ) ) ) {
 			if ( strpos( $file, $file_prefix ) !== false ) {
 				if ( strpos( $file, '.html' ) ) {
 					// delete old wpcache files immediately
 					wp_cache_debug( "wp_cache_post_change: Deleting obsolete wpcache cache+meta files: $file" );
-					@unlink( $blog_cache_dir . $file);
+					@unlink( $blog_cache_dir . $file );
 					@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
 					continue;
 				} else {
 					$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
-					if( false == is_array( $meta ) ) {
+					if ( false == is_array( $meta ) ) {
 						wp_cache_debug( "Post change cleaning up stray file: $file", 4 );
 						@unlink( $blog_cache_dir . 'meta/' . $file );
 						@unlink( $blog_cache_dir . $file );
@@ -3059,7 +3146,7 @@ function wp_cache_post_change( $post_id ) {
 					}
 					if ( $post_id > 0 && $meta ) {
 						$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
-						if ( $meta[ 'blog_id' ] == $blog_id  && ( ( $all == true && !$meta[ 'post' ] ) || $meta[ 'post' ] == $post_id) ) {
+						if ( $meta['blog_id'] == $blog_id && ( ( $all == true && ! $meta['post'] ) || $meta['post'] == $post_id ) ) {
 							wp_cache_debug( "Post change: deleting post wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
 							@unlink( $blog_cache_dir . 'meta/' . $file );
 							@unlink( $blog_cache_dir . $file );
@@ -3070,39 +3157,49 @@ function wp_cache_post_change( $post_id ) {
 								do_action( 'gc_cache', 'rebuild', $permalink );
 							}
 						}
-					} elseif ( $meta[ 'blog_id' ] == $blog_id ) {
+					} elseif ( $meta['blog_id'] == $blog_id ) {
 						wp_cache_debug( "Post change: deleting wp-cache files for {$meta[ 'uri' ]}: $file", 4 );
 						@unlink( $blog_cache_dir . 'meta/' . $file );
 						@unlink( $blog_cache_dir . $file );
 						if ( $super_cache_enabled == true ) {
 							wp_cache_debug( "Post change: deleting supercache files for {$meta[ 'uri' ]}" );
-							wpsc_rebuild_files( $dir . $meta[ 'uri' ] );
-							do_action( 'gc_cache', 'rebuild', trailingslashit( $meta[ 'uri' ] ) );
+							wpsc_rebuild_files( $dir . $meta['uri'] );
+							do_action( 'gc_cache', 'rebuild', trailingslashit( $meta['uri'] ) );
 						}
 					}
 				}
 			}
 		}
-		closedir($handle);
+		closedir( $handle );
 	}
 	wp_cache_writers_exit();
 	return $post_id;
 }
 
-function wp_cache_microtime_diff($a, $b) {
-	list($a_dec, $a_sec) = explode(' ', $a);
-	list($b_dec, $b_sec) = explode(' ', $b);
-	return (float)$b_sec - (float)$a_sec + (float)$b_dec - (float)$a_dec;
+function wp_cache_microtime_diff( $a, $b ) {
+	list($a_dec, $a_sec) = explode( ' ', $a );
+	list($b_dec, $b_sec) = explode( ' ', $b );
+	return (float) $b_sec - (float) $a_sec + (float) $b_dec - (float) $a_dec;
 }
 
 function wp_cache_post_id() {
 	global $posts, $comment_post_ID, $post_ID;
 	// We try hard all options. More frequent first.
-	if ($post_ID > 0 ) return $post_ID;
-	if ($comment_post_ID > 0 )  return $comment_post_ID;
-	if (is_singular() && !empty($posts)) return $posts[0]->ID;
-	if (isset( $_GET[ 'p' ] ) && $_GET['p'] > 0) return $_GET['p'];
-	if (isset( $_POST[ 'p' ] ) && $_POST['p'] > 0) return $_POST['p'];
+	if ( $post_ID > 0 ) {
+		return $post_ID;
+	}
+	if ( $comment_post_ID > 0 ) {
+		return $comment_post_ID;
+	}
+	if ( is_singular() && ! empty( $posts ) ) {
+		return $posts[0]->ID;
+	}
+	if ( isset( $_GET['p'] ) && $_GET['p'] > 0 ) {
+		return $_GET['p'];
+	}
+	if ( isset( $_POST['p'] ) && $_POST['p'] > 0 ) {
+		return $_POST['p'];
+	}
 	return 0;
 }
 
@@ -3124,7 +3221,7 @@ function maybe_stop_gc( $flag ) {
 }
 function get_gc_flag() {
 	global $cache_path;
-	return $cache_path . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . "_wp_cache_gc.txt";
+	return $cache_path . strtolower( preg_replace( '!/:.*$!', '', str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'home' ) ) ) ) ) . '_wp_cache_gc.txt';
 }
 
 function wp_cache_gc_cron() {
@@ -3149,26 +3246,28 @@ function wp_cache_gc_cron() {
 
 	wp_cache_debug( 'Cache garbage collection.', 5 );
 
-	if( !isset( $cache_max_time ) )
+	if ( ! isset( $cache_max_time ) ) {
 		$cache_max_time = 600;
+	}
 
 	$start = time();
-	$num = 0;
-	if( false === ( $num = wp_cache_phase2_clean_expired( $file_prefix ) ) ) {
+	$num   = 0;
+	if ( false === ( $num = wp_cache_phase2_clean_expired( $file_prefix ) ) ) {
 		wp_cache_debug( 'Cache Expiry cron job failed. Probably mutex locked.', 1 );
 		update_option( 'wpsupercache_gc_time', time() - ( $cache_time_interval - 10 ) ); // if GC failed then run it again in one minute
 		$msg .= __( 'Cache expiry cron job failed. Job will run again in 10 seconds.', 'wp-super-cache' ) . "\n";
 	}
-	if( time() - $start > 30 ) {
+	if ( time() - $start > 30 ) {
 		wp_cache_debug( "Cache Expiry cron job took more than 30 seconds to execute.\nYou should reduce the Expiry Time in the WP Super Cache admin page\nas you probably have more cache files than your server can handle efficiently.", 1 );
 		$msg .= __( 'Cache expiry cron job took more than 30 seconds. You should probably run the garbage collector more often.', 'wp-super-cache' ) . "\n";
 	}
 
 	if ( $cache_gc_email_me ) {
-		if ( $msg != '' )
+		if ( $msg != '' ) {
 			$msg = "The following warnings were generated by the WP Super Cache Garbage Collector:\n" . $msg;
+		}
 
-		$msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int)$num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
+		$msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int) $num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
 
 		wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] WP Super Cache GC Report', 'wp-super-cache' ), home_url() ), $msg );
 	}
@@ -3180,28 +3279,31 @@ function wp_cache_gc_cron() {
 function schedule_wp_gc( $forced = 0 ) {
 	global $cache_schedule_type, $cache_max_time, $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval;
 
-	if ( false == isset( $cache_time_interval ) )
+	if ( false == isset( $cache_time_interval ) ) {
 		$cache_time_interval = 3600;
+	}
 
 	if ( false == isset( $cache_schedule_type ) ) {
-		$cache_schedule_type = 'interval';
+		$cache_schedule_type     = 'interval';
 		$cache_schedule_interval = $cache_max_time;
 	}
 	if ( $cache_schedule_type == 'interval' ) {
-		if ( !isset( $cache_max_time ) )
+		if ( ! isset( $cache_max_time ) ) {
 			$cache_max_time = 600;
-		if ( $cache_max_time == 0 )
+		}
+		if ( $cache_max_time == 0 ) {
 			return false;
-		$last_gc = get_option( "wpsupercache_gc_time" );
+		}
+		$last_gc = get_option( 'wpsupercache_gc_time' );
 
-		if ( !$last_gc ) {
+		if ( ! $last_gc ) {
 			update_option( 'wpsupercache_gc_time', time() );
-			$last_gc = get_option( "wpsupercache_gc_time" );
+			$last_gc = get_option( 'wpsupercache_gc_time' );
 		}
 		if ( $forced || ( $last_gc < ( time() - 60 ) ) ) { // Allow up to 60 seconds for the previous job to run
 			global $wp_cache_shutdown_gc;
-			if ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) {
-				if ( !($t = wp_next_scheduled( 'wp_cache_gc' ) ) ) {
+			if ( ! isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) {
+				if ( ! ( $t = wp_next_scheduled( 'wp_cache_gc' ) ) ) {
 					wp_clear_scheduled_hook( 'wp_cache_gc' );
 					wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
 					wp_cache_debug( 'scheduled wp_cache_gc for 10 seconds time.', 5 );
@@ -3211,7 +3313,7 @@ function schedule_wp_gc( $forced = 0 ) {
 				$time_to_gc_cache = 1; // tell the "shutdown gc" to run!
 			}
 		}
-	} elseif ( $cache_schedule_type == 'time' && !wp_next_scheduled( 'wp_cache_gc' ) ) {
+	} elseif ( $cache_schedule_type == 'time' && ! wp_next_scheduled( 'wp_cache_gc' ) ) {
 		wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
 	}
 	return true;
@@ -3236,7 +3338,7 @@ function apache_request_headers() {
 
 		foreach ( array_keys( $_SERVER ) as $skey ) {
 			if ( 0 === strpos( $skey, 'HTTP_' ) ) {
-				$header = implode( '-', array_map( 'ucfirst', array_slice( explode( '_', strtolower( $skey ) ) , 1 ) ) );
+				$header             = implode( '-', array_map( 'ucfirst', array_slice( explode( '_', strtolower( $skey ) ), 1 ) ) );
 				$headers[ $header ] = $_SERVER[ $skey ];
 			}
 		}
diff --git a/wp-cache.php b/wp-cache.php
index d30b100b3..1ba846de7 100644
--- a/wp-cache.php
+++ b/wp-cache.php
@@ -12,25 +12,25 @@
 */
 
 /*
-    Copyright Automattic and many other contributors.
+	Copyright Automattic and many other contributors.
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 2 of the License, or
+	(at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+	You should have received a copy of the GNU General Public License
+	along with this program; if not, write to the Free Software
+	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
 if ( ! function_exists( 'wp_cache_phase2' ) ) {
-	require_once( dirname( __FILE__ ) . '/wp-cache-phase2.php');
+	require_once __DIR__ . '/wp-cache-phase2.php' );
 }
 
 if ( ! defined( 'PHP_VERSION_ID' ) ) {
@@ -45,23 +45,23 @@ function wpsc_init() {
 
 	$wp_cache_config_file = WP_CONTENT_DIR . '/wp-cache-config.php';
 
-	if ( !defined( 'WPCACHEHOME' ) ) {
-		define( 'WPCACHEHOME', dirname( __FILE__ ) . '/' );
-		$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
+	if ( ! defined( 'WPCACHEHOME' ) ) {
+		define( 'WPCACHEHOME', __DIR__ . '/' );
+		$wp_cache_config_file_sample       = WPCACHEHOME . 'wp-cache-config-sample.php';
 		$wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
-	} elseif ( realpath( WPCACHEHOME ) != realpath( dirname( __FILE__ ) ) ) {
-		$wp_cache_config_file_sample = dirname( __FILE__ ) . '/wp-cache-config-sample.php';
-		$wpsc_advanced_cache_dist_filename = dirname( __FILE__ ) . '/advanced-cache.php';
+	} elseif ( realpath( WPCACHEHOME ) != realpath( __DIR__ ) ) {
+		$wp_cache_config_file_sample       = __DIR__ . '/wp-cache-config-sample.php';
+		$wpsc_advanced_cache_dist_filename = __DIR__ . '/advanced-cache.php';
 		if ( ! defined( 'ADVANCEDCACHEPROBLEM' ) ) {
 			define( 'ADVANCEDCACHEPROBLEM', 1 ); // force an update of WPCACHEHOME
 		}
 	} else {
-		$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
+		$wp_cache_config_file_sample       = WPCACHEHOME . 'wp-cache-config-sample.php';
 		$wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
 	}
 	$wpsc_advanced_cache_filename = WP_CONTENT_DIR . '/advanced-cache.php';
 
-	if ( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
+	if ( ! defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
 		$wp_cache_check_wp_config = true;
 	}
 }
@@ -87,19 +87,19 @@ function wpsc_init() {
 if ( ! isset( $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite, $cache_path ) &&
 	empty( $wp_cache_phase1_loaded ) &&
 	// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
-	! @include( $wp_cache_config_file )
+	! @include $wp_cache_config_file
 ) {
 	@include $wp_cache_config_file_sample; // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
 }
 
-include(WPCACHEHOME . 'wp-cache-base.php');
+require WPCACHEHOME . 'wp-cache-base.php';
 if ( class_exists( 'WP_REST_Controller' ) ) {
-	include( dirname( __FILE__ ) . '/rest/load.php' );
+	include __DIR__ . '/rest/load.php';
 }
 
 function wp_super_cache_init_action() {
 
-	load_plugin_textdomain( 'wp-super-cache', false, basename( dirname( __FILE__ ) ) . '/languages' );
+	load_plugin_textdomain( 'wp-super-cache', false, basename( __DIR__ ) . '/languages' );
 
 	wpsc_register_post_hooks();
 }
@@ -108,14 +108,14 @@ function wp_super_cache_init_action() {
 function wp_cache_set_home() {
 	global $wp_cache_is_home;
 	$wp_cache_is_home = ( is_front_page() || is_home() );
-	if ( $wp_cache_is_home && is_paged() )
+	if ( $wp_cache_is_home && is_paged() ) {
 		$wp_cache_is_home = false;
+	}
 }
 add_action( 'template_redirect', 'wp_cache_set_home' );
 
-
 // OSSDL CDN plugin (https://wordpress.org/plugins/ossdl-cdn-off-linker/)
-include_once( WPCACHEHOME . 'ossdl-cdn.php' );
+require_once WPCACHEHOME . 'ossdl-cdn.php';
 
 function get_wpcachehome() {
 	if ( function_exists( '_deprecated_function' ) ) {
@@ -123,10 +123,10 @@ function get_wpcachehome() {
 	}
 
 	if ( ! defined( 'WPCACHEHOME' ) ) {
-		if ( is_file( dirname( __FILE__ ) . '/wp-cache-config-sample.php' ) ) {
-			define( 'WPCACHEHOME', trailingslashit( dirname( __FILE__ ) ) );
-		} elseif ( is_file( dirname( __FILE__ ) . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
-			define( 'WPCACHEHOME', dirname( __FILE__ ) . '/wp-super-cache/' );
+		if ( is_file( __DIR__ . '/wp-cache-config-sample.php' ) ) {
+			define( 'WPCACHEHOME', trailingslashit( __DIR__ ) );
+		} elseif ( is_file( __DIR__ . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
+			define( 'WPCACHEHOME', __DIR__ . '/wp-super-cache/' );
 		} else {
 			die( sprintf( esc_html__( 'Please create %s /wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), esc_attr( WP_CONTENT_DIR ) ) );
 		}
@@ -138,8 +138,8 @@ function wpsc_remove_advanced_cache() {
 	if ( file_exists( $wpsc_advanced_cache_filename ) ) {
 		$file = file_get_contents( $wpsc_advanced_cache_filename );
 		if (
-			strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ||
-			strpos( $file, "WP SUPER CACHE 1.2" )
+			strpos( $file, 'WP SUPER CACHE 0.8.9.1' ) ||
+			strpos( $file, 'WP SUPER CACHE 1.2' )
 		) {
 			unlink( $wpsc_advanced_cache_filename );
 		}
@@ -189,15 +189,16 @@ function wpsupercache_deactivate() {
 	wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
 	wp_clear_scheduled_hook( 'wp_cache_gc' );
 	wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
-	wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file);
+	wp_cache_replace_line( '^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file );
 	wp_cache_disable_plugin( false ); // don't delete configuration file
 }
 register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
 
 function wpsupercache_activate() {
 	global $cache_path;
-	if ( ! isset( $cache_path ) || $cache_path == '' )
+	if ( ! isset( $cache_path ) || $cache_path == '' ) {
 		$cache_path = WP_CONTENT_DIR . '/cache/'; // from sample config file
+	}
 
 	ob_start();
 	wpsc_init();
@@ -266,7 +267,7 @@ function wp_cache_manager_error_checks() {
 
 	if ( '' == get_option( 'permalink_structure' ) ) {
 		echo '

' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '

'; - echo "

" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the Permalinks Options Page to configure your permalinks.', 'wp-super-cache' ) . "

"; + echo '

' . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the Permalinks Options Page to configure your permalinks.', 'wp-super-cache' ) . '

'; echo '
'; return false; } @@ -278,33 +279,42 @@ function wp_cache_manager_error_checks() {

+ if ( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) { + ?> +

Troubleshooting section of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?>

0.01, 'blocking' => true)); - if( is_array( $cron ) ) { - if( $cron[ 'response' ][ 'code' ] == '404' ) { - ?>

Warning! wp-cron.php not found!

+ $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash( '187425' ); + $cron = wp_remote_get( + $cron_url, + array( + 'timeout' => 0.01, + 'blocking' => true, + ) + ); + if ( is_array( $cron ) ) { + if ( $cron['response']['code'] == '404' ) { + ?> +

Warning! wp-cron.php not found!

Troubleshooting section of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?>

' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '

'; + echo '

' . __( 'Cannot continue... fix previous problems and retry.', 'wp-super-cache' ) . '

'; return false; } if ( false == function_exists( 'wpsc_deep_replace' ) ) { - $msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . '
'; + $msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:', 'wp-super-cache' ) . '
'; $msg .= "define( 'WP_CACHE', true );
"; - $msg .= "define( 'WPCACHEHOME', '" . dirname( __FILE__ ) . "/' );
"; + $msg .= "define( 'WPCACHEHOME', '" . __DIR__ . "/' );
"; wp_die( $msg ); } - if (!wp_cache_check_global_config()) { + if ( ! wp_cache_check_global_config() ) { return false; } - if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) { - ?>

-

this page for instructions on modifying your php.ini.', 'wp-super-cache' ); ?>

+

+

this page for instructions on modifying your php.ini.', 'wp-super-cache' ); ?>

+

-

+

+

+

+ if ( ! is_writeable_ACLSafe( $wp_cache_config_file ) ) { + if ( ! defined( 'SUBMITDISABLED' ) ) { + define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' ); + } + ?> +

%s/wp-cache-config.php and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WP_CONTENT_DIR ); ?>

This page explains how to change file permissions.', 'wp-super-cache' ); ?>

chmod 666 /wp-cache-config.php
chmod 644 /wp-cache-config.php

-
+

+ ?> +

this form to enable it.', 'wp-super-cache' ); ?>

@@ -389,17 +407,18 @@ function wp_cache_manager_error_checks() { // Server could be running as the owner of the wp-content directory. Therefore, if it's // writable, issue a warning only if the permissions aren't 755. - if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_readable_warning' ) { - wp_cache_replace_line('^ *\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file); + if ( $valid_nonce && isset( $_POST['action'] ) && $_POST['action'] == 'dismiss_readable_warning' ) { + wp_cache_replace_line( '^ *\$dismiss_readable_warning', '$dismiss_readable_warning = 1;', $wp_cache_config_file ); $dismiss_readable_warning = 1; - } elseif ( !isset( $dismiss_readable_warning ) ) { + } elseif ( ! isset( $dismiss_readable_warning ) ) { $dismiss_readable_warning = 0; } - if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) { - $wp_content_stat = stat(WP_CONTENT_DIR . '/'); - $wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 ); - if( substr( $wp_content_mode, -2 ) == '77' ) { - ?>

+ if ( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) { + $wp_content_stat = stat( WP_CONTENT_DIR . '/' ); + $wp_content_mode = decoct( $wp_content_stat['mode'] & 0777 ); + if ( substr( $wp_content_mode, -2 ) == '77' ) { + ?> +

chmod 755 /

This page explains how to change file permissions.', 'wp-super-cache' ); ?>

@@ -414,68 +433,79 @@ function wp_cache_manager_error_checks() { } } - if ( ! $is_nginx && function_exists( "is_main_site" ) && true == is_main_site() ) { - if ( ! isset( $htaccess_path ) ) { - $home_path = trailingslashit( get_home_path() ); - } else { - $home_path = $htaccess_path; - } - $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) ); - if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) { - echo '

' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . "

"; - echo "

" . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . "

" . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . "

"; - } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( + if ( ! $is_nginx && function_exists( 'is_main_site' ) && true == is_main_site() ) { + if ( ! isset( $htaccess_path ) ) { + $home_path = trailingslashit( get_home_path() ); + } else { + $home_path = $htaccess_path; + } + $scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) ); + if ( $cache_enabled && $wp_cache_mod_rewrite && ! $wp_cache_mobile_enabled && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) { + echo '

' . __( 'Mobile rewrite rules detected', 'wp-super-cache' ) . '

'; + echo '

' . __( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . '

' . __( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . '

'; + } elseif ( $wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && ( ( '' != $wp_cache_mobile_prefixes && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) ) ) || ( '' != $wp_cache_mobile_browsers && false === strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) ) ) ) ) { - ?> + ?>

  1. Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>
  2. # BEGIN WPSuperCache and # END WPSuperCache and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?>
  3. -
  4. # BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?>

    -
# BEGIN WPSuperCache and # END WPSuperCache. There are two sections that look very similar. Just below the line %%{HTTP:Cookie} !^.*(comment_author_|%2$s|wp-postpass_).*$ add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?>

+
+

+ if ( $cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '' ) { + ?> +

- Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>

Update Mod_Rewrite Rules button.', 'wp-super-cache' ); ?>

+ __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) ); - foreach( $required_modules as $req => $desc ) { - if( !in_array( $req, $mods ) ) { + $mods = apache_get_modules(); + $required_modules = array( + 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), + 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), + 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ), + ); + foreach ( $required_modules as $req => $desc ) { + if ( ! in_array( $req, $mods ) ) { $missing_mods[ $req ] = $desc; } } - if( isset( $missing_mods) && is_array( $missing_mods ) ) { - ?>

-

"; - foreach( $missing_mods as $req => $desc ) { - echo "
  • $req - $desc
  • "; - } - echo ""; - echo "
    "; + if ( isset( $missing_mods ) && is_array( $missing_mods ) ) { + ?> +

    +

    + '; + foreach ( $missing_mods as $req => $desc ) { + echo "
  • $req - $desc
  • "; + } + echo ''; + echo '
    '; } } - if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_htaccess_warning' ) { - wp_cache_replace_line('^ *\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file); + if ( $valid_nonce && isset( $_POST['action'] ) && $_POST['action'] == 'dismiss_htaccess_warning' ) { + wp_cache_replace_line( '^ *\$dismiss_htaccess_warning', '$dismiss_htaccess_warning = 1;', $wp_cache_config_file ); $dismiss_htaccess_warning = 1; - } elseif ( !isset( $dismiss_htaccess_warning ) ) { + } elseif ( ! isset( $dismiss_htaccess_warning ) ) { $dismiss_htaccess_warning = 0; } - if ( isset( $disable_supercache_htaccess_warning ) == false ) + if ( isset( $disable_supercache_htaccess_warning ) == false ) { $disable_supercache_htaccess_warning = false; + } if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) { - ?>

    + ?> +

    here. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.
    When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?>

    @@ -484,7 +514,8 @@ function wp_cache_manager_error_checks() { ' />
    -
    + ' . __( "Warning! You attempted to enable compression but zlib.output_compression is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ) . '
    '; + if ( 1 == ini_get( 'zlib.output_compression' ) || 'on' == strtolower( ini_get( 'zlib.output_compression' ) ) ) { + echo '
    ' . __( 'Warning! You attempted to enable compression but zlib.output_compression is enabled. See #21 in the Troubleshooting section of the readme file.', 'wp-super-cache' ) . '
    '; } else { if ( $new_cache_compression != $cache_compression ) { $cache_compression = $new_cache_compression; - wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file); - if ( function_exists( 'prune_super_cache' ) ) + wp_cache_replace_line( '^ *\$cache_compression', '$cache_compression = ' . $cache_compression . ';', $wp_cache_config_file ); + if ( function_exists( 'prune_super_cache' ) ) { prune_super_cache( $cache_path, true ); + } delete_option( 'super_cache_meta' ); } } } } } -if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' ) +if ( isset( $_GET['page'] ) && $_GET['page'] == 'wpsupercache' ) { add_action( 'admin_init', 'wp_cache_manager_updates' ); +} function wp_cache_manager() { global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled; @@ -770,19 +808,20 @@ function wp_cache_manager() { global $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled; global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx; - if ( !wpsupercache_site_admin() ) + if ( ! wpsupercache_site_admin() ) { return false; + } // used by mod_rewrite rules and config file - if ( function_exists( "cfmobi_default_browsers" ) ) { - $wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" ); - $wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) ); + if ( function_exists( 'cfmobi_default_browsers' ) ) { + $wp_cache_mobile_browsers = cfmobi_default_browsers( 'mobile' ); + $wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( 'touch' ) ); } elseif ( function_exists( 'lite_detection_ua_contains' ) ) { $wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() ); } else { $wp_cache_mobile_browsers = array( '2.0 MMP', '240x320', '400X240', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', 'EudoraWeb', 'Googlebot-Mobile', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', 'Nokia', 'Opera Mini', 'Palm', 'PlayStation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'SHARP-TQ-GX10', 'SHG-i900', 'Small', 'SonyEricsson', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'webOS', 'Windows CE', 'WinWAP', 'YahooSeeker/M1A1-R2D2', 'iPhone', 'iPod', 'iPad', 'Android', 'BlackBerry9530', 'LG-TU915 Obigo', 'LGE VX', 'webOS', 'Nokia5800' ); } - if ( function_exists( "lite_detection_ua_prefixes" ) ) { + if ( function_exists( 'lite_detection_ua_prefixes' ) ) { $wp_cache_mobile_prefixes = lite_detection_ua_prefixes(); } else { $wp_cache_mobile_prefixes = array( 'w3c ', 'w3c-', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'htc_', 'inno', 'ipaq', 'ipod', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'lg/u', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-', 'newt', 'noki', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox', 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'winw', 'winw', 'xda ', 'xda-' ); // from http://svn.wp-plugins.org/wordpress-mobile-pack/trunk/plugins/wpmp_switcher/lite_detection.php @@ -799,17 +838,21 @@ function wp_cache_manager() { $wp_cache_mobile_browsers = implode( ', ', $wp_cache_mobile_browsers ); $wp_cache_mobile_prefixes = implode( ', ', $wp_cache_mobile_prefixes ); - if ( false == apply_filters( 'wp_super_cache_error_checking', true ) ) + if ( false == apply_filters( 'wp_super_cache_error_checking', true ) ) { return false; + } - if ( function_exists( 'get_supercache_dir' ) ) + if ( function_exists( 'get_supercache_dir' ) ) { $supercachedir = get_supercache_dir(); - if( get_option( 'gzipcompression' ) == 1 ) + } + if ( get_option( 'gzipcompression' ) == 1 ) { update_option( 'gzipcompression', 0 ); - if( !isset( $cache_rebuild_files ) ) + } + if ( ! isset( $cache_rebuild_files ) ) { $cache_rebuild_files = 0; + } - $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false; + $valid_nonce = isset( $_REQUEST['_wpnonce'] ) ? wp_verify_nonce( $_REQUEST['_wpnonce'], 'wp-cache' ) : false; /* http://www.netlobo.com/div_hiding.html */ ?> "; + echo ''; echo '
    '; echo ''; echo ''; echo ''; - echo "\n"; - echo "\n"; + echo "\n"; + echo '\n"; echo ''; echo ''; - echo "\n"; + echo "\n"; echo "
    " . __( "seconds", 'wp-super-cache' ) . "
    " . __( 'How long should cached pages remain fresh? Set to 0 to disable garbage collection. A good starting point is 3600 seconds.', 'wp-super-cache' ) . "
    " . __( 'seconds', 'wp-super-cache' ) . "
    ' . __( 'How long should cached pages remain fresh? Set to 0 to disable garbage collection. A good starting point is 3600 seconds.', 'wp-super-cache' ) . "
    ' . __( 'Scheduler', 'wp-super-cache' ) . ''; - echo ""; + echo "'; echo ''; - echo ""; + echo "'; $schedules = wp_get_schedules(); echo ""; + echo ''; echo '
    " . __( "seconds", 'wp-super-cache' ) . '
    ' . __( 'Check for stale cached files every interval seconds.', 'wp-super-cache' ) . "
    " . __( 'seconds', 'wp-super-cache' ) . '
    ' . __( 'Check for stale cached files every interval seconds.', 'wp-super-cache' ) . '
    " . __( "HH:MM", 'wp-super-cache' ) . "
    " . __( 'Check for stale cached files at this time (UTC) or starting at this time every interval below.', 'wp-super-cache' ) . "
    ' . __( 'HH:MM', 'wp-super-cache' ) . '
    ' . __( 'Check for stale cached files at this time (UTC) or starting at this time every interval below.', 'wp-super-cache' ) . '

    " . __( 'Email me when the garbage collection runs.', 'wp-super-cache' ) . "
    ' . __( 'Email me when the garbage collection runs.', 'wp-super-cache' ) . "
    \n"; - echo "
    " . __( 'Garbage Collection', 'wp-super-cache' ) . "
    "; - echo "
    1. " . __( 'Garbage collection is the simple act of throwing out your garbage. For this plugin that would be old or stale cached files that may be out of date. New cached files are described as fresh.', 'wp-super-cache' ) . "
    2. \n"; - echo "
    3. " . __( 'Cached files are fresh for a limited length of time. You can set that time in the Cache Timeout text box on this page.', 'wp-super-cache' ) . "
    4. \n"; - echo "
    5. " . __( 'Stale cached files are not removed as soon as they become stale. They have to be removed by the garbage collecter. That is why you have to tell the plugin when the garbage collector should run.', 'wp-super-cache' ) . "
    6. \n"; - echo "
    7. " . __( 'Use the Timer or Clock schedulers to define when the garbage collector should run.', 'wp-super-cache' ) . "
    8. \n"; - echo "
    9. " . __( 'The Timer scheduler tells the plugin to run the garbage collector at regular intervals. When one garbage collection is done, the next run is scheduled.', 'wp-super-cache' ) . "
    10. \n"; - echo "
    11. " . __( 'Or, the Clock scheduler allows the garbage collection to run at specific times. If set to run hourly or twice daily, the garbage collector will be first scheduled for the time you enter here. It will then run again at the indicated interval. If set to run daily, it will run once a day at the time specified.', 'wp-super-cache' ) . "
    12. \n"; - echo "
    "; - echo "

    " . __( 'There are no best garbage collection settings but here are a few scenarios. Garbage collection is separate to other actions that clear our cached files like leaving a comment or publishing a post.', 'wp-super-cache' ) . "

    \n"; - echo "
      "; - echo "
    1. " . __( 'Sites that want to serve lots of newly generated data should set the Cache Timeout to 60 and use the Timer scheduler set to 90 seconds.', 'wp-super-cache' ) . "
    2. \n"; - echo "
    3. " . __( 'Sites with widgets and rss feeds in their sidebar should probably use a timeout of 3600 seconds and set the timer to 600 seconds. Stale files will be caught within 10 minutes of going stale.', 'wp-super-cache' ) . "
    4. \n"; - echo "
    5. " . __( 'Sites with lots of static content, no widgets or rss feeds in their sidebar can use a timeout of 86400 seconds or even more and set the timer to something equally long.', 'wp-super-cache' ) . "
    6. \n"; - echo "
    7. " . __( 'Sites where an external data source updates at a particular time every day should set the timeout to 86400 seconds and use the Clock scheduler set appropriately.', 'wp-super-cache' ) . "
    8. \n"; - echo "
    "; - echo "

    " . __( 'Checking for and deleting expired files is expensive, but it’s expensive leaving them there too. On a very busy site, you should set the expiry time to 600 seconds. Experiment with different values and visit this page to see how many expired files remain at different times during the day.', 'wp-super-cache' ) . "

    "; - echo "

    " . __( 'Set the expiry time to 0 seconds to disable garbage collection.', 'wp-super-cache' ) . "

    "; + echo '
    ' . __( 'Garbage Collection', 'wp-super-cache' ) . '
    '; + echo '
    1. ' . __( 'Garbage collection is the simple act of throwing out your garbage. For this plugin that would be old or stale cached files that may be out of date. New cached files are described as fresh.', 'wp-super-cache' ) . "
    2. \n"; + echo '
    3. ' . __( 'Cached files are fresh for a limited length of time. You can set that time in the Cache Timeout text box on this page.', 'wp-super-cache' ) . "
    4. \n"; + echo '
    5. ' . __( 'Stale cached files are not removed as soon as they become stale. They have to be removed by the garbage collecter. That is why you have to tell the plugin when the garbage collector should run.', 'wp-super-cache' ) . "
    6. \n"; + echo '
    7. ' . __( 'Use the Timer or Clock schedulers to define when the garbage collector should run.', 'wp-super-cache' ) . "
    8. \n"; + echo '
    9. ' . __( 'The Timer scheduler tells the plugin to run the garbage collector at regular intervals. When one garbage collection is done, the next run is scheduled.', 'wp-super-cache' ) . "
    10. \n"; + echo '
    11. ' . __( 'Or, the Clock scheduler allows the garbage collection to run at specific times. If set to run hourly or twice daily, the garbage collector will be first scheduled for the time you enter here. It will then run again at the indicated interval. If set to run daily, it will run once a day at the time specified.', 'wp-super-cache' ) . "
    12. \n"; + echo '
    '; + echo '

    ' . __( 'There are no best garbage collection settings but here are a few scenarios. Garbage collection is separate to other actions that clear our cached files like leaving a comment or publishing a post.', 'wp-super-cache' ) . "

    \n"; + echo '
      '; + echo '
    1. ' . __( 'Sites that want to serve lots of newly generated data should set the Cache Timeout to 60 and use the Timer scheduler set to 90 seconds.', 'wp-super-cache' ) . "
    2. \n"; + echo '
    3. ' . __( 'Sites with widgets and rss feeds in their sidebar should probably use a timeout of 3600 seconds and set the timer to 600 seconds. Stale files will be caught within 10 minutes of going stale.', 'wp-super-cache' ) . "
    4. \n"; + echo '
    5. ' . __( 'Sites with lots of static content, no widgets or rss feeds in their sidebar can use a timeout of 86400 seconds or even more and set the timer to something equally long.', 'wp-super-cache' ) . "
    6. \n"; + echo '
    7. ' . __( 'Sites where an external data source updates at a particular time every day should set the timeout to 86400 seconds and use the Clock scheduler set appropriately.', 'wp-super-cache' ) . "
    8. \n"; + echo '
    '; + echo '

    ' . __( 'Checking for and deleting expired files is expensive, but it’s expensive leaving them there too. On a very busy site, you should set the expiry time to 600 seconds. Experiment with different values and visit this page to see how many expired files remain at different times during the day.', 'wp-super-cache' ) . '

    '; + echo '

    ' . __( 'Set the expiry time to 0 seconds to disable garbage collection.', 'wp-super-cache' ) . '

    '; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; - ?>
    + + $ua ) { + foreach ( $cache_rejected_user_agent as $k => $ua ) { $cache_rejected_user_agent[ $k ] = str_replace( '___', ' ', $ua ); } reset( $cache_rejected_user_agent ); @@ -1916,15 +2107,15 @@ function wp_cache_edit_rejected_ua() { wp_cache_update_rejected_ua(); echo '

    ' . __( 'Rejected User Agents', 'wp-super-cache' ) . '

    '; - echo "

    " . __( 'Strings in the HTTP ’User Agent’ header that prevent WP-Cache from caching bot, spiders, and crawlers’ requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "

    \n"; + echo '

    ' . __( 'Strings in the HTTP ’User Agent’ header that prevent WP-Cache from caching bot, spiders, and crawlers’ requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "

    \n"; echo '
    '; echo ' '; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo '
    '; echo "
    \n"; } @@ -1932,15 +2123,15 @@ function wp_cache_edit_rejected_ua() { function wp_cache_update_rejected_pages() { global $wp_cache_config_file, $valid_nonce, $wp_cache_pages; - if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) { + if ( isset( $_POST['wp_edit_rejected_pages'] ) && $valid_nonce ) { $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'author', 'search' ); - foreach( $pages as $page ) { - if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) { + foreach ( $pages as $page ) { + if ( isset( $_POST['wp_cache_pages'][ $page ] ) ) { $value = 1; } else { $value = 0; } - wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file); + wp_cache_replace_line( '^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file ); $wp_cache_pages[ $page ] = $value; } } @@ -1956,19 +2147,19 @@ function wp_cache_edit_rejected_pages() { echo '

    ' . __( 'Do not cache the following page types. See the Conditional Tags documentation for a complete discussion on each type.', 'wp-super-cache' ) . '

    '; echo '
    '; echo ''; - echo '
    '; - echo '
    '; - echo '
    '; - echo '  
    '; - echo '
    '; - echo '  
    '; - echo '  
    '; - echo '
    '; - echo '
    '; - echo '
    '; + echo '
    '; + echo '
    '; + echo '
    '; + echo '  
    '; + echo '
    '; + echo '  
    '; + echo '  
    '; + echo '
    '; + echo '
    '; + echo '
    '; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; } @@ -1976,9 +2167,9 @@ function wp_cache_edit_rejected_pages() { function wp_cache_update_rejected_strings() { global $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; - if ( isset($_REQUEST['wp_rejected_uri']) && $valid_nonce ) { + if ( isset( $_REQUEST['wp_rejected_uri'] ) && $valid_nonce ) { $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri ); - wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file); + wp_cache_replace_line( '^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file ); } } @@ -1991,22 +2182,22 @@ function wp_cache_edit_rejected() { echo ''; echo '
    '; - echo "

    " . __( 'Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it’s enough to specify the year, i.e. ’/2004/’. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "

    \n"; + echo '

    ' . __( 'Add here strings (not a filename) that forces a page not to be cached. For example, if your URLs include year and you dont want to cache last year posts, it’s enough to specify the year, i.e. ’/2004/’. WP-Cache will search if that string is part of the URI and if so, it will not cache that page.', 'wp-super-cache' ) . "

    \n"; echo ' '; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; } function wp_cache_update_accepted_strings() { global $cache_acceptable_files, $wp_cache_config_file, $valid_nonce; - if ( isset( $_REQUEST[ 'wp_accepted_files' ] ) && $valid_nonce ) { - $text = wp_cache_sanitize_value( $_REQUEST[ 'wp_accepted_files' ], $cache_acceptable_files ); + if ( isset( $_REQUEST['wp_accepted_files'] ) && $valid_nonce ) { + $text = wp_cache_sanitize_value( $_REQUEST['wp_accepted_files'], $cache_acceptable_files ); wp_cache_replace_line( '^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file ); } } @@ -2019,14 +2210,14 @@ function wp_cache_edit_accepted() { echo ''; echo '
    '; - echo "

    " . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "

    \n"; + echo '

    ' . __( 'Add here those filenames that can be cached, even if they match one of the rejected substring specified above.', 'wp-super-cache' ) . "

    \n"; echo ' '; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; } @@ -2041,21 +2232,21 @@ function wpsc_update_debug_settings() { } if ( false == $valid_nonce ) { - return array ( - 'wp_super_cache_debug' => $wp_super_cache_debug, - 'wp_cache_debug_log' => $wp_cache_debug_log, - 'wp_cache_debug_ip' => $wp_cache_debug_ip, - 'wp_super_cache_comments' => $wp_super_cache_comments, - 'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check, - 'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear, - 'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text, + return array( + 'wp_super_cache_debug' => $wp_super_cache_debug, + 'wp_cache_debug_log' => $wp_cache_debug_log, + 'wp_cache_debug_ip' => $wp_cache_debug_ip, + 'wp_super_cache_comments' => $wp_super_cache_comments, + 'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check, + 'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear, + 'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text, 'wp_super_cache_front_page_notification' => $wp_super_cache_front_page_notification, - 'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug, - 'wp_cache_debug_username' => $wp_cache_debug_username, + 'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug, + 'wp_cache_debug_username' => $wp_cache_debug_username, ); } - if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $wp_cache_debug_log != '' ) { + if ( isset( $_POST['wpsc_delete_log'] ) && $_POST['wpsc_delete_log'] == 1 && $wp_cache_debug_log != '' ) { @unlink( $cache_path . $wp_cache_debug_log ); extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username } @@ -2065,49 +2256,49 @@ function wpsc_update_debug_settings() { } elseif ( ! file_exists( $cache_path . $wp_cache_debug_log ) ) { // make sure debug log exists before toggling debugging extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username } - $wp_super_cache_debug = ( isset( $_POST[ 'wp_super_cache_debug' ] ) && $_POST[ 'wp_super_cache_debug' ] == 1 ) ? 1 : 0; + $wp_super_cache_debug = ( isset( $_POST['wp_super_cache_debug'] ) && $_POST['wp_super_cache_debug'] == 1 ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_debug', $wp_super_cache_debug ); - if ( isset( $_POST[ 'wp_cache_debug' ] ) ) { + if ( isset( $_POST['wp_cache_debug'] ) ) { wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username ); wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log ); - $wp_super_cache_comments = isset( $_POST[ 'wp_super_cache_comments' ] ) ? 1 : 0; + $wp_super_cache_comments = isset( $_POST['wp_super_cache_comments'] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments ); - if ( isset( $_POST[ 'wp_cache_debug_ip' ] ) ) { - $wp_cache_debug_ip = esc_html( $_POST[ 'wp_cache_debug_ip' ] ); + if ( isset( $_POST['wp_cache_debug_ip'] ) ) { + $wp_cache_debug_ip = esc_html( $_POST['wp_cache_debug_ip'] ); } else { $wp_cache_debug_ip = ''; } wp_cache_setting( 'wp_cache_debug_ip', $wp_cache_debug_ip ); - $wp_super_cache_front_page_check = isset( $_POST[ 'wp_super_cache_front_page_check' ] ) ? 1 : 0; + $wp_super_cache_front_page_check = isset( $_POST['wp_super_cache_front_page_check'] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_front_page_check', $wp_super_cache_front_page_check ); - $wp_super_cache_front_page_clear = isset( $_POST[ 'wp_super_cache_front_page_clear' ] ) ? 1 : 0; + $wp_super_cache_front_page_clear = isset( $_POST['wp_super_cache_front_page_clear'] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_front_page_clear', $wp_super_cache_front_page_clear ); - if ( isset( $_POST[ 'wp_super_cache_front_page_text' ] ) ) { - $wp_super_cache_front_page_text = esc_html( $_POST[ 'wp_super_cache_front_page_text' ] ); + if ( isset( $_POST['wp_super_cache_front_page_text'] ) ) { + $wp_super_cache_front_page_text = esc_html( $_POST['wp_super_cache_front_page_text'] ); } else { $wp_super_cache_front_page_text = ''; } wp_cache_setting( 'wp_super_cache_front_page_text', $wp_super_cache_front_page_text ); - $wp_super_cache_front_page_notification = isset( $_POST[ 'wp_super_cache_front_page_notification' ] ) ? 1 : 0; + $wp_super_cache_front_page_notification = isset( $_POST['wp_super_cache_front_page_notification'] ) ? 1 : 0; wp_cache_setting( 'wp_super_cache_front_page_notification', $wp_super_cache_front_page_notification ); - if ( $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { - wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' ); + if ( $wp_super_cache_front_page_check == 1 && ! wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { + wp_schedule_single_event( time() + 360, 'wp_cache_check_site_hook' ); wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.' ); } } - return array ( - 'wp_super_cache_debug' => $wp_super_cache_debug, - 'wp_cache_debug_log' => $wp_cache_debug_log, - 'wp_cache_debug_ip' => $wp_cache_debug_ip, - 'wp_super_cache_comments' => $wp_super_cache_comments, - 'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check, - 'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear, - 'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text, + return array( + 'wp_super_cache_debug' => $wp_super_cache_debug, + 'wp_cache_debug_log' => $wp_cache_debug_log, + 'wp_cache_debug_ip' => $wp_cache_debug_ip, + 'wp_super_cache_comments' => $wp_super_cache_comments, + 'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check, + 'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear, + 'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text, 'wp_super_cache_front_page_notification' => $wp_super_cache_front_page_notification, - 'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug, - 'wp_cache_debug_username' => $wp_cache_debug_username, + 'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug, + 'wp_cache_debug_username' => $wp_cache_debug_username, ); } @@ -2129,54 +2320,54 @@ function wp_cache_debug_settings() { $log_file_link = "$wp_cache_debug_log"; if ( $wp_super_cache_debug == 1 ) { - echo "

    " . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "

    "; + echo '

    ' . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . '

    '; } else { - echo "

    " . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "

    "; + echo '

    ' . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . '

    '; } - echo "

    " . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "

    "; + echo '

    ' . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . '

    '; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo ""; submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log_form', false ); - echo "
    "; + echo ''; echo '
    '; if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) { $debug_status_message = __( 'Enable Logging', 'wp-super-cache' ); - $not_status = 1; + $not_status = 1; } else { $debug_status_message = __( 'Disable Logging', 'wp-super-cache' ); - $not_status = 0; + $not_status = 0; } echo ""; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); submit_button( $debug_status_message, 'primary', 'wpsc_log_status', true ); - echo "
    "; + echo ''; echo '
    '; echo "
    "; echo ""; - echo ""; - echo ""; + echo ''; + echo "'; echo "
    " . __( 'IP Address', 'wp-super-cache' ) . " " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "
    " . __( 'Cache Status Messages', 'wp-super-cache' ) . " " . __( 'enabled', 'wp-super-cache' ) . "
    "; - echo __( 'Display comments at the end of every page like this:', 'wp-super-cache' ) . "
    "; - echo "
    <!-- Dynamic page generated in 0.450 seconds. -->
    -<!-- Cached page generated by WP-Super-Cache on " . date( "Y-m-d H:i:s", time() ) . " -->
    -<!-- super cache -->
    ' . __( 'IP Address', 'wp-super-cache' ) . " " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER['REMOTE_ADDR'] ) . '
    " . __( 'Cache Status Messages', 'wp-super-cache' ) . " ' . __( 'enabled', 'wp-super-cache' ) . '
    '; + echo __( 'Display comments at the end of every page like this:', 'wp-super-cache' ) . '
    '; + echo '
    <!-- Dynamic page generated in 0.450 seconds. -->
    +<!-- Cached page generated by WP-Super-Cache on ' . date( 'Y-m-d H:i:s', time() ) . ' -->
    +<!-- super cache -->
    \n"; if ( isset( $wp_super_cache_advanced_debug ) ) { - echo "
    " . __( 'Advanced', 'wp-super-cache' ) . "

    " . __( 'In very rare cases two problems may arise on some blogs:

    1. The front page may start downloading as a zip file.
    2. The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is /%category%/%postname%/.
    ', 'wp-super-cache' ) . '

    '; - echo "

    " . __( 'I’m 99% certain that they aren’t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you’re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "

    "; + echo '
    ' . __( 'Advanced', 'wp-super-cache' ) . '

    ' . __( 'In very rare cases two problems may arise on some blogs:

    1. The front page may start downloading as a zip file.
    2. The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is /%category%/%postname%/.
    ', 'wp-super-cache' ) . '

    '; + echo '

    ' . __( 'I’m 99% certain that they aren’t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you’re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . '

    '; echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + echo "'; + echo "'; + echo "'; + echo "'; echo "
    " . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "
    " . __( 'Front page text', 'wp-super-cache' ) . " (" . __( 'Text to search for on your front page. If this text is missing, the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")
    " . __( 'Clear cache on error.', 'wp-super-cache' ) . "
    " . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "
    ' . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . '
    " . __( 'Front page text', 'wp-super-cache' ) . " (" . __( 'Text to search for on your front page. If this text is missing, the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ')
    ' . __( 'Clear cache on error.', 'wp-super-cache' ) . '
    ' . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . '
    \n"; } echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; echo ''; } @@ -2295,23 +2486,23 @@ function wp_cache_remove_index() { return; } - @unlink( $cache_path . "index.html" ); - @unlink( $cache_path . "supercache/index.html" ); - @unlink( $cache_path . "blogs/index.html" ); - if ( is_dir( $cache_path . "blogs" ) ) { - $dir = new DirectoryIterator( $cache_path . "blogs" ); - foreach( $dir as $fileinfo ) { + @unlink( $cache_path . 'index.html' ); + @unlink( $cache_path . 'supercache/index.html' ); + @unlink( $cache_path . 'blogs/index.html' ); + if ( is_dir( $cache_path . 'blogs' ) ) { + $dir = new DirectoryIterator( $cache_path . 'blogs' ); + foreach ( $dir as $fileinfo ) { if ( $fileinfo->isDot() ) { continue; } if ( $fileinfo->isDir() ) { - $directory = $cache_path . "blogs/" . $fileinfo->getFilename(); - if ( is_file( $directory . "/index.html" ) ) { - unlink( $directory . "/index.html" ); + $directory = $cache_path . 'blogs/' . $fileinfo->getFilename(); + if ( is_file( $directory . '/index.html' ) ) { + unlink( $directory . '/index.html' ); } - if ( is_dir( $directory . "/meta" ) ) { - if ( is_file( $directory . "/meta/index.html" ) ) { - unlink( $directory . "/meta/index.html" ); + if ( is_dir( $directory . '/meta' ) ) { + if ( is_file( $directory . '/meta/index.html' ) ) { + unlink( $directory . '/meta/index.html' ); } } } @@ -2322,40 +2513,43 @@ function wp_cache_remove_index() { function wp_cache_index_notice() { global $wp_version, $cache_path; - if ( false == wpsupercache_site_admin() ) + if ( false == wpsupercache_site_admin() ) { return false; - if ( false == get_site_option( 'wp_super_cache_index_detected' ) ) + } + if ( false == get_site_option( 'wp_super_cache_index_detected' ) ) { return false; + } if ( strlen( $cache_path ) < strlen( ABSPATH ) - || ABSPATH != substr( $cache_path, 0, strlen( ABSPATH ) ) ) + || ABSPATH != substr( $cache_path, 0, strlen( ABSPATH ) ) ) { return false; // cache stored outside web root + } if ( get_site_option( 'wp_super_cache_index_detected' ) == 2 ) { update_site_option( 'wp_super_cache_index_detected', 3 ); echo "
    "; - echo "

    " . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '

    '; + echo '

    ' . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '

    '; echo '

    ' . __( 'All users of this site have been logged out to refresh their login cookies.', 'wp-super-cache' ) . '

    '; echo '
    '; return false; } elseif ( get_site_option( 'wp_super_cache_index_detected' ) != 3 ) { echo "
    "; - echo "

    " . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '

    '; + echo '

    ' . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '

    '; echo '

    ' . __( 'Your server is configured to show files and directories, which may expose sensitive data such as login cookies to attackers in the cache directories. That has been fixed by adding a file named index.html to each directory. If you use simple caching, consider moving the location of the cache directory on the Advanced Settings page.', 'wp-super-cache' ) . '

    '; - echo "

    "; + echo '

    '; _e( 'If you just installed WP Super Cache for the first time, you can dismiss this message. Otherwise, you should probably refresh the login cookies of all logged in WordPress users here by clicking the logout link below.', 'wp-super-cache' ); - echo "

    "; + echo '

    '; if ( -1 == version_compare( $wp_version, '4.0' ) ) { echo '

    ' . __( 'Your site is using a very old version of WordPress. When you update to the latest version everyone will be logged out and cookie information updated.', 'wp-super-cache' ) . '

    '; } else { echo '

    ' . __( 'The logout link will log out all WordPress users on this site except you. Your authentication cookie will be updated, but you will not be logged out.', 'wp-super-cache' ) . '

    '; } - echo "" . __( 'Dismiss', 'wp-super-cache' ) . ""; + echo "" . __( 'Dismiss', 'wp-super-cache' ) . ''; if ( 1 == version_compare( $wp_version, '4.0' ) ) { - echo " | " . __( 'Logout', 'wp-super-cache' ) . ""; + echo " | " . __( 'Logout', 'wp-super-cache' ) . ''; } - echo "
    "; -?> + echo ''; + ?> -ID; WP_Session_Tokens::destroy_all_for_all_users(); wp_set_auth_cookie( $user_id, false, is_ssl() ); @@ -2421,35 +2615,38 @@ function wp_cache_logout_all() { wp_redirect( admin_url() ); } } -if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' ) +if ( isset( $_GET['action'] ) && $_GET['action'] == 'wpsclogout' ) { add_action( 'admin_init', 'wp_cache_logout_all' ); +} function wp_cache_add_index_protection() { global $cache_path, $blog_cache_dir; if ( is_dir( $cache_path ) && false == is_file( "$cache_path/index.html" ) ) { - $page = wp_remote_get( home_url( "/wp-content/cache/" ) ); + $page = wp_remote_get( home_url( '/wp-content/cache/' ) ); if ( false == is_wp_error( $page ) ) { if ( false == get_site_option( 'wp_super_cache_index_detected' ) - && $page[ 'response' ][ 'code' ] == 200 - && stripos( $page[ 'body' ], 'index of' ) ) { + && $page['response']['code'] == 200 + && stripos( $page['body'], 'index of' ) ) { add_site_option( 'wp_super_cache_index_detected', 1 ); // only show this once } } if ( ! function_exists( 'insert_with_markers' ) ) { - include_once( ABSPATH . 'wp-admin/includes/misc.php' ); + include_once ABSPATH . 'wp-admin/includes/misc.php'; } - insert_with_markers( $cache_path . '.htaccess', "INDEX", array( 'Options -Indexes' ) ); + insert_with_markers( $cache_path . '.htaccess', 'INDEX', array( 'Options -Indexes' ) ); } - $directories = array( $cache_path, $cache_path . '/supercache/', $cache_path . '/blogs/', $blog_cache_dir, $blog_cache_dir . "/meta" ); - foreach( $directories as $dir ) { - if ( false == is_dir( $dir ) ) + $directories = array( $cache_path, $cache_path . '/supercache/', $cache_path . '/blogs/', $blog_cache_dir, $blog_cache_dir . '/meta' ); + foreach ( $directories as $dir ) { + if ( false == is_dir( $dir ) ) { @mkdir( $dir ); + } if ( is_dir( $dir ) && false == is_file( "$dir/index.html" ) ) { $fp = @fopen( "$dir/index.html", 'w' ); - if ( $fp ) + if ( $fp ) { fclose( $fp ); + } } } } @@ -2459,24 +2656,26 @@ function wp_cache_add_site_cache_index() { wp_cache_add_index_protection(); // root and supercache - if ( is_dir( $cache_path . "blogs" ) ) { - $dir = new DirectoryIterator( $cache_path . "blogs" ); - foreach( $dir as $fileinfo ) { + if ( is_dir( $cache_path . 'blogs' ) ) { + $dir = new DirectoryIterator( $cache_path . 'blogs' ); + foreach ( $dir as $fileinfo ) { if ( $fileinfo->isDot() ) { continue; } if ( $fileinfo->isDir() ) { - $directory = $cache_path . "blogs/" . $fileinfo->getFilename(); - if ( false == is_file( $directory . "/index.html" ) ) { - $fp = @fopen( $directory . "/index.html", 'w' ); - if ( $fp ) + $directory = $cache_path . 'blogs/' . $fileinfo->getFilename(); + if ( false == is_file( $directory . '/index.html' ) ) { + $fp = @fopen( $directory . '/index.html', 'w' ); + if ( $fp ) { fclose( $fp ); + } } - if ( is_dir( $directory . "/meta" ) ) { - if ( false == is_file( $directory . "/meta/index.html" ) ) { - $fp = @fopen( $directory . "/meta/index.html", 'w' ); - if ( $fp ) + if ( is_dir( $directory . '/meta' ) ) { + if ( false == is_file( $directory . '/meta/index.html' ) ) { + $fp = @fopen( $directory . '/meta/index.html', 'w' ); + if ( $fp ) { fclose( $fp ); + } } } } @@ -2487,30 +2686,32 @@ function wp_cache_add_site_cache_index() { function wp_cache_verify_cache_dir() { global $cache_path, $blog_cache_dir; - $dir = dirname($cache_path); - if ( !file_exists($cache_path) ) { - if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) { - echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory (%1$s) did not exist and couldn’t be created by the web server. Check %1$s permissions.', 'wp-super-cache' ), $dir ); + $dir = dirname( $cache_path ); + if ( ! file_exists( $cache_path ) ) { + if ( ! is_writeable_ACLSafe( $dir ) || ! ( $dir = mkdir( $cache_path ) ) ) { + echo '' . __( 'Error', 'wp-super-cache' ) . ': ' . sprintf( __( 'Your cache directory (%1$s) did not exist and couldn’t be created by the web server. Check %1$s permissions.', 'wp-super-cache' ), $dir ); return false; } } - if ( !is_writeable_ACLSafe($cache_path)) { - echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your cache directory (%1$s) or %2$s need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir ); + if ( ! is_writeable_ACLSafe( $cache_path ) ) { + echo '' . __( 'Error', 'wp-super-cache' ) . ': ' . sprintf( __( 'Your cache directory (%1$s) or %2$s need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir ); return false; } - if ( '/' != substr($cache_path, -1)) { + if ( '/' != substr( $cache_path, -1 ) ) { $cache_path .= '/'; } - if( false == is_dir( $blog_cache_dir ) ) { - @mkdir( $cache_path . "blogs" ); - if( $blog_cache_dir != $cache_path . "blogs/" ) + if ( false == is_dir( $blog_cache_dir ) ) { + @mkdir( $cache_path . 'blogs' ); + if ( $blog_cache_dir != $cache_path . 'blogs/' ) { @mkdir( $blog_cache_dir ); + } } - if( false == is_dir( $blog_cache_dir . 'meta' ) ) + if ( false == is_dir( $blog_cache_dir . 'meta' ) ) { @mkdir( $blog_cache_dir . 'meta' ); + } wp_cache_add_index_protection(); return true; @@ -2521,43 +2722,43 @@ function wp_cache_verify_config_file() { global $WPSC_HTTP_HOST; $new = false; - $dir = dirname($wp_cache_config_file); + $dir = dirname( $wp_cache_config_file ); - if ( file_exists($wp_cache_config_file) ) { + if ( file_exists( $wp_cache_config_file ) ) { $lines = join( ' ', file( $wp_cache_config_file ) ); - if( strpos( $lines, 'WPCACHEHOME' ) === false ) { - if( is_writeable_ACLSafe( $wp_cache_config_file ) ) { + if ( strpos( $lines, 'WPCACHEHOME' ) === false ) { + if ( is_writeable_ACLSafe( $wp_cache_config_file ) ) { @unlink( $wp_cache_config_file ); } else { - echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Your WP-Cache config file (%s) is out of date and not writable by the Web server. Please delete it and refresh this page.', 'wp-super-cache' ), $wp_cache_config_file ); + echo '' . __( 'Error', 'wp-super-cache' ) . ': ' . sprintf( __( 'Your WP-Cache config file (%s) is out of date and not writable by the Web server. Please delete it and refresh this page.', 'wp-super-cache' ), $wp_cache_config_file ); return false; } } - } elseif( !is_writeable_ACLSafe($dir)) { - echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Configuration file missing and %1$s directory (%2$s) is not writable by the web server. Check its permissions.', 'wp-super-cache' ), WP_CONTENT_DIR, $dir ); + } elseif ( ! is_writeable_ACLSafe( $dir ) ) { + echo '' . __( 'Error', 'wp-super-cache' ) . ': ' . sprintf( __( 'Configuration file missing and %1$s directory (%2$s) is not writable by the web server. Check its permissions.', 'wp-super-cache' ), WP_CONTENT_DIR, $dir ); return false; } - if ( !file_exists($wp_cache_config_file) ) { - if ( !file_exists($wp_cache_config_file_sample) ) { - echo "" . __( 'Error', 'wp-super-cache' ) . ": " . sprintf( __( 'Sample WP-Cache config file (%s) does not exist. Verify your installation.', 'wp-super-cache' ), $wp_cache_config_file_sample ); + if ( ! file_exists( $wp_cache_config_file ) ) { + if ( ! file_exists( $wp_cache_config_file_sample ) ) { + echo '' . __( 'Error', 'wp-super-cache' ) . ': ' . sprintf( __( 'Sample WP-Cache config file (%s) does not exist. Verify your installation.', 'wp-super-cache' ), $wp_cache_config_file_sample ); return false; } - copy($wp_cache_config_file_sample, $wp_cache_config_file); - $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', dirname(__FILE__) ) ); - if( is_file( dirname(__FILE__) . '/wp-cache-config-sample.php' ) ) { - wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file); - } elseif( is_file( dirname(__FILE__) . '/wp-super-cache/wp-cache-config-sample.php' ) ) { - wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file); + copy( $wp_cache_config_file_sample, $wp_cache_config_file ); + $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', ( __DIR__ ) ) ); + if ( is_file( ( __DIR__ ) . '/wp-cache-config-sample.php' ) ) { + wp_cache_replace_line( 'define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file ); + } elseif ( is_file( ( __DIR__ ) . '/wp-super-cache/wp-cache-config-sample.php' ) ) { + wp_cache_replace_line( 'define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file ); } $new = true; } if ( $sem_id == 5419 && $cache_path != '' && $WPSC_HTTP_HOST != '' ) { $sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff; - wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file); + wp_cache_replace_line( 'sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file ); } if ( $new ) { - require($wp_cache_config_file); + require $wp_cache_config_file; wpsc_set_default_gc( true ); } return true; @@ -2565,25 +2766,25 @@ function wp_cache_verify_config_file() { function wp_cache_create_advanced_cache() { global $wpsc_advanced_cache_filename, $wpsc_advanced_cache_dist_filename; - if ( file_exists( ABSPATH . 'wp-config.php') ) { + if ( file_exists( ABSPATH . 'wp-config.php' ) ) { $global_config_file = ABSPATH . 'wp-config.php'; } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) { $global_config_file = dirname( ABSPATH ) . '/wp-config.php'; } elseif ( defined( 'DEBIAN_FILE' ) && file_exists( DEBIAN_FILE ) ) { $global_config_file = DEBIAN_FILE; } else { - die('Cannot locate wp-config.php'); + die( 'Cannot locate wp-config.php' ); } - $line = 'define( \'WPCACHEHOME\', \'' . dirname( __FILE__ ) . '/\' );'; + $line = 'define( \'WPCACHEHOME\', \'' . __DIR__ . '/\' );'; if ( ! apply_filters( 'wpsc_enable_wp_config_edit', true ) ) { - echo '

    ' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Not allowed to edit %s per configuration.', 'wp-super-cache' ), $global_config_file ) . "

    "; + echo '

    ' . __( 'Warning', 'wp-super-cache' ) . '! ' . sprintf( __( 'Not allowed to edit %s per configuration.', 'wp-super-cache' ), $global_config_file ) . '

    '; return false; } if ( - ! strpos( file_get_contents( $global_config_file ), "WPCACHEHOME" ) || + ! strpos( file_get_contents( $global_config_file ), 'WPCACHEHOME' ) || ( defined( 'WPCACHEHOME' ) && ( @@ -2599,7 +2800,7 @@ function wp_cache_create_advanced_cache() { ! is_writeable_ACLSafe( $global_config_file ) || ! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', $line, $global_config_file ) ) { - echo '

    ' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Could not update %s! WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "

    "; + echo '

    ' . __( 'Warning', 'wp-super-cache' ) . '! ' . sprintf( __( 'Could not update %s! WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . '

    '; return false; } } @@ -2608,16 +2809,16 @@ function wp_cache_create_advanced_cache() { if ( file_exists( $wpsc_advanced_cache_filename ) ) { $file = file_get_contents( $wpsc_advanced_cache_filename ); if ( - ! strpos( $file, "WP SUPER CACHE 0.8.9.1" ) && - ! strpos( $file, "WP SUPER CACHE 1.2" ) + ! strpos( $file, 'WP SUPER CACHE 0.8.9.1' ) && + ! strpos( $file, 'WP SUPER CACHE 1.2' ) ) { return false; } } $file = file_get_contents( $wpsc_advanced_cache_dist_filename ); - $fp = @fopen( $wpsc_advanced_cache_filename, 'w' ); - if( $fp ) { + $fp = @fopen( $wpsc_advanced_cache_filename, 'w' ); + if ( $fp ) { fputs( $fp, $file ); fclose( $fp ); } else { @@ -2629,15 +2830,15 @@ function wp_cache_create_advanced_cache() { function wpsc_check_advanced_cache() { global $wpsc_advanced_cache_filename; - $ret = true; + $ret = true; $other_advanced_cache = false; if ( file_exists( $wpsc_advanced_cache_filename ) ) { $file = file_get_contents( $wpsc_advanced_cache_filename ); - if ( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) { + if ( strpos( $file, 'WP SUPER CACHE 0.8.9.1' ) || strpos( $file, 'WP SUPER CACHE 1.2' ) ) { return true; } else { $other_advanced_cache = true; - $ret = wp_cache_create_advanced_cache(); + $ret = wp_cache_create_advanced_cache(); } } else { $ret = wp_cache_create_advanced_cache(); @@ -2645,7 +2846,7 @@ function wpsc_check_advanced_cache() { if ( false == $ret ) { if ( $other_advanced_cache ) { - echo '

    ' . __( 'Warning! You may not be allowed to use this plugin on your site.', 'wp-super-cache' ) . "

    "; + echo '

    ' . __( 'Warning! You may not be allowed to use this plugin on your site.', 'wp-super-cache' ) . '

    '; echo '

    ' . sprintf( __( 'The file %s was created by another plugin or by your system administrator. Please examine the file carefully by FTP or SSH and consult your hosting documentation. ', 'wp-super-cache' ), @@ -2659,19 +2860,19 @@ function wpsc_check_advanced_cache() { __( 'If you need support for this problem contact your hosting provider.', 'wp-super-cache' ), '

    '; } elseif ( ! is_writeable_ACLSafe( $wpsc_advanced_cache_filename ) ) { - echo '

    ' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( '%s/advanced-cache.php cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "

    "; + echo '

    ' . __( 'Warning', 'wp-super-cache' ) . '! ' . sprintf( __( '%s/advanced-cache.php cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . '

    '; echo '
      '; - echo "
    1. " . + echo '
    2. ' . sprintf( __( 'Make %1$s writable using the chmod command through your ftp or server software. (chmod 777 %1$s) and refresh this page. This is only a temporary measure and you’ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ), WP_CONTENT_DIR ) . - "
    3. "; - echo "
    4. " . sprintf( __( 'Refresh this page to update %s/advanced-cache.php', 'wp-super-cache' ), WP_CONTENT_DIR ) . "
    "; - echo sprintf( __( 'If that doesn’t work, make sure the file %s/advanced-cache.php doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "
      "; - echo "
    "; + ''; + echo '
  • ' . sprintf( __( 'Refresh this page to update %s/advanced-cache.php', 'wp-super-cache' ), WP_CONTENT_DIR ) . '
  • '; + echo sprintf( __( 'If that doesn’t work, make sure the file %s/advanced-cache.php doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . '
      '; + echo '
    '; } - echo "
    "; + echo '
    '; return false; } return true; @@ -2680,11 +2881,11 @@ function wpsc_check_advanced_cache() { function wp_cache_check_global_config() { global $wp_cache_check_wp_config; - if ( !isset( $wp_cache_check_wp_config ) ) + if ( ! isset( $wp_cache_check_wp_config ) ) { return true; + } - - if ( file_exists( ABSPATH . 'wp-config.php') ) { + if ( file_exists( ABSPATH . 'wp-config.php' ) ) { $global_config_file = ABSPATH . 'wp-config.php'; } else { $global_config_file = dirname( ABSPATH ) . '/wp-config.php'; @@ -2696,41 +2897,41 @@ function wp_cache_check_global_config() { ! wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', $line, $global_config_file ) ) { if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) { - echo '
    ' . __( "

    WP_CACHE constant set to false

    The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:

    define('WP_CACHE', true);

    ", 'wp-super-cache' ) . "
    "; + echo '
    ' . __( "

    WP_CACHE constant set to false

    The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:

    define('WP_CACHE', true);

    ", 'wp-super-cache' ) . '
    '; } else { - echo '

    ' . __( "Error: WP_CACHE is not enabled in your wp-config.php file and I couldn’t modify it.", 'wp-super-cache' ) . "

    "; - echo "

    " . sprintf( __( "Edit %s and add the following line:
    define('WP_CACHE', true);
    Otherwise, WP-Cache will not be executed by WordPress core. ", 'wp-super-cache' ), $global_config_file ) . "

    "; + echo '

    ' . __( 'Error: WP_CACHE is not enabled in your wp-config.php file and I couldn’t modify it.', 'wp-super-cache' ) . '

    '; + echo '

    ' . sprintf( __( "Edit %s and add the following line:
    define('WP_CACHE', true);
    Otherwise, WP-Cache will not be executed by WordPress core. ", 'wp-super-cache' ), $global_config_file ) . '

    '; } return false; - } else { - echo "
    " . __( '

    WP_CACHE constant added to wp-config.php

    If you continue to see this warning message please see point 5 of the Troubleshooting Guide. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "

    "; + } else { + echo "
    " . __( '

    WP_CACHE constant added to wp-config.php

    If you continue to see this warning message please see point 5 of the Troubleshooting Guide. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . '

    '; } return true; } function wpsc_generate_sizes_array() { - $sizes = array(); + $sizes = array(); $cache_types = apply_filters( 'wpsc_cache_types', array( 'supercache', 'wpcache' ) ); $cache_states = apply_filters( 'wpsc_cache_state', array( 'expired', 'cached' ) ); - foreach( $cache_types as $type ) { + foreach ( $cache_types as $type ) { reset( $cache_states ); - foreach( $cache_states as $state ) { + foreach ( $cache_states as $state ) { $sizes[ $type ][ $state ] = 0; } - $sizes[ $type ][ 'fsize' ] = 0; - $sizes[ $type ][ 'cached_list' ] = array(); - $sizes[ $type ][ 'expired_list' ] = array(); + $sizes[ $type ]['fsize'] = 0; + $sizes[ $type ]['cached_list'] = array(); + $sizes[ $type ]['expired_list'] = array(); } return $sizes; } function wp_cache_format_fsize( $fsize ) { if ( $fsize > 1024 ) { - $fsize = number_format( $fsize / 1024, 2 ) . "MB"; + $fsize = number_format( $fsize / 1024, 2 ) . 'MB'; } elseif ( $fsize != 0 ) { - $fsize = number_format( $fsize, 2 ) . "KB"; + $fsize = number_format( $fsize, 2 ) . 'KB'; } else { - $fsize = "0KB"; + $fsize = '0KB'; } return $fsize; } @@ -2738,12 +2939,13 @@ function wp_cache_format_fsize( $fsize ) { function wp_cache_regenerate_cache_file_stats() { global $cache_compression, $supercachedir, $file_prefix, $wp_cache_preload_on, $cache_max_time; - if ( $supercachedir == '' ) + if ( $supercachedir == '' ) { $supercachedir = get_supercache_dir(); + } $sizes = wpsc_generate_sizes_array(); - $now = time(); - if (is_dir( $supercachedir ) ) { + $now = time(); + if ( is_dir( $supercachedir ) ) { if ( $dh = opendir( $supercachedir ) ) { while ( ( $entry = readdir( $dh ) ) !== false ) { if ( $entry != '.' && $entry != '..' ) { @@ -2753,12 +2955,12 @@ function wp_cache_regenerate_cache_file_stats() { closedir( $dh ); } } - foreach( $sizes as $cache_type => $list ) { - foreach( array( 'cached_list', 'expired_list' ) as $status ) { + foreach ( $sizes as $cache_type => $list ) { + foreach ( array( 'cached_list', 'expired_list' ) as $status ) { $cached_list = array(); - foreach( $list[ $status ] as $dir => $details ) { - if ( $details[ 'files' ] == 2 && !isset( $details[ 'upper_age' ] ) ) { - $details[ 'files' ] = 1; + foreach ( $list[ $status ] as $dir => $details ) { + if ( $details['files'] == 2 && ! isset( $details['upper_age'] ) ) { + $details['files'] = 1; } $cached_list[ $dir ] = $details; } @@ -2766,10 +2968,14 @@ function wp_cache_regenerate_cache_file_stats() { } } if ( $cache_compression ) { - $sizes[ 'supercache' ][ 'cached' ] = intval( $sizes[ 'supercache' ][ 'cached' ] / 2 ); - $sizes[ 'supercache' ][ 'expired' ] = intval( $sizes[ 'supercache' ][ 'expired' ] / 2 ); + $sizes['supercache']['cached'] = intval( $sizes['supercache']['cached'] / 2 ); + $sizes['supercache']['expired'] = intval( $sizes['supercache']['expired'] / 2 ); } - $cache_stats = array( 'generated' => time(), 'supercache' => $sizes[ 'supercache' ], 'wpcache' => $sizes[ 'wpcache' ] ); + $cache_stats = array( + 'generated' => time(), + 'supercache' => $sizes['supercache'], + 'wpcache' => $sizes['wpcache'], + ); update_option( 'supercache_stats', $cache_stats ); return $cache_stats; } @@ -2778,171 +2984,210 @@ function wp_cache_files() { global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $super_cache_enabled, $blog_cache_dir, $cache_compression; global $wp_cache_preload_on; - if ( '/' != substr($cache_path, -1)) { + if ( '/' != substr( $cache_path, -1 ) ) { $cache_path .= '/'; } if ( $valid_nonce ) { - if(isset($_REQUEST['wp_delete_cache'])) { - wp_cache_clean_cache($file_prefix); - $_GET[ 'action' ] = 'regenerate_cache_stats'; + if ( isset( $_REQUEST['wp_delete_cache'] ) ) { + wp_cache_clean_cache( $file_prefix ); + $_GET['action'] = 'regenerate_cache_stats'; } - if ( isset( $_REQUEST[ 'wp_delete_all_cache' ] ) ) { + if ( isset( $_REQUEST['wp_delete_all_cache'] ) ) { wp_cache_clean_cache( $file_prefix, true ); - $_GET[ 'action' ] = 'regenerate_cache_stats'; + $_GET['action'] = 'regenerate_cache_stats'; } - if(isset($_REQUEST['wp_delete_expired'])) { - wp_cache_clean_expired($file_prefix); - $_GET[ 'action' ] = 'regenerate_cache_stats'; + if ( isset( $_REQUEST['wp_delete_expired'] ) ) { + wp_cache_clean_expired( $file_prefix ); + $_GET['action'] = 'regenerate_cache_stats'; } } echo ""; echo '

    ' . __( 'Cache Contents', 'wp-super-cache' ) . '

    '; $cache_stats = get_option( 'supercache_stats' ); - if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) { - $count = 0; - $expired = 0; - $now = time(); - $wp_cache_fsize = 0; - if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { - if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) { - $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) ); - } else { - $deleteuri = ''; - } - - if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) { - $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) ); - $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) ); - if ( wp_cache_confirm_delete( $supercacheuri ) ) { - printf( __( "Deleting supercache file: %s
    ", 'wp-super-cache' ), $supercacheuri ); - wpsc_delete_files( $supercacheuri ); - prune_super_cache( $supercacheuri . 'page', true ); - @rmdir( $supercacheuri ); + if ( ! is_array( $cache_stats ) || ( isset( $_GET['listfiles'] ) ) || ( $valid_nonce && array_key_exists( 'action', $_GET ) && $_GET['action'] == 'regenerate_cache_stats' ) ) { + $count = 0; + $expired = 0; + $now = time(); + $wp_cache_fsize = 0; + if ( ( $handle = @opendir( $blog_cache_dir ) ) ) { + if ( $valid_nonce && isset( $_GET['action'] ) && $_GET['action'] == 'deletewpcache' ) { + $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET['uri'] ) ) ); } else { - wp_die( __( 'Warning! You are not allowed to delete that file', 'wp-super-cache' ) ); + $deleteuri = ''; } - } - while( false !== ( $file = readdir( $handle ) ) ) { - if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) { - if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) { - @unlink( $blog_cache_dir . $file ); - continue; // meta does not exist + + if ( $valid_nonce && isset( $_GET['action'] ) && $_GET['action'] == 'deletesupercache' ) { + $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( '/(\?.*)?$/', '', base64_decode( $_GET['uri'] ) ) ) ); + $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) ); + if ( wp_cache_confirm_delete( $supercacheuri ) ) { + printf( __( 'Deleting supercache file: %s
    ', 'wp-super-cache' ), $supercacheuri ); + wpsc_delete_files( $supercacheuri ); + prune_super_cache( $supercacheuri . 'page', true ); + @rmdir( $supercacheuri ); + } else { + wp_die( __( 'Warning! You are not allowed to delete that file', 'wp-super-cache' ) ); } - $mtime = filemtime( $blog_cache_dir . 'meta/' . $file ); - $fsize = @filesize( $blog_cache_dir . $file ); - if ( $fsize > 0 ) - $fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file - - $age = $now - $mtime; - if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) { - $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true ); - if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) { - printf( __( "Deleting wp-cache file: %s
    ", 'wp-super-cache' ), esc_html( $deleteuri ) ); - @unlink( $blog_cache_dir . 'meta/' . $file ); + } + while ( false !== ( $file = readdir( $handle ) ) ) { + if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) { + if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) { @unlink( $blog_cache_dir . $file ); - continue; + continue; // meta does not exist + } + $mtime = filemtime( $blog_cache_dir . 'meta/' . $file ); + $fsize = @filesize( $blog_cache_dir . $file ); + if ( $fsize > 0 ) { + $fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file } - $meta[ 'age' ] = $age; - foreach( $meta as $key => $val ) - $meta[ $key ] = esc_html( $val ); + + $age = $now - $mtime; + if ( $valid_nonce && isset( $_GET['listfiles'] ) ) { + $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true ); + if ( $deleteuri != '' && $meta['uri'] == $deleteuri ) { + printf( __( 'Deleting wp-cache file: %s
    ', 'wp-super-cache' ), esc_html( $deleteuri ) ); + @unlink( $blog_cache_dir . 'meta/' . $file ); + @unlink( $blog_cache_dir . $file ); + continue; + } + $meta['age'] = $age; + foreach ( $meta as $key => $val ) { + $meta[ $key ] = esc_html( $val ); + } + if ( $cache_max_time > 0 && $age > $cache_max_time ) { + $expired_list[ $age ][] = $meta; + } else { + $cached_list[ $age ][] = $meta; + } + } + if ( $cache_max_time > 0 && $age > $cache_max_time ) { - $expired_list[ $age ][] = $meta; + $expired++; } else { - $cached_list[ $age ][] = $meta; + $count++; } + $wp_cache_fsize += $fsize; } - - if ( $cache_max_time > 0 && $age > $cache_max_time ) { - $expired++; - } else { - $count++; - } - $wp_cache_fsize += $fsize; } + closedir( $handle ); } - closedir($handle); - } - if( $wp_cache_fsize != 0 ) { - $wp_cache_fsize = $wp_cache_fsize/1024; - } else { - $wp_cache_fsize = 0; - } - if( $wp_cache_fsize > 1024 ) { - $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB"; - } elseif( $wp_cache_fsize != 0 ) { - $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB"; - } else { - $wp_cache_fsize = '0KB'; - } - $cache_stats = wp_cache_regenerate_cache_file_stats(); + if ( $wp_cache_fsize != 0 ) { + $wp_cache_fsize = $wp_cache_fsize / 1024; + } else { + $wp_cache_fsize = 0; + } + if ( $wp_cache_fsize > 1024 ) { + $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . 'MB'; + } elseif ( $wp_cache_fsize != 0 ) { + $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . 'KB'; + } else { + $wp_cache_fsize = '0KB'; + } + $cache_stats = wp_cache_regenerate_cache_file_stats(); } else { - echo "

    " . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . "

    "; - echo " 'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . ""; + echo '

    ' . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . '

    '; + echo " 'wpsupercache', + 'tab' => 'contents', + 'action' => 'regenerate_cache_stats', + ) + ), + 'wp-cache' + ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . ''; if ( is_array( $cache_stats ) ) { - echo "

    " . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats[ 'generated' ] ) / 60 ) ) . "

    "; + echo '

    ' . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats['generated'] ) / 60 ) ) . '

    '; } $cache_stats = get_option( 'supercache_stats' ); }// regerate stats cache if ( is_array( $cache_stats ) ) { - $fsize = wp_cache_format_fsize( $cache_stats[ 'wpcache' ][ 'fsize' ] / 1024 ); - echo "

    " . __( 'WP-Cache', 'wp-super-cache' ) . " ({$fsize})

    "; - echo "
    • " . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'cached' ] ) . "
    • "; - echo "
    • " . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'expired' ] ) . "
    "; - if ( array_key_exists('fsize', (array)$cache_stats[ 'supercache' ]) ) - $fsize = $cache_stats[ 'supercache' ][ 'fsize' ] / 1024; - else + $fsize = wp_cache_format_fsize( $cache_stats['wpcache']['fsize'] / 1024 ); + echo '

    ' . __( 'WP-Cache', 'wp-super-cache' ) . " ({$fsize})

    "; + echo '
    • ' . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats['wpcache']['cached'] ) . '
    • '; + echo '
    • ' . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats['wpcache']['expired'] ) . '
    '; + if ( array_key_exists( 'fsize', (array) $cache_stats['supercache'] ) ) { + $fsize = $cache_stats['supercache']['fsize'] / 1024; + } else { $fsize = 0; + } $fsize = wp_cache_format_fsize( $fsize ); - echo "

    " . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})

    "; - echo "
    • " . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'supercache' ][ 'cached' ] ) . "
    • "; - if ( isset( $now ) && isset( $cache_stats ) ) + echo '

      ' . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})

      "; + echo '
      • ' . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats['supercache']['cached'] ) . '
      • '; + if ( isset( $now ) && isset( $cache_stats ) ) { $age = intval( ( $now - $cache_stats['generated'] ) / 60 ); - else + } else { $age = 0; - echo "
      • " . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'supercache' ][ 'expired' ] ) . "
      "; - if ( $valid_nonce && array_key_exists('listfiles', $_GET) && isset( $_GET[ 'listfiles' ] ) ) { + } + echo '
    • ' . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats['supercache']['expired'] ) . '
    '; + if ( $valid_nonce && array_key_exists( 'listfiles', $_GET ) && isset( $_GET['listfiles'] ) ) { echo "
    "; - $cache_description = array( 'supercache' => __( 'WP-Super-Cached', 'wp-super-cache' ), 'wpcache' => __( 'WP-Cached', 'wp-super-cache' ) ); - foreach( $cache_stats as $type => $details ) { - if ( is_array( $details ) == false ) + $cache_description = array( + 'supercache' => __( 'WP-Super-Cached', 'wp-super-cache' ), + 'wpcache' => __( 'WP-Cached', 'wp-super-cache' ), + ); + foreach ( $cache_stats as $type => $details ) { + if ( is_array( $details ) == false ) { continue; - foreach( array( 'cached_list' => 'Fresh', 'expired_list' => 'Stale' ) as $list => $description ) { - if ( is_array( $details[ $list ] ) & !empty( $details[ $list ] ) ) { - echo "
    " . sprintf( __( '%s %s Files', 'wp-super-cache' ), $description, $cache_description[ $type ] ) . "
    "; - echo ""; - $c = 1; + } + foreach ( array( + 'cached_list' => 'Fresh', + 'expired_list' => 'Stale', + ) as $list => $description ) { + if ( is_array( $details[ $list ] ) & ! empty( $details[ $list ] ) ) { + echo '
    ' . sprintf( __( '%1$s %2$s Files', 'wp-super-cache' ), $description, $cache_description[ $type ] ) . '
    '; + echo "
    #" . __( 'URI', 'wp-super-cache' ) . "" . __( 'Files', 'wp-super-cache' ) . "" . __( 'Age', 'wp-super-cache' ) . "" . __( 'Delete', 'wp-super-cache' ) . "
    '; + $c = 1; $flip = 1; ksort( $details[ $list ] ); - foreach( $details[ $list ] as $directory => $d ) { - if ( isset( $d[ 'upper_age' ] ) ) { + foreach ( $details[ $list ] as $directory => $d ) { + if ( isset( $d['upper_age'] ) ) { $age = "{$d[ 'lower_age' ]} - {$d[ 'upper_age' ]}"; } else { - $age = $d[ 'lower_age' ]; + $age = $d['lower_age']; } $bg = $flip ? 'style="background: #EAEAEA;"' : ''; - echo "\n"; - $flip = !$flip; + echo "\n"; + $flip = ! $flip; $c++; } - echo "
    #" . __( 'URI', 'wp-super-cache' ) . '' . __( 'Files', 'wp-super-cache' ) . '' . __( 'Age', 'wp-super-cache' ) . '' . __( 'Delete', 'wp-super-cache' ) . '
    $c {$directory}{$d[ 'files' ]}{$age} 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $directory ) ) ), 'wp-cache' ) . "#listfiles'>X
    $c {$directory}{$d[ 'files' ]}{$age} 'wpsupercache', + 'action' => 'deletesupercache', + 'uri' => base64_encode( $directory ), + ) + ), + 'wp-cache' + ) . "#listfiles'>X
    "; + echo ''; } } } - echo "
    "; - echo "

    " . __( 'Hide file list', 'wp-super-cache' ) . "

    "; - } elseif ( $cache_stats[ 'supercache' ][ 'cached' ] > 500 || $cache_stats[ 'supercache' ][ 'expired' ] > 500 || $cache_stats[ 'wpcache' ][ 'cached' ] > 500 || $cache_stats[ 'wpcache' ][ 'expired' ] > 500 ) { - echo "

    " . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . "

    "; + echo '
    '; + echo "

    " . __( 'Hide file list', 'wp-super-cache' ) . '

    '; + } elseif ( $cache_stats['supercache']['cached'] > 500 || $cache_stats['supercache']['expired'] > 500 || $cache_stats['wpcache']['cached'] > 500 || $cache_stats['wpcache']['expired'] > 500 ) { + echo '

    ' . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . '

    '; } else { - echo "

    'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "

    "; + echo "

    'wpsupercache', + 'listfiles' => '1', + ) + ), + 'wp-cache' + ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . '

    '; + } + if ( $cache_max_time > 0 ) { + echo '

    ' . sprintf( __( 'Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache' ), $cache_max_time ) . '

    '; + } + if ( $wp_cache_preload_on ) { + echo '

    ' . __( 'Preload mode is enabled. Supercache files will never be expired.', 'wp-super-cache' ) . '

    '; } - if ( $cache_max_time > 0 ) - echo "

    " . sprintf( __( 'Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache' ), $cache_max_time ) . "

    "; - if ( $wp_cache_preload_on ) - echo "

    " . __( 'Preload mode is enabled. Supercache files will never be expired.', 'wp-super-cache' ) . "

    "; } // cache_stats wp_cache_delete_buttons(); @@ -2956,19 +3201,19 @@ function wp_cache_delete_buttons() { echo '
    '; echo ''; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; echo '
    '; echo ''; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; if ( is_multisite() && wpsupercache_site_admin() ) { echo '
    '; echo ''; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; } } @@ -2978,28 +3223,30 @@ function delete_cache_dashboard() { _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.4' ); } - if ( false == wpsupercache_site_admin() ) + if ( false == wpsupercache_site_admin() ) { return false; + } - if ( function_exists('current_user_can') && !current_user_can('manage_options') ) + if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) { return false; + } - echo "
  • " . __( 'Delete Cache', 'wp-super-cache' ) . "
  • "; + echo "
  • " . __( 'Delete Cache', 'wp-super-cache' ) . '
  • '; } -//add_action( 'dashmenu', 'delete_cache_dashboard' ); +// add_action( 'dashmenu', 'delete_cache_dashboard' ); -function wpsc_dirsize($directory, $sizes) { +function wpsc_dirsize( $directory, $sizes ) { global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on, $file_prefix; $now = time(); - if (is_dir($directory)) { - if( $dh = opendir( $directory ) ) { - while( ( $entry = readdir( $dh ) ) !== false ) { - if ($entry != '.' && $entry != '..') { + if ( is_dir( $directory ) ) { + if ( $dh = opendir( $directory ) ) { + while ( ( $entry = readdir( $dh ) ) !== false ) { + if ( $entry != '.' && $entry != '..' ) { $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes ); } } - closedir($dh); + closedir( $dh ); } } else { if ( is_file( $directory ) && strpos( $directory, 'meta-' . $file_prefix ) === false ) { @@ -3009,41 +3256,44 @@ function wpsc_dirsize($directory, $sizes) { $cache_type = 'supercache'; } $keep_fresh = false; - if ( $cache_type == 'supercache' && $wp_cache_preload_on ) + if ( $cache_type == 'supercache' && $wp_cache_preload_on ) { $keep_fresh = true; + } $filem = filemtime( $directory ); if ( $keep_fresh == false && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) { $cache_status = 'expired'; } else { $cache_status = 'cached'; } - $sizes[ $cache_type ][ $cache_status ]+=1; - if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) { - $dir = str_replace( $cache_path . 'supercache/' , '', dirname( $directory ) ); + $sizes[ $cache_type ][ $cache_status ] += 1; + if ( $valid_nonce && isset( $_GET['listfiles'] ) ) { + $dir = str_replace( $cache_path . 'supercache/', '', dirname( $directory ) ); $age = $now - $filem; if ( false == isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ] ) ) { - $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'lower_age' ] = $age; - $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'files' ] = 1; + $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] = $age; + $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['files'] = 1; } else { - $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'files' ] += 1; - if ( $age <= $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'lower_age' ] ) { + $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['files'] += 1; + if ( $age <= $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] ) { - if ( $age < $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'lower_age' ] && !isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'upper_age' ] ) ) - $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'upper_age' ] = $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'lower_age' ]; + if ( $age < $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] && ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) ) { + $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] = $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age']; + } - $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'lower_age' ] = $age; + $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] = $age; - } elseif ( !isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'upper_age' ] ) || $age > $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'upper_age' ] ) { + } elseif ( ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) || $age > $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) { - $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ][ 'upper_age' ] = $age; + $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] = $age; } } } - if ( ! isset( $sizes[ 'fsize' ] ) ) - $sizes[ $cache_type ][ 'fsize' ] = @filesize( $directory ); - else - $sizes[ $cache_type ][ 'fsize' ] += @filesize( $directory ); + if ( ! isset( $sizes['fsize'] ) ) { + $sizes[ $cache_type ]['fsize'] = @filesize( $directory ); + } else { + $sizes[ $cache_type ]['fsize'] += @filesize( $directory ); + } } } return $sizes; @@ -3058,16 +3308,17 @@ function wp_cache_clean_cache( $file_prefix, $all = false ) { prune_super_cache( $cache_path, true ); return true; } - if ( $supercachedir == '' ) + if ( $supercachedir == '' ) { $supercachedir = get_supercache_dir(); + } - if (function_exists ('prune_super_cache')) { - if( is_dir( $supercachedir ) ) { + if ( function_exists( 'prune_super_cache' ) ) { + if ( is_dir( $supercachedir ) ) { prune_super_cache( $supercachedir, true ); - } elseif( is_dir( $supercachedir . '.disabled' ) ) { + } elseif ( is_dir( $supercachedir . '.disabled' ) ) { prune_super_cache( $supercachedir . '.disabled', true ); } - $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats; + $_POST['super_cache_stats'] = 1; // regenerate super cache stats; } else { wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 ); } @@ -3093,8 +3344,9 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { global $wpdb; $dir = trailingslashit( $dir ); - if ( @is_dir( $dir . 'meta' ) == false ) + if ( @is_dir( $dir . 'meta' ) == false ) { return false; + } if ( $handle = @opendir( $dir ) ) { $curr_blog_id = is_multisite() ? get_current_blog_id() : false; @@ -3107,23 +3359,23 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { if ( strpos( $file, $file_prefix ) !== false ) { if ( strpos( $file, '.html' ) ) { // delete old WPCache files immediately - @unlink( $dir . $file); + @unlink( $dir . $file ); @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); } else { $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true ); - if ( $curr_blog_id && $curr_blog_id !== (int)$meta['blog_id'] ) { + if ( $curr_blog_id && $curr_blog_id !== (int) $meta['blog_id'] ) { continue; } - @unlink( $dir . $file); - @unlink( $dir . 'meta/' . $file); + @unlink( $dir . $file ); + @unlink( $dir . 'meta/' . $file ); } } } - closedir($handle); + closedir( $handle ); } } -function wp_cache_clean_expired($file_prefix) { +function wp_cache_clean_expired( $file_prefix ) { global $cache_max_time, $blog_cache_dir, $wp_cache_preload_on; if ( $cache_max_time == 0 ) { @@ -3131,17 +3383,17 @@ function wp_cache_clean_expired($file_prefix) { } // If phase2 was compiled, use its function to avoid race-conditions - if(function_exists('wp_cache_phase2_clean_expired')) { - if ( $wp_cache_preload_on != 1 && function_exists ('prune_super_cache')) { + if ( function_exists( 'wp_cache_phase2_clean_expired' ) ) { + if ( $wp_cache_preload_on != 1 && function_exists( 'prune_super_cache' ) ) { $dir = get_supercache_dir(); - if( is_dir( $dir ) ) { + if ( is_dir( $dir ) ) { prune_super_cache( $dir ); - } elseif( is_dir( $dir . '.disabled' ) ) { + } elseif ( is_dir( $dir . '.disabled' ) ) { prune_super_cache( $dir . '.disabled' ); } - $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats; + $_POST['super_cache_stats'] = 1; // regenerate super cache stats; } - return wp_cache_phase2_clean_expired($file_prefix); + return wp_cache_phase2_clean_expired( $file_prefix ); } $now = time(); @@ -3149,7 +3401,7 @@ function wp_cache_clean_expired($file_prefix) { while ( false !== ( $file = readdir( $handle ) ) ) { if ( strpos( $file, $file_prefix ) !== false ) { if ( strpos( $file, '.html' ) ) { - @unlink( $blog_cache_dir . $file); + @unlink( $blog_cache_dir . $file ); @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); } elseif ( ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) { @unlink( $blog_cache_dir . $file ); @@ -3157,13 +3409,13 @@ function wp_cache_clean_expired($file_prefix) { } } } - closedir($handle); + closedir( $handle ); } } function wpsc_remove_marker( $filename, $marker ) { - if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) { - if (!file_exists( $filename ) ) { + if ( ! file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) { + if ( ! file_exists( $filename ) ) { return ''; } else { $markerdata = explode( "\n", implode( '', file( $filename ) ) ); @@ -3173,15 +3425,17 @@ function wpsc_remove_marker( $filename, $marker ) { if ( $markerdata ) { $state = true; foreach ( $markerdata as $n => $markerline ) { - if (strpos($markerline, '# BEGIN ' . $marker) !== false) + if ( strpos( $markerline, '# BEGIN ' . $marker ) !== false ) { $state = false; + } if ( $state ) { - if ( $n + 1 < count( $markerdata ) ) + if ( $n + 1 < count( $markerdata ) ) { fwrite( $f, "{$markerline}\n" ); - else + } else { fwrite( $f, "{$markerline}" ); + } } - if (strpos($markerline, '# END ' . $marker) !== false) { + if ( strpos( $markerline, '# END ' . $marker ) !== false ) { $state = true; } } @@ -3192,47 +3446,53 @@ function wpsc_remove_marker( $filename, $marker ) { } } -if( get_option( 'gzipcompression' ) ) +if ( get_option( 'gzipcompression' ) ) { update_option( 'gzipcompression', 0 ); +} // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404 function wp_cache_catch_404() { global $wp_cache_404; - if ( function_exists( '_deprecated_function' ) ) + if ( function_exists( '_deprecated_function' ) ) { _deprecated_function( __FUNCTION__, 'WP Super Cache 1.5.6' ); + } $wp_cache_404 = false; - if( is_404() ) + if ( is_404() ) { $wp_cache_404 = true; + } } -//More info - https://github.com/Automattic/wp-super-cache/pull/373 -//add_action( 'template_redirect', 'wp_cache_catch_404' ); +// More info - https://github.com/Automattic/wp-super-cache/pull/373 +// add_action( 'template_redirect', 'wp_cache_catch_404' ); function wp_cache_favorite_action( $actions ) { if ( function_exists( '_deprecated_function' ) ) { _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.4' ); } - if ( false == wpsupercache_site_admin() ) + if ( false == wpsupercache_site_admin() ) { return $actions; + } - if ( function_exists('current_user_can') && !current_user_can('manage_options') ) + if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) { return $actions; + } $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1&tab=contents', 'wp-cache' ) ] = array( __( 'Delete Cache', 'wp-super-cache' ), 'manage_options' ); return $actions; } -//add_filter( 'favorite_actions', 'wp_cache_favorite_action' ); +// add_filter( 'favorite_actions', 'wp_cache_favorite_action' ); function wp_cache_plugin_notice( $plugin ) { global $cache_enabled; - if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( 'admin_url' ) ) + if ( $plugin == 'wp-super-cache/wp-cache.php' && ! $cache_enabled && function_exists( 'admin_url' ) ) { echo '' . sprintf( __( 'WP Super Cache must be configured. Go to the admin page to enable and configure the plugin.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . ''; + } } add_action( 'after_plugin_row', 'wp_cache_plugin_notice' ); function wp_cache_plugin_actions( $links, $file ) { - if( $file == 'wp-super-cache/wp-cache.php' && function_exists( 'admin_url' ) ) { + if ( $file == 'wp-super-cache/wp-cache.php' && function_exists( 'admin_url' ) ) { $settings_link = '' . __( 'Settings', 'wp-super-cache' ) . ''; array_unshift( $links, $settings_link ); // before other links } @@ -3242,8 +3502,9 @@ function wp_cache_plugin_actions( $links, $file ) { function wp_cache_admin_notice() { global $cache_enabled, $wp_cache_phase1_loaded; - if( substr( $_SERVER['PHP_SELF'], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( 'admin_url' ) ) - echo '

    ' . sprintf( __('WP Super Cache is disabled. Please go to the plugin admin page to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '

    '; + if ( substr( $_SERVER['PHP_SELF'], -11 ) == 'plugins.php' && ! $cache_enabled && function_exists( 'admin_url' ) ) { + echo '

    ' . sprintf( __( 'WP Super Cache is disabled. Please go to the plugin admin page to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '

    '; + } if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) { if ( wp_cache_create_advanced_cache() ) { @@ -3256,28 +3517,34 @@ function wp_cache_admin_notice() { function wp_cache_check_site() { global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wpdb; - if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) { + if ( ! isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) { return false; } - if ( function_exists( "wp_remote_get" ) == false ) { + if ( function_exists( 'wp_remote_get' ) == false ) { return false; } - $front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) ); - if( is_array( $front_page ) ) { + $front_page = wp_remote_get( + site_url(), + array( + 'timeout' => 60, + 'blocking' => true, + ) + ); + if ( is_array( $front_page ) ) { // Check for gzipped front page - if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) { - if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); + if ( $front_page['headers']['content-type'] == 'application/x-gzip' ) { + if ( ! isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %s to clear the cache as the front page of your site is now downloading!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); } else { wp_cache_clear_cache( $wpdb->blogid ); - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); } } // Check for broken front page - if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) { - if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { + if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page['body'], $wp_super_cache_front_page_text ) ) { + if ( ! isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) { wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) ); } else { wp_cache_clear_cache( $wpdb->blogid ); @@ -3286,11 +3553,11 @@ function wp_cache_check_site() { } } if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) { - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), home_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", admin_url( 'options-general.php?page=wpsupercache' ) ) ); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), home_url() ), sprintf( __( 'WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.', 'wp-super-cache' ) . "\n\n", admin_url( 'options-general.php?page=wpsupercache' ) ) ); } - if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { - wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' ); + if ( ! wp_next_scheduled( 'wp_cache_check_site_hook' ) ) { + wp_schedule_single_event( time() + 360, 'wp_cache_check_site_hook' ); wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 ); } } @@ -3302,7 +3569,7 @@ function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $ wp_cache_setting( 'wp_cache_mobile_prefixes', $mobile_prefixes ); if ( is_array( $mobile_groups ) ) { $wp_cache_mobile_groups = $mobile_groups; - wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file); + wp_cache_replace_line( '^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file ); } return true; @@ -3310,8 +3577,8 @@ function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $ function wpsc_update_htaccess() { extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules - wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top - if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) { + wpsc_remove_marker( $home_path . '.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top + if ( insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path . '.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) { return true; } else { return false; @@ -3323,27 +3590,27 @@ function wpsc_update_htaccess_form( $short_form = true ) { $admin_url = admin_url( 'options-general.php?page=wpsupercache' ); extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules - if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) { - echo "
    " . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "

    " . sprintf( __( 'The file %s.htaccess cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "

    " . __( 'Refresh this page when the file permissions have been modified.' ) . "

    " . sprintf( __( 'Alternatively, you can edit your %s.htaccess file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "

    "; - echo "

    # BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache

    "; + if ( ! is_writeable_ACLSafe( $home_path . '.htaccess' ) ) { + echo "
    " . __( 'Cannot update .htaccess', 'wp-super-cache' ) . '

    ' . sprintf( __( 'The file %s.htaccess cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . '

    ' . __( 'Refresh this page when the file permissions have been modified.', 'wp-super-cache' ) . '

    ' . sprintf( __( 'Alternatively, you can edit your %s.htaccess file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . '

    '; + echo "

    # BEGIN WPSuperCache\n" . esc_html( $rules ) . '# END WPSuperCache

    '; } else { if ( $short_form == false ) { - echo "

    " . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called %s.htaccess', 'wp-super-cache' ), $home_path ) . " "; - _e( "You can edit the file yourself. Add the following rules.", 'wp-super-cache' ); - echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "

    "; + echo '

    ' . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called %s.htaccess', 'wp-super-cache' ), $home_path ) . ' '; + _e( 'You can edit the file yourself. Add the following rules.', 'wp-super-cache' ); + echo __( ' Make sure they appear before any existing WordPress rules. ', 'wp-super-cache' ) . '

    '; echo "
    "; - echo "
    # BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache

    "; - echo "
    "; - echo "
    " . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "
    "; + echo "
    # BEGIN WPSuperCache\n" . esc_html( $rules ) . '# END WPSuperCache

    '; + echo '
    '; + echo '
    ' . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . '/cache/.htaccess' ) . '
    '; echo "
    "; - echo "
    # BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache

    "; - echo "
    "; + echo "
    # BEGIN supercache\n" . esc_html( $gziprules ) . '# END supercache

    '; + echo ''; } - if ( !isset( $wpmu_version ) || $wpmu_version == '' ) { + if ( ! isset( $wpmu_version ) || $wpmu_version == '' ) { echo '
    '; echo ''; echo '
    '; - wp_nonce_field('wp-cache'); + wp_nonce_field( 'wp-cache' ); echo "
    \n"; } } @@ -3355,8 +3622,9 @@ function wpsc_update_htaccess_form( $short_form = true ) { */ function wpsc_get_logged_in_cookie() { $logged_in_cookie = 'wordpress_logged_in'; - if ( defined( 'LOGGED_IN_COOKIE' ) && substr( constant( 'LOGGED_IN_COOKIE' ), 0, 19 ) != 'wordpress_logged_in' ) + if ( defined( 'LOGGED_IN_COOKIE' ) && substr( constant( 'LOGGED_IN_COOKIE' ), 0, 19 ) != 'wordpress_logged_in' ) { $logged_in_cookie = constant( 'LOGGED_IN_COOKIE' ); + } return $logged_in_cookie; } @@ -3364,12 +3632,12 @@ function wpsc_get_htaccess_info() { global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8; global $htaccess_path; - if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) { - $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ]; - $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ]; + if ( isset( $_SERVER['PHP_DOCUMENT_ROOT'] ) ) { + $document_root = $_SERVER['PHP_DOCUMENT_ROOT']; + $apache_root = $_SERVER['PHP_DOCUMENT_ROOT']; } else { - $document_root = $_SERVER[ "DOCUMENT_ROOT" ]; - $apache_root = '%{DOCUMENT_ROOT}'; + $document_root = $_SERVER['DOCUMENT_ROOT']; + $apache_root = '%{DOCUMENT_ROOT}'; } $content_dir_root = $document_root; if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) { @@ -3387,87 +3655,89 @@ function wpsc_get_htaccess_info() { // PHP: /homepages/xx/dxxxxxxxx/htdocs/site1/index.html // Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting. $content_dir_root = substr( $content_dir_root, 7 ); - $apache_root = $document_root; + $apache_root = $document_root; } $home_path = get_home_path(); - $home_root = parse_url(get_bloginfo('url')); - $home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/'; + $home_root = parse_url( get_bloginfo( 'url' ) ); + $home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/'; if ( isset( $htaccess_path ) ) { $home_path = $htaccess_path; } elseif ( $home_root == '/' && - $home_path != $_SERVER[ 'DOCUMENT_ROOT' ] + $home_path != $_SERVER['DOCUMENT_ROOT'] ) { - $home_path = $_SERVER[ 'DOCUMENT_ROOT' ]; + $home_path = $_SERVER['DOCUMENT_ROOT']; } elseif ( $home_root != '/' && - $home_path != str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) && - is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) + $home_path != str_replace( '//', '/', $_SERVER['DOCUMENT_ROOT'] . $home_root ) && + is_dir( $_SERVER['DOCUMENT_ROOT'] . $home_root ) ) { - $home_path = str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ); + $home_path = str_replace( '//', '/', $_SERVER['DOCUMENT_ROOT'] . $home_root ); } - $home_path = trailingslashit( $home_path ); + $home_path = trailingslashit( $home_path ); $home_root_lc = str_replace( '//', '/', strtolower( $home_root ) ); - $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) ); - $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) ); - $wprules = str_replace( "RewriteEngine On\n", '', $wprules ); - $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules ); - $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) ); - - if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { - $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$"; - $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$"; - } - $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST"; - $condition_rules[] = "RewriteCond %{QUERY_STRING} ^$"; - $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|" . wpsc_get_logged_in_cookie() . wpsc_get_extra_cookies() . "|wp-postpass_).*$"; - $condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]"; - $condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]"; + $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) ); + $wprules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WordPress' ) ); + $wprules = str_replace( "RewriteEngine On\n", '', $wprules ); + $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules ); + $scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) ); + + if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) { + $condition_rules[] = 'RewriteCond %{REQUEST_URI} !^.*[^/]$'; + $condition_rules[] = 'RewriteCond %{REQUEST_URI} !^.*//.*$'; + } + $condition_rules[] = 'RewriteCond %{REQUEST_METHOD} !POST'; + $condition_rules[] = 'RewriteCond %{QUERY_STRING} ^$'; + $condition_rules[] = 'RewriteCond %{HTTP:Cookie} !^.*(comment_author_|' . wpsc_get_logged_in_cookie() . wpsc_get_extra_cookies() . '|wp-postpass_).*$'; + $condition_rules[] = 'RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\"]+ [NC]'; + $condition_rules[] = 'RewriteCond %{HTTP:Profile} !^[a-z0-9\\"]+ [NC]'; if ( $wp_cache_mobile_enabled ) { - if ( isset( $wp_cache_mobile_browsers ) && "" != $wp_cache_mobile_browsers ) - $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]"; - if ( isset( $wp_cache_mobile_prefixes ) && "" != $wp_cache_mobile_prefixes ) - $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]"; + if ( isset( $wp_cache_mobile_browsers ) && '' != $wp_cache_mobile_browsers ) { + $condition_rules[] = 'RewriteCond %{HTTP_USER_AGENT} !^.*(' . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) . ').* [NC]'; + } + if ( isset( $wp_cache_mobile_prefixes ) && '' != $wp_cache_mobile_prefixes ) { + $condition_rules[] = 'RewriteCond %{HTTP_USER_AGENT} !^(' . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) . ').* [NC]'; + } } $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules ); - $rules = "\n"; + $rules = "\n"; $rules .= "RewriteEngine On\n"; $rules .= "RewriteBase $home_root\n"; // props Chris Messina $rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n"; if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) { - $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset'); - $rules .= "AddDefaultCharset {$charset}\n"; + $charset = get_option( 'blog_charset' ) == '' ? 'UTF-8' : get_option( 'blog_charset' ); + $rules .= "AddDefaultCharset {$charset}\n"; } - $rules .= "CONDITION_RULES"; + $rules .= 'CONDITION_RULES'; $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n"; $rules .= "RewriteCond %{HTTPS} on\n"; $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz -f\n"; $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz\" [L]\n\n"; - $rules .= "CONDITION_RULES"; + $rules .= 'CONDITION_RULES'; $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n"; $rules .= "RewriteCond %{HTTPS} !on\n"; $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz -f\n"; $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz\" [L]\n\n"; - $rules .= "CONDITION_RULES"; + $rules .= 'CONDITION_RULES'; $rules .= "RewriteCond %{HTTPS} on\n"; $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html -f\n"; $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html\" [L]\n\n"; - $rules .= "CONDITION_RULES"; + $rules .= 'CONDITION_RULES'; $rules .= "RewriteCond %{HTTPS} !on\n"; $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html -f\n"; $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html\" [L]\n"; $rules .= "\n"; - $rules = apply_filters( 'supercacherewriterules', $rules ); + $rules = apply_filters( 'supercacherewriterules', $rules ); - $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules ); + $rules = str_replace( 'CONDITION_RULES', implode( "\n", $condition_rules ) . "\n", $rules ); - $gziprules = "\n \n ForceType text/html\n FileETag None\n \n AddEncoding gzip .gz\n AddType text/html .gz\n\n"; + $gziprules = "\n \n ForceType text/html\n FileETag None\n \n AddEncoding gzip .gz\n AddType text/html .gz\n\n"; $gziprules .= "\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n\n"; $vary_header = $cache_control_header = ''; @@ -3486,7 +3756,7 @@ function wpsc_get_htaccess_info() { } else { $cache_control_header = 'max-age=3, must-revalidate'; } - $headers_text = ""; + $headers_text = ''; if ( $vary_header != '' ) { $headers_text .= " Header set Vary '$vary_header'\n"; } @@ -3498,13 +3768,26 @@ function wpsc_get_htaccess_info() { } $gziprules .= "\n ExpiresActive On\n ExpiresByType text/html A3\n\n"; $gziprules .= "Options -Indexes\n"; - return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules ); + return array( + 'document_root' => $document_root, + 'apache_root' => $apache_root, + 'home_path' => $home_path, + 'home_root' => $home_root, + 'home_root_lc' => $home_root_lc, + 'inst_root' => $inst_root, + 'wprules' => $wprules, + 'scrules' => $scrules, + 'condition_rules' => $condition_rules, + 'rules' => $rules, + 'gziprules' => $gziprules, + ); } function clear_post_supercache( $post_id ) { $dir = get_current_url_supercache_dir( $post_id ); - if ( false == @is_dir( $dir ) ) + if ( false == @is_dir( $dir ) ) { return false; + } if ( get_supercache_dir() == $dir ) { wp_cache_debug( "clear_post_supercache: not deleting post_id $post_id as it points at homepage: $dir" ); @@ -3512,7 +3795,7 @@ function clear_post_supercache( $post_id ) { } wp_cache_debug( "clear_post_supercache: post_id: $post_id. deleting files in $dir" ); - if ( get_post_type( $post_id ) != 'page') { // don't delete child pages if they exist + if ( get_post_type( $post_id ) != 'page' ) { // don't delete child pages if they exist prune_super_cache( $dir, true ); } else { wpsc_delete_files( $dir ); @@ -3528,7 +3811,7 @@ function wp_cron_preload_cache() { return true; } - $mutex = $cache_path . "preload_mutex.tmp"; + $mutex = $cache_path . 'preload_mutex.tmp'; sleep( 3 + mt_rand( 1, 5 ) ); if ( @file_exists( $mutex ) ) { if ( @filemtime( $mutex ) > ( time() - 600 ) ) { @@ -3545,35 +3828,52 @@ function wp_cron_preload_cache() { $counter = get_option( 'preload_cache_counter' ); if ( is_array( $counter ) == false ) { wp_cache_debug( 'wp_cron_preload_cache: setting up preload for the first time!', 5 ); - $counter = array( 'c' => 0, 't' => time() ); + $counter = array( + 'c' => 0, + 't' => time(), + ); update_option( 'preload_cache_counter', $counter ); } - $c = $counter[ 'c' ]; + $c = $counter['c']; - update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) ); + update_option( + 'preload_cache_counter', + array( + 'c' => ( $c + 100 ), + 't' => time(), + ) + ); if ( $wp_cache_preload_email_volume == 'none' && $wp_cache_preload_email_me == 1 ) { $wp_cache_preload_email_me = 0; wp_cache_setting( 'wp_cache_preload_email_me', 0 ); } - if ( $wp_cache_preload_email_me && $c == 0 ) + if ( $wp_cache_preload_email_me && $c == 0 ) { wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' ); + } if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) { wp_cache_debug( 'wp_cron_preload_cache: doing taxonomy preload.', 5 ); - $permalink_counter_msg = $cache_path . "preload_permalink.txt"; + $permalink_counter_msg = $cache_path . 'preload_permalink.txt'; if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) { - $taxonomies = apply_filters( 'wp_cache_preload_taxonomies', array( 'post_tag' => 'tag', 'category' => 'category' ) ); - foreach( $taxonomies as $taxonomy => $path ) { - $taxonomy_filename = $cache_path . "taxonomy_" . $taxonomy . ".txt"; - if ( $c == 0 ) + $taxonomies = apply_filters( + 'wp_cache_preload_taxonomies', + array( + 'post_tag' => 'tag', + 'category' => 'category', + ) + ); + foreach ( $taxonomies as $taxonomy => $path ) { + $taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt'; + if ( $c == 0 ) { @unlink( $taxonomy_filename ); + } if ( false == @file_exists( $taxonomy_filename ) ) { - $out = ''; + $out = ''; $records = get_terms( $taxonomy ); - foreach( $records as $term ) { - $out .= get_term_link( $term ). "\n"; + foreach ( $records as $term ) { + $out .= get_term_link( $term ) . "\n"; } $fp = fopen( $taxonomy_filename, 'w' ); if ( $fp ) { @@ -3584,16 +3884,18 @@ function wp_cron_preload_cache() { } else { $details = explode( "\n", file_get_contents( $taxonomy_filename ) ); } - if ( count( $details ) != 1 && $details[ 0 ] != '' ) { + if ( count( $details ) != 1 && $details[0] != '' ) { $rows = array_splice( $details, 0, 50 ); - if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' ) - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), home_url(), $taxonomy, $c, ($c+100) ), 'Refreshing: ' . print_r( $rows, 1 ) ); - foreach( (array)$rows as $url ) { + if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), home_url(), $taxonomy, $c, ( $c + 100 ) ), 'Refreshing: ' . print_r( $rows, 1 ) ); + } + foreach ( (array) $rows as $url ) { set_time_limit( 60 ); - if ( $url == '' ) + if ( $url == '' ) { continue; + } $url_info = parse_url( $url ); - $dir = get_supercache_dir() . $url_info[ 'path' ]; + $dir = get_supercache_dir() . $url_info['path']; wp_cache_debug( "wp_cron_preload_cache: delete $dir", 5 ); prune_super_cache( $dir ); $fp = @fopen( $permalink_counter_msg, 'w' ); @@ -3601,17 +3903,30 @@ function wp_cron_preload_cache() { @fwrite( $fp, "$taxonomy: $url" ); @fclose( $fp ); } - wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) ); + wp_remote_get( + $url, + array( + 'timeout' => 60, + 'blocking' => true, + ) + ); wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 ); sleep( 1 ); - if ( @file_exists( $cache_path . "stop_preload.txt" ) ) { + if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) { wp_cache_debug( 'wp_cron_preload_cache: cancelling preload. stop_preload.txt found.', 5 ); @unlink( $mutex ); - @unlink( $cache_path . "stop_preload.txt" ); + @unlink( $cache_path . 'stop_preload.txt' ); @unlink( $taxonomy_filename ); - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); - if ( $wp_cache_preload_email_me ) + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); + if ( $wp_cache_preload_email_me ) { wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' ); + } return true; } } @@ -3633,25 +3948,28 @@ function wp_cron_preload_cache() { wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 ); $posts = false; } - if ( !isset( $wp_cache_preload_email_volume ) ) + if ( ! isset( $wp_cache_preload_email_volume ) ) { $wp_cache_preload_email_volume = 'medium'; + } if ( $posts ) { if ( get_option( 'show_on_front' ) == 'page' ) { - $page_on_front = get_option( 'page_on_front' ); + $page_on_front = get_option( 'page_on_front' ); $page_for_posts = get_option( 'page_for_posts' ); } else { $page_on_front = $page_for_posts = 0; } - if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' ) - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ($c+100) ), ' ' ); - $msg = ''; - $count = $c + 1; - $permalink_counter_msg = $cache_path . "preload_permalink.txt"; - foreach( $posts as $post_id ) { + if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ( $c + 100 ) ), ' ' ); + } + $msg = ''; + $count = $c + 1; + $permalink_counter_msg = $cache_path . 'preload_permalink.txt'; + foreach ( $posts as $post_id ) { set_time_limit( 60 ); - if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) ) + if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) ) { continue; + } $url = get_permalink( $post_id ); if ( wp_cache_is_rejected( $url ) ) { @@ -3661,26 +3979,40 @@ function wp_cron_preload_cache() { clear_post_supercache( $post_id ); $fp = @fopen( $permalink_counter_msg, 'w' ); if ( $fp ) { - @fwrite( $fp, $count . " " . $url ); + @fwrite( $fp, $count . ' ' . $url ); @fclose( $fp ); } - if ( @file_exists( $cache_path . "stop_preload.txt" ) ) { + if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) { wp_cache_debug( 'wp_cron_preload_cache: cancelling preload. stop_preload.txt found.', 5 ); @unlink( $mutex ); - @unlink( $cache_path . "stop_preload.txt" ); - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); - if ( $wp_cache_preload_email_me ) + @unlink( $cache_path . 'stop_preload.txt' ); + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); + if ( $wp_cache_preload_email_me ) { wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' ); + } return true; } $msg .= "$url\n"; - wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) ); + wp_remote_get( + $url, + array( + 'timeout' => 60, + 'blocking' => true, + ) + ); wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 ); sleep( 1 ); $count++; } - if ( $wp_cache_preload_email_me && ( $wp_cache_preload_email_volume == 'medium' || $wp_cache_preload_email_volume == 'many' ) ) - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" ); + if ( $wp_cache_preload_email_me && ( $wp_cache_preload_email_volume == 'medium' || $wp_cache_preload_email_volume == 'many' ) ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ( $c + 100 ) ), __( 'Refreshed the following posts:', 'wp-super-cache' ) . "\n$msg" ); + } if ( defined( 'DOING_CRON' ) ) { wp_cache_debug( 'wp_cron_preload_cache: scheduling the next preload in 30 seconds.', 5 ); wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' ); @@ -3688,21 +4020,29 @@ function wp_cron_preload_cache() { wpsc_delete_files( get_supercache_dir() ); } else { $msg = ''; - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); - if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) { - if ( $wp_cache_preload_email_me ) - $msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval ); + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); + if ( (int) $wp_cache_preload_interval && defined( 'DOING_CRON' ) ) { + if ( $wp_cache_preload_email_me ) { + $msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int) $wp_cache_preload_interval ); + } wp_cache_debug( "wp_cron_preload_cache: no more posts. scheduling next preload in $wp_cache_preload_interval minutes.", 5 ); - wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' ); + wp_schedule_single_event( time() + ( (int) $wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' ); } global $file_prefix, $cache_max_time; if ( $wp_cache_preload_interval > 0 ) { - $cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files + $cache_max_time = (int) $wp_cache_preload_interval * 60; // fool the GC into expiring really old files } else { $cache_max_time = 86400; // fool the GC into expiring really old files } - if ( $wp_cache_preload_email_me ) - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), home_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg ); + if ( $wp_cache_preload_email_me ) { + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), home_url() ), __( 'Cleaning up old supercache files.', 'wp-super-cache' ) . "\n" . $msg ); + } if ( $cache_max_time > 0 ) { // GC is NOT disabled wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 ); wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files. @@ -3717,24 +4057,32 @@ function next_preload_message( $hook, $text, $limit = 0 ) { global $currently_preloading, $wp_cache_preload_interval; if ( $next_preload = wp_next_scheduled( $hook ) ) { $next_time = $next_preload - time(); - if ( $limit != 0 && $next_time > $limit ) + if ( $limit != 0 && $next_time > $limit ) { return false; + } $h = $m = $s = 0; if ( $next_time > 0 ) { - $m = (int)($next_time / 60); + $m = (int) ( $next_time / 60 ); $s = $next_time % 60; - $h = (int)($m / 60); $m = $m % 60; + $h = (int) ( $m / 60 ); + $m = $m % 60; } - if ( $next_time > 0 && $next_time < ( 60 * $wp_cache_preload_interval ) ) + if ( $next_time > 0 && $next_time < ( 60 * $wp_cache_preload_interval ) ) { echo '

    ' . sprintf( $text, $h, $m, $s ) . '

    '; - if ( ( $next_preload - time() ) <= 60 ) + } + if ( ( $next_preload - time() ) <= 60 ) { $currently_preloading = true; + } } } function option_preload_cache_counter( $value ) { if ( false == is_array( $value ) ) { - $ret = array( 'c' => $value, 't' => time(), 'first' => 1 ); + $ret = array( + 'c' => $value, + 't' => time(), + 'first' => 1, + ); return $ret; } @@ -3744,10 +4092,10 @@ function option_preload_cache_counter( $value ) { function check_up_on_preloading() { $value = get_option( 'preload_cache_counter' ); - if ( is_array( $value ) && $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) { + if ( is_array( $value ) && $value['c'] > 0 && ( time() - $value['t'] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) { if ( is_admin() ) { if ( get_option( 'wpsc_preload_restart_email' ) < ( time() - 86400 ) ) { - wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Preload may have stalled.', 'wp-super-cache' ), get_bloginfo( 'url' ) ), sprintf( __( "Preload has been restarted.\n%s", 'wp-super-cache' ), admin_url( "options-general.php?page=wpsupercache" ) ) ); + wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Preload may have stalled.', 'wp-super-cache' ), get_bloginfo( 'url' ) ), sprintf( __( "Preload has been restarted.\n%s", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) ); update_option( 'wpsc_preload_restart_email', time() ); } add_action( 'admin_notices', 'wpsc_preload_restart_notice' ); @@ -3759,19 +4107,21 @@ function check_up_on_preloading() { function wpsc_preload_restart_notice() { - if ( false == wpsupercache_site_admin() ) + if ( false == wpsupercache_site_admin() ) { return false; - if ( ! isset( $_GET[ 'page' ] ) || $_GET[ 'page' ] != 'wpsupercache' ) + } + if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'wpsupercache' ) { return false; + } echo '

    ' . __( 'Warning! WP Super Cache preload was interrupted but has been restarted.', 'wp-super-cache' ) . '

    '; } function wp_cache_disable_plugin( $delete_config_file = true ) { global $wp_rewrite; - if ( file_exists( ABSPATH . 'wp-config.php') ) { + if ( file_exists( ABSPATH . 'wp-config.php' ) ) { $global_config_file = ABSPATH . 'wp-config.php'; } else { - $global_config_file = dirname(ABSPATH) . '/wp-config.php'; + $global_config_file = dirname( ABSPATH ) . '/wp-config.php'; } if ( apply_filters( 'wpsc_enable_wp_config_edit', true ) ) { @@ -3802,17 +4152,18 @@ function wp_cache_disable_plugin( $delete_config_file = true ) { uninstall_supercache( WP_CONTENT_DIR . '/cache' ); $file_not_deleted = false; wpsc_remove_advanced_cache(); - if ( @file_exists( WP_CONTENT_DIR . "/advanced-cache.php" ) ) { + if ( @file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) { $file_not_deleted[] = 'advanced-cache.php'; } - if ( $delete_config_file && @file_exists( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) { - if ( false == unlink( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) + if ( $delete_config_file && @file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) ) { + if ( false == unlink( WP_CONTENT_DIR . '/wp-cache-config.php' ) ) { $file_not_deleted[] = 'wp-cache-config.php'; + } } if ( $file_not_deleted ) { $msg = __( "Dear User,\n\nWP Super Cache was removed from your blog or deactivated but some files could\nnot be deleted.\n\n", 'wp-super-cache' ); - foreach( (array)$file_not_deleted as $filename ) { - $msg .= WP_CONTENT_DIR . "/{$filename}\n"; + foreach ( (array) $file_not_deleted as $filename ) { + $msg .= WP_CONTENT_DIR . "/{$filename}\n"; } $msg .= "\n"; $msg .= sprintf( __( "You should delete these files manually.\nYou may need to change the permissions of the files or parent directory.\nYou can read more about this in the Codex at\n%s\n\nThank you.", 'wp-super-cache' ), 'https://codex.wordpress.org/Changing_File_Permissions#About_Chmod' ); @@ -3822,22 +4173,24 @@ function wp_cache_disable_plugin( $delete_config_file = true ) { } } extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules - if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) { + if ( $scrules != '' && insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', array() ) ) { $wp_rewrite->flush_rules(); - } elseif( $scrules != '' ) { + } elseif ( $scrules != '' ) { wp_mail( get_option( 'admin_email' ), __( 'Supercache Uninstall Problems', 'wp-super-cache' ), sprintf( __( "Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttps://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) ); } } -function uninstall_supercache( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php - if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) ) +function uninstall_supercache( $folderPath ) { + // from http://www.php.net/manual/en/function.rmdir.php + if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) ) { return false; - if ( @is_dir ( $folderPath ) ) { - $dh = @opendir($folderPath); - while( false !== ( $value = @readdir( $dh ) ) ) { - if ( $value != "." && $value != ".." ) { - $value = $folderPath . "/" . $value; - if ( @is_dir ( $value ) ) { + } + if ( @is_dir( $folderPath ) ) { + $dh = @opendir( $folderPath ); + while ( false !== ( $value = @readdir( $dh ) ) ) { + if ( $value != '.' && $value != '..' ) { + $value = $folderPath . '/' . $value; + if ( @is_dir( $value ) ) { uninstall_supercache( $value ); } else { @unlink( $value ); @@ -3869,28 +4222,32 @@ function wpsc_admin_bar_render( $wp_admin_bar ) { return false; } - if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) { + if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) { $site_regex = preg_quote( rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' ), '`' ); - $req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ); + $req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER['REQUEST_URI'] ); $path = preg_replace( '`^' . $site_regex . '`', '', $req_uri ); - $wp_admin_bar->add_menu( array( - 'parent' => '', - 'id' => 'delete-cache', - 'title' => __( 'Delete Cache', 'wp-super-cache' ), - 'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ), - 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache' ) - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => '', + 'id' => 'delete-cache', + 'title' => __( 'Delete Cache', 'wp-super-cache' ), + 'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ), + 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache' ), + ) + ); } if ( is_admin() && wpsupercache_site_admin() && current_user_can( 'manage_options' ) ) { - $wp_admin_bar->add_menu( array( - 'parent' => '', - 'id' => 'delete-cache', - 'title' => __( 'Delete Cache', 'wp-super-cache' ), - 'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ), - 'href' => wp_nonce_url( admin_url( 'options-general.php?page=wpsupercache&tab=contents&wp_delete_cache=1' ), 'wp-cache' ) - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => '', + 'id' => 'delete-cache', + 'title' => __( 'Delete Cache', 'wp-super-cache' ), + 'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ), + 'href' => wp_nonce_url( admin_url( 'options-general.php?page=wpsupercache&tab=contents&wp_delete_cache=1' ), 'wp-cache' ), + ) + ); } } add_action( 'admin_bar_menu', 'wpsc_admin_bar_render', 99 ); @@ -3900,36 +4257,57 @@ function wpsc_cancel_preload() { $next_preload = wp_next_scheduled( 'wp_cache_preload_hook' ); if ( $next_preload ) { wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_preload_hook' ); - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' ); } $next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' ); if ( $next_preload ) { - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_full_preload_hook' ); wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' ); } wp_cache_debug( 'wpsc_cancel_preload: creating stop_preload.txt' ); - $fp = @fopen( $cache_path . "stop_preload.txt", 'w' ); + $fp = @fopen( $cache_path . 'stop_preload.txt', 'w' ); @fclose( $fp ); } function wpsc_enable_preload() { global $cache_path; - @unlink( $cache_path . "preload_mutex.tmp" ); - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); + @unlink( $cache_path . 'preload_mutex.tmp' ); + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); wp_schedule_single_event( time() + 10, 'wp_cache_full_preload_hook' ); } function wpsc_get_post_types() { - $preload_type_args = apply_filters( 'wpsc_preload_post_types_args', array( - 'public' => true, - 'publicly_queryable' => true - ) ); + $preload_type_args = apply_filters( + 'wpsc_preload_post_types_args', + array( + 'public' => true, + 'publicly_queryable' => true, + ) + ); - $post_types = (array) apply_filters( 'wpsc_preload_post_types', get_post_types( $preload_type_args, 'names', 'or' )); + $post_types = (array) apply_filters( 'wpsc_preload_post_types', get_post_types( $preload_type_args, 'names', 'or' ) ); return "'" . join( "', '", array_map( 'esc_sql', $post_types ) ) . "'"; } @@ -3942,7 +4320,7 @@ function wpsc_post_count() { } $post_type_list = wpsc_get_post_types(); - $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ( $post_type_list ) AND post_status = 'publish'" ); + $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ( $post_type_list ) AND post_status = 'publish'" ); return $count; } @@ -3951,14 +4329,15 @@ function wpsc_preload_settings( $min_refresh_interval = 'NA' ) { $return = array(); - if ( isset( $_POST[ 'action' ] ) == false || $_POST[ 'action' ] != 'preload' ) + if ( isset( $_POST['action'] ) == false || $_POST['action'] != 'preload' ) { return $return; + } - if ( isset( $_POST[ 'preload_off' ] ) ) { + if ( isset( $_POST['preload_off'] ) ) { wpsc_cancel_preload(); - $return[] = "

    " . __( 'Scheduled preloading of cache almost cancelled. It may take up to a minute for it to cancel completely.', 'wp-super-cache' ) . "

    "; + $return[] = '

    ' . __( 'Scheduled preloading of cache almost cancelled. It may take up to a minute for it to cancel completely.', 'wp-super-cache' ) . '

    '; return $return; - } elseif ( isset( $_POST[ 'preload_now' ] ) ) { + } elseif ( isset( $_POST['preload_now'] ) ) { wpsc_enable_preload(); return $return; } @@ -3971,54 +4350,62 @@ function wpsc_preload_settings( $min_refresh_interval = 'NA' ) { $min_refresh_interval = 30; } } - if ( isset( $_POST[ 'wp_cache_preload_interval' ] ) && ( $_POST[ 'wp_cache_preload_interval' ] == 0 || $_POST[ 'wp_cache_preload_interval' ] >= $min_refresh_interval ) ) { + if ( isset( $_POST['wp_cache_preload_interval'] ) && ( $_POST['wp_cache_preload_interval'] == 0 || $_POST['wp_cache_preload_interval'] >= $min_refresh_interval ) ) { // if preload interval changes than unschedule any preload jobs and schedule any new one. - $_POST[ 'wp_cache_preload_interval' ] = (int)$_POST[ 'wp_cache_preload_interval' ]; - if ( $wp_cache_preload_interval != $_POST[ 'wp_cache_preload_interval' ] ) { + $_POST['wp_cache_preload_interval'] = (int) $_POST['wp_cache_preload_interval']; + if ( $wp_cache_preload_interval != $_POST['wp_cache_preload_interval'] ) { $next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' ); if ( $next_preload ) { - update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) ); + update_option( + 'preload_cache_counter', + array( + 'c' => 0, + 't' => time(), + ) + ); add_option( 'preload_cache_stop', 1 ); wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' ); if ( $wp_cache_preload_interval == 0 ) { - $return[] = "

    " . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . "

    "; + $return[] = '

    ' . __( 'Scheduled preloading of cache cancelled.', 'wp-super-cache' ) . '

    '; + } + if ( $_POST['wp_cache_preload_interval'] != 0 ) { + wp_schedule_single_event( time() + ( $_POST['wp_cache_preload_interval'] * 60 ), 'wp_cache_full_preload_hook' ); } - if ( $_POST[ 'wp_cache_preload_interval' ] != 0 ) - wp_schedule_single_event( time() + ( $_POST[ 'wp_cache_preload_interval' ] * 60 ), 'wp_cache_full_preload_hook' ); } } - $wp_cache_preload_interval = (int)$_POST[ 'wp_cache_preload_interval' ]; - wp_cache_setting( "wp_cache_preload_interval", $wp_cache_preload_interval ); + $wp_cache_preload_interval = (int) $_POST['wp_cache_preload_interval']; + wp_cache_setting( 'wp_cache_preload_interval', $wp_cache_preload_interval ); } - if ( $_POST[ 'wp_cache_preload_posts' ] == 'all' ) { + if ( $_POST['wp_cache_preload_posts'] == 'all' ) { $wp_cache_preload_posts = 'all'; } else { - $wp_cache_preload_posts = (int)$_POST[ 'wp_cache_preload_posts' ]; + $wp_cache_preload_posts = (int) $_POST['wp_cache_preload_posts']; } wp_cache_setting( 'wp_cache_preload_posts', $wp_cache_preload_posts ); - if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'none', 'less', 'medium', 'many' ) ) ) { - $wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ]; + if ( isset( $_POST['wp_cache_preload_email_volume'] ) && in_array( $_POST['wp_cache_preload_email_volume'], array( 'none', 'less', 'medium', 'many' ) ) ) { + $wp_cache_preload_email_volume = $_POST['wp_cache_preload_email_volume']; } else { $wp_cache_preload_email_volume = 'none'; } wp_cache_setting( 'wp_cache_preload_email_volume', $wp_cache_preload_email_volume ); - if ( $wp_cache_preload_email_volume == 'none' ) + if ( $wp_cache_preload_email_volume == 'none' ) { wp_cache_setting( 'wp_cache_preload_email_me', 0 ); - else + } else { wp_cache_setting( 'wp_cache_preload_email_me', 1 ); + } - if ( isset( $_POST[ 'wp_cache_preload_taxonomies' ] ) ) { + if ( isset( $_POST['wp_cache_preload_taxonomies'] ) ) { $wp_cache_preload_taxonomies = 1; } else { $wp_cache_preload_taxonomies = 0; } wp_cache_setting( 'wp_cache_preload_taxonomies', $wp_cache_preload_taxonomies ); - if ( isset( $_POST[ 'wp_cache_preload_on' ] ) ) { + if ( isset( $_POST['wp_cache_preload_on'] ) ) { $wp_cache_preload_on = 1; } else { $wp_cache_preload_on = 0; @@ -4084,33 +4471,33 @@ function update_mod_rewrite_rules( $add_rules = true ) { $update_mod_rewrite_rules_error = false; - if ( defined( "DO_NOT_UPDATE_HTACCESS" ) ) { - $update_mod_rewrite_rules_error = ".htaccess update disabled by admin: DO_NOT_UPDATE_HTACCESS defined"; + if ( defined( 'DO_NOT_UPDATE_HTACCESS' ) ) { + $update_mod_rewrite_rules_error = '.htaccess update disabled by admin: DO_NOT_UPDATE_HTACCESS defined'; return false; } if ( ! function_exists( 'get_home_path' ) ) { - include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path() - include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers() + include_once ABSPATH . 'wp-admin/includes/file.php'; // get_home_path() + include_once ABSPATH . 'wp-admin/includes/misc.php'; // extract_from_markers() } $home_path = trailingslashit( get_home_path() ); $home_root = parse_url( get_bloginfo( 'url' ) ); - $home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/'; + $home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/'; if ( $home_root == '/' && - $home_path != $_SERVER[ 'DOCUMENT_ROOT' ] + $home_path != $_SERVER['DOCUMENT_ROOT'] ) { - $home_path = $_SERVER[ 'DOCUMENT_ROOT' ]; + $home_path = $_SERVER['DOCUMENT_ROOT']; } elseif ( $home_root != '/' && - $home_path != str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) && - is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) + $home_path != str_replace( '//', '/', $_SERVER['DOCUMENT_ROOT'] . $home_root ) && + is_dir( $_SERVER['DOCUMENT_ROOT'] . $home_root ) ) { - $home_path = str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ); + $home_path = str_replace( '//', '/', $_SERVER['DOCUMENT_ROOT'] . $home_root ); } $home_path = trailingslashit( $home_path ); - if ( ! file_exists( $home_path . ".htaccess" ) ) { + if ( ! file_exists( $home_path . '.htaccess' ) ) { $update_mod_rewrite_rules_error = ".htaccess not found: {$home_path}.htaccess"; return false; } @@ -4118,15 +4505,15 @@ function update_mod_rewrite_rules( $add_rules = true ) { $generated_rules = wpsc_get_htaccess_info(); $existing_rules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) ); - $rules = $add_rules ? $generated_rules[ 'rules' ] : ''; + $rules = $add_rules ? $generated_rules['rules'] : ''; if ( $existing_rules == $rules ) { - $update_mod_rewrite_rules_error = "rules have not changed"; + $update_mod_rewrite_rules_error = 'rules have not changed'; return true; } - if ( $generated_rules[ 'wprules' ] == '' ) { - $update_mod_rewrite_rules_error = "WordPress rules empty"; + if ( $generated_rules['wprules'] == '' ) { + $update_mod_rewrite_rules_error = 'WordPress rules empty'; return false; } @@ -4134,37 +4521,49 @@ function update_mod_rewrite_rules( $add_rules = true ) { return insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', array() ); } - $url = trailingslashit( get_bloginfo( 'url' ) ); - $original_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) ); + $url = trailingslashit( get_bloginfo( 'url' ) ); + $original_page = wp_remote_get( + $url, + array( + 'timeout' => 60, + 'blocking' => true, + ) + ); if ( is_wp_error( $original_page ) ) { - $update_mod_rewrite_rules_error = "Problem loading page"; + $update_mod_rewrite_rules_error = 'Problem loading page'; return false; } - $backup_filename = $cache_path . 'htaccess.' . mt_rand() . ".php"; + $backup_filename = $cache_path . 'htaccess.' . mt_rand() . '.php'; $backup_file_contents = file_get_contents( $home_path . '.htaccess' ); - file_put_contents( $backup_filename, "<" . "?php die(); ?" . ">" . $backup_file_contents ); + file_put_contents( $backup_filename, '<' . '?php die(); ?' . '>' . $backup_file_contents ); $existing_gzip_rules = implode( "\n", extract_from_markers( $cache_path . '.htaccess', 'supercache' ) ); - if ( $existing_gzip_rules != $generated_rules[ 'gziprules' ] ) { - insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $generated_rules[ 'gziprules' ] ) ); + if ( $existing_gzip_rules != $generated_rules['gziprules'] ) { + insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $generated_rules['gziprules'] ) ); } $wprules = extract_from_markers( $home_path . '.htaccess', 'WordPress' ); wpsc_remove_marker( $home_path . '.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top if ( insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path . '.htaccess', 'WordPress', $wprules ) ) { - $new_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) ); + $new_page = wp_remote_get( + $url, + array( + 'timeout' => 60, + 'blocking' => true, + ) + ); $restore_backup = false; if ( is_wp_error( $new_page ) ) { - $restore_backup = true; - $update_mod_rewrite_rules_error = "Error testing page with new .htaccess rules: " . $new_page->get_error_message() . "."; + $restore_backup = true; + $update_mod_rewrite_rules_error = 'Error testing page with new .htaccess rules: ' . $new_page->get_error_message() . '.'; wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. error fetching second page: ' . $new_page->get_error_message() ); - } elseif ( $new_page[ 'body' ] != $original_page[ 'body' ] ) { - $restore_backup = true; - $update_mod_rewrite_rules_error = "Page test failed as pages did not match with new .htaccess rules."; + } elseif ( $new_page['body'] != $original_page['body'] ) { + $restore_backup = true; + $update_mod_rewrite_rules_error = 'Page test failed as pages did not match with new .htaccess rules.'; wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. page test failed as pages did not match. Files dumped in ' . $cache_path . ' for inspection.' ); - wp_cache_debug( 'update_mod_rewrite_rules: original page: 1-' . md5( $original_page[ 'body' ] ) . '.txt' ); - wp_cache_debug( 'update_mod_rewrite_rules: new page: 1-' . md5( $new_page[ 'body' ] ) . '.txt' ); - file_put_contents( $cache_path . '1-' . md5( $original_page[ 'body' ] ) . '.txt', $original_page[ 'body' ] ); - file_put_contents( $cache_path . '2-' . md5( $new_page[ 'body' ] ) . '.txt', $new_page[ 'body' ] ); + wp_cache_debug( 'update_mod_rewrite_rules: original page: 1-' . md5( $original_page['body'] ) . '.txt' ); + wp_cache_debug( 'update_mod_rewrite_rules: new page: 1-' . md5( $new_page['body'] ) . '.txt' ); + file_put_contents( $cache_path . '1-' . md5( $original_page['body'] ) . '.txt', $original_page['body'] ); + file_put_contents( $cache_path . '2-' . md5( $new_page['body'] ) . '.txt', $new_page['body'] ); } if ( $restore_backup ) { @@ -4172,9 +4571,9 @@ function update_mod_rewrite_rules( $add_rules = true ) { file_put_contents( $home_path . '.htaccess', $backup_file_contents ); unlink( $backup_filename ); if ( $wp_cache_debug ) { - $update_mod_rewrite_rules_error .= "
    See debug log for further details"; + $update_mod_rewrite_rules_error .= '
    See debug log for further details'; } else { - $update_mod_rewrite_rules_error .= "
    Enable debug log on Debugging page for further details and try again"; + $update_mod_rewrite_rules_error .= '
    Enable debug log on Debugging page for further details and try again'; } return false; @@ -4182,7 +4581,7 @@ function update_mod_rewrite_rules( $add_rules = true ) { } else { file_put_contents( $home_path . '.htaccess', $backup_file_contents ); unlink( $backup_filename ); - $update_mod_rewrite_rules_error = "problem inserting rules in .htaccess and original .htaccess restored"; + $update_mod_rewrite_rules_error = 'problem inserting rules in .htaccess and original .htaccess restored'; return false; } @@ -4195,7 +4594,7 @@ function wpsc_feed_update( $type, $permalink ) { update_option( 'wpsc_feed_list', array() ); if ( is_array( $wpsc_feed_list ) && ! empty( $wpsc_feed_list ) ) { - foreach( $wpsc_feed_list as $file ) { + foreach ( $wpsc_feed_list as $file ) { wp_cache_debug( "wpsc_feed_update: deleting feed: $file" ); prune_super_cache( $file, true ); prune_super_cache( dirname( $file ) . '/meta-' . basename( $file ), true ); @@ -4206,26 +4605,26 @@ function wpsc_feed_update( $type, $permalink ) { function wpsc_get_plugin_list() { $list = do_cacheaction( 'wpsc_filter_list' ); - foreach( $list as $t => $details ) { - $key = "cache_" . $details[ 'key' ]; + foreach ( $list as $t => $details ) { + $key = 'cache_' . $details['key']; if ( isset( $GLOBALS[ $key ] ) && $GLOBALS[ $key ] == 1 ) { - $list[ $t ][ 'enabled' ] = true; + $list[ $t ]['enabled'] = true; } else { - $list[ $t ][ 'enabled' ] = false; + $list[ $t ]['enabled'] = false; } - $list[ $t ][ 'desc' ] = strip_tags( $list[ $t ][ 'desc' ] ); - $list[ $t ][ 'title' ] = strip_tags( $list[ $t ][ 'title' ] ); + $list[ $t ]['desc'] = strip_tags( $list[ $t ]['desc'] ); + $list[ $t ]['title'] = strip_tags( $list[ $t ]['title'] ); } return $list; } function wpsc_update_plugin_list( $update ) { $list = do_cacheaction( 'wpsc_filter_list' ); - foreach( $update as $key => $enabled ) { + foreach ( $update as $key => $enabled ) { $plugin_toggle = "cache_{$key}"; if ( isset( $GLOBALS[ $plugin_toggle ] ) || isset( $list[ $key ] ) ) { - wp_cache_setting( $plugin_toggle, (int)$enabled ); + wp_cache_setting( $plugin_toggle, (int) $enabled ); } } } @@ -4323,7 +4722,7 @@ function wpsc_update_check() { ) { wp_cache_setting( 'wpsc_version', 169 ); global $wp_cache_debug_log, $cache_path; - $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log)); + $log_file = $cache_path . str_replace( '/', '', str_replace( '..', '', $wp_cache_debug_log ) ); if ( ! file_exists( $log_file ) ) { return false; }