PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / includes / class-smart-post-show-updates.php

class-smart-post-show-updates.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.2, at includes/class-smart-post-show-updates.php

121 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fired during plugin updates
4 *
5 * @link https://wpsmartpost.com/
6 * @since 2.2.0
7 *
8 * @package Smart_Post_Show
9 * @subpackage Smart_Post_Show/includes
10 */
11
12 // don't call the file directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Fired during plugin updates.
19 *
20 * This class defines all code necessary to run during the plugin's updates.
21 */
22 class Smart_Post_Show_Updates {
23
24 /**
25 * DB updates that need to be run
26 *
27 * @var array
28 */
29 private static $updates = array(
30 '2.2.0' => 'updates/update-2.2.0.php',
31 '2.4.13' => 'updates/update-2.4.13.php',
32 '3.0.0' => 'updates/update-3.0.0.php',
33 '3.0.6' => 'updates/update-3.0.6.php',
34 );
35
36 /**
37 * Binding all events
38 *
39 * @since 2.2.0
40 *
41 * @return void
42 */
43 public function __construct() {
44 add_action( 'plugins_loaded', array( $this, 'do_updates' ) );
45 }
46
47 /**
48 * Check if need any update
49 *
50 * @since 2.2.0
51 *
52 * @return boolean
53 */
54 public function is_needs_update() {
55 $installed_version = get_option( 'smart_post_show_version' );
56 $first_version = get_option( 'smart_post_show_first_version' );
57 $activation_date = get_option( 'smart_post_show_activation_date' );
58
59 if ( false === $installed_version ) {
60 update_option( 'smart_post_show_version', SMART_POST_SHOW_VERSION );
61 update_option( 'smart_post_show_db_version', SMART_POST_SHOW_VERSION );
62 }
63 if ( false === $first_version ) {
64 update_option( 'smart_post_show_first_version', SMART_POST_SHOW_VERSION );
65 }
66 if ( false === $activation_date ) {
67 update_option( 'smart_post_show_activation_date', current_time( 'timestamp' ) );
68 }
69
70 if ( version_compare( $installed_version, SMART_POST_SHOW_VERSION, '<' ) ) {
71 return true;
72 }
73
74 return false;
75 }
76
77 /**
78 * Do updates.
79 *
80 * @since 2.2.0
81 *
82 * @return void
83 */
84 public function do_updates() {
85 $this->perform_updates();
86 }
87
88 /**
89 * Perform all updates
90 *
91 * @since 2.2.0
92 *
93 * @return void
94 */
95 public function perform_updates() {
96 if ( ! $this->is_needs_update() ) {
97 return;
98 }
99
100 $installed_version = get_option( 'smart_post_show_version' );
101
102 foreach ( self::$updates as $version => $path ) {
103 if ( version_compare( $installed_version, $version, '<' ) ) {
104 $allowed_paths = array(
105 'updates/update-2.2.0.php',
106 'updates/update-2.4.13.php',
107 'updates/update-3.0.0.php',
108 'updates/update-3.0.6.php',
109 );
110 if ( in_array( $path, $allowed_paths ) && file_exists( SP_PC_PATH . 'includes/' . $path ) ) {
111 require_once SP_PC_PATH . 'includes/' . $path;
112 }
113 update_option( 'smart_post_show_version', $version );
114 }
115 }
116
117 update_option( 'smart_post_show_version', SMART_POST_SHOW_VERSION );
118 }
119 }
120 new Smart_Post_Show_Updates();
121