1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* LSX Sensei Class |
4
|
|
|
* |
5
|
|
|
* @package lsx |
6
|
|
|
* @subpackage sensei |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
if ( ! class_exists( 'LSX_Sensei' ) ) : |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The LSX Sensei integration class |
17
|
|
|
*/ |
18
|
|
|
class LSX_Sensei { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Holds the LSX_Sensei_Course() variable. |
22
|
|
|
* |
23
|
|
|
* @var LSX_Sensei_Course() |
24
|
|
|
*/ |
25
|
|
|
public $lsx_sensei_course = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Setup class. |
29
|
|
|
* |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
|
|
public function __construct() { |
33
|
|
|
|
34
|
|
|
$this->lsx_sensei_course = require_once get_stylesheet_directory() . '/includes/sensei/class-lsx-sensei-course.php'; |
35
|
|
|
|
36
|
|
|
global $woothemes_sensei; |
37
|
|
|
|
38
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'lsx_sensei_scripts_add_styles' ) ); |
39
|
|
|
|
40
|
|
|
remove_action( 'sensei_before_main_content', array( $woothemes_sensei->frontend, 'sensei_output_content_wrapper' ), 10 ); |
41
|
|
|
add_action( 'sensei_before_main_content', array( $this, 'lsx_sensei_theme_wrapper_start' ) ); |
42
|
|
|
|
43
|
|
|
remove_action( 'sensei_after_main_content', array( $woothemes_sensei->frontend, 'sensei_output_content_wrapper_end' ), 10 ); |
44
|
|
|
add_action( 'sensei_after_main_content', array( $this, 'lsx_sensei_theme_wrapper_end' ) ); |
45
|
|
|
|
46
|
|
|
add_filter( 'get_the_archive_title', array( $this, 'lsx_sensei_modify_archive_title' ), 99, 1 ); |
47
|
|
|
|
48
|
|
|
// LSX |
49
|
|
|
add_filter( 'lsx_global_header_disable', array( $this, 'lsx_sensei_disable_lsx_banner' ) ); |
50
|
|
|
// LSX Banners - Plugin, Placeholders |
51
|
|
|
add_filter( 'lsx_banner_plugin_disable', array( $this, 'lsx_sensei_disable_lsx_banner' ) ); |
52
|
|
|
// LSX Banners - Banner |
53
|
|
|
add_filter( 'lsx_banner_disable', array( $this, 'lsx_sensei_disable_lsx_banner' ) ); |
54
|
|
|
|
55
|
|
|
add_filter( 'course_archive_title', array( $this, 'lsx_sensei_archive_title' ), 10, 1 ); |
56
|
|
|
add_filter( 'sensei_lesson_archive_title', array( $this, 'lsx_sensei_archive_title' ), 10, 1 ); |
57
|
|
|
|
58
|
|
|
add_filter( 'course_category_title', array( $this, 'lsx_sensei_category_title' ), 10, 1 ); |
59
|
|
|
|
60
|
|
|
add_action( 'sensei_course_content_inside_after', array( $this, 'lsx_sensei_add_buttons' ), 9 ); |
61
|
|
|
|
62
|
|
|
add_filter( 'sensei_wc_single_add_to_cart_button_text', array( $this, 'lsx_sensei_add_to_cart_text' ) ); |
63
|
|
|
|
64
|
|
|
add_action( 'lsx_content_wrap_before', array( $this, 'lsx_sensei_results_header' ) ); |
65
|
|
|
|
66
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_course_breadcrumb_filter' ), 40, 1 ); |
67
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_course_breadcrumb_filter' ), 40, 1 ); |
68
|
|
|
|
69
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_lesson_breadcrumb_filter' ), 40, 1 ); |
70
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_lesson_breadcrumb_filter' ), 40, 1 ); |
71
|
|
|
|
72
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_module_breadcrumb_filter' ), 40, 1 ); |
73
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_module_breadcrumb_filter' ), 40, 1 ); |
74
|
|
|
|
75
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_learner_breadcrumb_filter' ), 40, 1 ); |
76
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_learner_breadcrumb_filter' ), 40, 1 ); |
77
|
|
|
|
78
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_quiz_breadcrumb_filter' ), 40, 1 ); |
79
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_quiz_breadcrumb_filter' ), 40, 1 ); |
80
|
|
|
|
81
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_messages_breadcrumb_filter' ), 40, 1 ); |
82
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_messages_breadcrumb_filter' ), 40, 1 ); |
83
|
|
|
|
84
|
|
|
add_filter( 'wpseo_breadcrumb_links', array( $this, 'lsx_sensei_results_breadcrumb_filter' ), 40, 1 ); |
85
|
|
|
add_filter( 'woocommerce_get_breadcrumb', array( $this, 'lsx_sensei_results_breadcrumb_filter' ), 40, 1 ); |
86
|
|
|
|
87
|
|
|
add_action( 'sensei_archive_before_message_loop', array( $this, 'lsx_sensei_back_message_button' ) ); |
88
|
|
|
add_action( 'sensei_content_message_after', array( $this, 'lsx_sensei_view_message_button' ) ); |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Sensei enqueue styles. |
94
|
|
|
* |
95
|
|
|
* @package lsx |
96
|
|
|
* @subpackage sensei |
97
|
|
|
*/ |
98
|
|
|
public function lsx_sensei_scripts_add_styles() { |
99
|
|
|
wp_enqueue_style( 'sensei-lsx', get_template_directory_uri() . '/assets/css/sensei/sensei.css', array( 'lsx_main' ), LSX_VERSION ); |
100
|
|
|
wp_style_add_data( 'sensei-lsx', 'rtl', 'replace' ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sensei wrapper start. |
105
|
|
|
* |
106
|
|
|
* @package lsx |
107
|
|
|
* @subpackage sensei |
108
|
|
|
*/ |
109
|
|
View Code Duplication |
public function lsx_sensei_theme_wrapper_start() { |
|
|
|
|
110
|
|
|
lsx_content_wrap_before(); |
111
|
|
|
echo '<div id="primary" class="content-area ' . esc_attr( lsx_main_class() ) . '">'; |
112
|
|
|
lsx_content_before(); |
113
|
|
|
echo '<main id="main" class="site-main" role="main">'; |
114
|
|
|
lsx_content_top(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Sensei wrapper end. |
119
|
|
|
* |
120
|
|
|
* @package lsx |
121
|
|
|
* @subpackage sensei |
122
|
|
|
*/ |
123
|
|
|
public function lsx_sensei_theme_wrapper_end() { |
124
|
|
|
lsx_content_bottom(); |
125
|
|
|
echo '</main>'; |
126
|
|
|
lsx_content_after(); |
127
|
|
|
echo '</div>'; |
128
|
|
|
lsx_content_wrap_after(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Remove "Archives:" from the courses archive title. |
133
|
|
|
* |
134
|
|
|
* @param [type] $title |
|
|
|
|
135
|
|
|
* @return void |
136
|
|
|
*/ |
137
|
|
|
public function lsx_sensei_modify_archive_title( $title ) { |
138
|
|
|
if ( is_archive() && is_post_type_archive( 'course' ) ) { |
139
|
|
|
$title = __( 'Courses', 'lsx' ); |
140
|
|
|
} |
141
|
|
|
if ( is_archive() && is_post_type_archive( 'sensei_message' ) ) { |
142
|
|
|
$title = __( 'Messages', 'lsx' ); |
143
|
|
|
} |
144
|
|
|
if ( is_archive() && is_post_type_archive( 'lesson' ) ) { |
145
|
|
|
$title = __( 'Lessons', 'lsx' ); |
146
|
|
|
} |
147
|
|
|
if ( is_archive() && is_tax() ) { |
148
|
|
|
$title = single_term_title( '', false ); |
149
|
|
|
} |
150
|
|
|
return $title; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Disable LSX Banners in some Sensei pages. |
155
|
|
|
* |
156
|
|
|
* @package lsx |
157
|
|
|
* @subpackage sensei |
158
|
|
|
*/ |
159
|
|
|
public function lsx_sensei_disable_lsx_banner( $disabled ) { |
160
|
|
|
if ( is_sensei() ) { |
161
|
|
|
$disabled = true; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $disabled; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Filters the archive title. |
169
|
|
|
* |
170
|
|
|
* @package lsx |
171
|
|
|
* @subpackage sensei |
172
|
|
|
*/ |
173
|
|
|
public function lsx_sensei_archive_title( $html ) { |
174
|
|
|
$html = preg_replace( '/<header class="archive-header"><h1>([^<]+)<\/h1><\/header>/i', '<h1>$1</h1>', $html ); |
175
|
|
|
return $html; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Filters the archive title. |
180
|
|
|
* |
181
|
|
|
* @package lsx |
182
|
|
|
* @subpackage sensei |
183
|
|
|
*/ |
184
|
|
|
public function lsx_sensei_category_title( $html ) { |
185
|
|
|
$html = str_replace( 'h2', 'h1', $html ); |
186
|
|
|
return $html; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Add extra buttons to the single view on lists. |
191
|
|
|
* |
192
|
|
|
* @package lsx |
193
|
|
|
* @subpackage sensei |
194
|
|
|
*/ |
195
|
|
|
public function lsx_sensei_add_buttons( $course_id ) { |
|
|
|
|
196
|
|
|
global $post, $current_user; |
197
|
|
|
$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
198
|
|
|
$course_purchasable = Sensei_WC::is_course_purchasable( $post->ID ); |
199
|
|
|
|
200
|
|
|
?> |
201
|
|
|
<section class="entry-actions"> |
202
|
|
|
<a class="button" href="<?php echo esc_url( tribe_get_event_link() ); ?>"><?php esc_html_e( 'View course', 'lsx' ); ?></a> |
203
|
|
|
|
204
|
|
|
<?php |
205
|
|
|
if ( ( ! $is_user_taking_course ) && $course_purchasable ) { |
206
|
|
|
Sensei_WC::the_add_to_cart_button_html( $post->ID ); |
207
|
|
|
} |
208
|
|
|
?> |
209
|
|
|
</section> |
210
|
|
|
<?php |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Change add to cart button text. |
215
|
|
|
* |
216
|
|
|
* @package lsx |
217
|
|
|
* @subpackage sensei |
218
|
|
|
*/ |
219
|
|
|
public function lsx_sensei_add_to_cart_text( $text ) { |
|
|
|
|
220
|
|
|
$text = esc_html__( 'Add to cart', 'lsx' ); |
221
|
|
|
return $text; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Displays the Results header. |
226
|
|
|
* |
227
|
|
|
* @package lsx |
228
|
|
|
* @subpackage layout |
229
|
|
|
*/ |
230
|
|
|
public function lsx_sensei_results_header( $user ) { |
|
|
|
|
231
|
|
|
|
232
|
|
|
$default_size = 'sm'; |
233
|
|
|
$size = apply_filters( 'lsx_bootstrap_column_size', $default_size ); |
234
|
|
|
global $wp_query; |
235
|
|
|
if ( isset( $wp_query->query_vars['course_results'] ) ) { |
236
|
|
|
$is_results = $wp_query->query_vars['course_results']; |
237
|
|
|
} else { |
238
|
|
|
$is_results = false; |
239
|
|
|
} |
240
|
|
View Code Duplication |
if ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
|
|
|
241
|
|
|
$is_profile = $wp_query->query_vars['learner_profile']; |
242
|
|
|
} else { |
243
|
|
|
$is_profile = false; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
if ( is_sticky() && $is_results ) : |
247
|
|
|
$course_for_results = get_page_by_path( $is_results, OBJECT, 'course' ); |
248
|
|
|
|
249
|
|
|
$course_title = esc_html( $course_for_results->post_title ); |
250
|
|
|
?> |
251
|
|
|
<div class="archive-header-wrapper banner-single col-<?php echo esc_attr( $size ); ?>-12"> |
252
|
|
|
<?php lsx_global_header_inner_bottom(); ?> |
253
|
|
|
<header class="archive-header"> |
254
|
|
|
<h1 class="archive-title"><?php echo wp_kses_post( $course_title ); ?></h1> |
255
|
|
|
</header> |
256
|
|
|
|
257
|
|
|
</div> |
258
|
|
|
<?php |
259
|
|
|
endif; |
260
|
|
|
|
261
|
|
|
if ( is_sticky() && $is_profile ) : |
262
|
|
|
$query_var = $wp_query->query_vars['learner_profile']; |
263
|
|
|
$learner_user = Sensei_Learner::find_by_query_var( $query_var ); |
264
|
|
|
$learner_name = $learner_user->display_name; |
265
|
|
|
?> |
266
|
|
|
<div class="archive-header-wrapper banner-single col-<?php echo esc_attr( $size ); ?>-12"> |
267
|
|
|
<?php lsx_global_header_inner_bottom(); ?> |
268
|
|
|
<header class="archive-header"> |
269
|
|
|
<h1 class="archive-title"><?php echo esc_html( $learner_name ); ?></h1> |
270
|
|
|
</header> |
271
|
|
|
|
272
|
|
|
</div> |
273
|
|
|
<?php |
274
|
|
|
endif; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Add the Parent Course link to the course breadcrumbs |
279
|
|
|
* @param $crumbs |
280
|
|
|
* @return array |
281
|
|
|
*/ |
282
|
|
|
public function lsx_sensei_course_breadcrumb_filter( $crumbs, $id = 0 ) { |
|
|
|
|
283
|
|
|
if ( is_single() && ( is_singular( 'course' ) ) ) { |
284
|
|
|
global $course; |
285
|
|
|
$lesson = get_the_title(); |
286
|
|
|
$course_page_url = intval( Sensei()->settings->settings['course_page'] ); |
287
|
|
|
$course_page_url = get_permalink( $course_page_url ); |
288
|
|
|
|
289
|
|
|
if ( $lesson ) { |
290
|
|
|
|
291
|
|
|
$new_crumbs = array(); |
292
|
|
|
$new_crumbs[0] = $crumbs[0]; |
293
|
|
|
|
294
|
|
View Code Duplication |
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
|
|
|
295
|
|
|
$new_crumbs[1] = array( |
296
|
|
|
0 => __( 'All Courses', 'lsx' ), |
297
|
|
|
1 => $course_page_url, |
298
|
|
|
); |
299
|
|
|
$new_crumbs[2] = array( |
300
|
|
|
0 => $lesson, |
301
|
|
|
); |
302
|
|
|
} else { |
303
|
|
|
$new_crumbs[1] = array( |
304
|
|
|
'text' => __( 'All Courses', 'lsx' ), |
305
|
|
|
'url' => $course_page_url, |
306
|
|
|
); |
307
|
|
|
$new_crumbs[2] = array( |
308
|
|
|
'text' => $lesson, |
309
|
|
|
); |
310
|
|
|
} |
311
|
|
|
$crumbs = $new_crumbs; |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
return $crumbs; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Add the Parent Course link to the lessons breadcrumbs |
319
|
|
|
* @param $crumbs |
320
|
|
|
* @return array |
321
|
|
|
*/ |
322
|
|
View Code Duplication |
public function lsx_sensei_lesson_breadcrumb_filter( $crumbs, $id = 0 ) { |
|
|
|
|
323
|
|
|
if ( is_single() && ( is_singular( 'lesson' ) ) ) { |
324
|
|
|
global $course; |
325
|
|
|
$lesson = get_the_title(); |
326
|
|
|
$course_page_url = intval( Sensei()->settings->settings['course_page'] ); |
327
|
|
|
$course_page_url = get_permalink( $course_page_url ); |
328
|
|
|
|
329
|
|
|
if ( empty( $id ) ) { |
330
|
|
|
$id = get_the_ID(); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
if ( 0 < intval( $id ) ) { |
334
|
|
|
$course = intval( get_post_meta( $id, '_lesson_course', true ) ); |
335
|
|
|
$course_id = esc_url( get_permalink( $course ) ); |
336
|
|
|
$course_title = esc_html( get_the_title( $course ) ); |
337
|
|
|
if ( ! $course ) { |
338
|
|
|
return; |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
if ( $course_id ) { |
343
|
|
|
|
344
|
|
|
$new_crumbs = array(); |
345
|
|
|
$new_crumbs[0] = $crumbs[0]; |
346
|
|
|
|
347
|
|
|
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
348
|
|
|
$new_crumbs[1] = array( |
349
|
|
|
0 => __( 'Courses', 'lsx' ), |
350
|
|
|
1 => $course_page_url, |
351
|
|
|
); |
352
|
|
|
$new_crumbs[2] = array( |
353
|
|
|
0 => $course_title, |
|
|
|
|
354
|
|
|
1 => $course_id, |
|
|
|
|
355
|
|
|
); |
356
|
|
|
$new_crumbs[3] = array( |
357
|
|
|
0 => $lesson, |
358
|
|
|
); |
359
|
|
|
} else { |
360
|
|
|
$new_crumbs[1] = array( |
361
|
|
|
'text' => __( 'Courses', 'lsx' ), |
362
|
|
|
'url' => $course_page_url, |
363
|
|
|
); |
364
|
|
|
$new_crumbs[2] = array( |
365
|
|
|
'text' => $course_title, |
366
|
|
|
'url' => $course_id, |
367
|
|
|
); |
368
|
|
|
$new_crumbs[3] = array( |
369
|
|
|
'text' => $lesson, |
370
|
|
|
); |
371
|
|
|
} |
372
|
|
|
$crumbs = $new_crumbs; |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
return $crumbs; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Add the Parent Course link to the module breadcrumbs |
380
|
|
|
* @param $crumbs |
381
|
|
|
* @return array |
382
|
|
|
*/ |
383
|
|
|
public function lsx_sensei_module_breadcrumb_filter( $crumbs, $id = 0 ) { |
384
|
|
|
$title = apply_filters( 'sensei_module_archive_title', get_queried_object()->name ); |
385
|
|
|
|
386
|
|
|
if ( is_tax() && is_archive() && ( ! empty( $title ) ) ) { |
387
|
|
|
|
388
|
|
|
$lesson = get_the_archive_title(); |
389
|
|
|
$course_page_url = intval( Sensei()->settings->settings['course_page'] ); |
390
|
|
|
$course_page_url = get_permalink( $course_page_url ); |
391
|
|
|
|
392
|
|
|
if ( empty( $id ) ) { |
393
|
|
|
$id = get_the_ID(); |
|
|
|
|
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$new_crumbs = array(); |
397
|
|
|
$new_crumbs[0] = $crumbs[0]; |
398
|
|
|
|
399
|
|
View Code Duplication |
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
|
|
|
400
|
|
|
$new_crumbs[1] = array( |
401
|
|
|
0 => __( 'Courses', 'lsx' ), |
402
|
|
|
1 => $course_page_url, |
403
|
|
|
); |
404
|
|
|
$new_crumbs[2] = array( |
405
|
|
|
0 => $lesson, |
406
|
|
|
); |
407
|
|
|
} else { |
408
|
|
|
$new_crumbs[1] = array( |
409
|
|
|
'text' => __( 'Courses', 'lsx' ), |
410
|
|
|
'url' => $course_page_url, |
411
|
|
|
); |
412
|
|
|
$new_crumbs[2] = array( |
413
|
|
|
'text' => $lesson, |
414
|
|
|
); |
415
|
|
|
} |
416
|
|
|
$crumbs = $new_crumbs; |
417
|
|
|
} |
418
|
|
|
return $crumbs; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Add the Parent Course link to the Learner breadcrumbs |
423
|
|
|
* @param $crumbs |
424
|
|
|
* @return array |
425
|
|
|
*/ |
426
|
|
|
public function lsx_sensei_learner_breadcrumb_filter( $crumbs, $id = 0 ) { |
427
|
|
|
global $wp_query; |
428
|
|
|
|
429
|
|
View Code Duplication |
if ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
|
|
|
430
|
|
|
$is_profile = $wp_query->query_vars['learner_profile']; |
431
|
|
|
} else { |
432
|
|
|
$is_profile = false; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
if ( is_sticky() && $is_profile ) { |
436
|
|
|
|
437
|
|
|
if ( empty( $id ) ) { |
438
|
|
|
$id = get_the_ID(); |
|
|
|
|
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
$query_var = $wp_query->query_vars['learner_profile']; |
442
|
|
|
$learner_user = Sensei_Learner::find_by_query_var( $query_var ); |
443
|
|
|
$learner_name = $learner_user->display_name; |
444
|
|
|
|
445
|
|
|
$new_crumbs = array(); |
446
|
|
|
$new_crumbs[0] = $crumbs[0]; |
447
|
|
|
|
448
|
|
|
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
449
|
|
|
$new_crumbs[1] = array( |
450
|
|
|
0 => __( 'Learners', 'lsx' ), |
451
|
|
|
); |
452
|
|
|
$new_crumbs[2] = array( |
453
|
|
|
0 => $learner_name, |
454
|
|
|
); |
455
|
|
|
} else { |
456
|
|
|
$new_crumbs[1] = array( |
457
|
|
|
'text' => __( 'Learners', 'lsx' ), |
458
|
|
|
); |
459
|
|
|
$new_crumbs[2] = array( |
460
|
|
|
'text' => $learner_name, |
461
|
|
|
); |
462
|
|
|
} |
463
|
|
|
$crumbs = $new_crumbs; |
464
|
|
|
} |
465
|
|
|
return $crumbs; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Add the Parent Course link to the messages breadcrumbs |
470
|
|
|
* @param $crumbs |
471
|
|
|
* @return array |
472
|
|
|
*/ |
473
|
|
|
public function lsx_sensei_messages_breadcrumb_filter( $crumbs, $id = 0 ) { |
474
|
|
|
if ( is_archive() && ( is_post_type_archive( 'sensei_message' ) ) ) { |
475
|
|
|
|
476
|
|
|
$course_page_url = intval( Sensei()->settings->settings['course_page'] ); |
477
|
|
|
$course_page_url = get_permalink( $course_page_url ); |
478
|
|
|
|
479
|
|
|
if ( empty( $id ) ) { |
480
|
|
|
$id = get_the_ID(); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
if ( $id ) { |
484
|
|
|
|
485
|
|
|
$new_crumbs = array(); |
486
|
|
|
$new_crumbs[0] = $crumbs[0]; |
487
|
|
|
|
488
|
|
|
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
489
|
|
|
$new_crumbs[1] = array( |
490
|
|
|
0 => __( 'Courses', 'lsx' ), |
491
|
|
|
1 => $course_page_url, |
492
|
|
|
); |
493
|
|
|
$new_crumbs[2] = array( |
494
|
|
|
0 => __( 'Messages', 'lsx' ), |
495
|
|
|
); |
496
|
|
|
} else { |
497
|
|
|
$new_crumbs[1] = array( |
498
|
|
|
'text' => __( 'Courses', 'lsx' ), |
499
|
|
|
'url' => $course_page_url, |
500
|
|
|
); |
501
|
|
|
$new_crumbs[2] = array( |
502
|
|
|
'text' => __( 'Messages', 'lsx' ), |
503
|
|
|
); |
504
|
|
|
} |
505
|
|
|
$crumbs = $new_crumbs; |
506
|
|
|
} |
507
|
|
|
} |
508
|
|
|
return $crumbs; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Add the Parent Course link to the quiz breadcrumbs |
513
|
|
|
* @param $crumbs |
514
|
|
|
* @return array |
515
|
|
|
*/ |
516
|
|
View Code Duplication |
public function lsx_sensei_quiz_breadcrumb_filter( $crumbs, $id = 0 ) { |
|
|
|
|
517
|
|
|
if ( ( is_single() && ( is_singular( 'quiz' ) ) ) ) { |
518
|
|
|
global $course; |
519
|
|
|
$course_page_url = intval( Sensei()->settings->settings['course_page'] ); |
520
|
|
|
$course_page_url = get_permalink( $course_page_url ); |
521
|
|
|
$lesson = get_the_title(); |
522
|
|
|
|
523
|
|
|
if ( empty( $id ) ) { |
524
|
|
|
$id = get_the_ID(); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
if ( 0 < intval( $id ) ) { |
528
|
|
|
|
529
|
|
|
$course = intval( get_post_meta( $id, '_quiz_lesson', true ) ); |
530
|
|
|
$course_id = esc_url( get_permalink( $course ) ); |
531
|
|
|
$course_title = esc_html( get_the_title( $course ) ); |
532
|
|
|
if ( ! $course ) { |
533
|
|
|
return; |
534
|
|
|
} |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
if ( $course_id ) { |
538
|
|
|
|
539
|
|
|
$new_crumbs = array(); |
540
|
|
|
$new_crumbs[0] = $crumbs[0]; |
541
|
|
|
|
542
|
|
|
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
543
|
|
|
$new_crumbs[1] = array( |
544
|
|
|
0 => __( 'Courses', 'lsx' ), |
545
|
|
|
1 => $course_page_url, |
546
|
|
|
); |
547
|
|
|
$new_crumbs[2] = array( |
548
|
|
|
0 => $course_title, |
|
|
|
|
549
|
|
|
1 => $course_id, |
|
|
|
|
550
|
|
|
); |
551
|
|
|
$new_crumbs[3] = array( |
552
|
|
|
0 => $lesson, |
553
|
|
|
); |
554
|
|
|
} else { |
555
|
|
|
$new_crumbs[1] = array( |
556
|
|
|
'text' => __( 'Courses', 'lsx' ), |
557
|
|
|
'url' => $course_page_url, |
558
|
|
|
); |
559
|
|
|
$new_crumbs[2] = array( |
560
|
|
|
'text' => $course_title, |
561
|
|
|
'url' => $course_id, |
562
|
|
|
); |
563
|
|
|
$new_crumbs[3] = array( |
564
|
|
|
'text' => $lesson, |
565
|
|
|
); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
$crumbs = $new_crumbs; |
569
|
|
|
} |
570
|
|
|
} |
571
|
|
|
return $crumbs; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* Add the Parent Course link to the results breadcrumbs |
576
|
|
|
* @param $crumbs |
577
|
|
|
* @return array |
578
|
|
|
*/ |
579
|
|
|
public function lsx_sensei_results_breadcrumb_filter( $crumbs, $id = 0 ) { |
580
|
|
|
if ( is_sticky() ) { |
581
|
|
|
global $wp_query; |
582
|
|
|
$course_id = ''; |
583
|
|
|
if ( isset( $wp_query->query_vars['course_results'] ) ) { |
584
|
|
|
$is_results = $wp_query->query_vars['course_results']; |
585
|
|
|
} |
586
|
|
|
$course_page_url = intval( Sensei()->settings->settings['course_page'] ); |
587
|
|
|
$course_page_url = get_permalink( $course_page_url ); |
588
|
|
|
|
589
|
|
|
if ( empty( $id ) ) { |
590
|
|
|
$id = get_the_ID(); |
|
|
|
|
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
if ( isset( $is_results ) ) { |
594
|
|
|
$course_for_results = get_page_by_path( $is_results, OBJECT, 'course' ); |
595
|
|
|
|
596
|
|
|
$course_id = esc_url( get_permalink( $course_for_results ) ); |
597
|
|
|
$course_title = esc_html( $course_for_results->post_title ); |
598
|
|
|
|
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
if ( $course_id ) { |
602
|
|
|
$new_crumbs = array(); |
603
|
|
|
$new_crumbs[0] = $crumbs[0]; |
604
|
|
|
|
605
|
|
|
if ( $is_results ) { |
|
|
|
|
606
|
|
|
if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
607
|
|
|
$new_crumbs[1] = array( |
608
|
|
|
0 => __( 'Courses', 'lsx' ), |
609
|
|
|
1 => $course_page_url, |
610
|
|
|
); |
611
|
|
|
$new_crumbs[2] = array( |
612
|
|
|
0 => $course_title, |
|
|
|
|
613
|
|
|
1 => $course_id, |
614
|
|
|
); |
615
|
|
|
$new_crumbs[3] = array( |
616
|
|
|
0 => __( 'Results', 'lsx' ), |
617
|
|
|
); |
618
|
|
|
} else { |
619
|
|
|
$new_crumbs[1] = array( |
620
|
|
|
'text' => __( 'Courses', 'lsx' ), |
621
|
|
|
'url' => $course_page_url, |
622
|
|
|
); |
623
|
|
|
$new_crumbs[2] = array( |
624
|
|
|
'text' => __( 'Results', 'lsx' ), |
625
|
|
|
); |
626
|
|
|
} |
627
|
|
|
} |
628
|
|
|
$crumbs = $new_crumbs; |
629
|
|
|
} |
630
|
|
|
} |
631
|
|
|
return $crumbs; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
/** |
635
|
|
|
* Show the 'View Message' button on messages. |
636
|
|
|
* |
637
|
|
|
* @param [type] $message_post_id |
|
|
|
|
638
|
|
|
* @return void |
639
|
|
|
*/ |
640
|
|
|
public function lsx_sensei_view_message_button( $message_post_id ) { |
641
|
|
|
$message_link = get_the_permalink( $message_post_id ); |
642
|
|
|
echo '<a href="' . esc_url_raw( $message_link ) . '" class="btn view-msg-btn">' . wp_kses_post( 'View Message', 'lsx' ) . '</a>'; |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* Show the 'Back to My Courses' button on messages. |
647
|
|
|
* |
648
|
|
|
* @param [type] $message_post_id |
|
|
|
|
649
|
|
|
* @return void |
650
|
|
|
*/ |
651
|
|
|
public function lsx_sensei_back_message_button( $courses_link ) { |
|
|
|
|
652
|
|
|
$courses_link = '/my-courses/'; |
653
|
|
|
echo '<a href="' . esc_url_raw( $courses_link ) . '" class="btn border-btn my-courses-btn">' . wp_kses_post( 'My Courses', 'lsx' ) . '</a>'; |
654
|
|
|
} |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
endif; |
658
|
|
|
|
659
|
|
|
return new LSX_Sensei(); |
660
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.