class-ld-shortcodes-sections.php
8.58 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* LearnDash Admin Shortcodes Section Class.
*
* @since 2.4.0
* @package LearnDash\Settings\Shortcodes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'LearnDash_Shortcodes_Section' ) ) {
/**
* Class for LearnDash Admin Course Edit.
*
* @since 2.4.0
*/
class LearnDash_Shortcodes_Section {
/**
* Shortcodes Section Key.
*
* @var string $shortcodes_section_key
*/
protected $shortcodes_section_key = '';
/**
* Shortcodes Section Title.
*
* @var string $shortcodes_section_title
*/
protected $shortcodes_section_title = '';
/**
* Shortcodes Section Type.
*
* @var integer $shortcodes_section_type
*/
protected $shortcodes_section_type = 1;
/**
* Shortcodes Section Description.
*
* @var string $shortcodes_section_description
*/
protected $shortcodes_section_description = '';
/**
* Shortcodes Section Fields.
*
* @var array $shortcodes_option_fields
*/
protected $shortcodes_option_fields = array();
/**
* Shortcodes Section Values.
*
* @var array $shortcodes_option_values
*/
protected $shortcodes_option_values = array();
/**
* This is derived from the $shortcodes_option_fields within the function init_shortcodes_section_fields();
*
* @var array $shortcodes_settings_fields
*/
protected $shortcodes_settings_fields = array();
/**
* This is the HTML form field prefix used.
*
* @var array $shortcodes_option_fields
*/
protected $setting_field_prefix = '';
/**
* Fields Args.
*
* @var array $fields_args
*/
protected $fields_args = array();
/**
* Public constructor for class.
*
* @since 2.4.0
*/
public function __construct() {
$this->init_shortcodes_section_fields();
}
/**
* Initialize the Shortcodes Fields.
*
* @since 2.4.0
*/
public function init_shortcodes_section_fields() {
foreach ( $this->shortcodes_option_fields as $field_id => $setting_option_field ) {
if ( ! isset( $setting_option_field['label_for'] ) ) {
$setting_option_field['label_for'] = $setting_option_field['id'];
}
if ( ! isset( $setting_option_field['label_for'] ) ) {
$setting_option_field['label_for'] = $setting_option_field['id'];
}
$setting_option_field['setting_option_key'] = $setting_option_field['id'];
if ( ! isset( $setting_option_field['display_callback'] ) ) {
$display_ref = LearnDash_Settings_Fields::get_field_instance( $setting_option_field['type'] );
if ( ! $display_ref ) {
$setting_option_field['display_callback'] = array( $this, 'field_element_create' );
} else {
$setting_option_field['display_callback'] = array( $display_ref, 'create_section_field' );
}
}
$this->shortcodes_settings_fields[ $field_id ] = array(
'id' => $setting_option_field['id'],
'title' => $setting_option_field['label'],
'callback' => $setting_option_field['display_callback'],
'args' => $setting_option_field,
);
}
}
/**
* Section Fields Create.
*
* @since 2.4.0
*
* @param array $field_args Field Args.
*/
public function field_element_create( $field_args = array() ) {
$field_html = '';
if ( ( isset( $field_args['display_func'] ) ) && ( ! empty( $field_args['display_func'] ) ) && ( is_callable( $field_args['display_func'] ) ) ) {
call_user_func(
$field_args['display_func'],
$field_args,
$this->setting_field_prefix
);
}
}
/**
* Show Section Fields.
*
* @since 2.4.0
*/
public function show_section_fields() {
$this->show_shortcodes_section_header();
echo LearnDash_Settings_Fields::show_section_fields( $this->shortcodes_settings_fields ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Need to output HTML.
$this->show_shortcodes_section_footer();
}
/**
* Show Section Header.
*
* @since 2.4.0
*/
public function show_shortcodes_section_header() {
/**
* Action shortcodes section header before form.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_header_before_form', $this->shortcodes_section_key );
?><form id="learndash_shortcodes_form_<?php echo esc_attr( $this->shortcodes_section_key ); ?>" class="learndash_shortcodes_form" shortcode_slug="<?php echo esc_attr( $this->shortcodes_section_key ); ?>" shortcode_type="<?php echo esc_attr( $this->shortcodes_section_type ); ?>">
<?php
/**
* Action shortcodes section header before title output.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_header_before_title', $this->shortcodes_section_key );
?>
<?php $this->show_shortcodes_section_title(); ?>
<?php
/**
* Action shortcodes section header before description output.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_header_before_description', $this->shortcodes_section_key );
?>
<?php $this->show_shortcodes_section_description(); ?>
<?php
/**
* Action shortcodes section before content output.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_before_content', $this->shortcodes_section_key );
?>
<div class="sfwd sfwd_options learndash_shortcodes_section" style="clear:left">
<?php
}
/**
* Show Section Footer.
*
* @since 2.4.0
*/
public function show_shortcodes_section_footer() {
?>
</div>
<?php
/**
* Action shortcodes section after content output.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_after_content', $this->shortcodes_section_key );
?>
<?php $this->show_shortcodes_section_footer_extra(); ?>
<?php
/**
* Action shortcodes section before button output.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_before_button', $this->shortcodes_section_key );
?>
<p style="clear:left"><input type="submit" class="button-primary" value="<?php esc_html_e( 'Insert Shortcode', 'learndash' ); ?>"></p>
<?php
/**
* Action shortcodes section after button output.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_after_button', $this->shortcodes_section_key );
?>
</form>
<?php
/**
* Action shortcodes section header after form.
*
* @since 4.0.0
*
* @param string $shortcodes_section_key Shortcodes section key.
*/
do_action( 'learndash_shortcodes_section_header_after_form', $this->shortcodes_section_key );
}
/**
* Show Section Footer Extra.
*
* @since 2.4.0
*/
public function show_shortcodes_section_footer_extra() {
// This is a hook called after the section closing </div> to allow adding JS/CSS.
}
/**
* Get Section Key.
*
* @since 2.4.0
*/
public function get_shortcodes_section_key() {
return $this->shortcodes_section_key;
}
/**
* Get Section Title.
*
* @since 2.4.0
*/
public function get_shortcodes_section_title() {
return $this->shortcodes_section_title;
}
/**
* Show Section Key.
*
* @since 2.4.0
*/
public function show_shortcodes_section_title() {
if ( ! empty( $this->shortcodes_section_title ) ) {
?>
<h2><?php echo wp_kses_post( $this->shortcodes_section_title ); ?> [<?php echo esc_html( $this->shortcodes_section_key ); ?>]</h2>
<?php
}
}
/**
* Get Section Description.
*
* @since 2.4.0
*/
public function get_shortcodes_section_description() {
return $this->shortcodes_section_description;
}
/**
* Show Section Description.
*
* @since 2.4.0
*/
public function show_shortcodes_section_description() {
if ( ! empty( $this->shortcodes_section_description ) ) {
echo wp_kses_post( wpautop( $this->shortcodes_section_description ) );
}
}
/**
* Get Shortcode field by key;
*
* @since 3.1.4
*
* @param string $field_key Field key.
*/
public function get_shortcodes_section_field( $field_key = '' ) {
if ( ( ! empty( $field_key ) ) && ( isset( $this->shortcodes_option_fields[ $field_key ] ) ) ) {
return $this->shortcodes_option_fields[ $field_key ];
}
}
}
}