Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/gift-course/InitGift.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Initialize Gift Course
4
+
*
5
+
* @package TutorPro\GiftCourse
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 3.8.0
9
+
*/
10
+
11
+
namespace TutorPro\GiftCourse;
12
+
13
+
use TUTOR\Container;
14
+
15
+
/**
16
+
* Initialize gift course feature
17
+
*
18
+
* @since 3.8.0
19
+
*/
20
+
class InitGift {
21
+
22
+
/**
23
+
* Register hooks.
24
+
*
25
+
* @since 3.3.0
26
+
*/
27
+
public function __construct() {
28
+
add_filter( 'tutor/options/extend/attr', array( $this, 'gift_course_setting_field' ), 13 );
29
+
if ( ! $this->is_enabled() ) {
30
+
return;
31
+
}
32
+
33
+
$this->include_modules();
34
+
}
35
+
36
+
/**
37
+
* Add gift course settings field.
38
+
*
39
+
* @since 3.8.0
40
+
*
41
+
* @param array $attr attr.
42
+
*
43
+
* @return array
44
+
*/
45
+
public function gift_course_setting_field( $attr ) {
46
+
$attr['course']['blocks']['block_course']['fields'][] = array(
47
+
'key' => 'enable_gift_course',
48
+
'type' => 'toggle_switch',
49
+
'label' => __( 'Enable Course Gifting', 'tutor-pro' ),
50
+
'default' => 'off',
51
+
'desc' => __( 'Allow users to purchase and send courses as gifts.', 'tutor-pro' ),
52
+
);
53
+
54
+
return $attr;
55
+
}
56
+
57
+
/**
58
+
* Include modules
59
+
*
60
+
* @since 3.8.0
61
+
*
62
+
* @return void
63
+
*/
64
+
public function include_modules() {
65
+
$classes = array(
66
+
GiftCourse::class,
67
+
EventHandler::class,
68
+
GiftEnrollment::class,
69
+
GiftScheduler::class,
70
+
);
71
+
72
+
foreach ( $classes as $class ) {
73
+
Container::make( $class );
74
+
}
75
+
}
76
+
77
+
/**
78
+
* Check whether gift course is enabled & useable
79
+
*
80
+
* This method consider all the scenarios that should
81
+
* meet to use this feature
82
+
*
83
+
* @since 3.8.0
84
+
*
85
+
* @return boolean
86
+
*/
87
+
public function is_enabled(): bool {
88
+
// Gift course only works with woocommerce and tutor native.
89
+
$monetization = tutor_utils()->get_option( 'monetize_by' );
90
+
if ( 'tutor' !== $monetization && 'wc' !== $monetization ) {
91
+
return false;
92
+
}
93
+
94
+
$subscription_enabled = tutor_utils()->is_addon_enabled( 'subscription' );
95
+
if ( $subscription_enabled ) {
96
+
$membership_only_mode_enabled = tutor_utils()->get_option( 'membership_only_mode', false );
97
+
if ( $membership_only_mode_enabled ) {
98
+
return false;
99
+
}
100
+
}
101
+
102
+
$enable_gift_course = tutor_utils()->get_option( 'enable_gift_course', false );
103
+
if ( ! $enable_gift_course ) {
104
+
return false;
105
+
}
106
+
107
+
return true;
108
+
}
109
+
}
110
+