Adds storefront/theme step to the setup wizard
Also includes a background install to get Storefront installed and activated on demand. To test, use a default theme and go to wp-admin/index.php?page=wc-setup The theme step will be after payments!
This commit is contained in:
parent
34a7f9b3dd
commit
956b1a6181
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -384,6 +384,62 @@ body {
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.wc-wizard-storefront {
|
||||
.wc-wizard-storefront-intro {
|
||||
padding: 40px 40px 0;
|
||||
background: #F5F5F5;
|
||||
text-align: center;
|
||||
|
||||
img {
|
||||
margin: 40px 0 0 0;
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
.wc-wizard-storefront-features {
|
||||
list-style: none outside;
|
||||
margin: 0 0 20px;
|
||||
padding: 0 0 0 30px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.wc-wizard-storefront-feature {
|
||||
margin: 0;
|
||||
padding: 20px 30px 20px 2em;
|
||||
width: 50%;
|
||||
box-sizing: border-box;
|
||||
|
||||
&::before {
|
||||
margin-left: -2em;
|
||||
position: absolute;
|
||||
}
|
||||
&.first {
|
||||
clear: both;
|
||||
float: left;
|
||||
}
|
||||
&.last {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
.wc-wizard-storefront-feature__bulletproof::before {
|
||||
content: '🔒';
|
||||
}
|
||||
.wc-wizard-storefront-feature__mobile::before {
|
||||
content: '📱';
|
||||
}
|
||||
.wc-wizard-storefront-feature__accessibility::before {
|
||||
content: '👓';
|
||||
}
|
||||
.wc-wizard-storefront-feature__search::before {
|
||||
content: '🔍';
|
||||
}
|
||||
.wc-wizard-storefront-feature__compatibility::before {
|
||||
content: '🔧';
|
||||
}
|
||||
.wc-wizard-storefront-feature__extendable::before {
|
||||
content: '🎨';
|
||||
}
|
||||
}
|
||||
|
||||
ul.wc-wizard-payment-gateways {
|
||||
border: 1px solid #eee;
|
||||
border-bottom-width: 2px;
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 374 KiB |
|
@ -80,6 +80,11 @@ class WC_Admin_Setup_Wizard {
|
|||
'view' => array( $this, 'wc_setup_payments' ),
|
||||
'handler' => array( $this, 'wc_setup_payments_save' ),
|
||||
),
|
||||
'theme' => array(
|
||||
'name' => __( 'Theme', 'woocommerce' ),
|
||||
'view' => array( $this, 'wc_setup_theme' ),
|
||||
'handler' => array( $this, 'wc_setup_theme_save' ),
|
||||
),
|
||||
'next_steps' => array(
|
||||
'name' => __( 'Ready!', 'woocommerce' ),
|
||||
'view' => array( $this, 'wc_setup_ready' ),
|
||||
|
@ -87,6 +92,11 @@ class WC_Admin_Setup_Wizard {
|
|||
),
|
||||
);
|
||||
|
||||
// Hide storefront step if using a WooCommerce theme or user cannot modify themes.
|
||||
if ( ! current_user_can( 'install_themes' ) || ! current_user_can( 'switch_themes' ) || is_multisite() || current_theme_supports( 'woocommerce' ) ) {
|
||||
unset( $default_steps['theme'] );
|
||||
}
|
||||
|
||||
$this->steps = apply_filters( 'woocommerce_setup_wizard_steps', $default_steps );
|
||||
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
|
@ -762,6 +772,45 @@ class WC_Admin_Setup_Wizard {
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme step.
|
||||
*/
|
||||
private function wc_setup_theme() {
|
||||
?>
|
||||
<form method="post" class="wc-wizard-storefront">
|
||||
<p class="wc-wizard-storefront-intro">
|
||||
<?php echo wp_kses_post( __( '<strong>Storefront</strong> is the free WordPress theme built and maintained by the makers of WooCommerce.', 'woocommerce' ) ); ?>
|
||||
<img src="<?php echo esc_url( WC()->plugin_url() . '/assets/images/storefront-intro.png' ); ?>" alt="Storefront" />
|
||||
</p>
|
||||
|
||||
<ul class="wc-wizard-storefront-features">
|
||||
<li class="wc-wizard-storefront-feature wc-wizard-storefront-feature__bulletproof first"><?php echo wp_kses_post( __( '<strong>Bulletproof WooCommerce integration:</strong> Rest assured the integration between WooCommerce, WooCommerce extensions and Storefront is water-tight.', 'woocommerce' ) ); ?></li>
|
||||
<li class="wc-wizard-storefront-feature wc-wizard-storefront-feature__accessibility last"><?php echo wp_kses_post( __( '<strong>Built with accessibility in mind:</strong> Storefront adheres to the strict wordpress.org accessibility guidelines making your store accessible to the widest audience possible.', 'woocommerce' ) ); ?></li>
|
||||
<li class="wc-wizard-storefront-feature wc-wizard-storefront-feature__extendable first"><?php echo wp_kses_post( __( '<strong>Child themes and extensions available:</strong> Like WooCommerce, you can extend Storefront with an extension or child theme to make your store truly your own.', 'woocommerce' ) ); ?></li>
|
||||
<li class="wc-wizard-storefront-feature wc-wizard-storefront-feature__compatibility last"><?php echo wp_kses_post( __( '<strong>No Shortcodes, sliders or page builders:</strong> Bring your favorite sliders or page builders, Storefront is built to work with the most popular options.', 'woocommerce' ) ); ?></li>
|
||||
<li class="wc-wizard-storefront-feature wc-wizard-storefront-feature__mobile first"><?php echo wp_kses_post( __( '<strong>Clean, simple mobile-first design:</strong> The perfect place to start when customizing your store, looks beautiful on any device.', 'woocommerce' ) ); ?></li>
|
||||
<li class="wc-wizard-storefront-feature wc-wizard-storefront-feature__search last"><?php echo wp_kses_post( __( '<strong>Optimized for search:</strong> Valid schema markup for improved SEO performance.', 'woocommerce' ) ); ?></li>
|
||||
</ul>
|
||||
<p class="wc-setup-actions step">
|
||||
<input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Install & activate Storefront', 'woocommerce' ); ?>" name="save_step" />
|
||||
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a>
|
||||
<?php wp_nonce_field( 'wc-setup' ); ?>
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme step save.
|
||||
*/
|
||||
private function wc_setup_theme_save() {
|
||||
check_admin_referer( 'wc-setup' );
|
||||
wp_schedule_single_event( time() + 1, 'woocommerce_theme_background_installer', array( 'storefront' ) );
|
||||
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions on the final step.
|
||||
*/
|
||||
|
|
|
@ -97,6 +97,7 @@ class WC_Install {
|
|||
add_filter( 'wpmu_drop_tables', array( __CLASS__, 'wpmu_drop_tables' ) );
|
||||
add_filter( 'cron_schedules', array( __CLASS__, 'cron_schedules' ) );
|
||||
add_action( 'woocommerce_plugin_background_installer', array( __CLASS__, 'background_installer' ), 10, 2 );
|
||||
add_action( 'woocommerce_theme_background_installer', array( __CLASS__, 'theme_background_installer' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1085,6 +1086,65 @@ CREATE TABLE {$wpdb->prefix}woocommerce_termmeta (
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a theme from .org in the background via a cron job (used by installer - opt in).
|
||||
*
|
||||
* @param string $theme_slug
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public static function theme_background_installer( $theme_slug ) {
|
||||
// Explicitly clear the event.
|
||||
wp_clear_scheduled_hook( 'woocommerce_theme_background_installer', func_get_args() );
|
||||
|
||||
if ( ! empty( $theme_slug ) ) {
|
||||
// Suppress feedback
|
||||
ob_start();
|
||||
|
||||
try {
|
||||
$theme = wp_get_theme( $theme_slug );
|
||||
|
||||
if ( ! $theme->exists() ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
||||
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
|
||||
include_once( ABSPATH . 'wp-admin/includes/theme.php' );
|
||||
|
||||
WP_Filesystem();
|
||||
|
||||
$skin = new Automatic_Upgrader_Skin;
|
||||
$upgrader = new Theme_Upgrader( $skin );
|
||||
$api = themes_api( 'theme_information', array(
|
||||
'slug' => $theme_slug,
|
||||
'fields' => array( 'sections' => false ),
|
||||
) );
|
||||
$result = $upgrader->install( $api->download_link );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
throw new Exception( $result->get_error_message() );
|
||||
} elseif ( is_wp_error( $skin->result ) ) {
|
||||
throw new Exception( $skin->result->get_error_message() );
|
||||
} elseif ( is_null( $result ) ) {
|
||||
throw new Exception( 'Unable to connect to the filesystem. Please confirm your credentials.' );
|
||||
}
|
||||
}
|
||||
|
||||
switch_theme( $theme_slug );
|
||||
} catch ( Exception $e ) {
|
||||
WC_Admin_Notices::add_custom_notice(
|
||||
$theme_slug . '_install_error',
|
||||
sprintf(
|
||||
__( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ),
|
||||
$theme_slug,
|
||||
$e->getMessage(),
|
||||
esc_url( admin_url( 'http://local.wordpress.dev/wp-admin/update.php?action=install-theme&theme=' . $theme_slug . '&_wpnonce=' . wp_create_nonce( 'install-theme_' . $theme_slug ) ) )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Discard feedback
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WC_Install::init();
|
||||
|
|
Loading…
Reference in New Issue