PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Updater.php
pods / tribe-common / src / Tribe Last commit date
Admin 1 week ago Ajax 1 week ago Asset 1 week ago Context 1 week ago Customizer 1 week ago Debug_Bar 1 week ago Dialog 1 week ago Documentation 1 week ago Duplicate 1 week ago Editor 1 week ago Image 1 week ago JSON_LD 1 week ago Languages 1 week ago Log 1 week ago Meta 1 week ago Models 1 week ago PUE 1 week ago Process 1 week ago Promoter 1 week ago REST 1 week ago Repository 1 week ago Service_Providers 1 week ago Shortcode 1 week ago Support 1 week ago Tabbed_View 1 week ago Tooltip 1 week ago Traits 1 week ago Utils 1 week ago Validator 1 week ago Widget 1 week ago Abstract_Deactivation.php 1 week ago Abstract_Plugin_Register.php 1 week ago App_Shop.php 1 week ago Assets.php 1 week ago Assets_Pipeline.php 1 week ago Autoloader.php 1 week ago Cache.php 1 week ago Cache_Listener.php 1 week ago Changelog_Reader.php 1 week ago Container.php 1 week ago Context.php 1 week ago Cost_Utils.php 1 week ago Credits.php 1 week ago Customizer.php 1 week ago DB_Lock.php 1 week ago Data.php 1 week ago Date_Utils.php 1 week ago Db.php 1 week ago Debug.php 1 week ago Dependency.php 1 week ago Deprecation.php 1 week ago Editor.php 1 week ago Error.php 1 week ago Exception.php 1 week ago Extension.php 1 week ago Extension_Loader.php 1 week ago Feature_Detection.php 1 week ago Field.php 1 week ago Field_Conditional.php 1 week ago Freemius.php 1 week ago Log.php 1 week ago Main.php 1 week ago Notices.php 1 week ago Plugin_Meta_Links.php 1 week ago Plugins.php 1 week ago Plugins_API.php 1 week ago Post_History.php 1 week ago Post_Transient.php 1 week ago Promise.php 1 week ago Repository.php 1 week ago Rewrite.php 1 week ago Settings.php 1 week ago Settings_Manager.php 1 week ago Settings_Tab.php 1 week ago Simple_Table.php 1 week ago Support.php 1 week ago Tabbed_View.php 1 week ago Template.php 1 week ago Template_Factory.php 1 week ago Template_Part_Cache.php 1 week ago Templates.php 1 week ago Terms.php 1 week ago Timezones.php 1 week ago Tracker.php 1 week ago Updater.php 1 week ago Validate.php 1 week ago View_Helpers.php 1 week ago
Updater.php
181 lines
1 <?php
2
3
4 /**
5 * Run schema updates on plugin activation or updates
6 *
7 * @since 4.9.4
8 *
9 */
10 class Tribe__Updater {
11
12 protected $version_option = 'schema-version';
13 protected $reset_version = '3.9'; // when a reset() is called, go to this version
14 protected $current_version = 0;
15
16 public $capabilities;
17
18 /**
19 * Tribe__Updater constructor.
20 *
21 * @since 4.9.4
22 *
23 * @param int $current_version the current version number of a plugin
24 */
25 public function __construct( $current_version ) {
26 $this->current_version = $current_version;
27 }
28
29 /**
30 * We've had problems with the notoptions and
31 * alloptions caches getting out of sync with the DB,
32 * forcing an eternal update cycle
33 *
34 * @since 4.9.4
35 *
36 */
37 protected function clear_option_caches() {
38 wp_cache_delete( 'notoptions', 'options' );
39 wp_cache_delete( 'alloptions', 'options' );
40 }
41
42 /**
43 * Run Updates for a Plugin
44 *
45 * @since 4.9.4
46 *
47 */
48 public function do_updates() {
49 $this->clear_option_caches();
50 $updates = $this->get_update_callbacks();
51 uksort( $updates, 'version_compare' );
52
53 try {
54 foreach ( $updates as $version => $callback ) {
55
56 if ( ! $this->is_new_install() && version_compare( $version, $this->current_version, '<=' ) && $this->is_version_in_db_less_than( $version ) ) {
57 call_user_func( $callback );
58 }
59 }
60
61 foreach ( $this->get_constant_update_callbacks() as $callback ) {
62 call_user_func( $callback );
63 }
64
65 $this->update_version_option( $this->current_version );
66 } catch ( Exception $e ) {
67 // fail silently, but it should try again next time
68 }
69 }
70
71 /**
72 * Update Version Number for a Plugin
73 *
74 * @since 4.9.4
75 *
76 * @param int $new_version the current version number of a plugin
77 */
78 public function update_version_option( $new_version ) {
79 Tribe__Settings_Manager::set_option( $this->version_option, $new_version );
80 }
81
82 /**
83 * Returns an array of callbacks with version strings as keys.
84 * Any key higher than the version recorded in the DB
85 * and lower than $this->current_version will have its
86 * callback called.
87 *
88 * @since 4.9.4
89 *
90 * @return array
91 */
92 public function get_update_callbacks() {
93 return [];
94 }
95
96 /**
97 * Returns an array of callbacks that should be called
98 * every time the version is updated
99 *
100 * @since 4.9.4
101 *
102 * @return array
103 */
104 public function get_constant_update_callbacks() {
105 return [
106 [ $this, 'flush_rewrites' ],
107 ];
108 }
109
110 /**
111 * Get version from Tribe Settings for the Plugin
112 *
113 * @since 4.9.4
114 *
115 * @return mixed the version number of the plugin saved in the options
116 */
117 public function get_version_from_db() {
118 return Tribe__Settings_Manager::get_option( $this->version_option );
119 }
120
121 /**
122 * Returns true if the version in the DB is less than the provided version
123 *
124 * @since 4.9.4
125 *
126 * @return boolean
127 */
128 public function is_version_in_db_less_than( $version ) {
129 $version_in_db = $this->get_version_from_db();
130
131 return ( version_compare( $version, $version_in_db ) > 0 );
132 }
133
134 /**
135 * Returns true if this is a new install
136 *
137 * @since 4.9.4
138 *
139 * @return boolean
140 */
141 public function is_new_install() {
142 $version_in_db = $this->get_version_from_db();
143
144 return empty( $version_in_db );
145 }
146
147 /**
148 * Returns true if an update is required
149 *
150 * @since 4.9.4
151 *
152 * @return boolean
153 */
154 public function update_required() {
155 return $this->is_version_in_db_less_than( $this->current_version );
156 }
157
158 /**
159 * Flush Rewrite rules
160 *
161 * @since 4.9.4
162 *
163 */
164 public function flush_rewrites() {
165 // run after 'init' to ensure that all CPTs are registered
166 add_action( 'wp_loaded', 'flush_rewrite_rules' );
167 }
168
169 /**
170 * Reset update flags. All updates past $this->reset_version will
171 * run again on the next page load
172 *
173 * @since 4.9.4
174 *
175 */
176 public function reset() {
177 $this->update_version_option( $this->reset_version );
178 }
179
180 }
181