class-wc-settings-integrations.php
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* WooCommerce Integration Settings
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Settings_Integrations' ) ) :
/**
* WC_Settings_Integrations.
*/
class WC_Settings_Integrations extends WC_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'integration';
$this->label = __( 'Integration', 'woocommerce' );
if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) {
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
}
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
global $current_section;
$sections = array();
if ( ! defined( 'WC_INSTALLING' ) ) {
$integrations = WC()->integrations->get_integrations();
if ( ! $current_section && ! empty( $integrations ) ) {
$current_section = current( $integrations )->id;
}
if ( sizeof( $integrations ) > 1 ) {
foreach ( $integrations as $integration ) {
$title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
$sections[ strtolower( $integration->id ) ] = esc_html( $title );
}
}
}
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
$integrations = WC()->integrations->get_integrations();
if ( isset( $integrations[ $current_section ] ) )
$integrations[ $current_section ]->admin_options();
}
}
endif;
return new WC_Settings_Integrations();