updated plugin Jetpack Protect version 1.3.0

This commit is contained in:
2023-03-17 22:34:13 +00:00
committed by Gitium
parent 19e086d1c4
commit 1e9ac45ec6
183 changed files with 4388 additions and 2345 deletions

View File

@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.1.4] - 2023-03-07
### Changed
- Updated package dependencies.
## [0.1.3] - 2023-01-25
### Changed
- Use `WP_Filesystem` more consistently in `Helper_Script_Manager`. [#28198]
## [0.1.2] - 2022-12-05
### Changed
- Updated package dependencies. [#27688]
@ -21,5 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Updated package dependencies.
[0.1.4]: https://github.com/Automattic/jetpack-transport-helper/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/Automattic/jetpack-transport-helper/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/Automattic/jetpack-transport-helper/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/Automattic/jetpack-transport-helper/compare/v0.1.0...v0.1.1

View File

@ -4,11 +4,11 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.47.1"
"automattic/jetpack-connection": "^1.51.1"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/wordbless": "dev-master"
},
"autoload": {
@ -23,9 +23,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
],

View File

@ -49,6 +49,11 @@ class Helper_Script_Manager {
// Replace '[wp_path]' in the Helper Script with the WordPress installation location. Allows the Helper Script to find WordPress.
$script_body = str_replace( '[wp_path]', addslashes( ABSPATH ), $script_body );
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return new \WP_Error( 'install_failed', 'Failed to install Helper Script' );
}
// Create a jetpack-temp directory for the Helper Script.
$temp_directory = self::create_temp_directory();
if ( \is_wp_error( $temp_directory ) ) {
@ -62,11 +67,11 @@ class Helper_Script_Manager {
$file_name = 'jp-helper-' . $file_key . '.php';
$file_path = trailingslashit( $temp_directory['path'] ) . $file_name;
if ( ! file_exists( $file_path ) ) {
if ( ! $wp_filesystem->exists( $file_path ) ) {
// Attempt to write helper script.
if ( ! self::put_contents( $file_path, $script_body ) ) {
if ( file_exists( $file_path ) ) {
unlink( $file_path );
if ( $wp_filesystem->exists( $file_path ) ) {
$wp_filesystem->delete( $file_path );
}
continue;
@ -96,7 +101,12 @@ class Helper_Script_Manager {
* @return boolean True if the file is deleted (or does not exist).
*/
public static function delete_helper_script( $path ) {
if ( ! file_exists( $path ) ) {
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return false;
}
if ( ! $wp_filesystem->exists( $path ) ) {
return true;
}
@ -105,7 +115,7 @@ class Helper_Script_Manager {
return false;
}
return unlink( $path );
return $wp_filesystem->delete( $path );
}
/**
@ -138,16 +148,21 @@ class Helper_Script_Manager {
* @param int|null $expiry_time If specified, only delete scripts older than $expiry_time.
*/
public static function cleanup_helper_scripts( $expiry_time = null ) {
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return;
}
foreach ( self::get_install_locations() as $directory => $url ) {
$temp_dir = trailingslashit( $directory ) . self::TEMP_DIRECTORY;
if ( is_dir( $temp_dir ) ) {
if ( $wp_filesystem->is_dir( $temp_dir ) ) {
// Find expired helper scripts and delete them.
$helper_scripts = glob( trailingslashit( $temp_dir ) . 'jp-helper-*.php' );
$helper_scripts = $wp_filesystem->dirlist( $temp_dir );
if ( is_array( $helper_scripts ) ) {
foreach ( $helper_scripts as $filename ) {
if ( null === $expiry_time || filemtime( $filename ) < $expiry_time ) {
self::delete_helper_script( $filename );
foreach ( $helper_scripts as $entry ) {
if ( preg_match( '/^jp-helper-*\.php$/', $entry['name'] ) && ( null === $expiry_time || $entry['lastmodunix'] < $expiry_time ) ) {
self::delete_helper_script( trailingslashit( $temp_dir ) . $entry['name'] );
}
}
}
@ -168,14 +183,18 @@ class Helper_Script_Manager {
* @return boolean True if the directory is deleted
*/
private static function delete_empty_helper_directory( $dir ) {
if ( ! is_dir( $dir ) ) {
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return false;
}
if ( ! $wp_filesystem->is_dir( $dir ) ) {
return false;
}
// Tally the files in the target directory, and reject if there are too many.
$glob_path = trailingslashit( $dir ) . '*';
$dir_contents = glob( $glob_path );
if ( count( $dir_contents ) > 2 ) {
$dir_contents = $wp_filesystem->dirlist( $dir );
if ( $dir_contents === false || count( $dir_contents ) > 2 ) {
return false;
}
@ -185,8 +204,9 @@ class Helper_Script_Manager {
'index.php' => self::INDEX_FILE,
);
foreach ( $dir_contents as $path ) {
$basename = basename( $path );
foreach ( $dir_contents as $entry ) {
$basename = $entry['name'];
$path = trailingslashit( $dir ) . $basename;
if ( ! isset( $allowed_files[ $basename ] ) ) {
return false;
}
@ -196,14 +216,15 @@ class Helper_Script_Manager {
return false;
}
if ( ! unlink( $path ) ) {
if ( ! $wp_filesystem->delete( $path ) ) {
return false;
}
}
// If the directory is now empty, delete it.
if ( count( glob( $glob_path ) ) === 0 ) {
return rmdir( $dir );
$dir_contents = $wp_filesystem->dirlist( $dir );
if ( $dir_contents === false || count( $dir_contents ) === 0 ) {
return $wp_filesystem->rmdir( $dir );
}
return false;
@ -218,16 +239,21 @@ class Helper_Script_Manager {
* @return WP_Error|array Array containing the url and path of the temp directory if successful, WP_Error if not.
*/
private static function create_temp_directory() {
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return new \WP_Error( 'temp_directory', 'Failed to create jetpack-temp directory' );
}
foreach ( self::get_install_locations() as $directory => $url ) {
// Check if the install location is writeable.
if ( ! is_writeable( $directory ) ) {
if ( ! $wp_filesystem->is_writable( $directory ) ) {
continue;
}
// Create if one doesn't already exist.
$temp_dir = trailingslashit( $directory ) . self::TEMP_DIRECTORY;
if ( ! is_dir( $temp_dir ) ) {
if ( ! mkdir( $temp_dir ) ) {
if ( ! $wp_filesystem->is_dir( $temp_dir ) ) {
if ( ! $wp_filesystem->mkdir( $temp_dir ) ) {
continue;
}
@ -271,13 +297,8 @@ class Helper_Script_Manager {
* @return boolean True if successfully written.
*/
private static function put_contents( $file_path, $contents ) {
global $wp_filesystem;
if ( ! function_exists( '\\WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
if ( ! \WP_Filesystem() ) {
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return false;
}
@ -295,13 +316,8 @@ class Helper_Script_Manager {
* @return boolean True if the file exists, is readable, and the header matches.
*/
private static function verify_file_header( $file_path, $expected_header ) {
global $wp_filesystem;
if ( ! function_exists( '\\WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
if ( ! \WP_Filesystem() ) {
$wp_filesystem = self::get_wp_filesystem();
if ( ! $wp_filesystem ) {
return false;
}
@ -343,4 +359,25 @@ class Helper_Script_Manager {
return $install_locations;
}
/**
* Get the WP_Filesystem.
*
* @return \WP_Filesystem|null
*/
private static function get_wp_filesystem() {
global $wp_filesystem;
if ( ! $wp_filesystem ) {
if ( ! function_exists( '\\WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
if ( ! \WP_Filesystem() ) {
return null;
}
}
return $wp_filesystem;
}
}

View File

@ -12,7 +12,7 @@ namespace Automattic\Jetpack\Transport_Helper;
*/
class Package_Version {
const PACKAGE_VERSION = '0.1.2';
const PACKAGE_VERSION = '0.1.4';
const PACKAGE_SLUG = 'transport-helper';