profile.php
9.56 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
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
<?php
/**
* LearnDash LD30 Displays a user's profile.
*
* Available Variables:
*
* $user_id : Current User ID
* $current_user : (object) Currently logged in user object
* $user_courses : Array of course ID's of the current user
* $quiz_attempts : Array of quiz attempts of the current user
* $shortcode_atts : Array of values passed to shortcode
*
* @since 3.0.0
*
* @package LearnDash\Templates\LD30
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $learndash_assets_loaded;
$learndash_shortcode_data_json = htmlspecialchars( wp_json_encode( $shortcode_atts ) );
/**
* Logic to load assets as needed
*
* @var [type]
*/
if ( ! isset( $learndash_assets_loaded['scripts']['learndash_template_script_js'] ) ) :
$learndash_template_script_filepath = SFWD_LMS::get_template( 'learndash_template_script.js', null, null, true );
if ( ! empty( $learndash_template_script_filepath ) ) :
wp_enqueue_script( 'learndash_template_script_js', learndash_template_url_from_path( $learndash_template_script_filepath ), array( 'jquery' ), LEARNDASH_SCRIPT_VERSION_TOKEN, true );
$learndash_assets_loaded['scripts']['learndash_template_script_js'] = __FUNCTION__;
$learndash_data = array();
$learndash_data['ajaxurl'] = admin_url( 'admin-ajax.php' );
$learndash_data = array( 'json' => wp_json_encode( $learndash_data ) );
wp_localize_script( 'learndash_template_script_js', 'sfwd_data', $learndash_data );
endif;
endif;
/**
* We don't want to include this if this is a paginated or search view as we'll end up with duplicates
*
* @var $_GET['action'] (string) is set to 'ld30_ajax_pager' if paginating or set to 'ld30_ajax_profile_search' on search.
*/
if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], array( 'ld30_ajax_pager', 'ld30_ajax_profile_search' ), true ) ) :
LD_QuizPro::showModalWindow();
endif; ?>
<div class="<?php learndash_the_wrapper_class(); ?>">
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped on line 20 ?>
<div id="ld-profile" data-shortcode_instance="<?php echo $learndash_shortcode_data_json; ?>">
<?php
/**
* If the user wants to include the summary, they use the shortcode attr summary="true"
*
* @var [type]
*/
if ( isset( $shortcode_atts['show_header'] ) && 'yes' === $shortcode_atts['show_header'] ) :
?>
<div class="ld-profile-summary">
<div class="ld-profile-card">
<div class="ld-profile-avatar">
<?php
/**
* Related to the CSS themes/ld30/assets/css/learndash.css
* .learndash-wrapper .ld-profile-summary .ld-profile-card .ld-profile-avatar
*/
echo wp_kses_post( get_avatar( $user_id, 150 ) );
?>
</div> <!--/.ld-profile-avatar-->
<?php
if ( ! empty( $current_user->user_lastname ) || ! empty( $current_user->user_firstname ) ) :
?>
<div class="ld-profile-heading">
<?php echo esc_html( $current_user->user_firstname . ' ' . $current_user->user_lastname ); ?>
</div>
<?php endif; ?>
<?php
/**
* Filters whether to show the user profile link.
*
* @since 2.5.8
*
* @param boolean $show_profile Whether to show profile link.
*/
if ( current_user_can( 'read' ) && isset( $shortcode_atts['profile_link'] ) && true === (bool) $shortcode_atts['profile_link'] && apply_filters( 'learndash_show_profile_link', $shortcode_atts['profile_link'] ) ) :
?>
<a class="ld-profile-edit-link" href='<?php echo esc_url( get_edit_user_link() ); ?>'><?php esc_html_e( 'Edit profile', 'learndash' ); ?></a>
<?php endif; ?>
</div> <!--/.ld-profile-card-->
<div class="ld-profile-stats">
<?php
$learndash_user_stats = learndash_get_user_stats( $user_id );
$learndash_profile_stats = array(
array(
'title' => LearnDash_Custom_Label::get_label( 'courses' ),
'value' => $learndash_user_stats['courses'],
'class' => 'ld-profile-stat-courses',
),
array(
'title' => __( 'Completed', 'learndash' ),
'value' => $learndash_user_stats['completed'],
'class' => 'ld-profile-stat-completed',
),
array(
'title' => __( 'Certificates', 'learndash' ),
'value' => $learndash_user_stats['certificates'],
'class' => 'ld-profile-stat-certificates',
),
);
if ( isset( $shortcode_atts['course_points_user'] ) && 'yes' === $shortcode_atts['course_points_user'] ) {
$learndash_profile_stats[] = array(
'title' => esc_html__( 'Points', 'learndash' ),
'value' => $learndash_user_stats['points'],
'class' => 'ld-profile-stat-points',
);
}
/**
* Filters LearnDash user profile statistics.
*
* @since 3.1.0
*
* @param array $learndash_profile_stats An array of profile stats data.
* @param int $user_id User ID.
*/
$learndash_profile_stats = apply_filters( 'learndash_profile_stats', $learndash_profile_stats, $user_id );
if ( ( ! empty( $learndash_profile_stats ) ) && ( is_array( $learndash_profile_stats ) ) ) {
foreach ( $learndash_profile_stats as $learndash_profile_stat ) {
$learndash_stat_class = 'ld-profile-stat';
if ( ( isset( $learndash_profile_stat['class'] ) ) && ( ! empty( $learndash_profile_stat['class'] ) ) ) {
$learndash_stat_class .= ' ' . $learndash_profile_stat['class'];
}
?>
<div class="<?php echo esc_attr( $learndash_stat_class ); ?>">
<strong><?php echo esc_html( $learndash_profile_stat['value'] ); ?></strong>
<span><?php echo esc_html( $learndash_profile_stat['title'] ); ?></span>
</div> <!--/.ld-profile-stat-->
<?php
}
}
?>
</div> <!--/.ld-profile-stats-->
</div>
<?php endif; ?>
<div class="ld-item-list ld-course-list">
<div class="ld-section-heading">
<h3>
<?php
printf(
// translators: Profile Course Content Label.
esc_html_x( 'Your %s', 'Profile Course Content Label', 'learndash' ),
esc_attr( LearnDash_Custom_Label::get_label( 'courses' ) )
);
?>
</h3>
<div class="ld-item-list-actions">
<?php if ( isset( $shortcode_atts['show_search'] ) && 'yes' === $shortcode_atts['show_search'] ) { ?>
<button class="ld-search-prompt ld-icon-search ld-icon" data-ld-expands="ld-course-search" aria-label="
<?php
printf(
// translators: placeholder: Profile Search Prompt Label.
esc_html_x( 'Show %s Search Field', 'placeholder: Profile Search Prompt Label', 'learndash' ),
esc_attr( LearnDash_Custom_Label::get_label( 'courses' ) )
);
?>
">
</button> <!--/.ld-search-prompt-->
<?php } ?>
<div class="ld-expand-button" data-ld-expands="ld-main-course-list" data-ld-expand-text="<?php echo esc_attr_e( 'Expand All', 'learndash' ); ?>" data-ld-collapse-text="<?php echo esc_attr_e( 'Collapse All', 'learndash' ); ?>">
<span class="ld-icon-arrow-down ld-icon"></span>
<span class="ld-text"><?php echo esc_html_e( 'Expand All', 'learndash' ); ?></span>
</div> <!--/.ld-expand-button-->
</div> <!--/.ld-course-list-actions-->
</div> <!--/.ld-section-heading-->
<?php
if ( isset( $shortcode_atts['show_search'] ) && 'yes' === $shortcode_atts['show_search'] ) {
learndash_get_template_part(
'shortcodes/profile/search.php',
array(
'user_id' => $user_id,
'user_courses' => $user_courses,
),
true
);
}
?>
<div class="ld-item-list-items" id="ld-main-course-list" data-ld-expand-list="true" data-ld-expand-id="<?php echo esc_attr( 'ld-main-course-list' ); ?>">
<?php
if ( ! empty( $user_courses ) ) :
foreach ( $user_courses as $learndash_course_id ) :
learndash_get_template_part(
'shortcodes/profile/course-row.php',
array(
'user_id' => $user_id,
'course_id' => $learndash_course_id,
'quiz_attempts' => $quiz_attempts,
'shortcode_atts' => $shortcode_atts,
),
true
);
endforeach;
else :
$learndash_no_courses_found_alert = array(
'icon' => 'alert',
// translators: placeholder: Courses.
'message' => sprintf( esc_html_x( 'No %s found', 'placeholder: Courses', 'learndash' ), LearnDash_Custom_Label::get_label( 'courses' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Method escapes output
'type' => 'warning',
);
learndash_get_template_part( 'modules/alert.php', $learndash_no_courses_found_alert, true );
endif;
?>
</div> <!--/.ld-course-list-items-->
</div> <!--/ld-course-list-->
<?php
$learndash_profile_search = isset( $_GET['ld-profile-search'], $_GET['learndash_profile_course_search_nonce'] ) &&
! empty( $_GET['ld-profile-search'] ) &&
wp_verify_nonce( $_GET['learndash_profile_course_search_nonce'], $learndash_profile_course_search_nonce_field )
? sanitize_text_field( $_GET['ld-profile-search'] )
: false;
learndash_get_template_part(
'modules/pagination',
array(
'pager_results' => $profile_pager,
'pager_context' => 'profile',
'search' => $learndash_profile_search,
),
true
);
?>
</div> <!--/#ld-profile-->
</div> <!--/.ld-course-wrapper-->
<?php
/** This filter is documented in themes/ld30/templates/course.php */
if ( apply_filters( 'learndash_course_steps_expand_all', $shortcode_atts['expand_all'], 0, 'profile_shortcode' ) ) :
?>
<script>
jQuery( function() {
setTimeout(function() {
jQuery(".ld-item-list-actions .ld-expand-button").trigger('click');
}, 1000 );
});
</script>
<?php
endif;