Beispiel #1
0
/**
 * @action   wp_stream_after_connectors_registration
 * @return string $current_version if updated correctly
 */
function wp_stream_update_migrate_installer_edits_to_theme_editor_connector()
{
    global $wpdb;
    $db_version = WP_Stream_Install::$db_version;
    $current_version = WP_Stream_Install::$current;
    $args = array('connector' => 'installer', 'context' => 'themes', 'action' => 'edited');
    $records = wp_stream_query($args);
    foreach ($records as $record) {
        $file_name = wp_stream_get_meta($record->ID, 'file', true);
        $theme_name = wp_stream_get_meta($record->ID, 'name', true);
        if ('' !== $theme_name) {
            $matched_themes = array_filter(wp_get_themes(), function ($theme) use($theme_name) {
                return (string) $theme === $theme_name;
            });
            $theme = array_shift($matched_themes);
            // `stream`
            $wpdb->update($wpdb->stream, array('summary' => sprintf(WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name)), array('ID' => $record->ID));
            // `stream_context`
            $wpdb->update($wpdb->streamcontext, array('connector' => 'editor', 'context' => is_object($theme) ? $theme->get_template() : $theme_name, 'action' => 'updated'), array('record_id' => $record->ID));
            wp_stream_update_meta($record->ID, 'theme_name', $theme_name);
            if (is_object($theme)) {
                wp_stream_update_meta($record->ID, 'theme_slug', $theme->get_template());
            }
        }
    }
    do_action('wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error);
    if ($wpdb->last_error) {
        return false;
    }
    return $current_version;
}