1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WooCommerce Settings Page/Tab |
4
|
|
|
* |
5
|
|
|
* @author WooThemes |
6
|
|
|
* @category Admin |
7
|
|
|
* @package WooCommerce/Admin |
8
|
|
|
* @version 2.1.0 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; // Exit if accessed directly |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
if ( ! class_exists( 'WC_Settings_Page' ) ) : |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* WC_Settings_Page. |
19
|
|
|
*/ |
20
|
|
|
abstract class WC_Settings_Page { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Setting page id. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $id = ''; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Setting page label. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $label = ''; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
*/ |
39
|
|
|
public function __construct() { |
40
|
|
|
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
41
|
|
|
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); |
42
|
|
|
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); |
43
|
|
|
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get settings page ID. |
48
|
|
|
* @since 2.7.0 |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function get_id() { |
52
|
|
|
return $this->id; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get settings page label. |
57
|
|
|
* @since 2.7.0 |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function get_label() { |
61
|
|
|
return $this->label; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Add this page to settings. |
66
|
|
|
*/ |
67
|
|
|
public function add_settings_page( $pages ) { |
68
|
|
|
$pages[ $this->id ] = $this->label; |
69
|
|
|
|
70
|
|
|
return $pages; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get settings array. |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function get_settings() { |
79
|
|
|
return apply_filters( 'woocommerce_get_settings_' . $this->id, array() ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get sections. |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function get_sections() { |
88
|
|
|
return apply_filters( 'woocommerce_get_sections_' . $this->id, array() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Output sections. |
93
|
|
|
*/ |
94
|
|
|
public function output_sections() { |
95
|
|
|
global $current_section; |
96
|
|
|
|
97
|
|
|
$sections = $this->get_sections(); |
98
|
|
|
|
99
|
|
|
if ( empty( $sections ) || 1 === sizeof( $sections ) ) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
echo '<ul class="subsubsub">'; |
104
|
|
|
|
105
|
|
|
$array_keys = array_keys( $sections ); |
106
|
|
|
|
107
|
|
|
foreach ( $sections as $id => $label ) { |
108
|
|
|
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>'; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
echo '</ul><br class="clear" />'; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Output the settings. |
116
|
|
|
*/ |
117
|
|
|
public function output() { |
118
|
|
|
$settings = $this->get_settings(); |
119
|
|
|
|
120
|
|
|
WC_Admin_Settings::output_fields( $settings ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Save settings. |
125
|
|
|
*/ |
126
|
|
|
public function save() { |
127
|
|
|
global $current_section; |
128
|
|
|
|
129
|
|
|
$settings = $this->get_settings(); |
130
|
|
|
WC_Admin_Settings::save_fields( $settings ); |
131
|
|
|
|
132
|
|
|
if ( $current_section ) { |
133
|
|
|
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section ); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
endif; |
139
|
|
|
|