Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/addons/course-bundle/src/Init.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Course Bundle Addon Init
4 + *
5 + * @package TutorPro\CourseBundle
6 + * @author Themeum <support@themeum.com>
7 + * @link https://themeum.com
8 + * @since 2.2.0
9 + */
10 +
11 + namespace TutorPro\CourseBundle;
12 +
13 + use TutorPro\CourseBundle\Backend\BundleList;
14 + use TutorPro\CourseBundle\Backend\Menu;
15 + use TutorPro\CourseBundle\CustomPosts\ManagePostMeta;
16 + use TutorPro\CourseBundle\CustomPosts\RegisterPosts;
17 + use TutorPro\CourseBundle\Frontend\BundleArchive;
18 + use TutorPro\CourseBundle\Frontend\BundleBuilder;
19 + use TutorPro\CourseBundle\Frontend\BundleDetails;
20 + use TutorPro\CourseBundle\Frontend\Dashboard;
21 + use TutorPro\CourseBundle\Frontend\DashboardMenu;
22 + use TutorPro\CourseBundle\Frontend\Enrollments;
23 + use TutorPro\CourseBundle\Frontend\MyBundleList;
24 + use TutorPro\CourseBundle\Integrations\WooCommerce;
25 +
26 + /**
27 + * Init Class
28 + *
29 + * @since 2.2.0
30 + */
31 + class Init {
32 +
33 + /**
34 + * Register hooks and dependencies.
35 + *
36 + * @since 2.2.0
37 + *
38 + * @return void
39 + */
40 + public function __construct() {
41 + if ( ! function_exists( 'tutor' ) ) {
42 + return;
43 + }
44 +
45 + add_filter( 'tutor_addons_lists_config', __CLASS__ . '::register_addon' );
46 +
47 + // Return if addon not enabled.
48 + if ( ! self::is_addon_enabled() ) {
49 + return;
50 + }
51 +
52 + // Return if has monetization requirement.
53 + $active_monetization = tutor_utils()->get_option( 'monetize_by', false );
54 + $required_monetizations = array( 'wc', 'tutor', 'free' );
55 + if ( ! in_array( $active_monetization, $required_monetizations ) ) {
56 + return;
57 + }
58 +
59 + $this->include_files();
60 +
61 + // Class instances.
62 + new Assets();
63 + new Menu();
64 + new Dashboard();
65 + new RegisterPosts();
66 + new BundleList();
67 + new MyBundleList();
68 + new Ajax();
69 + new ManagePostMeta();
70 + new BundleArchive();
71 + new BundleDetails();
72 + new BundleBuilder();
73 + new Enrollments();
74 +
75 + // Integrations.
76 + new WooCommerce();
77 + }
78 +
79 + /**
80 + * Register course bundle addon
81 + *
82 + * @since 2.2.0
83 + *
84 + * @param array $addons array of addons.
85 + *
86 + * @return array
87 + */
88 + public static function register_addon( $addons ) {
89 + $required_settings = self::has_required_monetization();
90 +
91 + $new_addon = array(
92 + 'name' => __( 'Course Bundle', 'tutor-pro' ),
93 + 'description' => __( 'Group multiple courses to sell together.', 'tutor-pro' ),
94 + 'path' => TUTOR_COURSE_BUNDLE_DIR,
95 + 'basename' => plugin_basename( TUTOR_COURSE_BUNDLE_FILE ),
96 + 'url' => plugin_dir_url( TUTOR_COURSE_BUNDLE_FILE ),
97 + 'required_settings' => $required_settings['has'],
98 + 'required_title' => $required_settings['title'],
99 + 'required_message' => $required_settings['message'],
100 + );
101 +
102 + $addons[ plugin_basename( $new_addon['basename'] ) ] = $new_addon;
103 +
104 + return $addons;
105 + }
106 +
107 + /**
108 + * Check whether addon is enabled or not.
109 + *
110 + * @return boolean
111 + */
112 + public static function is_addon_enabled() {
113 + $basename = plugin_basename( TUTOR_COURSE_BUNDLE_FILE );
114 + $is_enabled = tutor_utils()->is_addon_enabled( $basename );
115 + return $is_enabled;
116 + }
117 +
118 + /**
119 + * Check whether required monetization has enabled
120 + *
121 + * @since 2.2.0
122 + *
123 + * @return array of required settings & additional info
124 + */
125 + private static function has_required_monetization(): array {
126 + $monetization = tutor_utils()->get_option( 'monetize_by', false );
127 +
128 + return array(
129 + 'has' => 'wc' === $monetization || tutor_utils()->is_monetize_by_tutor() || 'free' === $monetization ? false : true,
130 + 'title' => __( 'Requires WooCommerce/Native Monetization to be enabled.', 'tutor-pro' ),
131 + 'message' => __( 'Choose WooCommerce/Native Payment from the eCommerce engine option in the settings', 'tutor-pro' ),
132 + );
133 + }
134 +
135 + /**
136 + * Include files.
137 + *
138 + * @since 2.2.0
139 + *
140 + * @return void
141 + */
142 + private function include_files() {
143 +
144 + }
145 +
146 + }
147 +