PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.2
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / admin / settings / class-lp-settings-payments.php

class-lp-settings-payments.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.2, at inc/admin/settings/class-lp-settings-payments.php

214 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class LP_Settings_Payment
4 *
5 * @author ThimPress
6 * @package LearnPress/Admin/Classes
7 * @version 4.0.0
8 */
9
10 use LearnPress\Helpers\Config;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Class LP_Settings_Payments
16 *
17 * Manage all payments are registered and settings to control order process.
18 */
19 class LP_Settings_Payments extends LP_Abstract_Settings_Page {
20 /**
21 * Constructor
22 */
23 public function __construct() {
24 $this->id = 'payments';
25 $this->text = esc_html__( 'Payments', 'learnpress' );
26
27 parent::__construct();
28
29 add_filter( 'learn-press/admin/submenu-section-title', array( $this, 'custom_section_title' ), 10, 2 );
30 }
31
32 public function custom_section_title( $title, $slug ) {
33 $sections = $this->get_sections();
34
35 if ( ! empty( $sections[ $slug ] ) && $sections[ $slug ] instanceof LP_Gateway_Abstract ) {
36 $title = $title . sprintf( '<span class="learn-press-tooltip" data-tooltip="%s"></span>', esc_attr( $sections[ $slug ]->get_method_description() ) );
37 }
38
39 return $title;
40 }
41
42 /**
43 * Get sections.
44 * Add a general section and each registered payment is a section.
45 *
46 * @return mixed
47 */
48 public function get_sections() {
49 static $sections;
50 if ( is_null( $sections ) ) {
51 $gateways = LP_Gateways::instance()->get_gateways();
52 $sections = array(
53 'general' => esc_html__( 'General', 'learnpress' ),
54 'refund' => esc_html__( 'Refund', 'learnpress' ),
55 );
56
57 if ( $gateways ) {
58 foreach ( $gateways as $id => $gateway ) {
59 $sections[ $id ] = $gateway;
60 }
61 }
62 }
63
64 return $sections;
65 }
66
67 /**
68 * Settings fields of general section.
69 *
70 * @return mixed
71 */
72 public function get_settings_general() {
73 $checkout_url = learn_press_get_checkout_url();
74
75 $guest = apply_filters(
76 'learn-press/payment-settings/general',
77 array(
78 array(
79 'type' => 'title',
80 ),
81 array(
82 'title' => esc_html__( 'Guest checkout', 'learnpress' ),
83 'id' => 'guest_checkout',
84 'default' => 'no',
85 'type' => 'checkbox',
86 'desc' => esc_html__( 'Enable guest checkout.', 'learnpress' ),
87 ),
88 array(
89 'title' => esc_html__( 'Account login', 'learnpress' ),
90 'id' => 'enable_login_checkout',
91 'default' => 'yes',
92 'type' => 'checkbox',
93 'desc' => esc_html__( 'Enable the login form in the checkout.', 'learnpress' ),
94 ),
95 array(
96 'title' => esc_html__( 'Account creation', 'learnpress' ),
97 'id' => 'enable_registration_checkout',
98 'default' => 'yes',
99 'type' => 'checkbox',
100 'desc' => esc_html__( 'Enable the register form in the checkout.', 'learnpress' ),
101 ),
102 )
103 );
104
105 $enpoints = apply_filters(
106 'learn-press/payment-settings/checkout-endpoints',
107 array(
108 array(
109 'title' => esc_html__( 'Custom order slug', 'learnpress' ),
110 'id' => 'checkout_endpoints[lp_order_received]',
111 'default' => 'lp-order-received',
112 'placeholder' => 'lp-order-received',
113 'type' => 'text',
114 'desc' => sprintf( 'e.g. %s', "{$checkout_url}<code>" . LP_Settings::instance()->get( 'checkout_endpoints.lp_order_received', 'lp-order-received' ) . '</code>' ),
115 ),
116 )
117 );
118
119 $payment = array(
120 array(
121 'title' => esc_html__( 'Payments', 'learnpress' ),
122 'id' => 'payment_order',
123 'default' => '',
124 'type' => 'payment-order',
125 ),
126 array(
127 'type' => 'sectionend',
128 ),
129 );
130
131 return apply_filters( 'learn-press/payment-settings', array_merge( $guest, $enpoints, $payment ) );
132 }
133
134 /**
135 * Settings fields of refund section.
136 *
137 * @return array
138 */
139 public function get_settings_refund() {
140 return Config::instance()->get( 'refund', 'settings/payments' );
141 }
142
143 /**
144 * Keep refund option names compatible with the former general settings fields.
145 *
146 * @param string $name Field name.
147 *
148 * @return mixed
149 */
150 public function get_admin_field_name( $name ) {
151 $items = LP_Admin_Menu::instance()->get_menu_items();
152 $tab = '';
153 $section = '';
154
155 if ( ! empty( $items['settings'] ) ) {
156 $tab = $items['settings']->get_active_tab();
157 $section = $items['settings']->get_active_section();
158 }
159
160 if ( 'payments' === $tab && 'refund' === $section ) {
161 if ( empty( $name ) ) {
162 $name = md5( microtime( true ) );
163 }
164
165 return apply_filters( 'learn_press_settings_field_name_' . $name, "learn_press_{$name}" );
166 }
167
168 return parent::get_admin_field_name( $name );
169 }
170
171 public function admin_page_settings( $section = null, $tab = null ) {
172 $sections = array();
173 $items = LP_Admin_Menu::instance()->get_menu_items();
174
175 if ( ! empty( $items['settings'] ) ) {
176 $tab = $items['settings']->get_active_tab();
177 $section = $items['settings']->get_active_section();
178 $sections = $items['settings']->get_sections();
179 }
180
181 $section_data = ! empty( $sections[ $section ] ) ? $sections[ $section ] : false;
182
183 if ( $section_data instanceof LP_Abstract_Settings ) {
184 $section_data->admin_option_settings();
185 } elseif ( is_callable( array( $this, 'admin_options_' . $section ) ) ) {
186 call_user_func_array( array( $this, 'admin_options_' . $section ), array( $section, $tab ) );
187 } else {
188 do_action( 'learn-press/admin/setting-payments/admin-options-' . $section, $tab );
189 }
190 }
191
192 /**
193 * Output admin option of general page.
194 *
195 * @param string $section
196 * @param string $tab
197 */
198 public function admin_options_general( $section, $tab ) {
199 parent::admin_page_settings( $section, $tab );
200 }
201
202 /**
203 * Output admin option of refund page.
204 *
205 * @param string $section
206 * @param string $tab
207 */
208 public function admin_options_refund( $section, $tab ) {
209 parent::admin_page_settings( $section, $tab );
210 }
211 }
212
213 return new LP_Settings_Payments();
214