Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/addons/subscription/src/Settings.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Manage settings related to subscriptions.
4 + *
5 + * @package TutorPro\Subscription
6 + * @author Themeum <support@themeum.com>
7 + * @link https://themeum.com
8 + * @since 3.0.0
9 + */
10 +
11 + namespace TutorPro\Subscription;
12 +
13 + /**
14 + * Settings Class.
15 + *
16 + * @since 3.0.0
17 + */
18 + class Settings {
19 + const PRICING_PAGE_SLUG = 'membership-pricing';
20 + const PRICING_PAGE_OPTION_NAME = 'membership_pricing_page_id';
21 +
22 + /**
23 + * Constructor.
24 + *
25 + * @since 3.0.0
26 + */
27 + public function __construct() {
28 + add_action( 'tutor_before_ecommerce_payment_settings', array( $this, 'add_subscription_settings' ) );
29 + add_action( 'tutor_pages', array( $this, 'add_pricing_page' ), 10, 1 );
30 + add_action( 'tutor_after_option_sub_section', array( $this, 'add_membership_only_mode_consent_modal' ) );
31 + }
32 +
33 + /**
34 + * Get membership pricing page ID
35 + *
36 + * @since 3.2.0
37 + *
38 + * @return string
39 + */
40 + public static function get_pricing_page_id() {
41 + return (int) tutor_utils()->get_option( self::PRICING_PAGE_OPTION_NAME );
42 + }
43 +
44 + /**
45 + * Get membership pricing page URL
46 + *
47 + * @since 3.2.0
48 + *
49 + * @return string
50 + */
51 + public static function get_pricing_page_url() {
52 + $page_id = self::get_pricing_page_id();
53 + return $page_id ? get_permalink( $page_id ) : '';
54 + }
55 +
56 + /**
57 + * Add pricing page
58 + *
59 + * @since 2.1.0
60 + *
61 + * @param array $pages page list.
62 + *
63 + * @return array
64 + */
65 + public function add_pricing_page( array $pages ) {
66 + return $pages + array( self::PRICING_PAGE_OPTION_NAME => __( 'Membership Pricing', 'tutor-pro' ) );
67 + }
68 +
69 + /**
70 + * Check membership-only mode enabled.
71 + *
72 + * @since 3.3.0
73 + *
74 + * @return bool
75 + */
76 + public static function membership_only_mode_enabled() {
77 + return (bool) tutor_utils()->get_option( 'membership_only_mode', false );
78 + }
79 +
80 + /**
81 + * Add subscription settings.
82 + *
83 + * @since 3.0.0
84 + *
85 + * @param array $arr array.
86 + *
87 + * @return array
88 + */
89 + public function add_subscription_settings( $arr ) {
90 + $pages = tutor_utils()->get_pages();
91 +
92 + $arr['ecommerce_subscription'] = array(
93 + 'label' => __( 'Subscriptions', 'tutor-pro' ),
94 + 'slug' => 'ecommerce_subscription',
95 + 'desc' => __( 'Subscription Settings', 'tutor-pro' ),
96 + 'template' => 'basic',
97 + 'icon' => 'tutor-icon-subscription',
98 + 'blocks' => array(
99 + array(
100 + 'label' => __( 'Membership Plans', 'tutor-pro' ),
101 + 'block_type' => 'custom',
102 + 'slug' => 'memberships',
103 + 'template_path' => Utils::template_path( 'membership-settings-block.php' ),
104 + ),
105 + array(
106 + 'label' => __( 'Options', 'tutor-pro' ),
107 + 'block_type' => 'uniform',
108 + 'slug' => 'options',
109 + 'fields' => array(
110 + array(
111 + 'key' => self::PRICING_PAGE_OPTION_NAME,
112 + 'type' => 'select',
113 + 'label' => __( 'Pricing Page', 'tutor-pro' ),
114 + 'default' => '0',
115 + 'options' => $pages,
116 + 'desc' => __( 'Select the Membership pricing page.', 'tutor-pro' ),
117 + 'searchable' => true,
118 + ),
119 + array(
120 + 'key' => 'subscription_cancel_anytime',
121 + 'type' => 'toggle_switch',
122 + 'label' => __( 'Cancel Anytime', 'tutor-pro' ),
123 + 'label_title' => '',
124 + 'default' => 'on',
125 + 'desc' => __( 'Allow students to cancel their subscriptions whenever they want.', 'tutor-pro' ),
126 + ),
127 + array(
128 + 'key' => 'subscription_early_renewal',
129 + 'type' => 'toggle_switch',
130 + 'label' => __( 'Early Renewal', 'tutor-pro' ),
131 + 'label_title' => '',
132 + 'default' => 'off',
133 + 'desc' => __( 'Allow students to renew their subscriptions before next payment date.', 'tutor-pro' ),
134 + ),
135 + array(
136 + 'key' => 'membership_only_mode',
137 + 'type' => 'toggle_switch',
138 + 'label' => __( 'Membership-Only Mode', 'tutor-pro' ),
139 + 'label_title' => '',
140 + 'default' => 'off',
141 + 'desc' => __( 'Enable this to sell courses exclusively through membership plans. Individual course sales will be disabled.', 'tutor-pro' ),
142 + ),
143 + array(
144 + 'key' => 'allow_trial_checkout_without_payment',
145 + 'type' => 'toggle_switch',
146 + 'label' => __( 'Skip Payment for Free Trials', 'tutor-pro' ),
147 + 'label_title' => '',
148 + 'default' => 'off',
149 + 'desc' => __( 'Allow students to skip the payment gateway when the trial price is set to zero.', 'tutor-pro' ),
150 + ),
151 + ),
152 + ),
153 + ),
154 + );
155 +
156 + return $arr;
157 + }
158 +
159 + /**
160 + * Membership only mode consent modal content.
161 + *
162 + * @since 3.3.0
163 + *
164 + * @param string $key key.
165 + *
166 + * @return void
167 + */
168 + public function add_membership_only_mode_consent_modal( $key ) {
169 + if ( 'ecommerce_subscription' === $key ) {
170 + tutor_load_template_from_custom_path( Utils::template_path( 'membership-only-mode-modal.php' ) );
171 + }
172 + }
173 + }
174 +