This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,186 @@
# Changelog
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.5.11] - 2026-06-08
### Changed
- Internal updates.
## [0.5.10] - 2026-06-05
### Changed
- Internal updates.
## [0.5.9] - 2026-05-19
### Changed
- Internal updates.
## [0.5.8] - 2026-05-04
### Changed
- Internal: No longer require automattic/jetpack-changelogger as a per-project dev dependency. [#48225]
## [0.5.7] - 2025-08-14
### Changed
- Internal updates.
## [0.5.6] - 2025-07-21
### Changed
- Internal updates.
## [0.5.5] - 2025-04-28
### Changed
- Internal updates.
## [0.5.4] - 2025-03-21
### Changed
- Internal updates.
## [0.5.3] - 2025-03-12
### Changed
- Internal updates.
## [0.5.2] - 2025-03-05
### Changed
- Internal updates.
## [0.5.1] - 2025-02-24
### Changed
- Update dependencies.
## [0.5.0] - 2024-11-14
### Removed
- General: Update minimum PHP version to 7.2. [#40147]
## [0.4.4] - 2024-11-04
### Added
- Enable test coverage. [#39961]
## [0.4.3] - 2024-09-05
### Changed
- Update dependencies.
## [0.4.2] - 2024-08-26
### Changed
- Updated package dependencies. [#39004]
## [0.4.1] - 2024-08-15
### Fixed
- Fix incorrect next-version tokens in php `@since` and/or `@deprecated` docs. [#38869]
## [0.4.0] - 2024-05-20
### Deprecated
- Extract the 'is_current_request_activating_plugin_from_plugins_screen' method into Status package. [#37430]
## [0.3.5] - 2024-05-06
### Changed
- Internal updates.
## [0.3.4] - 2024-04-08
### Changed
- Internal updates.
## [0.3.3] - 2024-03-25
### Changed
- Internal updates.
## [0.3.2] - 2024-03-14
### Changed
- Internal updates.
## [0.3.1] - 2024-01-02
### Fixed
- Ensured that language packs are installed after installing a new plugin. [#34763]
## [0.3.0] - 2023-11-20
### Changed
- Updated required PHP version to >= 7.0. [#34192]
## [0.2.6] - 2023-11-14
## [0.2.5] - 2023-08-23
### Changed
- Updated package dependencies. [#32605]
## [0.2.4] - 2023-04-10
### Added
- Add Jetpack Autoloader package suggestion. [#29988]
## [0.2.3] - 2023-02-20
### Changed
- Minor internal updates.
## [0.2.2] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
## [0.2.1] - 2022-11-22
### Changed
- Updated package dependencies. [#27043]
## [0.2.0] - 2022-08-23
### Added
- Add method to check plugin activation context. [#25422]
## [0.1.4] - 2022-07-26
### Changed
- Updated package dependencies. [#25158]
## [0.1.3] - 2022-06-21
### Changed
- Renaming master to trunk.
## [0.1.2] - 2022-04-26
### Changed
- Updated package dependencies.
## [0.1.1] - 2022-03-29
### Added
- Set composer package type to "jetpack-library" so i18n will work.
## 0.1.0 - 2022-02-02
### Added
- First version
- New functions to safely check plugin statuses
### Changed
- Build: add missing mirror repo details, so package can be deployed.
### Fixed
- Fix method logic
[0.5.11]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.10...v0.5.11
[0.5.10]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.9...v0.5.10
[0.5.9]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.8...v0.5.9
[0.5.8]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.7...v0.5.8
[0.5.7]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.6...v0.5.7
[0.5.6]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.5...v0.5.6
[0.5.5]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.4...v0.5.5
[0.5.4]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.3...v0.5.4
[0.5.3]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.2...v0.5.3
[0.5.2]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.1...v0.5.2
[0.5.1]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.4.4...v0.5.0
[0.4.4]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.4.3...v0.4.4
[0.4.3]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.4.2...v0.4.3
[0.4.2]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.4.1...v0.4.2
[0.4.1]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.3.5...v0.4.0
[0.3.5]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.3.4...v0.3.5
[0.3.4]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.3.3...v0.3.4
[0.3.3]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.3.2...v0.3.3
[0.3.2]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.6...v0.3.0
[0.2.6]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.5...v0.2.6
[0.2.5]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.4...v0.2.5
[0.2.4]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.3...v0.2.4
[0.2.3]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.2...v0.2.3
[0.2.2]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.1.4...v0.2.0
[0.1.4]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/Automattic/jetpack-plugins-installer/compare/v0.1.0...v0.1.1
@@ -0,0 +1,161 @@
<?php
/**
* Automatic_Upgrader_Skin extension for Jetpack
*
* @package jetpack-plugins-installer
*/
namespace Automattic\Jetpack;
use Automatic_Upgrader_Skin;
use WP_Error;
use WP_Upgrader;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
/**
* Include required files from wp-admin.
*/
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
/**
* Allows us to capture that the site doesn't have proper file system access.
* In order to update the plugin.
*/
class Automatic_Install_Skin extends Automatic_Upgrader_Skin {
/**
* Stores the last error key;
*
* @var string
**/
protected $main_error_code = 'install_error';
/**
* Stores the last error message.
*
* @var string
**/
protected $main_error_message = 'An unknown error occurred during installation';
/**
* Overwrites the set_upgrader to be able to tell if we e ven have the ability to write to the files.
*
* @param WP_Upgrader $upgrader The upgrader object.
*/
public function set_upgrader( &$upgrader ) {
parent::set_upgrader( $upgrader );
// Check if we even have permission to.
$result = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
if ( ! $result ) {
// set the string here since they are not available just yet.
$upgrader->generic_strings();
$this->feedback( 'fs_unavailable' );
}
}
/**
* Overwrites the error function
*
* @param WP_Error|mixed $error The error object.
*/
public function error( $error ) {
if ( is_wp_error( $error ) ) {
$this->feedback( $error );
}
}
/**
* Set the main error code.
*
* Don't set the process_failed as code since it is not that helpful unless we don't have one already set
*
* @param string $code The error code.
* @return void
*/
private function set_main_error_code( $code ) {
$this->main_error_code = ( 'process_failed' === $code && $this->main_error_code ? $this->main_error_code : $code );
}
/**
* Set the main error message.
*
* Don't set the process_failed as message since it is not that helpful unless we don't have one already set
*
* @param string $message The error message.
* @param string $code The error code.
* @return void
*/
private function set_main_error_message( $message, $code ) {
$this->main_error_message = ( 'process_failed' === $code && $this->main_error_message ? $this->main_error_message : $message );
}
/**
* Get the main error code
*
* @return string
*/
public function get_main_error_code() {
return $this->main_error_code;
}
/**
* Get the main error message
*
* @return string
*/
public function get_main_error_message() {
return $this->main_error_message;
}
/**
* Overwrites the feedback function
*
* @param string|array|WP_Error $data Data.
* @param mixed ...$args Optional text replacements.
*/
public function feedback( $data, ...$args ) {
$current_error = null;
if ( is_wp_error( $data ) ) {
$this->set_main_error_code( $data->get_error_code() );
$string = $data->get_error_message();
} elseif ( is_array( $data ) ) {
return;
} else {
$string = $data;
}
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
$this->set_main_error_code( $string );
$current_error = $string;
$string = $this->upgrader->strings[ $string ];
}
if ( strpos( $string, '%' ) !== false ) {
if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args );
}
}
$string = trim( $string );
$string = wp_kses(
$string,
array(
'a' => array(
'href' => true,
),
'br' => true,
'em' => true,
'strong' => true,
)
);
$this->set_main_error_message( $string, $current_error );
$this->messages[] = $string;
}
}
@@ -0,0 +1,255 @@
<?php
/**
* Plugins Library
*
* Helper functions for installing and activating plugins.
*
* Used by the REST API
*
* @package jetpack-plugins-installer
*/
namespace Automattic\Jetpack;
use Plugin_Upgrader;
use WP_Error;
/**
* Plugins management tools.
*/
class Plugins_Installer {
/**
* Ensures that plugins functions are loaded, as they are only loaded in admin context by default.
*/
private static function ensure_plugin_functions_are_loaded() {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
}
/**
* Install and activate a plugin.
*
* @since-jetpack 5.8.0
*
* @param string $slug Plugin slug.
*
* @return bool|WP_Error True if installation succeeded, error object otherwise.
*/
public static function install_and_activate_plugin( $slug ) {
$plugin_id = self::get_plugin_id_by_slug( $slug );
if ( ! $plugin_id ) {
$installed = self::install_plugin( $slug );
if ( is_wp_error( $installed ) ) {
return $installed;
}
$plugin_id = self::get_plugin_id_by_slug( $slug );
} elseif ( self::is_plugin_active( $plugin_id ) ) {
return true; // Already installed and active.
}
if ( ! current_user_can( 'activate_plugins' ) ) {
return new WP_Error( 'not_allowed', __( 'You are not allowed to activate plugins on this site.', 'jetpack-plugins-installer' ) );
}
$activated = activate_plugin( $plugin_id );
if ( is_wp_error( $activated ) ) {
return $activated;
}
return true;
}
/**
* Install a plugin.
*
* @since-jetpack 5.8.0
*
* @param string $slug Plugin slug.
*
* @return bool|WP_Error True if installation succeeded, error object otherwise.
*/
public static function install_plugin( $slug ) {
if ( is_multisite() && ! current_user_can( 'manage_network' ) ) {
return new WP_Error( 'not_allowed', __( 'You are not allowed to install plugins on this site.', 'jetpack-plugins-installer' ) );
}
// Initialize admin filters to make sure WordPress post-install hooks run. Handles things like language packs.
include_once ABSPATH . '/wp-admin/includes/admin-filters.php';
$skin = new Automatic_Install_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$zip_url = self::generate_wordpress_org_plugin_download_link( $slug );
$mc_stats = new A8c_Mc_Stats();
$result = $upgrader->install( $zip_url );
if ( is_wp_error( $result ) ) {
$mc_stats->add( 'install-plugin', "fail-$slug" );
return $result;
}
$plugin = self::get_plugin_id_by_slug( $slug );
$error_code = 'install_error';
if ( ! $plugin ) {
$error = __( 'There was an error installing your plugin', 'jetpack-plugins-installer' );
}
if ( ! $result ) {
$error_code = $skin->get_main_error_code();
$message = $skin->get_main_error_message();
$error = $message ? $message : __( 'An unknown error occurred during installation', 'jetpack-plugins-installer' );
}
if ( ! empty( $error ) ) {
if ( 'download_failed' === $error_code ) {
// For backwards compatibility: versions prior to 3.9 would return no_package instead of download_failed.
$error_code = 'no_package';
}
$mc_stats->add( 'install-plugin', "fail-$slug" );
return new WP_Error( $error_code, $error, 400 );
}
$mc_stats->add( 'install-plugin', "success-$slug" );
return (array) $upgrader->skin->get_upgrade_messages();
}
/**
* Get WordPress.org zip download link from a plugin slug
*
* @param string $plugin_slug Plugin slug.
*/
protected static function generate_wordpress_org_plugin_download_link( $plugin_slug ) {
return "https://downloads.wordpress.org/plugin/$plugin_slug.latest-stable.zip";
}
/**
* Get the plugin ID (composed of the plugin slug and the name of the main plugin file) from a plugin slug.
*
* @param string $slug Plugin slug.
*/
public static function get_plugin_id_by_slug( $slug ) {
// Check if get_plugins() function exists. This is required on the front end of the
// site, since it is in a file that is normally only loaded in the admin.
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
$plugins = apply_filters( 'all_plugins', get_plugins() );
if ( ! is_array( $plugins ) ) {
return false;
}
foreach ( $plugins as $plugin_file => $plugin_data ) {
if ( self::get_slug_from_file_path( $plugin_file ) === $slug ) {
return $plugin_file;
}
}
return false;
}
/**
* Get the plugin slug from the plugin ID (composed of the plugin slug and the name of the main plugin file)
*
* @param string $plugin_file Plugin file (ID -- e.g. hello-dolly/hello.php).
*/
protected static function get_slug_from_file_path( $plugin_file ) {
// Similar to get_plugin_slug() method.
$slug = dirname( $plugin_file );
if ( '.' === $slug ) {
$slug = preg_replace( '/(.+)\.php$/', '$1', $plugin_file );
}
return $slug;
}
/**
* Get the activation status for a plugin.
*
* @since-jetpack 8.9.0
*
* @param string $plugin_file The plugin file to check.
* @return string Either 'network-active', 'active' or 'inactive'.
*/
public static function get_plugin_status( $plugin_file ) {
if ( self::is_plugin_active_for_network( $plugin_file ) ) {
return 'network-active';
}
if ( self::is_plugin_active( $plugin_file ) ) {
return 'active';
}
return 'inactive';
}
/**
* Safely checks if the plugin is active
*
* @since 0.1.0
*
* @param string $plugin_file The plugin file to check.
* @return bool
*/
public static function is_plugin_active( $plugin_file ) {
self::ensure_plugin_functions_are_loaded();
return is_plugin_active( $plugin_file );
}
/**
* Safely checks if the plugin is active for network
*
* @since 0.1.0
*
* @param string $plugin_file The plugin file to check.
* @return bool
*/
public static function is_plugin_active_for_network( $plugin_file ) {
self::ensure_plugin_functions_are_loaded();
return is_plugin_active_for_network( $plugin_file );
}
/**
* Returns a list of all plugins in the site.
*
* @since-jetpack 8.9.0
* @uses get_plugins()
*
* @return array
*/
public static function get_plugins() {
self::ensure_plugin_functions_are_loaded();
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
$plugins = apply_filters( 'all_plugins', get_plugins() );
if ( is_array( $plugins ) && ! empty( $plugins ) ) {
foreach ( $plugins as $plugin_slug => $plugin_data ) {
$plugins[ $plugin_slug ]['active'] = in_array(
self::get_plugin_status( $plugin_slug ),
array( 'active', 'network-active' ),
true
);
}
return $plugins;
}
return array();
}
/**
* Determine if the current request is activating a plugin from the plugins page.
*
* @deprecated 0.4.0
* @see Paths::is_current_request_activating_plugin_from_plugins_screen()
*
* @param string $plugin Plugin file path to check.
* @return bool
*/
public static function is_current_request_activating_plugin_from_plugins_screen( $plugin ) {
_deprecated_function( __METHOD__, '0.4.0', 'Automattic\\Jetpack\\Paths::is_current_request_activating_plugin_from_plugins_screen()' );
return ( new Paths() )->is_current_request_activating_plugin_from_plugins_screen( $plugin );
}
}