response ) ) { return false; } $bizznis_update = $bizznis_update->response; if ( ! isset( $bizznis_update['bizznis'] ) ) { return false; } else { $bizznis_update = $bizznis_update['bizznis']; } # If we're already using the latest version, return false if ( version_compare( PARENT_THEME_VERSION, $bizznis_update['new_version'], '>=' ) ) { return false; } return $bizznis_update; } /** * Update Bizznis to the latest version. * * This iterative update function will take a Bizznis installation, no matter * how old, and update its options to the latest version. * * It used to iterate over theme version, but now uses a database version * system, which allows for changes within pre-releases, too. * * @since 1.0.0 */ add_action( 'admin_init', 'bizznis_upgrade', 20 ); function bizznis_upgrade() { # Don't do anything if we're on the latest version if ( bizznis_get_option( 'db_version', null, false ) >= PARENT_DB_VERSION ) { return; } /* ######################### # UPDATE TO VERSION 1.0. ######################### if ( version_compare( bizznis_get_option( 'theme_version', null, false ), '1.9', '<' ) ) { # Vestige nav settings, for backward compatibility if ( 'nav-menu' != bizznis_get_option( 'nav_type' ) ) { _bizznis_vestige( array( 'nav_type', 'nav_superfish', 'nav_home', 'nav_pages_sort', 'nav_categories_sort', 'nav_depth', 'nav_exclude', 'nav_include', ) ); } # Vestige subnav settings, for backward compatibility if ( 'nav-menu' != bizznis_get_option( 'subnav_type' ) ) { _bizznis_vestige( array( 'subnav_type', 'subnav_superfish', 'subnav_home', 'subnav_pages_sort', 'subnav_categories_sort', 'subnav_depth', 'subnav_exclude', 'subnav_include', ) ); } $theme_settings = get_option( BIZZNIS_SETTINGS_FIELD ); $new_settings = array( 'theme_version' => '1.6', ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( BIZZNIS_SETTINGS_FIELD, $settings ); } */ # UPDATE DB TO VERSION 1008 if ( bizznis_get_option( 'db_version', null, false ) < '1008' ) { bizznis_upgrade_1008(); } do_action( 'bizznis_upgrade' ); } /** * Upgrade the database to version 1008. * * @since 1.0.8 */ function bizznis_upgrade_1008() { # Update Settings _bizznis_update_settings( array( 'theme_version' => '1.0.8', 'db_version' => '1008', ) ); } /** * Redirects the user back to the theme settings page, refreshing the data and * notifying the user that they have successfully updated. * * @since 1.0.0 */ add_action( 'bizznis_upgrade', 'bizznis_upgrade_redirect' ); function bizznis_upgrade_redirect() { if ( ! is_admin() || ! current_user_can( 'edit_theme_options' ) ) { return; } bizznis_admin_redirect( 'bizznis-about' ); exit; } /** * Displays the notice that the theme settings were successfully updated to the * latest version. * * Currently, only used for pre-release update notices. * * @since 1.0.0 */ add_action( 'admin_notices', 'bizznis_upgraded_notice' ); function bizznis_upgraded_notice() { if ( ! bizznis_is_menu_page( 'bizznis' ) ) { return; } if ( isset( $_REQUEST['upgraded'] ) && 'true' == $_REQUEST['upgraded'] ) { echo '

' . sprintf( __( 'Congratulations! You are now rocking Bizznis %s', 'bizznis' ), bizznis_get_option( 'theme_version' ) ) . '

'; } } /** * Filters the action links at the end of an update. * * This function filters the action links that are presented to the * user at the end of a theme update. If the theme being updated is * not Bizznis, the filter returns the default values. Otherwise, * it will provide a link to the Bizznis Theme Settings page, which * will trigger the database/settings upgrade. * * @since 1.0.0 */ add_filter( 'update_theme_complete_actions', 'bizznis_update_action_links', 10, 2 ); function bizznis_update_action_links( $actions, $theme ) { if ( 'bizznis' != $theme ) { return $actions; } return sprintf( '%s', menu_page_url( 'bizznis', 0 ), __( 'Click here to complete the upgrade', 'bizznis' ) ); } /** * Displays the update nag at the top of the dashboard if there is a Bizznis * update available. * * @since 1.0.0 */ add_action( 'admin_notices', 'bizznis_update_nag' ); function bizznis_update_nag() { $bizznis_update = bizznis_update_check(); if ( ! is_super_admin() || ! $bizznis_update ) { return false; } echo '
'; printf( __( 'Bizznis %s is available. Update now.', 'bizznis' ), esc_html( $bizznis_update['new_version'] ), wp_nonce_url( 'update.php?action=upgrade-theme&theme=bizznis', 'upgrade-theme_bizznis' ), esc_js( __( 'Upgrading Bizznis will overwrite the current installed version of Bizznis. Are you sure you want to upgrade?. "Cancel" to stop, "OK" to upgrade.', 'bizznis' ) ) ); echo '
'; } /** * Converts array of keys from Bizznis options to vestigial options. * This is done for backwards compatibility. * * @since 1.0.0 */ function _bizznis_vestige( $keys = array(), $setting = BIZZNIS_SETTINGS_FIELD ) { # If no $keys passed, do nothing if ( ! $keys ) { return; } # Pull options $options = get_option( $setting ); $vestige = get_option( 'bizznis-vestige' ); # Cycle through $keys, creating new vestige array $new_vestige = array(); foreach ( (array) $keys as $key ) { if ( isset( $options[$key] ) ) { $new_vestige[$key] = $options[$key]; unset( $options[$key] ); } } # If no new vestigial options being pushed, do nothing if ( ! $new_vestige ) { return; } # Merge the arrays, if necessary $vestige = $vestige ? wp_parse_args( $new_vestige, $vestige ) : $new_vestige; # Insert into options table update_option( 'bizznis-vestige', $vestige ); update_option( $setting, $options ); }