← All changes
|
inc/admin/settings/class-lp-settings-payments.php
+50
-13
4.1.7.2
→
4.4.9
View file →
| @@ -6,8 +6,11 @@ | ||
| 6 | 6 | * @package LearnPress/Admin/Classes |
| 7 | 7 | * @version 4.0.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | +use LearnPress\Helpers\Config; | |
| 11 | +use LearnPress\TemplateHooks\Admin\AdminSettingsPage; | |
| 12 | + | |
| 10 | 13 | defined( 'ABSPATH' ) || exit; |
| 11 | 14 | |
| 12 | 15 | /** |
| 13 | 16 | * Class LP_Settings_Payments |
| @@ -12,9 +15,8 @@ | ||
| 12 | 15 | /** |
| 13 | 16 | * Class LP_Settings_Payments |
| 14 | 17 | * |
| 15 | 18 | * Manage all payments are registered and settings to control order process. |
| 16 | - * | |
| 17 | 19 | */ |
| 18 | 20 | class LP_Settings_Payments extends LP_Abstract_Settings_Page { |
| 19 | 21 | /** |
| 20 | 22 | * Constructor |
| @@ -45,13 +47,13 @@ | ||
| 45 | 47 | * @return mixed |
| 46 | 48 | */ |
| 47 | 49 | public function get_sections() { |
| 48 | 50 | static $sections; |
| 49 | - | |
| 50 | - if ( ! $sections ) { | |
| 51 | + if ( is_null( $sections ) ) { | |
| 51 | 52 | $gateways = LP_Gateways::instance()->get_gateways(); |
| 52 | 53 | $sections = array( |
| 53 | 54 | 'general' => esc_html__( 'General', 'learnpress' ), |
| 55 | + 'refund' => esc_html__( 'Refund', 'learnpress' ), | |
| 54 | 56 | ); |
| 55 | 57 | |
| 56 | 58 | if ( $gateways ) { |
| 57 | 59 | foreach ( $gateways as $id => $gateway ) { |
| @@ -81,9 +83,9 @@ | ||
| 81 | 83 | 'title' => esc_html__( 'Guest checkout', 'learnpress' ), |
| 82 | 84 | 'id' => 'guest_checkout', |
| 83 | 85 | 'default' => 'no', |
| 84 | 86 | 'type' => 'checkbox', |
| 85 | - 'desc' => esc_html__( 'Enable guest checkout', 'learnpress' ), | |
| 87 | + 'desc' => esc_html__( 'Enable guest checkout.', 'learnpress' ), | |
| 86 | 88 | ), |
| 87 | 89 | array( |
| 88 | 90 | 'title' => esc_html__( 'Account login', 'learnpress' ), |
| 89 | 91 | 'id' => 'enable_login_checkout', |
| @@ -88,9 +90,9 @@ | ||
| 88 | 90 | 'title' => esc_html__( 'Account login', 'learnpress' ), |
| 89 | 91 | 'id' => 'enable_login_checkout', |
| 90 | 92 | 'default' => 'yes', |
| 91 | 93 | 'type' => 'checkbox', |
| 92 | - 'desc' => esc_html__( 'Enable login form in checkout', 'learnpress' ), | |
| 94 | + 'desc' => esc_html__( 'Enable the login form in the checkout.', 'learnpress' ), | |
| 93 | 95 | ), |
| 94 | 96 | array( |
| 95 | 97 | 'title' => esc_html__( 'Account creation', 'learnpress' ), |
| 96 | 98 | 'id' => 'enable_registration_checkout', |
| @@ -95,9 +97,9 @@ | ||
| 95 | 97 | 'title' => esc_html__( 'Account creation', 'learnpress' ), |
| 96 | 98 | 'id' => 'enable_registration_checkout', |
| 97 | 99 | 'default' => 'yes', |
| 98 | 100 | 'type' => 'checkbox', |
| 99 | - 'desc' => esc_html__( 'Enable register form in checkout', 'learnpress' ), | |
| 101 | + 'desc' => esc_html__( 'Enable the register form in the checkout.', 'learnpress' ), | |
| 100 | 102 | ), |
| 101 | 103 | ) |
| 102 | 104 | ); |
| 103 | 105 | |
| @@ -129,18 +131,43 @@ | ||
| 129 | 131 | |
| 130 | 132 | return apply_filters( 'learn-press/payment-settings', array_merge( $guest, $enpoints, $payment ) ); |
| 131 | 133 | } |
| 132 | 134 | |
| 133 | - public function admin_page_settings( $section = null, $tab = null ) { | |
| 134 | - $sections = array(); | |
| 135 | - $items = LP_Admin_Menu::instance()->get_menu_items(); | |
| 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 | + } | |
| 136 | 143 | |
| 137 | - if ( ! empty( $items['settings'] ) ) { | |
| 138 | - $tab = $items['settings']->get_active_tab(); | |
| 139 | - $section = $items['settings']->get_active_section(); | |
| 140 | - $sections = $items['settings']->get_sections(); | |
| 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}" ); | |
| 141 | 161 | } |
| 142 | 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(); | |
| 143 | 170 | $section_data = ! empty( $sections[ $section ] ) ? $sections[ $section ] : false; |
| 144 | 171 | |
| 145 | 172 | if ( $section_data instanceof LP_Abstract_Settings ) { |
| 146 | 173 | $section_data->admin_option_settings(); |
| @@ -157,8 +184,18 @@ | ||
| 157 | 184 | * @param string $section |
| 158 | 185 | * @param string $tab |
| 159 | 186 | */ |
| 160 | 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 ) { | |
| 161 | 198 | parent::admin_page_settings( $section, $tab ); |
| 162 | 199 | } |
| 163 | 200 | } |
| 164 | 201 | |