← All changes
|
jetpack_vendor/automattic/jetpack-search/src/class-package.php
+66
-0
16.2-beta
→
16.3-beta
View file →
| @@ -1,0 +1,66 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Search package information. | |
| 4 | + * | |
| 5 | + * @package automattic/jetpack-search | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace Automattic\Jetpack\Search; | |
| 9 | + | |
| 10 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + exit( 0 ); | |
| 12 | +} | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Search package general information | |
| 16 | + */ | |
| 17 | +class Package { | |
| 18 | + const VERSION = '8.3.0'; | |
| 19 | + const SLUG = 'search'; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * The path where package is installed. | |
| 23 | + * | |
| 24 | + * @var string | |
| 25 | + */ | |
| 26 | + protected static $installed_path; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Adds the package slug and version to the package version tracker's data. | |
| 30 | + * | |
| 31 | + * @param array $package_versions The package version array. | |
| 32 | + * | |
| 33 | + * @return array The packge version array. | |
| 34 | + */ | |
| 35 | + public static function send_version_to_tracker( $package_versions ) { | |
| 36 | + // Multiple versions could co-exist, we want to send the version which is in use. | |
| 37 | + // `jetpack-autoloader` would load classes from the latest package, so we send the latest version here. | |
| 38 | + if ( empty( $package_versions[ self::SLUG ] ) || version_compare( $package_versions[ self::SLUG ], self::VERSION, '<' ) ) { | |
| 39 | + $package_versions[ self::SLUG ] = self::VERSION; | |
| 40 | + } | |
| 41 | + return $package_versions; | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Whether Jetpack Search Package's version maps to a public release, or a development version. | |
| 46 | + */ | |
| 47 | + public static function is_development_version() { | |
| 48 | + return (bool) apply_filters( | |
| 49 | + 'jetpack_search_is_development_version', | |
| 50 | + ! preg_match( '/^\d+(\.\d+)+$/', self::VERSION ) | |
| 51 | + ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Return the path where the package is installed with trailing slash. | |
| 56 | + * It's important not to use a constant, as there could be multiple versions of search package installed. | |
| 57 | + * | |
| 58 | + * @return string | |
| 59 | + */ | |
| 60 | + public static function get_installed_path() { | |
| 61 | + if ( static::$installed_path === null ) { | |
| 62 | + static::$installed_path = dirname( __DIR__ ) . DIRECTORY_SEPARATOR; | |
| 63 | + } | |
| 64 | + return apply_filters( 'jetpack_search_installed_path', static::$installed_path ); | |
| 65 | + } | |
| 66 | +} | |