-
Notifications
You must be signed in to change notification settings - Fork 40
/
functions.php
executable file
·270 lines (217 loc) · 8.59 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* Dokan functions and definitions
*
* @package Dokan
* @since Dokan 1.0
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* @since Dokan 1.0
*/
if ( !isset( $content_width ) ) {
$content_width = 640;
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @since Dokan 1.0
*/
class WeDevs_Dokan_Theme {
function __construct() {
//includes file
$this->includes();
// init actions and filter
$this->init_filters();
$this->init_actions();
// initialize classes
$this->init_classes();
}
/**
* Initialize filters
*
* @return void
*/
function init_filters() {
add_filter( 'wp_title', array( $this, 'wp_title' ), 10, 2 );
add_filter( 'dokan_ls_theme_tags', array( $this, 'live_search_support' ), 10, 2 );
}
/**
* Init action hooks
*
* @return void
*/
function init_actions() {
add_action( 'after_setup_theme', array( $this, 'setup' ) );
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
add_action( 'dokan_admin_menu', array( $this, 'slider_page' ) );
}
public function init_classes() {
Dokan_Slider::init();
}
function includes() {
$lib_dir = dirname( __FILE__ ) . '/lib/';
$inc_dir = dirname( __FILE__ ) . '/includes/';
$classes_dir = dirname( __FILE__ ) . '/classes/';
require_once $classes_dir . 'slider.php';
require_once $inc_dir . 'wc-functions.php';
require_once $inc_dir . 'wc-template.php';
if ( is_child_theme() && file_exists( get_stylesheet_directory() . '/classes/customizer.php' ) ) {
require_once get_stylesheet_directory() . '/classes/customizer.php';
} else {
require_once $classes_dir . 'customizer.php';
}
if ( is_admin() ) {
} else {
require_once $lib_dir . 'bootstrap-walker.php';
require_once $inc_dir . 'template-tags.php';
}
}
/**
* Setup dokan
*
* @uses `after_setup_theme` hook
*/
function setup() {
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
*/
load_theme_textdomain( 'dokan-theme', 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
*/
add_theme_support( 'post-thumbnails' );
/**
* This theme uses wp_nav_menu() in one location.
*/
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'dokan-theme' ),
'top-left' => __( 'Top Left', 'dokan-theme' ),
'footer' => __( 'Footer Menu', 'dokan-theme' ),
) );
add_theme_support( 'woocommerce' );
// Support gallery image for single product page
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/*
* This theme supports custom background color and image,
* and here we also set up the default background color.
*/
add_theme_support( 'custom-background', array(
'default-color' => 'F7F7F7',
) );
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );
}
/**
* Live search module on support
*
* @since 2.3.1
*
* @return void
**/
public function live_search_support( $themes ) {
$themes['dokan-theme'] = '#primary';
return $themes;
}
/**
* Register widgetized area and update sidebar with default widgets
*
* @since Dokan 1.0
*/
function widgets_init() {
$sidebars = array(
array( 'name' => __( 'General Sidebar', 'dokan-theme' ), 'id' => 'sidebar-1' ),
array( 'name' => __( 'Home Sidebar', 'dokan-theme' ), 'id' => 'sidebar-home' ),
array( 'name' => __( 'Blog Sidebar', 'dokan-theme' ), 'id' => 'sidebar-blog' ),
array( 'name' => __( 'Header Sidebar', 'dokan-theme' ), 'id' => 'sidebar-header' ),
array( 'name' => __( 'Shop Archive', 'dokan-theme' ), 'id' => 'sidebar-shop' ),
array( 'name' => __( 'Single Product', 'dokan-theme' ), 'id' => 'sidebar-single-product' ),
array( 'name' => __( 'Footer Sidebar - 1', 'dokan-theme' ), 'id' => 'footer-1' ),
array( 'name' => __( 'Footer Sidebar - 2', 'dokan-theme' ), 'id' => 'footer-2' ),
array( 'name' => __( 'Footer Sidebar - 3', 'dokan-theme' ), 'id' => 'footer-3' ),
array( 'name' => __( 'Footer Sidebar - 4', 'dokan-theme' ), 'id' => 'footer-4' ),
);
$args = apply_filters( 'dokan_widget_args', array(
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
foreach ( $sidebars as $sidebar ) {
$args['name'] = $sidebar['name'];
$args['id'] = $sidebar['id'];
register_sidebar( $args );
}
}
/**
* Enqueue scripts and styles
*
* @since Dokan 1.0
*/
function scripts() {
$protocol = is_ssl() ? 'https' : 'http';
$template_directory = get_template_directory_uri();
$skin = get_theme_mod( 'color_skin', 'orange.css' );
wp_register_style( 'dokan-fontawesome', $template_directory . '/assets/css/font-awesome.min.css', false, null );
// register styles
wp_enqueue_style( 'bootstrap', $template_directory . '/assets/css/bootstrap.css', false, null );
wp_enqueue_style( 'flexslider', $template_directory . '/assets/css/flexslider.css', false, null );
wp_enqueue_style( 'dokan-fontawesome' );
wp_enqueue_style( 'dokan-opensans', $protocol . '://fonts.googleapis.com/css?family=Open+Sans:400,700' );
wp_enqueue_style( 'dokan-theme', $template_directory . '/style.css', false, null );
wp_enqueue_style( 'dokan-theme-skin', $template_directory . '/assets/css/skins/' . $skin, false, null );
/****** Scripts ******/
if ( is_single() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'keyboard-image-navigation', $template_directory . '/assets/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );
}
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui' );
wp_enqueue_script( 'bootstrap-min', $template_directory . '/assets/js/bootstrap.min.js', false, null, true );
wp_enqueue_script( 'flexslider', $template_directory . '/assets/js/jquery.flexslider-min.js', array( 'jquery' ) );
wp_enqueue_script( 'dokan-theme-scripts', $template_directory . '/assets/js/script.js', false, null, true );
wp_enqueue_script( 'wc-cart-fragments' );
}
/**
* Create a nicely formatted and more specific title element text for output
* in head of document, based on current view.
*
* @since Dokan 1.0.4
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string The filtered title.
*/
function wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() ) {
return $title;
}
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'dokan-theme' ), max( $paged, $page ) );
}
return $title;
}
public function slider_page() {
add_submenu_page( 'themes.php', __( 'Slider', 'dokan-theme' ), __( 'Slider', 'dokan-theme' ), 'manage_options', 'edit.php?post_type=dokan_slider' );
}
}
$dokan = new WeDevs_Dokan_Theme();