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

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