PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9.1
4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 All 141 releases
← All changes | inc/TemplateHooks/Table/TableListTemplate.php +70 -8 4.4.1 → 4.4.9.1 View file →
@@ -14,10 +14,9 @@
14 14
15 15 class TableListTemplate {
16 16 use Singleton;
17 17
18 - public function init() {
19 - }
18 + public function init(): void {}
20 19
21 20 /**
22 21 * Render the HTML table.
23 22 *
@@ -53,13 +52,9 @@
53 52 public function html_header( array $data = [] ): string {
54 53 $html_th = '';
55 54
56 55 foreach ( $data as $item ) {
57 - $html_th .= sprintf(
58 - '<th class="%s">%s</th>',
59 - esc_attr( $item['class'] ?? '' ),
60 - wp_kses_post( $item['title'] ?? '' )
61 - );
56 + $html_th .= $this->html_header_sort( $item );
62 57 }
63 58
64 59 $section = [
65 60 'wrapper' => '<thead>',
@@ -72,8 +67,75 @@
72 67 return Template::combine_components( $section );
73 68 }
74 69
75 70 /**
71 + * Render a single sortable/non-sortable column header.
72 + *
73 + * Mirrors WordPress WP_List_Table column headers, replacing the
74 + * default .sorting-indicator pseudo-element icon with lp-icon carets.
75 + *
76 + * Expected item keys:
77 + * - class : CSS class(es) for the <th>.
78 + * - title : Column title.
79 + * - sortable : Whether the column supports sorting.
80 + * - sort_url : URL to use when the header is clicked (required when sortable).
81 + * - sorted : Whether this column is the currently sorted one.
82 + * - sort_order : Current sort order, 'asc' or 'desc' (default 'asc').
83 + *
84 + * @param array $item
85 + *
86 + * @return string
87 + */
88 + public function html_header_sort( array $item = [] ): string {
89 + $classes = array_filter( [ (string) ( $item['class'] ?? '' ) ] );
90 + $sortable = ! empty( $item['sortable'] );
91 + $sorted = $sortable && ! empty( $item['sorted'] );
92 + $order = $sorted ? strtolower( (string) ( $item['sort_order'] ?? 'asc' ) ) : '';
93 + if ( ! in_array( $order, [ 'asc', 'desc' ], true ) ) {
94 + $order = 'asc';
95 + }
96 +
97 + if ( $sortable ) {
98 + $classes[] = $sorted ? 'sorted' : 'sortable';
99 + if ( $sorted ) {
100 + $classes[] = $order;
101 + }
102 + }
103 +
104 + $title = wp_kses_post( $item['title'] ?? '' );
105 + $class = implode( ' ', $classes );
106 +
107 + if ( ! $sortable ) {
108 + return sprintf(
109 + '<th scope="col" class="%s">%s</th>',
110 + esc_attr( $class ),
111 + $title
112 + );
113 + }
114 +
115 + $up_active = $sorted && 'asc' === $order ? ' is-active' : '';
116 + $down_active = $sorted && 'desc' === $order ? ' is-active' : '';
117 + $sort_url = $item['sort_url'] ?? '#';
118 +
119 + return sprintf(
120 + '<th scope="col" class="%s">
121 + <a href="%s">
122 + <span>%s</span>
123 + <span class="sorting-indicator">
124 + <i class="lp-icon-caret-up%4$s"></i>
125 + <i class="lp-icon-caret-down%5$s"></i>
126 + </span>
127 + </a>
128 + </th>',
129 + esc_attr( $class ),
130 + esc_url( $sort_url ),
131 + $title,
132 + esc_attr( $up_active ),
133 + esc_attr( $down_active )
134 + );
135 + }
136 +
137 + /**
76 138 * Render the HTML table body.
77 139 *
78 140 * @param array $data
79 141 *
@@ -108,9 +170,9 @@
108 170 return Template::combine_components( $section );
109 171 }
110 172
111 173 /**
112 - * Reder the HTML table footer.
174 + * Render the HTML table footer.
113 175 *
114 176 * @param string $footer_html
115 177 *
116 178 * @return string