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