| | 1248 | /** |
| | 1249 | * plugin_disable_self() - When called will disable the current plugin |
| | 1250 | * |
| | 1251 | * Allows plugins a simple way to disable their plugin during the |
| | 1252 | * pre-upgrade process. The plugin just has to call the function and it |
| | 1253 | * will do all the work. |
| | 1254 | * |
| | 1255 | * Also a safer way, in case the way plugins are enabled changes. |
| | 1256 | * |
| | 1257 | * @uses $current_plugin_processed Disables current plugin |
| | 1258 | */ |
| | 1259 | function plugin_disable_self() { |
| | 1260 | global $current_plugin_processed; |
| | 1261 | |
| | 1262 | $plugins = __get_option( 'active_plugins' ); |
| | 1263 | |
| | 1264 | foreach ( (array) $plugins as $plugin ) { |
| | 1265 | if ( $current_plugin_processed == $plugin ) { |
| | 1266 | array_splice( $plugins, array_search( $plugin, $plugins ), 1 ); |
| | 1267 | update_option( 'active_plugins', $plugins ); |
| | 1268 | break; |
| | 1269 | } |
| | 1270 | } |
| | 1271 | } |
| | 1272 | |
| | 1273 | /** |
| | 1274 | * plugin_enable_self() - When called will enable the current plugin |
| | 1275 | * |
| | 1276 | * Companion of plugin_disable_self(), will enable the plugin if it disabled |
| | 1277 | * itself. Real simple way of enabling a plugin that disabled itself and is |
| | 1278 | * future proof, in case the plugin activation is changed. |
| | 1279 | * |
| | 1280 | * @uses $current_plugin_processed Enables the current plugin |
| | 1281 | */ |
| | 1282 | function plugin_enable_self() { |
| | 1283 | global $current_plugin_processed; |
| | 1284 | |
| | 1285 | $plugins = __get_option( 'active_plugins' ); |
| | 1286 | |
| | 1287 | // Prevent duplicate plugin entries if the plugin did not disable itself. |
| | 1288 | if( false === in_array($current_plugin_processed, $plugins) ) |
| | 1289 | $plugins[] = $current_plugin_processed; |
| | 1290 | |
| | 1291 | sort($plugins); |
| | 1292 | update_option( 'active_plugins', $plugins ); |
| | 1293 | } |
| | 1294 | |
| | 1295 | /** |
| | 1296 | * Called before upgrade for plugins to clean up. |
| | 1297 | * |
| | 1298 | * Plugins must not die during their call. Plugins will be able to enable themselves |
| | 1299 | * after the upgrade has been made and the result of the pre-upgrade hook will be passed |
| | 1300 | * to the post upgrade plugin hook. |
| | 1301 | * |
| | 1302 | * @uses apply_filters() Calls pre_upgrade_PLUGIN PLUGIN is the path from PLUGINDIR. |
| | 1303 | * @global string $current_plugin_processed Sets the current plugin processed value |
| | 1304 | * @since 2.4 |
| | 1305 | * |
| | 1306 | * @returns array The results of the plugins upgrade hook |
| | 1307 | */ |
| | 1308 | function wp_call_pre_upgrade_hook() |
| | 1309 | { |
| | 1310 | global $current_plugin_processed; |
| | 1311 | |
| | 1312 | $plugin_pre_upgrade = array(); |
| | 1313 | $current_plugins = __get_option('active_plugins'); |
| | 1314 | if ( is_array($current_plugins) ) { |
| | 1315 | foreach ($current_plugins as $plugin) { |
| | 1316 | if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin)) { |
| | 1317 | // Use '@' to prevent errors from halting the rest of the upgrade process |
| | 1318 | @include_once(ABSPATH . PLUGINDIR . '/' . $plugin); |
| | 1319 | |
| | 1320 | $current_plugin_processed = $plugin; |
| | 1321 | $plugin_pre_upgrade[ $plugin ] = apply_filters('pre_upgrade_'.$plugin, null); |
| | 1322 | } |
| | 1323 | } |
| | 1324 | } |
| | 1325 | |
| | 1326 | return $plugin_pre_upgrade; |
| | 1327 | } |
| | 1328 | |
| | 1329 | /** |
| | 1330 | * Called for plugins after the WordPress upgrade process has been made. |
| | 1331 | * |
| | 1332 | * The result of the pre-upgrade process for the plugin is passed to the plugin |
| | 1333 | * from the pre upgrade process. The plugin can use this as they will. The plugin |
| | 1334 | * may also output their status for the user to see on the upgrade page to provide |
| | 1335 | * feedback. |
| | 1336 | * |
| | 1337 | * @uses do_action() Calls post_upgrade_PLUGIN where PLUGIN is the path of the plugin from PLUGINDIR |
| | 1338 | * @since 2.4 |
| | 1339 | * @param array $pre_upgrade Passed the array from the pre upgrade |
| | 1340 | */ |
| | 1341 | function wp_call_post_upgrade_hook($pre_upgrade) |
| | 1342 | { |
| | 1343 | global $current_plugin_processed; |
| | 1344 | |
| | 1345 | if ( is_array($pre_upgrade) ) { |
| | 1346 | foreach ($pre_upgrade as $plugin => $result) { |
| | 1347 | $current_plugin_processed = $plugin; |
| | 1348 | do_action( 'post_upgrade_'.$plugin, $result ); |
| | 1349 | } |
| | 1350 | } |
| | 1351 | } |
| | 1352 | |