Added login request
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Admin Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_Admin' ) ) :
|
||||
/**
|
||||
* The Storefront admin class
|
||||
*/
|
||||
class Storefront_Admin {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'welcome_register_menu' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'welcome_style' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load welcome screen css
|
||||
*
|
||||
* @param string $hook_suffix the current page hook suffix.
|
||||
* @return void
|
||||
* @since 1.4.4
|
||||
*/
|
||||
public function welcome_style( $hook_suffix ) {
|
||||
global $storefront_version;
|
||||
|
||||
if ( 'appearance_page_storefront-welcome' === $hook_suffix ) {
|
||||
wp_enqueue_style( 'storefront-welcome-screen', get_template_directory_uri() . '/assets/css/admin/welcome-screen/welcome.css', $storefront_version );
|
||||
wp_style_add_data( 'storefront-welcome-screen', 'rtl', 'replace' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the dashboard page
|
||||
*
|
||||
* @see add_theme_page()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function welcome_register_menu() {
|
||||
add_theme_page( 'Storefront', 'Storefront', 'activate_plugins', 'storefront-welcome', array( $this, 'storefront_welcome_screen' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* The welcome screen
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function storefront_welcome_screen() {
|
||||
require_once( ABSPATH . 'wp-load.php' );
|
||||
require_once( ABSPATH . 'wp-admin/admin.php' );
|
||||
require_once( ABSPATH . 'wp-admin/admin-header.php' );
|
||||
|
||||
global $storefront_version;
|
||||
?>
|
||||
|
||||
<div class="storefront-wrap">
|
||||
<section class="storefront-welcome-nav">
|
||||
<span class="storefront-welcome-nav__version">Storefront <?php echo esc_attr( $storefront_version ); ?></span>
|
||||
<ul>
|
||||
<li><a href="https://wordpress.org/support/theme/storefront" target="_blank"><?php esc_attr_e( 'Support', 'storefront' ); ?></a></li>
|
||||
<li><a href="https://docs.woocommerce.com/documentation/themes/storefront/" target="_blank"><?php esc_attr_e( 'Documentation', 'storefront' ); ?></a></li>
|
||||
<li><a href="https://woocommerce.wordpress.com/category/storefront/" target="_blank"><?php esc_attr_e( 'Development blog', 'storefront' ); ?></a></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<div class="storefront-logo">
|
||||
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/assets/images/admin/storefront-icon.svg" alt="Storefront" />
|
||||
</div>
|
||||
|
||||
<div class="storefront-intro">
|
||||
<?php
|
||||
/**
|
||||
* Display a different message when the user visits this page when returning from the guided tour
|
||||
*/
|
||||
$referrer = wp_get_referer();
|
||||
|
||||
if ( strpos( $referrer, 'sf_starter_content' ) !== false ) {
|
||||
echo '<h1>' . sprintf( esc_attr__( 'Setup complete %sYour Storefront adventure begins now 🚀%s ', 'storefront' ), '<span>', '</span>' ) . '</h1>';
|
||||
echo '<p>' . esc_attr__( 'One more thing... You might be interested in the following Storefront extensions and designs.', 'storefront' ) . '</p>';
|
||||
} else {
|
||||
echo '<p>' . esc_attr__( 'Hello! You might be interested in the following Storefront extensions and designs.', 'storefront' ) . '</p>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="storefront-enhance">
|
||||
<div class="storefront-enhance__column storefront-bundle">
|
||||
<h3><?php esc_attr_e( 'Storefront Extensions Bundle', 'storefront' ); ?></h3>
|
||||
<span class="bundle-image">
|
||||
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/assets/images/admin/welcome-screen/storefront-bundle-hero.png" alt="Storefront Extensions Hero" />
|
||||
</span>
|
||||
|
||||
<p>
|
||||
<?php esc_attr_e( 'All the tools you\'ll need to define your style and customize Storefront.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php esc_attr_e( 'Make it yours without touching code with the Storefront Extensions bundle. Express yourself, optimize conversions, delight customers.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<a href="https://woocommerce.com/products/storefront-extensions-bundle/?utm_source=product&utm_medium=upsell&utm_campaign=storefrontaddons" class="storefront-button" target="_blank"><?php esc_attr_e( 'Read more and purchase', 'storefront' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="storefront-enhance__column storefront-child-themes">
|
||||
<h3><?php esc_attr_e( 'Alternate designs', 'storefront' ); ?></h3>
|
||||
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/assets/images/admin/welcome-screen/child-themes.jpg" alt="Storefront Powerpack" />
|
||||
|
||||
<p>
|
||||
<?php esc_attr_e( 'Quickly and easily transform your shops appearance with Storefront child themes.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php esc_attr_e( 'Each has been designed to serve a different industry - from fashion to food.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php esc_attr_e( 'Of course they are all fully compatible with each Storefront extension.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="https://woocommerce.com/product-category/themes/storefront-child-theme-themes/?utm_source=product&utm_medium=upsell&utm_campaign=storefrontaddons" class="storefront-button" target="_blank"><?php esc_attr_e( 'Check \'em out', 'storefront' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="automattic">
|
||||
<p>
|
||||
<?php printf( esc_html__( 'An %s project', 'storefront' ), '<a href="https://automattic.com/"><img src="' . esc_url( get_template_directory_uri() ) . '/assets/images/admin/welcome-screen/automattic.png" alt="Automattic" /></a>' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Welcome screen intro
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function welcome_intro() {
|
||||
require_once( get_template_directory() . '/inc/admin/welcome-screen/component-intro.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a button that will install or activate a plugin if it doesn't exist, or display a disabled button if the
|
||||
* plugin is already activated.
|
||||
*
|
||||
* @param string $plugin_slug The plugin slug.
|
||||
* @param string $plugin_file The plugin file.
|
||||
*/
|
||||
public function install_plugin_button( $plugin_slug, $plugin_file ) {
|
||||
if ( current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) ) {
|
||||
if ( is_plugin_active( $plugin_slug . '/' . $plugin_file ) ) {
|
||||
/**
|
||||
* The plugin is already active
|
||||
*/
|
||||
$button = array(
|
||||
'message' => esc_attr__( 'Activated', 'storefront' ),
|
||||
'url' => '#',
|
||||
'classes' => 'disabled',
|
||||
);
|
||||
} elseif ( $url = $this->_is_plugin_installed( $plugin_slug ) ) {
|
||||
/**
|
||||
* The plugin exists but isn't activated yet.
|
||||
*/
|
||||
$button = array(
|
||||
'message' => esc_attr__( 'Activate', 'storefront' ),
|
||||
'url' => $url,
|
||||
'classes' => 'activate-now',
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* The plugin doesn't exist.
|
||||
*/
|
||||
$url = wp_nonce_url( add_query_arg( array(
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => $plugin_slug,
|
||||
), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug );
|
||||
$button = array(
|
||||
'message' => esc_attr__( 'Install now', 'storefront' ),
|
||||
'url' => $url,
|
||||
'classes' => ' install-now install-' . $plugin_slug,
|
||||
);
|
||||
}
|
||||
?>
|
||||
<a href="<?php echo esc_url( $button['url'] ); ?>" class="storefront-button <?php echo esc_attr( $button['classes'] ); ?>" data-originaltext="<?php echo esc_attr( $button['message'] ); ?>" data-slug="<?php echo esc_attr( $plugin_slug ); ?>" aria-label="<?php echo esc_attr( $button['message'] ); ?>"><?php echo esc_attr( $button['message'] ); ?></a>
|
||||
<a href="https://wordpress.org/plugins/<?php echo esc_attr( $plugin_slug ); ?>" target="_blank"><?php esc_attr_e( 'Learn more', 'storefront' ); ?></a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a plugin is installed and return the url to activate it if so.
|
||||
*
|
||||
* @param string $plugin_slug The plugin slug.
|
||||
*/
|
||||
public function _is_plugin_installed( $plugin_slug ) {
|
||||
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
|
||||
$plugins = get_plugins( '/' . $plugin_slug );
|
||||
if ( ! empty( $plugins ) ) {
|
||||
$keys = array_keys( $plugins );
|
||||
$plugin_file = $plugin_slug . '/' . $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;
|
||||
}
|
||||
/**
|
||||
* Welcome screen enhance section
|
||||
*
|
||||
* @since 1.5.2
|
||||
*/
|
||||
public function welcome_enhance() {
|
||||
require_once( get_template_directory() . '/inc/admin/welcome-screen/component-enhance.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Welcome screen contribute section
|
||||
*
|
||||
* @since 1.5.2
|
||||
*/
|
||||
public function welcome_contribute() {
|
||||
require_once( get_template_directory() . '/inc/admin/welcome-screen/component-contribute.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product data from json
|
||||
*
|
||||
* @param string $url URL to the json file.
|
||||
* @param string $transient Name the transient.
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function get_storefront_product_data( $url, $transient ) {
|
||||
$raw_products = wp_safe_remote_get( $url );
|
||||
$products = json_decode( wp_remote_retrieve_body( $raw_products ) );
|
||||
|
||||
if ( ! empty( $products ) ) {
|
||||
set_transient( $transient, $products, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_Admin();
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Plugin Install Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
* @since 2.2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_Plugin_Install' ) ) :
|
||||
/**
|
||||
* The Storefront plugin install class
|
||||
*/
|
||||
class Storefront_Plugin_Install {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'plugin_install_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load plugin install scripts
|
||||
*
|
||||
* @param string $hook_suffix the current page hook suffix.
|
||||
* @return void
|
||||
* @since 1.4.4
|
||||
*/
|
||||
public function plugin_install_scripts( $hook_suffix ) {
|
||||
global $storefront_version;
|
||||
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
wp_enqueue_script( 'storefront-plugin-install', get_template_directory_uri() . '/assets/js/admin/plugin-install' . $suffix . '.js', array( 'jquery', 'updates' ), $storefront_version, 'all' );
|
||||
|
||||
wp_enqueue_style( 'storefront-plugin-install', get_template_directory_uri() . '/assets/css/admin/plugin-install.css', array(), $storefront_version, 'all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a button that will install or activate a plugin if it doesn't exist, or display a disabled button if the
|
||||
* plugin is already activated.
|
||||
*
|
||||
* @param string $plugin_slug The plugin slug.
|
||||
* @param string $plugin_file The plugin file.
|
||||
*/
|
||||
public static function install_plugin_button( $plugin_slug, $plugin_file, $plugin_name, $classes = array(), $activated = '', $activate = '', $install = '' ) {
|
||||
if ( current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) ) {
|
||||
if ( is_plugin_active( $plugin_slug . '/' . $plugin_file ) ) {
|
||||
// The plugin is already active
|
||||
$button = array(
|
||||
'message' => esc_attr__( 'Activated', 'storefront' ),
|
||||
'url' => '#',
|
||||
'classes' => array( 'storefront-button', 'disabled' ),
|
||||
);
|
||||
|
||||
if ( '' !== $activated ) {
|
||||
$button['message'] = esc_attr( $activated );
|
||||
}
|
||||
} elseif ( $url = self::_is_plugin_installed( $plugin_slug ) ) {
|
||||
// The plugin exists but isn't activated yet.
|
||||
$button = array(
|
||||
'message' => esc_attr__( 'Activate', 'storefront' ),
|
||||
'url' => $url,
|
||||
'classes' => array( 'storefront-button', 'activate-now' ),
|
||||
);
|
||||
|
||||
if ( '' !== $activate ) {
|
||||
$button['message'] = esc_attr( $activate );
|
||||
}
|
||||
} else {
|
||||
// The plugin doesn't exist.
|
||||
$url = wp_nonce_url( add_query_arg( array(
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => $plugin_slug,
|
||||
), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug );
|
||||
$button = array(
|
||||
'message' => esc_attr__( 'Install now', 'storefront' ),
|
||||
'url' => $url,
|
||||
'classes' => array( 'storefront-button', 'sf-install-now', 'install-now', 'install-' . $plugin_slug ),
|
||||
);
|
||||
|
||||
if ( '' !== $install ) {
|
||||
$button['message'] = esc_attr( $install );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $classes ) ) {
|
||||
$button['classes'] = array_merge( $button['classes'], $classes );
|
||||
}
|
||||
|
||||
$button['classes'] = implode( ' ', $button['classes'] );
|
||||
|
||||
?>
|
||||
<span class="sf-plugin-card plugin-card-<?php echo esc_attr( $plugin_slug ); ?>">
|
||||
<a href="<?php echo esc_url( $button['url'] ); ?>" class="<?php echo esc_attr( $button['classes'] ); ?>" data-originaltext="<?php echo esc_attr( $button['message'] ); ?>" data-name="<?php echo esc_attr( $plugin_name ); ?>" data-slug="<?php echo esc_attr( $plugin_slug ); ?>" aria-label="<?php echo esc_attr( $button['message'] ); ?>"><?php echo esc_attr( $button['message'] ); ?></a>
|
||||
</span>
|
||||
<a href="https://wordpress.org/plugins/<?php echo esc_attr( $plugin_slug ); ?>" target="_blank"><?php esc_attr_e( 'Learn more', 'storefront' ); ?></a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a plugin is installed and return the url to activate it if so.
|
||||
*
|
||||
* @param string $plugin_slug The plugin slug.
|
||||
*/
|
||||
private static function _is_plugin_installed( $plugin_slug ) {
|
||||
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
|
||||
$plugins = get_plugins( '/' . $plugin_slug );
|
||||
if ( ! empty( $plugins ) ) {
|
||||
$keys = array_keys( $plugins );
|
||||
$plugin_file = $plugin_slug . '/' . $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;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_Plugin_Install();
|
||||
@@ -0,0 +1,401 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @since 2.0.0
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront' ) ) :
|
||||
|
||||
/**
|
||||
* The main Storefront class
|
||||
*/
|
||||
class Storefront {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'after_setup_theme', array( $this, 'setup' ) );
|
||||
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ), 10 );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'child_scripts' ), 30 ); // After WooCommerce.
|
||||
add_filter( 'body_class', array( $this, 'body_classes' ) );
|
||||
add_filter( 'wp_page_menu_args', array( $this, 'page_menu_args' ) );
|
||||
add_filter( 'navigation_markup_template', array( $this, 'navigation_markup_template' ) );
|
||||
add_action( 'enqueue_embed_scripts', array( $this, 'print_embed_styles' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up theme defaults and registers support for various WordPress features.
|
||||
*
|
||||
* Note that this function is hooked into the after_setup_theme hook, which
|
||||
* runs before the init hook. The init hook is too late for some features, such
|
||||
* as indicating support for post thumbnails.
|
||||
*/
|
||||
public function setup() {
|
||||
/*
|
||||
* Load Localisation files.
|
||||
*
|
||||
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
|
||||
*/
|
||||
|
||||
// Loads wp-content/languages/themes/storefront-it_IT.mo.
|
||||
load_theme_textdomain( 'storefront', trailingslashit( WP_LANG_DIR ) . 'themes/' );
|
||||
|
||||
// Loads wp-content/themes/child-theme-name/languages/it_IT.mo.
|
||||
load_theme_textdomain( 'storefront', get_stylesheet_directory() . '/languages' );
|
||||
|
||||
// Loads wp-content/themes/storefront/languages/it_IT.mo.
|
||||
load_theme_textdomain( 'storefront', get_template_directory() . '/languages' );
|
||||
|
||||
/**
|
||||
* Add default posts and comments RSS feed links to head.
|
||||
*/
|
||||
add_theme_support( 'automatic-feed-links' );
|
||||
|
||||
/*
|
||||
* Enable support for Post Thumbnails on posts and pages.
|
||||
*
|
||||
* @link https://developer.wordpress.org/reference/functions/add_theme_support/#Post_Thumbnails
|
||||
*/
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
|
||||
/**
|
||||
* Enable support for site logo
|
||||
*/
|
||||
add_theme_support( 'custom-logo', apply_filters( 'storefront_custom_logo_args', array(
|
||||
'height' => 110,
|
||||
'width' => 470,
|
||||
'flex-width' => true,
|
||||
) ) );
|
||||
|
||||
// This theme uses wp_nav_menu() in two locations.
|
||||
register_nav_menus( apply_filters( 'storefront_register_nav_menus', array(
|
||||
'primary' => __( 'Primary Menu', 'storefront' ),
|
||||
'secondary' => __( 'Secondary Menu', 'storefront' ),
|
||||
'handheld' => __( 'Handheld Menu', 'storefront' ),
|
||||
) ) );
|
||||
|
||||
/*
|
||||
* Switch default core markup for search form, comment form, comments, galleries, captions and widgets
|
||||
* to output valid HTML5.
|
||||
*/
|
||||
add_theme_support( 'html5', apply_filters( 'storefront_html5_args', array(
|
||||
'search-form',
|
||||
'comment-form',
|
||||
'comment-list',
|
||||
'gallery',
|
||||
'caption',
|
||||
'widgets',
|
||||
) ) );
|
||||
|
||||
// Setup the WordPress core custom background feature.
|
||||
add_theme_support( 'custom-background', apply_filters( 'storefront_custom_background_args', array(
|
||||
'default-color' => apply_filters( 'storefront_default_background_color', 'ffffff' ),
|
||||
'default-image' => '',
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Add support for the Site Logo plugin and the site logo functionality in JetPack
|
||||
* https://github.com/automattic/site-logo
|
||||
* http://jetpack.me/
|
||||
*/
|
||||
add_theme_support( 'site-logo', apply_filters( 'storefront_site_logo_args', array(
|
||||
'size' => 'full'
|
||||
) ) );
|
||||
|
||||
// Declare WooCommerce support.
|
||||
add_theme_support( 'woocommerce', apply_filters( 'storefront_woocommerce_args', array(
|
||||
'single_image_width' => 416,
|
||||
'thumbnail_image_width' => 324,
|
||||
'product_grid' => array(
|
||||
'default_columns' => 3,
|
||||
'default_rows' => 4,
|
||||
'min_columns' => 1,
|
||||
'max_columns' => 6,
|
||||
'min_rows' => 1
|
||||
)
|
||||
) ) );
|
||||
|
||||
add_theme_support( 'wc-product-gallery-zoom' );
|
||||
add_theme_support( 'wc-product-gallery-lightbox' );
|
||||
add_theme_support( 'wc-product-gallery-slider' );
|
||||
|
||||
// Declare support for title theme feature.
|
||||
add_theme_support( 'title-tag' );
|
||||
|
||||
// Declare support for selective refreshing of widgets.
|
||||
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register widget area.
|
||||
*
|
||||
* @link https://codex.wordpress.org/Function_Reference/register_sidebar
|
||||
*/
|
||||
public function widgets_init() {
|
||||
$sidebar_args['sidebar'] = array(
|
||||
'name' => __( 'Sidebar', 'storefront' ),
|
||||
'id' => 'sidebar-1',
|
||||
'description' => ''
|
||||
);
|
||||
|
||||
$sidebar_args['header'] = array(
|
||||
'name' => __( 'Below Header', 'storefront' ),
|
||||
'id' => 'header-1',
|
||||
'description' => __( 'Widgets added to this region will appear beneath the header and above the main content.', 'storefront' ),
|
||||
);
|
||||
|
||||
$rows = intval( apply_filters( 'storefront_footer_widget_rows', 1 ) );
|
||||
$regions = intval( apply_filters( 'storefront_footer_widget_columns', 4 ) );
|
||||
|
||||
for ( $row = 1; $row <= $rows; $row++ ) {
|
||||
for ( $region = 1; $region <= $regions; $region++ ) {
|
||||
$footer_n = $region + $regions * ( $row - 1 ); // Defines footer sidebar ID.
|
||||
$footer = sprintf( 'footer_%d', $footer_n );
|
||||
|
||||
if ( 1 == $rows ) {
|
||||
$footer_region_name = sprintf( __( 'Footer Column %1$d', 'storefront' ), $region );
|
||||
$footer_region_description = sprintf( __( 'Widgets added here will appear in column %1$d of the footer.', 'storefront' ), $region );
|
||||
} else {
|
||||
$footer_region_name = sprintf( __( 'Footer Row %1$d - Column %2$d', 'storefront' ), $row, $region );
|
||||
$footer_region_description = sprintf( __( 'Widgets added here will appear in column %1$d of footer row %2$d.', 'storefront' ), $region, $row );
|
||||
}
|
||||
|
||||
$sidebar_args[ $footer ] = array(
|
||||
'name' => $footer_region_name,
|
||||
'id' => sprintf( 'footer-%d', $footer_n ),
|
||||
'description' => $footer_region_description,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sidebar_args = apply_filters( 'storefront_sidebar_args', $sidebar_args );
|
||||
|
||||
foreach ( $sidebar_args as $sidebar => $args ) {
|
||||
$widget_tags = array(
|
||||
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<span class="gamma widget-title">',
|
||||
'after_title' => '</span>',
|
||||
);
|
||||
|
||||
/**
|
||||
* Dynamically generated filter hooks. Allow changing widget wrapper and title tags. See the list below.
|
||||
*
|
||||
* 'storefront_header_widget_tags'
|
||||
* 'storefront_sidebar_widget_tags'
|
||||
*
|
||||
* 'storefront_footer_1_widget_tags'
|
||||
* 'storefront_footer_2_widget_tags'
|
||||
* 'storefront_footer_3_widget_tags'
|
||||
* 'storefront_footer_4_widget_tags'
|
||||
*/
|
||||
$filter_hook = sprintf( 'storefront_%s_widget_tags', $sidebar );
|
||||
$widget_tags = apply_filters( $filter_hook, $widget_tags );
|
||||
|
||||
if ( is_array( $widget_tags ) ) {
|
||||
register_sidebar( $args + $widget_tags );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function scripts() {
|
||||
global $storefront_version;
|
||||
|
||||
/**
|
||||
* Styles
|
||||
*/
|
||||
wp_enqueue_style( 'storefront-style', get_template_directory_uri() . '/style.css', '', $storefront_version );
|
||||
wp_style_add_data( 'storefront-style', 'rtl', 'replace' );
|
||||
|
||||
wp_enqueue_style( 'storefront-icons', get_template_directory_uri() . '/assets/css/base/icons.css', '', $storefront_version );
|
||||
wp_style_add_data( 'storefront-icons', 'rtl', 'replace' );
|
||||
|
||||
/**
|
||||
* Fonts
|
||||
*/
|
||||
$google_fonts = apply_filters( 'storefront_google_font_families', array(
|
||||
'source-sans-pro' => 'Source+Sans+Pro:400,300,300italic,400italic,600,700,900',
|
||||
) );
|
||||
|
||||
$query_args = array(
|
||||
'family' => implode( '|', $google_fonts ),
|
||||
'subset' => urlencode( 'latin,latin-ext' ),
|
||||
);
|
||||
|
||||
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
|
||||
|
||||
wp_enqueue_style( 'storefront-fonts', $fonts_url, array(), null );
|
||||
|
||||
/**
|
||||
* Scripts
|
||||
*/
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
wp_enqueue_script( 'storefront-navigation', get_template_directory_uri() . '/assets/js/navigation' . $suffix . '.js', array(), $storefront_version, true );
|
||||
wp_enqueue_script( 'storefront-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix' . $suffix . '.js', array(), '20130115', true );
|
||||
|
||||
if ( has_nav_menu( 'handheld' ) ) {
|
||||
$storefront_l10n = array(
|
||||
'expand' => __( 'Expand child menu', 'storefront' ),
|
||||
'collapse' => __( 'Collapse child menu', 'storefront' ),
|
||||
);
|
||||
|
||||
wp_localize_script( 'storefront-navigation', 'storefrontScreenReaderText', $storefront_l10n );
|
||||
}
|
||||
|
||||
if ( is_page_template( 'template-homepage.php' ) && has_post_thumbnail() ) {
|
||||
wp_enqueue_script( 'storefront-homepage', get_template_directory_uri() . '/assets/js/homepage' . $suffix . '.js', array(), $storefront_version, true );
|
||||
}
|
||||
|
||||
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
||||
wp_enqueue_script( 'comment-reply' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue child theme stylesheet.
|
||||
* A separate function is required as the child theme css needs to be enqueued _after_ the parent theme
|
||||
* primary css and the separate WooCommerce css.
|
||||
*
|
||||
* @since 1.5.3
|
||||
*/
|
||||
public function child_scripts() {
|
||||
if ( is_child_theme() ) {
|
||||
$child_theme = wp_get_theme( get_stylesheet() );
|
||||
wp_enqueue_style( 'storefront-child-style', get_stylesheet_uri(), array(), $child_theme->get( 'Version' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
|
||||
*
|
||||
* @param array $args Configuration arguments.
|
||||
* @return array
|
||||
*/
|
||||
public function page_menu_args( $args ) {
|
||||
$args['show_home'] = true;
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds custom classes to the array of body classes.
|
||||
*
|
||||
* @param array $classes Classes for the body element.
|
||||
* @return array
|
||||
*/
|
||||
public function body_classes( $classes ) {
|
||||
// Adds a class of group-blog to blogs with more than 1 published author.
|
||||
if ( is_multi_author() ) {
|
||||
$classes[] = 'group-blog';
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {
|
||||
$classes[] = 'no-wc-breadcrumb';
|
||||
}
|
||||
|
||||
/**
|
||||
* What is this?!
|
||||
* Take the blue pill, close this file and forget you saw the following code.
|
||||
* Or take the red pill, filter storefront_make_me_cute and see how deep the rabbit hole goes...
|
||||
*/
|
||||
$cute = apply_filters( 'storefront_make_me_cute', false );
|
||||
|
||||
if ( true === $cute ) {
|
||||
$classes[] = 'storefront-cute';
|
||||
}
|
||||
|
||||
// If our main sidebar doesn't contain widgets, adjust the layout to be full-width.
|
||||
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
|
||||
$classes[] = 'storefront-full-width-content';
|
||||
}
|
||||
|
||||
// Add class when using homepage template + featured image
|
||||
if ( is_page_template( 'template-homepage.php' ) && has_post_thumbnail() ) {
|
||||
$classes[] = 'has-post-thumbnail';
|
||||
}
|
||||
|
||||
// Add class when Secondary Navigation is in use
|
||||
if ( has_nav_menu( 'secondary' ) ) {
|
||||
$classes[] = 'storefront-secondary-navigation';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom navigation markup template hooked into `navigation_markup_template` filter hook.
|
||||
*/
|
||||
public function navigation_markup_template() {
|
||||
$template = '<nav id="post-navigation" class="navigation %1$s" role="navigation" aria-label="' . esc_html__( 'Post Navigation', 'storefront' ) . '">';
|
||||
$template .= '<h2 class="screen-reader-text">%2$s</h2>';
|
||||
$template .= '<div class="nav-links">%3$s</div>';
|
||||
$template .= '</nav>';
|
||||
|
||||
return apply_filters( 'storefront_navigation_markup_template', $template );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add styles for embeds
|
||||
*/
|
||||
public function print_embed_styles() {
|
||||
wp_enqueue_style( 'source-sans-pro', '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,300italic,400italic,700,900' );
|
||||
$accent_color = get_theme_mod( 'storefront_accent_color' );
|
||||
$background_color = storefront_get_content_background_color();
|
||||
?>
|
||||
<style type="text/css">
|
||||
.wp-embed {
|
||||
padding: 2.618em !important;
|
||||
border: 0 !important;
|
||||
border-radius: 3px !important;
|
||||
font-family: "Source Sans Pro", "Open Sans", sans-serif !important;
|
||||
background-color: <?php echo esc_html( storefront_adjust_color_brightness( $background_color, -7 ) ); ?> !important;
|
||||
}
|
||||
|
||||
.wp-embed .wp-embed-featured-image {
|
||||
margin-bottom: 2.618em;
|
||||
}
|
||||
|
||||
.wp-embed .wp-embed-featured-image img,
|
||||
.wp-embed .wp-embed-featured-image.square {
|
||||
min-width: 100%;
|
||||
margin-bottom: .618em;
|
||||
}
|
||||
|
||||
a.wc-embed-button {
|
||||
padding: .857em 1.387em !important;
|
||||
font-weight: 600;
|
||||
background-color: <?php echo esc_attr( $accent_color ); ?>;
|
||||
color: #fff !important;
|
||||
border: 0 !important;
|
||||
line-height: 1;
|
||||
border-radius: 0 !important;
|
||||
box-shadow:
|
||||
inset 0 -1px 0 rgba(#000,.3);
|
||||
}
|
||||
|
||||
a.wc-embed-button + a.wc-embed-button {
|
||||
background-color: #60646c;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
return new Storefront();
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Class to create a custom arbitrary html control for dividers etc
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The arbitrary control class
|
||||
*/
|
||||
class Arbitrary_Storefront_Control extends WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* The settings var
|
||||
*
|
||||
* @var string $settings the blog name.
|
||||
*/
|
||||
public $settings = 'blogname';
|
||||
|
||||
/**
|
||||
* The description var
|
||||
*
|
||||
* @var string $description the control description.
|
||||
*/
|
||||
public $description = '';
|
||||
|
||||
/**
|
||||
* Renter the control
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_content() {
|
||||
switch ( $this->type ) {
|
||||
default:
|
||||
case 'text' :
|
||||
echo '<p class="description">' . wp_kses_post( $this->description ) . '</p>';
|
||||
break;
|
||||
|
||||
case 'heading':
|
||||
echo '<span class="customize-control-title">' . esc_html( $this->label ) . '</span>';
|
||||
break;
|
||||
|
||||
case 'divider' :
|
||||
echo '<hr style="margin: 1em 0;" />';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Class to create a Customizer control for displaying information
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'more' Storefront control class
|
||||
*/
|
||||
class More_Storefront_Control extends WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* Render the content on the theme customizer page
|
||||
*/
|
||||
public function render_content() {
|
||||
?>
|
||||
<label style="overflow: hidden; zoom: 1;">
|
||||
|
||||
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
|
||||
|
||||
<p>
|
||||
<?php printf( esc_html__( 'There\'s a range of %s extensions available to put additional power in your hands. Check out the %s%s%s page in your dashboard for more information.', 'storefront' ), 'Storefront', '<a href="' . esc_url( admin_url() . 'themes.php?page=storefront-welcome' ) .'">', 'Storefront', '</a>' ); ?>
|
||||
</p>
|
||||
|
||||
<span class="customize-control-title"><?php printf( esc_html__( 'Enjoying %s?', 'storefront' ), 'Storefront' ); ?></span>
|
||||
|
||||
<p>
|
||||
<?php printf( esc_html__( 'Why not leave us a review on %sWordPress.org%s? We\'d really appreciate it!', 'storefront' ), '<a href="https://wordpress.org/themes/storefront">', '</a>' ); ?>
|
||||
</p>
|
||||
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Create a Radio-Image control
|
||||
*
|
||||
* This class incorporates code from the Kirki Customizer Framework and from a tutorial
|
||||
* written by Otto Wood.
|
||||
*
|
||||
* The Kirki Customizer Framework, Copyright Aristeides Stathopoulos (@aristath),
|
||||
* is licensed under the terms of the GNU GPL, Version 2 (or later).
|
||||
*
|
||||
* @link https://github.com/reduxframework/kirki/
|
||||
* @link http://ottopress.com/2012/making-a-custom-control-for-the-theme-customizer/
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The radio image class.
|
||||
*/
|
||||
class Storefront_Custom_Radio_Image_Control extends WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* Declare the control type.
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'radio-image';
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles for the custom control.
|
||||
*
|
||||
* Scripts are hooked at {@see 'customize_controls_enqueue_scripts'}.
|
||||
*
|
||||
* Note, you can also enqueue stylesheets here as well. Stylesheets are hooked
|
||||
* at 'customize_controls_print_styles'.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_script( 'jquery-ui-button' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the control to be displayed in the Customizer.
|
||||
*/
|
||||
public function render_content() {
|
||||
if ( empty( $this->choices ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = '_customize-radio-' . $this->id; ?>
|
||||
|
||||
<span class="customize-control-title">
|
||||
<?php echo esc_attr( $this->label ); ?>
|
||||
</span>
|
||||
|
||||
<?php if ( ! empty( $this->description ) ) : ?>
|
||||
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="input_<?php echo esc_attr( $this->id ); ?>" class="image">
|
||||
<?php foreach ( $this->choices as $value => $label ) : ?>
|
||||
<input class="image-select" type="radio" value="<?php echo esc_attr( $value ); ?>" id="<?php echo esc_attr( $this->id . $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?>>
|
||||
<label for="<?php echo esc_attr( $this->id ) . esc_attr( $value ); ?>">
|
||||
<img src="<?php echo esc_html( $label ); ?>" alt="<?php echo esc_attr( $value ); ?>" title="<?php echo esc_attr( $value ); ?>">
|
||||
</label>
|
||||
</input>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<script>jQuery(document).ready(function($) { $( '[id="input_<?php echo esc_attr( $this->id ); ?>"]' ).buttonset(); });</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Jetpack Class
|
||||
*
|
||||
* @package storefront
|
||||
* @author WooThemes
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_Jetpack' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront Jetpack integration class
|
||||
*/
|
||||
class Storefront_Jetpack {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'jetpack_setup' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'jetpack_scripts' ), 10 );
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
add_action( 'init', array( $this, 'jetpack_infinite_scroll_wrapper_columns' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add theme support for Infinite Scroll.
|
||||
* See: http://jetpack.me/support/infinite-scroll/
|
||||
*/
|
||||
public function jetpack_setup() {
|
||||
add_theme_support( 'infinite-scroll', apply_filters( 'storefront_jetpack_infinite_scroll_args', array(
|
||||
'container' => 'main',
|
||||
'footer' => 'page',
|
||||
'render' => array( $this, 'jetpack_infinite_scroll_loop' ),
|
||||
'footer_widgets' => array(
|
||||
'footer-1',
|
||||
'footer-2',
|
||||
'footer-3',
|
||||
'footer-4',
|
||||
),
|
||||
) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* A loop used to display content appended using Jetpack infinite scroll
|
||||
* @return void
|
||||
*/
|
||||
public function jetpack_infinite_scroll_loop() {
|
||||
do_action( 'storefront_jetpack_infinite_scroll_before' );
|
||||
|
||||
if ( storefront_is_product_archive() ) {
|
||||
do_action( 'storefront_jetpack_product_infinite_scroll_before' );
|
||||
woocommerce_product_loop_start();
|
||||
}
|
||||
|
||||
while ( have_posts() ) : the_post();
|
||||
if ( storefront_is_product_archive() ) {
|
||||
wc_get_template_part( 'content', 'product' );
|
||||
} else {
|
||||
get_template_part( 'content', get_post_format() );
|
||||
}
|
||||
endwhile; // end of the loop.
|
||||
|
||||
if ( storefront_is_product_archive() ) {
|
||||
woocommerce_product_loop_end();
|
||||
do_action( 'storefront_jetpack_product_infinite_scroll_after' );
|
||||
}
|
||||
|
||||
do_action( 'storefront_jetpack_infinite_scroll_after' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds columns wrapper to content appended by Jetpack infinite scroll
|
||||
* @return void
|
||||
*/
|
||||
public function jetpack_infinite_scroll_wrapper_columns() {
|
||||
add_action( 'storefront_jetpack_product_infinite_scroll_before', 'storefront_product_columns_wrapper' );
|
||||
add_action( 'storefront_jetpack_product_infinite_scroll_after', 'storefront_product_columns_wrapper_close' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue jetpack styles.
|
||||
*
|
||||
* @since 1.6.1
|
||||
*/
|
||||
public function jetpack_scripts() {
|
||||
global $storefront_version;
|
||||
|
||||
wp_enqueue_style( 'storefront-jetpack-style', get_template_directory_uri() . '/assets/css/jetpack/jetpack.css', '', $storefront_version );
|
||||
wp_style_add_data( 'storefront-jetpack-style', 'rtl', 'replace' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_Jetpack();
|
||||
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront NUX Admin Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_NUX_Admin' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront NUX Admin class
|
||||
*/
|
||||
class Storefront_NUX_Admin {
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_action( 'admin_notices', array( $this, 'admin_notices' ), 99 );
|
||||
add_action( 'wp_ajax_storefront_dismiss_notice', array( $this, 'dismiss_nux' ) );
|
||||
add_action( 'admin_post_storefront_starter_content', array( $this, 'redirect_customizer' ) );
|
||||
add_action( 'init', array( $this, 'log_fresh_site_state' ) );
|
||||
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
global $wp_customize, $storefront_version;
|
||||
|
||||
if ( isset( $wp_customize ) || true === (bool) get_option( 'storefront_nux_dismissed' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
wp_enqueue_style( 'storefront-admin-nux', get_template_directory_uri() . '/assets/css/admin/admin.css', '', $storefront_version );
|
||||
|
||||
wp_enqueue_script( 'storefront-admin-nux', get_template_directory_uri() . '/assets/js/admin/admin' . $suffix . '.js', array( 'jquery' ), $storefront_version, 'all' );
|
||||
|
||||
$storefront_nux = array(
|
||||
'nonce' => 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;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="notice notice-info sf-notice-nux is-dismissible">
|
||||
<span class="sf-icon">
|
||||
<?php echo '<img src="' . esc_url( get_template_directory_uri() ) . '/assets/images/admin/storefront-icon.svg" alt="Storefront" width="250" />'; ?>
|
||||
</span>
|
||||
|
||||
<div class="notice-content">
|
||||
<?php if ( ! storefront_is_woocommerce_activated() && current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) ) : ?>
|
||||
<h2><?php esc_attr_e( 'Thanks for installing Storefront, you rock! 🤘', 'storefront' ); ?></h2>
|
||||
<p><?php esc_attr_e( 'To enable eCommerce features you need to install the WooCommerce plugin.', 'storefront' ); ?></p>
|
||||
<p><?php Storefront_Plugin_Install::install_plugin_button( 'woocommerce', 'woocommerce.php', 'WooCommerce', array( 'sf-nux-button' ), __( 'WooCommerce activated', 'storefront' ), __( 'Activate WooCommerce', 'storefront' ), __( 'Install WooCommerce', 'storefront' ) ); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( storefront_is_woocommerce_activated() ) : ?>
|
||||
<h2><?php esc_html_e( 'Design your store 🎨', 'storefront' ); ?></h2>
|
||||
<p>
|
||||
<?php
|
||||
if ( true === (bool) get_option( 'storefront_nux_fresh_site' ) && 'post-new.php' === $pagenow ) {
|
||||
echo esc_attr__( 'Before you add your first product let\'s design your store. We\'ll add some example products for you. When you\'re ready let\'s get started by adding your logo.', 'storefront' );
|
||||
} else {
|
||||
echo esc_attr__( 'You\'ve set up WooCommerce, now it\'s time to give it some style! Let\'s get started by entering the Customizer and adding your logo.', 'storefront' );
|
||||
} ?>
|
||||
</p>
|
||||
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post">
|
||||
<input type="hidden" name="action" value="storefront_starter_content">
|
||||
<?php wp_nonce_field( 'storefront_starter_content' ); ?>
|
||||
|
||||
<?php if ( true === (bool) get_option( 'storefront_nux_fresh_site' ) ) : ?>
|
||||
<input type="hidden" name="homepage" value="on">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( true === (bool) get_option( 'storefront_nux_fresh_site' ) && true === $this->_is_woocommerce_empty() ) : ?>
|
||||
<input type="hidden" name="products" value="on">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( false === (bool) get_option( 'storefront_nux_fresh_site' ) ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="homepage" checked>
|
||||
<?php
|
||||
if ( 'page' === get_option( 'show_on_front' ) ) {
|
||||
esc_attr_e( 'Apply the Storefront homepage template', 'storefront' );
|
||||
} else {
|
||||
esc_attr_e( 'Create a homepage using Storefront\'s homepage template', 'storefront' );
|
||||
}
|
||||
?>
|
||||
</label>
|
||||
|
||||
<?php if ( true === $this->_is_woocommerce_empty() ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="products" checked>
|
||||
<?php esc_attr_e( 'Add example products', 'storefront' ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="submit" name="storefront-guided-tour" class="sf-nux-button" value="<?php esc_attr_e( 'Let\'s go!', 'storefront' ); ?>">
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php }
|
||||
|
||||
/**
|
||||
* AJAX dismiss notice.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function dismiss_nux() {
|
||||
$nonce = ! empty( $_POST['nonce'] ) ? $_POST['nonce'] : false;
|
||||
|
||||
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'storefront_notice_dismiss' ) || ! current_user_can( 'manage_options' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
update_option( 'storefront_nux_dismissed', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects to the customizer with the correct variables.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function redirect_customizer() {
|
||||
check_admin_referer( 'storefront_starter_content' );
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Dismiss notice.
|
||||
update_option( 'storefront_nux_dismissed', true );
|
||||
}
|
||||
|
||||
$args = array( 'sf_starter_content' => '1' );
|
||||
|
||||
$tasks = array();
|
||||
|
||||
if ( ! empty( $_REQUEST['homepage'] ) && 'on' === $_REQUEST['homepage'] ) {
|
||||
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' === $_REQUEST['products'] ) {
|
||||
$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'] = urlencode( 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
|
||||
* @param string $template
|
||||
* @return void
|
||||
*/
|
||||
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();
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront NUX Guided Tour Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_NUX_Guided_Tour' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront NUX Guided Tour class
|
||||
*/
|
||||
class Storefront_NUX_Guided_Tour {
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_init', array( $this, 'customizer' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Customizer.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function customizer() {
|
||||
global $pagenow;
|
||||
|
||||
if ( 'customize.php' === $pagenow && false === (bool) get_option( 'storefront_nux_guided_tour', false ) ) {
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_scripts' ) );
|
||||
add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) );
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Set Guided Tour flag so it doesn't show up again.
|
||||
update_option( 'storefront_nux_guided_tour', true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customizer enqueues.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function customize_scripts() {
|
||||
global $storefront_version;
|
||||
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
wp_enqueue_style( 'sp-guided-tour', get_template_directory_uri() . '/assets/css/admin/customizer/customizer.css', array(), $storefront_version, 'all' );
|
||||
|
||||
wp_enqueue_script( 'sf-guided-tour', get_template_directory_uri() . '/assets/js/admin/customizer' . $suffix . '.js', array( 'jquery', 'wp-backbone' ), $storefront_version, true );
|
||||
|
||||
wp_localize_script( 'sf-guided-tour', '_wpCustomizeSFGuidedTourSteps', $this->guided_tour_steps() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Template for steps.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function print_templates() {
|
||||
?>
|
||||
<script type="text/html" id="tmpl-sf-guided-tour-step">
|
||||
<div class="sf-guided-tour-step">
|
||||
<# if ( data.title ) { #>
|
||||
<h2>{{ data.title }}</h2>
|
||||
<# } #>
|
||||
{{{ data.message }}}
|
||||
<a class="sf-nux-button" href="#">
|
||||
<# if ( data.button_text ) { #>
|
||||
{{ data.button_text }}
|
||||
<# } else { #>
|
||||
<?php esc_attr_e( 'Next', 'storefront' ); ?>
|
||||
<# } #>
|
||||
</a>
|
||||
<# if ( ! data.last_step ) { #>
|
||||
<a class="sf-guided-tour-skip" href="#">
|
||||
<# if ( data.first_step ) { #>
|
||||
<?php esc_attr_e( 'No thanks, skip the tour', 'storefront' ); ?>
|
||||
<# } else { #>
|
||||
<?php esc_attr_e( 'Skip this step', 'storefront' ); ?>
|
||||
<# } #>
|
||||
</a>
|
||||
<# } #>
|
||||
</div>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Guided tour steps.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function guided_tour_steps() {
|
||||
$steps = array();
|
||||
|
||||
$steps[] = array(
|
||||
'title' => __( 'Welcome to the Customizer', 'storefront' ),
|
||||
'message' => sprintf( __( 'Here you can control the overall look and feel of your store.%sTo get started, let\'s add your logo', 'storefront' ), PHP_EOL . PHP_EOL ),
|
||||
'button_text' => __( 'Let\'s go!', 'storefront' ),
|
||||
'section' => '#customize-info',
|
||||
);
|
||||
|
||||
if ( ! has_custom_logo() ) {
|
||||
$steps[] = array(
|
||||
'title' => __( 'Add your logo', 'storefront' ),
|
||||
'message' => __( 'Open the Site Identity Panel, then click the \'Select Logo\' button to upload your logo.', 'storefront' ),
|
||||
'section' => 'title_tagline',
|
||||
);
|
||||
}
|
||||
|
||||
$steps[] = array(
|
||||
'title' => __( 'Customize your navigation menus', 'storefront' ),
|
||||
'message' => __( 'Organize your menus by adding Pages, Categories, Tags, and Custom Links.', 'storefront' ),
|
||||
'section' => 'nav_menus',
|
||||
);
|
||||
|
||||
$steps[] = array(
|
||||
'title' => __( 'Choose your accent color', 'storefront' ),
|
||||
'message' => __( 'In the typography panel you can specify an accent color which will be applied to things like links and star ratings. We recommend using your brand color for this setting.', 'storefront' ),
|
||||
'section' => 'storefront_typography',
|
||||
);
|
||||
|
||||
$steps[] = array(
|
||||
'title' => __( 'Color your buttons', 'storefront' ),
|
||||
'message' => __( 'Choose colors for your button backgrounds and text. Once again, brand colors are good choices here.', 'storefront' ),
|
||||
'section' => 'storefront_buttons',
|
||||
);
|
||||
|
||||
$steps[] = array(
|
||||
'title' => '',
|
||||
'message' => sprintf( __( 'All set! Remember to %ssave & publish%s your changes when you\'re done.%sYou can return to your dashboard by clicking the X in the top left corner.', 'storefront' ), '<strong>', '</strong>', PHP_EOL . PHP_EOL ),
|
||||
'section' => '#customize-header-actions .save',
|
||||
'button_text' => __( 'Done', 'storefront' ),
|
||||
);
|
||||
|
||||
return $steps;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_NUX_Guided_Tour();
|
||||
@@ -0,0 +1,988 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront NUX Starter Content Class
|
||||
*
|
||||
* @author WooThemes
|
||||
* @package storefront
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_NUX_Starter_Content' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront NUX Starter Content class
|
||||
*/
|
||||
class Storefront_NUX_Starter_Content {
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'after_setup_theme', array( $this, 'starter_content' ) );
|
||||
add_filter( 'get_theme_starter_content', array( $this, 'filter_start_content' ), 10, 2 );
|
||||
add_action( 'woocommerce_product_query', array( $this, 'wc_query' ) );
|
||||
add_filter( 'woocommerce_shortcode_products_query', array( $this, 'shortcode_loop_products' ), 10, 3 );
|
||||
add_action( 'customize_preview_init', array( $this, 'add_product_tax' ), 10 );
|
||||
add_action( 'customize_preview_init', array( $this, 'set_product_data' ), 10 );
|
||||
add_action( 'after_setup_theme', array( $this, 'remove_default_widgets' ) );
|
||||
add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 10, 3 );
|
||||
add_filter( 'the_title', array( $this, 'filter_auto_draft_title' ) , 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove default widgets on activation
|
||||
* Set an option so that this is only done the first time the user activates Storefront.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @return void
|
||||
*/
|
||||
public function remove_default_widgets() {
|
||||
if ( false === (bool) get_option( 'storefront_cleared_widgets' ) && true === (bool) get_option( 'storefront_nux_fresh_site' ) ) {
|
||||
update_option( 'sidebars_widgets', array( 'wp_inactive_widgets' => array() ) );
|
||||
update_option( 'storefront_cleared_widgets', true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starter content.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function starter_content() {
|
||||
$starter_content = array(
|
||||
'posts' => array(
|
||||
'home' => array(
|
||||
'post_title' => esc_attr__( 'Welcome', 'storefront' ),
|
||||
'post_content' => sprintf( esc_attr__( 'This is your homepage which is what most visitors will see when they first visit your shop.%sYou can change this text by editing the "Welcome" page via the "Pages" menu in your dashboard.', 'storefront' ), PHP_EOL . PHP_EOL ),
|
||||
'template' => 'template-homepage.php',
|
||||
'thumbnail' => '{{hero-image}}',
|
||||
),
|
||||
'about' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'About', 'storefront' ),
|
||||
'post_content' => __( 'You might be an artist who would like to introduce yourself and your work here or maybe you’re a business with a mission to describe.', 'storefront' ),
|
||||
),
|
||||
'contact' => array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => __( 'Contact', 'storefront' ),
|
||||
'post_content' => __( 'This is a page with some basic contact information, such as an address and phone number. You might also try a plugin to add a contact form.', 'storefront' ),
|
||||
),
|
||||
'blog'
|
||||
),
|
||||
'attachments' => array(
|
||||
'beanie-image' => array(
|
||||
'post_title' => 'Beanie',
|
||||
'file' => 'assets/images/customizer/starter-content/products/beanie.jpg',
|
||||
),
|
||||
'belt-image' => array(
|
||||
'post_title' => 'Belt',
|
||||
'file' => 'assets/images/customizer/starter-content/products/belt.jpg',
|
||||
),
|
||||
'cap-image' => array(
|
||||
'post_title' => 'Cap',
|
||||
'file' => 'assets/images/customizer/starter-content/products/cap.jpg',
|
||||
),
|
||||
'hoodie-with-logo-image' => array(
|
||||
'post_title' => 'Hoodie with Logo',
|
||||
'file' => 'assets/images/customizer/starter-content/products/hoodie-with-logo.jpg',
|
||||
),
|
||||
'hoodie-with-pocket-image' => array(
|
||||
'post_title' => 'Hoodie with Pocket',
|
||||
'file' => 'assets/images/customizer/starter-content/products/hoodie-with-pocket.jpg',
|
||||
),
|
||||
'hoodie-with-zipper-image' => array(
|
||||
'post_title' => 'Hoodie with Zipper',
|
||||
'file' => 'assets/images/customizer/starter-content/products/hoodie-with-zipper.jpg',
|
||||
),
|
||||
'hoodie-image' => array(
|
||||
'post_title' => 'Hoodie',
|
||||
'file' => 'assets/images/customizer/starter-content/products/hoodie.jpg',
|
||||
),
|
||||
'long-sleeve-tee-image' => array(
|
||||
'post_title' => 'Long Sleeve Tee',
|
||||
'file' => 'assets/images/customizer/starter-content/products/long-sleeve-tee.jpg',
|
||||
),
|
||||
'polo-image' => array(
|
||||
'post_title' => 'Polo',
|
||||
'file' => 'assets/images/customizer/starter-content/products/polo.jpg',
|
||||
),
|
||||
'sunglasses-image' => array(
|
||||
'post_title' => 'Sunglasses',
|
||||
'file' => 'assets/images/customizer/starter-content/products/sunglasses.jpg',
|
||||
),
|
||||
'tshirt-image' => array(
|
||||
'post_title' => 'Tshirt',
|
||||
'file' => 'assets/images/customizer/starter-content/products/tshirt.jpg',
|
||||
),
|
||||
'vneck-tee-image' => array(
|
||||
'post_title' => 'Vneck Tshirt',
|
||||
'file' => 'assets/images/customizer/starter-content/products/vneck-tee.jpg',
|
||||
),
|
||||
'hero-image' => array(
|
||||
'post_title' => 'Hero',
|
||||
'file' => 'assets/images/customizer/starter-content/hero.jpg',
|
||||
),
|
||||
'accessories-image' => array(
|
||||
'post_title' => 'Accessories',
|
||||
'file' => 'assets/images/customizer/starter-content/categories/accessories.jpg',
|
||||
),
|
||||
'tshirts-image' => array(
|
||||
'post_title' => 'T-shirts',
|
||||
'file' => 'assets/images/customizer/starter-content/categories/tshirts.jpg',
|
||||
),
|
||||
'hoodies-image' => array(
|
||||
'post_title' => 'Hoodies',
|
||||
'file' => 'assets/images/customizer/starter-content/categories/hoodies.jpg',
|
||||
),
|
||||
),
|
||||
'options' => array(
|
||||
'show_on_front' => 'page',
|
||||
'page_on_front' => '{{home}}',
|
||||
'page_for_posts' => '{{blog}}',
|
||||
),
|
||||
'widgets' => array(
|
||||
'footer-1' => array(
|
||||
'text_about'
|
||||
),
|
||||
'footer-2' => array(
|
||||
'text_business_info'
|
||||
),
|
||||
),
|
||||
'nav_menus' => array(
|
||||
'primary' => array(
|
||||
'name' => __( 'Primary Menu', 'storefront' ),
|
||||
'items' => array(
|
||||
'shop' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{sf_shop}}',
|
||||
),
|
||||
'page_about' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{about}}',
|
||||
),
|
||||
'page_contact' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{contact}}',
|
||||
),
|
||||
),
|
||||
),
|
||||
'secondary' => array(
|
||||
'name' => __( 'Secondary Menu', 'storefront' ),
|
||||
'items' => array(
|
||||
'my_account' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{sf_my-account}}',
|
||||
),
|
||||
),
|
||||
),
|
||||
'handheld' => array(
|
||||
'name' => __( 'Handheld Menu', 'storefront' ),
|
||||
'items' => array(
|
||||
'shop' => array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'page',
|
||||
'object_id' => '{{sf_shop}}',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Add products.
|
||||
$starter_content_wc_products = $this->_starter_content_products();
|
||||
|
||||
if ( ! empty( $starter_content_wc_products ) ) {
|
||||
$starter_content['posts'] = array_merge( $starter_content['posts'], $starter_content_wc_products );
|
||||
}
|
||||
|
||||
// Use symbols as post name for attachments.
|
||||
foreach ( $starter_content['attachments'] as $symbol => $attachment ) {
|
||||
$starter_content['attachments'][ $symbol ]['post_name'] = $symbol;
|
||||
}
|
||||
|
||||
// Add WooCommerce pages.
|
||||
$starter_content_wc_pages = array();
|
||||
$woocommerce_pages = Storefront_NUX_Admin::get_woocommerce_pages();
|
||||
|
||||
foreach ( $woocommerce_pages as $option => $page_id ) {
|
||||
$page = get_post( $page_id );
|
||||
|
||||
if ( null !== $page ) {
|
||||
$starter_content_wc_pages[ 'sf_' . $page->post_name ] = array(
|
||||
'post_title' => $page->post_title,
|
||||
'post_name' => $page->post_name,
|
||||
'post_type' => 'page',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $starter_content_wc_pages ) ) {
|
||||
$starter_content['posts'] = array_merge( $starter_content['posts'], $starter_content_wc_pages );
|
||||
}
|
||||
|
||||
// Register support for starter content.
|
||||
add_theme_support( 'starter-content', apply_filters( 'storefront_starter_content', $starter_content ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters starter content and remove some of the content if necessary.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param array $content Starter content.
|
||||
* @param array $config Config.
|
||||
* @return array $content
|
||||
*/
|
||||
public function filter_start_content( $content, $config ) {
|
||||
if ( ! isset( $_GET['sf_starter_content'] ) || 1 !== absint( $_GET['sf_starter_content'] ) ) {
|
||||
|
||||
// We only allow starter content if the users comes from the NUX wizard.
|
||||
return $content;
|
||||
}
|
||||
|
||||
$tasks = array();
|
||||
|
||||
if ( isset( $_GET['sf_tasks'] ) && '' !== sanitize_text_field( $_GET['sf_tasks'] ) ) {
|
||||
$tasks = explode( ',', sanitize_text_field( $_GET['sf_tasks'] ) );
|
||||
}
|
||||
|
||||
$tasks = $this->_validate_tasks( $tasks );
|
||||
|
||||
foreach ( $tasks as $task ) {
|
||||
switch ( $task ) {
|
||||
case 'homepage':
|
||||
unset( $content['options'] );
|
||||
unset( $content['posts']['home'] );
|
||||
unset( $content['posts']['blog'] );
|
||||
|
||||
break;
|
||||
|
||||
case 'products':
|
||||
if ( isset( $content['posts'] ) ) {
|
||||
foreach ( $content['posts'] as $post_id => $post ) {
|
||||
if ( isset( $post['post_type'] ) && 'product' === $post['post_type'] ) {
|
||||
unset( $content['posts'][ $post_id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset( $content['posts']['about'] );
|
||||
unset( $content['posts']['contact'] );
|
||||
unset( $content['attachments'] );
|
||||
unset( $content['nav_menus'] );
|
||||
unset( $content['widgets'] );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Existing site: remove custom pages, navigation menus and widgets from starter content.
|
||||
if ( true !== (bool) get_option( 'storefront_nux_fresh_site' ) ) {
|
||||
unset( $content['posts']['about'] );
|
||||
unset( $content['posts']['contact'] );
|
||||
unset( $content['nav_menus'] );
|
||||
unset( $content['widgets'] );
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter WooCommerce main query to include starter content products.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param object $query The Query.
|
||||
* @return void
|
||||
*/
|
||||
public function wc_query( $query ) {
|
||||
if ( ! is_customize_preview() || true !== (bool) get_option( 'fresh_site' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post__in = array();
|
||||
|
||||
// Add existing products.
|
||||
$existing_products = $this->_get_existing_wc_products();
|
||||
|
||||
if ( ! empty( $existing_products ) ) {
|
||||
$post__in = array_merge( $post__in, $existing_products );
|
||||
}
|
||||
|
||||
// Add starter content.
|
||||
$created_products = $this->_get_created_starter_content_products();
|
||||
|
||||
if ( false !== $created_products ) {
|
||||
|
||||
// Merge starter content products.
|
||||
$post__in = array_merge( $post__in, $created_products );
|
||||
|
||||
// Allow for multiple status.
|
||||
$query->set( 'post_status', get_post_stati() );
|
||||
}
|
||||
|
||||
// Add products to query.
|
||||
$query->set( 'post__in', $post__in );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter shortcode products loop in WooCommerce.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param array $query_args Query args.
|
||||
* @param array $atts Shortcode attributes.
|
||||
* @param string $loop_name Loop name.
|
||||
* @return array $args
|
||||
*/
|
||||
public function shortcode_loop_products( $query_args, $atts, $loop_name = null ) {
|
||||
if ( ! is_customize_preview() || true !== (bool) get_option( 'fresh_site' ) ) {
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
$query_args['post__in'] = array();
|
||||
|
||||
// Add existing products to query
|
||||
$existing_products = $this->_get_existing_wc_products();
|
||||
|
||||
if ( ! empty( $existing_products ) ) {
|
||||
$query_args['post__in'] = array_merge( $query_args['post__in'], $existing_products );
|
||||
}
|
||||
|
||||
// Add starter content to query
|
||||
$created_products = $this->_get_created_starter_content_products();
|
||||
|
||||
if ( false !== $created_products ) {
|
||||
|
||||
// Add created products to query.
|
||||
$query_args['post__in'] = array_merge( $query_args['post__in'], $created_products );
|
||||
|
||||
// Allow for multiple status.
|
||||
$query_args['post_status'] = get_post_stati();
|
||||
}
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add product taxonomies to starter content.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function add_product_tax() {
|
||||
if ( ! is_customize_preview() || true !== (bool) get_option( 'fresh_site' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$created_products = $this->_get_created_starter_content_products();
|
||||
|
||||
if ( false === $created_products ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$starter_products = $this->_starter_content_products();
|
||||
|
||||
if ( is_array( $created_products ) ) {
|
||||
foreach ( $created_products as $product ) {
|
||||
$product = get_post( $product );
|
||||
|
||||
if ( ! $product ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$post_name = get_post_meta( $product->ID, '_customize_draft_post_name', true );
|
||||
|
||||
if ( ! $post_name || ! array_key_exists( $post_name, $starter_products ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$taxonomies = array( 'product_cat', 'product_tag' );
|
||||
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
if ( array_key_exists( $taxonomy, $starter_products[ $post_name ]['taxonomy'] ) ) {
|
||||
$categories = $starter_products[ $post_name ]['taxonomy'][ $taxonomy ];
|
||||
|
||||
if ( ! empty( $categories ) ) {
|
||||
$category_ids = array();
|
||||
|
||||
foreach ( $categories as $category ) {
|
||||
// Check if the term already exists.
|
||||
$category_exists = term_exists( $category['term'], $taxonomy );
|
||||
|
||||
if ( $category_exists ) {
|
||||
$category_ids[] = (int) $category_exists['term_id'];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create new category.
|
||||
$created_category = wp_insert_term(
|
||||
$category['term'],
|
||||
$taxonomy,
|
||||
array(
|
||||
'description' => $category['description'],
|
||||
'slug' => $category['slug'],
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_wp_error( $created_category ) ) {
|
||||
$category_ids[] = $created_category['term_id'];
|
||||
|
||||
$category_image = $this->_get_category_image_attachment_id( $category['slug'] );
|
||||
|
||||
if ( $category_image ) {
|
||||
update_term_meta( (int) $created_category['term_id'], 'thumbnail_id', $category_image );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wp_set_object_terms( $product->ID, $category_ids, $taxonomy );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'storefront_product_categories_shortcode_args', array( $this, 'filter_sf_categories' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add product data to starter products.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @return void
|
||||
*/
|
||||
public function set_product_data() {
|
||||
if ( ! is_customize_preview() || true !== (bool) get_option( 'fresh_site' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$created_products = $this->_get_created_starter_content_products();
|
||||
|
||||
if ( false === $created_products ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$starter_products = $this->_starter_content_products();
|
||||
|
||||
if ( is_array( $created_products ) ) {
|
||||
foreach ( $created_products as $product ) {
|
||||
$product = wc_get_product( $product );
|
||||
|
||||
if ( ! $product ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$post_name = get_post_meta( $product->get_id(), '_customize_draft_post_name', true );
|
||||
|
||||
if ( ! $post_name || ! array_key_exists( $post_name, $starter_products ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! array_key_exists( 'product_data', $starter_products[ $post_name ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$product_data = $starter_products[ $post_name ]['product_data'];
|
||||
|
||||
// Set visibility
|
||||
$product->set_catalog_visibility( 'visible' );
|
||||
|
||||
// Set regular price
|
||||
if ( ! empty( $product_data['regular_price'] ) ) {
|
||||
$product->set_regular_price( floatval( $product_data['regular_price'] ) );
|
||||
}
|
||||
|
||||
// Set price
|
||||
if ( ! empty( $product_data['price'] ) ) {
|
||||
$product->set_price( floatval( $product_data['price'] ) );
|
||||
}
|
||||
|
||||
// Set sale price
|
||||
if ( ! empty( $product_data['sale_price'] ) ) {
|
||||
$product->set_sale_price( floatval( $product_data['sale_price'] ) );
|
||||
}
|
||||
|
||||
// Set featured
|
||||
if ( ! empty( $product_data['featured'] ) ) {
|
||||
$product->set_featured( true );
|
||||
} else {
|
||||
$product->set_featured( false );
|
||||
}
|
||||
|
||||
// Save
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter Storefront Product Categories shortcode.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param array $args Shortcode args.
|
||||
* @return array $args
|
||||
*/
|
||||
public function filter_sf_categories( $args ) {
|
||||
// Get Categories.
|
||||
$product_cats = get_terms( 'product_cat', array( 'fields' => 'ids', 'hide_empty' => false ) );
|
||||
|
||||
if ( ! empty( $product_cats ) ) {
|
||||
|
||||
// Needs to be set for categories to show up.
|
||||
$args['hide_empty'] = false;
|
||||
|
||||
// List of categories to display.
|
||||
$args['ids'] = implode( $product_cats, ',' );
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce 3.0.0 changes the title of all auto-draft products to "AUTO-DRAFT".
|
||||
* Here we change the title back when the post status changes.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $new_status
|
||||
* @param string $old_status
|
||||
* @param object $post
|
||||
*/
|
||||
public function transition_post_status( $new_status, $old_status, $post ) {
|
||||
if ( 'publish' === $new_status && 'auto-draft' === $old_status && in_array( $post->post_type, array( 'product' ) ) ) {
|
||||
$post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true );
|
||||
|
||||
$starter_products = $this->_starter_content_products();
|
||||
|
||||
if ( $post_name && array_key_exists( $post_name, $starter_products ) ) {
|
||||
$update_product = array(
|
||||
'ID' => $post->ID,
|
||||
'post_title' => $starter_products[ $post_name ]['post_title']
|
||||
);
|
||||
|
||||
wp_update_post( $update_product );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce 3.0.0 changes the title of all auto-draft products to "AUTO-DRAFT".
|
||||
* Here we filter the title and display the correct one instead.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $title
|
||||
* @param int $post_id
|
||||
*/
|
||||
public function filter_auto_draft_title( $title, $post_id = null ) {
|
||||
if ( ! $post_id ) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( $post && 'auto-draft' === $post->post_status && in_array( $post->post_type, array( 'product' ) ) && 'AUTO-DRAFT' === $post->post_title ) {
|
||||
$post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true );
|
||||
|
||||
$starter_products = $this->_starter_content_products();
|
||||
|
||||
if ( $post_name && array_key_exists( $post_name, $starter_products ) ) {
|
||||
return $starter_products[ $post_name ]['post_title'];
|
||||
}
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starter content products.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
private function _starter_content_products() {
|
||||
$accessories_name = esc_attr__( 'Accessories', 'storefront' );
|
||||
$accessories_description = esc_attr__( 'A short category description', 'storefront' );
|
||||
|
||||
$hoodies_name = esc_attr__( 'Hoodies', 'storefront' );
|
||||
$hoodies_description = esc_attr__( 'A short category description', 'storefront' );
|
||||
|
||||
$tshirts_name = esc_attr__( 'Tshirts', 'storefront' );
|
||||
$tshirts_description = esc_attr__( 'A short category description', 'storefront' );
|
||||
|
||||
$products = array(
|
||||
// Accessories
|
||||
'beanie' => array(
|
||||
'post_title' => esc_attr__( 'Beanie', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{beanie-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '20',
|
||||
'price' => '18',
|
||||
'sale_price' => '18',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $accessories_name,
|
||||
'slug' => 'accessories',
|
||||
'description' => $accessories_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
'belt' => array(
|
||||
'post_title' => esc_attr__( 'Belt', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{belt-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '65',
|
||||
'price' => '55',
|
||||
'sale_price' => '55',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $accessories_name,
|
||||
'slug' => 'accessories',
|
||||
'description' => $accessories_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'cap' => array(
|
||||
'post_title' => esc_attr__( 'Cap', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{cap-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '18',
|
||||
'price' => '16',
|
||||
'sale_price' => '16',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $accessories_name,
|
||||
'slug' => 'accessories',
|
||||
'description' => $accessories_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'sunglasses' => array(
|
||||
'post_title' => esc_attr__( 'Sunglasses', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{sunglasses-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '90',
|
||||
'price' => '90',
|
||||
'featured' => true,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $accessories_name,
|
||||
'slug' => 'accessories',
|
||||
'description' => $accessories_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'hoodie-with-logo' => array(
|
||||
'post_title' => esc_attr__( 'Hoodie with Logo', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{hoodie-with-logo-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '45',
|
||||
'price' => '45',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $hoodies_name,
|
||||
'slug' => 'hoodies',
|
||||
'description' => $hoodies_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'hoodie-with-pocket' => array(
|
||||
'post_title' => esc_attr__( 'Hoodie with Pocket', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{hoodie-with-pocket-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '45',
|
||||
'price' => '35',
|
||||
'sale_price' => '35',
|
||||
'featured' => true,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $hoodies_name,
|
||||
'slug' => 'hoodies',
|
||||
'description' => $hoodies_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'hoodie-with-zipper' => array(
|
||||
'post_title' => esc_attr__( 'Hoodie with Zipper', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{hoodie-with-zipper-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '45',
|
||||
'price' => '45',
|
||||
'featured' => true,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $hoodies_name,
|
||||
'slug' => 'hoodies',
|
||||
'description' => $hoodies_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'hoodie' => array(
|
||||
'post_title' => esc_attr__( 'Hoodie', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{hoodie-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '45',
|
||||
'price' => '42',
|
||||
'sale_price' => '42',
|
||||
'featured' => true,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $hoodies_name,
|
||||
'slug' => 'hoodies',
|
||||
'description' => $hoodies_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'long-sleeve-tee' => array(
|
||||
'post_title' => esc_attr__( 'Long Sleeve Tee', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{long-sleeve-tee-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '25',
|
||||
'price' => '25',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $tshirts_name,
|
||||
'slug' => 'tshirts',
|
||||
'description' => $tshirts_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'polo' => array(
|
||||
'post_title' => esc_attr__( 'Polo', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{polo-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '20',
|
||||
'price' => '20',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $tshirts_name,
|
||||
'slug' => 'tshirts',
|
||||
'description' => $tshirts_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'tshirt' => array(
|
||||
'post_title' => esc_attr__( 'Tshirt', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{tshirt-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '18',
|
||||
'price' => '18',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $tshirts_name,
|
||||
'slug' => 'tshirts',
|
||||
'description' => $tshirts_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'vneck-tee' => array(
|
||||
'post_title' => esc_attr__( 'Vneck Tshirt', 'storefront' ),
|
||||
'post_content' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
|
||||
'post_type' => 'product',
|
||||
'comment_status' => 'open',
|
||||
'thumbnail' => '{{vneck-tee-image}}',
|
||||
'product_data' => array(
|
||||
'regular_price' => '18',
|
||||
'price' => '18',
|
||||
'featured' => false,
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'product_cat' => array(
|
||||
array(
|
||||
'term' => $tshirts_name,
|
||||
'slug' => 'tshirts',
|
||||
'description' => $tshirts_description,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Use symbols as post name.
|
||||
foreach ( $products as $symbol => $product ) {
|
||||
$products[ $symbol ]['post_name'] = $symbol;
|
||||
}
|
||||
|
||||
return apply_filters( 'storefront_starter_content_products', $products );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of posts created by starter content.
|
||||
*
|
||||
* @since 2.2.1
|
||||
* @return mixed false|rray $query Array of post ids.
|
||||
*/
|
||||
private function _get_created_starter_content_products() {
|
||||
global $wp_customize;
|
||||
|
||||
$data = $wp_customize->get_setting( 'nav_menus_created_posts' );
|
||||
$created_products_ids = $data->value();
|
||||
|
||||
if ( ! empty( $created_products_ids ) ) {
|
||||
return (array) $created_products_ids;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of existing products in the store.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @return array $query Array of product ids.
|
||||
*/
|
||||
private function _get_existing_wc_products() {
|
||||
$query_args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'fields' => 'ids',
|
||||
'posts_per_page' => -1,
|
||||
);
|
||||
|
||||
$products = get_posts( $query_args );
|
||||
|
||||
if ( $products && ! empty( $products ) ) {
|
||||
return $products;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a category slug, find the related image attachment.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $category Category.
|
||||
* @return mixed false|int $query first attachment found.
|
||||
*/
|
||||
private function _get_category_image_attachment_id( $category ) {
|
||||
$query_args = array(
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'auto-draft',
|
||||
'fields' => 'ids',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_customize_draft_post_name',
|
||||
'value' => $category . '-image',
|
||||
'compare' => '=',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$query = get_posts( $query_args );
|
||||
|
||||
if ( $query && ! empty( $query ) ) {
|
||||
return $query[0];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and sanitizes a given tasks list.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $tasks The tasks.
|
||||
* @return mixed false|array $validated_tasks if tasks list is not empty.
|
||||
*/
|
||||
private function _validate_tasks( $tasks ) {
|
||||
$valid_tasks = apply_filters( 'storefront_valid_tour_tasks', array( 'homepage', 'products' ) );
|
||||
|
||||
$validated_tasks = array();
|
||||
|
||||
foreach ( $tasks as $task ) {
|
||||
$task = sanitize_key( $task );
|
||||
|
||||
if ( in_array( $task, $valid_tasks, true ) ) {
|
||||
$validated_tasks[] = $task;
|
||||
}
|
||||
}
|
||||
|
||||
$validated_tasks = array_diff( $valid_tasks, $validated_tasks );
|
||||
|
||||
return $validated_tasks;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_NUX_Starter_Content();
|
||||
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront functions.
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'storefront_is_woocommerce_activated' ) ) {
|
||||
/**
|
||||
* Query WooCommerce activation
|
||||
*/
|
||||
function storefront_is_woocommerce_activated() {
|
||||
return class_exists( 'WooCommerce' ) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current page is a product archive
|
||||
* @return boolean
|
||||
*/
|
||||
function storefront_is_product_archive() {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
if ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a shortcode function by tag name.
|
||||
*
|
||||
* @since 1.4.6
|
||||
*
|
||||
* @param string $tag The shortcode whose function to call.
|
||||
* @param array $atts The attributes to pass to the shortcode function. Optional.
|
||||
* @param array $content The shortcode's content. Default is null (none).
|
||||
*
|
||||
* @return string|bool False on failure, the result of the shortcode on success.
|
||||
*/
|
||||
function storefront_do_shortcode( $tag, array $atts = array(), $content = null ) {
|
||||
global $shortcode_tags;
|
||||
|
||||
if ( ! isset( $shortcode_tags[ $tag ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return call_user_func( $shortcode_tags[ $tag ], $atts, $content, $tag );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content background color
|
||||
* Accounts for the Storefront Designer and Storefront Powerpack content background option.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @return string the background color
|
||||
*/
|
||||
function storefront_get_content_background_color() {
|
||||
if ( class_exists( 'Storefront_Designer' ) ) {
|
||||
$content_bg_color = get_theme_mod( 'sd_content_background_color' );
|
||||
$content_frame = get_theme_mod( 'sd_fixed_width' );
|
||||
}
|
||||
|
||||
if ( class_exists( 'Storefront_Powerpack' ) ) {
|
||||
$content_bg_color = get_theme_mod( 'sp_content_frame_background' );
|
||||
$content_frame = get_theme_mod( 'sp_content_frame' );
|
||||
}
|
||||
|
||||
$bg_color = str_replace( '#', '', get_theme_mod( 'background_color' ) );
|
||||
|
||||
if ( class_exists( 'Storefront_Powerpack' ) || class_exists( 'Storefront_Designer' ) ) {
|
||||
if ( $content_bg_color && ( 'true' == $content_frame || 'frame' == $content_frame ) ) {
|
||||
$bg_color = str_replace( '#', '', $content_bg_color );
|
||||
}
|
||||
}
|
||||
|
||||
return '#' . $bg_color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply inline style to the Storefront header.
|
||||
*
|
||||
* @uses get_header_image()
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function storefront_header_styles() {
|
||||
$is_header_image = get_header_image();
|
||||
$header_bg_image = '';
|
||||
|
||||
if ( $is_header_image ) {
|
||||
$header_bg_image = 'url(' . esc_url( $is_header_image ) . ')';
|
||||
}
|
||||
|
||||
$styles = array();
|
||||
|
||||
if ( '' !== $header_bg_image ) {
|
||||
$styles['background-image'] = $header_bg_image;
|
||||
}
|
||||
|
||||
$styles = apply_filters( 'storefront_header_styles', $styles );
|
||||
|
||||
foreach ( $styles as $style => $value ) {
|
||||
echo esc_attr( $style . ': ' . $value . '; ' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply inline style to the Storefront homepage content.
|
||||
*
|
||||
* @uses get_the_post_thumbnail_url()
|
||||
* @since 2.2.0
|
||||
*/
|
||||
function storefront_homepage_content_styles() {
|
||||
$featured_image = get_the_post_thumbnail_url( get_the_ID() );
|
||||
$background_image = '';
|
||||
|
||||
if ( $featured_image ) {
|
||||
$background_image = 'url(' . esc_url( $featured_image ) . ')';
|
||||
}
|
||||
|
||||
$styles = array();
|
||||
|
||||
if ( '' !== $background_image ) {
|
||||
$styles['background-image'] = $background_image;
|
||||
}
|
||||
|
||||
$styles = apply_filters( 'storefront_homepage_content_styles', $styles );
|
||||
|
||||
foreach ( $styles as $style => $value ) {
|
||||
echo esc_attr( $style . ': ' . $value . '; ' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust a hex color brightness
|
||||
* Allows us to create hover styles for custom link colors
|
||||
*
|
||||
* @param strong $hex hex color e.g. #111111.
|
||||
* @param integer $steps factor by which to brighten/darken ranging from -255 (darken) to 255 (brighten).
|
||||
* @return string brightened/darkened hex color
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_adjust_color_brightness( $hex, $steps ) {
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter.
|
||||
$steps = max( -255, min( 255, $steps ) );
|
||||
|
||||
// Format the hex color string.
|
||||
$hex = str_replace( '#', '', $hex );
|
||||
|
||||
if ( 3 == strlen( $hex ) ) {
|
||||
$hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
|
||||
}
|
||||
|
||||
// Get decimal values.
|
||||
$r = hexdec( substr( $hex, 0, 2 ) );
|
||||
$g = hexdec( substr( $hex, 2, 2 ) );
|
||||
$b = hexdec( substr( $hex, 4, 2 ) );
|
||||
|
||||
// Adjust number of steps and keep it inside 0 to 255.
|
||||
$r = max( 0, min( 255, $r + $steps ) );
|
||||
$g = max( 0, min( 255, $g + $steps ) );
|
||||
$b = max( 0, min( 255, $b + $steps ) );
|
||||
|
||||
$r_hex = str_pad( dechex( $r ), 2, '0', STR_PAD_LEFT );
|
||||
$g_hex = str_pad( dechex( $g ), 2, '0', STR_PAD_LEFT );
|
||||
$b_hex = str_pad( dechex( $b ), 2, '0', STR_PAD_LEFT );
|
||||
|
||||
return '#' . $r_hex . $g_hex . $b_hex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes choices (selects / radios)
|
||||
* Checks that the input matches one of the available choices
|
||||
*
|
||||
* @param array $input the available choices.
|
||||
* @param array $setting the setting object.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
function storefront_sanitize_choices( $input, $setting ) {
|
||||
// Ensure input is a slug.
|
||||
$input = sanitize_key( $input );
|
||||
|
||||
// Get list of choices from the control associated with the setting.
|
||||
$choices = $setting->manager->get_control( $setting->id )->choices;
|
||||
|
||||
// If the input is a valid key, return it; otherwise, return the default.
|
||||
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox sanitization callback.
|
||||
*
|
||||
* Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked`
|
||||
* as a boolean value, either TRUE or FALSE.
|
||||
*
|
||||
* @param bool $checked Whether the checkbox is checked.
|
||||
* @return bool Whether the checkbox is checked.
|
||||
* @since 1.5.0
|
||||
*/
|
||||
function storefront_sanitize_checkbox( $checked ) {
|
||||
return ( ( isset( $checked ) && true == $checked ) ? true : false );
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'is_woocommerce_activated' ) ) {
|
||||
/**
|
||||
* Query WooCommerce activation
|
||||
*/
|
||||
function is_woocommerce_activated() {
|
||||
_deprecated_function( 'is_woocommerce_activated', '2.1.6', 'storefront_is_woocommerce_activated' );
|
||||
|
||||
return class_exists( 'woocommerce' ) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schema type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function storefront_html_tag_schema() {
|
||||
_deprecated_function( 'storefront_html_tag_schema', '2.0.2' );
|
||||
|
||||
$schema = 'http://schema.org/';
|
||||
$type = 'WebPage';
|
||||
|
||||
if ( is_singular( 'post' ) ) {
|
||||
$type = 'Article';
|
||||
} elseif ( is_author() ) {
|
||||
$type = 'ProfilePage';
|
||||
} elseif ( is_search() ) {
|
||||
$type = 'SearchResultsPage';
|
||||
}
|
||||
|
||||
echo 'itemscope="itemscope" itemtype="' . esc_attr( $schema ) . esc_attr( $type ) . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes the layout setting
|
||||
*
|
||||
* Ensures only array keys matching the original settings specified in add_control() are valid
|
||||
*
|
||||
* @param array $input the layout options.
|
||||
* @since 1.0.3
|
||||
*/
|
||||
function storefront_sanitize_layout( $input ) {
|
||||
_deprecated_function( 'storefront_sanitize_layout', '2.0', 'storefront_sanitize_choices' );
|
||||
|
||||
$valid = array(
|
||||
'right' => 'Right',
|
||||
'left' => 'Left',
|
||||
);
|
||||
|
||||
if ( array_key_exists( $input, $valid ) ) {
|
||||
return $input;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Storefront Sanitize Hex Color
|
||||
*
|
||||
* @param string $color The color as a hex.
|
||||
* @todo remove in 2.1.
|
||||
*/
|
||||
function storefront_sanitize_hex_color( $color ) {
|
||||
_deprecated_function( 'storefront_sanitize_hex_color', '2.0', 'sanitize_hex_color' );
|
||||
|
||||
if ( '' === $color ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// 3 or 6 hex digits, or the empty string.
|
||||
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
|
||||
return $color;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a blog has more than 1 category.
|
||||
*
|
||||
* @return bool
|
||||
* @todo remove in 2.1.
|
||||
*/
|
||||
function storefront_categorized_blog() {
|
||||
_deprecated_function( 'storefront_categorized_blog', '2.0' );
|
||||
|
||||
if ( false === ( $all_the_cool_cats = get_transient( 'storefront_categories' ) ) ) {
|
||||
// Create an array of all the categories that are attached to posts.
|
||||
$all_the_cool_cats = get_categories( array(
|
||||
'fields' => 'ids',
|
||||
'hide_empty' => 1,
|
||||
// We only need to know if there is more than one category.
|
||||
'number' => 2,
|
||||
) );
|
||||
|
||||
// Count the number of categories that are attached to the posts.
|
||||
$all_the_cool_cats = count( $all_the_cool_cats );
|
||||
set_transient( 'storefront_categories', $all_the_cool_cats );
|
||||
}
|
||||
|
||||
if ( $all_the_cool_cats > 1 ) {
|
||||
// This blog has more than 1 category so storefront_categorized_blog should return true.
|
||||
return true;
|
||||
} else {
|
||||
// This blog has only 1 category so storefront_categorized_blog should return false.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,960 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront template functions.
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'storefront_display_comments' ) ) {
|
||||
/**
|
||||
* Storefront display comments
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_display_comments() {
|
||||
// If comments are open or we have at least one comment, load up the comment template.
|
||||
if ( comments_open() || '0' != get_comments_number() ) :
|
||||
comments_template();
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_comment' ) ) {
|
||||
/**
|
||||
* Storefront comment template
|
||||
*
|
||||
* @param array $comment the comment array.
|
||||
* @param array $args the comment args.
|
||||
* @param int $depth the comment depth.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_comment( $comment, $args, $depth ) {
|
||||
if ( 'div' == $args['style'] ) {
|
||||
$tag = 'div';
|
||||
$add_below = 'comment';
|
||||
} else {
|
||||
$tag = 'li';
|
||||
$add_below = 'div-comment';
|
||||
}
|
||||
?>
|
||||
<<?php echo esc_attr( $tag ); ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
|
||||
<div class="comment-body">
|
||||
<div class="comment-meta commentmetadata">
|
||||
<div class="comment-author vcard">
|
||||
<?php echo get_avatar( $comment, 128 ); ?>
|
||||
<?php printf( wp_kses_post( '<cite class="fn">%s</cite>', 'storefront' ), get_comment_author_link() ); ?>
|
||||
</div>
|
||||
<?php if ( '0' == $comment->comment_approved ) : ?>
|
||||
<em class="comment-awaiting-moderation"><?php esc_attr_e( 'Your comment is awaiting moderation.', 'storefront' ); ?></em>
|
||||
<br />
|
||||
<?php endif; ?>
|
||||
|
||||
<a href="<?php echo esc_url( htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ); ?>" class="comment-date">
|
||||
<?php echo '<time datetime="' . get_comment_date( 'c' ) . '">' . get_comment_date() . '</time>'; ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php if ( 'div' != $args['style'] ) : ?>
|
||||
<div id="div-comment-<?php comment_ID() ?>" class="comment-content">
|
||||
<?php endif; ?>
|
||||
<div class="comment-text">
|
||||
<?php comment_text(); ?>
|
||||
</div>
|
||||
<div class="reply">
|
||||
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
|
||||
<?php edit_comment_link( __( 'Edit', 'storefront' ), ' ', '' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ( 'div' != $args['style'] ) : ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_footer_widgets' ) ) {
|
||||
/**
|
||||
* Display the footer widget regions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_footer_widgets() {
|
||||
$rows = intval( apply_filters( 'storefront_footer_widget_rows', 1 ) );
|
||||
$regions = intval( apply_filters( 'storefront_footer_widget_columns', 4 ) );
|
||||
|
||||
for ( $row = 1; $row <= $rows; $row++ ) :
|
||||
|
||||
// Defines the number of active columns in this footer row.
|
||||
for ( $region = $regions; 0 < $region; $region-- ) {
|
||||
if ( is_active_sidebar( 'footer-' . strval( $region + $regions * ( $row - 1 ) ) ) ) {
|
||||
$columns = $region;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $columns ) ) : ?>
|
||||
<div class=<?php echo '"footer-widgets row-' . strval( $row ) . ' col-' . strval( $columns ) . ' fix"'; ?>><?php
|
||||
|
||||
for ( $column = 1; $column <= $columns; $column++ ) :
|
||||
$footer_n = $column + $regions * ( $row - 1 );
|
||||
|
||||
if ( is_active_sidebar( 'footer-' . strval( $footer_n ) ) ) : ?>
|
||||
|
||||
<div class="block footer-widget-<?php echo strval( $column ); ?>">
|
||||
<?php dynamic_sidebar( 'footer-' . strval( $footer_n ) ); ?>
|
||||
</div><?php
|
||||
|
||||
endif;
|
||||
endfor; ?>
|
||||
|
||||
</div><!-- .footer-widgets.row-<?php echo strval( $row ); ?> --><?php
|
||||
|
||||
unset( $columns );
|
||||
endif;
|
||||
endfor;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_credit' ) ) {
|
||||
/**
|
||||
* Display the theme credit
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_credit() {
|
||||
?>
|
||||
<div class="site-info">
|
||||
<?php echo esc_html( apply_filters( 'storefront_copyright_text', $content = '© ' . get_bloginfo( 'name' ) . ' ' . date( 'Y' ) ) ); ?>
|
||||
<?php if ( apply_filters( 'storefront_credit_link', true ) ) { ?>
|
||||
<br />
|
||||
<?php
|
||||
if ( apply_filters( 'storefront_privacy_policy_link', true ) && function_exists( 'the_privacy_policy_link' ) ) {
|
||||
the_privacy_policy_link( '', '<span role="separator" aria-hidden="true"></span>' );
|
||||
}
|
||||
?>
|
||||
<?php echo '<a href="https://woocommerce.com" target="_blank" title="' . esc_attr__( 'WooCommerce - The Best eCommerce Platform for WordPress', 'storefront' ) . '" rel="author">' . esc_html__( 'Built with Storefront & WooCommerce', 'storefront' ) . '</a>.' ?>
|
||||
<?php } ?>
|
||||
</div><!-- .site-info -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_header_widget_region' ) ) {
|
||||
/**
|
||||
* Display header widget region
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_header_widget_region() {
|
||||
if ( is_active_sidebar( 'header-1' ) ) {
|
||||
?>
|
||||
<div class="header-widget-region" role="complementary">
|
||||
<div class="col-full">
|
||||
<?php dynamic_sidebar( 'header-1' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_site_branding' ) ) {
|
||||
/**
|
||||
* Site branding wrapper and display
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_site_branding() {
|
||||
?>
|
||||
<div class="site-branding">
|
||||
<?php storefront_site_title_or_logo(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_site_title_or_logo' ) ) {
|
||||
/**
|
||||
* Display the site title or logo
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @param bool $echo Echo the string or return it.
|
||||
* @return string
|
||||
*/
|
||||
function storefront_site_title_or_logo( $echo = true ) {
|
||||
if ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
|
||||
$logo = get_custom_logo();
|
||||
$html = is_home() ? '<h1 class="logo">' . $logo . '</h1>' : $logo;
|
||||
} elseif ( function_exists( 'jetpack_has_site_logo' ) && jetpack_has_site_logo() ) {
|
||||
// Copied from jetpack_the_site_logo() function.
|
||||
$logo = site_logo()->logo;
|
||||
$logo_id = get_theme_mod( 'custom_logo' ); // Check for WP 4.5 Site Logo
|
||||
$logo_id = $logo_id ? $logo_id : $logo['id']; // Use WP Core logo if present, otherwise use Jetpack's.
|
||||
$size = site_logo()->theme_size();
|
||||
$html = sprintf( '<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>',
|
||||
esc_url( home_url( '/' ) ),
|
||||
wp_get_attachment_image(
|
||||
$logo_id,
|
||||
$size,
|
||||
false,
|
||||
array(
|
||||
'class' => 'site-logo attachment-' . $size,
|
||||
'data-size' => $size,
|
||||
'itemprop' => 'logo'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$html = apply_filters( 'jetpack_the_site_logo', $html, $logo, $size );
|
||||
} else {
|
||||
$tag = is_home() ? 'h1' : 'div';
|
||||
|
||||
$html = '<' . esc_attr( $tag ) . ' class="beta site-title"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . esc_html( get_bloginfo( 'name' ) ) . '</a></' . esc_attr( $tag ) .'>';
|
||||
|
||||
if ( '' !== get_bloginfo( 'description' ) ) {
|
||||
$html .= '<p class="site-description">' . esc_html( get_bloginfo( 'description', 'display' ) ) . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $echo ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
echo $html;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_primary_navigation' ) ) {
|
||||
/**
|
||||
* Display Primary Navigation
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_primary_navigation() {
|
||||
?>
|
||||
<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php esc_html_e( 'Primary Navigation', 'storefront' ); ?>">
|
||||
<button class="menu-toggle" aria-controls="site-navigation" aria-expanded="false"><span><?php echo esc_attr( apply_filters( 'storefront_menu_toggle_text', __( 'Menu', 'storefront' ) ) ); ?></span></button>
|
||||
<?php
|
||||
wp_nav_menu(
|
||||
array(
|
||||
'theme_location' => 'primary',
|
||||
'container_class' => 'primary-navigation',
|
||||
)
|
||||
);
|
||||
|
||||
wp_nav_menu(
|
||||
array(
|
||||
'theme_location' => 'handheld',
|
||||
'container_class' => 'handheld-navigation',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</nav><!-- #site-navigation -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_secondary_navigation' ) ) {
|
||||
/**
|
||||
* Display Secondary Navigation
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_secondary_navigation() {
|
||||
if ( has_nav_menu( 'secondary' ) ) {
|
||||
?>
|
||||
<nav class="secondary-navigation" role="navigation" aria-label="<?php esc_html_e( 'Secondary Navigation', 'storefront' ); ?>">
|
||||
<?php
|
||||
wp_nav_menu(
|
||||
array(
|
||||
'theme_location' => 'secondary',
|
||||
'fallback_cb' => '',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</nav><!-- #site-navigation -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_skip_links' ) ) {
|
||||
/**
|
||||
* Skip links
|
||||
*
|
||||
* @since 1.4.1
|
||||
* @return void
|
||||
*/
|
||||
function storefront_skip_links() {
|
||||
?>
|
||||
<a class="skip-link screen-reader-text" href="#site-navigation"><?php esc_attr_e( 'Skip to navigation', 'storefront' ); ?></a>
|
||||
<a class="skip-link screen-reader-text" href="#content"><?php esc_attr_e( 'Skip to content', 'storefront' ); ?></a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_homepage_header' ) ) {
|
||||
/**
|
||||
* Display the page header without the featured image
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_homepage_header() {
|
||||
edit_post_link( __( 'Edit this section', 'storefront' ), '', '', '', 'button storefront-hero__button-edit' );
|
||||
?>
|
||||
<header class="entry-header">
|
||||
<?php
|
||||
the_title( '<h1 class="entry-title">', '</h1>' );
|
||||
?>
|
||||
</header><!-- .entry-header -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_page_header' ) ) {
|
||||
/**
|
||||
* Display the page header
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_page_header() {
|
||||
?>
|
||||
<header class="entry-header">
|
||||
<?php
|
||||
storefront_post_thumbnail( 'full' );
|
||||
the_title( '<h1 class="entry-title">', '</h1>' );
|
||||
?>
|
||||
</header><!-- .entry-header -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_page_content' ) ) {
|
||||
/**
|
||||
* Display the post content
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_page_content() {
|
||||
?>
|
||||
<div class="entry-content">
|
||||
<?php the_content(); ?>
|
||||
<?php
|
||||
wp_link_pages( array(
|
||||
'before' => '<div class="page-links">' . __( 'Pages:', 'storefront' ),
|
||||
'after' => '</div>',
|
||||
) );
|
||||
?>
|
||||
</div><!-- .entry-content -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_post_header' ) ) {
|
||||
/**
|
||||
* Display the post header with a link to the single post
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_post_header() {
|
||||
?>
|
||||
<header class="entry-header">
|
||||
<?php
|
||||
if ( is_single() ) {
|
||||
storefront_posted_on();
|
||||
the_title( '<h1 class="entry-title">', '</h1>' );
|
||||
} else {
|
||||
if ( 'post' == get_post_type() ) {
|
||||
storefront_posted_on();
|
||||
}
|
||||
|
||||
the_title( sprintf( '<h2 class="alpha entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
|
||||
}
|
||||
?>
|
||||
</header><!-- .entry-header -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_post_content' ) ) {
|
||||
/**
|
||||
* Display the post content with a link to the single post
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_post_content() {
|
||||
?>
|
||||
<div class="entry-content">
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Functions hooked in to storefront_post_content_before action.
|
||||
*
|
||||
* @hooked storefront_post_thumbnail - 10
|
||||
*/
|
||||
do_action( 'storefront_post_content_before' );
|
||||
|
||||
the_content(
|
||||
sprintf(
|
||||
__( 'Continue reading %s', 'storefront' ),
|
||||
'<span class="screen-reader-text">' . get_the_title() . '</span>'
|
||||
)
|
||||
);
|
||||
|
||||
do_action( 'storefront_post_content_after' );
|
||||
|
||||
wp_link_pages( array(
|
||||
'before' => '<div class="page-links">' . __( 'Pages:', 'storefront' ),
|
||||
'after' => '</div>',
|
||||
) );
|
||||
?>
|
||||
</div><!-- .entry-content -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_post_meta' ) ) {
|
||||
/**
|
||||
* Display the post meta
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_post_meta() {
|
||||
?>
|
||||
<aside class="entry-meta">
|
||||
<?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search.
|
||||
|
||||
?>
|
||||
<div class="vcard author">
|
||||
<?php
|
||||
echo get_avatar( get_the_author_meta( 'ID' ), 128 );
|
||||
echo '<div class="label">' . esc_attr( __( 'Written by', 'storefront' ) ) . '</div>';
|
||||
echo sprintf( '<a href="%1$s" class="url fn" rel="author">%2$s</a>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), get_the_author() );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
/* translators: used between list items, there is a space after the comma */
|
||||
$categories_list = get_the_category_list( __( ', ', 'storefront' ) );
|
||||
|
||||
if ( $categories_list ) : ?>
|
||||
<div class="cat-links">
|
||||
<?php
|
||||
echo '<div class="label">' . esc_attr( __( 'Posted in', 'storefront' ) ) . '</div>';
|
||||
echo wp_kses_post( $categories_list );
|
||||
?>
|
||||
</div>
|
||||
<?php endif; // End if categories. ?>
|
||||
|
||||
<?php
|
||||
/* translators: used between list items, there is a space after the comma */
|
||||
$tags_list = get_the_tag_list( '', __( ', ', 'storefront' ) );
|
||||
|
||||
if ( $tags_list ) : ?>
|
||||
<div class="tags-links">
|
||||
<?php
|
||||
echo '<div class="label">' . esc_attr( __( 'Tagged', 'storefront' ) ) . '</div>';
|
||||
echo wp_kses_post( $tags_list );
|
||||
?>
|
||||
</div>
|
||||
<?php endif; // End if $tags_list. ?>
|
||||
|
||||
<?php endif; // End if 'post' == get_post_type(). ?>
|
||||
|
||||
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
|
||||
<div class="comments-link">
|
||||
<?php echo '<div class="label">' . esc_attr( __( 'Comments', 'storefront' ) ) . '</div>'; ?>
|
||||
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'storefront' ), __( '1 Comment', 'storefront' ), __( '% Comments', 'storefront' ) ); ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</aside>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_paging_nav' ) ) {
|
||||
/**
|
||||
* Display navigation to next/previous set of posts when applicable.
|
||||
*/
|
||||
function storefront_paging_nav() {
|
||||
global $wp_query;
|
||||
|
||||
$args = array(
|
||||
'type' => 'list',
|
||||
'next_text' => _x( 'Next', 'Next post', 'storefront' ),
|
||||
'prev_text' => _x( 'Previous', 'Previous post', 'storefront' ),
|
||||
);
|
||||
|
||||
the_posts_pagination( $args );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_post_nav' ) ) {
|
||||
/**
|
||||
* Display navigation to next/previous post when applicable.
|
||||
*/
|
||||
function storefront_post_nav() {
|
||||
$args = array(
|
||||
'next_text' => '<span class="screen-reader-text">' . esc_html__( 'Next post:', 'storefront' ) . ' </span>%title',
|
||||
'prev_text' => '<span class="screen-reader-text">' . esc_html__( 'Previous post:', 'storefront' ) . ' </span>%title',
|
||||
);
|
||||
the_post_navigation( $args );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_posted_on' ) ) {
|
||||
/**
|
||||
* Prints HTML with meta information for the current post-date/time and author.
|
||||
*/
|
||||
function storefront_posted_on() {
|
||||
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
|
||||
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
||||
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time> <time class="updated" datetime="%3$s">%4$s</time>';
|
||||
}
|
||||
|
||||
$time_string = sprintf( $time_string,
|
||||
esc_attr( get_the_date( 'c' ) ),
|
||||
esc_html( get_the_date() ),
|
||||
esc_attr( get_the_modified_date( 'c' ) ),
|
||||
esc_html( get_the_modified_date() )
|
||||
);
|
||||
|
||||
$posted_on = sprintf(
|
||||
_x( 'Posted on %s', 'post date', 'storefront' ),
|
||||
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
|
||||
);
|
||||
|
||||
echo wp_kses( apply_filters( 'storefront_single_post_posted_on_html', '<span class="posted-on">' . $posted_on . '</span>', $posted_on ), array(
|
||||
'span' => array(
|
||||
'class' => array(),
|
||||
),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'title' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
'time' => array(
|
||||
'datetime' => array(),
|
||||
'class' => array(),
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_product_categories' ) ) {
|
||||
/**
|
||||
* Display Product Categories
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_product_categories( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_product_categories_args', array(
|
||||
'limit' => 3,
|
||||
'columns' => 3,
|
||||
'child_categories' => 0,
|
||||
'orderby' => 'name',
|
||||
'title' => __( 'Shop by Category', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'product_categories', apply_filters( 'storefront_product_categories_shortcode_args', array(
|
||||
'number' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'parent' => esc_attr( $args['child_categories'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns product categories
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product-category' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-product-categories" aria-label="' . esc_attr__( 'Product Categories', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_product_categories' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_product_categories_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_product_categories' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_recent_products' ) ) {
|
||||
/**
|
||||
* Display Recent Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_recent_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_recent_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'title' => __( 'New In', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_recent_products_shortcode_args', array(
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-recent-products" aria-label="' . esc_attr__( 'Recent Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_recent_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_recent_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_recent_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_featured_products' ) ) {
|
||||
/**
|
||||
* Display Featured Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_featured_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_featured_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'visibility' => 'featured',
|
||||
'title' => __( 'We Recommend', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_featured_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'visibility' => esc_attr( $args['visibility'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-featured-products" aria-label="' . esc_attr__( 'Featured Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_featured_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_featured_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_featured_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_popular_products' ) ) {
|
||||
/**
|
||||
* Display Popular Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_popular_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_popular_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'rating',
|
||||
'order' => 'desc',
|
||||
'title' => __( 'Fan Favorites', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_popular_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-popular-products" aria-label="' . esc_attr__( 'Popular Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_popular_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_popular_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_popular_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_on_sale_products' ) ) {
|
||||
/**
|
||||
* Display On Sale Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @param array $args the product section args.
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_on_sale_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_on_sale_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'on_sale' => 'true',
|
||||
'title' => __( 'On Sale', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_on_sale_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'on_sale' => esc_attr( $args['on_sale'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-on-sale-products" aria-label="' . esc_attr__( 'On Sale Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_on_sale_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_on_sale_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_on_sale_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_best_selling_products' ) ) {
|
||||
/**
|
||||
* Display Best Selling Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_best_selling_products( $args ) {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_best_selling_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'popularity',
|
||||
'order' => 'desc',
|
||||
'title' => esc_attr__( 'Best Sellers', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_best_selling_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-best-selling-products" aria-label="' . esc_attr__( 'Best Selling Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_best_selling_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_homepage_content' ) ) {
|
||||
/**
|
||||
* Display homepage content
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_homepage_content() {
|
||||
while ( have_posts() ) {
|
||||
the_post();
|
||||
|
||||
get_template_part( 'content', 'homepage' );
|
||||
|
||||
} // end of the loop.
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_social_icons' ) ) {
|
||||
/**
|
||||
* Display social icons
|
||||
* If the subscribe and connect plugin is active, display the icons.
|
||||
*
|
||||
* @link http://wordpress.org/plugins/subscribe-and-connect/
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_social_icons() {
|
||||
if ( class_exists( 'Subscribe_And_Connect' ) ) {
|
||||
echo '<div class="subscribe-and-connect-connect">';
|
||||
subscribe_and_connect_connect();
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_get_sidebar' ) ) {
|
||||
/**
|
||||
* Display storefront sidebar
|
||||
*
|
||||
* @uses get_sidebar()
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_get_sidebar() {
|
||||
get_sidebar();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_post_thumbnail' ) ) {
|
||||
/**
|
||||
* Display post thumbnail
|
||||
*
|
||||
* @var $size thumbnail size. thumbnail|medium|large|full|$custom
|
||||
* @uses has_post_thumbnail()
|
||||
* @uses the_post_thumbnail
|
||||
* @param string $size the post thumbnail size.
|
||||
* @since 1.5.0
|
||||
*/
|
||||
function storefront_post_thumbnail( $size = 'full' ) {
|
||||
if ( has_post_thumbnail() ) {
|
||||
the_post_thumbnail( $size );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_primary_navigation_wrapper' ) ) {
|
||||
/**
|
||||
* The primary navigation wrapper
|
||||
*/
|
||||
function storefront_primary_navigation_wrapper() {
|
||||
echo '<div class="storefront-primary-navigation"><div class="col-full">';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_primary_navigation_wrapper_close' ) ) {
|
||||
/**
|
||||
* The primary navigation wrapper close
|
||||
*/
|
||||
function storefront_primary_navigation_wrapper_close() {
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_header_container' ) ) {
|
||||
/**
|
||||
* The header container
|
||||
*/
|
||||
function storefront_header_container() {
|
||||
echo '<div class="col-full">';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_header_container_close' ) ) {
|
||||
/**
|
||||
* The header container close
|
||||
*/
|
||||
function storefront_header_container_close() {
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront hooks
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
/**
|
||||
* General
|
||||
*
|
||||
* @see storefront_header_widget_region()
|
||||
* @see storefront_get_sidebar()
|
||||
*/
|
||||
add_action( 'storefront_before_content', 'storefront_header_widget_region', 10 );
|
||||
add_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
|
||||
|
||||
/**
|
||||
* Header
|
||||
*
|
||||
* @see storefront_skip_links()
|
||||
* @see storefront_secondary_navigation()
|
||||
* @see storefront_site_branding()
|
||||
* @see storefront_primary_navigation()
|
||||
*/
|
||||
add_action( 'storefront_header', 'storefront_header_container', 0 );
|
||||
add_action( 'storefront_header', 'storefront_skip_links', 5 );
|
||||
add_action( 'storefront_header', 'storefront_site_branding', 20 );
|
||||
add_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
|
||||
add_action( 'storefront_header', 'storefront_header_container_close', 41 );
|
||||
add_action( 'storefront_header', 'storefront_primary_navigation_wrapper', 42 );
|
||||
add_action( 'storefront_header', 'storefront_primary_navigation', 50 );
|
||||
add_action( 'storefront_header', 'storefront_primary_navigation_wrapper_close', 68 );
|
||||
|
||||
/**
|
||||
* Footer
|
||||
*
|
||||
* @see storefront_footer_widgets()
|
||||
* @see storefront_credit()
|
||||
*/
|
||||
add_action( 'storefront_footer', 'storefront_footer_widgets', 10 );
|
||||
add_action( 'storefront_footer', 'storefront_credit', 20 );
|
||||
|
||||
/**
|
||||
* Homepage
|
||||
*
|
||||
* @see storefront_homepage_content()
|
||||
* @see storefront_product_categories()
|
||||
* @see storefront_recent_products()
|
||||
* @see storefront_featured_products()
|
||||
* @see storefront_popular_products()
|
||||
* @see storefront_on_sale_products()
|
||||
* @see storefront_best_selling_products()
|
||||
*/
|
||||
add_action( 'homepage', 'storefront_homepage_content', 10 );
|
||||
add_action( 'homepage', 'storefront_product_categories', 20 );
|
||||
add_action( 'homepage', 'storefront_recent_products', 30 );
|
||||
add_action( 'homepage', 'storefront_featured_products', 40 );
|
||||
add_action( 'homepage', 'storefront_popular_products', 50 );
|
||||
add_action( 'homepage', 'storefront_on_sale_products', 60 );
|
||||
add_action( 'homepage', 'storefront_best_selling_products', 70 );
|
||||
|
||||
/**
|
||||
* Posts
|
||||
*
|
||||
* @see storefront_post_header()
|
||||
* @see storefront_post_meta()
|
||||
* @see storefront_post_content()
|
||||
* @see storefront_paging_nav()
|
||||
* @see storefront_single_post_header()
|
||||
* @see storefront_post_nav()
|
||||
* @see storefront_display_comments()
|
||||
*/
|
||||
add_action( 'storefront_loop_post', 'storefront_post_header', 10 );
|
||||
add_action( 'storefront_loop_post', 'storefront_post_meta', 20 );
|
||||
add_action( 'storefront_loop_post', 'storefront_post_content', 30 );
|
||||
add_action( 'storefront_loop_after', 'storefront_paging_nav', 10 );
|
||||
add_action( 'storefront_single_post', 'storefront_post_header', 10 );
|
||||
add_action( 'storefront_single_post', 'storefront_post_meta', 20 );
|
||||
add_action( 'storefront_single_post', 'storefront_post_content', 30 );
|
||||
add_action( 'storefront_single_post_bottom', 'storefront_post_nav', 10 );
|
||||
add_action( 'storefront_single_post_bottom', 'storefront_display_comments', 20 );
|
||||
add_action( 'storefront_post_content_before', 'storefront_post_thumbnail', 10 );
|
||||
|
||||
/**
|
||||
* Pages
|
||||
*
|
||||
* @see storefront_page_header()
|
||||
* @see storefront_page_content()
|
||||
* @see storefront_display_comments()
|
||||
*/
|
||||
add_action( 'storefront_page', 'storefront_page_header', 10 );
|
||||
add_action( 'storefront_page', 'storefront_page_content', 20 );
|
||||
add_action( 'storefront_page_after', 'storefront_display_comments', 10 );
|
||||
|
||||
add_action( 'storefront_homepage', 'storefront_homepage_header', 10 );
|
||||
add_action( 'storefront_homepage', 'storefront_page_content', 20 );
|
||||
@@ -0,0 +1,425 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce Class
|
||||
*
|
||||
* @package storefront
|
||||
* @author WooThemes
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_WooCommerce' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront WooCommerce Integration class
|
||||
*/
|
||||
class Storefront_WooCommerce {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'body_class', array( $this, 'woocommerce_body_class' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_scripts' ), 20 );
|
||||
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
|
||||
add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_args' ) );
|
||||
add_filter( 'woocommerce_product_thumbnails_columns', array( $this, 'thumbnail_columns' ) );
|
||||
add_filter( 'woocommerce_breadcrumb_defaults', array( $this,'change_breadcrumb_delimiter' ) );
|
||||
|
||||
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.5', '<' ) ) {
|
||||
add_action( 'wp_footer', array( $this, 'star_rating_script' ) );
|
||||
}
|
||||
|
||||
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
|
||||
add_filter( 'loop_shop_per_page', array( $this, 'products_per_page' ) );
|
||||
}
|
||||
|
||||
// Integrations.
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_integrations_scripts' ), 99 );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'add_customizer_css' ), 140 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add CSS in <head> for styles handled by the theme customizer
|
||||
* If the Customizer is active pull in the raw css. Otherwise pull in the prepared theme_mods if they exist.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @return void
|
||||
*/
|
||||
public function add_customizer_css() {
|
||||
wp_add_inline_style( 'storefront-woocommerce-style', $this->get_woocommerce_extension_css() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign styles to individual theme mod.
|
||||
*
|
||||
* @deprecated 2.3.1
|
||||
* @since 2.1.0
|
||||
* @return void
|
||||
*/
|
||||
public function set_storefront_style_theme_mods() {
|
||||
if ( function_exists( 'wc_deprecated_function' ) ) {
|
||||
wc_deprecated_function( __FUNCTION__, '2.3.1' );
|
||||
} else {
|
||||
_deprecated_function( __FUNCTION__, '2.3.1' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'woocommerce-active' class to the body tag
|
||||
*
|
||||
* @param array $classes css classes applied to the body tag.
|
||||
* @return array $classes modified to include 'woocommerce-active' class
|
||||
*/
|
||||
public function woocommerce_body_class( $classes ) {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
$classes[] = 'woocommerce-active';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce specific scripts & stylesheets
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function woocommerce_scripts() {
|
||||
global $storefront_version;
|
||||
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
wp_enqueue_style( 'storefront-woocommerce-style', get_template_directory_uri() . '/assets/css/woocommerce/woocommerce.css', array(), $storefront_version );
|
||||
wp_style_add_data( 'storefront-woocommerce-style', 'rtl', 'replace' );
|
||||
|
||||
wp_register_script( 'storefront-header-cart', get_template_directory_uri() . '/assets/js/woocommerce/header-cart' . $suffix . '.js', array(), $storefront_version, true );
|
||||
wp_enqueue_script( 'storefront-header-cart' );
|
||||
|
||||
if ( ! class_exists( 'Storefront_Sticky_Add_to_Cart' ) && is_product() ) {
|
||||
wp_register_script( 'storefront-sticky-add-to-cart', get_template_directory_uri() . '/assets/js/sticky-add-to-cart' . $suffix . '.js', array(), $storefront_version, true );
|
||||
}
|
||||
|
||||
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-legacy', get_template_directory_uri() . '/assets/css/woocommerce/woocommerce-legacy.css', array(), $storefront_version );
|
||||
wp_style_add_data( 'storefront-woocommerce-legacy', 'rtl', 'replace' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Star rating backwards compatibility script (WooCommerce <2.5).
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function star_rating_script() {
|
||||
if ( is_product() ) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var starsEl = document.querySelector( '#respond p.stars' );
|
||||
if ( starsEl ) {
|
||||
starsEl.addEventListener( 'click', function( event ) {
|
||||
if ( event.target.tagName === 'A' ) {
|
||||
starsEl.classList.add( 'selected' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Related Products Args
|
||||
*
|
||||
* @param array $args related products args.
|
||||
* @since 1.0.0
|
||||
* @return array $args related products args
|
||||
*/
|
||||
public function related_products_args( $args ) {
|
||||
$args = apply_filters( 'storefront_related_products_args', array(
|
||||
'posts_per_page' => 3,
|
||||
'columns' => 3,
|
||||
) );
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Product gallery thumbnail columns
|
||||
*
|
||||
* @return integer number of columns
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function thumbnail_columns() {
|
||||
$columns = 4;
|
||||
|
||||
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
|
||||
$columns = 5;
|
||||
}
|
||||
|
||||
return intval( apply_filters( 'storefront_product_thumbnail_columns', $columns ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Products per page
|
||||
*
|
||||
* @return integer number of products
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function products_per_page() {
|
||||
return intval( apply_filters( 'storefront_products_per_page', 12 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query WooCommerce Extension Activation.
|
||||
*
|
||||
* @param string $extension Extension class name.
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_woocommerce_extension_activated( $extension = 'WC_Bookings' ) {
|
||||
return class_exists( $extension ) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the breadcrumb delimiter
|
||||
* @param array $defaults The breadcrumb defaults
|
||||
* @return array The breadcrumb defaults
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function change_breadcrumb_delimiter( $defaults ) {
|
||||
$defaults['delimiter'] = '<span class="breadcrumb-separator"> / </span>';
|
||||
$defaults['wrap_before'] = '<div class="storefront-breadcrumb"><div class="col-full"><nav class="woocommerce-breadcrumb">';
|
||||
$defaults['wrap_after'] = '</nav></div></div>';
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration Styles & Scripts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function woocommerce_integrations_scripts() {
|
||||
global $storefront_version;
|
||||
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
/**
|
||||
* Bookings
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Bookings' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-bookings-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/bookings.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-bookings-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Brands
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Brands' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-brands-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/brands.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-brands-style', 'rtl', 'replace' );
|
||||
|
||||
wp_enqueue_script( 'storefront-woocommerce-brands', get_template_directory_uri() . '/assets/js/woocommerce/extensions/brands' . $suffix . '.js', array(), $storefront_version, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Wishlists
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Wishlists_Wishlist' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-wishlists-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/wishlists.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-wishlists-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX Layered Nav
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'SOD_Widget_Ajax_Layered_Nav' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-ajax-layered-nav-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/ajax-layered-nav.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-ajax-layered-nav-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Variation Swatches
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_SwatchesPlugin' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-variation-swatches-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/variation-swatches.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-variation-swatches-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Composite Products
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Composite_Products' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-composite-products-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/composite-products.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-composite-products-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Photography
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Photography' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-photography-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/photography.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-photography-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Product Reviews Pro
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Product_Reviews_Pro' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-product-reviews-pro-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/product-reviews-pro.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-product-reviews-pro-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Smart Coupons
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Smart_Coupons' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-smart-coupons-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/smart-coupons.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-smart-coupons-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Deposits
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Deposits' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-deposits-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/deposits.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-deposits-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Product Bundles
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Bundles' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-bundles-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/bundles.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-bundles-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Multiple Shipping Addresses
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Ship_Multiple' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-sma-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/ship-multiple-addresses.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-sma-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Advanced Product Labels
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'Woocommerce_Advanced_Product_Labels' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-apl-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/advanced-product-labels.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-apl-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Mix and Match
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Mix_and_Match' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-mix-and-match-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/mix-and-match.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-mix-and-match-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Memberships
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Memberships' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-memberships-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/memberships.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-memberships-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Quick View
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Quick_View' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-quick-view-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/quick-view.css', 'storefront-woocommerce-style' );
|
||||
wp_style_add_data( 'storefront-woocommerce-quick-view-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout Add Ons
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Checkout_Add_Ons' ) ) {
|
||||
add_filter( 'storefront_sticky_order_review', '__return_false' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension css.
|
||||
*
|
||||
* @see get_storefront_theme_mods()
|
||||
* @return array $styles the css
|
||||
*/
|
||||
public function get_woocommerce_extension_css() {
|
||||
$storefront_customizer = new Storefront_Customizer();
|
||||
$storefront_theme_mods = $storefront_customizer->get_storefront_theme_mods();
|
||||
|
||||
$woocommerce_extension_style = '';
|
||||
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Bookings' ) ) {
|
||||
$woocommerce_extension_style .= '
|
||||
.wc-bookings-date-picker .ui-datepicker td.bookable a {
|
||||
background-color: ' . $storefront_theme_mods['accent_color'] . ' !important;
|
||||
}
|
||||
|
||||
.wc-bookings-date-picker .ui-datepicker td.bookable a.ui-state-default {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['accent_color'], -10 ) . ' !important;
|
||||
}
|
||||
|
||||
.wc-bookings-date-picker .ui-datepicker td.bookable a.ui-state-active {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['accent_color'], -50 ) . ' !important;
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Product_Reviews_Pro' ) ) {
|
||||
$woocommerce_extension_style .= '
|
||||
.woocommerce #reviews .product-rating .product-rating-details table td.rating-graph .bar,
|
||||
.woocommerce-page #reviews .product-rating .product-rating-details table td.rating-graph .bar {
|
||||
background-color: ' . $storefront_theme_mods['text_color'] . ' !important;
|
||||
}
|
||||
|
||||
.woocommerce #reviews .contribution-actions .feedback,
|
||||
.woocommerce-page #reviews .contribution-actions .feedback,
|
||||
.star-rating-selector:not(:checked) label.checkbox {
|
||||
color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
}
|
||||
|
||||
.woocommerce #reviews #comments ol.commentlist li .contribution-actions a,
|
||||
.woocommerce-page #reviews #comments ol.commentlist li .contribution-actions a,
|
||||
.star-rating-selector:not(:checked) input:checked ~ label.checkbox,
|
||||
.star-rating-selector:not(:checked) label.checkbox:hover ~ label.checkbox,
|
||||
.star-rating-selector:not(:checked) label.checkbox:hover,
|
||||
.woocommerce #reviews #comments ol.commentlist li .contribution-actions a,
|
||||
.woocommerce-page #reviews #comments ol.commentlist li .contribution-actions a,
|
||||
.woocommerce #reviews .form-contribution .attachment-type:not(:checked) label.checkbox:before,
|
||||
.woocommerce-page #reviews .form-contribution .attachment-type:not(:checked) label.checkbox:before {
|
||||
color: ' . $storefront_theme_mods['accent_color'] . ' !important;
|
||||
}';
|
||||
}
|
||||
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Smart_Coupons' ) ) {
|
||||
$woocommerce_extension_style .= '
|
||||
.coupon-container {
|
||||
background-color: ' . $storefront_theme_mods['button_background_color'] . ' !important;
|
||||
}
|
||||
|
||||
.coupon-content {
|
||||
border-color: ' . $storefront_theme_mods['button_text_color'] . ' !important;
|
||||
color: ' . $storefront_theme_mods['button_text_color'] . ';
|
||||
}
|
||||
|
||||
.sd-buttons-transparent.woocommerce .coupon-content,
|
||||
.sd-buttons-transparent.woocommerce-page .coupon-content {
|
||||
border-color: ' . $storefront_theme_mods['button_background_color'] . ' !important;
|
||||
}';
|
||||
}
|
||||
|
||||
return apply_filters( 'storefront_customizer_woocommerce_extension_css', $woocommerce_extension_style );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_WooCommerce();
|
||||
@@ -0,0 +1,555 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Template Functions.
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'storefront_before_content' ) ) {
|
||||
/**
|
||||
* Before Content
|
||||
* Wraps all WooCommerce content in wrappers which match the theme markup
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_before_content() {
|
||||
?>
|
||||
<div id="primary" class="content-area">
|
||||
<main id="main" class="site-main" role="main">
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_after_content' ) ) {
|
||||
/**
|
||||
* After Content
|
||||
* Closes the wrapping divs
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_after_content() {
|
||||
?>
|
||||
</main><!-- #main -->
|
||||
</div><!-- #primary -->
|
||||
|
||||
<?php do_action( 'storefront_sidebar' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_cart_link_fragment' ) ) {
|
||||
/**
|
||||
* Cart Fragments
|
||||
* Ensure cart contents update when products are added to the cart via AJAX
|
||||
*
|
||||
* @param array $fragments Fragments to refresh via AJAX.
|
||||
* @return array Fragments to refresh via AJAX
|
||||
*/
|
||||
function storefront_cart_link_fragment( $fragments ) {
|
||||
global $woocommerce;
|
||||
|
||||
ob_start();
|
||||
storefront_cart_link();
|
||||
$fragments['a.cart-contents'] = ob_get_clean();
|
||||
|
||||
ob_start();
|
||||
storefront_handheld_footer_bar_cart_link();
|
||||
$fragments['a.footer-cart-contents'] = ob_get_clean();
|
||||
|
||||
return $fragments;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_cart_link' ) ) {
|
||||
/**
|
||||
* Cart Link
|
||||
* Displayed a link to the cart including the number of items present and the cart total
|
||||
*
|
||||
* @return void
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_cart_link() {
|
||||
?>
|
||||
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
|
||||
<?php echo wp_kses_post( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'storefront' ), WC()->cart->get_cart_contents_count() ) );?></span>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_product_search' ) ) {
|
||||
/**
|
||||
* Display Product Search
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @uses storefront_is_woocommerce_activated() check if WooCommerce is activated
|
||||
* @return void
|
||||
*/
|
||||
function storefront_product_search() {
|
||||
if ( storefront_is_woocommerce_activated() ) { ?>
|
||||
<div class="site-search">
|
||||
<?php the_widget( 'WC_Widget_Product_Search', 'title=' ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_header_cart' ) ) {
|
||||
/**
|
||||
* Display Header Cart
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @uses storefront_is_woocommerce_activated() check if WooCommerce is activated
|
||||
* @return void
|
||||
*/
|
||||
function storefront_header_cart() {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
if ( is_cart() ) {
|
||||
$class = 'current-menu-item';
|
||||
} else {
|
||||
$class = '';
|
||||
}
|
||||
?>
|
||||
<ul id="site-header-cart" class="site-header-cart menu">
|
||||
<li class="<?php echo esc_attr( $class ); ?>">
|
||||
<?php storefront_cart_link(); ?>
|
||||
</li>
|
||||
<li>
|
||||
<?php the_widget( 'WC_Widget_Cart', 'title=' ); ?>
|
||||
</li>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_upsell_display' ) ) {
|
||||
/**
|
||||
* Upsells
|
||||
* Replace the default upsell function with our own which displays the correct number product columns
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @uses woocommerce_upsell_display()
|
||||
*/
|
||||
function storefront_upsell_display() {
|
||||
$columns = apply_filters( 'storefront_upsells_columns', 3 );
|
||||
woocommerce_upsell_display( -1, $columns );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_sorting_wrapper' ) ) {
|
||||
/**
|
||||
* Sorting wrapper
|
||||
*
|
||||
* @since 1.4.3
|
||||
* @return void
|
||||
*/
|
||||
function storefront_sorting_wrapper() {
|
||||
echo '<div class="storefront-sorting">';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_sorting_wrapper_close' ) ) {
|
||||
/**
|
||||
* Sorting wrapper close
|
||||
*
|
||||
* @since 1.4.3
|
||||
* @return void
|
||||
*/
|
||||
function storefront_sorting_wrapper_close() {
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_product_columns_wrapper' ) ) {
|
||||
/**
|
||||
* Product columns wrapper
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_product_columns_wrapper() {
|
||||
$columns = storefront_loop_columns();
|
||||
echo '<div class="columns-' . absint( $columns ) . '">';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_loop_columns' ) ) {
|
||||
/**
|
||||
* Default loop columns on product archives
|
||||
*
|
||||
* @return integer products per row
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_loop_columns() {
|
||||
$columns = 3; // 3 products per row
|
||||
|
||||
if ( function_exists( 'wc_get_default_products_per_row' ) ) {
|
||||
$columns = wc_get_default_products_per_row();
|
||||
}
|
||||
|
||||
return apply_filters( 'storefront_loop_columns', $columns );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_product_columns_wrapper_close' ) ) {
|
||||
/**
|
||||
* Product columns wrapper close
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_product_columns_wrapper_close() {
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_shop_messages' ) ) {
|
||||
/**
|
||||
* Storefront shop messages
|
||||
*
|
||||
* @since 1.4.4
|
||||
* @uses storefront_do_shortcode
|
||||
*/
|
||||
function storefront_shop_messages() {
|
||||
if ( ! is_checkout() ) {
|
||||
echo wp_kses_post( storefront_do_shortcode( 'woocommerce_messages' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_woocommerce_pagination' ) ) {
|
||||
/**
|
||||
* Storefront WooCommerce Pagination
|
||||
* WooCommerce disables the product pagination inside the woocommerce_product_subcategories() function
|
||||
* but since Storefront adds pagination before that function is excuted we need a separate function to
|
||||
* determine whether or not to display the pagination.
|
||||
*
|
||||
* @since 1.4.4
|
||||
*/
|
||||
function storefront_woocommerce_pagination() {
|
||||
if ( woocommerce_products_will_display() ) {
|
||||
woocommerce_pagination();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_promoted_products' ) ) {
|
||||
/**
|
||||
* Featured and On-Sale Products
|
||||
* Check for featured products then on-sale products and use the appropiate shortcode.
|
||||
* If neither exist, it can fallback to show recently added products.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @param integer $per_page total products to display.
|
||||
* @param integer $columns columns to arrange products in to.
|
||||
* @param boolean $recent_fallback Should the function display recent products as a fallback when there are no featured or on-sale products?.
|
||||
* @uses storefront_is_woocommerce_activated()
|
||||
* @uses wc_get_featured_product_ids()
|
||||
* @uses wc_get_product_ids_on_sale()
|
||||
* @uses storefront_do_shortcode()
|
||||
* @return void
|
||||
*/
|
||||
function storefront_promoted_products( $per_page = '2', $columns = '2', $recent_fallback = true ) {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
if ( wc_get_featured_product_ids() ) {
|
||||
|
||||
echo '<h2>' . esc_html__( 'Featured Products', 'storefront' ) . '</h2>';
|
||||
|
||||
echo storefront_do_shortcode( 'featured_products', array(
|
||||
'per_page' => $per_page,
|
||||
'columns' => $columns,
|
||||
) );
|
||||
} elseif ( wc_get_product_ids_on_sale() ) {
|
||||
|
||||
echo '<h2>' . esc_html__( 'On Sale Now', 'storefront' ) . '</h2>';
|
||||
|
||||
echo storefront_do_shortcode( 'sale_products', array(
|
||||
'per_page' => $per_page,
|
||||
'columns' => $columns,
|
||||
) );
|
||||
} elseif ( $recent_fallback ) {
|
||||
|
||||
echo '<h2>' . esc_html__( 'New In Store', 'storefront' ) . '</h2>';
|
||||
|
||||
echo storefront_do_shortcode( 'recent_products', array(
|
||||
'per_page' => $per_page,
|
||||
'columns' => $columns,
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_handheld_footer_bar' ) ) {
|
||||
/**
|
||||
* Display a menu intended for use on handheld devices
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function storefront_handheld_footer_bar() {
|
||||
$links = array(
|
||||
'my-account' => array(
|
||||
'priority' => 10,
|
||||
'callback' => 'storefront_handheld_footer_bar_account_link',
|
||||
),
|
||||
'search' => array(
|
||||
'priority' => 20,
|
||||
'callback' => 'storefront_handheld_footer_bar_search',
|
||||
),
|
||||
'cart' => array(
|
||||
'priority' => 30,
|
||||
'callback' => 'storefront_handheld_footer_bar_cart_link',
|
||||
),
|
||||
);
|
||||
|
||||
if ( wc_get_page_id( 'myaccount' ) === -1 ) {
|
||||
unset( $links['my-account'] );
|
||||
}
|
||||
|
||||
if ( wc_get_page_id( 'cart' ) === -1 ) {
|
||||
unset( $links['cart'] );
|
||||
}
|
||||
|
||||
$links = apply_filters( 'storefront_handheld_footer_bar_links', $links );
|
||||
?>
|
||||
<div class="storefront-handheld-footer-bar">
|
||||
<ul class="columns-<?php echo count( $links ); ?>">
|
||||
<?php foreach ( $links as $key => $link ) : ?>
|
||||
<li class="<?php echo esc_attr( $key ); ?>">
|
||||
<?php
|
||||
if ( $link['callback'] ) {
|
||||
call_user_func( $link['callback'], $key, $link );
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_handheld_footer_bar_search' ) ) {
|
||||
/**
|
||||
* The search callback function for the handheld footer bar
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function storefront_handheld_footer_bar_search() {
|
||||
echo '<a href="">' . esc_attr__( 'Search', 'storefront' ) . '</a>';
|
||||
storefront_product_search();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_handheld_footer_bar_cart_link' ) ) {
|
||||
/**
|
||||
* The cart callback function for the handheld footer bar
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function storefront_handheld_footer_bar_cart_link() {
|
||||
?>
|
||||
<a class="footer-cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
|
||||
<span class="count"><?php echo wp_kses_data( WC()->cart->get_cart_contents_count() );?></span>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_handheld_footer_bar_account_link' ) ) {
|
||||
/**
|
||||
* The account callback function for the handheld footer bar
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function storefront_handheld_footer_bar_account_link() {
|
||||
echo '<a href="' . esc_url( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ) . '">' . esc_attr__( 'My Account', 'storefront' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_single_product_pagination' ) ) {
|
||||
/**
|
||||
* Single Product Pagination
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
function storefront_single_product_pagination() {
|
||||
if ( class_exists( 'Storefront_Product_Pagination' ) || true !== get_theme_mod( 'storefront_product_pagination' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show only products in the same category?
|
||||
$same_category = apply_filters( 'storefront_single_product_pagination_same_category', false );
|
||||
|
||||
// Get previous and next products
|
||||
$previous_product = get_previous_post( $same_category );
|
||||
$next_product = get_next_post( $same_category );
|
||||
|
||||
if ( ! $previous_product && ! $next_product ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $previous_product ) {
|
||||
$previous_product = wc_get_product( $previous_product->ID );
|
||||
}
|
||||
|
||||
if ( $next_product ) {
|
||||
$next_product = wc_get_product( $next_product->ID );
|
||||
}
|
||||
|
||||
?>
|
||||
<nav class="storefront-product-pagination" aria-label="<?php esc_attr_e( 'More products', 'storefront' ); ?>">
|
||||
<?php if ( $previous_product && $previous_product->is_visible() ) : ?>
|
||||
<?php previous_post_link( '%link', wp_kses_post( $previous_product->get_image() ) . '<span class="storefront-product-pagination__title">%title</span>', $same_category, '', 'product_cat' ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $next_product && $next_product->is_visible() ) : ?>
|
||||
<?php next_post_link( '%link', wp_kses_post( $next_product->get_image() ) . '<span class="storefront-product-pagination__title">%title</span>', $same_category, '', 'product_cat' ); ?>
|
||||
<?php endif; ?>
|
||||
</nav><!-- .storefront-product-pagination -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_sticky_single_add_to_cart' ) ) {
|
||||
/**
|
||||
* Sticky Add to Cart
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
function storefront_sticky_single_add_to_cart() {
|
||||
global $product;
|
||||
|
||||
if ( class_exists( 'Storefront_Sticky_Add_to_Cart' ) || true !== get_theme_mod( 'storefront_sticky_add_to_cart' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_product() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = apply_filters( 'storefront_sticky_add_to_cart_params', array(
|
||||
'trigger_class' => 'entry-summary'
|
||||
) );
|
||||
|
||||
wp_localize_script( 'storefront-sticky-add-to-cart', 'storefront_sticky_add_to_cart_params', $params );
|
||||
|
||||
wp_enqueue_script( 'storefront-sticky-add-to-cart' );
|
||||
?>
|
||||
<section class="storefront-sticky-add-to-cart">
|
||||
<div class="col-full">
|
||||
<div class="storefront-sticky-add-to-cart__content">
|
||||
<?php echo wp_kses_post( woocommerce_get_product_thumbnail() ); ?>
|
||||
<div class="storefront-sticky-add-to-cart__content-product-info">
|
||||
<span class="storefront-sticky-add-to-cart__content-title"><?php esc_attr_e( 'You\'re viewing:', 'storefront' ); ?> <strong><?php the_title(); ?></strong></span>
|
||||
<span class="storefront-sticky-add-to-cart__content-price"><?php echo wp_kses_post( $product->get_price_html() ); ?></span>
|
||||
<?php echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>
|
||||
</div>
|
||||
<a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="storefront-sticky-add-to-cart__content-button button alt">
|
||||
<?php echo esc_attr( $product->add_to_cart_text() ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</section><!-- .storefront-sticky-add-to-cart -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_woocommerce_brands_homepage_section' ) ) {
|
||||
/**
|
||||
* Display WooCommerce Brands
|
||||
* Hooked into the `homepage` action in the homepage template.
|
||||
* Requires WooCommerce Brands.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @link https://woocommerce.com/products/brands/
|
||||
* @uses apply_filters()
|
||||
* @uses storefront_do_shortcode()
|
||||
* @uses wp_kses_post()
|
||||
* @uses do_action()
|
||||
* @return void
|
||||
*/
|
||||
function storefront_woocommerce_brands_homepage_section() {
|
||||
$args = apply_filters( 'storefront_woocommerce_brands_args', array(
|
||||
'number' => 6,
|
||||
'columns' => 4,
|
||||
'orderby' => 'name',
|
||||
'show_empty' => false,
|
||||
'title' => __( 'Shop by Brand', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'product_brand_thumbnails', apply_filters( 'storefront_woocommerce_brands_shortcode_args', array(
|
||||
'number' => absint( $args['number'] ),
|
||||
'columns' => absint( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'show_empty' => (bool) $args['show_empty'],
|
||||
) ) );
|
||||
|
||||
echo '<section class="storefront-product-section storefront-woocommerce-brands" aria-label="' . esc_attr__( 'Product Brands', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_woocommerce_brands' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_woocommerce_brands_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_woocommerce_brands' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_woocommerce_brands_archive' ) ) {
|
||||
/**
|
||||
* Display brand image on brand archives
|
||||
* Requires WooCommerce Brands.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @link https://woocommerce.com/products/brands/
|
||||
* @uses is_tax()
|
||||
* @uses wp_kses_post()
|
||||
* @uses get_brand_thumbnail_image()
|
||||
* @uses get_queried_object()
|
||||
* @return void
|
||||
*/
|
||||
function storefront_woocommerce_brands_archive() {
|
||||
if ( is_tax( 'product_brand' ) ) {
|
||||
echo wp_kses_post( get_brand_thumbnail_image( get_queried_object() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_woocommerce_brands_single' ) ) {
|
||||
/**
|
||||
* Output product brand image for use on single product pages
|
||||
* Requires WooCommerce Brands.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @link https://woocommerce.com/products/brands/
|
||||
* @uses storefront_do_shortcode()
|
||||
* @uses wp_kses_post()
|
||||
* @return void
|
||||
*/
|
||||
function storefront_woocommerce_brands_single() {
|
||||
$brand = storefront_do_shortcode( 'product_brand', array(
|
||||
'class' => ''
|
||||
) );
|
||||
|
||||
if ( empty( $brand ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="storefront-wc-brands-single-product">
|
||||
<?php echo wp_kses_post( $brand ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce hooks
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
/**
|
||||
* Styles
|
||||
*
|
||||
* @see storefront_woocommerce_scripts()
|
||||
*/
|
||||
|
||||
/**
|
||||
* Layout
|
||||
*
|
||||
* @see storefront_before_content()
|
||||
* @see storefront_after_content()
|
||||
* @see woocommerce_breadcrumb()
|
||||
* @see storefront_shop_messages()
|
||||
*/
|
||||
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
|
||||
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
|
||||
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
|
||||
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
|
||||
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
|
||||
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
|
||||
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
|
||||
add_action( 'woocommerce_before_main_content', 'storefront_before_content', 10 );
|
||||
add_action( 'woocommerce_after_main_content', 'storefront_after_content', 10 );
|
||||
add_action( 'storefront_content_top', 'storefront_shop_messages', 15 );
|
||||
add_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10 );
|
||||
|
||||
add_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper', 9 );
|
||||
add_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
|
||||
add_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
|
||||
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 );
|
||||
add_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper_close', 31 );
|
||||
|
||||
add_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper', 9 );
|
||||
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
|
||||
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
|
||||
add_action( 'woocommerce_before_shop_loop', 'storefront_woocommerce_pagination', 30 );
|
||||
add_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper_close', 31 );
|
||||
|
||||
add_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
|
||||
|
||||
// Legacy WooCommerce columns filter.
|
||||
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
|
||||
add_filter( 'loop_shop_columns', 'storefront_loop_columns' );
|
||||
add_action( 'woocommerce_before_shop_loop', 'storefront_product_columns_wrapper', 40 );
|
||||
add_action( 'woocommerce_after_shop_loop', 'storefront_product_columns_wrapper_close', 40 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Products
|
||||
*
|
||||
* @see storefront_upsell_display()
|
||||
*/
|
||||
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
|
||||
add_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 15 );
|
||||
|
||||
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
|
||||
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 6 );
|
||||
|
||||
add_action( 'woocommerce_after_single_product_summary', 'storefront_single_product_pagination', 30 );
|
||||
add_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart', 999 );
|
||||
|
||||
/**
|
||||
* Header
|
||||
*
|
||||
* @see storefront_product_search()
|
||||
* @see storefront_header_cart()
|
||||
*/
|
||||
add_action( 'storefront_header', 'storefront_product_search', 40 );
|
||||
add_action( 'storefront_header', 'storefront_header_cart', 60 );
|
||||
|
||||
/**
|
||||
* Cart fragment
|
||||
*
|
||||
* @see storefront_cart_link_fragment()
|
||||
*/
|
||||
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
|
||||
add_filter( 'woocommerce_add_to_cart_fragments', 'storefront_cart_link_fragment' );
|
||||
} else {
|
||||
add_filter( 'add_to_cart_fragments', 'storefront_cart_link_fragment' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrations
|
||||
*
|
||||
* @see storefront_woocommerce_brands_archive()
|
||||
* @see storefront_woocommerce_brands_single()
|
||||
* @see storefront_woocommerce_brands_homepage_section()
|
||||
*/
|
||||
if ( class_exists( 'WC_Brands' ) ) {
|
||||
add_action( 'woocommerce_archive_description', 'storefront_woocommerce_brands_archive', 5 );
|
||||
add_action( 'woocommerce_single_product_summary', 'storefront_woocommerce_brands_single', 4 );
|
||||
add_action( 'homepage', 'storefront_woocommerce_brands_homepage_section', 80 );
|
||||
}
|
||||
Reference in New Issue
Block a user