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

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