Skip to content

Commit

Permalink
feat(Theme): Storefront theme compatibilty
Browse files Browse the repository at this point in the history
Added Storefront theme compatibilty so that the store page and the vendor dashboard page becomes full-width and doesn’t show sidebar.
  • Loading branch information
tareq1988 committed Oct 30, 2018
1 parent 2736b32 commit 8557bb3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dokan.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ function includes() {
require_once $inc_dir . 'admin/promotion.php';
} else {
require_once $inc_dir . 'template-tags.php';
require_once $inc_dir . 'class-theme-support.php';
}

// API includes
Expand Down Expand Up @@ -376,6 +377,10 @@ function init_classes() {
Dokan_Template_Settings::init();
}

if ( ! is_admin() ) {
new Dokan_Theme_Support();
}

if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
Dokan_Ajax::init()->init_ajax();
}
Expand Down
41 changes: 41 additions & 0 deletions includes/class-theme-support.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* Dokan Theme Support
*
* @since 3.0
*
* @package Dokan
*/
class Dokan_Theme_Support {

/**
* The currently active theme
*
* @var string
*/
private $theme;

/**
* Constructor
*/
public function __construct() {
$this->theme = get_template();

$this->include_support();
}

/**
* Include supported theme compatibility
*
* @return void
*/
private function include_support() {
switch ( $this->theme ) {
case 'storefront':
require_once __DIR__ . '/theme-support/class-' . $this->theme . '.php';
break;
}
}

}
51 changes: 51 additions & 0 deletions includes/theme-support/class-storefront.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* Storefront Theme Support
*
* @see https://woocommerce.com/storefront/
*
* @since 3.0
*/
class Dokan_Theme_Support_Storefront {

/**
* The constructor
*/
function __construct() {
add_action( 'storefront_page_after', [ $this, 'remove_sidebar'], 5 );
add_filter( 'body_class', [ $this, 'full_width_page'] );
}

/**
* Remove sidebar from store and dashboard page
*
* @return void
*/
public function remove_sidebar() {
if ( dokan_is_store_page() || dokan_is_seller_dashboard() ) {
remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
}
}

/**
* Makes the store and dashboard page full width
*
* @param array $classes
*
* @return array
*/
public function full_width_page( $classes ) {

if ( dokan_is_store_page() || dokan_is_seller_dashboard() ) {

if ( ! in_array( 'page-template-template-fullwidth-php', $classes ) ) {
$classes[] = 'page-template-template-fullwidth-php';
}
}

return $classes;
}
}

return new Dokan_Theme_Support_Storefront();

0 comments on commit 8557bb3

Please sign in to comment.