PluginProbe
Faust.js / 1.0.2
Faust.js v1.0.2
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / updates / upgrade-database.php

upgrade-database.php in Faust.js 1.0.2, at includes/updates/upgrade-database.php

59 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Database upgrade functions.
4 *
5 * @package FaustWP
6 */
7
8 namespace WPE\FaustWP\Updates;
9
10 add_action( 'plugins_loaded', __NAMESPACE__ . '\\upgrade_database' );
11 /**
12 * Migrates the plugin's stored data to the latest format.
13 *
14 * @return bool True if updates were carried out or false.
15 */
16 function upgrade_database(): bool {
17 $current_version = get_option( 'faustwp_current_version', '0.0.0' );
18 $file_data = get_file_data( FAUSTWP_FILE, array( 'Version' => 'Version' ) );
19 $plugin_version = $file_data['Version'];
20
21 if ( 1 === version_compare( $plugin_version, $current_version ) ) {
22
23 // Array of versions requiring update and their callbacks.
24 // Note these do not have to exactly match plugin version.
25 $update_versions = array(
26 '0.6.1' => 'upgrade_0_6_1',
27 );
28
29 foreach ( $update_versions as $version => $callback ) {
30 if ( 1 === version_compare( $version, $current_version ) ) {
31 call_user_func( __NAMESPACE__ . '\\' . $callback );
32 }
33 }
34
35 // Save the last updated version.
36 update_option( 'faustwp_current_version', $plugin_version );
37 return true;
38 }
39
40 return false;
41 }
42
43 /**
44 * Update settings option name for versions after to 0.6.1.
45 *
46 * @return bool True if the database was updated or false.
47 */
48 function upgrade_0_6_1(): bool {
49 $settings = get_option( 'wpe_headless', array() );
50
51 if ( empty( $settings ) ) {
52 return false;
53 }
54
55 delete_option( 'wpe_headless' );
56
57 return update_option( 'faustwp_settings', $settings );
58 }
59