array( 'genesis_version' => PARENT_THEME_VERSION, 'html5' => genesis_html5(), 'php_version' => phpversion(), 'uri' => home_url(), 'stylesheet' => get_stylesheet(), 'user-agent' => "WordPress/$wp_version;", 'wp_version' => $wp_version, ), ) ); $response = wp_remote_post( $url, $options ); $response_body = wp_remote_retrieve_body( $response ); // If an error occurred, return FALSE, store for 1 hour. if ( 'error' === $response_body || is_wp_error( $response_body ) || ! is_serialized( $response_body ) ) { $genesis_update = array( 'new_version' => PARENT_THEME_VERSION, ); set_transient( 'genesis-update', $genesis_update, HOUR_IN_SECONDS ); return array(); } // Else, unserialize. $genesis_update = maybe_unserialize( $response_body ); // And store in transient for 24 hours. set_transient( 'genesis-update', $genesis_update, DAY_IN_SECONDS ); } // If we're already using the latest version, return empty array. if ( version_compare( PARENT_THEME_VERSION, $genesis_update['new_version'], '>=' ) ) { return array(); } return $genesis_update; } /** * Upgrade the database to latest version. * * @since 2.6.0 */ function genesis_upgrade_db_latest() { // Update Settings. genesis_update_settings( array( 'theme_version' => PARENT_THEME_VERSION, 'db_version' => PARENT_DB_VERSION, 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2603. * * @since 2.6.1 */ function genesis_upgrade_2603() { genesis_unslash_post_meta_scripts(); genesis_update_settings( array( 'header_scripts' => stripslashes( genesis_get_option( 'header_scripts' ) ), 'footer_scripts' => stripslashes( genesis_get_option( 'footer_scripts' ) ), 'theme_version' => '2.6.1', 'db_version' => '2603', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2501. * * @since 2.5.0 */ function genesis_upgrade_2501() { if ( genesis_get_seo_option( 'semantic_headings', false ) ) { genesis_update_settings( array( 'semantic_headings' => 'unset', ), GENESIS_SEO_SETTINGS_FIELD ); } // Update Settings. genesis_update_settings( array( 'theme_version' => '2.5.0', 'db_version' => '2501', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2403. * * @since 2.4.2 */ function genesis_upgrade_2403() { // Update Settings. genesis_update_settings( array( 'theme_version' => '2.4.2', 'db_version' => '2403', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2209. * * @since 2.2.6 */ function genesis_upgrade_2209() { $term_meta = get_option( 'genesis-term-meta' ); foreach ( (array) $term_meta as $term_id => $meta ) { foreach ( (array) $meta as $key => $value ) { add_term_meta( $term_id, $key, $value, true ); } } // Update Settings. genesis_update_settings( array( 'theme_version' => '2.2.6', 'db_version' => '2209', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2207. * * @since 2.2.4 */ function genesis_upgrade_2207() { $update_email_address = genesis_get_option( 'update_email' ) ? genesis_get_option( 'update_email_address' ) : ''; // Update Settings. genesis_update_settings( array( 'theme_version' => '2.2.4', 'db_version' => '2207', 'update_email' => 'unset', 'update_email_address' => $update_email_address, 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2201. * * @since 2.2.0 */ function genesis_upgrade_2201() { // Update Settings. genesis_update_settings( array( 'theme_version' => '2.2.0-beta2', 'db_version' => '2201', 'upgrade' => 1, ) ); // Update SEO Settings. genesis_update_settings( array( 'canonical_archives' => 'unset', ), GENESIS_SEO_SETTINGS_FIELD ); } /** * Upgrade the database to version 2100. * * @since 2.1.0 */ function genesis_upgrade_2100() { // Update Settings. genesis_update_settings( array( 'db_version' => '2100', 'image_alignment' => 'alignleft', 'first_version' => '2.0.2', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2003. * * @since 2.0.0 */ function genesis_upgrade_2003() { // Update Settings. genesis_update_settings( array( 'superfish' => genesis_get_option( 'nav_superfish', null, 0 ) || genesis_get_option( 'subnav_superfish', null, 0 ) ? 1 : 0, 'db_version' => '2003', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 2001. * * @since 2.0.0 */ function genesis_upgrade_2001() { // Update Settings. genesis_update_settings( array( 'nav_extras' => genesis_get_option( 'nav_extras_enable', null, 0 ) ? genesis_get_option( 'nav_extras', null, 0 ) : '', 'db_version' => '2001', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 1901. * * @since 1.9.0 */ function genesis_upgrade_1901() { // Get menu locations. $menu_locations = get_theme_mod( 'nav_menu_locations' ); // Clear assigned nav if nav disabled. if ( $menu_locations['primary'] && ! genesis_get_option( 'nav' ) ) { $menu_locations['primary'] = 0; set_theme_mod( 'nav_menu_locations', $menu_locations ); } // Clear assigned subnav if subnav disabled. if ( $menu_locations['secondary'] && ! genesis_get_option( 'subnav' ) ) { $menu_locations['secondary'] = 0; set_theme_mod( 'nav_menu_locations', $menu_locations ); } // Update Settings. genesis_update_settings( array( 'db_version' => '1901', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 1800. * * @since 1.8.0 */ function genesis_upgrade_1800() { // Convert term meta for new title/description options. genesis_convert_term_meta(); // Update Settings. genesis_update_settings( array( 'db_version' => '1800', 'upgrade' => 1, ) ); } /** * Upgrade the database to version 1700. * * Also removes old user meta box options, as the UI changed. * * @since 1.7.0 * * @global wpdb $wpdb WordPress database object. */ function genesis_upgrade_1700() { global $wpdb; // Changing the UI. Remove old user options. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key = %s OR meta_key = %s", 'meta-box-order_toplevel_page_genesis', 'meta-box-order_genesis_page_seosettings' ) ); $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->usermeta SET meta_value = %s WHERE meta_key = %s OR meta_key = %s", '1', 'screen_layout_toplevel_page_genesis', 'screen_layout_genesis_page_seosettings' ) ); // Update Settings. genesis_update_settings( array( 'db_version' => '1700', 'upgrade' => 1, ) ); } /** * Convert term meta for new title/description options. * * Called in `genesis_upgrade_1800()`. * * @since 2.6.0 */ function genesis_convert_term_meta() { // Convert term meta for new title/description options. $terms = get_terms( get_taxonomies(), array( 'hide_empty' => false, ) ); $term_meta = get_option( 'genesis-term-meta' ); foreach ( (array) $terms as $term ) { if ( isset( $term_meta[ $term->term_id ]['display_title'] ) && $term_meta[ $term->term_id ]['display_title'] ) { $term_meta[ $term->term_id ]['headline'] = $term->name; } if ( isset( $term_meta[ $term->term_id ]['display_description'] ) && $term_meta[ $term->term_id ]['display_description'] ) { $term_meta[ $term->term_id ]['intro_text'] = $term->description; } } update_option( 'genesis-term-meta', $term_meta ); } /** * Strip slashes from header and body scripts saved as post meta. * * Called in `genesis_upgrade_2603()`. * * @since 2.6.1 */ function genesis_unslash_post_meta_scripts() { global $wpdb; $header_scripts_posts = $wpdb->get_results( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_genesis_scripts'" ); $body_scripts_posts = $wpdb->get_results( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_genesis_scripts_body'" ); foreach ( $header_scripts_posts as $post ) { if ( ! empty( $post->post_id ) ) { update_post_meta( $post->post_id, '_genesis_scripts', get_post_meta( $post->post_id, '_genesis_scripts', 1 ) ); } } foreach ( $body_scripts_posts as $post ) { if ( ! empty( $post->post_id ) ) { update_post_meta( $post->post_id, '_genesis_scripts_body', get_post_meta( $post->post_id, '_genesis_scripts_body', 1 ) ); } } } add_action( 'admin_init', 'genesis_upgrade', 20 ); /** * Update Genesis to the latest version. * * This iterative update function will take a Genesis 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.1 * * @return void Return early if we're already on the latest version. */ function genesis_upgrade() { // Don't do anything if we're on the latest version. if ( genesis_get_option( 'db_version', null, false ) >= PARENT_DB_VERSION ) { return; } global $wp_db_version; // If the WP db hasn't been upgraded, make them upgrade first. if ( get_option( 'db_version' ) != $wp_db_version ) { wp_redirect( admin_url( 'upgrade.php?_wp_http_referer=' . urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); exit; } // UPDATE TO VERSION 1.0.1. if ( version_compare( genesis_get_option( 'theme_version', null, false ), '1.0.1', '<' ) ) { $theme_settings = get_option( GENESIS_SETTINGS_FIELD ); $new_settings = array( 'nav_home' => 1, 'nav_twitter_text' => 'Follow me on Twitter', 'subnav_home' => 1, 'theme_version' => '1.0.1', 'upgrade' => 1, ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( GENESIS_SETTINGS_FIELD, $settings ); } // UPDATE TO VERSION 1.1. if ( version_compare( genesis_get_option( 'theme_version', null, false ), '1.1', '<' ) ) { $theme_settings = get_option( GENESIS_SETTINGS_FIELD ); $new_settings = array( 'content_archive_thumbnail' => genesis_get_option( 'thumbnail' ), 'theme_version' => '1.1', 'upgrade' => 1, ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( GENESIS_SETTINGS_FIELD, $settings ); } // UPDATE TO VERSION 1.1.2. if ( version_compare( genesis_get_option( 'theme_version', null, false ), '1.1.2', '<' ) ) { $theme_settings = get_option( GENESIS_SETTINGS_FIELD ); $new_settings = array( 'header_right' => genesis_get_option( 'header_full' ) ? 0 : 1, 'nav_superfish' => 1, 'subnav_superfish' => 1, 'nav_extras_enable' => genesis_get_option( 'nav_right' ) ? 1 : 0, 'nav_extras' => genesis_get_option( 'nav_right' ), 'nav_extras_twitter_id' => genesis_get_option( 'twitter_id' ), 'nav_extras_twitter_text' => genesis_get_option( 'nav_twitter_text' ), 'theme_version' => '1.1.2', 'upgrade' => 1, ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( GENESIS_SETTINGS_FIELD, $settings ); } // UPDATE TO VERSION 1.2. if ( version_compare( genesis_get_option( 'theme_version', null, false ), '1.2', '<' ) ) { $theme_settings = get_option( GENESIS_SETTINGS_FIELD ); $new_settings = array( 'update' => 1, 'theme_version' => '1.2', 'upgrade' => 1, ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( GENESIS_SETTINGS_FIELD, $settings ); } // UPDATE TO VERSION 1.3. if ( version_compare( genesis_get_option( 'theme_version', null, false ), '1.3', '<' ) ) { // Update theme settings. $theme_settings = get_option( GENESIS_SETTINGS_FIELD ); $new_settings = array( 'author_box_single' => genesis_get_option( 'author_box' ), 'theme_version' => '1.3', 'upgrade' => 1, ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( GENESIS_SETTINGS_FIELD, $settings ); // Update SEO settings. $seo_settings = get_option( GENESIS_SEO_SETTINGS_FIELD ); $new_settings = array( 'noindex_cat_archive' => genesis_get_seo_option( 'index_cat_archive' ) ? 0 : 1, 'noindex_tag_archive' => genesis_get_seo_option( 'index_tag_archive' ) ? 0 : 1, 'noindex_author_archive' => genesis_get_seo_option( 'index_author_archive' ) ? 0 : 1, 'noindex_date_archive' => genesis_get_seo_option( 'index_date_archive' ) ? 0 : 1, 'noindex_search_archive' => genesis_get_seo_option( 'index_search_archive' ) ? 0 : 1, 'noodp' => 1, 'noydir' => 1, 'canonical_archives' => 1, ); $settings = wp_parse_args( $new_settings, $seo_settings ); update_option( GENESIS_SEO_SETTINGS_FIELD, $settings ); // Delete the store transient, force refresh. delete_transient( 'genesis-remote-store' ); } // UPDATE TO VERSION 1.6. if ( version_compare( genesis_get_option( 'theme_version', null, false ), '1.6', '<' ) ) { // Vestige nav settings, for backward compatibility. if ( 'nav-menu' !== genesis_get_option( 'nav_type' ) ) { _genesis_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' !== genesis_get_option( 'subnav_type' ) ) { _genesis_vestige( array( 'subnav_type', 'subnav_superfish', 'subnav_home', 'subnav_pages_sort', 'subnav_categories_sort', 'subnav_depth', 'subnav_exclude', 'subnav_include' ) ); } $theme_settings = get_option( GENESIS_SETTINGS_FIELD ); $new_settings = array( 'theme_version' => '1.6', 'upgrade' => 1, ); $settings = wp_parse_args( $new_settings, $theme_settings ); update_option( GENESIS_SETTINGS_FIELD, $settings ); } // UPDATE DB TO VERSION 1700. if ( genesis_get_option( 'db_version', null, false ) < '1700' ) { genesis_upgrade_1700(); } // UPDATE DB TO VERSION 1800. if ( genesis_get_option( 'db_version', null, false ) < '1800' ) { genesis_upgrade_1800(); } // UPDATE DB TO VERSION 1901. if ( genesis_get_option( 'db_version', null, false ) < '1901' ) { genesis_upgrade_1901(); } // UPDATE DB TO VERSION 2001. if ( genesis_get_option( 'db_version', null, false ) < '2001' ) { genesis_upgrade_2001(); } // UPDATE DB TO VERSION 2003. if ( genesis_get_option( 'db_version', null, false ) < '2003' ) { genesis_upgrade_2003(); } // UPDATE DB TO VERSION 2100. if ( genesis_get_option( 'db_version', null, false ) < '2100' ) { genesis_upgrade_2100(); } // UPDATE DB TO VERSION 2201. if ( genesis_get_option( 'db_version', null, false ) < '2201' ) { genesis_upgrade_2201(); } // UPDATE DB TO VERSION 2207. if ( genesis_get_option( 'db_version', null, false ) < '2207' ) { genesis_upgrade_2207(); } // UPDATE DB TO VERSION 2209. if ( genesis_get_option( 'db_version', null, false ) < '2209' ) { genesis_upgrade_2209(); } // UPDATE DB TO VERSION 2403. if ( genesis_get_option( 'db_version', null, false ) < '2403' ) { genesis_upgrade_2403(); } // UPDATE DB TO VERSION 2501. if ( genesis_get_option( 'db_version', null, false ) < '2501' ) { genesis_upgrade_2501(); } // UPDATE DB TO VERSION 2603. if ( genesis_get_option( 'db_version', null, false ) < '2603' ) { genesis_upgrade_2603(); } // UPDATE DB TO LATEST VERSION. if ( genesis_get_option( 'db_version', null, false ) < PARENT_DB_VERSION ) { genesis_upgrade_db_latest(); } /** * Fires after upgrade processes have completed. * * @since 1.0.1 */ do_action( 'genesis_upgrade' ); } add_action( 'wpmu_upgrade_site', 'genesis_network_upgrade_site' ); /** * Run silent upgrade on each site in the network during a network upgrade. * * Update Genesis database settings for all sites in a network during network upgrade process. * * @since 2.0.0 * * @param int $blog_id Blog ID. */ function genesis_network_upgrade_site( $blog_id ) { switch_to_blog( $blog_id ); $upgrade_url = add_query_arg( array( 'action' => 'genesis-silent-upgrade', ), admin_url( 'admin-ajax.php' ) ); restore_current_blog(); wp_remote_get( esc_url_raw( $upgrade_url ) ); } add_action( 'wp_ajax_no_priv_genesis-silent-upgrade', 'genesis_silent_upgrade' ); /** * Genesis settings upgrade. Silent upgrade (no redirect). * * Meant to be called via ajax request during network upgrade process. * * @since 2.0.0 */ function genesis_silent_upgrade() { remove_action( 'genesis_upgrade', 'genesis_upgrade_redirect' ); genesis_upgrade(); exit( 0 ); } add_action( 'genesis_upgrade', 'genesis_upgrade_redirect' ); /** * Redirect the user back to the theme settings page, refreshing the data and notifying the user that they have * successfully updated. * * @since 1.6.0 * * @return null Return early if not an admin page. */ function genesis_upgrade_redirect() { if ( ! is_admin() || ! current_user_can( 'edit_theme_options' ) || is_customize_preview() ) { return; } if ( genesis_is_major_version( PARENT_THEME_VERSION ) ) { genesis_admin_redirect( 'genesis-upgraded' ); // What's New page. } else { genesis_admin_redirect( 'genesis', array( // Theme Settings page. 'upgraded' => 'true', ) ); } } add_action( 'admin_notices', 'genesis_upgraded_notice' ); /** * Displays the notice that the theme settings were successfully updated to the latest version. * * Currently only used for pre-release update notices. * * @since 1.2.0 * * @return void Return early if not on the Theme Settings page. */ function genesis_upgraded_notice() { if ( ! genesis_is_menu_page( 'genesis' ) ) { return; } if ( isset( $_REQUEST['upgraded'] ) && 'true' === $_REQUEST['upgraded'] ) { echo '
'; /* translators: 1: Genesis version, 2: URL for What's New admin page. */ printf( __( 'Congratulations, you are now rocking Genesis %1$s! See what\'s new in %3$s.', 'genesis' ), genesis_get_option( 'theme_version' ), menu_page_url( 'genesis-upgraded', 0 ), PARENT_THEME_BRANCH ); echo '