wp_create_nonce( 'storefront_notice_dismiss' ),
);
wp_localize_script( 'storefront-admin-nux', 'storefrontNUX', $storefront_nux );
}
/**
* Output admin notices.
*
* @since 2.2.0
*/
public function admin_notices() {
global $pagenow;
if ( true === (bool) get_option( 'storefront_nux_dismissed' ) ) {
return;
}
// Coming from the WooCommerce Wizard?
if ( wp_get_referer() && 'index.php?page=wc-setup&step=next_steps' === basename( wp_get_referer() ) && 'post-new.php' === $pagenow ) {
return;
}
?>
'1' );
$tasks = array();
if ( ! empty( $_REQUEST['homepage'] ) && 'on' === sanitize_text_field( wp_unslash( $_REQUEST['homepage'] ) ) ) { // WPCS: input var ok.
if ( current_user_can( 'edit_pages' ) && 'page' === get_option( 'show_on_front' ) ) {
$this->_assign_page_template( get_option( 'page_on_front' ), 'template-homepage.php' );
} else {
$tasks[] = 'homepage';
}
}
if ( ! empty( $_REQUEST['products'] ) && 'on' === sanitize_text_field( wp_unslash( $_REQUEST['products'] ) ) ) { // WPCS: input var ok.
$tasks[] = 'products';
}
if ( ! empty( $tasks ) ) {
$args['sf_tasks'] = implode( ',', $tasks );
if ( current_user_can( 'manage_options' ) ) {
// Make sure the fresh_site flag is set to true.
update_option( 'fresh_site', true );
if ( current_user_can( 'edit_pages' ) && true === (bool) get_option( 'storefront_nux_fresh_site' ) ) {
$this->_set_woocommerce_pages_full_width();
}
}
}
// Redirect to the Storefront Welcome screen when exiting the Customizer.
$args['return'] = rawurlencode( admin_url( 'themes.php?page=storefront-welcome' ) );
wp_safe_redirect( add_query_arg( $args, admin_url( 'customize.php' ) ) );
die();
}
/**
* Get WooCommerce page ids.
*
* @since 2.2.0
*/
public static function get_woocommerce_pages() {
$woocommerce_pages = array();
$wc_pages_options = apply_filters(
'storefront_page_option_names', array(
'woocommerce_cart_page_id',
'woocommerce_checkout_page_id',
'woocommerce_myaccount_page_id',
'woocommerce_shop_page_id',
'woocommerce_terms_page_id',
)
);
foreach ( $wc_pages_options as $option ) {
$page_id = get_option( $option );
if ( ! empty( $page_id ) ) {
$page_id = intval( $page_id );
if ( null !== get_post( $page_id ) ) {
$woocommerce_pages[ $option ] = $page_id;
}
}
}
return $woocommerce_pages;
}
/**
* Update Storefront fresh site flag.
*
* @since 2.2.0
*/
public function log_fresh_site_state() {
if ( null === get_option( 'storefront_nux_fresh_site', null ) ) {
update_option( 'storefront_nux_fresh_site', get_option( 'fresh_site' ) );
}
}
/**
* Add custom classes to the list of admin body classes.
*
* @since 2.2.0
* @param string $classes Classes for the admin body element.
* @return string
*/
public function admin_body_class( $classes ) {
if ( true === (bool) get_option( 'storefront_nux_dismissed' ) ) {
return $classes;
}
$classes .= ' sf-nux ';
return $classes;
}
/**
* Check if WooCommerce is installed.
*
* @since 2.2.0
*/
private function _is_woocommerce_installed() {
if ( file_exists( WP_PLUGIN_DIR . '/woocommerce' ) ) {
$plugins = get_plugins( '/woocommerce' );
if ( ! empty( $plugins ) ) {
$keys = array_keys( $plugins );
$plugin_file = 'woocommerce/' . $keys[0];
$url = wp_nonce_url(
add_query_arg(
array(
'action' => 'activate',
'plugin' => $plugin_file,
), admin_url( 'plugins.php' )
), 'activate-plugin_' . $plugin_file
);
return $url;
}
}
return false;
}
/**
* Set WooCommerce pages to use the full width template.
*
* @since 2.2.0
*/
private function _set_woocommerce_pages_full_width() {
$wc_pages = $this->get_woocommerce_pages();
foreach ( $wc_pages as $option => $page_id ) {
$this->_assign_page_template( $page_id, 'template-fullwidth.php' );
}
}
/**
* Given a page id assign a given page template to it.
*
* @since 2.2.0
* @param int $page_id Page id.
* @param string $template Template file name.
* @return void|bool Returns false if $page_id or $template is empty.
*/
private function _assign_page_template( $page_id, $template ) {
if ( empty( $page_id ) || empty( $template ) || '' === locate_template( $template ) ) {
return false;
}
update_post_meta( $page_id, '_wp_page_template', $template );
}
/**
* Check if WooCommerce is empty.
*
* @since 2.2.0
* @return bool
*/
private function _is_woocommerce_empty() {
$products = wp_count_posts( 'product' );
if ( 0 < $products->publish ) {
return false;
}
return true;
}
}
endif;
return new Storefront_NUX_Admin();