This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
/
update.php
111 lines (87 loc) · 2.97 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Version check and update functionality.
*
* @package Members
* @subpackage Includes
*/
/* Don't run when installing. */
if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING )
return;
/* Hook our version check to 'init'. */
add_action( 'init', 'members_version_check' );
/**
* Checks the version number and runs install or update functions if needed.
*
* @since 0.2.0
*/
function members_version_check() {
/* Get the old database version. */
$old_db_version = get_option( 'members_db_version' );
/* Get the theme settings. */
$settings = get_option( 'members_settings' );
/* If there is no old database version, run the install. */
if ( empty( $old_db_version ) && false === $settings )
members_install();
/* Temporary check b/c version 0.1.0 didn't have an upgrade path. */
elseif ( empty( $old_db_version ) && !empty( $settings ) )
members_update();
/* If the old version is less than the new version, run the update. */
elseif ( intval( $old_db_version ) < intval( MEMBERS_DB_VERSION ) )
members_update();
}
/**
* Adds the plugin settings on install.
*
* @since 0.2.0
*/
function members_install() {
/* Add the database version setting. */
add_option( 'members_db_version', MEMBERS_DB_VERSION );
/* Add the default plugin settings. */
add_option( 'members_settings', members_get_default_settings() );
}
/**
* Updates plugin settings if there are new settings to add.
*
* @since 0.2.0
*/
function members_update() {
/* Update the database version setting. */
update_option( 'members_db_version', MEMBERS_DB_VERSION );
/* Get the settings from the database. */
$settings = get_option( 'members_settings' );
/* Get the default plugin settings. */
$default_settings = members_get_default_settings();
/* Loop through each of the default plugin settings. */
foreach ( $default_settings as $setting_key => $setting_value ) {
/* If the setting didn't previously exist, add the default value to the $settings array. */
if ( !isset( $settings[$setting_key] ) )
$settings[$setting_key] = $setting_value;
}
/* Update the plugin settings. */
update_option( 'members_settings', $settings );
}
/**
* Returns an array of the default plugin settings. These are only used on initial setup.
*
* @since 0.2.0
*/
function members_get_default_settings() {
/* Set up the default plugin settings. */
$settings = array(
// Version 0.1.0
'role_manager' => 1,
'content_permissions' => 1,
'private_blog' => 0,
// Version 0.2.0
'private_feed' => 0,
'login_form_widget' => 0,
'users_widget' => 0,
'content_permissions_error' => '<p class="restricted">' . __( 'Sorry, but you do not have permission to view this content.', 'members' ) . '</p>',
'private_feed_error' => '<p class="restricted">' . __( 'You must be logged into the site to view this content.', 'members' ) . '</p>',
);
/* Return the default settings. */
return $settings;
}
?>