WordPress.org

Make WordPress Core

Ticket #2927: pre.post.upgrade-hooks.patch

File pre.post.upgrade-hooks.patch, 2.1 KB (added by darkdragon, 10 years ago)

Draft for opinions on pre and post plugin hooks

  • upgrade.php

     
    144144        if ( $wp_db_version == $wp_current_db_version )
    145145                return;
    146146
     147        $plugin_results = wp_call_pre_upgrade_hook();
    147148        wp_check_mysql_version();
    148149        wp_cache_flush();
    149150        make_db_current_silent();
    150151        upgrade_all();
    151152        wp_cache_flush();
     153        wp_call_post_upgrade_hook($plugin_results);
    152154}
    153155endif;
    154156
     
    12431245        }
    12441246}
    12451247
     1248/**
     1249 * Called before upgrade for plugins to clean up.
     1250 *
     1251 * Plugins must not die during their call. Plugins will be able to enable themselves
     1252 * after the upgrade has been made and the result of the pre-upgrade hook will be passed
     1253 * to the post upgrade plugin hook.
     1254 *
     1255 * @uses apply_filters() Calls pre_upgrade_PLUGIN PLUGIN is the path from PLUGINDIR.
     1256 *
     1257 * @returns array The results of the
     1258 */
     1259function wp_call_pre_upgrade_hook()
     1260{
     1261        $plugin_pre_upgrade = array();
     1262        $current_plugins = __get_option('active_plugins');
     1263        if ( is_array($current_plugins) ) {
     1264                foreach ($current_plugins as $plugin) {
     1265                        if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin)) {
     1266                                include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
     1267
     1268                                $plugin_pre_upgrade[ $plugin ] = apply_filters('pre_upgrade_'.$plugin, null);
     1269                        }
     1270                }
     1271        }
     1272
     1273        return $plugin_pre_upgrade;
     1274}
     1275
     1276/**
     1277 * Called for plugins after the WordPress upgrade process has been made.
     1278 *
     1279 * The results of the pre-upgrade process is passed to the plugin from the pre
     1280 * upgrade process. The plugin can use this as they will. The plugin may also
     1281 * output their status for the user to see on the upgrade page to provide feedback.
     1282 *
     1283 * @uses do_action() Calls post_upgrade_PLUGIN where PLUGIN is the path of the plugin from PLUGINDIR
     1284 * @param array $pre_upgrade Passed the array from the pre upgrade
     1285 */
     1286function wp_call_post_upgrade_hook($pre_upgrade)
     1287{
     1288        if ( is_array($pre_upgrade) ) {
     1289                foreach ($pre_upgrade as $plugin => $result) {
     1290                        do_action( 'post_upgrade_'.$plugin, $result );
     1291                }
     1292        }
     1293}
     1294
    12461295function wp_check_mysql_version() {
    12471296        global $wpdb;
    12481297        $result = $wpdb->check_database_version();