This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplate-tags.php
executable file
·670 lines (565 loc) · 22.5 KB
/
template-tags.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<?php
/**
* Custom template tags for this theme.
*
* Eventually, some of the functionality here could be replaced by core features
*
* @package dokan
*/
if ( ! function_exists( 'dokan_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function dokan_content_nav( $nav_id, $query = null ) {
global $wp_query, $post;
if ( $query ) {
$wp_query = $query;
}
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( !$next && !$previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = 'site-navigation paging-navigation';
if ( is_single() )
$nav_class = 'site-navigation post-navigation';
?>
<nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>">
<ul class="pager">
<?php if ( is_single() ) : // navigation links for single posts ?>
<li class="previous">
<?php previous_post_link( '%link', _x( '←', 'Previous post link', 'dokan' ) . ' %title' ); ?>
</li>
<li class="next">
<?php next_post_link( '%link', '%title ' . _x( '→', 'Next post link', 'dokan' ) ); ?>
</li>
<?php endif; ?>
</ul>
<?php if ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php dokan_page_navi( '', '', $wp_query ); ?>
<?php endif; ?>
</nav><!-- #<?php echo $nav_id; ?> -->
<?php
}
endif;
if ( ! function_exists( 'dokan_page_navi' ) ) :
function dokan_page_navi( $before = '', $after = '', $wp_query ) {
$posts_per_page = intval( get_query_var( 'posts_per_page' ) );
$paged = intval( get_query_var( 'paged' ) );
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
if ( $numposts <= $posts_per_page ) {
return;
}
if ( empty( $paged ) || $paged == 0 ) {
$paged = 1;
}
$pages_to_show = 7;
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor( $pages_to_show_minus_1 / 2 );
$half_page_end = ceil( $pages_to_show_minus_1 / 2 );
$start_page = $paged - $half_page_start;
if ( $start_page <= 0 ) {
$start_page = 1;
}
$end_page = $paged + $half_page_end;
if ( ($end_page - $start_page) != $pages_to_show_minus_1 ) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if ( $end_page > $max_page ) {
$start_page = $max_page - $pages_to_show_minus_1;
$end_page = $max_page;
}
if ( $start_page <= 0 ) {
$start_page = 1;
}
echo $before . '<div class="dokan-pagination-container"><ul class="dokan-pagination">' . "";
if ( $paged > 1 ) {
$first_page_text = "«";
echo '<li class="prev"><a href="' . get_pagenum_link() . '" title="First">' . $first_page_text . '</a></li>';
}
$prevposts = get_previous_posts_link( '← Previous' );
if ( $prevposts ) {
echo '<li>' . $prevposts . '</li>';
} else {
echo '<li class="disabled"><a href="#">' . __( '← Previous', 'dokan' ) . '</a></li>';
}
for ($i = $start_page; $i <= $end_page; $i++) {
if ( $i == $paged ) {
echo '<li class="active"><a href="#">' . $i . '</a></li>';
} else {
echo '<li><a href="' . get_pagenum_link( $i ) . '">' . number_format_i18n( $i ) . '</a></li>';
}
}
echo '<li class="">';
next_posts_link( __('Next →', 'dokan') );
echo '</li>';
if ( $end_page < $max_page ) {
$last_page_text = "→";
echo '<li class="next"><a href="' . get_pagenum_link( $max_page ) . '" title="Last">' . $last_page_text . '</a></li>';
}
echo '</ul></div>' . $after . "";
}
endif;
function dokan_product_dashboard_errors() {
$type = isset( $_GET['message'] ) ? $_GET['message'] : '';
switch ($type) {
case 'product_deleted':
dokan_get_template_part( 'global/dokan-success', '', array( 'deleted' => true, 'message' => __( 'Product succesfully deleted', 'dokan' ) ) );
break;
case 'error':
dokan_get_template_part( 'global/dokan-error', '', array( 'deleted' => false, 'message' => __( 'Something went wrong!', 'dokan' ) ) );
break;
}
}
function dokan_product_listing_status_filter() {
$permalink = dokan_get_navigation_url( 'products' );
$status_class = isset( $_GET['post_status'] ) ? $_GET['post_status'] : 'all';
$post_counts = dokan_count_posts( 'product', get_current_user_id() );
dokan_get_template_part( 'products/listing-status-filter', '', array(
'permalink' => $permalink,
'status_class' => $status_class,
'post_counts' => $post_counts,
) );
}
function dokan_order_listing_status_filter() {
$orders_url = dokan_get_navigation_url( 'orders' );
$status_class = isset( $_GET['order_status'] ) ? $_GET['order_status'] : 'all';
$orders_counts = dokan_count_orders( get_current_user_id() );
$order_date = ( isset( $_GET['order_date'] ) ) ? $_GET['order_date'] : '';
$date_filter = array();
$all_order_url = array();
$complete_order_url = array();
$processing_order_url = array();
$pending_order_url = array();
$on_hold_order_url = array();
$canceled_order_url = array();
$refund_order_url = array();
?>
<ul class="list-inline order-statuses-filter">
<li<?php echo $status_class == 'all' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$all_order_url = array_merge( $date_filter, array( 'order_status' => 'all' ) );
?>
<a href="<?php echo ( empty( $all_order_url ) ) ? $orders_url : add_query_arg( $complete_order_url, $orders_url ); ?>">
<?php printf( __( 'All (%d)', 'dokan' ), $orders_counts->total ); ?></span>
</a>
</li>
<li<?php echo $status_class == 'wc-completed' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$complete_order_url = array_merge( array( 'order_status' => 'wc-completed' ), $date_filter );
?>
<a href="<?php echo add_query_arg( $complete_order_url, $orders_url ); ?>">
<?php printf( __( 'Completed (%d)', 'dokan' ), $orders_counts->{'wc-completed'} ); ?></span>
</a>
</li>
<li<?php echo $status_class == 'wc-processing' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$processing_order_url = array_merge( $date_filter, array( 'order_status' => 'wc-processing' ) );
?>
<a href="<?php echo add_query_arg( $processing_order_url, $orders_url ); ?>">
<?php printf( __( 'Processing (%d)', 'dokan' ), $orders_counts->{'wc-processing'} ); ?></span>
</a>
</li>
<li<?php echo $status_class == 'wc-on-hold' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$on_hold_order_url = array_merge( $date_filter, array( 'order_status' => 'wc-on-hold' ) );
?>
<a href="<?php echo add_query_arg( $on_hold_order_url, $orders_url ); ?>">
<?php printf( __( 'On-hold (%d)', 'dokan' ), $orders_counts->{'wc-on-hold'} ); ?></span>
</a>
</li>
<li<?php echo $status_class == 'wc-pending' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$pending_order_url = array_merge( $date_filter, array( 'order_status' => 'wc-pending' ) );
?>
<a href="<?php echo add_query_arg( $pending_order_url, $orders_url ); ?>">
<?php printf( __( 'Pending (%d)', 'dokan' ), $orders_counts->{'wc-pending'} ); ?></span>
</a>
</li>
<li<?php echo $status_class == 'wc-canceled' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$canceled_order_url = array_merge( $date_filter, array( 'order_status' => 'wc-cancelled' ) );
?>
<a href="<?php echo add_query_arg( $canceled_order_url, $orders_url ); ?>">
<?php printf( __( 'Cancelled (%d)', 'dokan' ), $orders_counts->{'wc-cancelled'} ); ?></span>
</a>
</li>
<li<?php echo $status_class == 'wc-refunded' ? ' class="active"' : ''; ?>>
<?php
if( $order_date ) {
$date_filter = array(
'order_date' => $order_date,
'dokan_order_filter' => 'Filter',
);
}
$refund_order_url = array_merge( $date_filter, array( 'order_status' => 'wc-refunded' ) );
?>
<a href="<?php echo add_query_arg( $refund_order_url, $orders_url ); ?>">
<?php printf( __( 'Refunded (%d)', 'dokan' ), $orders_counts->{'wc-refunded'} ); ?></span>
</a>
</li>
<?php do_action( 'dokan_status_listing_item', $orders_counts ); ?>
</ul>
<?php
}
function dokan_nav_sort_by_pos( $a, $b ) {
if ( isset( $a['pos'] ) && isset( $b['pos'] ) ) {
return $a['pos'] - $b['pos'];
} else {
return 199;
}
}
/**
* Dashboard Navigation menus
*
* @return array
*/
function dokan_get_dashboard_nav() {
$urls = array(
'dashboard' => array(
'title' => __( 'Dashboard', 'dokan'),
'icon' => '<i class="fa fa-tachometer"></i>',
'url' => dokan_get_navigation_url(),
'pos' => 10
),
'products' => array(
'title' => __( 'Products', 'dokan'),
'icon' => '<i class="fa fa-briefcase"></i>',
'url' => dokan_get_navigation_url( 'products' ),
'pos' => 30
),
'orders' => array(
'title' => __( 'Orders', 'dokan'),
'icon' => '<i class="fa fa-shopping-cart"></i>',
'url' => dokan_get_navigation_url( 'orders' ),
'pos' => 50
),
'withdraw' => array(
'title' => __( 'Withdraw', 'dokan'),
'icon' => '<i class="fa fa-upload"></i>',
'url' => dokan_get_navigation_url( 'withdraw' ),
'pos' => 70
),
);
$settings = array(
'title' => __( 'Settings <i class="fa fa-angle-right pull-right"></i>', 'dokan'),
'icon' => '<i class="fa fa-cog"></i>',
'url' => dokan_get_navigation_url( 'settings/store' ),
'pos' => 200,
);
$settings_sub = array(
'back' => array(
'title' => __( 'Back to Dashboard', 'dokan'),
'icon' => '<i class="fa fa-long-arrow-left"></i>',
'url' => dokan_get_navigation_url(),
'pos' => 10
),
'store' => array(
'title' => __( 'Store', 'dokan'),
'icon' => '<i class="fa fa-university"></i>',
'url' => dokan_get_navigation_url( 'settings/store' ),
'pos' => 30
),
'payment' => array(
'title' => __( 'Payment', 'dokan'),
'icon' => '<i class="fa fa-credit-card"></i>',
'url' => dokan_get_navigation_url( 'settings/payment' ),
'pos' => 50
)
);
/**
* Filter to get the seller dashboard settings navigation.
*
* @since 2.2
*
* @param array.
*/
$settings['sub'] = apply_filters( 'dokan_get_dashboard_settings_nav', $settings_sub );
uasort( $settings['sub'], 'dokan_nav_sort_by_pos' );
$urls['settings'] = $settings;
$nav_urls = apply_filters( 'dokan_get_dashboard_nav', $urls );
uasort( $nav_urls, 'dokan_nav_sort_by_pos' );
/**
* Filter to get the final seller dashboard navigation.
*
* @since 2.2
*
* @param array $urls.
*/
return $nav_urls;
}
/**
* Renders the Dokan dashboard menu
*
* For settings menu, the active menu format is `settings/menu_key_name`.
* The active menu will be splitted at `/` and the `menu_key_name` will be matched
* with settings sub menu array. If it's a match, the settings menu will be shown
* only. Otherwise the main navigation menu will be shown.
*
* @param string $active_menu
*
* @return string rendered menu HTML
*/
function dokan_dashboard_nav( $active_menu = '' ) {
$nav_menu = dokan_get_dashboard_nav();
$active_menu_parts = explode( '/', $active_menu );
if ( isset( $active_menu_parts[1] ) && $active_menu_parts[0] == 'settings' && array_key_exists( $active_menu_parts[1], $nav_menu['settings']['sub'] ) ) {
$urls = $nav_menu['settings']['sub'];
$active_menu = $active_menu_parts[1];
} else {
$urls = $nav_menu;
}
$menu = '<ul class="dokan-dashboard-menu">';
foreach ($urls as $key => $item) {
$class = ( $active_menu == $key ) ? 'active ' . $key : $key;
$menu .= sprintf( '<li class="%s"><a href="%s">%s %s</a></li>', $class, $item['url'], $item['icon'], $item['title'] );
}
$menu .= '</ul>';
return $menu;
}
if ( ! function_exists( 'dokan_store_category_menu' ) ) :
/**
* Store category menu for a store
*
* @param int $seller_id
* @return void
*/
function dokan_store_category_menu( $seller_id, $title = '' ) { ?>
<aside class="widget dokan-category-menu">
<h3 class="widget-title"><?php echo $title; ?></h3>
<div id="cat-drop-stack">
<?php
global $wpdb;
$categories = get_transient( 'dokan-store-category-'.$seller_id );
if ( false === $categories ) {
$sql = "SELECT t.term_id,t.name, tt.parent FROM $wpdb->terms as t
LEFT JOIN $wpdb->term_taxonomy as tt on t.term_id = tt.term_id
LEFT JOIN $wpdb->term_relationships AS tr on tt.term_taxonomy_id = tr.term_taxonomy_id
LEFT JOIN $wpdb->posts AS p on tr.object_id = p.ID
WHERE tt.taxonomy = 'product_cat'
AND p.post_type = 'product'
AND p.post_status = 'publish'
AND p.post_author = $seller_id GROUP BY t.term_id";
$categories = $wpdb->get_results( $sql );
set_transient( 'dokan-store-category-'.$seller_id , $categories );
}
$args = array(
'taxonomy' => 'product_cat',
'selected_cats' => ''
);
$walker = new Dokan_Store_Category_Walker( $seller_id );
echo "<ul>";
echo call_user_func_array( array(&$walker, 'walk'), array($categories, 0, array()) );
echo "</ul>";
?>
</div>
</aside>
<?php
}
endif;
/**
* Clear transient once a product is saved or deleted
*
* @param int $post_id
*
* @return void
*/
function dokan_store_category_delete_transient( $post_id ) {
$post_tmp = get_post( $post_id );
$seller_id = $post_tmp->post_author;
//delete store category transient
delete_transient( 'dokan-store-category-'.$seller_id );
}
add_action( 'delete_post', 'dokan_store_category_delete_transient' );
add_action( 'save_post', 'dokan_store_category_delete_transient' );
function dokan_seller_reg_form_fields() {
$postdata = $_POST;
$role = isset( $postdata['role'] ) ? $postdata['role'] : 'customer';
$role_style = ( $role == 'customer' ) ? ' style="display:none"' : '';
dokan_get_template_part( 'global/seller-registration-form', '', array(
'postdata' => $postdata,
'role' => $role,
'role_style' => $role_style
) );
}
add_action( 'register_form', 'dokan_seller_reg_form_fields' );
if ( !function_exists( 'dokan_seller_not_enabled_notice' ) ) :
function dokan_seller_not_enabled_notice() {
dokan_get_template_part( 'global/seller-warning' );
}
endif;
if ( !function_exists( 'dokan_header_user_menu' ) ) :
/**
* User top navigation menu
*
* @return void
*/
function dokan_header_user_menu() {
global $current_user;
$user_id = $current_user->ID;
$nav_urls = dokan_get_dashboard_nav();
dokan_get_template_part( 'global/header-menu', '', array( 'current_user' => $current_user, 'user_id' => $user_id, 'nav_urls' => $nav_urls ) );
}
endif;
add_action( 'template_redirect', 'dokan_myorder_login_check');
/**
* Redirect My order in Login page without user logged login
*
* @since 2.4
*
* @return [redirect]
*/
function dokan_myorder_login_check(){
global $post;
if ( !$post ) {
return;
}
if ( !isset( $post->ID ) ) {
return;
}
$my_order_page_id = dokan_get_option( 'my_orders', 'dokan_pages' );
if ( $my_order_page_id == $post->ID ) {
dokan_redirect_login();
}
}
//Render Store listing shortcode as it appears without logged in
add_shortcode( 'dokan-stores', 'store_listing' );
/**
* Displays the store lists
*
* @since 2.4
*
* @param array $atts
*
* @return string
*/
function store_listing( $atts ) {
global $post;
/**
* Filter return the number of store listing number per page.
*
* @since 2.2
*
* @param array
*/
$attr = shortcode_atts( apply_filters( 'dokan_store_listing_per_page', array(
'per_page' => 10,
) ), $atts );
$paged = max( 1, get_query_var( 'paged' ) );
$limit = $attr['per_page'];
$offset = ( $paged - 1 ) * $limit;
$sellers = dokan_get_sellers( $limit, $offset );
ob_start();
if ( $sellers['users'] ) {
?>
<ul class="dokan-seller-wrap">
<?php
foreach ( $sellers['users'] as $seller ) {
$store_info = dokan_get_store_info( $seller->ID );
$banner_id = isset( $store_info['banner'] ) ? $store_info['banner'] : 0;
$store_name = isset( $store_info['store_name'] ) ? esc_html( $store_info['store_name'] ) : __( 'N/A', 'dokan' );
$store_url = dokan_get_store_url( $seller->ID );
?>
<li class="dokan-single-seller">
<div class="dokan-store-thumbnail">
<a href="<?php echo $store_url; ?>">
<?php if ( $banner_id ) {
$banner_url = wp_get_attachment_image_src( $banner_id, 'medium' );
?>
<img class="dokan-store-img" src="<?php echo esc_url( $banner_url[0] ); ?>" alt="<?php echo esc_attr( $store_name ); ?>">
<?php } else { ?>
<img class="dokan-store-img" src="<?php echo dokan_get_no_seller_image(); ?>" alt="<?php _e( 'No Image', 'dokan' ); ?>">
<?php } ?>
</a>
<div class="dokan-store-caption">
<h3><a href="<?php echo $store_url; ?>"><?php echo $store_name; ?></a></h3>
<address>
<?php if ( isset( $store_info['address'] ) && !empty( $store_info['address'] ) ) {
echo dokan_get_seller_address( $seller->ID );
} ?>
<?php if ( isset( $store_info['phone'] ) && !empty( $store_info['phone'] ) ) { ?>
<br>
<abbr title="<?php _e( 'Phone Number', 'dokan' ); ?>"><?php _e( 'P:', 'dokan' ); ?></abbr> <?php echo esc_html( $store_info['phone'] ); ?>
<?php } ?>
</address>
<p><a class="dokan-btn dokan-btn-theme" href="<?php echo $store_url; ?>"><?php _e( 'Visit Store', 'dokan' ); ?></a></p>
</div> <!-- .caption -->
</div> <!-- .thumbnail -->
</li> <!-- .single-seller -->
<?php } ?>
</ul> <!-- .dokan-seller-wrap -->
<?php
$user_count = $sellers['count'];
$num_of_pages = ceil( $user_count / $limit );
if ( $num_of_pages > 1 ) {
echo '<div class="pagination-container clearfix">';
$page_links = paginate_links( array(
'current' => $paged,
'total' => $num_of_pages,
'base' => str_replace( $post->ID, '%#%', esc_url( get_pagenum_link( $post->ID ) ) ),
'type' => 'array',
'prev_text' => __( '← Previous', 'dokan' ),
'next_text' => __( 'Next →', 'dokan' ),
) );
if ( $page_links ) {
$pagination_links = '<div class="pagination-wrap">';
$pagination_links .= '<ul class="pagination"><li>';
$pagination_links .= join( "</li>\n\t<li>", $page_links );
$pagination_links .= "</li>\n</ul>\n";
$pagination_links .= '</div>';
echo $pagination_links;
}
echo '</div>';
}
?>
<?php
} else {
?>
<p class="dokan-error"><?php _e( 'No seller found!', 'dokan' ); ?></p>
<?php
}
$content = ob_get_clean();
return apply_filters( 'dokan_seller_listing', $content, $attr );
}