3rdparty
6 days ago
abilities
6 days ago
admin
6 days ago
cli
5 years ago
frontend
2 weeks ago
helpers
2 weeks ago
metaboxes
2 years ago
module
2 weeks ago
modules
6 days ago
opengraph
2 weeks ago
replace-variables
2 weeks ago
rest
6 days ago
settings
2 weeks ago
traits
2 weeks ago
updates
2 weeks ago
class-auto-updater.php
5 years ago
class-cmb2.php
2 weeks ago
class-common.php
5 months ago
class-compatibility.php
1 year ago
class-data-encryption.php
5 months ago
class-defaults.php
6 years ago
class-frontend-seo-score.php
2 weeks ago
class-helper.php
10 months ago
class-installer.php
2 weeks ago
class-json-manager.php
1 year ago
class-kb.php
7 months ago
class-metadata.php
2 months ago
class-post.php
1 year ago
class-rewrite.php
5 months ago
class-settings.php
1 year ago
class-term.php
1 year ago
class-thumbnail-overlay.php
1 year ago
class-tracking.php
6 days ago
class-update-email.php
2 weeks ago
class-updates.php
3 months ago
class-user.php
8 months ago
index.php
7 years ago
interface-runner.php
7 years ago
template-tags.php
1 year ago
class-updates.php
103 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 | '1.0.250' => 'updates/update-1.0.250.php', |
| 49 | '1.0.251' => 'updates/update-1.0.251.php', |
| 50 | '1.0.264' => 'updates/update-1.0.264.php', |
| 51 | ]; |
| 52 | |
| 53 | /** |
| 54 | * Register hooks. |
| 55 | */ |
| 56 | public function hooks() { |
| 57 | $this->action( 'admin_init', 'do_updates' ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Check if any update is required. |
| 62 | */ |
| 63 | public function do_updates() { |
| 64 | $installed_version = get_option( 'rank_math_version', '1.0.0' ); |
| 65 | |
| 66 | // Maybe it's the first install. |
| 67 | if ( ! $installed_version ) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if ( version_compare( $installed_version, rank_math()->version, '<' ) ) { |
| 72 | $this->perform_updates(); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Perform all updates. |
| 78 | */ |
| 79 | public function perform_updates() { |
| 80 | $installed_version = get_option( 'rank_math_version', '1.0.0' ); |
| 81 | |
| 82 | foreach ( self::$updates as $version => $path ) { |
| 83 | if ( version_compare( $installed_version, $version, '<' ) ) { |
| 84 | include $path; |
| 85 | update_option( 'rank_math_version', $version ); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // Save install date. |
| 90 | if ( false === boolval( get_option( 'rank_math_install_date' ) ) ) { |
| 91 | update_option( 'rank_math_install_date', Helper::get_current_time() ); |
| 92 | } |
| 93 | |
| 94 | // Clear rollback option if necessary. |
| 95 | if ( rank_math()->version !== get_option( 'rank_math_rollback_version' ) ) { |
| 96 | delete_option( 'rank_math_rollback_version' ); |
| 97 | } |
| 98 | |
| 99 | update_option( 'rank_math_version', rank_math()->version, false ); |
| 100 | update_option( 'rank_math_db_version', rank_math()->db_version, false ); |
| 101 | } |
| 102 | } |
| 103 |