class-ld-settings-page-support.php
8.55 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
<?php
/**
* LearnDash Settings Page Support.
*
* @since 3.1.0
* @package LearnDash\Settings\Pages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( class_exists( 'LearnDash_Settings_Page' ) ) && ( ! class_exists( 'LearnDash_Settings_Page_Support' ) ) ) {
/**
* Class LearnDash Settings Page Support.
*
* @since 3.1.0
*/
class LearnDash_Settings_Page_Support extends LearnDash_Settings_Page {
/**
* Systems Info array.
*
* @var array $system_info Array of System Info items to check.
*/
private $system_info = array();
/**
* Public constructor for class
*
* @since 3.1.0
*/
public function __construct() {
$this->parent_menu_page_url = 'admin.php?page=learndash_lms_settings';
$this->menu_page_capability = LEARNDASH_ADMIN_CAPABILITY_CHECK;
$this->settings_page_id = 'learndash_support';
$this->settings_page_title = esc_html__( 'Support', 'learndash' );
$this->settings_tab_title = $this->settings_page_title;
$this->settings_tab_priority = 60;
$this->settings_form_wrap = false;
$this->show_submit_meta = false;
$this->show_quick_links_meta = true;
add_action( 'learndash_settings_page_load', array( $this, 'learndash_settings_page_load' ) );
parent::__construct();
}
/**
* Setting Page Load
*
* @since 3.1.0
*
* @param string $settings_screen_id Screen ID.
*/
public function learndash_settings_page_load( $settings_screen_id = '' ) {
global $sfwd_lms;
if ( $settings_screen_id === $this->settings_screen_id ) {
$this->gather_system_details();
// download-system-info.
if ( ( isset( $_GET['ld_download_system_info_nonce'] ) ) && ( ! empty( $_GET['ld_download_system_info_nonce'] ) ) && ( wp_verify_nonce( $_GET['ld_download_system_info_nonce'], 'ld_download_system_info_' . get_current_user_id() ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
header( 'Content-type: text/plain' );
header( 'Content-Disposition: attachment; filename=ld_system_info-' . gmdate( 'Ymd' ) . '.txt' );
$support_page_instance = LearnDash_Settings_Page::get_page_instance( 'LearnDash_Settings_Page_Support' );
if ( $support_page_instance ) {
foreach ( $support_page_instance->get_support_sections() as $_key => $_section ) {
$support_page_instance->show_support_section( $_key, 'text' );
}
}
die();
}
// Load JS/CSS as needed for page.
wp_enqueue_style(
'learndash-admin-support-page',
LEARNDASH_LMS_PLUGIN_URL . 'assets/css/learndash-admin-support-page' . learndash_min_asset() . '.css',
array(),
LEARNDASH_SCRIPT_VERSION_TOKEN
);
wp_style_add_data( 'learndash-admin-support-page', 'rtl', 'replace' );
$learndash_assets_loaded['styles']['learndash-admin-support-page'] = __FUNCTION__;
}
}
/**
* Used to collect all needed display elements. Many filters by section as well as a final filter
*
* @since 3.1.0
*/
public function gather_system_details() {
/**
* Filters list of initial sections for admin settings support tab.
*
* @param array $system_info An array of support sections.
*/
$this->system_info = apply_filters( 'learndash_support_sections_init', $this->system_info );
// Finally a filter for all sections. This is where some external process will add new sections etc.
/**
* Filters list of sections for admin settings support tab.
*
* @param array $system_info An array of support sections.
*/
$this->system_info = apply_filters( 'learndash_support_sections', $this->system_info );
}
/**
* Get Support Sections
*
* @since 3.1.0
*/
public function get_support_sections() {
return $this->system_info;
}
/**
* Show System Info section
*
* @since 3.1.0
*
* @param string $section_key Section Key.
* @param string $output_type Controls formatting. 'html' or 'text'.
*/
public function show_support_section( $section_key = '', $output_type = 'html' ) {
if ( isset( $this->system_info[ $section_key ] ) ) {
$_set = $this->system_info[ $section_key ];
$_key = $section_key;
switch ( $output_type ) {
case 'text':
if ( ( isset( $_set['header']['text'] ) ) && ( ! empty( $_set['header']['text'] ) ) ) {
echo esc_html( strtoupper( $_set['header']['text'] ) ) . "\r\n";
}
if ( ( isset( $_set['columns'] ) ) && ( ! empty( $_set['columns'] ) ) && ( isset( $_set['settings'] ) ) && ( ! empty( $_set['settings'] ) ) ) {
foreach ( $_set['settings'] as $setting_key => $setting_set ) {
if ( 'settings-sub-section-' === substr( $setting_key, 0, strlen( 'settings-sub-section-' ) ) ) {
if ( isset( $setting_set['text'] ) ) {
echo "\r\n";
echo esc_html( $setting_set['text'] );
echo "\r\n";
}
} else {
foreach ( $_set['columns'] as $column_key => $column_set ) {
$value = wp_strip_all_tags( str_replace( array( '<br />', '<br>', '<br >' ), "\r\n", $setting_set[ $column_key ] ) );
// Add some format spacing to make the raw txt version easier to read.
$spaces_needed = 50 - strlen( $value );
if ( $spaces_needed > 0 ) {
$value .= str_repeat( ' ', $spaces_needed );
}
echo esc_html( $value );
}
echo "\r\n";
}
}
}
echo "\r\n";
break;
case 'html':
default:
if ( ( isset( $_set['desc'] ) ) & ( ! empty( $_set['desc'] ) ) ) {
?>
<div class="learndash-support-settings-desc"><?php echo wp_kses_post( wptexturize( $_set['desc'] ) ); ?></div>
<?php
}
if ( ( isset( $_set['columns'] ) ) && ( ! empty( $_set['columns'] ) ) && ( isset( $_set['settings'] ) ) && ( ! empty( $_set['settings'] ) ) ) {
?>
<table cellspacing="0" class="learndash-support-settings">
<thead>
<tr>
<?php
foreach ( $_set['columns'] as $column_key => $column_set ) {
$column_class = '';
if ( isset( $column_set['class'] ) ) {
$column_class = $column_set['class'];
}
/**
* Filters admin settings support column CSS class.
*
* @param string $column_class Column CSS class.
* @param string $column_key Column Key.
* @param string $system_info_item Name fo system info item.
*/
$column_class = apply_filters( 'learndash_support_column_class', $column_class, $column_key, $_key );
?>
<th scope="col" class="<?php echo esc_attr( $column_class ); ?>">
<?php
if ( isset( $column_set['html'] ) ) {
echo wp_kses_post( $column_set['html'] );
} elseif ( isset( $column_set['text'] ) ) {
echo esc_html( $column_set['text'] );
}
?>
</th>
<?php
}
?>
</tr>
</thead>
<body>
<?php
foreach ( $_set['settings'] as $setting_key => $setting_set ) {
if ( 'settings-sub-section-' === substr( $setting_key, 0, strlen( 'settings-sub-section-' ) ) ) {
?>
<tr class="settings-sub-section">
<th scope="row" class="settings-sub-section" colspan="<?php echo count( $_set['columns'] ); ?>">
<?php
if ( isset( $setting_set['html'] ) ) {
echo wp_kses_post( $setting_set['html'] );
}
?>
</th>
</tr>
<?php
} else {
?>
<tr>
<?php
foreach ( $_set['columns'] as $column_key => $column_set ) {
?>
<td scope="col" class="
<?php
/** This filter is documented in includes/settings/settings-pages/class-ld-settings-page-support.php */
apply_filters( 'learndash_support_column_class', '', $column_key, $_key );
?>
">
<?php
if ( isset( $setting_set[ $column_key . '_html' ] ) ) {
echo wp_kses_post( $setting_set[ $column_key . '_html' ] );
} elseif ( isset( $setting_set[ $column_key ] ) ) {
echo wp_kses_post( $setting_set[ $column_key ] );
}
?>
</td>
<?php
}
?>
</tr>
<?php
}
}
?>
</body>
</table>
<?php
}
}
}
}
}
}
add_action(
'learndash_settings_pages_init',
function() {
LearnDash_Settings_Page_Support::add_page_instance();
}
);