learn.php
4.57 KB
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
<?php
add_shortcode( 'breadcrumbs', 'the_bread' );
function the_bread() {
if(!is_admin()){
$ingredients = array(
'separator' => ' | ',
'offset' => -3,
'length' => 3,
);
ob_start();
$flour = $_SERVER['REQUEST_URI'];
if ( str_contains( $flour, '?' ) )
$flour = substr( $flour, 0, strpos( $flour, '?' ) );
$flour = ( str_ends_with( $flour, '/' ) ? explode( '/', substr( $flour, 1, -1 ) ) : explode( '/', substr( $flour, 1 ) ) );
$crumbs = [];
foreach ( $flour as $crumb ) {
$slug = esc_html( $crumb );
$url = esc_url( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . '/' . substr( implode( '/', $flour ), 0, strpos( implode( '/', $flour ), $crumb ) ) . $crumb. '/' );
if($crumb == 'courses'){
continue;
}
array_push( $crumbs, ( object )
[
'slug' => $slug,
'url' => $url,
]
);
};
$offset = ( empty( $ingredients['offset'] ) ? 0 : $ingredients['offset'] );
$length = ( empty( $ingredients['length'] ) ? null : $ingredients['length'] );
$crumbs = array_slice( $crumbs, $offset, $length );
echo '<ul class="bread">';
$i = 0;
if ( is_singular( 'sfwd-courses' ) ) {
echo '<li class="crumb" itemprop="itemListElement">
<a class="item" itemprop="item" href="'.site_url().'/learning-opportunities/">
<span itemprop="name">Programs</span>
</a>
<meta itemprop="position" content="1">
</li> |';
}
foreach ( $crumbs as $crumb ) {
$i++;
echo '<li class="crumb" itemprop="itemListElement">
<a class="item" itemprop="item" href="' . $crumb->url . '">
<span itemprop="name">' . ( url_to_postid( $crumb->url ) ? get_the_title( url_to_postid( $crumb->url ) ) : ucfirst( str_replace( '-', ' ', $crumb->slug ) ) ) . '</span>
</a>
<meta itemprop="position" content="' . $i . '">
</li>';
if ( $i !== sizeof( $crumbs ) && ! empty( $ingredients['separator'] ) )
echo $ingredients['separator'];
};
echo '</ul>';
$output = ob_get_clean();
return $output;
}
};
add_shortcode( 'certs', 'certs' );
function certs(){
try{
$enrolled_courses = learndash_user_get_enrolled_courses( get_current_user_id(), array(), false);
ob_start();
if (is_array($enrolled_courses) && !empty($enrolled_courses)):?>
<div class="carousel">
<div id="cert" class="cert-carousel carousel-items container">
<div class='swiper-wrapper'>
<?php foreach($enrolled_courses as $enrolled_course){
$cert = learndash_get_course_certificate_link($enrolled_course, get_current_user_id());
if(!empty($cert)){
$sfwd_course = get_post_meta($enrolled_course , '_sfwd-courses', true );
$thumbnail_id = "911"; ?>
<div class="swiper-slide">
<div class="cert">
<?php echo '<a target="_blank" style="background-image:url('.wp_get_attachment_url( $thumbnail_id).')" class="cert_link" href="'.$cert.'">'. wp_get_attachment_image($thumbnail_id,'medium' ).'<div class="cert-text"><p><strong>'
.get_user_meta(get_current_user_id(), 'first_name', true )." ". get_user_meta(get_current_user_id(), 'last_name', true ).'</strong></p>'
.get_the_title( $enrolled_course ).'</div></a>';
?>
</div>
</div>
<?php }
}; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev" data-id="cert"></div>
<div class="swiper-button-next" data-id="cert"></div>
</div>
</div>
<?php else: ?>
<p class="empty-message" >When you complete a program, your well earned certificate will be saved here.</p>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}catch(Throwable $e) {
error_log("certs()". $e->getMessage()) ;
}
}