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,678 @@
# 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).
## [6.1.8] - 2026-06-15
### Changed
- Internal updates.
## [6.1.7] - 2026-06-08
### Changed
- Internal updates.
## [6.1.6] - 2026-06-03
### Changed
- Internal updates.
## [6.1.5] - 2026-05-21
### Fixed
- Phan: Address PhanPluginDuplicateConditionalNullCoalescing violations. [#48887]
## [6.1.4] - 2026-05-19
### Changed
- Internal updates.
## [6.1.3] - 2026-05-04
### Added
- Tests: Load polyfills for `str_contains`, `str_starts_with`, and `str_ends_with` in the test bootstrap on PHP < 8.0. [#48225]
### Changed
- Internal: No longer require automattic/jetpack-changelogger as a per-project dev dependency. [#48225]
## [6.1.2] - 2025-12-15
### Changed
- Internal updates.
## [6.1.1] - 2025-11-03
### Fixed
- Phan: Address PhanRedundantCondition, PhanRedundantArrayValuesCall, and PhanPluginRedundantAssignment violations. [#45681]
## [6.1.0] - 2025-10-13
### Added
- Identify `.ddev.site` as a local site. [#45457]
## [6.0.4] - 2025-09-08
### Changed
- Internal updates.
## [6.0.3] - 2025-08-14
### Changed
- Update `is_frontend` method to allow not sending "Vary" header. [#44741]
## [6.0.2] - 2025-08-06
### Added
- Status: Add two new helper functions for P2 and WordPress.com site ID checks. [#44512]
## [6.0.1] - 2025-08-04
### Added
- Requests: Treat WPCOM_CLI_SCRIPT as a backend request. [#44553]
## [6.0.0] - 2025-07-21
### Removed
- Remove host guess based on DNS. [#44325]
## [5.4.0] - 2025-07-08
### Changed
- VIP: Change hosting check method back now that constant is reliable. [#44223]
## [5.3.1] - 2025-06-27
### Changed
- Internal updates.
## [5.3.0] - 2025-06-23
### Changed
- VIP: Change hosting check method. [#44059]
## [5.2.1] - 2025-06-19
### Changed
- Internal updates.
## [5.2.0] - 2025-06-10
### Added
- Request: Add new class used to classify requests on a site. [#43843]
## [5.1.4] - 2025-04-28
### Changed
- Internal updates.
## [5.1.3] - 2025-04-21
### Fixed
- Module Activation: Use require_once to avoid potential redeclaration errors. [#43120]
## [5.1.2] - 2025-04-14
### Changed
- Internal updates.
## [5.1.1] - 2025-03-31
### Changed
- Internal updates.
## [5.1.0] - 2025-03-26
### Added
- Add database option to enable Offline Mode. [#42630]
## [5.0.10] - 2025-03-21
### Changed
- Internal updates.
## [5.0.9] - 2025-03-18
### Changed
- Internal updates.
## [5.0.8] - 2025-03-17
### Changed
- Internal updates.
## [5.0.7] - 2025-03-12
### Changed
- Internal updates.
## [5.0.6] - 2025-03-05
### Changed
- Internal updates.
## [5.0.5] - 2025-03-03
### Fixed
- Hosting provider checks: Avoid PHP warnings in local environments. [#41994]
## [5.0.4] - 2025-02-24
### Changed
- Host detection: Look for specific external hosting provider only when required. [#41890]
## [5.0.3] - 2025-02-03
### Fixed
- Code: Remove extra params on function calls. [#41263]
## [5.0.2] - 2025-01-20
### Changed
- Code: Use function-style exit() and die() with a default status code of 0. [#41167]
## [5.0.1] - 2024-11-25
### Changed
- Updated package dependencies. [#40258]
## [5.0.0] - 2024-11-14
### Removed
- General: Update minimum PHP version to 7.2. [#40147]
## [4.0.3] - 2024-11-04
### Added
- Enable test coverage. [#39961]
## [4.0.2] - 2024-09-23
### Changed
- Update dependencies.
## [4.0.1] - 2024-09-06
### Removed
- Removed usage of _deprecated_function when deprecating Status::is_onboarding [#39272]
## [4.0.0] - 2024-09-05
### Deprecated
- Deprecated Jetpack Onboarding system. [#39229]
## [3.3.4] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
## [3.3.3] - 2024-08-19
### Changed
- Internal updates.
## [3.3.2] - 2024-06-24
### Changed
- Internal updates.
## [3.3.1] - 2024-06-21
### Added
- Check for active modules among the unavailable ones. [#37358]
## [3.3.0] - 2024-06-10
### Deprecated
- Deprecated is_staging_site [#37023]
## [3.2.3] - 2024-06-03
### Removed
- Remove the Identity Crisis dev dependency. [#37654]
## [3.2.2] - 2024-05-29
### Changed
- Phab baseline file update. [#36968]
## [3.2.1] - 2024-05-28
### Changed
- Internal updates.
## [3.2.0] - 2024-05-22
### Deprecated
- Jetpack: Deprecated Errors class. [#37451]
## [3.1.0] - 2024-05-20
### Added
- Add the 'is_current_request_activating_plugin_from_plugins_screen' method extracted from the Plugin Install package. [#37430]
## [3.0.3] - 2024-05-08
### Fixed
- Status: Added check for compatibility reasons [#37256]
## [3.0.2] - 2024-05-06
### Added
- Add new method used to track allowed domains for API access. [#36924]
## [3.0.1] - 2024-04-30
### Changed
- Internal updates.
## [3.0.0] - 2024-04-25
### Added
- Add is_automattician_feature_flags_only on Jetpack sites as an alternative to is_automattician present on simple sites. [#34798]
### Removed
- Remove methods deprecated long ago. [#36985]
## [2.2.2] - 2024-04-22
### Changed
- Internal updates.
## [2.2.1] - 2024-04-08
### Changed
- Internal updates.
## [2.2.0] - 2024-03-22
### Added
- Add support for A8C for Agencies source parameter. [#36491]
## [2.1.3] - 2024-03-20
### Changed
- Internal updates.
## [2.1.2] - 2024-03-12
### Changed
- Internal updates.
## [2.1.1] - 2024-03-01
### Fixed
- Avoid issues when the dns_get_record function is not defined [#36019]
## [2.1.0] - 2024-01-18
### Added
- Add hosting provider check. [#34864]
## [2.0.2] - 2023-12-03
### Fixed
- Module active checks should always be true on WordPress.com simple sites. [#34248]
## [2.0.1] - 2023-11-21
### Changed
- Added a note of non-usage of PHP8+ functions yet. [#34137]
- Replaced usage of substr() with str_starts_with() and str_ends_with(). [#34207]
## [2.0.0] - 2023-11-20
### Changed
- Updated required PHP version to >= 7.0. [#34192]
## [1.19.0] - 2023-11-13
### Added
- Added Host::get_source_query() to return the 'source' query param from the current URL. [#33984]
## [1.18.5] - 2023-09-25
### Changed
- Add 127.0.0.1 into the list of known local domains. [#32898]
- WP.com Compatibility: Abort out early checking if Protect is active. WP.com's protection is not site option based. [#33196]
## [1.18.4] - 2023-09-19
- Minor internal updates.
## [1.18.3] - 2023-09-11
### Changed
- General: remove backwards-compatibility function checks now that the package supports WP 6.2. [#32772]
## [1.18.2] - 2023-09-04
### Fixed
- Exclude domains starting with live from known Pantheon staging domains [#32789]
## [1.18.1] - 2023-08-23
### Changed
- Updated package dependencies. [#32605]
## [1.18.0] - 2023-07-18
### Added
- Transferred 'get_calypso_env()' method from Jetpack plugin. [#31906]
## [1.17.2] - 2023-06-19
### Changed
- Use Plans package to detect feature support. [#31213]
## [1.17.1] - 2023-05-11
### Changed
- PHP 8.1 compatibility updates [#30517]
## [1.17.0] - 2023-04-17
### Changed
- When Jetpack is available, `Modules::get()` no longer translates `module_tags`. Use Jetpack's `jetpack_get_module_i18n_tag()` function if you need translations. [#30067]
## [1.16.4] - 2023-04-10
### Added
- Add Jetpack Autoloader package suggestion. [#29988]
## [1.16.3] - 2023-03-28
### Changed
- Move brute force protection into WAF package. [#28401]
## [1.16.2] - 2023-02-20
### Changed
- Minor internal updates.
## [1.16.1] - 2023-01-23
### Added
- Add new filters for the latest status methods [#28328]
## [1.16.0] - 2023-01-16
### Added
- Add 2 new methods to detect whether a site is private or not. [#28322]
## [1.15.4] - 2023-01-11
### Changed
- Modules: Allow for deactivating multiple plugins when activating a module. [#28181]
## [1.15.3] - 2022-12-19
### Changed
- Updated package dependencies.
## [1.15.2] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
## [1.15.1] - 2022-11-22
### Changed
- Updated package dependencies. [#27043]
## [1.15.0] - 2022-11-07
### Added
- WordPress.com: add checks for Simple or either Simple/WoA. [#27278]
## [1.14.3] - 2022-07-26
### Changed
- Updated package dependencies. [#25158]
## [1.14.2] - 2022-07-19
### Changed
- Update logic in `is_woa_site` function for host changes [#25067]
## [1.14.1] - 2022-06-21
### Changed
- Renaming master to trunk.
## [1.14.0] - 2022-06-14
### Fixed
- Moved the connection_url_redirect action handling to the connection package. [#24529]
## [1.13.6] - 2022-05-24
### Added
- Allow plugins to filter the list of available modules. Only activate and consider active modules that are available [#24454]
## [1.13.5] - 2022-05-20
### Changed
- Modules: Make activate() method Jetpack plugin agnostic. Allowing standalone plugins to use it without Jetpack.
## [1.13.4] - 2022-05-19
### Added
- PHPCS updates. [#24418]
## [1.13.3] - 2022-05-10
## [1.13.2] - 2022-04-26
### Changed
- Updated package dependencies.
## [1.13.1] - 2022-04-19
### Changed
- PHPCS: Fix `WordPress.Security.ValidatedSanitizedInput`
## [1.13.0] - 2022-04-05
### Added
- Created Modules and File modules for managing those resources
## [1.12.0] - 2022-03-02
### Added
- Cache return values (per blog) from various status methods.
## [1.11.2] - 2022-02-28
### Fixed
- Re-doing 1.11.1 to fixup a bad release.
## [1.11.1] - 2022-02-28
### Fixed
- Remove trailing semicolor form site suffix.
## [1.11.0] - 2022-02-22
### Added
- Add methods to distinguish Newspack and VIP sites.
## [1.10.0] - 2022-01-25
### Added
- Added Visitor class for status regarding the site visitor.
## [1.9.5] - 2022-01-04
### Changed
- Switch to pcov for code coverage.
- Updated package dependencies
## [1.9.4] - 2021-12-14
### Changed
- Updated package dependencies.
## [1.9.3] - 2021-11-22
### Changed
- Updated package dependencies
## [1.9.2] - 2021-11-16
### Changed
- Add a function_exists check before calling wp_get_environment_type
## [1.9.1] - 2021-11-02
### Changed
- Set `convertDeprecationsToExceptions` true in PHPUnit config.
- Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't.
## [1.9.0] - 2021-10-26
### Added
- Added Host class for reporting known hosting environment information.
## [1.8.4] - 2021-10-13
### Changed
- Updated package dependencies.
## [1.8.3] - 2021-10-12
### Changed
- Updated package dependencies
## [1.8.2] - 2021-09-28
### Changed
- Updated package dependencies.
## [1.8.1] - 2021-08-30
### Changed
- Run composer update on test-php command instead of phpunit
- Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills).
- update annotations versions
## [1.8.0] - 2021-06-15
### Changed
- Update callback to Jetpack to new Identity_Crisis class.
## [1.7.6] - 2021-05-25
### Changed
- Updated package dependencies.
## [1.7.5] - 2021-04-27
### Deprecated
- Deprecates is_no_user_testing_mode
## [1.7.4] - 2021-04-08
### Changed
- Packaging and build changes, no change to the package itself.
## [1.7.3] - 2021-03-30
### Added
- Composer alias for dev-master, to improve dependencies
### Changed
- Update package dependencies.
### Fixed
- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in.
## [1.7.2] - 2021-02-05
- CI: Make tests more generic
## [1.7.1] - 2021-01-20
- Add mirror-repo information to all current composer packages
- Monorepo: Reorganize all projects
## [1.7.0] - 2020-12-14
- Update dependency brain/monkey to v2.6.0
- Pin dependencies
- Packages: Update for PHP 8 testing
## [1.6.0] - 2020-11-23
- Status: Introduce get_site_suffix method
- Status: Fix test failure
- Status: Improve the staging site detection
- General: update minimum required version to WordPress 5.5
- Add the no_user_testing mode
- Status: Add a couple of test cases for staging site detection
- Update dependency brain/monkey to v2.5.0
- Updated PHPCS: Packages and Debugger
## [1.5.0] - 2020-10-13
- Also use Core `wp_get_environment_type` for local
## [1.4.0] - 2020-08-13
- CI: Try collect js coverage
## [1.3.0] - 2020-07-28
- Core Compat: Site Environment
## [1.2.0] - 2020-06-22
- PHPCS: Clean up the packages
- Staging Sites: add newspack staging to the list of known providers
## [1.1.1] - 2020-01-27
- Pin dependency brain/monkey to 2.4.0
## [1.1.0] - 2020-01-14
- Packages: Various improvements for wp.com or self-contained consumers
## [1.0.4] - 2019-11-08
- Packages: Use classmap instead of PSR-4
## [1.0.3] - 2019-10-28
- Packages: Add gitattributes files to all packages that need th…
## [1.0.2] - 2019-10-23
- Use spread operator instead of func_get_args
## [1.0.1] - 2019-09-20
- Docs: Unify usage of @package phpdoc tags
## 1.0.0 - 2019-09-14
- Packages: Introduce a status package
[6.1.8]: https://github.com/Automattic/jetpack-status/compare/v6.1.7...v6.1.8
[6.1.7]: https://github.com/Automattic/jetpack-status/compare/v6.1.6...v6.1.7
[6.1.6]: https://github.com/Automattic/jetpack-status/compare/v6.1.5...v6.1.6
[6.1.5]: https://github.com/Automattic/jetpack-status/compare/v6.1.4...v6.1.5
[6.1.4]: https://github.com/Automattic/jetpack-status/compare/v6.1.3...v6.1.4
[6.1.3]: https://github.com/Automattic/jetpack-status/compare/v6.1.2...v6.1.3
[6.1.2]: https://github.com/Automattic/jetpack-status/compare/v6.1.1...v6.1.2
[6.1.1]: https://github.com/Automattic/jetpack-status/compare/v6.1.0...v6.1.1
[6.1.0]: https://github.com/Automattic/jetpack-status/compare/v6.0.4...v6.1.0
[6.0.4]: https://github.com/Automattic/jetpack-status/compare/v6.0.3...v6.0.4
[6.0.3]: https://github.com/Automattic/jetpack-status/compare/v6.0.2...v6.0.3
[6.0.2]: https://github.com/Automattic/jetpack-status/compare/v6.0.1...v6.0.2
[6.0.1]: https://github.com/Automattic/jetpack-status/compare/v6.0.0...v6.0.1
[6.0.0]: https://github.com/Automattic/jetpack-status/compare/v5.4.0...v6.0.0
[5.4.0]: https://github.com/Automattic/jetpack-status/compare/v5.3.1...v5.4.0
[5.3.1]: https://github.com/Automattic/jetpack-status/compare/v5.3.0...v5.3.1
[5.3.0]: https://github.com/Automattic/jetpack-status/compare/v5.2.1...v5.3.0
[5.2.1]: https://github.com/Automattic/jetpack-status/compare/v5.2.0...v5.2.1
[5.2.0]: https://github.com/Automattic/jetpack-status/compare/v5.1.4...v5.2.0
[5.1.4]: https://github.com/Automattic/jetpack-status/compare/v5.1.3...v5.1.4
[5.1.3]: https://github.com/Automattic/jetpack-status/compare/v5.1.2...v5.1.3
[5.1.2]: https://github.com/Automattic/jetpack-status/compare/v5.1.1...v5.1.2
[5.1.1]: https://github.com/Automattic/jetpack-status/compare/v5.1.0...v5.1.1
[5.1.0]: https://github.com/Automattic/jetpack-status/compare/v5.0.10...v5.1.0
[5.0.10]: https://github.com/Automattic/jetpack-status/compare/v5.0.9...v5.0.10
[5.0.9]: https://github.com/Automattic/jetpack-status/compare/v5.0.8...v5.0.9
[5.0.8]: https://github.com/Automattic/jetpack-status/compare/v5.0.7...v5.0.8
[5.0.7]: https://github.com/Automattic/jetpack-status/compare/v5.0.6...v5.0.7
[5.0.6]: https://github.com/Automattic/jetpack-status/compare/v5.0.5...v5.0.6
[5.0.5]: https://github.com/Automattic/jetpack-status/compare/v5.0.4...v5.0.5
[5.0.4]: https://github.com/Automattic/jetpack-status/compare/v5.0.3...v5.0.4
[5.0.3]: https://github.com/Automattic/jetpack-status/compare/v5.0.2...v5.0.3
[5.0.2]: https://github.com/Automattic/jetpack-status/compare/v5.0.1...v5.0.2
[5.0.1]: https://github.com/Automattic/jetpack-status/compare/v5.0.0...v5.0.1
[5.0.0]: https://github.com/Automattic/jetpack-status/compare/v4.0.3...v5.0.0
[4.0.3]: https://github.com/Automattic/jetpack-status/compare/v4.0.2...v4.0.3
[4.0.2]: https://github.com/Automattic/jetpack-status/compare/v4.0.1...v4.0.2
[4.0.1]: https://github.com/Automattic/jetpack-status/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/Automattic/jetpack-status/compare/v3.3.4...v4.0.0
[3.3.4]: https://github.com/Automattic/jetpack-status/compare/v3.3.3...v3.3.4
[3.3.3]: https://github.com/Automattic/jetpack-status/compare/v3.3.2...v3.3.3
[3.3.2]: https://github.com/Automattic/jetpack-status/compare/v3.3.1...v3.3.2
[3.3.1]: https://github.com/Automattic/jetpack-status/compare/v3.3.0...v3.3.1
[3.3.0]: https://github.com/Automattic/jetpack-status/compare/v3.2.3...v3.3.0
[3.2.3]: https://github.com/Automattic/jetpack-status/compare/v3.2.2...v3.2.3
[3.2.2]: https://github.com/Automattic/jetpack-status/compare/v3.2.1...v3.2.2
[3.2.1]: https://github.com/Automattic/jetpack-status/compare/v3.2.0...v3.2.1
[3.2.0]: https://github.com/Automattic/jetpack-status/compare/v3.1.0...v3.2.0
[3.1.0]: https://github.com/Automattic/jetpack-status/compare/v3.0.3...v3.1.0
[3.0.3]: https://github.com/Automattic/jetpack-status/compare/v3.0.2...v3.0.3
[3.0.2]: https://github.com/Automattic/jetpack-status/compare/v3.0.1...v3.0.2
[3.0.1]: https://github.com/Automattic/jetpack-status/compare/v3.0.0...v3.0.1
[3.0.0]: https://github.com/Automattic/jetpack-status/compare/v2.2.2...v3.0.0
[2.2.2]: https://github.com/Automattic/jetpack-status/compare/v2.2.1...v2.2.2
[2.2.1]: https://github.com/Automattic/jetpack-status/compare/v2.2.0...v2.2.1
[2.2.0]: https://github.com/Automattic/jetpack-status/compare/v2.1.3...v2.2.0
[2.1.3]: https://github.com/Automattic/jetpack-status/compare/v2.1.2...v2.1.3
[2.1.2]: https://github.com/Automattic/jetpack-status/compare/v2.1.1...v2.1.2
[2.1.1]: https://github.com/Automattic/jetpack-status/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/Automattic/jetpack-status/compare/v2.0.2...v2.1.0
[2.0.2]: https://github.com/Automattic/jetpack-status/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/Automattic/jetpack-status/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Automattic/jetpack-status/compare/v1.19.0...v2.0.0
[1.19.0]: https://github.com/Automattic/jetpack-status/compare/v1.18.5...v1.19.0
[1.18.5]: https://github.com/Automattic/jetpack-status/compare/v1.18.4...v1.18.5
[1.18.4]: https://github.com/Automattic/jetpack-status/compare/v1.18.3...v1.18.4
[1.18.3]: https://github.com/Automattic/jetpack-status/compare/v1.18.2...v1.18.3
[1.18.2]: https://github.com/Automattic/jetpack-status/compare/v1.18.1...v1.18.2
[1.18.1]: https://github.com/Automattic/jetpack-status/compare/v1.18.0...v1.18.1
[1.18.0]: https://github.com/Automattic/jetpack-status/compare/v1.17.2...v1.18.0
[1.17.2]: https://github.com/Automattic/jetpack-status/compare/v1.17.1...v1.17.2
[1.17.1]: https://github.com/Automattic/jetpack-status/compare/v1.17.0...v1.17.1
[1.17.0]: https://github.com/Automattic/jetpack-status/compare/v1.16.4...v1.17.0
[1.16.4]: https://github.com/Automattic/jetpack-status/compare/v1.16.3...v1.16.4
[1.16.3]: https://github.com/Automattic/jetpack-status/compare/v1.16.2...v1.16.3
[1.16.2]: https://github.com/Automattic/jetpack-status/compare/v1.16.1...v1.16.2
[1.16.1]: https://github.com/Automattic/jetpack-status/compare/v1.16.0...v1.16.1
[1.16.0]: https://github.com/Automattic/jetpack-status/compare/v1.15.4...v1.16.0
[1.15.4]: https://github.com/Automattic/jetpack-status/compare/v1.15.3...v1.15.4
[1.15.3]: https://github.com/Automattic/jetpack-status/compare/v1.15.2...v1.15.3
[1.15.2]: https://github.com/Automattic/jetpack-status/compare/v1.15.1...v1.15.2
[1.15.1]: https://github.com/Automattic/jetpack-status/compare/v1.15.0...v1.15.1
[1.15.0]: https://github.com/Automattic/jetpack-status/compare/v1.14.3...v1.15.0
[1.14.3]: https://github.com/Automattic/jetpack-status/compare/v1.14.2...v1.14.3
[1.14.2]: https://github.com/Automattic/jetpack-status/compare/v1.14.1...v1.14.2
[1.14.1]: https://github.com/Automattic/jetpack-status/compare/v1.14.0...v1.14.1
[1.14.0]: https://github.com/Automattic/jetpack-status/compare/v1.13.6...v1.14.0
[1.13.6]: https://github.com/Automattic/jetpack-status/compare/v1.13.5...v1.13.6
[1.13.5]: https://github.com/Automattic/jetpack-status/compare/v1.13.4...v1.13.5
[1.13.4]: https://github.com/Automattic/jetpack-status/compare/v1.13.3...v1.13.4
[1.13.3]: https://github.com/Automattic/jetpack-status/compare/v1.13.2...v1.13.3
[1.13.2]: https://github.com/Automattic/jetpack-status/compare/v1.13.1...v1.13.2
[1.13.1]: https://github.com/Automattic/jetpack-status/compare/v1.13.0...v1.13.1
[1.13.0]: https://github.com/Automattic/jetpack-status/compare/v1.12.0...v1.13.0
[1.12.0]: https://github.com/Automattic/jetpack-status/compare/v1.11.2...v1.12.0
[1.11.2]: https://github.com/Automattic/jetpack-status/compare/v1.11.1...v1.11.2
[1.11.1]: https://github.com/Automattic/jetpack-status/compare/v1.11.0...v1.11.1
[1.11.0]: https://github.com/Automattic/jetpack-status/compare/v1.10.0...v1.11.0
[1.10.0]: https://github.com/Automattic/jetpack-status/compare/v1.9.5...v1.10.0
[1.9.5]: https://github.com/Automattic/jetpack-status/compare/v1.9.4...v1.9.5
[1.9.4]: https://github.com/Automattic/jetpack-status/compare/v1.9.3...v1.9.4
[1.9.3]: https://github.com/Automattic/jetpack-status/compare/v1.9.2...v1.9.3
[1.9.2]: https://github.com/Automattic/jetpack-status/compare/v1.9.1...v1.9.2
[1.9.1]: https://github.com/Automattic/jetpack-status/compare/v1.9.0...v1.9.1
[1.9.0]: https://github.com/Automattic/jetpack-status/compare/v1.8.4...v1.9.0
[1.8.4]: https://github.com/Automattic/jetpack-status/compare/v1.8.3...v1.8.4
[1.8.3]: https://github.com/Automattic/jetpack-status/compare/v1.8.2...v1.8.3
[1.8.2]: https://github.com/Automattic/jetpack-status/compare/v1.8.1...v1.8.2
[1.8.1]: https://github.com/Automattic/jetpack-status/compare/v1.8.0...v1.8.1
[1.8.0]: https://github.com/Automattic/jetpack-status/compare/v1.7.6...v1.8.0
[1.7.6]: https://github.com/Automattic/jetpack-status/compare/v1.7.5...v1.7.6
[1.7.5]: https://github.com/Automattic/jetpack-status/compare/v1.7.4...v1.7.5
[1.7.4]: https://github.com/Automattic/jetpack-status/compare/v1.7.3...v1.7.4
[1.7.3]: https://github.com/Automattic/jetpack-status/compare/v1.7.2...v1.7.3
[1.7.2]: https://github.com/Automattic/jetpack-status/compare/v1.7.1...v1.7.2
[1.7.1]: https://github.com/Automattic/jetpack-status/compare/v1.7.0...v1.7.1
[1.7.0]: https://github.com/Automattic/jetpack-status/compare/v1.6.0...v1.7.0
[1.6.0]: https://github.com/Automattic/jetpack-status/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/Automattic/jetpack-status/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/Automattic/jetpack-status/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/Automattic/jetpack-status/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/Automattic/jetpack-status/compare/v1.1.1...v1.2.0
[1.1.1]: https://github.com/Automattic/jetpack-status/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/Automattic/jetpack-status/compare/v1.0.4...v1.1.0
[1.0.4]: https://github.com/Automattic/jetpack-status/compare/v1.0.3...v1.0.4
[1.0.3]: https://github.com/Automattic/jetpack-status/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/Automattic/jetpack-status/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/Automattic/jetpack-status/compare/v1.0.0...v1.0.1
@@ -0,0 +1,54 @@
<?php
/**
* A static in-process cache for blog data.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack\Status;
/**
* A static in-process cache for blog data.
*
* For internal use only. Do not use this externally.
*/
class Cache {
/**
* Cached data;
*
* @var array[]
*/
private static $cache = array();
/**
* Get a value from the cache.
*
* @param string $key Key to fetch.
* @param mixed $default Default value to return if the key is not set.
* @return mixed Data.
*/
public static function get( $key, $default = null ) {
$blog_id = get_current_blog_id();
return isset( self::$cache[ $blog_id ] ) && array_key_exists( $key, self::$cache[ $blog_id ] ) ? self::$cache[ $blog_id ][ $key ] : $default;
}
/**
* Set a value in the cache.
*
* @param string $key Key to set.
* @param mixed $value Value to store.
*/
public static function set( $key, $value ) {
$blog_id = get_current_blog_id();
self::$cache[ $blog_id ][ $key ] = $value;
}
/**
* Clear the cache.
*
* This is intended for use in unit tests.
*/
public static function clear() {
self::$cache = array();
}
}
@@ -0,0 +1,101 @@
<?php
/**
* Pass state to subsequent requests via cookies.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack;
/**
* Class Automattic\Jetpack\Status
*
* Used to retrieve information about the current status of Jetpack and the site overall.
*/
class CookieState {
/**
* State is passed via cookies from one request to the next, but never to subsequent requests.
* SET: state( $key, $value );
* GET: $value = state( $key );
*
* @param string $key State key.
* @param string $value Value.
* @param bool $restate Reset the cookie (private).
*/
public function state( $key = null, $value = null, $restate = false ) {
static $state = array();
static $path, $domain; // this initializes values to null
if ( ! isset( $path ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$admin_url = ( new Paths() )->admin_url();
$bits = wp_parse_url( $admin_url );
if ( is_array( $bits ) ) {
$path = ( isset( $bits['path'] ) ) ? dirname( $bits['path'] ) : null;
$domain = $bits['host'] ?? null;
}
}
// Extract state from cookies and delete cookies.
if ( isset( $_COOKIE['jetpackState'] ) && is_array( $_COOKIE['jetpackState'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- User should sanitize if necessary.
$yum = wp_unslash( $_COOKIE['jetpackState'] );
unset( $_COOKIE['jetpackState'] );
foreach ( $yum as $k => $v ) {
if ( strlen( $v ) ) {
$state[ $k ] = $v;
}
// @phan-suppress-next-line PhanTypeMismatchArgumentInternal -- Setting cookie to false is valid and documented for deletion.
setcookie( "jetpackState[$k]", false, 0, $path, $domain, is_ssl(), true );
}
}
if ( $restate ) {
foreach ( $state as $k => $v ) {
setcookie( "jetpackState[$k]", $v, 0, $path, $domain, is_ssl(), true );
}
return;
}
// Get a state variable.
if ( isset( $key ) && ! isset( $value ) ) {
if ( array_key_exists( $key, $state ) ) {
return $state[ $key ];
}
return null;
}
// Set a state variable.
if ( isset( $key ) && isset( $value ) ) {
if ( is_array( $value ) && isset( $value[0] ) ) {
$value = $value[0];
}
$state[ $key ] = $value;
if ( ! headers_sent() ) {
if ( $this->should_set_cookie( $key ) ) {
setcookie( "jetpackState[$key]", $value, 0, $path, $domain, is_ssl(), true );
}
}
}
}
/**
* Determines whether the jetpackState[$key] value should be added to the
* cookie.
*
* @param string $key The state key.
*
* @return boolean Whether the value should be added to the cookie.
*/
public function should_set_cookie( $key ) {
global $current_screen;
$page = $current_screen->base ?? null;
if ( 'toplevel_page_jetpack' === $page && 'display_update_modal' === $key ) {
return false;
}
return true;
}
}
@@ -0,0 +1,51 @@
<?php
/**
* An errors utility class for Jetpack.
*
* @package automattic/jetpack-status
*/
// phpcs:disable WordPress.PHP.IniSet.display_errors_Disallowed
// phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
// phpcs:disable WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
namespace Automattic\Jetpack;
/**
* Erros class.
*
* @deprecated since 3.2.0
*/
class Errors {
/**
* Catches PHP errors. Must be used in conjunction with output buffering.
*
* @deprecated since 3.2.0
* @param bool $catch True to start catching, False to stop.
*
* @static
*/
public function catch_errors( $catch ) {
_deprecated_function( __METHOD__, '3.2.0' );
static $display_errors, $error_reporting;
if ( $catch ) {
// Force error reporting and output, store original values.
$display_errors = @ini_set( 'display_errors', 1 );
$error_reporting = @error_reporting( E_ALL );
if ( class_exists( 'Jetpack' ) ) {
add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 );
}
} else {
// Restore the original values for error reporting and output.
@ini_set( 'display_errors', $display_errors );
if ( $error_reporting !== null ) {
@error_reporting( $error_reporting );
}
if ( class_exists( 'Jetpack' ) ) {
remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 );
}
}
}
}
@@ -0,0 +1,54 @@
<?php
/**
* A modules class for Jetpack.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack;
/**
* Class Automattic\Jetpack\Files
*
* Used to retrieve information about files.
*/
class Files {
/**
* Returns an array of all PHP files in the specified absolute path.
* Equivalent to glob( "$absolute_path/*.php" ).
*
* @param string $absolute_path The absolute path of the directory to search.
* @return array Array of absolute paths to the PHP files.
*/
public function glob_php( $absolute_path ) {
if ( function_exists( 'glob' ) ) {
return glob( "$absolute_path/*.php" );
}
$absolute_path = untrailingslashit( $absolute_path );
$files = array();
$dir = @opendir( $absolute_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
if ( ! $dir ) {
return $files;
}
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( false !== $file = readdir( $dir ) ) {
if ( str_starts_with( $file, '.' ) || ! str_ends_with( $file, '.php' ) ) {
continue;
}
$file = "$absolute_path/$file";
if ( ! is_file( $file ) ) {
continue;
}
$files[] = $file;
}
closedir( $dir );
return $files;
}
}
@@ -0,0 +1,216 @@
<?php
/**
* A hosting provide class for Jetpack.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack\Status;
use Automattic\Jetpack\Constants;
/**
* Hosting provider class.
*/
class Host {
/**
* Determine if this site is an WordPress.com on Atomic site or not by looking for presence of the wpcomsh plugin.
*
* @since 1.9.0
*
* @return bool
*/
public function is_woa_site() {
$ret = Cache::get( 'is_woa_site' );
if ( null === $ret ) {
$ret = $this->is_atomic_platform() && Constants::is_true( 'WPCOMSH__PLUGIN_FILE' );
Cache::set( 'is_woa_site', $ret );
}
return $ret;
}
/**
* Determine if the site is hosted on the Atomic hosting platform.
*
* @since 1.9.0
*
* @return bool
*/
public function is_atomic_platform() {
return Constants::is_true( 'ATOMIC_SITE_ID' ) && Constants::is_true( 'ATOMIC_CLIENT_ID' );
}
/**
* Determine if this is a Newspack site.
*
* @return bool
*/
public function is_newspack_site() {
return Constants::is_defined( 'NEWSPACK_PLUGIN_FILE' );
}
/**
* Determine if this is a VIP-hosted site.
*
* @return bool
*/
public function is_vip_site() {
return Constants::is_defined( 'WPCOM_IS_VIP_ENV' ) && true === Constants::get_constant( 'WPCOM_IS_VIP_ENV' );
}
/**
* Determine if this is a Simple platform site.
*
* @return bool
*/
public function is_wpcom_simple() {
return Constants::is_defined( 'IS_WPCOM' ) && true === Constants::get_constant( 'IS_WPCOM' );
}
/**
* Determine if this is a WordPress.com site.
*
* Includes both Simple and WoA platforms.
*
* @return bool
*/
public function is_wpcom_platform() {
return $this->is_wpcom_simple() || $this->is_woa_site();
}
/**
* Determine if this is a P2 site.
* This covers both P2 and P2020 themes.
*
* @return bool
*/
public function is_p2_site() {
$site_id = $this->get_wpcom_site_id();
if ( ! $site_id ) {
return false;
}
return str_contains( get_stylesheet(), 'pub/p2' ) || ( function_exists( '\WPForTeams\is_wpforteams_site' ) && \WPForTeams\is_wpforteams_site( $site_id ) );
}
/**
* Get the current site's WordPress.com ID.
*
* @return mixed The site's WordPress.com ID.
*/
public function get_wpcom_site_id() {
if ( $this->is_wpcom_simple() ) {
return get_current_blog_id();
} elseif ( class_exists( 'Jetpack' ) && \Jetpack::is_connection_ready() ) {
return \Jetpack_Options::get_option( 'id' );
}
return false;
}
/**
* Add all wordpress.com environments to the safe redirect allowed list.
*
* To be used with a filter of allowed domains for a redirect.
*
* @param array $domains Allowed WP.com Environments.
*/
public static function allow_wpcom_environments( $domains ) {
$domains[] = 'wordpress.com';
$domains[] = 'jetpack.wordpress.com';
$domains[] = 'wpcalypso.wordpress.com';
$domains[] = 'horizon.wordpress.com';
$domains[] = 'calypso.localhost';
return $domains;
}
/**
* Return Calypso environment value; used for developing Jetpack and pairing
* it with different Calypso environments, such as localhost.
*
* @since 1.18.0
*
* @return string Calypso environment
*/
public function get_calypso_env() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Nonce is not required; only used for changing environments.
if ( isset( $_GET['calypso_env'] ) ) {
return sanitize_key( $_GET['calypso_env'] );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
if ( getenv( 'CALYPSO_ENV' ) ) {
return sanitize_key( getenv( 'CALYPSO_ENV' ) );
}
if ( defined( 'CALYPSO_ENV' ) && CALYPSO_ENV ) {
return sanitize_key( CALYPSO_ENV );
}
return '';
}
/**
* Return source query param value from the URL if exists in the allowed sources list.
*
* @return string "source" query param value
*/
public function get_source_query() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$allowed_sources = array( 'jetpack-manage', 'a8c-for-agencies' );
if ( isset( $_GET['source'] ) && in_array( $_GET['source'], $allowed_sources, true ) ) {
return sanitize_key( $_GET['source'] );
}
return '';
}
/**
* Returns a guess of the hosting provider for the current site based on various checks.
*
* @since 5.0.4 Added $guess parameter.
* @since 6.0.0 Removed $guess parameter.
*
* @return string
*/
public function get_known_host_guess() {
// First, let's check if we can recognize provider manually:
switch ( true ) {
case $this->is_woa_site():
$provider = 'woa';
break;
case $this->is_atomic_platform():
$provider = 'atomic';
break;
case $this->is_newspack_site():
$provider = 'newspack';
break;
case $this->is_vip_site():
$provider = 'vip';
break;
case $this->is_wpcom_simple():
case $this->is_wpcom_platform():
$provider = 'wpcom';
break;
default:
$provider = 'unknown';
break;
}
return $provider;
}
/**
* Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access.
*
* @since 3.0.2 Ported from Jetpack to the Status package.
*
* To be used with a filter of allowed domains for a redirect.
*
* @param array $domains Allowed WP.com Environments.
*
* @return array
*/
public static function allow_wpcom_public_api_domain( $domains ) {
$domains[] = 'public-api.wordpress.com';
return $domains;
}
}
@@ -0,0 +1,609 @@
<?php
/**
* A modules class for Jetpack.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\IP\Utils as IP_Utils;
use Automattic\Jetpack\Status\Host;
/**
* Class Automattic\Jetpack\Modules
*
* Used to retrieve information about the current status of Jetpack modules.
*/
class Modules {
/**
* Check whether or not a Jetpack module is active.
*
* @param string $module The slug of a Jetpack module.
* @param bool $available_only Whether to only check among available modules.
*
* @return bool
*/
public function is_active( $module, $available_only = true ) {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
return true;
}
return in_array( $module, self::get_active( $available_only ), true );
}
/**
* Load module data from module file. Headers differ from WordPress
* plugin headers to avoid them being identified as standalone
* plugins on the WordPress plugins page.
*
* @param string $module The module slug.
*/
public function get( $module ) {
static $modules_details;
// This method relies heavy on auto-generated file found in Jetpack only: module-headings.php
// If it doesn't exist, it's safe to assume none of this will be helpful.
if ( ! function_exists( 'jetpack_has_no_module_info' ) ) {
return false;
}
if ( jetpack_has_no_module_info( $module ) ) {
return false;
}
$file = $this->get_path( $this->get_slug( $module ) );
if ( isset( $modules_details[ $module ] ) ) {
$mod = $modules_details[ $module ];
} else {
$mod = jetpack_get_module_info( $module );
if ( null === $mod ) {
// Try to get the module info from the file as a fallback.
$mod = $this->get_file_data( $file, jetpack_get_all_module_header_names() );
if ( empty( $mod['name'] ) ) {
// No info for this module.
return false;
}
}
$mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort'];
$mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order'];
$mod['deactivate'] = empty( $mod['deactivate'] );
$mod['free'] = empty( $mod['free'] );
$mod['requires_connection'] = empty( $mod['requires_connection'] ) || 'No' !== $mod['requires_connection'];
$mod['requires_user_connection'] = ! ( empty( $mod['requires_user_connection'] ) || 'No' === $mod['requires_user_connection'] );
if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ), true ) ) {
$mod['auto_activate'] = 'No';
} else {
$mod['auto_activate'] = (string) $mod['auto_activate'];
}
if ( $mod['module_tags'] ) {
$mod['module_tags'] = explode( ',', $mod['module_tags'] );
$mod['module_tags'] = array_map( 'trim', $mod['module_tags'] );
} else {
$mod['module_tags'] = array( 'Other' );
}
if ( $mod['plan_classes'] ) {
$mod['plan_classes'] = explode( ',', $mod['plan_classes'] );
$mod['plan_classes'] = array_map( 'strtolower', array_map( 'trim', $mod['plan_classes'] ) );
} else {
$mod['plan_classes'] = array( 'free' );
}
if ( $mod['feature'] ) {
$mod['feature'] = explode( ',', $mod['feature'] );
$mod['feature'] = array_map( 'trim', $mod['feature'] );
} else {
$mod['feature'] = array( 'Other' );
}
$modules_details[ $module ] = $mod;
}
/**
* Filters the feature array on a module.
*
* This filter allows you to control where each module is filtered: Recommended,
* and the default "Other" listing.
*
* @since-jetpack 3.5.0
*
* @param array $mod['feature'] The areas to feature this module:
* 'Recommended' shows on the main Jetpack admin screen.
* 'Other' should be the default if no other value is in the array.
* @param string $module The slug of the module, e.g. sharedaddy.
* @param array $mod All the currently assembled module data.
*/
$mod['feature'] = apply_filters( 'jetpack_module_feature', $mod['feature'], $module, $mod );
/**
* Filter the returned data about a module.
*
* This filter allows overriding any info about Jetpack modules. It is dangerous,
* so please be careful.
*
* @since-jetpack 3.6.0
*
* @param array $mod The details of the requested module.
* @param string $module The slug of the module, e.g. sharedaddy
* @param string $file The path to the module source file.
*/
return apply_filters( 'jetpack_get_module', $mod, $module, $file );
}
/**
* Like core's get_file_data implementation, but caches the result.
*
* @param string $file Absolute path to the file.
* @param array $headers List of headers, in the format array( 'HeaderKey' => 'Header Name' ).
*/
public function get_file_data( $file, $headers ) {
// Get just the filename from $file (i.e. exclude full path) so that a consistent hash is generated.
$file_name = basename( $file );
if ( ! Constants::is_defined( 'JETPACK__VERSION' ) ) {
return get_file_data( $file, $headers );
}
$cache_key = 'jetpack_file_data_' . JETPACK__VERSION;
$file_data_option = get_transient( $cache_key );
if ( ! is_array( $file_data_option ) ) {
delete_transient( $cache_key );
$file_data_option = false;
}
if ( false === $file_data_option ) {
$file_data_option = array();
}
$key = md5( $file_name . maybe_serialize( $headers ) );
$refresh_cache = is_admin() && isset( $_GET['page'] ) && is_string( $_GET['page'] ) && str_starts_with( $_GET['page'], 'jetpack' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
// If we don't need to refresh the cache, and already have the value, short-circuit!
if ( ! $refresh_cache && isset( $file_data_option[ $key ] ) ) {
return $file_data_option[ $key ];
}
$data = get_file_data( $file, $headers );
$file_data_option[ $key ] = $data;
set_transient( $cache_key, $file_data_option, 29 * DAY_IN_SECONDS );
return $data;
}
/**
* Get a list of activated modules as an array of module slugs.
*
* @param bool $available_only Filter out the unavailable (deleted) modules.
*
* @return array
*/
public function get_active( $available_only = true ) {
$active = \Jetpack_Options::get_option( 'active_modules' );
if ( ! is_array( $active ) ) {
$active = array();
}
if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) {
$active[] = 'vaultpress';
} else {
$active = array_diff( $active, array( 'vaultpress' ) );
}
// If protect is active on the main site of a multisite, it should be active on all sites. Doesn't apply to WP.com.
if ( ! in_array( 'protect', $active, true )
&& ! ( new Host() )->is_wpcom_simple()
&& is_multisite()
&& get_site_option( 'jetpack_protect_active' ) ) {
$active[] = 'protect';
}
if ( $available_only ) {
// If it's not available, it shouldn't be active.
// We don't delete it from the options though, as it will be active again when a plugin gets reactivated.
$active = array_intersect( $active, $this->get_available() );
}
/**
* Allow filtering of the active modules.
*
* Gives theme and plugin developers the power to alter the modules that
* are activated on the fly.
*
* @since-jetpack 5.8.0
*
* @param array $active Array of active module slugs.
*/
$active = apply_filters( 'jetpack_active_modules', $active );
return array_unique( $active );
}
/**
* Extract a module's slug from its full path.
*
* @param string $file Full path to a file.
*
* @return string Module slug.
*/
public function get_slug( $file ) {
return str_replace( '.php', '', basename( $file ) );
}
/**
* List available Jetpack modules. Simply lists .php files in /modules/.
* Make sure to tuck away module "library" files in a sub-directory.
*
* @param bool|string $min_version Only return modules introduced in this version or later. Default is false, do not filter.
* @param bool|string $max_version Only return modules introduced before this version. Default is false, do not filter.
* @param bool|null $requires_connection Pass a boolean value to only return modules that require (or do not require) a connection.
* @param bool|null $requires_user_connection Pass a boolean value to only return modules that require (or do not require) a user connection.
*
* @return array $modules Array of module slugs
*/
public function get_available( $min_version = false, $max_version = false, $requires_connection = null, $requires_user_connection = null ) {
static $modules = null;
if ( ! class_exists( 'Jetpack' ) || ! Constants::is_defined( 'JETPACK__VERSION' ) || ! Constants::is_defined( 'JETPACK__PLUGIN_DIR' ) ) {
return array_unique(
/**
* Stand alone plugins need to use this filter to register the modules they interact with.
* This will allow them to activate and deactivate these modules even when Jetpack is not present.
* Note: Standalone plugins can only interact with modules that also exist in the Jetpack plugin, otherwise they'll lose the ability to control it if Jetpack is activated.
*
* @since 1.13.6
*
* @param array $modules The list of available modules as an array of slugs.
* @param bool $requires_connection Whether to list only modules that require a connection to work.
* @param bool $requires_user_connection Whether to list only modules that require a user connection to work.
*/
apply_filters( 'jetpack_get_available_standalone_modules', array(), $requires_connection, $requires_user_connection )
);
}
if ( ! isset( $modules ) ) {
$available_modules_option = \Jetpack_Options::get_option( 'available_modules', array() );
// Use the cache if we're on the front-end and it's available...
if ( ! is_admin() && ! empty( $available_modules_option[ JETPACK__VERSION ] ) ) {
$modules = $available_modules_option[ JETPACK__VERSION ];
} else {
$files = ( new Files() )->glob_php( JETPACK__PLUGIN_DIR . 'modules' );
$modules = array();
foreach ( $files as $file ) {
$slug = $this->get_slug( $file );
$headers = $this->get( $slug );
if ( ! $headers ) {
continue;
}
$modules[ $slug ] = $headers['introduced'];
}
\Jetpack_Options::update_option(
'available_modules',
array(
JETPACK__VERSION => $modules,
)
);
}
}
/**
* Filters the array of modules available to be activated.
*
* @since 2.4.0
*
* @param array $modules Array of available modules.
* @param string $min_version Minimum version number required to use modules.
* @param string $max_version Maximum version number required to use modules.
* @param bool|null $requires_connection Value of the Requires Connection filter.
* @param bool|null $requires_user_connection Value of the Requires User Connection filter.
*/
$mods = apply_filters( 'jetpack_get_available_modules', $modules, $min_version, $max_version, $requires_connection, $requires_user_connection );
if ( ! $min_version && ! $max_version && $requires_connection === null && $requires_user_connection === null ) {
return array_keys( $mods );
}
$r = array();
foreach ( $mods as $slug => $introduced ) {
if ( $min_version && version_compare( $min_version, $introduced, '>=' ) ) {
continue;
}
if ( $max_version && version_compare( $max_version, $introduced, '<' ) ) {
continue;
}
$mod_details = $this->get( $slug );
if ( null !== $requires_connection && (bool) $requires_connection !== $mod_details['requires_connection'] ) {
continue;
}
if ( null !== $requires_user_connection && (bool) $requires_user_connection !== $mod_details['requires_user_connection'] ) {
continue;
}
$r[] = $slug;
}
return $r;
}
/**
* Is slug a valid module.
*
* @param string $module Module slug.
*
* @return bool
*/
public function is_module( $module ) {
return ! empty( $module ) && ! validate_file( $module, $this->get_available() );
}
/**
* Update module status.
*
* @param string $module - module slug.
* @param boolean $active - true to activate, false to deactivate.
* @param bool $exit Should exit be called after deactivation.
* @param bool $redirect Should there be a redirection after activation.
*/
public function update_status( $module, $active, $exit = true, $redirect = true ) {
return $active ? $this->activate( $module, $exit, $redirect ) : $this->deactivate( $module );
}
/**
* Activate a module.
*
* @param string $module Module slug.
* @param bool $exit Should exit be called after deactivation.
* @param bool $redirect Should there be a redirection after activation.
*
* @return bool|void
*/
public function activate( $module, $exit = true, $redirect = true ) {
/**
* Fires before a module is activated.
*
* @since 2.6.0
*
* @param string $module Module slug.
* @param bool $exit Should we exit after the module has been activated. Default to true.
* @param bool $redirect Should the user be redirected after module activation? Default to true.
*/
do_action( 'jetpack_pre_activate_module', $module, $exit, $redirect );
if ( ! strlen( $module ) ) {
return false;
}
// If it's already active, then don't do it again.
$active = $this->get_active();
foreach ( $active as $act ) {
if ( $act === $module ) {
return true;
}
}
if ( ! $this->is_module( $module ) ) {
return false;
}
// Jetpack plugin only
if ( class_exists( 'Jetpack' ) ) {
$module_data = $this->get( $module );
$status = new Status();
$state = new CookieState();
if ( ! \Jetpack::is_connection_ready() ) {
if ( ! $status->is_offline_mode() ) {
return false;
}
// If we're not connected but in offline mode, make sure the module doesn't require a connection.
if ( $status->is_offline_mode() && $module_data['requires_connection'] ) {
return false;
}
}
if ( class_exists( 'Jetpack_Client_Server' ) ) {
$jetpack = \Jetpack::init();
// Check and see if the old plugin is active.
if ( isset( $jetpack->plugins_to_deactivate[ $module ] ) ) {
// Deactivate the old plugins.
$deactivated = array();
foreach ( $jetpack->plugins_to_deactivate[ $module ] as $idx => $deactivate_me ) {
if ( \Jetpack_Client_Server::deactivate_plugin( $deactivate_me[0], $deactivate_me[1] ) ) {
// If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module
// We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load.
$deactivated[] = "$module:$idx";
}
}
if ( $deactivated ) {
$state->state( 'deactivated_plugins', implode( ',', $deactivated ) );
wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) );
exit( 0 );
}
}
}
// Protect won't work with mis-configured IPs.
if ( 'protect' === $module ) {
if ( ! IP_Utils::get_ip() ) {
$state->state( 'message', 'protect_misconfigured_ip' );
return false;
}
}
if ( ! Jetpack_Plan::supports( $module ) ) {
return false;
}
// Check the file for fatal errors, a la wp-admin/plugins.php::activate.
$state->state( 'module', $module );
$state->state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error.
ob_start();
$module_path = $this->get_path( $module );
if ( file_exists( $module_path ) ) {
require_once $this->get_path( $module );
}
$active[] = $module;
$this->update_active( $active );
$state->state( 'error', false ); // the override.
ob_end_clean();
} else { // Not a Jetpack plugin.
$active[] = $module;
$this->update_active( $active );
}
if ( $redirect ) {
wp_safe_redirect( ( new Paths() )->admin_url( 'page=jetpack' ) );
}
if ( $exit ) {
exit( 0 );
}
return true;
}
/**
* Deactivate module.
*
* @param string $module Module slug.
*
* @return bool
*/
public function deactivate( $module ) {
/**
* Fires when a module is deactivated.
*
* @since 1.9.0
*
* @param string $module Module slug.
*/
do_action( 'jetpack_pre_deactivate_module', $module );
$active = $this->get_active();
$new = array_filter( array_diff( $active, (array) $module ) );
return $this->update_active( $new );
}
/**
* Generate a module's path from its slug.
*
* @param string $slug Module slug.
*/
public function get_path( $slug ) {
if ( ! Constants::is_defined( 'JETPACK__PLUGIN_DIR' ) ) {
return '';
}
/**
* Filters the path of a modules.
*
* @since 7.4.0
*
* @param array $return The absolute path to a module's root php file
* @param string $slug The module slug
*/
return apply_filters( 'jetpack_get_module_path', JETPACK__PLUGIN_DIR . "modules/$slug.php", $slug );
}
/**
* Saves all the currently active modules to options.
* Also fires Action hooks for each newly activated and deactivated module.
*
* @param array $modules Array of active modules to be saved in options.
*
* @return bool $success true for success, false for failure.
*/
public function update_active( $modules ) {
$current_modules = \Jetpack_Options::get_option( 'active_modules', array() );
$active_modules = $this->get_active();
$new_active_modules = array_diff( $modules, $current_modules );
$new_inactive_modules = array_diff( $active_modules, $modules );
$new_current_modules = array_diff( array_merge( $current_modules, $new_active_modules ), $new_inactive_modules );
$reindexed_modules = array_values( $new_current_modules );
$success = \Jetpack_Options::update_option( 'active_modules', array_unique( $reindexed_modules ) );
// Let's take `pre_update_option_jetpack_active_modules` filter into account
// and actually decide for which modules we need to fire hooks by comparing
// the 'active_modules' option before and after the update.
$current_modules_post_update = \Jetpack_Options::get_option( 'active_modules', array() );
$new_inactive_modules = array_diff( $current_modules, $current_modules_post_update );
$new_inactive_modules = array_unique( $new_inactive_modules );
$new_inactive_modules = array_values( $new_inactive_modules );
$new_active_modules = array_diff( $current_modules_post_update, $current_modules );
$new_active_modules = array_unique( $new_active_modules );
$new_active_modules = array_values( $new_active_modules );
foreach ( $new_active_modules as $module ) {
/**
* Fires when a specific module is activated.
*
* @since 1.9.0
*
* @param string $module Module slug.
* @param boolean $success whether the module was activated. @since 4.2
*/
do_action( 'jetpack_activate_module', $module, $success );
/**
* Fires when a module is activated.
* The dynamic part of the filter, $module, is the module slug.
*
* @since 1.9.0
*
* @param string $module Module slug.
*/
do_action( "jetpack_activate_module_$module", $module );
}
foreach ( $new_inactive_modules as $module ) {
/**
* Fired after a module has been deactivated.
*
* @since 4.2.0
*
* @param string $module Module slug.
* @param boolean $success whether the module was deactivated.
*/
do_action( 'jetpack_deactivate_module', $module, $success );
/**
* Fires when a module is deactivated.
* The dynamic part of the filter, $module, is the module slug.
*
* @since 1.9.0
*
* @param string $module Module slug.
*/
do_action( "jetpack_deactivate_module_$module", $module );
}
return $success;
}
}
@@ -0,0 +1,81 @@
<?php
/**
* A Path & URL utility class for Jetpack.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack;
/**
* Class Automattic\Jetpack\Paths
*
* Used to retrieve information about files.
*/
class Paths {
/**
* Jetpack Admin URL.
*
* @param array $args Query string args.
*
* @return string Jetpack admin URL.
*/
public function admin_url( $args = null ) {
$args = wp_parse_args( $args, array( 'page' => 'jetpack' ) );
$url = add_query_arg( $args, admin_url( 'admin.php' ) );
return $url;
}
/**
* Determine if the current request is activating a plugin from the plugins page.
*
* @param string $plugin Plugin file path to check.
* @return bool
*/
public function is_current_request_activating_plugin_from_plugins_screen( $plugin ) {
// Filter out common async request contexts
if (
wp_doing_ajax() ||
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
( defined( 'WP_CLI' ) && WP_CLI )
) {
return false;
}
if ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
$request_file = esc_url_raw( wp_unslash( $_SERVER['SCRIPT_NAME'] ) );
} elseif ( isset( $_SERVER['REQUEST_URI'] ) ) {
list( $request_file ) = explode( '?', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
} else {
return false;
}
// Not the plugins page
if ( strpos( $request_file, 'wp-admin/plugins.php' ) === false ) {
return false;
}
// Same method to get the action as used by plugins.php
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
$action = $wp_list_table->current_action();
// Not a singular activation
// This also means that if the plugin is activated as part of a group ( bulk activation ), this function will return false here.
if ( 'activate' !== $action ) {
return false;
}
// Check the nonce associated with the plugin activation
// We are not changing any data here, so this is not super necessary, it's just a best practice before using the form data from $_REQUEST.
check_admin_referer( 'activate-plugin_' . $plugin );
// Not the right plugin
$requested_plugin = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : null;
if ( $requested_plugin !== $plugin ) {
return false;
}
return true;
}
}
@@ -0,0 +1,112 @@
<?php
/**
* Get information about the current request.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack\Status;
use Automattic\Jetpack\Constants;
/**
* Get information about the current request.
*/
class Request {
/**
* Determine whether the current request is for accessing the frontend.
* Also update Vary headers to indicate that the response may vary by Accept header.
*
* @since 6.0.3 Added $send_vary_headers argument.
*
* @param bool $send_vary_headers Whether to send Vary headers.
*
* @return bool True if it's a frontend request, false otherwise.
*/
public static function is_frontend( $send_vary_headers = true ) {
$is_frontend = true;
$is_varying_request = true;
if (
is_admin()
|| wp_doing_ajax()
|| wp_is_jsonp_request()
|| is_feed()
|| Constants::is_true( 'REST_REQUEST' )
|| Constants::is_true( 'REST_API_REQUEST' )
|| Constants::is_true( 'WP_CLI' )
|| Constants::is_true( 'WPCOM_CLI_SCRIPT' ) // Special case for CLI scripts on WP.com that aren't using WP CLI.
) {
$is_frontend = false;
$is_varying_request = false;
} elseif (
wp_is_json_request()
|| wp_is_xml_request()
) {
$is_frontend = false;
}
/*
* Check existing headers for the request.
* If there is no existing Vary Accept header, add one.
*/
if ( $send_vary_headers && $is_varying_request && ! headers_sent() ) {
$headers = headers_list();
$vary_header_parts = self::get_vary_headers( $headers );
header( 'Vary: ' . implode( ', ', $vary_header_parts ) );
}
/**
* Filter whether the current request is for accessing the frontend.
*
* @since jetpack-9.0.0
* @since 6.0.3 Added $send_vary_headers argument.
*
* @param bool $is_frontend Whether the current request is for accessing the frontend.
* @param bool $send_vary_headers Whether to send Vary headers.
*/
return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend, $send_vary_headers );
}
/**
* Go through headers and get a list of Vary headers to add,
* including Vary on Accept and Content-Type if necessary.
*
* @since jetpack-12.2
*
* @param array $headers The headers to be sent.
*
* @return array $vary_header_parts Vary Headers to be sent.
*/
public static function get_vary_headers( $headers = array() ) {
$vary_header_parts = array( 'accept', 'content-type' );
foreach ( $headers as $header ) {
// Check for a Vary header.
if ( ! str_starts_with( strtolower( $header ), 'vary:' ) ) {
continue;
}
// If the header is a wildcard, we'll return that.
if ( str_contains( $header, '*' ) ) {
$vary_header_parts = array( '*' );
break;
}
// Remove the Vary: part of the header.
$header = preg_replace( '/^vary\:\s?/i', '', $header );
// Remove spaces from the header.
$header = str_replace( ' ', '', $header );
// Break the header into parts.
$header_parts = explode( ',', strtolower( $header ) );
// Build an array with the Accept header and what was already there.
$vary_header_parts = array_values( array_unique( array_merge( $vary_header_parts, $header_parts ) ) );
}
return $vary_header_parts;
}
}
@@ -0,0 +1,439 @@
<?php
/**
* A status class for Jetpack.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack;
use Automattic\Jetpack\Status\Cache;
use Automattic\Jetpack\Status\Host;
use WPCOM_Masterbar;
/**
* Class Automattic\Jetpack\Status
*
* Used to retrieve information about the current status of Jetpack and the site overall.
*/
class Status {
/**
* Is Jetpack in offline mode?
*
* This was formerly called "Development Mode", but sites "in development" aren't always offline/localhost.
*
* @since 1.3.0
*
* @return bool Whether Jetpack's offline mode is active.
*/
public function is_offline_mode() {
$cached = Cache::get( 'is_offline_mode' );
if ( null !== $cached ) {
return $cached;
}
$offline_mode = false;
if ( defined( '\\JETPACK_DEV_DEBUG' ) ) {
$offline_mode = constant( '\\JETPACK_DEV_DEBUG' );
} elseif ( defined( '\\WP_LOCAL_DEV' ) ) {
$offline_mode = constant( '\\WP_LOCAL_DEV' );
} elseif ( $this->is_local_site() ) {
$offline_mode = true;
}
/**
* Filters Jetpack's offline mode.
*
* @see https://jetpack.com/support/offline-mode/
*
* @since 1.3.0
*
* @param bool $offline_mode Is Jetpack's offline mode active.
*/
$offline_mode = (bool) apply_filters( 'jetpack_offline_mode', $offline_mode );
if ( ! $offline_mode ) {
$offline_mode = (bool) get_option( 'jetpack_offline_mode' );
}
Cache::set( 'is_offline_mode', $offline_mode );
return $offline_mode;
}
/**
* Whether this is a system with a multiple networks.
* Implemented since there is no core is_multi_network function.
* Right now there is no way to tell which network is the dominant network on the system.
*
* @return boolean
*/
public function is_multi_network() {
global $wpdb;
$cached = Cache::get( 'is_multi_network' );
if ( null !== $cached ) {
return $cached;
}
// If we don't have a multi site setup no need to do any more.
if ( ! is_multisite() ) {
Cache::set( 'is_multi_network', false );
return false;
}
$num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" );
if ( $num_sites > 1 ) {
Cache::set( 'is_multi_network', true );
return true;
}
Cache::set( 'is_multi_network', false );
return false;
}
/**
* Whether the current site is single user site.
*
* @return bool
*/
public function is_single_user_site() {
global $wpdb;
$ret = Cache::get( 'is_single_user_site' );
if ( null === $ret ) {
$some_users = get_transient( 'jetpack_is_single_user' );
if ( false === $some_users ) {
$some_users = $wpdb->get_var( "SELECT COUNT(*) FROM (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' LIMIT 2) AS someusers" );
set_transient( 'jetpack_is_single_user', (int) $some_users, 12 * HOUR_IN_SECONDS );
}
$ret = 1 === (int) $some_users;
Cache::set( 'is_single_user_site', $ret );
}
return $ret;
}
/**
* If the site is a local site.
*
* @since 1.3.0
*
* @return bool
*/
public function is_local_site() {
$cached = Cache::get( 'is_local_site' );
if ( null !== $cached ) {
return $cached;
}
$site_url = site_url();
// Check for localhost and sites using an IP only first.
// Note: str_contains() is not used here, as wp-includes/compat.php is not loaded in this file.
$is_local = $site_url && false === strpos( $site_url, '.' );
// Use Core's environment check, if available.
if ( 'local' === wp_get_environment_type() ) {
$is_local = true;
}
// Then check for usual usual domains used by local dev tools.
$known_local = array(
'#\.local$#i',
'#\.localhost$#i',
'#\.test$#i',
'#\.docksal$#i', // Docksal.
'#\.docksal\.site$#i', // Docksal.
'#\.dev\.cc$#i', // ServerPress.
'#\.lndo\.site$#i', // Lando.
'#\.ddev\.site$#i', // DDEV.
'#^https?://127\.0\.0\.1$#',
);
if ( ! $is_local ) {
foreach ( $known_local as $url ) {
if ( preg_match( $url, $site_url ) ) {
$is_local = true;
break;
}
}
}
/**
* Filters is_local_site check.
*
* @since 1.3.0
*
* @param bool $is_local If the current site is a local site.
*/
$is_local = apply_filters( 'jetpack_is_local_site', $is_local );
Cache::set( 'is_local_site', $is_local );
return $is_local;
}
/**
* If is a staging site.
*
* @deprecated since 3.3.0
*
* @return bool
*/
public function is_staging_site() {
_deprecated_function( __FUNCTION__, '3.3.0', 'in_safe_mode' );
$cached = Cache::get( 'is_staging_site' );
if ( null !== $cached ) {
return $cached;
}
/*
* Core's wp_get_environment_type allows for a few specific options.
* We should default to bowing out gracefully for anything other than production or local.
*/
$is_staging = ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true );
$known_staging = array(
'urls' => array(
'#\.staging\.wpengine\.com$#i', // WP Engine. This is their legacy staging URL structure. Their new platform does not have a common URL. https://github.com/Automattic/jetpack/issues/21504
'#\.staging\.kinsta\.com$#i', // Kinsta.com.
'#\.kinsta\.cloud$#i', // Kinsta.com.
'#\.stage\.site$#i', // DreamPress.
'#\.newspackstaging\.com$#i', // Newspack.
'#^(?!live-)([a-zA-Z0-9-]+)\.pantheonsite\.io$#i', // Pantheon.
'#\.flywheelsites\.com$#i', // Flywheel.
'#\.flywheelstaging\.com$#i', // Flywheel.
'#\.cloudwaysapps\.com$#i', // Cloudways.
'#\.azurewebsites\.net$#i', // Azure.
'#\.wpserveur\.net$#i', // WPServeur.
'#\-liquidwebsites\.com$#i', // Liquidweb.
),
'constants' => array(
'IS_WPE_SNAPSHOT', // WP Engine. This is used on their legacy staging environment. Their new platform does not have a constant. https://github.com/Automattic/jetpack/issues/21504
'KINSTA_DEV_ENV', // Kinsta.com.
'WPSTAGECOACH_STAGING', // WP Stagecoach.
'JETPACK_STAGING_MODE', // Generic.
'WP_LOCAL_DEV', // Generic.
),
);
/**
* Filters the flags of known staging sites.
*
* @since 1.1.1
* @since-jetpack 3.9.0
*
* @param array $known_staging {
* An array of arrays that each are used to check if the current site is staging.
* @type array $urls URLs of staging sites in regex to check against site_url.
* @type array $constants PHP constants of known staging/developement environments.
* }
*/
$known_staging = apply_filters( 'jetpack_known_staging', $known_staging );
if ( isset( $known_staging['urls'] ) ) {
$site_url = site_url();
foreach ( $known_staging['urls'] as $url ) {
if ( preg_match( $url, wp_parse_url( $site_url, PHP_URL_HOST ) ) ) {
$is_staging = true;
break;
}
}
}
if ( isset( $known_staging['constants'] ) ) {
foreach ( $known_staging['constants'] as $constant ) {
if ( defined( $constant ) && constant( $constant ) ) {
$is_staging = true;
}
}
}
// Last, let's check if sync is erroring due to an IDC. If so, set the site to staging mode.
if ( ! $is_staging && method_exists( 'Automattic\\Jetpack\\Identity_Crisis', 'validate_sync_error_idc_option' ) && \Automattic\Jetpack\Identity_Crisis::validate_sync_error_idc_option() ) {
$is_staging = true;
}
/**
* Filters is_staging_site check.
*
* @since 1.1.1
* @since-jetpack 3.9.0
*
* @param bool $is_staging If the current site is a staging site.
*/
$is_staging = apply_filters( 'jetpack_is_staging_site', $is_staging );
Cache::set( 'is_staging_site', $is_staging );
return $is_staging;
}
/**
* If the site is in safe mode.
*
* @since 3.3.0
*
* @return bool
*/
public function in_safe_mode() {
$cached = Cache::get( 'in_safe_mode' );
if ( null !== $cached ) {
return $cached;
}
$in_safe_mode = false;
if ( method_exists( 'Automattic\\Jetpack\\Identity_Crisis', 'validate_sync_error_idc_option' ) && \Automattic\Jetpack\Identity_Crisis::validate_sync_error_idc_option() ) {
$in_safe_mode = true;
}
/**
* Filters in_safe_mode check.
*
* @since 3.3.0
*
* @param bool $in_safe_mode If the current site is in safe mode.
*/
$in_safe_mode = apply_filters( 'jetpack_is_in_safe_mode', $in_safe_mode );
Cache::set( 'in_safe_mode', $in_safe_mode );
return $in_safe_mode;
}
/**
* If the site is a development/staging site.
* This is a new version of is_staging_site added to separate safe mode from the legacy staging mode.
* This method checks for core WP_ENVIRONMENT_TYPE setting
* Using the jetpack_is_development_site filter.
*
* @since 3.3.0
*
* @return bool
*/
public static function is_development_site() {
$cached = Cache::get( 'is_development_site' );
if ( null !== $cached ) {
return $cached;
}
$is_dev_site = ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true );
/**
* Filters is_development_site check.
*
* @since 3.3.0
*
* @param bool $is_dev_site If the current site is a staging or dev site.
*/
$is_dev_site = apply_filters( 'jetpack_is_development_site', $is_dev_site );
Cache::set( 'is_development_site', $is_dev_site );
return $is_dev_site;
}
/**
* Whether the site is currently onboarding or not.
* A site is considered as being onboarded if it currently has an onboarding token.
*
* @since-jetpack 5.8
*
* @deprecated since 4.0.0
*
* @access public
* @static
*
* @return bool True if the site is currently onboarding, false otherwise
*/
public function is_onboarding() {
return \Jetpack_Options::get_option( 'onboarding' ) !== false;
}
/**
* Whether the site is currently private or not.
* On WordPress.com and WoA, sites can be marked as private
*
* @since 1.16.0
*
* @return bool True if the site is private.
*/
public function is_private_site() {
$ret = Cache::get( 'is_private_site' );
if ( null === $ret ) {
$is_private_site = '-1' === get_option( 'blog_public' );
/**
* Filters the is_private_site check.
*
* @since 1.16.1
*
* @param bool $is_private_site True if the site is private.
*/
$is_private_site = apply_filters( 'jetpack_is_private_site', $is_private_site );
Cache::set( 'is_private_site', $is_private_site );
return $is_private_site;
}
return $ret;
}
/**
* Whether the site is currently unlaunched or not.
* On WordPress.com and WoA, sites can be marked as "coming soon", aka unlaunched
*
* @since 1.16.0
*
* @return bool True if the site is not launched.
*/
public function is_coming_soon() {
$ret = Cache::get( 'is_coming_soon' );
if ( null === $ret ) {
$is_coming_soon = ( function_exists( 'site_is_coming_soon' ) && \site_is_coming_soon() )
|| get_option( 'wpcom_public_coming_soon' );
/**
* Filters the is_coming_soon check.
*
* @since 1.16.1
*
* @param bool $is_coming_soon True if the site is coming soon (i.e. unlaunched).
*/
$is_coming_soon = apply_filters( 'jetpack_is_coming_soon', $is_coming_soon );
Cache::set( 'is_coming_soon', $is_coming_soon );
return $is_coming_soon;
}
return $ret;
}
/**
* Returns the site slug suffix to be used as part of Calypso URLs.
*
* Strips http:// or https:// from a url, replaces forward slash with ::.
*
* @since 1.6.0
*
* @param string $url Optional. URL to build the site suffix from. Default: Home URL.
*
* @return string
*/
public function get_site_suffix( $url = '' ) {
// On WordPress.com, site suffixes are a bit different.
if ( method_exists( 'WPCOM_Masterbar', 'get_calypso_site_slug' ) ) {
return WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() );
}
// Grab the 'site_url' option for WoA sites to avoid plugins to interfere with the site
// identifier (e.g. i18n plugins may change the main url to '<DOMAIN>/<LOCALE>', but we
// want to exclude the locale since it's not part of the site suffix).
if ( ( new Host() )->is_woa_site() ) {
$url = \site_url();
}
if ( empty( $url ) ) {
// WordPress can be installed in subdirectories (e.g. make.wordpress.org/plugins)
// where the 'site_url' option points to the root domain (e.g. make.wordpress.org)
// which could collide with another site in the same domain but with WordPress
// installed in a different subdirectory (e.g. make.wordpress.org/core). To avoid
// such collision, we identify the site with the 'home_url' option.
$url = \home_url();
}
$url = preg_replace( '#^.*?://#', '', $url );
$url = str_replace( '/', '::', $url );
return rtrim( $url, ':' );
}
}
@@ -0,0 +1,56 @@
<?php
/**
* Status and information regarding the site visitor.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack\Status;
/**
* Visitor class.
*/
class Visitor {
/**
* Gets current user IP address.
*
* @param bool $check_all_headers Check all headers? Default is `false`.
*
* @return string Current user IP address.
*/
public function get_ip( $check_all_headers = false ) {
if ( $check_all_headers ) {
foreach ( array(
'HTTP_CF_CONNECTING_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
) as $key ) {
if ( ! empty( $_SERVER[ $key ] ) ) {
// @todo Some of these might actually be lists of IPs (e.g. HTTP_X_FORWARDED_FOR) or something else entirely (HTTP_VIA).
return filter_var( wp_unslash( $_SERVER[ $key ] ) );
}
}
}
return ! empty( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
}
/**
* Simple gate check for a11n feature testing purposes using AT_PROXIED_REQUEST constant.
* IMPORTANT: Only use it for internal feature test purposes, not authorization.
*
* The goal of this function is to help us gate features by using a similar function name
* we find on simple sites: is_automattician().
*
* @return bool True if the current request is PROXIED, false otherwise.
*/
public function is_automattician_feature_flags_only() {
return ( defined( 'AT_PROXIED_REQUEST' ) && AT_PROXIED_REQUEST );
}
}