class-ld-settings-metabox-topic-display-content.php
46.8 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
<?php
/**
* LearnDash Settings Metabox for Topic Display and Content Options.
*
* @since 3.0.0
* @package LearnDash\Settings\Metaboxes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( class_exists( 'LearnDash_Settings_Metabox' ) ) && ( ! class_exists( 'LearnDash_Settings_Metabox_Topic_Display_Content' ) ) ) {
/**
* Class LearnDash Settings Metabox for Topic Display and Content Options.
*
* @since 3.0.0
*/
class LearnDash_Settings_Metabox_Topic_Display_Content extends LearnDash_Settings_Metabox {
/**
* Public constructor for class
*
* @since 3.0.0
*/
public function __construct() {
// What screen ID are we showing on.
$this->settings_screen_id = 'sfwd-topic';
// Used within the Settings API to uniquely identify this section.
$this->settings_metabox_key = 'learndash-topic-display-content-settings';
// Section label/header.
$this->settings_section_label = esc_html__( 'Display and Content Options', 'learndash' );
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
// translators: placeholder: topic.
esc_html_x( 'Controls the look and feel of the %s and optional content settings', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
);
add_filter( 'learndash_metabox_save_fields_' . $this->settings_metabox_key, array( $this, 'filter_saved_fields' ), 30, 3 );
// Map internal settings field ID to legacy field ID.
$this->settings_fields_map = array(
// New fields.
'topic_materials_enabled' => 'topic_materials_enabled',
'topic_materials' => 'topic_materials',
'lesson_video_enabled' => 'lesson_video_enabled',
'lesson_video_url' => 'lesson_video_url',
'lesson_video_shown' => 'lesson_video_shown',
'lesson_video_auto_start' => 'lesson_video_auto_start',
'lesson_video_show_controls' => 'lesson_video_show_controls',
'lesson_video_focus_pause' => 'lesson_video_focus_pause',
'lesson_video_track_time' => 'lesson_video_track_time',
'lesson_video_auto_complete' => 'lesson_video_auto_complete',
'lesson_video_auto_complete_delay' => 'lesson_video_auto_complete_delay',
'lesson_video_hide_complete_button' => 'lesson_video_hide_complete_button',
'lesson_video_show_complete_button' => 'lesson_video_show_complete_button',
'lesson_assignment_upload' => 'lesson_assignment_upload',
'assignment_upload_limit_extensions' => 'assignment_upload_limit_extensions',
'assignment_upload_limit_size' => 'assignment_upload_limit_size',
'lesson_assignment_points_enabled' => 'lesson_assignment_points_enabled',
'lesson_assignment_points_amount' => 'lesson_assignment_points_amount',
'assignment_upload_limit_count' => 'assignment_upload_limit_count',
'lesson_assignment_deletion_enabled' => 'lesson_assignment_deletion_enabled',
'auto_approve_assignment' => 'auto_approve_assignment',
'forced_lesson_time_enabled' => 'forced_lesson_time_enabled',
'forced_lesson_time' => 'forced_lesson_time',
);
parent::__construct();
}
/**
* Initialize the metabox settings values.
*
* @since 3.0.0
*/
public function load_settings_values() {
global $sfwd_lms;
parent::load_settings_values();
if ( true === $this->settings_values_loaded ) {
if ( ! isset( $this->setting_option_values['topic_materials'] ) ) {
$this->setting_option_values['topic_materials'] = '';
}
if ( ! empty( $this->setting_option_values['topic_materials'] ) ) {
$this->setting_option_values['topic_materials_enabled'] = 'on';
} else {
$this->setting_option_values['topic_materials_enabled'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_enabled'] ) ) {
$this->setting_option_values['lesson_video_enabled'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_url'] ) ) {
$this->setting_option_values['lesson_video_url'] = '';
}
if ( ( ! isset( $this->setting_option_values['lesson_video_shown'] ) ) || ( empty( $this->setting_option_values['lesson_video_shown'] ) ) ) {
$this->setting_option_values['lesson_video_shown'] = 'BEFORE';
}
if ( ! isset( $this->setting_option_values['lesson_video_auto_start'] ) ) {
$this->setting_option_values['lesson_video_auto_start'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_show_controls'] ) ) {
$this->setting_option_values['lesson_video_show_controls'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_focus_pause'] ) ) {
$this->setting_option_values['lesson_video_focus_pause'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_track_time'] ) ) {
$this->setting_option_values['lesson_video_track_time'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_auto_complete'] ) ) {
$this->setting_option_values['lesson_video_auto_complete'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_video_auto_complete_delay'] ) ) {
$this->setting_option_values['lesson_video_auto_complete_delay'] = '0';
}
if ( ! isset( $this->setting_option_values['lesson_video_hide_complete_button'] ) ) {
$this->setting_option_values['lesson_video_hide_complete_button'] = '';
}
if ( 'on' === $this->setting_option_values['lesson_video_hide_complete_button'] ) {
$this->setting_option_values['lesson_video_show_complete_button'] = '';
} else {
$this->setting_option_values['lesson_video_show_complete_button'] = 'on';
}
if ( ! isset( $this->setting_option_values['lesson_assignment_upload'] ) ) {
$this->setting_option_values['lesson_assignment_upload'] = '';
}
if ( ! empty( $this->setting_option_values['assignment_upload_limit_extensions'] ) ) {
if ( is_array( $this->setting_option_values['assignment_upload_limit_extensions'] ) ) {
if ( count( $this->setting_option_values['assignment_upload_limit_extensions'] ) > 1 ) {
$this->setting_option_values['assignment_upload_limit_extensions'] = implode( ',', $this->setting_option_values['assignment_upload_limit_extensions'] );
} else {
$this->setting_option_values['assignment_upload_limit_extensions'] = $this->setting_option_values['assignment_upload_limit_extensions'][0];
}
}
}
if ( ! isset( $this->setting_option_values['assignment_upload_limit_size'] ) ) {
$this->setting_option_values['assignment_upload_limit_size'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_assignment_points_enabled'] ) ) {
$this->setting_option_values['lesson_assignment_points_enabled'] = '';
}
if ( ! isset( $this->setting_option_values['lesson_assignment_points_amount'] ) ) {
$this->setting_option_values['lesson_assignment_points_amount'] = '';
}
if ( ! isset( $this->setting_option_values['assignment_upload_limit_count'] ) ) {
$this->setting_option_values['assignment_upload_limit_count'] = '';
}
$this->setting_option_values['assignment_upload_limit_count'] = absint( $this->setting_option_values['assignment_upload_limit_count'] );
if ( empty( $this->setting_option_values['assignment_upload_limit_count'] ) ) {
$this->setting_option_values['assignment_upload_limit_count'] = 1;
}
if ( ! isset( $this->setting_option_values['lesson_assignment_deletion_enabled'] ) ) {
$this->setting_option_values['lesson_assignment_deletion_enabled'] = '';
}
if ( ! isset( $this->setting_option_values['auto_approve_assignment'] ) ) {
$this->setting_option_values['auto_approve_assignment'] = 'on';
}
if ( ! isset( $this->setting_option_values['forced_lesson_time'] ) ) {
$this->setting_option_values['forced_lesson_time'] = '';
}
if ( ! isset( $this->setting_option_values['forced_lesson_time_enabled'] ) ) {
$this->setting_option_values['forced_lesson_time_enabled'] = '';
}
if ( ( isset( $this->setting_option_values['forced_lesson_time'] ) ) && ( ! empty( $this->setting_option_values['forced_lesson_time'] ) ) ) {
$this->setting_option_values['forced_lesson_time_enabled'] = 'on';
} else {
$this->setting_option_values['forced_lesson_time_enabled'] = '';
}
}
// Ensure all settings fields are present.
foreach ( $this->settings_fields_map as $_internal => $_external ) {
if ( ! isset( $this->setting_option_values[ $_internal ] ) ) {
$this->setting_option_values[ $_internal ] = '';
}
}
if ( 'on' === $this->setting_option_values['lesson_video_enabled'] ) {
$this->setting_option_values['lesson_assignment_upload'] = '';
$this->setting_option_values['forced_lesson_time_enabled'] = '';
} elseif ( 'on' === $this->setting_option_values['lesson_assignment_upload'] ) {
$this->setting_option_values['lesson_video_enabled'] = '';
$this->setting_option_values['forced_lesson_time_enabled'] = '';
} elseif ( 'on' === $this->setting_option_values['forced_lesson_time_enabled'] ) {
$this->setting_option_values['lesson_video_enabled'] = '';
$this->setting_option_values['lesson_assignment_upload'] = '';
}
if ( 'on' !== $this->setting_option_values['lesson_video_enabled'] ) {
$this->setting_option_values['lesson_video_enabled'] = '';
$this->setting_option_values['lesson_video_url'] = '';
$this->setting_option_values['lesson_video_shown'] = '';
$this->setting_option_values['lesson_video_auto_start'] = '';
$this->setting_option_values['lesson_video_show_controls'] = '';
$this->setting_option_values['lesson_video_focus_pause'] = '';
$this->setting_option_values['lesson_video_track_time'] = '';
$this->setting_option_values['lesson_video_auto_complete'] = '';
$this->setting_option_values['lesson_video_auto_complete_delay'] = '0';
$this->setting_option_values['lesson_video_show_complete_button'] = '';
} elseif ( 'on' !== $this->setting_option_values['lesson_assignment_upload'] ) {
$this->setting_option_values['lesson_assignment_upload'] = '';
$this->setting_option_values['assignment_upload_limit_extensions'] = '';
$this->setting_option_values['assignment_upload_limit_size'] = '';
$this->setting_option_values['lesson_assignment_points_enabled'] = '';
$this->setting_option_values['lesson_assignment_points_amount'] = '';
$this->setting_option_values['assignment_upload_limit_count'] = '';
$this->setting_option_values['lesson_assignment_deletion_enabled'] = '';
$this->setting_option_values['auto_approve_assignment'] = 'on';
} elseif ( 'on' !== $this->setting_option_values['forced_lesson_time_enabled'] ) {
$this->setting_option_values['forced_lesson_time_enabled'] = '';
$this->setting_option_values['forced_lesson_time'] = '';
}
}
/**
* Initialize the metabox settings fields.
*
* @since 3.0.0
*/
public function load_settings_fields() {
global $sfwd_lms;
$this->setting_option_fields = array(
'lesson_video_auto_complete' => array(
'name' => 'lesson_video_auto_complete',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Topic.
esc_html_x( '%s auto-completion', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
),
'default' => '',
'value' => $this->setting_option_values['lesson_video_auto_complete'],
'options' => array(
'' => '',
'on' => '',
),
'help_text' => sprintf(
// translators: placeholder: topic.
esc_html_x( ' Automatically mark the %s as completed once the user has watched the full video.', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_auto_complete',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Auto-complete', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_video_auto_complete_delay' => array(
'name' => 'lesson_video_auto_complete_delay',
'label' => esc_html__( 'Completion delay', 'learndash' ),
'type' => 'number',
'class' => '-small',
'default' => 0,
'value' => $this->setting_option_values['lesson_video_auto_complete_delay'],
'attrs' => array(
'step' => 1,
'min' => 0,
),
'input_label' => esc_html__( 'seconds', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: topic.
esc_html_x( 'Specify a delay between video completion and %s completion.', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_auto_complete_delay',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Completion Delay (seconds).', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'integer',
'default' => 0,
),
),
),
),
'lesson_video_show_complete_button' => array(
'name' => 'lesson_video_show_complete_button',
'label' => esc_html__( 'Mark Complete Button', 'learndash' ),
'type' => 'checkbox-switch',
'help_text' => sprintf(
// translators: placeholder: lesson.
esc_html_x( 'Display the Mark Complete button on a %s even if not yet clickable.', 'placeholder: lesson', 'learndash' ),
learndash_get_custom_label_lower( 'lesson' )
),
'value' => $this->setting_option_values['lesson_video_show_complete_button'],
'default' => '',
'options' => array(
'on' => '',
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_show_complete_button',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Show Mark Complete Button', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
);
parent::load_settings_fields();
$this->settings_sub_option_fields['video_display_timing_after_fields'] = $this->setting_option_fields;
$this->setting_option_fields = array(
'assignment_upload_limit_count' => array(
'name' => 'assignment_upload_limit_count',
'label' => esc_html__( 'Limit number of uploaded files', 'learndash' ),
'type' => 'number',
'value' => $this->setting_option_values['assignment_upload_limit_count'],
'default' => '1',
'class' => 'small-text',
'input_label' => esc_html__( 'file(s) maximum', 'learndash' ),
'attrs' => array(
'step' => 1,
'min' => 1,
),
'help_text' => esc_html__( 'Specify the maximum number of files a user can upload for this assignment.', 'learndash' ),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Upload Count Limit.', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'integer',
'default' => 0,
),
),
),
),
'lesson_assignment_deletion_enabled' => array(
'name' => 'lesson_assignment_deletion_enabled',
'label' => esc_html__( 'Allow file deletion', 'learndash' ),
'type' => 'checkbox-switch',
'value' => $this->setting_option_values['lesson_assignment_deletion_enabled'],
'default' => '',
'help_text' => esc_html__( 'Allow the user to delete their own uploaded files. This is only possible up until the assignment has been approved.', 'learndash' ),
'options' => array(
'on' => '',
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'assignment_deletion_enabled',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Allow File Deletion.', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
);
parent::load_settings_fields();
$this->settings_sub_option_fields['lesson_assignment_grading_manual_fields'] = $this->setting_option_fields;
$this->setting_option_fields = array(
'topic_materials_enabled' => array(
'name' => 'topic_materials_enabled',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Topic.
esc_html_x( '%s Materials', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
),
'help_text' => sprintf(
// translators: placeholder: topic, topic.
esc_html_x( 'List and display support materials for the %1$s. This is visible to any user having access to the %2$s.', 'placeholder: topic, topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' ),
learndash_get_custom_label_lower( 'topic' )
),
'value' => $this->setting_option_values['topic_materials_enabled'],
'default' => '',
'options' => array(
'on' => sprintf(
// translators: placeholder: topic.
esc_html_x( 'Any content added below is displayed on the %s page', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
'' => '',
),
'child_section_state' => ( 'on' === $this->setting_option_values['topic_materials_enabled'] ) ? 'open' : 'closed',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'materials_enabled',
'description' => esc_html__( 'Materials Enabled', 'learndash' ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'topic_materials' => array(
'name' => 'topic_materials',
'type' => 'wpeditor',
'parent_setting' => 'topic_materials_enabled',
'value' => $this->setting_option_values['topic_materials'],
'default' => '',
'placeholder' => esc_html__( 'Add a list of needed documents or URLs. This field supports HTML.', 'learndash' ),
'editor_args' => array(
'textarea_name' => $this->settings_metabox_key . '[topic_materials]',
'textarea_rows' => 3,
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'materials',
'description' => esc_html__( 'Materials', 'learndash' ),
'type' => 'object',
'properties' => array(
'raw' => array(
'description' => 'Content for the object, as it exists in the database.',
'type' => 'string',
'context' => array( 'edit' ),
),
'rendered' => array(
'description' => 'HTML content for the object, transformed for display.',
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
'arg_options' => array(
'sanitize_callback' => null, // Note: sanitization performed in rest_pre_insert_filter().
'validate_callback' => null,
),
),
),
),
),
'lesson_video_enabled' => array(
'name' => 'lesson_video_enabled',
'label' => esc_html__( 'Video Progression', 'learndash' ),
'type' => 'checkbox-switch',
'help_text' => sprintf(
// translators: placeholder: Course.
esc_html_x( 'Require users to watch the full video as part of the %s progression. Use shortcode [ld_video] to move within the post content.', 'placeholder: Course', 'learndash' ),
learndash_get_custom_label_lower( 'course' )
),
'value' => $this->setting_option_values['lesson_video_enabled'],
'default' => '',
'options' => array(
'' => '',
'on' => array(
'label' => sprintf(
// translators: placeholder: Course.
esc_html_x( 'The below video is tied to %s progression', 'placeholder: Course', 'learndash' ),
learndash_get_custom_label_lower( 'course' )
),
'description' => '',
'tooltip' => sprintf(
// translators: placeholder: Topic.
esc_html_x( 'Cannot be enabled while %s timer or Assignments are enabled', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
),
),
),
'child_section_state' => ( 'on' === $this->setting_option_values['lesson_video_enabled'] ) ? 'open' : 'closed',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_enabled',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Progression Enabled', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_video_url' => array(
'name' => 'lesson_video_url',
'label' => esc_html__( 'Video URL', 'learndash' ),
'type' => 'textarea',
'class' => 'full-text',
'value' => $this->setting_option_values['lesson_video_url'],
'default' => '',
'placeholder' => esc_html__( 'Input URL, iFrame, or shortcode here.', 'learndash' ),
'attrs' => array(
'rows' => '1',
'cols' => '57',
),
'parent_setting' => 'lesson_video_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_url',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Progression URL', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'text',
'default' => '',
),
),
),
),
'lesson_video_shown' => array(
'name' => 'lesson_video_shown',
'label' => esc_html__( 'Display Timing', 'learndash' ),
'type' => 'radio',
'value' => $this->setting_option_values['lesson_video_shown'],
'default' => 'AFTER',
'parent_setting' => 'lesson_video_enabled',
'options' => array(
'BEFORE' => array(
'label' => esc_html__( 'Before completed sub-steps', 'learndash' ),
'description' => sprintf(
// translators: placeholder: topic.
esc_html_x( 'The video will be shown and must be fully watched before the user can access the %s’s associated steps.', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
),
'AFTER' => array(
'label' => esc_html__( 'After completing sub-steps', 'learndash' ),
'description' => sprintf(
// translators: placeholder: topic, topic.
esc_html_x( 'The video will be visible after the user has completed the %1$s’s associated steps. The full video must be watched in order to complete the %2$s.', 'placeholder: topic, topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' ),
learndash_get_custom_label_lower( 'topic' )
),
'inline_fields' => array(
'lesson_video_display_timing_after' => $this->settings_sub_option_fields['video_display_timing_after_fields'],
),
'inner_section_state' => ( 'AFTER' === $this->setting_option_values['lesson_video_shown'] ) ? 'open' : 'closed',
),
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_shown',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Shown before or after sub-steps', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'default' => 'BEFORE',
'type' => 'string',
'enum' => array(
'BEFORE',
'AFTER',
),
),
),
),
),
'lesson_video_auto_start' => array(
'name' => 'lesson_video_auto_start',
'label' => esc_html__( 'Autostart', 'learndash' ),
'type' => 'checkbox-switch',
'value' => $this->setting_option_values['lesson_video_auto_start'],
'help_text' => esc_html__( 'Note, due to browser requirements videos will be automatically muted for autoplay to work.', 'learndash' ),
'default' => '',
'options' => array(
'on' => esc_html__( 'The video now starts automatically on page load', 'learndash' ),
'' => '',
),
'parent_setting' => 'lesson_video_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_auto_start',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Autostart', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_video_show_controls' => array(
'name' => 'lesson_video_show_controls',
'label' => esc_html__( 'Video Controls Display', 'learndash' ),
'type' => 'checkbox-switch',
'help_text' => esc_html__( 'Only available for YouTube and local videos.', 'learndash' ),
'value' => $this->setting_option_values['lesson_video_show_controls'],
'default' => '',
'options' => array(
'' => '',
'on' => esc_html__( 'Users can pause, move backward and forward within the video', 'learndash' ),
),
'parent_setting' => 'lesson_video_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_show_controls',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Video Controls Display. YouTube and local videos only', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_video_focus_pause' => array(
'name' => 'lesson_video_focus_pause',
'label' => esc_html__( 'Video Pause on Window Unfocused', 'learndash' ),
'type' => 'checkbox-switch',
'value' => $this->setting_option_values['lesson_video_focus_pause'],
'help_text' => esc_html__( 'Pause the video if user switches to a different window.', 'learndash' ),
'default' => '',
'options' => array(
'on' => '',
'' => '',
),
'parent_setting' => 'lesson_video_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_focus_pause',
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_video_track_time' => array(
'name' => 'lesson_video_track_time',
'label' => esc_html__( 'Video Resume', 'learndash' ),
'type' => 'checkbox-switch',
'value' => $this->setting_option_values['lesson_video_track_time'],
'help_text' => esc_html__( 'Allows user to resume video position. Uses browser cookie.', 'learndash' ),
'default' => '',
'options' => array(
'on' => '',
'' => '',
),
'parent_setting' => 'lesson_video_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'video_resume',
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_assignment_upload' => array(
'name' => 'lesson_assignment_upload',
'label' => esc_html__( 'Assignment Uploads', 'learndash' ),
'type' => 'checkbox-switch',
'default' => '',
'value' => $this->setting_option_values['lesson_assignment_upload'],
'options' => array(
'on' => array(
'label' => '',
'description' => '',
'tooltip' => sprintf(
// translators: placeholder: topic.
esc_html_x( 'Cannot be enabled while %s timer or Video progression are enabled', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
),
),
'child_section_state' => ( 'on' === $this->setting_option_values['lesson_assignment_upload'] ) ? 'open' : 'closed',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'assignment_upload_enabled',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Uploads Enabled', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'assignment_upload_limit_extensions' => array(
'name' => 'assignment_upload_limit_extensions',
'label' => esc_html__( 'File Extensions', 'learndash' ),
'type' => 'text',
'placeholder' => esc_html__( 'pdf, xls, zip', 'learndash' ),
'help_text' => esc_html__( 'Specify the type of files users can upload. Leave blank for any.', 'learndash' ),
'class' => '-small',
'default' => '',
'value' => $this->setting_option_values['assignment_upload_limit_extensions'],
'parent_setting' => 'lesson_assignment_upload',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Allowed file extensions. Comma separated pdf, xls, zip', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'text',
'default' => '',
),
),
),
),
'assignment_upload_limit_size' => array(
'name' => 'assignment_upload_limit_size',
'label' => esc_html__( 'File Size Limit', 'learndash' ),
'type' => 'text',
'class' => '-small',
'placeholder' => ini_get( 'upload_max_filesize' ),
'help_text' => sprintf(
// translators: placeholder: PHP file upload size.
esc_html_x( 'Default maximum file size supported is: %s', 'placeholder: PHP file upload size', 'learndash' ),
ini_get( 'upload_max_filesize' )
),
'default' => '',
'value' => $this->setting_option_values['assignment_upload_limit_size'],
'parent_setting' => 'lesson_assignment_upload',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%1$s Assignment Upload size limit. Max per server is %2$s ', 'placeholder: Topic, Upload size limit', 'learndash' ), learndash_get_custom_label( 'topic' ), ini_get( 'upload_max_filesize' ) ),
'type' => 'text',
'default' => '',
),
),
),
),
'lesson_assignment_points_enabled' => array(
'name' => 'lesson_assignment_points_enabled',
'label' => esc_html__( 'Points', 'learndash' ),
'type' => 'checkbox-switch',
'default' => 0,
'value' => $this->setting_option_values['lesson_assignment_points_enabled'],
'options' => array(
'on' => esc_html__( 'Award points for submitting assignments', 'learndash' ),
'' => '',
),
'parent_setting' => 'lesson_assignment_upload',
'child_section_state' => ( 'on' === $this->setting_option_values['lesson_assignment_points_enabled'] ) ? 'open' : 'closed',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'assignment_points_enabled',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Points Enabled', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'lesson_assignment_points_amount' => array(
'name' => 'lesson_assignment_points_amount',
'type' => 'number',
'class' => '-small',
'attrs' => array(
'step' => 1,
'min' => 0,
),
'default' => 0,
'value' => $this->setting_option_values['lesson_assignment_points_amount'],
'input_label' => esc_html__( 'available point(s)', 'learndash' ),
'parent_setting' => 'lesson_assignment_points_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'assignment_points_amount',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Points Amount', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'integer',
'default' => 0,
),
),
),
),
'auto_approve_assignment' => array(
'name' => 'auto_approve_assignment',
'label' => esc_html__( 'Grading Type', 'learndash' ),
'type' => 'radio',
'value' => $this->setting_option_values['auto_approve_assignment'],
'parent_setting' => 'lesson_assignment_upload',
'options' => array(
'on' => array(
'label' => esc_html__( 'Auto-approve', 'learndash' ),
'description' => esc_html__( 'No grading or approval needed. The assignment will be automatically approved and full points will be awarded.', 'learndash' ),
),
'' => array(
'label' => esc_html__( 'Manually grade', 'learndash' ),
'description' => sprintf(
// translators: placeholder: Group, topic.
esc_html_x( 'Admin or %1$s leader approval and grading required. The %2$s cannot be completed until the assignment is approved.', 'placeholder: Group, topic', 'learndash' ),
learndash_get_custom_label( 'group' ),
learndash_get_custom_label_lower( 'topic' )
),
'inline_fields' => array(
'lesson_assignment_grading_manual' => $this->settings_sub_option_fields['lesson_assignment_grading_manual_fields'],
),
'inner_section_state' => ( '' === $this->setting_option_values['auto_approve_assignment'] ) ? 'open' : 'closed',
),
),
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'assignment_auto_approve',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Assignment Auto-approve Enabled', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => true,
),
),
),
),
'forced_lesson_time_enabled' => array(
'name' => 'forced_lesson_time_enabled',
'label' => sprintf(
// translators: placeholder: Topic.
esc_html_x( '%s Timer', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
),
'default' => '',
'type' => 'checkbox-switch',
'value' => $this->setting_option_values['forced_lesson_time_enabled'],
'help_text' => sprintf(
// translators: placeholder: topic.
esc_html_x( 'The %s cannot be marked as completed until the set time has elapsed.', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
'options' => array(
'on' => array(
'label' => '',
'description' => '',
'tooltip' => esc_html__( 'Cannot be enabled while Video progression or Assignments are enabled', 'learndash' ),
),
),
'child_section_state' => ( 'on' === $this->setting_option_values['forced_lesson_time_enabled'] ) ? 'open' : 'closed',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'forced_timer_enabled',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Time Enabled', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'boolean',
'default' => false,
),
),
),
),
'forced_lesson_time' => array(
'name' => 'forced_lesson_time',
'type' => 'timer-entry',
'class' => 'small-text',
'default' => '',
'value' => $this->setting_option_values['forced_lesson_time'],
'parent_setting' => 'forced_lesson_time_enabled',
'rest' => array(
'show_in_rest' => LearnDash_REST_API::enabled(),
'rest_args' => array(
'schema' => array(
'field_key' => 'forced_timer_amount',
// translators: placeholder: Topic.
'description' => sprintf( esc_html_x( '%s Timer Amount.', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ),
'type' => 'integer',
'default' => 0,
),
),
),
),
);
/** This filter is documented in includes/settings/settings-metaboxes/class-ld-settings-metabox-course-access-settings.php */
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_metabox_key );
parent::load_settings_fields();
}
/**
* Update Metabox Settings values.
*
* @since 3.4.0
*
* @param array $settings_field_updates Array of key/value settings changes.
*/
public function apply_metabox_settings_fields_changes( $settings_field_updates = array() ) {
$settings_field_values = $this->get_settings_metabox_values();
if ( ! empty( $settings_field_updates ) ) {
$settings_changes_only = array();
foreach ( $settings_field_updates as $setting_key => $setting_value ) {
if ( isset( $settings_field_values[ $setting_key ] ) ) {
$settings_changes_only[ $setting_key ] = $setting_value;
}
}
if ( ! empty( $settings_changes_only ) ) {
if ( ( isset( $settings_changes_only['lesson_video_enabled'] ) ) && ( 'on' === $settings_changes_only['lesson_video_enabled'] ) ) {
$settings_changes_only['lesson_assignment_upload'] = '';
$settings_changes_only['forced_lesson_time_enabled'] = '';
} elseif ( ( isset( $settings_changes_only['lesson_assignment_upload'] ) ) && ( 'on' === $settings_changes_only['lesson_assignment_upload'] ) ) {
$settings_changes_only['lesson_video_enabled'] = '';
$settings_changes_only['forced_lesson_time_enabled'] = '';
} elseif ( ( isset( $settings_changes_only['forced_lesson_time_enabled'] ) ) && ( 'on' === $settings_changes_only['forced_lesson_time_enabled'] ) ) {
$settings_changes_only['lesson_video_enabled'] = '';
$settings_changes_only['lesson_assignment_upload'] = '';
} else {
$settings_changes_only['lesson_video_enabled'] = '';
$settings_changes_only['lesson_assignment_upload'] = '';
$settings_changes_only['forced_lesson_time_enabled'] = '';
}
foreach ( $settings_changes_only as $setting_key => $setting_value ) {
if ( isset( $settings_field_values[ $setting_key ] ) ) {
$settings_field_values[ $setting_key ] = $setting_value;
}
}
}
}
return $settings_field_values;
}
/**
* Filter settings values for metabox before save to database.
*
* @since 3.0.0
*
* @param array $settings_values Array of settings values.
* @param string $settings_metabox_key Metabox key.
* @param string $settings_screen_id Screen ID.
*
* @return array $settings_values.
*/
public function filter_saved_fields( $settings_values = array(), $settings_metabox_key = '', $settings_screen_id = '' ) {
if ( ( $settings_screen_id === $this->settings_screen_id ) && ( $settings_metabox_key === $this->settings_metabox_key ) ) {
if ( ( 'on' !== $settings_values['topic_materials_enabled'] ) || ( empty( $settings_values['topic_materials'] ) ) ) {
$settings_values['topic_materials_enabled'] = '';
$settings_values['topic_materials'] = '';
}
// If video progression is enables but the video URL is empty then turn off video progression.
if ( ( 'on' !== $settings_values['lesson_video_enabled'] ) || ( empty( $settings_values['lesson_video_url'] ) ) ) {
$settings_values['lesson_video_enabled'] = '';
$settings_values['lesson_video_url'] = '';
}
if ( ( 'on' !== $settings_values['forced_lesson_time_enabled'] ) || ( empty( $settings_values['forced_lesson_time'] ) ) ) {
$settings_values['forced_lesson_time_enabled'] = '';
$settings_values['forced_lesson_time'] = '';
}
if ( ( 'on' !== $settings_values['lesson_assignment_points_enabled'] ) || ( empty( $settings_values['lesson_assignment_points_amount'] ) ) ) {
$settings_values['lesson_assignment_points_amount'] = '';
$settings_values['lesson_assignment_points_enabled'] = '';
}
if ( 'on' === $settings_values['lesson_video_enabled'] ) {
$settings_values['lesson_assignment_upload'] = '';
$settings_values['forced_lesson_time_enabled'] = '';
} elseif ( 'on' === $settings_values['lesson_assignment_upload'] ) {
$settings_values['lesson_video_enabled'] = '';
$settings_values['forced_lesson_time_enabled'] = '';
} elseif ( 'on' === $settings_values['forced_lesson_time_enabled'] ) {
$settings_values['lesson_video_enabled'] = '';
$settings_values['lesson_assignment_upload'] = '';
} else {
$settings_values['lesson_video_enabled'] = '';
$settings_values['lesson_assignment_upload'] = '';
$settings_values['forced_lesson_time_enabled'] = '';
}
if ( 'on' !== $settings_values['lesson_video_enabled'] ) {
$settings_values['lesson_video_url'] = '';
$settings_values['lesson_video_shown'] = '';
$settings_values['lesson_video_auto_start'] = '';
$settings_values['lesson_video_show_controls'] = '';
$settings_values['lesson_video_focus_pause'] = '';
$settings_values['lesson_video_track_time'] = '';
$settings_values['lesson_video_auto_complete'] = '';
$settings_values['lesson_video_auto_complete_delay'] = '';
$settings_values['lesson_video_show_complete_button'] = '';
$settings_values['lesson_video_hide_complete_button'] = '';
}
if ( 'on' !== $settings_values['lesson_assignment_upload'] ) {
$settings_values['assignment_upload_limit_extensions'] = '';
$settings_values['assignment_upload_limit_size'] = '';
$settings_values['lesson_assignment_points_enabled'] = '';
$settings_values['lesson_assignment_points_amount'] = '';
$settings_values['assignment_upload_limit_count'] = '';
$settings_values['lesson_assignment_deletion_enabled'] = '';
$settings_values['auto_approve_assignment'] = '';
}
if ( 'on' !== $settings_values['forced_lesson_time_enabled'] ) {
$settings_values['forced_lesson_time_enabled'] = '';
$settings_values['forced_lesson_time'] = '';
}
if ( 'on' === $settings_values['lesson_video_enabled'] ) {
if ( ( 'on' === $settings_values['lesson_video_show_complete_button'] ) ) {
$settings_values['lesson_video_hide_complete_button'] = '';
} else {
$settings_values['lesson_video_hide_complete_button'] = 'on';
}
}
if ( 'on' === $settings_values['lesson_assignment_upload'] ) {
if ( ! empty( $settings_values['assignment_upload_limit_extensions'] ) ) {
$settings_values['assignment_upload_limit_extensions'] = learndash_validate_extensions( $settings_values['assignment_upload_limit_extensions'] );
}
if ( ! empty( $settings_values['assignment_upload_limit_size'] ) ) {
$limit_file_size = learndash_return_bytes_from_shorthand( $settings_values['assignment_upload_limit_size'] );
$wp_limit_file_size = wp_max_upload_size();
if ( $limit_file_size > $wp_limit_file_size ) {
$settings_values['assignment_upload_limit_size'] = '';
}
}
}
}
return $settings_values;
}
// End of functions.
}
add_filter(
'learndash_post_settings_metaboxes_init_' . learndash_get_post_type_slug( 'topic' ),
function( $metaboxes = array() ) {
if ( ( ! isset( $metaboxes['LearnDash_Settings_Metabox_Topic_Display_Content'] ) ) && ( class_exists( 'LearnDash_Settings_Metabox_Topic_Display_Content' ) ) ) {
$metaboxes['LearnDash_Settings_Metabox_Topic_Display_Content'] = LearnDash_Settings_Metabox_Topic_Display_Content::add_metabox_instance();
}
return $metaboxes;
},
50,
1
);
}