forked from disgogo/flexmarket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
344 lines (292 loc) · 10 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
if (!function_exists('m413_options')) {
// Admin functions
require_once(get_template_directory() . '/admin/admin-functions.php');
require_once(get_template_directory() . '/admin/admin-interface.php');
require_once(get_template_directory() . '/admin/theme-settings.php');
require_once(get_template_directory() . '/admin/admin-custom-functions.php');
}
if ( ! class_exists( 'cmb_Meta_Box' ) ) {
// register metaboxes
require_once(get_template_directory() . '/functions/post-metabox.php');
require_once(get_template_directory() . '/functions/page-metabox.php');
}
//add shortcodes functions
require_once(get_template_directory() . '/functions/shortcodes.php');
if(!class_exists('AQ_Page_Builder')) {
//Register Aqua Page Builder
require_once(get_template_directory() . '/functions/aqua-page-builder/aq-page-builder.php');
}
if ( class_exists( 'MarketPress' ) ) {
//Register MarketPress related functions
require_once(get_template_directory() . '/functions/mp-functions.php');
require_once(get_template_directory() . '/functions/mp-metabox.php');
require_once(get_template_directory() . '/functions/mp-widgets.php');
}
// Register Custom Navigation Walker
require_once(get_template_directory() . '/functions/twitter_bootstrap_nav_walker.php');
// register CSS
function mpt_register_style() {
wp_enqueue_style('prettyphoto-style', get_template_directory_uri() . '/css/prettyPhoto.css', null, null);
}
add_action('wp_enqueue_scripts', 'mpt_register_style');
// register JS
function mpt_register_js(){
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'));
wp_enqueue_script('filterablejs', get_template_directory_uri() . '/js/filterable.js', array('jquery'));
wp_enqueue_script('prettyphotojs', get_template_directory_uri() . '/js/jquery.prettyPhoto.js', array('jquery'));
wp_enqueue_script('waypoints', get_template_directory_uri() . '/js/waypoints.min.js', array('jquery'));
}
add_action('wp_enqueue_scripts', 'mpt_register_js');
if ( class_exists( 'MarketPress' ) ) {
// register marketpress css
function mpt_enqueue_mp_css() {
wp_deregister_style('mp-store-theme');
wp_enqueue_style('mp-flexmarket-css', get_template_directory_uri() . '/css/mp.css', null, null);
}
add_action('wp_enqueue_scripts', 'mpt_enqueue_mp_css');
}
// register menu
if(function_exists('register_nav_menus')){
register_nav_menus(array(
'mainmenu' => 'Main Menu'
)
);
}
// add sidebar
if(function_exists('register_sidebar')){
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar',
'description' => 'Widgets in this area will be shown on the right-hand side.',
'before_widget' => '<div class="well well-small">',
'after_widget' => '</div>',
'before_title' => '<h4 class="page-header">',
'after_title' => '</h4>'
)
);
register_sidebar(array(
'name' => 'Footer One',
'id' => 'footer-one',
'description' => 'First Footer Widget',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4 class="page-header"><span>',
'after_title' => '</span></h4>'
)
);
register_sidebar(array(
'name' => 'Footer Two',
'id' => 'footer-two',
'description' => 'Second Footer Widget',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4 class="page-header"><span>',
'after_title' => '</span></h4>'
)
);
register_sidebar(array(
'name' => 'Footer Three',
'id' => 'footer-three',
'description' => 'Three Footer Widget',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4 class="page-header"><span>',
'after_title' => '</span></h4>'
)
);
}
// add post type support to page and post
add_action( 'init', 'add_extra_metabox' );
function add_extra_metabox() {
add_post_type_support( 'page', 'excerpt' );
add_post_type_support( 'page', 'thumbnail' );
add_post_type_support( 'post', 'excerpt');
add_post_type_support( 'post', 'custom-fields');
add_post_type_support( 'post', 'comments');
}
// add comment function to Product Page
if ( class_exists( 'MarketPress' ) ) {
add_action( 'init', 'allow_comments_marketpress' );
function allow_comments_marketpress() {
add_post_type_support( 'product', 'comments' );
}
}
// add thumbnail support to theme
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
// add additional image size
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'tb-360', 360, 270, true );
add_image_size( 'tb-860', 860, 300, true );
}
// set excerpt lenght to custom character length
function the_excerpt_max_charlength($charlength) {
$excerpt = get_the_excerpt();
$charlength++;
if ( mb_strlen( $excerpt ) > $charlength ) {
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
echo '[...]';
} else {
echo $excerpt;
}
}
// Initialize the metabox class.
add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
function cmb_initialize_cmb_meta_boxes() {
if ( ! class_exists( 'cmb_Meta_Box' ) )
require_once(get_template_directory() . '/functions/metabox/init.php');
}
// call for product listing functions
add_action('flexmarket_product_listing_page' , 'flexmarket_list_products' , 10 , 2);
add_action('flexmarket_category_page' , 'flexmarket_list_products' , 10 , 2);
add_action('flexmarket_tag_page' , 'flexmarket_list_products' , 10 , 2);
add_action('flexmarket_taxonomy_page' , 'flexmarket_list_products' , 10 , 2);
function flexmarket_list_products( $unique_id = '' , $context = '' ) {
$btnclass = mpt_load_mp_btn_color();
$iconclass = mpt_load_whiteicon_in_btn();
$tagcolor = mpt_load_icontag_color();
$span = mpt_load_product_listing_layout();
$counter = mpt_load_product_listing_counter();
$entries = get_option('mpt_mp_listing_entries');
$advancedsoft = mpt_enable_advanced_sort();
$advancedsoftbtnposition = mpt_advanced_sort_btn_position();
echo flexmarket_advance_product_sort( $unique_id , $advancedsoft , $advancedsoftbtnposition , $context , false , true , '' , $entries, '', '', '' , '' , $counter, $span, $btnclass, $iconclass, $tagcolor);
}
// MP Dynamic Grid Integration
if( class_exists('MPDG') ) {
// if 'enable dynamic grid' option is selected
if (get_option('mpt_mpdg_enable_dg') == 'true') {
// remove exisitng action hooks
remove_action('flexmarket_product_listing_page' , 'flexmarket_list_products' , 10 , 2);
remove_action('flexmarket_category_page' , 'flexmarket_list_products' , 10 , 2);
remove_action('flexmarket_tag_page' , 'flexmarket_list_products' , 10 , 2);
remove_action('flexmarket_taxonomy_page' , 'flexmarket_list_products' , 10 , 2);
// add mpdg action hooks
add_action('flexmarket_product_listing_page' , 'mpdg_list_products' , 11 , 2);
add_action('flexmarket_category_page' , 'mpdg_list_products' , 11 , 2);
add_action('flexmarket_tag_page' , 'mpdg_list_products' , 11 , 2);
add_action('flexmarket_taxonomy_page' , 'mpdg_list_products' , 11 , 2);
}
if (!function_exists('mpdg_list_products')) {
function mpdg_list_products( $unique_id = '' , $context = '' ) {
$column = get_option('mpt_mpdg_listing_layout');
$btncolor = get_option('mpt_mpdg_btn_color');
$tagcolor = get_option('mpt_mpdg_icon_tag_color');
$pricelabel = get_option('mpt_mpdg_price_tag_color');
$entries = get_option('mpt_mpdg_listing_entries');
$showcategory = ( $context == 'list' ? 'yes' : 'no');
switch ($column) {
case '2 Columns':
$span = 'span6';
break;
case '3 Columns':
$span = 'span4';
break;
case '4 Columns':
$span = 'span3';
break;
case '5 Columns':
$span = 'span2';
break;
default:
$span = 'span4';
break;
}
switch ($btncolor) {
case 'Grey':
$btnclass = '';
$iconclass = '';
break;
case 'Blue':
$btnclass = ' btn-primary';
$iconclass = ' icon-white';
break;
case 'Light Blue':
$btnclass = ' btn-info';
$iconclass = ' icon-white';
break;
case 'Green':
$btnclass = ' btn-success';
$iconclass = ' icon-white';
break;
case 'Yellow':
$btnclass = ' btn-warning';
$iconclass = ' icon-white';
break;
case 'Red':
$btnclass = ' btn-danger';
$iconclass = ' icon-white';
break;
case 'Black':
$btnclass = ' btn-inverse';
$iconclass = ' icon-white';
break;
default:
$btnclass = '';
$iconclass = '';
break;
}
switch ($tagcolor) {
case 'White':
$tagclass = ' icon-white';
break;
case 'Blue':
$tagclass = ' icon-blue';
break;
case 'Light Blue':
$tagclass = ' icon-lightblue';
break;
case 'Green':
$tagclass = ' icon-green';
break;
case 'Yellow':
$tagclass = ' icon-yellow';
break;
case 'Red':
$tagclass = ' icon-red';
break;
case 'Black':
$tagclass = '';
break;
default:
$tagclass = '';
break;
}
switch ($pricelabel) {
case 'Grey':
$labelclass = '';
break;
case 'Light Blue':
$labelclass = ' label-info';
break;
case 'Green':
$labelclass = ' label-success';
break;
case 'Yellow':
$labelclass = ' label-warning';
break;
case 'Red':
$labelclass = ' label-important';
break;
case 'Black':
$labelclass = ' label-inverse';
break;
default:
$labelclass = ' label-info';
break;
}
wp_enqueue_script('mpdg', MPDG_DIR . 'js/mpdg.js', array('jquery'));
add_action('wp_footer' , 'mpdg_add_js_to_footer');
echo mpdg_dynamic_grid(false , true , '', $entries , '' , '' , '' , '' , $showcategory , false , $span , 'full' , $btnclass, $iconclass, $tagclass, $labelclass );
}
}
}