3rdparty
1 year ago
admin
1 year ago
cli
5 years ago
frontend
1 year ago
helpers
1 year ago
metaboxes
2 years ago
module
1 year ago
modules
1 year ago
opengraph
1 year ago
replace-variables
1 year ago
rest
1 year ago
settings
1 year ago
traits
1 year ago
updates
1 year ago
class-auto-updater.php
5 years ago
class-cmb2.php
2 years ago
class-common.php
1 year ago
class-compatibility.php
1 year ago
class-data-encryption.php
1 year ago
class-defaults.php
6 years ago
class-frontend-seo-score.php
1 year ago
class-helper.php
1 year ago
class-installer.php
1 year ago
class-json-manager.php
1 year ago
class-kb.php
1 year ago
class-metadata.php
1 year ago
class-post.php
1 year ago
class-rewrite.php
2 years ago
class-settings.php
1 year ago
class-term.php
1 year ago
class-thumbnail-overlay.php
1 year ago
class-update-email.php
3 years ago
class-updates.php
1 year ago
class-user.php
1 year ago
index.php
7 years ago
interface-runner.php
7 years ago
template-tags.php
1 year ago
class-updates.php
100 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Functions and actions related to updates. |
| 4 | * |
| 5 | * @since 0.9.0 |
| 6 | * @package RankMath |
| 7 | * @subpackage RankMath\Core |
| 8 | * @author Rank Math <support@rankmath.com> |
| 9 | */ |
| 10 | |
| 11 | namespace RankMath; |
| 12 | |
| 13 | use RankMath\Helper; |
| 14 | use RankMath\Traits\Hooker; |
| 15 | |
| 16 | |
| 17 | defined( 'ABSPATH' ) || exit; |
| 18 | |
| 19 | /** |
| 20 | * Updates class |
| 21 | */ |
| 22 | class Updates implements Runner { |
| 23 | |
| 24 | use Hooker; |
| 25 | |
| 26 | /** |
| 27 | * Updates that need to be run |
| 28 | * |
| 29 | * @var array |
| 30 | */ |
| 31 | private static $updates = [ |
| 32 | '1.0.84' => 'updates/update-1.0.84.php', |
| 33 | '1.0.86' => 'updates/update-1.0.86.php', |
| 34 | '1.0.89' => 'updates/update-1.0.89.php', |
| 35 | '1.0.98' => 'updates/update-1.0.98.php', |
| 36 | '1.0.103.1' => 'updates/update-1.0.103.1.php', |
| 37 | '1.0.104' => 'updates/update-1.0.104.php', |
| 38 | '1.0.107.3' => 'updates/update-1.0.107.3.php', |
| 39 | '1.0.110' => 'updates/update-1.0.110.php', |
| 40 | '1.0.201' => 'updates/update-1.0.201.php', |
| 41 | '1.0.201.1' => 'updates/update-1.0.201.1.php', |
| 42 | '1.0.202' => 'updates/update-1.0.202.php', |
| 43 | '1.0.211' => 'updates/update-1.0.211.php', |
| 44 | '1.0.232' => 'updates/update-1.0.232.php', |
| 45 | '1.0.237' => 'updates/update-1.0.237.php', |
| 46 | '1.0.238' => 'updates/update-1.0.238.php', |
| 47 | '1.0.239' => 'updates/update-1.0.239.php', |
| 48 | ]; |
| 49 | |
| 50 | /** |
| 51 | * Register hooks. |
| 52 | */ |
| 53 | public function hooks() { |
| 54 | $this->action( 'admin_init', 'do_updates' ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Check if any update is required. |
| 59 | */ |
| 60 | public function do_updates() { |
| 61 | $installed_version = get_option( 'rank_math_version', '1.0.0' ); |
| 62 | |
| 63 | // Maybe it's the first install. |
| 64 | if ( ! $installed_version ) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | if ( version_compare( $installed_version, rank_math()->version, '<' ) ) { |
| 69 | $this->perform_updates(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Perform all updates. |
| 75 | */ |
| 76 | public function perform_updates() { |
| 77 | $installed_version = get_option( 'rank_math_version', '1.0.0' ); |
| 78 | |
| 79 | foreach ( self::$updates as $version => $path ) { |
| 80 | if ( version_compare( $installed_version, $version, '<' ) ) { |
| 81 | include $path; |
| 82 | update_option( 'rank_math_version', $version ); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // Save install date. |
| 87 | if ( false === boolval( get_option( 'rank_math_install_date' ) ) ) { |
| 88 | update_option( 'rank_math_install_date', Helper::get_current_time() ); |
| 89 | } |
| 90 | |
| 91 | // Clear rollback option if necessary. |
| 92 | if ( rank_math()->version !== get_option( 'rank_math_rollback_version' ) ) { |
| 93 | delete_option( 'rank_math_rollback_version' ); |
| 94 | } |
| 95 | |
| 96 | update_option( 'rank_math_version', rank_math()->version, false ); |
| 97 | update_option( 'rank_math_db_version', rank_math()->db_version, false ); |
| 98 | } |
| 99 | } |
| 100 |