/**
 * Load either 1.0 or 2.0 theme engine, based on several critical and evolving criteron.
 * Theme and plugin developers are advised to check and filter this function as needed.
 *
 * @since  3.9
 *
 * @return bool $activate Whether or not to activate the 2.0 theme engine.
 */
function _wpsc_maybe_activate_theme_engine_v2()
{
    $activate = false;
    global $wp_rewrite;
    if (!is_a($wp_rewrite, 'WP_Rewrite')) {
        $wp_rewrite = new WP_Rewrite();
    }
    // The theme engine routing mechanism (WPSC_Router) is not currently equipped to work without pretty permalinks.
    if (!$wp_rewrite->using_permalinks()) {
        $activate = false;
    }
    // We're also not currently able to work as expected when using "Almost Pretty" permalinks, where PATHINFO is not enabled.
    if ($wp_rewrite->using_index_permalinks()) {
        $activate = false;
    }
    // In the future, this check will be more refined.  As of 3.9, the current Gold Cart release is incompatible with the 2.0 theme engine.
    if (defined('WPSC_GOLD_VERSION')) {
        $activate = false;
    }
    // If an active theme is dependent on 1.0 theme template files from 3.8.
    if (_wpsc_theme_engine_v2_has_old_templates()) {
        $activate = false;
    }
    // If any plugins or theme functionality are hooking into 1.0 template hooks, we don't activate 2.0.
    if (_wpsc_theme_engine_v1_has_actions()) {
        $activate = false;
    }
    $activate = apply_filters('_wpsc_maybe_activate_theme_engine_v2', $activate);
    $new_theme_engine = $activate ? '2.0' : '1.0';
    $old_theme_engine = get_option('wpsc_get_active_theme_engine');
    if ($old_theme_engine !== $new_theme_engine) {
        do_action('wpsc_updated_theme_engine', $new_theme_engine, $old_theme_engine);
        do_action("wpsc_updated_theme_engine_from_{$old_theme_engine}_to_{$new_theme_engine}");
        add_action('shutdown', '_wpsc_action_flush_rewrite_rules');
        update_option('wpsc_get_active_theme_engine', $new_theme_engine);
    }
    return $activate;
}
/**
 * Load either 1.0 or 2.0 theme engine, based on several critical and evolving criteron.
 * Theme and plugin developers are advised to check and filter this function as needed.
 *
 * @since  3.9
 *
 * @return bool $activate Whether or not to activate the 2.0 theme engine.
 */
function _wpsc_maybe_activate_theme_engine_v2()
{
    $activate = true;
    global $wp_rewrite;
    if (!is_a($wp_rewrite, 'WP_Rewrite')) {
        $wp_rewrite = new WP_Rewrite();
    }
    // The theme engine routing mechanism (WPSC_Router) is not currently equipped to work without pretty permalinks.
    if (!$wp_rewrite->using_permalinks()) {
        $activate = false;
    }
    // We're also not currently able to work as expected when using "Almost Pretty" permalinks, where PATHINFO is not enabled.
    if ($wp_rewrite->using_index_permalinks()) {
        $activate = false;
    }
    // In the future, this check will be more refined.  As of 3.9, the current Gold Cart release is incompatible with the 2.0 theme engine.
    if (defined('WPSC_GOLD_VERSION')) {
        $activate = false;
    }
    // If an active theme is dependent on 1.0 theme template files from 3.8.
    if (_wpsc_theme_engine_v2_has_old_templates()) {
        $activate = false;
    }
    // If any plugins or theme functionality are hooking into 1.0 template hooks, we don't activate 2.0.
    if (_wpsc_theme_engine_v1_has_actions()) {
        $activate = false;
    }
    $activate = apply_filters('_wpsc_maybe_activate_theme_engine_v2', $activate);
    $new_theme_engine = $activate ? '2.0' : '1.0';
    $old_theme_engine = get_option('wpsc_get_active_theme_engine');
    if ($old_theme_engine !== $new_theme_engine) {
        // _wpsc_action_flush_rewrite_rules lives here.
        require_once WPSC_FILE_PATH . '/wpsc-admin/init.php';
        do_action('wpsc_updated_theme_engine', $new_theme_engine, $old_theme_engine);
        do_action("wpsc_updated_theme_engine_from_{$old_theme_engine}_to_{$new_theme_engine}");
        add_action('shutdown', '_wpsc_action_flush_rewrite_rules');
        update_option('wpsc_get_active_theme_engine', $new_theme_engine);
        $location = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : home_url();
        // Redirect ensures that both templates will not be loaded, fixing fatal errors, etc.
        wp_safe_redirect(esc_url_raw($location));
        exit;
    }
    return $activate;
}
/**
 * Load either 1.0 or 2.0 theme engine, based on several critical and evolving criteron.
 * Theme and plugin developers are advised to check and filter this function as needed.
 *
 * @since  3.9
 * @return bool $activate Whether or not to activate the 2.0 theme engine.
 */
function _wpsc_maybe_activate_theme_engine_v2()
{
    $activate = true;
    global $wp_rewrite;
    if (!is_a($wp_rewrite, 'WP_Rewrite')) {
        $wp_rewrite = new WP_Rewrite();
    }
    // The theme engine routing mechanism (WPSC_Router) is not currently equipped to work without pretty permalinks.
    if (!$wp_rewrite->using_permalinks()) {
        $activate = false;
    }
    // We're also not currently able to work as expected when using "Almost Pretty" permalinks, where PATHINFO is not enabled.
    if ($wp_rewrite->using_index_permalinks()) {
        $activate = false;
    }
    // In the future, this check will be more refined.  As of 3.9, the current Gold Cart release is incompatible with the 2.0 theme engine.
    if (defined('WPSC_GOLD_VERSION')) {
        $activate = false;
    }
    // If an active theme is dependent on 1.0 theme template files from 3.8.
    if (_wpsc_theme_engine_v2_has_old_templates()) {
        $activate = false;
    }
    // If any plugins or theme functionality are hooking into 1.0 template hooks, we don't activate 2.0.
    if (_wpsc_theme_engine_v1_has_actions()) {
        $activate = false;
    }
    return apply_filters('_wpsc_maybe_activate_theme_engine_v2', $activate);
}