first commit
This commit is contained in:
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Admin Class
|
||||
*
|
||||
* @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', array(), $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;
|
||||
|
||||
$show_setup_screen = ( false === (bool) get_option( 'storefront_nux_dismissed' ) ) && ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '4.8.0', '>=' ) );
|
||||
?>
|
||||
|
||||
<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_html_e( 'Support', 'storefront' ); ?></a></li>
|
||||
<li><a href="https://docs.woocommerce.com/documentation/themes/storefront/" target="_blank"><?php esc_html_e( 'Documentation', 'storefront' ); ?></a></li>
|
||||
<li><a href="https://woocommerce.wordpress.com/category/storefront/" target="_blank"><?php esc_html_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
|
||||
if ( $show_setup_screen ) {
|
||||
?>
|
||||
<div class="storefront-intro-setup">
|
||||
<?php
|
||||
Storefront_NUX_Admin::admin_notices_content();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
echo '<div class="storefront-intro-message" style="display:none">';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) {
|
||||
/* translators: 1: HTML, 2: HTML */
|
||||
echo '<h1>' . sprintf( esc_attr__( 'Setup complete %1$sYour Storefront adventure begins now 🚀%2$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>';
|
||||
}
|
||||
|
||||
if ( $show_setup_screen ) {
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="storefront-enhance">
|
||||
<div class="storefront-enhance__column storefront-bundle">
|
||||
<h3><?php esc_html_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_html_e( 'All the tools you\'ll need to define your style and customize Storefront.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php esc_html_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=storefront&utm_medium=product&utm_campaign=storefrontaddons" class="storefront-button" target="_blank"><?php esc_html_e( 'Read more and purchase', 'storefront' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="storefront-enhance__column storefront-child-themes">
|
||||
<h3><?php esc_html_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_html_e( 'Quickly and easily transform your shops appearance with Storefront child themes.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php esc_html_e( 'Each has been designed to serve a different industry - from fashion to food.', 'storefront' ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php esc_html_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=storefront&utm_medium=product&utm_campaign=storefrontaddons" class="storefront-button" target="_blank"><?php esc_html_e( 'Check \'em out', 'storefront' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="automattic">
|
||||
<p>
|
||||
<?php
|
||||
/* translators: %s: Automattic branding */
|
||||
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 ( $this->is_plugin_installed( $plugin_slug ) ) {
|
||||
$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_html( $button['message'] ); ?></a>
|
||||
<a href="https://wordpress.org/plugins/<?php echo esc_attr( $plugin_slug ); ?>" target="_blank"><?php esc_html_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 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,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Plugin Install Class
|
||||
*
|
||||
* @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.
|
||||
* @param string $plugin_name The plugin name.
|
||||
* @param string $classes CSS classes.
|
||||
* @param string $activated Button activated text.
|
||||
* @param string $activate Button activate text.
|
||||
* @param string $install Button install text.
|
||||
*/
|
||||
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 ( self::is_plugin_installed( $plugin_slug ) ) {
|
||||
$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( '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( '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="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_html( $button['message'] ); ?></a>
|
||||
</span> <?php echo /* translators: conjunction of two alternative options user can choose (in missing plugin admin notice). Example: "Activate WooCommerce or learn more" */ esc_html__( 'or', 'storefront' ); ?>
|
||||
<a href="https://wordpress.org/plugins/<?php echo esc_attr( $plugin_slug ); ?>" target="_blank"><?php esc_html_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();
|
||||
542
wp-content/themes/storefront/inc/class-storefront.php
Normal file
542
wp-content/themes/storefront/inc/class-storefront.php
Normal file
@@ -0,0 +1,542 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Class
|
||||
*
|
||||
* @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_action( 'enqueue_block_assets', array( $this, 'block_assets' ) );
|
||||
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,
|
||||
'flex-height' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Register menu 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',
|
||||
'style',
|
||||
'script',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* 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' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Setup the WordPress core custom header feature.
|
||||
*/
|
||||
add_theme_support(
|
||||
'custom-header',
|
||||
apply_filters(
|
||||
'storefront_custom_header_args',
|
||||
array(
|
||||
'default-image' => '',
|
||||
'header-text' => false,
|
||||
'width' => 1950,
|
||||
'height' => 500,
|
||||
'flex-width' => true,
|
||||
'flex-height' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* 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 support for title theme feature.
|
||||
*/
|
||||
add_theme_support( 'title-tag' );
|
||||
|
||||
/**
|
||||
* Declare support for selective refreshing of widgets.
|
||||
*/
|
||||
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||
|
||||
/**
|
||||
* Add support for Block Styles.
|
||||
*/
|
||||
add_theme_support( 'wp-block-styles' );
|
||||
|
||||
/**
|
||||
* Add support for full and wide align images.
|
||||
*/
|
||||
add_theme_support( 'align-wide' );
|
||||
|
||||
/**
|
||||
* Add support for editor styles.
|
||||
*/
|
||||
add_theme_support( 'editor-styles' );
|
||||
|
||||
/**
|
||||
* Add support for editor font sizes.
|
||||
*/
|
||||
add_theme_support(
|
||||
'editor-font-sizes',
|
||||
array(
|
||||
array(
|
||||
'name' => __( 'Small', 'storefront' ),
|
||||
'size' => 14,
|
||||
'slug' => 'small',
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Normal', 'storefront' ),
|
||||
'size' => 16,
|
||||
'slug' => 'normal',
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Medium', 'storefront' ),
|
||||
'size' => 23,
|
||||
'slug' => 'medium',
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Large', 'storefront' ),
|
||||
'size' => 26,
|
||||
'slug' => 'large',
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Huge', 'storefront' ),
|
||||
'size' => 37,
|
||||
'slug' => 'huge',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Enqueue editor styles.
|
||||
*/
|
||||
add_editor_style( array( 'assets/css/base/gutenberg-editor.css', $this->google_fonts() ) );
|
||||
|
||||
/**
|
||||
* Add support for responsive embedded content.
|
||||
*/
|
||||
add_theme_support( 'responsive-embeds' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) {
|
||||
/* translators: 1: column number */
|
||||
$footer_region_name = sprintf( __( 'Footer Column %1$d', 'storefront' ), $region );
|
||||
|
||||
/* translators: 1: column number */
|
||||
$footer_region_description = sprintf( __( 'Widgets added here will appear in column %1$d of the footer.', 'storefront' ), $region );
|
||||
} else {
|
||||
/* translators: 1: row number, 2: column number */
|
||||
$footer_region_name = sprintf( __( 'Footer Row %1$d - Column %2$d', 'storefront' ), $row, $region );
|
||||
|
||||
/* translators: 1: column number, 2: row number */
|
||||
$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
|
||||
*/
|
||||
wp_enqueue_style( 'storefront-fonts', $this->google_fonts(), array(), $storefront_version );
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Google fonts.
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @return string Google fonts URL for the theme.
|
||||
*/
|
||||
public function google_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' => rawurlencode( 'latin,latin-ext' ),
|
||||
);
|
||||
|
||||
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
|
||||
|
||||
return $fonts_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue block assets.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function block_assets() {
|
||||
global $storefront_version;
|
||||
|
||||
// Styles.
|
||||
wp_enqueue_style( 'storefront-gutenberg-blocks', get_template_directory_uri() . '/assets/css/base/gutenberg-blocks.css', '', $storefront_version );
|
||||
wp_style_add_data( 'storefront-gutenberg-blocks', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 to blogs with more than 1 published author.
|
||||
if ( is_multi_author() ) {
|
||||
$classes[] = 'group-blog';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a class when WooCommerce is not active.
|
||||
*
|
||||
* @todo Refactor child themes to remove dependency on this class.
|
||||
*/
|
||||
$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';
|
||||
}
|
||||
|
||||
// Add class if align-wide is supported.
|
||||
if ( current_theme_supports( 'align-wide' ) ) {
|
||||
$classes[] = 'storefront-align-wide';
|
||||
}
|
||||
|
||||
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() {
|
||||
global $storefront_version;
|
||||
|
||||
wp_enqueue_style( 'source-sans-pro', '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,300italic,400italic,700,900', array(), $storefront_version );
|
||||
$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,52 @@
|
||||
<?php // @codingStandardsIgnoreLine.
|
||||
/**
|
||||
* Class to create a custom arbitrary html control for dividers etc
|
||||
*
|
||||
* @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,50 @@
|
||||
<?php // @codingStandardsIgnoreLine.
|
||||
/**
|
||||
* Class to create a Customizer control for displaying information
|
||||
*
|
||||
* @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
|
||||
/* translators: 1: Storefront, 2: start <a> tag, 3: Storefront, 4: end <a> tag */
|
||||
printf( esc_html__( 'There\'s a range of %1$s extensions available to put additional power in your hands. Check out the %2$s%3$s%4$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
|
||||
/* translators: %s: Storefront */
|
||||
printf( esc_html__( 'Enjoying %s?', 'storefront' ), 'Storefront' );
|
||||
?>
|
||||
</span>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
/* translators: 1: start <a> tag, 2: end <a> tag */
|
||||
printf( esc_html__( 'Why not leave us a review on %1$sWordPress.org%2$s? We\'d really appreciate it!', 'storefront' ), '<a href="https://wordpress.org/themes/storefront">', '</a>' );
|
||||
?>
|
||||
</p>
|
||||
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php // @codingStandardsIgnoreLine.
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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'.
|
||||
*/
|
||||
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,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront Jetpack Class
|
||||
*
|
||||
* @package storefront
|
||||
* @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 ( function_exists( 'storefront_is_product_archive' ) && storefront_is_product_archive() ) {
|
||||
do_action( 'storefront_jetpack_product_infinite_scroll_before' );
|
||||
woocommerce_product_loop_start();
|
||||
}
|
||||
|
||||
while ( have_posts() ) :
|
||||
the_post();
|
||||
if ( function_exists( 'storefront_is_product_archive' ) && storefront_is_product_archive() ) {
|
||||
wc_get_template_part( 'content', 'product' );
|
||||
} else {
|
||||
get_template_part( 'content', get_post_format() );
|
||||
}
|
||||
endwhile; // end of the loop.
|
||||
|
||||
if ( function_exists( 'storefront_is_product_archive' ) && 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;
|
||||
|
||||
if ( wp_style_is( 'the-neverending-homepage', 'enqueued' ) ) {
|
||||
wp_enqueue_style( 'storefront-jetpack-infinite-scroll', get_template_directory_uri() . '/assets/css/jetpack/infinite-scroll.css', array( 'the-neverending-homepage' ), $storefront_version );
|
||||
wp_style_add_data( 'storefront-jetpack-infinite-scroll', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'storefront-jetpack-widgets', get_template_directory_uri() . '/assets/css/jetpack/widgets.css', array(), $storefront_version );
|
||||
wp_style_add_data( 'storefront-jetpack-widgets', 'rtl', 'replace' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_Jetpack();
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront NUX Admin Inbox Messages.
|
||||
*
|
||||
* @package storefront
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
use Automattic\WooCommerce\Admin\Notes\Note;
|
||||
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'Storefront_NUX_Admin_Inbox_Messages_Customize' ) ) :
|
||||
/**
|
||||
* The initial Storefront inbox Message.
|
||||
*/
|
||||
class Storefront_NUX_Admin_Inbox_Messages_Customize {
|
||||
|
||||
use NoteTraits;
|
||||
|
||||
/**
|
||||
* Name of the note for use in the database.
|
||||
*/
|
||||
const NOTE_NAME = 'storefront-customize';
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*
|
||||
* @return Note
|
||||
*/
|
||||
public static function get_note() {
|
||||
$note = new Note();
|
||||
$note->set_title( __( 'Design your store with Storefront 🎨', 'storefront' ) );
|
||||
$note->set_content( __( 'Visit the Storefront settings page to start setup and customization of your shop.', 'storefront' ) );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_content_data( (object) array() );
|
||||
$note->set_source( 'storefront' );
|
||||
$note->add_action(
|
||||
'customize-store-with-storefront',
|
||||
__( 'Let\'s go!', 'storefront' ),
|
||||
admin_url( 'themes.php?page=storefront-welcome' ),
|
||||
Note::E_WC_ADMIN_NOTE_ACTIONED,
|
||||
true
|
||||
);
|
||||
return $note;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront NUX Admin Class
|
||||
*
|
||||
* @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' ) );
|
||||
|
||||
/*
|
||||
* In case the WC Admin inbox is not available, show the admin notice.
|
||||
*/
|
||||
if ( $this->is_inbox_available() ) {
|
||||
add_action( 'admin_notices', array( $this, 'admin_inbox_messages' ), 99 );
|
||||
} else {
|
||||
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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if WC Admin inbox is available. It might not be available if
|
||||
* WooCommerce is not installed, in old versions of WC or if wc-admin
|
||||
* has been disabled.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
private function is_inbox_available() {
|
||||
if (
|
||||
function_exists( 'WC' ) &&
|
||||
is_callable( array( WC(), 'is_wc_admin_active' ) ) &&
|
||||
WC()->is_wc_admin_active() &&
|
||||
version_compare( WC_VERSION, '4.8.0', '>=' )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_style_add_data( 'storefront-admin-nux', 'rtl', 'replace' );
|
||||
|
||||
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() && 0 === strpos( basename( wp_get_referer() ), 'index.php?page=wc-setup' ) && '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>
|
||||
<?php
|
||||
self::admin_notices_content();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin notices body.
|
||||
* Extracted to a separate static function to be usable in other than admin_notice context.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public static function admin_notices_content() {
|
||||
global $pagenow;
|
||||
?>
|
||||
<div class="notice-content">
|
||||
<?php if ( ! storefront_is_woocommerce_activated() && current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) ) : ?>
|
||||
<h2><?php esc_html_e( 'Thanks for installing Storefront, you rock! 🤘', 'storefront' ); ?></h2>
|
||||
<p><?php esc_html_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(), __( '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_html__( '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_html__( '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' ) && self::is_woocommerce_empty() ) : ?>
|
||||
<input type="hidden" name="products" value="on">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( false === (bool) get_option( 'storefront_nux_fresh_site' ) ) : ?>
|
||||
<div class="notice-input">
|
||||
<label>
|
||||
<input type="checkbox" name="homepage" checked>
|
||||
<?php
|
||||
if ( 'page' === get_option( 'show_on_front' ) ) {
|
||||
esc_html_e( 'Apply the Storefront homepage template', 'storefront' );
|
||||
} else {
|
||||
esc_html_e( 'Create a homepage using Storefront\'s homepage template', 'storefront' );
|
||||
}
|
||||
?>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<?php if ( self::is_woocommerce_empty() ) : ?>
|
||||
<div class="notice-input">
|
||||
<label>
|
||||
<input type="checkbox" name="products" checked>
|
||||
<?php esc_html_e( 'Add example products', 'storefront' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="submit" name="storefront-guided-tour" class="sf-nux-button" value="<?php esc_attr_e( 'Let\'s go!', 'storefront' ); ?>">
|
||||
<a href="#" class="sf-nux-dismiss-button" ><?php esc_html_e( 'Skip', 'storefront' ); ?></a>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX dismiss notice.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function dismiss_nux() {
|
||||
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'storefront_notice_dismiss' ) || ! current_user_can( 'manage_options' ) ) { // WPCS: input var ok.
|
||||
die();
|
||||
}
|
||||
|
||||
update_option( 'storefront_nux_dismissed', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints Storefront inbox messages.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function admin_inbox_messages() {
|
||||
// The setup already has happened. No inbox message needed.
|
||||
if ( true === (bool) get_option( 'storefront_nux_dismissed' ) ) {
|
||||
return;
|
||||
}
|
||||
// Storefront settings page link and welcome message.
|
||||
require 'class-storefront-nux-admin-inbox-messages-customize.php';
|
||||
Storefront_NUX_Admin_Inbox_Messages_Customize::possibly_add_note();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' === sanitize_text_field( wp_unslash( $_REQUEST['homepage'] ) ) ) { // WPCS: input var ok.
|
||||
if ( current_user_can( 'edit_pages' ) && 'page' === get_option( 'show_on_front' ) ) {
|
||||
$this->assign_page_template( get_option( 'page_on_front' ), 'template-homepage.php' );
|
||||
} else {
|
||||
$tasks[] = 'homepage';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_REQUEST['products'] ) && 'on' === sanitize_text_field( wp_unslash( $_REQUEST['products'] ) ) ) { // WPCS: input var ok.
|
||||
$tasks[] = 'products';
|
||||
}
|
||||
|
||||
if ( ! empty( $tasks ) ) {
|
||||
$args['sf_tasks'] = implode( ',', $tasks );
|
||||
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
|
||||
// Make sure the fresh_site flag is set to true.
|
||||
update_option( 'fresh_site', true );
|
||||
|
||||
if ( current_user_can( 'edit_pages' ) && true === (bool) get_option( 'storefront_nux_fresh_site' ) ) {
|
||||
$this->set_woocommerce_pages_full_width();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to the Storefront Welcome screen when exiting the Customizer.
|
||||
$args['return'] = rawurlencode( admin_url( 'themes.php?page=storefront-welcome' ) );
|
||||
|
||||
wp_safe_redirect( add_query_arg( $args, admin_url( 'customize.php' ) ) );
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WooCommerce page ids.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public static function get_woocommerce_pages() {
|
||||
$woocommerce_pages = array();
|
||||
|
||||
$wc_pages_options = apply_filters(
|
||||
'storefront_page_option_names',
|
||||
array(
|
||||
'woocommerce_cart_page_id',
|
||||
'woocommerce_checkout_page_id',
|
||||
'woocommerce_myaccount_page_id',
|
||||
'woocommerce_shop_page_id',
|
||||
'woocommerce_terms_page_id',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $wc_pages_options as $option ) {
|
||||
$page_id = get_option( $option );
|
||||
|
||||
if ( ! empty( $page_id ) ) {
|
||||
$page_id = intval( $page_id );
|
||||
|
||||
if ( null !== get_post( $page_id ) ) {
|
||||
$woocommerce_pages[ $option ] = $page_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $woocommerce_pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Storefront fresh site flag.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public function log_fresh_site_state() {
|
||||
if ( null === get_option( 'storefront_nux_fresh_site', null ) ) {
|
||||
update_option( 'storefront_nux_fresh_site', get_option( 'fresh_site' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom classes to the list of admin body classes.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param string $classes Classes for the admin body element.
|
||||
* @return string
|
||||
*/
|
||||
public function admin_body_class( $classes ) {
|
||||
if ( true === (bool) get_option( 'storefront_nux_dismissed' ) ) {
|
||||
return $classes;
|
||||
}
|
||||
|
||||
$classes .= ' sf-nux ';
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set WooCommerce pages to use the full width template.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
private function set_woocommerce_pages_full_width() {
|
||||
$wc_pages = $this->get_woocommerce_pages();
|
||||
|
||||
foreach ( $wc_pages as $option => $page_id ) {
|
||||
$this->assign_page_template( $page_id, 'template-fullwidth.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a page id assign a given page template to it.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @param int $page_id Page id.
|
||||
* @param string $template Template file name.
|
||||
* @return void|bool Returns false if $page_id or $template is empty.
|
||||
*/
|
||||
private function assign_page_template( $page_id, $template ) {
|
||||
if ( empty( $page_id ) || empty( $template ) || '' === locate_template( $template ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
update_post_meta( $page_id, '_wp_page_template', $template );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WooCommerce is empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static 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,156 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront NUX Guided Tour Class
|
||||
*
|
||||
* @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_style_add_data( 'sp-guided-tour', 'rtl', 'replace' );
|
||||
|
||||
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' ),
|
||||
/* translators: %s: 'End Of Line' symbol */
|
||||
'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' => '',
|
||||
/* translators: 1: open <strong> tag, 2: close <strong> tag, 3: 'End Of Line' symbol */
|
||||
'message' => sprintf( __( 'All set! Remember to %1$ssave & publish%2$s your changes when you\'re done.%3$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();
|
||||
File diff suppressed because it is too large
Load Diff
226
wp-content/themes/storefront/inc/storefront-functions.php
Normal file
226
wp-content/themes/storefront/inc/storefront-functions.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 . '; ' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an hex colors, returns an array with the colors components.
|
||||
*
|
||||
* @param strong $hex Hex color e.g. #111111.
|
||||
* @return bool Array with color components (r, g, b).
|
||||
* @since 2.5.8
|
||||
*/
|
||||
function get_rgb_values_from_hex( $hex ) {
|
||||
// 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 ) );
|
||||
|
||||
return array(
|
||||
'r' => $r,
|
||||
'g' => $g,
|
||||
'b' => $b,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true for light colors and false for dark colors.
|
||||
*
|
||||
* @param strong $hex Hex color e.g. #111111.
|
||||
* @return bool True if the average lightness of the three components of the color is higher or equal than 127.5.
|
||||
* @since 2.5.8
|
||||
*/
|
||||
function is_color_light( $hex ) {
|
||||
$rgb_values = get_rgb_values_from_hex( $hex );
|
||||
$average_lightness = ( $rgb_values['r'] + $rgb_values['g'] + $rgb_values['b'] ) / 3;
|
||||
return $average_lightness >= 127.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust a hex color brightness
|
||||
* Allows us to create hover styles for custom link colors
|
||||
*
|
||||
* @since 2.5.8 Added $opacity argument.
|
||||
*
|
||||
* @param strong $hex Hex color e.g. #111111.
|
||||
* @param integer $steps Factor by which to brighten/darken ranging from -255 (darken) to 255 (brighten).
|
||||
* @param float $opacity Opacity factor between 0 and 1.
|
||||
* @return string Brightened/darkened color (hex by default, rgba if opacity is set to a valid value below 1).
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function storefront_adjust_color_brightness( $hex, $steps, $opacity = 1 ) {
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter.
|
||||
$steps = max( -255, min( 255, $steps ) );
|
||||
|
||||
$rgb_values = get_rgb_values_from_hex( $hex );
|
||||
|
||||
// Adjust number of steps and keep it inside 0 to 255.
|
||||
$r = max( 0, min( 255, $rgb_values['r'] + $steps ) );
|
||||
$g = max( 0, min( 255, $rgb_values['g'] + $steps ) );
|
||||
$b = max( 0, min( 255, $rgb_values['b'] + $steps ) );
|
||||
|
||||
if ( $opacity >= 0 && $opacity < 1 ) {
|
||||
return 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $opacity . ')';
|
||||
}
|
||||
|
||||
$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 );
|
||||
}
|
||||
@@ -0,0 +1,698 @@
|
||||
<?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 !== intval( 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_html_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="' . esc_attr( get_comment_date( 'c' ) ) . '">' . esc_html( 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-' . esc_attr( $region + $regions * ( $row - 1 ) ) ) ) {
|
||||
$columns = $region;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $columns ) ) :
|
||||
?>
|
||||
<div class=<?php echo '"footer-widgets row-' . esc_attr( $row ) . ' col-' . esc_attr( $columns ) . ' fix"'; ?>>
|
||||
<?php
|
||||
for ( $column = 1; $column <= $columns; $column++ ) :
|
||||
$footer_n = $column + $regions * ( $row - 1 );
|
||||
|
||||
if ( is_active_sidebar( 'footer-' . esc_attr( $footer_n ) ) ) :
|
||||
?>
|
||||
<div class="block footer-widget-<?php echo esc_attr( $column ); ?>">
|
||||
<?php dynamic_sidebar( 'footer-' . esc_attr( $footer_n ) ); ?>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
endfor;
|
||||
?>
|
||||
</div><!-- .footer-widgets.row-<?php echo esc_attr( $row ); ?> -->
|
||||
<?php
|
||||
unset( $columns );
|
||||
endif;
|
||||
endfor;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_credit' ) ) {
|
||||
/**
|
||||
* Display the theme credit
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_credit() {
|
||||
$links_output = '';
|
||||
|
||||
if ( apply_filters( 'storefront_credit_link', true ) ) {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
$links_output .= '<a href="https://woocommerce.com" target="_blank" title="' . esc_attr__( 'WooCommerce - The Best eCommerce Platform for WordPress', 'storefront' ) . '" rel="noreferrer">' . esc_html__( 'Built with Storefront & WooCommerce', 'storefront' ) . '</a>.';
|
||||
} else {
|
||||
$links_output .= '<a href="https://woocommerce.com/storefront/" target="_blank" title="' . esc_attr__( 'Storefront - The perfect platform for your next WooCommerce project.', 'storefront' ) . '" rel="noreferrer">' . esc_html__( 'Built with Storefront', 'storefront' ) . '</a>.';
|
||||
}
|
||||
}
|
||||
|
||||
if ( apply_filters( 'storefront_privacy_policy_link', true ) && function_exists( 'the_privacy_policy_link' ) ) {
|
||||
$separator = '<span role="separator" aria-hidden="true"></span>';
|
||||
$links_output = get_the_privacy_policy_link( '', ( ! empty( $links_output ) ? $separator : '' ) ) . $links_output;
|
||||
}
|
||||
|
||||
$links_output = apply_filters( 'storefront_credit_links_output', $links_output );
|
||||
?>
|
||||
<div class="site-info">
|
||||
<?php echo esc_html( apply_filters( 'storefront_copyright_text', $content = '© ' . get_bloginfo( 'name' ) . ' ' . gmdate( 'Y' ) ) ); ?>
|
||||
|
||||
<?php if ( ! empty( $links_output ) ) { ?>
|
||||
<br />
|
||||
<?php echo wp_kses_post( $links_output ); ?>
|
||||
<?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;
|
||||
} 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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
}
|
||||
|
||||
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_attr_e( 'Primary Navigation', 'storefront' ); ?>">
|
||||
<button class="menu-toggle" aria-controls="site-navigation" aria-expanded="false"><span><?php echo esc_html( 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_attr_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_html_e( 'Skip to navigation', 'storefront' ); ?></a>
|
||||
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_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() {
|
||||
if ( is_front_page() && is_page_template( 'template-fullwidth.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<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
|
||||
|
||||
/**
|
||||
* Functions hooked in to storefront_post_header_before action.
|
||||
*
|
||||
* @hooked storefront_post_meta - 10
|
||||
*/
|
||||
do_action( 'storefront_post_header_before' );
|
||||
|
||||
if ( is_single() ) {
|
||||
the_title( '<h1 class="entry-title">', '</h1>' );
|
||||
} else {
|
||||
the_title( sprintf( '<h2 class="alpha entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
|
||||
}
|
||||
|
||||
do_action( 'storefront_post_header_after' );
|
||||
?>
|
||||
</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(
|
||||
/* translators: %s: post title */
|
||||
__( '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() {
|
||||
if ( 'post' !== get_post_type() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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() )
|
||||
);
|
||||
|
||||
$output_time_string = sprintf( '<a href="%1$s" rel="bookmark">%2$s</a>', esc_url( get_permalink() ), $time_string );
|
||||
|
||||
$posted_on = '
|
||||
<span class="posted-on">' .
|
||||
/* translators: %s: post date */
|
||||
sprintf( __( 'Posted on %s', 'storefront' ), $output_time_string ) .
|
||||
'</span>';
|
||||
|
||||
// Author.
|
||||
$author = sprintf(
|
||||
'<span class="post-author">%1$s <a href="%2$s" class="url fn" rel="author">%3$s</a></span>',
|
||||
__( 'by', 'storefront' ),
|
||||
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
|
||||
esc_html( get_the_author() )
|
||||
);
|
||||
|
||||
// Comments.
|
||||
$comments = '';
|
||||
|
||||
if ( ! post_password_required() && ( comments_open() || 0 !== intval( get_comments_number() ) ) ) {
|
||||
$comments_number = get_comments_number_text( __( 'Leave a comment', 'storefront' ), __( '1 Comment', 'storefront' ), __( '% Comments', 'storefront' ) );
|
||||
|
||||
$comments = sprintf(
|
||||
'<span class="post-comments">— <a href="%1$s">%2$s</a></span>',
|
||||
esc_url( get_comments_link() ),
|
||||
$comments_number
|
||||
);
|
||||
}
|
||||
|
||||
echo wp_kses(
|
||||
sprintf( '%1$s %2$s %3$s', $posted_on, $author, $comments ),
|
||||
array(
|
||||
'span' => array(
|
||||
'class' => array(),
|
||||
),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'title' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
'time' => array(
|
||||
'datetime' => array(),
|
||||
'class' => array(),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_edit_post_link' ) ) {
|
||||
/**
|
||||
* Display the edit link
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function storefront_edit_post_link() {
|
||||
edit_post_link(
|
||||
sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s: Name of current post. Only visible to screen readers */
|
||||
__( 'Edit <span class="screen-reader-text">%s</span>', 'storefront' ),
|
||||
array(
|
||||
'span' => array(
|
||||
'class' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
get_the_title()
|
||||
),
|
||||
'<div class="edit-link">',
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_post_taxonomy' ) ) {
|
||||
/**
|
||||
* Display the post taxonomies
|
||||
*
|
||||
* @since 2.4.0
|
||||
*/
|
||||
function storefront_post_taxonomy() {
|
||||
/* translators: used between list items, there is a space after the comma */
|
||||
$categories_list = get_the_category_list( __( ', ', 'storefront' ) );
|
||||
|
||||
/* translators: used between list items, there is a space after the comma */
|
||||
$tags_list = get_the_tag_list( '', __( ', ', 'storefront' ) );
|
||||
?>
|
||||
|
||||
<aside class="entry-taxonomy">
|
||||
<?php if ( $categories_list ) : ?>
|
||||
<div class="cat-links">
|
||||
<?php echo esc_html( _n( 'Category:', 'Categories:', count( get_the_category() ), 'storefront' ) ); ?> <?php echo wp_kses_post( $categories_list ); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $tags_list ) : ?>
|
||||
<div class="tags-links">
|
||||
<?php echo esc_html( _n( 'Tag:', 'Tags:', count( get_the_tags() ), 'storefront' ) ); ?> <?php echo wp_kses_post( $tags_list ); ?>
|
||||
</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_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,93 @@
|
||||
<?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()
|
||||
*/
|
||||
add_action( 'homepage', 'storefront_homepage_content', 10 );
|
||||
|
||||
/**
|
||||
* 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_content', 30 );
|
||||
add_action( 'storefront_loop_post', 'storefront_post_taxonomy', 40 );
|
||||
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_content', 30 );
|
||||
add_action( 'storefront_single_post_bottom', 'storefront_edit_post_link', 5 );
|
||||
add_action( 'storefront_single_post_bottom', 'storefront_post_taxonomy', 5 );
|
||||
add_action( 'storefront_single_post_bottom', 'storefront_post_nav', 10 );
|
||||
add_action( 'storefront_single_post_bottom', 'storefront_display_comments', 20 );
|
||||
add_action( 'storefront_post_header_before', 'storefront_post_meta', 10 );
|
||||
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', 'storefront_edit_post_link', 30 );
|
||||
add_action( 'storefront_page_after', 'storefront_display_comments', 10 );
|
||||
|
||||
/**
|
||||
* Homepage Page Template
|
||||
*
|
||||
* @see storefront_homepage_header()
|
||||
* @see storefront_page_content()
|
||||
*/
|
||||
add_action( 'storefront_homepage', 'storefront_homepage_header', 10 );
|
||||
add_action( 'storefront_homepage', 'storefront_page_content', 20 );
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce Adjacent Products Class
|
||||
*
|
||||
* @package storefront
|
||||
* @since 2.4.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_WooCommerce_Adjacent_Products' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront WooCommerce Adjacent Products Class
|
||||
*/
|
||||
class Storefront_WooCommerce_Adjacent_Products {
|
||||
|
||||
/**
|
||||
* The current product ID.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
private $current_product = null;
|
||||
|
||||
/**
|
||||
* Whether post should be in a same taxonomy term.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $in_same_term = false;
|
||||
|
||||
/**
|
||||
* List of excluded term IDs.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $excluded_terms = '';
|
||||
|
||||
/**
|
||||
* Taxonomy slug.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $taxonomy = 'product_cat';
|
||||
|
||||
/**
|
||||
* Whether to retrieve previous product.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $previous = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
|
||||
* @param array|string $excluded_terms Optional. Comma-separated list of excluded term IDs. Default empty.
|
||||
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'product_cat'.
|
||||
* @param bool $previous Optional. Whether to retrieve previous product. Default false.
|
||||
*/
|
||||
public function __construct( $in_same_term = false, $excluded_terms = '', $taxonomy = 'product_cat', $previous = false ) {
|
||||
$this->in_same_term = $in_same_term;
|
||||
$this->excluded_terms = $excluded_terms;
|
||||
$this->taxonomy = $taxonomy;
|
||||
$this->previous = $previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adjacent product or circle back to the first/last valid product.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @return WC_Product|false Product object if successful. False if no valid product is found.
|
||||
*/
|
||||
public function get_product() {
|
||||
global $post;
|
||||
|
||||
$product = false;
|
||||
$this->current_product = $post->ID;
|
||||
|
||||
// Try to get a valid product via `get_adjacent_post()`.
|
||||
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
|
||||
while ( $adjacent = $this->get_adjacent() ) {
|
||||
$product = wc_get_product( $adjacent->ID );
|
||||
|
||||
if ( $product && $product->is_visible() ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$product = false;
|
||||
$this->current_product = $adjacent->ID;
|
||||
}
|
||||
|
||||
if ( $product ) {
|
||||
return $product;
|
||||
}
|
||||
|
||||
// No valid product found; Query WC for first/last product.
|
||||
$product = $this->query_wc();
|
||||
|
||||
if ( $product ) {
|
||||
return $product;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adjacent post.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @return WP_POST|false Post object if successful. False if no valid post is found.
|
||||
*/
|
||||
private function get_adjacent() {
|
||||
global $post;
|
||||
|
||||
$direction = $this->previous ? 'previous' : 'next';
|
||||
|
||||
add_filter( 'get_' . $direction . '_post_where', array( $this, 'filter_post_where' ) );
|
||||
|
||||
$adjacent = get_adjacent_post( $this->in_same_term, $this->excluded_terms, $this->previous, $this->taxonomy );
|
||||
|
||||
remove_filter( 'get_' . $direction . '_post_where', array( $this, 'filter_post_where' ) );
|
||||
|
||||
return $adjacent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the WHERE clause in the SQL for an adjacent post query, replacing the
|
||||
* date with date of the next post to consider.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @param string $where The `WHERE` clause in the SQL.
|
||||
* @return WP_POST|false Post object if successful. False if no valid post is found.
|
||||
*/
|
||||
public function filter_post_where( $where ) {
|
||||
global $post;
|
||||
|
||||
$new = get_post( $this->current_product );
|
||||
|
||||
$where = str_replace( $post->post_date, $new->post_date, $where );
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query WooCommerce for either the first or last products.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @return WC_Product|false Post object if successful. False if no valid post is found.
|
||||
*/
|
||||
private function query_wc() {
|
||||
global $post;
|
||||
|
||||
$args = array(
|
||||
'limit' => 2,
|
||||
'visibility' => 'catalog',
|
||||
'exclude' => array( $post->ID ),
|
||||
'orderby' => 'date',
|
||||
'status' => 'publish',
|
||||
);
|
||||
|
||||
if ( ! $this->previous ) {
|
||||
$args['order'] = 'ASC';
|
||||
}
|
||||
|
||||
if ( $this->in_same_term ) {
|
||||
$terms = get_the_terms( $post->ID, $this->taxonomy );
|
||||
|
||||
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
|
||||
$args['category'] = wp_list_pluck( $terms, 'slug' );
|
||||
}
|
||||
}
|
||||
|
||||
$products = wc_get_products( apply_filters( 'storefront_woocommerce_adjacent_query_args', $args ) );
|
||||
|
||||
// At least 2 results are required, otherwise previous/next will be the same.
|
||||
if ( ! empty( $products ) && count( $products ) >= 2 ) {
|
||||
return $products[0];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce Customizer Class
|
||||
*
|
||||
* @package storefront
|
||||
* @since 2.4.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_WooCommerce_Customizer' ) ) :
|
||||
|
||||
/**
|
||||
* The Storefront Customizer class
|
||||
*/
|
||||
class Storefront_WooCommerce_Customizer extends Storefront_Customizer {
|
||||
|
||||
/**
|
||||
* Setup class.
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'customize_register', array( $this, 'customize_register' ), 10 );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'add_customizer_css' ), 130 );
|
||||
add_filter( 'storefront_setting_default_values', array( $this, 'setting_default_values' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the desired default Storefront Options
|
||||
*
|
||||
* @param array $defaults array of default options.
|
||||
* @since 2.4.0
|
||||
* @return array
|
||||
*/
|
||||
public function setting_default_values( $defaults = array() ) {
|
||||
$defaults['storefront_sticky_add_to_cart'] = true;
|
||||
$defaults['storefront_product_pagination'] = true;
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add postMessage support for site title and description for the Theme Customizer along with several other settings.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @since 2.4.0
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
|
||||
/**
|
||||
* Product Page
|
||||
*/
|
||||
$wp_customize->add_section(
|
||||
'storefront_single_product_page',
|
||||
array(
|
||||
'title' => __( 'Product Page', 'storefront' ),
|
||||
'priority' => 10,
|
||||
'panel' => 'woocommerce',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'storefront_product_pagination',
|
||||
array(
|
||||
'default' => apply_filters( 'storefront_default_product_pagination', true ),
|
||||
'sanitize_callback' => 'wp_validate_boolean',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting(
|
||||
'storefront_sticky_add_to_cart',
|
||||
array(
|
||||
'default' => apply_filters( 'storefront_default_sticky_add_to_cart', true ),
|
||||
'sanitize_callback' => 'wp_validate_boolean',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'storefront_sticky_add_to_cart',
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'section' => 'storefront_single_product_page',
|
||||
'label' => __( 'Sticky Add-To-Cart', 'storefront' ),
|
||||
'description' => __( 'A small content bar at the top of the browser window which includes relevant product information and an add-to-cart button. It slides into view once the standard add-to-cart button has scrolled out of view.', 'storefront' ),
|
||||
'priority' => 10,
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'storefront_product_pagination',
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'section' => 'storefront_single_product_page',
|
||||
'label' => __( 'Product Pagination', 'storefront' ),
|
||||
'description' => __( 'Displays next and previous links on product pages. A product thumbnail is displayed with the title revealed on hover.', 'storefront' ),
|
||||
'priority' => 20,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Customizer css.
|
||||
*
|
||||
* @see get_storefront_theme_mods()
|
||||
* @since 2.4.0
|
||||
* @return string $styles the css
|
||||
*/
|
||||
public function get_css() {
|
||||
$storefront_theme_mods = $this->get_storefront_theme_mods();
|
||||
$brighten_factor = apply_filters( 'storefront_brighten_factor', 25 );
|
||||
$darken_factor = apply_filters( 'storefront_darken_factor', -25 );
|
||||
|
||||
$styles = '
|
||||
a.cart-contents,
|
||||
.site-header-cart .widget_shopping_cart a {
|
||||
color: ' . $storefront_theme_mods['header_link_color'] . ';
|
||||
}
|
||||
|
||||
a.cart-contents:hover,
|
||||
.site-header-cart .widget_shopping_cart a:hover,
|
||||
.site-header-cart:hover > li > a {
|
||||
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_link_color'], 65 ) . ';
|
||||
}
|
||||
|
||||
table.cart td.product-remove,
|
||||
table.cart td.actions {
|
||||
border-top-color: ' . $storefront_theme_mods['background_color'] . ';
|
||||
}
|
||||
|
||||
.storefront-handheld-footer-bar ul li.cart .count {
|
||||
background-color: ' . $storefront_theme_mods['header_link_color'] . ';
|
||||
color: ' . $storefront_theme_mods['header_background_color'] . ';
|
||||
border-color: ' . $storefront_theme_mods['header_background_color'] . ';
|
||||
}
|
||||
|
||||
.woocommerce-tabs ul.tabs li.active a,
|
||||
ul.products li.product .price,
|
||||
.onsale,
|
||||
.wc-block-grid__product-onsale,
|
||||
.widget_search form:before,
|
||||
.widget_product_search form:before {
|
||||
color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
}
|
||||
|
||||
.woocommerce-breadcrumb a,
|
||||
a.woocommerce-review-link,
|
||||
.product_meta a {
|
||||
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['text_color'], 5 ) . ';
|
||||
}
|
||||
|
||||
.wc-block-grid__product-onsale,
|
||||
.onsale {
|
||||
border-color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
}
|
||||
|
||||
.star-rating span:before,
|
||||
.quantity .plus, .quantity .minus,
|
||||
p.stars a:hover:after,
|
||||
p.stars a:after,
|
||||
.star-rating span:before,
|
||||
#payment .payment_methods li input[type=radio]:first-child:checked+label:before {
|
||||
color: ' . $storefront_theme_mods['accent_color'] . ';
|
||||
}
|
||||
|
||||
.widget_price_filter .ui-slider .ui-slider-range,
|
||||
.widget_price_filter .ui-slider .ui-slider-handle {
|
||||
background-color: ' . $storefront_theme_mods['accent_color'] . ';
|
||||
}
|
||||
|
||||
.order_details {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -7 ) . ';
|
||||
}
|
||||
|
||||
.order_details > li {
|
||||
border-bottom: 1px dotted ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -28 ) . ';
|
||||
}
|
||||
|
||||
.order_details:before,
|
||||
.order_details:after {
|
||||
background: -webkit-linear-gradient(transparent 0,transparent 0),-webkit-linear-gradient(135deg,' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -7 ) . ' 33.33%,transparent 33.33%),-webkit-linear-gradient(45deg,' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -7 ) . ' 33.33%,transparent 33.33%)
|
||||
}
|
||||
|
||||
#order_review {
|
||||
background-color: ' . $storefront_theme_mods['background_color'] . ';
|
||||
}
|
||||
|
||||
#payment .payment_methods > li .payment_box,
|
||||
#payment .place-order {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -5 ) . ';
|
||||
}
|
||||
|
||||
#payment .payment_methods > li:not(.woocommerce-notice) {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -10 ) . ';
|
||||
}
|
||||
|
||||
#payment .payment_methods > li:not(.woocommerce-notice):hover {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -15 ) . ';
|
||||
}
|
||||
|
||||
.woocommerce-pagination .page-numbers li .page-numbers.current {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], $darken_factor ) . ';
|
||||
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['text_color'], -10 ) . ';
|
||||
}
|
||||
|
||||
.wc-block-grid__product-onsale,
|
||||
.onsale,
|
||||
.woocommerce-pagination .page-numbers li .page-numbers:not(.current) {
|
||||
color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
}
|
||||
|
||||
p.stars a:before,
|
||||
p.stars a:hover~a:before,
|
||||
p.stars.selected a.active~a:before {
|
||||
color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
}
|
||||
|
||||
p.stars.selected a.active:before,
|
||||
p.stars:hover a:before,
|
||||
p.stars.selected a:not(.active):before,
|
||||
p.stars.selected a.active:before {
|
||||
color: ' . $storefront_theme_mods['accent_color'] . ';
|
||||
}
|
||||
|
||||
.single-product div.product .woocommerce-product-gallery .woocommerce-product-gallery__trigger {
|
||||
background-color: ' . $storefront_theme_mods['button_background_color'] . ';
|
||||
color: ' . $storefront_theme_mods['button_text_color'] . ';
|
||||
}
|
||||
|
||||
.single-product div.product .woocommerce-product-gallery .woocommerce-product-gallery__trigger:hover {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
|
||||
border-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
|
||||
color: ' . $storefront_theme_mods['button_text_color'] . ';
|
||||
}
|
||||
|
||||
.button.added_to_cart:focus,
|
||||
.button.wc-forward:focus {
|
||||
outline-color: ' . $storefront_theme_mods['accent_color'] . ';
|
||||
}
|
||||
|
||||
.added_to_cart,
|
||||
.site-header-cart .widget_shopping_cart a.button,
|
||||
.wc-block-grid__products .wc-block-grid__product .wp-block-button__link {
|
||||
background-color: ' . $storefront_theme_mods['button_background_color'] . ';
|
||||
border-color: ' . $storefront_theme_mods['button_background_color'] . ';
|
||||
color: ' . $storefront_theme_mods['button_text_color'] . ';
|
||||
}
|
||||
|
||||
.added_to_cart:hover,
|
||||
.site-header-cart .widget_shopping_cart a.button:hover,
|
||||
.wc-block-grid__products .wc-block-grid__product .wp-block-button__link:hover {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
|
||||
border-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
|
||||
color: ' . $storefront_theme_mods['button_text_color'] . ';
|
||||
}
|
||||
|
||||
.added_to_cart.alt, .added_to_cart, .widget a.button.checkout {
|
||||
background-color: ' . $storefront_theme_mods['button_alt_background_color'] . ';
|
||||
border-color: ' . $storefront_theme_mods['button_alt_background_color'] . ';
|
||||
color: ' . $storefront_theme_mods['button_alt_text_color'] . ';
|
||||
}
|
||||
|
||||
.added_to_cart.alt:hover, .added_to_cart:hover, .widget a.button.checkout:hover {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_alt_background_color'], $darken_factor ) . ';
|
||||
border-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_alt_background_color'], $darken_factor ) . ';
|
||||
color: ' . $storefront_theme_mods['button_alt_text_color'] . ';
|
||||
}
|
||||
|
||||
.button.loading {
|
||||
color: ' . $storefront_theme_mods['button_background_color'] . ';
|
||||
}
|
||||
|
||||
.button.loading:hover {
|
||||
background-color: ' . $storefront_theme_mods['button_background_color'] . ';
|
||||
}
|
||||
|
||||
.button.loading:after {
|
||||
color: ' . $storefront_theme_mods['button_text_color'] . ';
|
||||
}
|
||||
|
||||
@media screen and ( min-width: 768px ) {
|
||||
.site-header-cart .widget_shopping_cart,
|
||||
.site-header .product_list_widget li .quantity {
|
||||
color: ' . $storefront_theme_mods['header_text_color'] . ';
|
||||
}
|
||||
|
||||
.site-header-cart .widget_shopping_cart .buttons,
|
||||
.site-header-cart .widget_shopping_cart .total {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_background_color'], -10 ) . ';
|
||||
}
|
||||
|
||||
.site-header-cart .widget_shopping_cart {
|
||||
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_background_color'], -15 ) . ';
|
||||
}
|
||||
}';
|
||||
|
||||
if ( ! class_exists( 'Storefront_Product_Pagination' ) ) {
|
||||
$styles .= '
|
||||
.storefront-product-pagination a {
|
||||
color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
background-color: ' . $storefront_theme_mods['background_color'] . ';
|
||||
}';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Storefront_Sticky_Add_to_Cart' ) ) {
|
||||
$styles .= '
|
||||
.storefront-sticky-add-to-cart {
|
||||
color: ' . $storefront_theme_mods['text_color'] . ';
|
||||
background-color: ' . $storefront_theme_mods['background_color'] . ';
|
||||
}
|
||||
|
||||
.storefront-sticky-add-to-cart a:not(.button) {
|
||||
color: ' . $storefront_theme_mods['header_link_color'] . ';
|
||||
}';
|
||||
}
|
||||
|
||||
return apply_filters( 'storefront_customizer_woocommerce_css', $styles );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add CSS in <head> for styles handled by the theme customizer
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @return void
|
||||
*/
|
||||
public function add_customizer_css() {
|
||||
wp_add_inline_style( 'storefront-woocommerce-style', $this->get_css() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_WooCommerce_Customizer();
|
||||
@@ -0,0 +1,513 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce Class
|
||||
*
|
||||
* @package storefront
|
||||
* @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_action( 'after_setup_theme', array( $this, 'setup' ) );
|
||||
add_filter( 'body_class', array( $this, 'woocommerce_body_class' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_scripts' ), 20 );
|
||||
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' ) );
|
||||
|
||||
// Integrations.
|
||||
add_action( 'storefront_woocommerce_setup', array( $this, 'setup_integrations' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_integrations_scripts' ), 99 );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'add_customizer_css' ), 140 );
|
||||
|
||||
// Instead of loading Core CSS files, we only register the font families.
|
||||
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
|
||||
add_filter( 'wp_enqueue_scripts', array( $this, 'add_core_fonts' ), 130 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up theme defaults and registers support for various WooCommerce 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.
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @return void
|
||||
*/
|
||||
public function setup() {
|
||||
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' );
|
||||
|
||||
/**
|
||||
* Add 'storefront_woocommerce_setup' action.
|
||||
*
|
||||
* @since 2.4.0
|
||||
*/
|
||||
do_action( 'storefront_woocommerce_setup' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add CSS in <head> to register WooCommerce Core fonts.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @return void
|
||||
*/
|
||||
public function add_core_fonts() {
|
||||
$fonts_url = plugins_url( '/woocommerce/assets/fonts/' );
|
||||
wp_add_inline_style(
|
||||
'storefront-woocommerce-style',
|
||||
'@font-face {
|
||||
font-family: star;
|
||||
src: url(' . $fonts_url . 'star.eot);
|
||||
src:
|
||||
url(' . $fonts_url . 'star.eot?#iefix) format("embedded-opentype"),
|
||||
url(' . $fonts_url . 'star.woff) format("woff"),
|
||||
url(' . $fonts_url . 'star.ttf) format("truetype"),
|
||||
url(' . $fonts_url . 'star.svg#star) format("svg");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
@font-face {
|
||||
font-family: WooCommerce;
|
||||
src: url(' . $fonts_url . 'WooCommerce.eot);
|
||||
src:
|
||||
url(' . $fonts_url . 'WooCommerce.eot?#iefix) format("embedded-opentype"),
|
||||
url(' . $fonts_url . 'WooCommerce.woff) format("woff"),
|
||||
url(' . $fonts_url . 'WooCommerce.ttf) format("truetype"),
|
||||
url(' . $fonts_url . 'WooCommerce.svg#WooCommerce) format("svg");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add WooCommerce specific classes 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 ) {
|
||||
$classes[] = 'woocommerce-active';
|
||||
|
||||
// Remove `no-wc-breadcrumb` body class.
|
||||
$key = array_search( 'no-wc-breadcrumb', $classes, true );
|
||||
|
||||
if ( false !== $key ) {
|
||||
unset( $classes[ $key ] );
|
||||
}
|
||||
|
||||
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-style', 'storefront-icons' ), $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' );
|
||||
|
||||
wp_enqueue_script( 'storefront-handheld-footer-bar', get_template_directory_uri() . '/assets/js/footer' . $suffix . '.js', array(), $storefront_version, true );
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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" aria-label="' . esc_attr__( 'breadcrumbs', 'storefront' ) . '">';
|
||||
$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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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', $storefront_version );
|
||||
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' );
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Product Recommendations
|
||||
*/
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Product_Recommendations' ) ) {
|
||||
wp_enqueue_style( 'storefront-woocommerce-product-recommendations-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/product-recommendations.css', 'storefront-woocommerce-style', $storefront_version );
|
||||
wp_style_add_data( 'storefront-woocommerce-product-recommendations-style', 'rtl', 'replace' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension css.
|
||||
*
|
||||
* @see get_storefront_theme_mods()
|
||||
* @return array $styles the css
|
||||
*/
|
||||
public function get_woocommerce_extension_css() {
|
||||
global $storefront;
|
||||
|
||||
if ( ! is_object( $storefront ) ||
|
||||
! property_exists( $storefront, 'customizer' ) ||
|
||||
! is_a( $storefront->customizer, 'Storefront_Customizer' ) ||
|
||||
! method_exists( $storefront->customizer, 'get_storefront_theme_mods' ) ) {
|
||||
return apply_filters( 'storefront_customizer_woocommerce_extension_css', '' );
|
||||
}
|
||||
|
||||
$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 );
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Integrations.
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets up integrations.
|
||||
*
|
||||
* @since 2.3.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setup_integrations() {
|
||||
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Bundles' ) ) {
|
||||
add_filter( 'woocommerce_bundled_table_item_js_enqueued', '__return_true' );
|
||||
add_filter( 'woocommerce_bundles_group_mode_options_data', array( $this, 'bundles_group_mode_options_data' ) );
|
||||
}
|
||||
|
||||
if ( $this->is_woocommerce_extension_activated( 'WC_Composite_Products' ) ) {
|
||||
add_filter( 'woocommerce_composited_table_item_js_enqueued', '__return_true' );
|
||||
add_filter( 'woocommerce_display_composite_container_cart_item_data', '__return_true' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Includes" meta to parent cart items.
|
||||
* Displayed only on handheld/mobile screens.
|
||||
*
|
||||
* @since 2.3.4
|
||||
*
|
||||
* @param array $group_mode_data Group mode data.
|
||||
* @return array
|
||||
*/
|
||||
public function bundles_group_mode_options_data( $group_mode_data ) {
|
||||
$group_mode_data['parent']['features'][] = 'parent_cart_item_meta';
|
||||
|
||||
return $group_mode_data;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new Storefront_WooCommerce();
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce functions.
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if the current page is a product archive
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function storefront_is_product_archive() {
|
||||
if ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the previous product.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
|
||||
* @param array|string $excluded_terms Optional. Comma-separated list of excluded term IDs. Default empty.
|
||||
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'product_cat'.
|
||||
* @return WC_Product|false Product object if successful. False if no valid product is found.
|
||||
*/
|
||||
function storefront_get_previous_product( $in_same_term = false, $excluded_terms = '', $taxonomy = 'product_cat' ) {
|
||||
$product = new Storefront_WooCommerce_Adjacent_Products( $in_same_term, $excluded_terms, $taxonomy, true );
|
||||
return $product->get_product();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the next product.
|
||||
*
|
||||
* @since 2.4.3
|
||||
*
|
||||
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
|
||||
* @param array|string $excluded_terms Optional. Comma-separated list of excluded term IDs. Default empty.
|
||||
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'product_cat'.
|
||||
* @return WC_Product|false Product object if successful. False if no valid product is found.
|
||||
*/
|
||||
function storefront_get_next_product( $in_same_term = false, $excluded_terms = '', $taxonomy = 'product_cat' ) {
|
||||
$product = new Storefront_WooCommerce_Adjacent_Products( $in_same_term, $excluded_terms, $taxonomy );
|
||||
return $product->get_product();
|
||||
}
|
||||
@@ -0,0 +1,956 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Template Functions.
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'storefront_woo_cart_available' ) ) {
|
||||
/**
|
||||
* Validates whether the Woo Cart instance is available in the request
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @return bool
|
||||
*/
|
||||
function storefront_woo_cart_available() {
|
||||
$woo = WC();
|
||||
return $woo instanceof \WooCommerce && $woo->cart instanceof \WC_Cart;
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
if ( ! storefront_woo_cart_available() ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
|
||||
<?php /* translators: %d: number of items in cart */ ?>
|
||||
<?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_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 ) {
|
||||
$args = apply_filters(
|
||||
'storefront_product_categories_args',
|
||||
array(
|
||||
'limit' => 3,
|
||||
'columns' => 3,
|
||||
'child_categories' => 0,
|
||||
'orderby' => 'menu_order',
|
||||
'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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
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 ) {
|
||||
$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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
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 ) {
|
||||
$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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
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 ) {
|
||||
$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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
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 ) {
|
||||
$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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
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 ) {
|
||||
$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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>';
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo storefront_do_shortcode(
|
||||
'featured_products',
|
||||
array(
|
||||
'per_page' => $per_page,
|
||||
'columns' => $columns,
|
||||
)
|
||||
);
|
||||
// phpcs:enable
|
||||
} elseif ( wc_get_product_ids_on_sale() ) {
|
||||
|
||||
echo '<h2>' . esc_html__( 'On Sale Now', 'storefront' ) . '</h2>';
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo storefront_do_shortcode(
|
||||
'sale_products',
|
||||
array(
|
||||
'per_page' => $per_page,
|
||||
'columns' => $columns,
|
||||
)
|
||||
);
|
||||
// phpcs:enable
|
||||
} elseif ( $recent_fallback ) {
|
||||
|
||||
echo '<h2>' . esc_html__( 'New In Store', 'storefront' ) . '</h2>';
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo storefront_do_shortcode(
|
||||
'recent_products',
|
||||
array(
|
||||
'per_page' => $per_page,
|
||||
'columns' => $columns,
|
||||
)
|
||||
);
|
||||
// phpcs:enable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 ( did_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' ) || did_action( 'woocommerce_blocks_enqueue_checkout_block_scripts_after' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
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() {
|
||||
if ( ! storefront_woo_cart_available() ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<a class="footer-cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>"><?php esc_html_e( '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?
|
||||
$in_same_term = apply_filters( 'storefront_single_product_pagination_same_category', true );
|
||||
$excluded_terms = apply_filters( 'storefront_single_product_pagination_excluded_terms', '' );
|
||||
$taxonomy = apply_filters( 'storefront_single_product_pagination_taxonomy', 'product_cat' );
|
||||
|
||||
$previous_product = storefront_get_previous_product( $in_same_term, $excluded_terms, $taxonomy );
|
||||
$next_product = storefront_get_next_product( $in_same_term, $excluded_terms, $taxonomy );
|
||||
|
||||
if ( ! $previous_product && ! $next_product ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<nav class="storefront-product-pagination" aria-label="<?php esc_attr_e( 'More products', 'storefront' ); ?>">
|
||||
<?php if ( $previous_product ) : ?>
|
||||
<a href="<?php echo esc_url( $previous_product->get_permalink() ); ?>" rel="prev">
|
||||
<?php echo wp_kses_post( $previous_product->get_image() ); ?>
|
||||
<span class="storefront-product-pagination__title"><?php echo wp_kses_post( $previous_product->get_name() ); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $next_product ) : ?>
|
||||
<a href="<?php echo esc_url( $next_product->get_permalink() ); ?>" rel="next">
|
||||
<?php echo wp_kses_post( $next_product->get_image() ); ?>
|
||||
<span class="storefront-product-pagination__title"><?php echo wp_kses_post( $next_product->get_name() ); ?></span>
|
||||
</a>
|
||||
<?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 ( ! $product || ! is_product() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$show = false;
|
||||
|
||||
if ( $product->is_purchasable() && $product->is_in_stock() ) {
|
||||
$show = true;
|
||||
} elseif ( $product->is_type( 'external' ) ) {
|
||||
$show = true;
|
||||
}
|
||||
|
||||
if ( ! $show ) {
|
||||
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_html_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" rel="nofollow">
|
||||
<?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; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
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,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Storefront WooCommerce hooks
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
/**
|
||||
* Homepage
|
||||
*
|
||||
* @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_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 );
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/**
|
||||
* Products
|
||||
*
|
||||
* @see storefront_edit_post_link()
|
||||
* @see storefront_upsell_display()
|
||||
* @see storefront_single_product_pagination()
|
||||
* @see storefront_sticky_single_add_to_cart()
|
||||
*/
|
||||
add_action( 'woocommerce_single_product_summary', 'storefront_edit_post_link', 60 );
|
||||
|
||||
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()
|
||||
*/
|
||||
add_filter( 'woocommerce_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 );
|
||||
}
|
||||
19
wp-content/themes/storefront/inc/wordpress-shims.php
Normal file
19
wp-content/themes/storefront/inc/wordpress-shims.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* WordPress shims.
|
||||
*
|
||||
* @package storefront
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'wp_body_open' ) ) {
|
||||
/**
|
||||
* Adds backwards compatibility for wp_body_open() introduced with WordPress 5.2
|
||||
*
|
||||
* @since 2.5.4
|
||||
* @see https://developer.wordpress.org/reference/functions/wp_body_open/
|
||||
* @return void
|
||||
*/
|
||||
function wp_body_open() {
|
||||
do_action( 'wp_body_open' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user