views
1 month ago
class-wc-settings-accounts.php
5 months ago
class-wc-settings-advanced.php
1 month ago
class-wc-settings-checkout.php
5 years ago
class-wc-settings-emails.php
1 month ago
class-wc-settings-general.php
1 month ago
class-wc-settings-integrations.php
1 year ago
class-wc-settings-page.php
1 week ago
class-wc-settings-payment-gateways.php
1 week ago
class-wc-settings-point-of-sale.php
3 months ago
class-wc-settings-products.php
1 month ago
class-wc-settings-shipping.php
3 months ago
class-wc-settings-site-visibility.php
2 years ago
class-wc-settings-tax.php
5 months ago
class-wc-settings-integrations.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Integration Settings |
| 4 | * |
| 5 | * @package WooCommerce\Admin |
| 6 | * @version 2.1.0 |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Constants; |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | if ( ! class_exists( 'WC_Settings_Integrations', false ) ) : |
| 14 | |
| 15 | /** |
| 16 | * WC_Settings_Integrations. |
| 17 | */ |
| 18 | class WC_Settings_Integrations extends WC_Settings_Page { |
| 19 | |
| 20 | /** |
| 21 | * Constructor. |
| 22 | */ |
| 23 | public function __construct() { |
| 24 | $this->id = 'integration'; |
| 25 | $this->label = __( 'Integration', 'woocommerce' ); |
| 26 | |
| 27 | if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) { |
| 28 | parent::__construct(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Setting page icon. |
| 34 | * |
| 35 | * @var string |
| 36 | */ |
| 37 | public $icon = 'plugins'; |
| 38 | |
| 39 | /** |
| 40 | * Get own sections. |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | protected function get_own_sections() { |
| 45 | global $current_section; |
| 46 | |
| 47 | $sections = array(); |
| 48 | |
| 49 | if ( ! $this->wc_is_installing() ) { |
| 50 | $integrations = $this->get_integrations(); |
| 51 | |
| 52 | if ( ! $current_section && ! empty( $integrations ) ) { |
| 53 | $current_section = current( $integrations )->id; |
| 54 | } |
| 55 | |
| 56 | if ( count( $integrations ) > 1 ) { |
| 57 | foreach ( $integrations as $integration ) { |
| 58 | $title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title; |
| 59 | $sections[ strtolower( $integration->id ) ] = esc_html( $title ); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return $sections; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Is WC_INSTALLING constant defined? |
| 69 | * This method exists to ease unit testing. |
| 70 | * |
| 71 | * @return bool True is the WC_INSTALLING constant is defined. |
| 72 | */ |
| 73 | protected function wc_is_installing() { |
| 74 | return Constants::is_defined( 'WC_INSTALLING' ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get the currently available integrations. |
| 79 | * This method exists to ease unit testing. |
| 80 | * |
| 81 | * @return array Currently available integrations. |
| 82 | */ |
| 83 | protected function get_integrations() { |
| 84 | return WC()->integrations->get_integrations(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Output the settings. |
| 89 | */ |
| 90 | public function output() { |
| 91 | global $current_section; |
| 92 | |
| 93 | $integrations = $this->get_integrations(); |
| 94 | |
| 95 | if ( isset( $integrations[ $current_section ] ) ) { |
| 96 | $integrations[ $current_section ]->admin_options(); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | endif; |
| 102 | |
| 103 | return new WC_Settings_Integrations(); |
| 104 |