class-learndash-admin-certificates-listing.php
5.94 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
<?php
/**
* LearnDash certificates (certificate) Posts Listing Class.
*
* @package LearnDash\Admin
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( class_exists( 'Learndash_Admin_Posts_Listing' ) ) && ( ! class_exists( 'Learndash_Admin_Certificates_Listing' ) ) ) {
/**
* Class for LearnDash Certificates Listing Pages.
*/
class Learndash_Admin_Certificates_Listing extends Learndash_Admin_Posts_Listing {
/**
* Public constructor for class
*/
public function __construct() {
$this->post_type = learndash_get_post_type_slug( 'certificate' );
parent::__construct();
}
/**
* Called via the WordPress init action hook.
*/
public function listing_init() {
if ( $this->listing_init_done ) {
return;
}
$this->selectors = array();
$this->columns = array(
'certificate_groups_courses_quizzes' => array(
'label' => esc_html__( 'Used in', 'learndash' ),
'display' => array( $this, 'show_column_certificate_groups_courses_quizzes' ),
'after' => 'title',
),
);
parent::listing_init();
$this->listing_init_done = true;
}
/**
* Call via the WordPress load sequence for admin pages.
*/
public function on_load_listing() {
if ( $this->post_type_check() ) {
parent::on_load_listing();
if ( isset( $this->columns['certificate_groups_courses_quizzes'] ) ) {
if ( ( ! current_user_can( 'edit_groups' ) ) && ( ! current_user_can( 'edit_courses' ) ) ) {
unset( $this->columns['certificate_groups_courses_quizzes'] );
} elseif ( ( ! learndash_post_meta_processed( learndash_get_post_type_slug( 'course' ) ) ) && ( ! learndash_post_meta_processed( learndash_get_post_type_slug( 'quiz' ) ) ) && ( ! learndash_post_meta_processed( learndash_get_post_type_slug( 'group' ) ) ) ) {
unset( $this->columns['certificate_groups_courses_quizzes'] );
}
}
}
}
/**
* Show Group Course Users column.
*
* @since 3.4.1
*
* @param int $post_id The Step post ID shown.
* @param array $column_meta Array of column meta information.
*/
protected function show_column_certificate_groups_courses_quizzes( $post_id = 0, $column_meta = array() ) {
if ( ! empty( $post_id ) ) {
if ( current_user_can( 'edit_courses' ) ) {
if ( learndash_post_meta_processed( learndash_get_post_type_slug( 'course' ) ) ) {
$cert_sets = learndash_certificate_get_used_by( $post_id, learndash_get_post_type_slug( 'course' ) );
if ( ! empty( $cert_sets ) ) {
$filter_url = add_query_arg(
array(
'post_type' => learndash_get_post_type_slug( 'course' ),
'certificate_id' => $post_id,
),
admin_url( 'edit.php' )
);
$link_aria_label = sprintf(
// translators: placeholder: Courses, Certificate.
esc_html_x( 'Filter %1$s by Certificate "%2$s"', 'placeholder: Courses, Certificate Post title', 'learndash' ),
LearnDash_Custom_Label::get_label( 'courses' ),
get_the_title( $post_id )
);
echo sprintf(
// translators: placeholder: Courses, Certificate Courses Count.
esc_html_x( '%1$s: %2$s', 'placeholder: Courses, Certificate Courses Count', 'learndash' ),
esc_attr( learndash_get_custom_label( 'courses' ) ),
'<a href="' . esc_url( $filter_url ) . '" aria-label="' . esc_attr( $link_aria_label ) . '">' . count( $cert_sets ) . '</a>'
);
echo '<br />';
}
}
if ( learndash_post_meta_processed( learndash_get_post_type_slug( 'course' ) ) ) {
$cert_sets = learndash_certificate_get_used_by( $post_id, learndash_get_post_type_slug( 'quiz' ) );
if ( ! empty( $cert_sets ) ) {
$filter_url = add_query_arg(
array(
'post_type' => learndash_get_post_type_slug( 'quiz' ),
'certificate_id' => $post_id,
),
admin_url( 'edit.php' )
);
$link_aria_label = sprintf(
// translators: placeholder: Quizzes, Certificate Post title.
esc_html_x( 'Filter %1$s by Certificate "%2$s"', 'placeholder: Quizzes, Certificate Post title', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quizzes' ),
get_the_title( $post_id )
);
echo sprintf(
// translators: placeholder: Quizzes, Certificate Quizzes Count.
esc_html_x( '%1$s: %2$s', 'placeholder: Quizzes, Certificate Quizzes Count', 'learndash' ),
esc_attr( learndash_get_custom_label( 'quizzes' ) ),
'<a href="' . esc_url( $filter_url ) . '" aria-label="' . esc_attr( $link_aria_label ) . '">' . count( $cert_sets ) . '</a>'
);
echo '<br />';
}
}
}
if ( current_user_can( 'edit_groups' ) ) {
if ( learndash_post_meta_processed( learndash_get_post_type_slug( 'group' ) ) ) {
$cert_sets = learndash_certificate_get_used_by( $post_id, learndash_get_post_type_slug( 'group' ) );
if ( ! empty( $cert_sets ) ) {
$filter_url = add_query_arg(
array(
'post_type' => learndash_get_post_type_slug( 'group' ),
'certificate_id' => $post_id,
),
admin_url( 'edit.php' )
);
$link_aria_label = sprintf(
// translators: placeholder: Groups, Certificate Post title.
esc_html_x( 'Filter %1$s by Certificate "%2$s"', 'placeholder: Groups, Certificate Post title', 'learndash' ),
LearnDash_Custom_Label::get_label( 'groups' ),
get_the_title( $post_id )
);
echo sprintf(
// translators: placeholder: Groups, Certificate Groups Count.
esc_html_x( '%1$s: %2$s', 'placeholder: Groups, Certificate Groups Count', 'learndash' ),
esc_attr( learndash_get_custom_label( 'groups' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Method escapes output
'<a href="' . esc_url( $filter_url ) . '" aria-label="' . esc_attr( $link_aria_label ) . '">' . count( $cert_sets ) . '</a>'
);
}
}
}
}
}
// End of functions.
}
}
new Learndash_Admin_Certificates_Listing();