PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.12
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.12
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 2.4.12, at includes/class-smart-post-show-updates.php

112 lines 2.2 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://smartpostshow.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;
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 );
32
33 /**
34 * Binding all events
35 *
36 * @since 2.2.0
37 *
38 * @return void
39 */
40 public function __construct() {
41 add_action( 'plugins_loaded', array( $this, 'do_updates' ) );
42 }
43
44 /**
45 * Check if need any update
46 *
47 * @since 2.2.0
48 *
49 * @return boolean
50 */
51 public function is_needs_update() {
52 $installed_version = get_option( 'smart_post_show_version' );
53 $first_version = get_option( 'smart_post_show_first_version' );
54 $activation_date = get_option( 'smart_post_show_activation_date' );
55
56 if ( false === $installed_version ) {
57 update_option( 'smart_post_show_version', SMART_POST_SHOW_VERSION );
58 update_option( 'smart_post_show_db_version', SMART_POST_SHOW_VERSION );
59 }
60 if ( false === $first_version ) {
61 update_option( 'smart_post_show_first_version', SMART_POST_SHOW_VERSION );
62 }
63 if ( false === $activation_date ) {
64 update_option( 'smart_post_show_activation_date', current_time( 'timestamp' ) );
65 }
66
67 if ( version_compare( $installed_version, SMART_POST_SHOW_VERSION, '<' ) ) {
68 return true;
69 }
70
71 return false;
72 }
73
74 /**
75 * Do updates.
76 *
77 * @since 2.2.0
78 *
79 * @return void
80 */
81 public function do_updates() {
82 $this->perform_updates();
83 }
84
85 /**
86 * Perform all updates
87 *
88 * @since 2.2.0
89 *
90 * @return void
91 */
92 public function perform_updates() {
93 if ( ! $this->is_needs_update() ) {
94 return;
95 }
96
97 $installed_version = get_option( 'smart_post_show_version' );
98
99 foreach ( self::$updates as $version => $path ) {
100 if ( version_compare( $installed_version, $version, '<' ) ) {
101 include $path;
102 update_option( 'smart_post_show_version', $version );
103 }
104 }
105
106 update_option( 'smart_post_show_version', SMART_POST_SHOW_VERSION );
107
108 }
109
110 }
111 new Smart_Post_Show_Updates();
112