| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Updater |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage Updater |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Compare the bbPress version to the DB version to determine if updating |
| 15 |
* |
| 16 |
* @since bbPress (r3421) |
| 17 |
* |
| 18 |
* @uses get_option() |
| 19 |
* @uses bbp_get_db_version() To get bbPress's database version |
| 20 |
* @return bool True if update, False if not |
| 21 |
*/ |
| 22 |
function bbp_is_update() { |
| 23 |
|
| 24 |
// Current DB version of this site (per site in a multisite network) |
| 25 |
$current_db = get_option( '_bbp_db_version' ); |
| 26 |
$current_live = bbp_get_db_version(); |
| 27 |
|
| 28 |
// Compare versions (cast as int and bool to be safe) |
| 29 |
$is_update = (bool) ( (int) $current_db < (int) $current_live ); |
| 30 |
|
| 31 |
// Return the product of version comparison |
| 32 |
return $is_update; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Determine if bbPress is being activated |
| 37 |
* |
| 38 |
* @since bbPress (r3421) |
| 39 |
* |
| 40 |
* @global bbPress $bbp |
| 41 |
* @return bool True if activating bbPress, false if not |
| 42 |
*/ |
| 43 |
function bbp_is_activation( $basename = '' ) { |
| 44 |
global $bbp; |
| 45 |
|
| 46 |
// Baif if action or plugin are empty |
| 47 |
if ( empty( $_GET['action'] ) || empty( $_GET['plugin'] ) ) |
| 48 |
return false; |
| 49 |
|
| 50 |
// Bail if not activating |
| 51 |
if ( 'activate' !== $_GET['action'] ) |
| 52 |
return false; |
| 53 |
|
| 54 |
// The plugin being activated |
| 55 |
$plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : ''; |
| 56 |
|
| 57 |
// Set basename if empty |
| 58 |
if ( empty( $basename ) && !empty( $bbp->basename ) ) |
| 59 |
$basename = $bbp->basename; |
| 60 |
|
| 61 |
// Bail if no basename |
| 62 |
if ( empty( $basename ) ) |
| 63 |
return false; |
| 64 |
|
| 65 |
// Bail if plugin is not bbPress |
| 66 |
if ( $basename !== $_GET['plugin'] ) |
| 67 |
return false; |
| 68 |
|
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Determine if bbPress is being deactivated |
| 74 |
* |
| 75 |
* @since bbPress (r3421) |
| 76 |
* @global bbPress $bbp |
| 77 |
* @return bool True if deactivating bbPress, false if not |
| 78 |
*/ |
| 79 |
function bbp_is_deactivation( $basename = '' ) { |
| 80 |
global $bbp; |
| 81 |
|
| 82 |
// Baif if action or plugin are empty |
| 83 |
if ( empty( $_GET['action'] ) || empty( $_GET['plugin'] ) ) |
| 84 |
return false; |
| 85 |
|
| 86 |
// Bail if not deactivating |
| 87 |
if ( 'deactivate' !== $_GET['action'] ) |
| 88 |
return false; |
| 89 |
|
| 90 |
// The plugin being deactivated |
| 91 |
$plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : ''; |
| 92 |
|
| 93 |
// Set basename if empty |
| 94 |
if ( empty( $basename ) && !empty( $bbp->basename ) ) |
| 95 |
$basename = $bbp->basename; |
| 96 |
|
| 97 |
// Bail if no basename |
| 98 |
if ( empty( $basename ) ) |
| 99 |
return false; |
| 100 |
|
| 101 |
// Bail if plugin is not bbPress |
| 102 |
if ( $basename !== $plugin ) |
| 103 |
return false; |
| 104 |
|
| 105 |
return true; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Update the DB to the latest version |
| 110 |
* |
| 111 |
* @since bbPress (r3421) |
| 112 |
* @uses update_option() |
| 113 |
* @uses bbp_get_db_version() To get bbPress's database version |
| 114 |
*/ |
| 115 |
function bbp_version_bump() { |
| 116 |
$db_version = bbp_get_db_version(); |
| 117 |
update_option( '_bbp_db_version', $db_version ); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Setup the bbPress updater |
| 122 |
* |
| 123 |
* @since bbPress (r3419) |
| 124 |
* |
| 125 |
* @global bbPress $bbp |
| 126 |
* @uses BBP_Updater |
| 127 |
*/ |
| 128 |
function bbp_setup_updater() { |
| 129 |
|
| 130 |
// Are we running an outdated version of bbPress? |
| 131 |
if ( bbp_is_update() ) { |
| 132 |
|
| 133 |
// Bump the version |
| 134 |
bbp_version_bump(); |
| 135 |
|
| 136 |
// Run the deactivation function to wipe roles, caps, and rewrite rules |
| 137 |
bbp_deactivation(); |
| 138 |
|
| 139 |
// Run the activation function to reset roles, caps, and rewrite rules |
| 140 |
bbp_activation(); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
?> |
| 145 |
|