switch_theme example

    } elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) {
        // Invalid.     } elseif ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
        // Invalid.     } else {
        // Valid.         return true;
    }

    $default = wp_get_theme( WP_DEFAULT_THEME );
    if ( $default->exists() ) {
        switch_theme( WP_DEFAULT_THEME );
        return false;
    }

    /** * If we're in an invalid state but WP_DEFAULT_THEME doesn't exist, * switch to the latest core default theme that's installed. * * If it turns out that this latest core default theme is our current * theme, then there's nothing we can do about that, so we have to bail, * rather than going into an infinite loop. (This is why there are * checks against WP_DEFAULT_THEME above, also.) We also can't do anything * if it turns out there is no default theme installed. (That's `false`.) */
check_admin_referer( 'switch-theme_' . $_GET['stylesheet'] );
        $theme = wp_get_theme( $_GET['stylesheet'] );

        if ( ! $theme->exists() || ! $theme->is_allowed() ) {
            wp_die(
                '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
                '<p>' . __( 'The requested theme does not exist.' ) . '</p>',
                403
            );
        }

        switch_theme( $theme->get_stylesheet() );
        wp_redirect( admin_url( 'themes.php?activated=true' ) );
        exit;
    } elseif ( 'resume' === $_GET['action'] ) {
        check_admin_referer( 'resume-theme_' . $_GET['stylesheet'] );
        $theme = wp_get_theme( $_GET['stylesheet'] );

        if ( ! current_user_can( 'resume_theme', $_GET['stylesheet'] ) ) {
            wp_die(
                '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
                '<p>' . __( 'Sorry, you are not allowed to resume this theme.' ) . '</p>',
                403
            );
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';

        // Only run if active theme.         if ( get_stylesheet() !== $theme ) {
            return $response;
        }

        // Ensure stylesheet name hasn't changed after the upgrade:         if ( get_stylesheet() === $theme && $theme !== $this->result['destination_name'] ) {
            wp_clean_themes_cache();
            $stylesheet = $this->result['destination_name'];
            switch_theme( $stylesheet );
        }

        // Time to remove maintenance mode. Bulk edit handles this separately.         if ( ! $this->bulk ) {
            $this->maintenance_mode( false );
        }
        return $response;
    }

    /** * Deletes the old theme during an upgrade. * * Hooked to the {@see 'upgrader_clear_destination'} filter by Theme_Upgrader::upgrade() * and Theme_Upgrader::bulk_upgrade(). * * @since 2.8.0 * * @global WP_Filesystem_Base $wp_filesystem Subclass * * @param bool $removed * @param string $local_destination * @param string $remote_destination * @param array $theme * @return bool */

        $data = apply_filters( 'customize_changeset_save_data', $data$filter_context );

        // Switch theme if publishing changes now.         if ( 'publish' === $args['status'] && ! $this->is_theme_active() ) {
            // Temporarily stop previewing the theme to allow switch_themes() to operate properly.             $this->stop_previewing_theme();
            switch_theme( $this->get_stylesheet() );
            update_option( 'theme_switched_via_customizer', true );
            $this->start_previewing_theme();
        }

        // Gather the data for wp_insert_post()/wp_update_post().         $post_array = array(
            // JSON_UNESCAPED_SLASHES is only to improve readability as slashes needn't be escaped in storage.             'post_content' => wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ),
        );
        if ( $args['title'] ) {
            $post_array['post_title'] = $args['title'];
        }
Home | Imprint | This part of the site doesn't use cookies.