1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Manages breadcrumb administration settings. |
4
|
|
|
*/ |
5
|
|
|
class Carbon_Breadcrumb_Admin_Settings { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Registered fields. |
9
|
|
|
* |
10
|
|
|
* @access protected |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
public $fields = array(); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Constructor. |
17
|
|
|
* |
18
|
|
|
* Initialize the administration breadcrumb settings. |
19
|
|
|
* |
20
|
|
|
* @access public |
21
|
|
|
*/ |
22
|
1 |
|
public function __construct() { |
23
|
|
|
// register settings page |
24
|
1 |
|
add_action( 'admin_menu', array( $this, 'admin_menu' ), 30 ); |
25
|
|
|
|
26
|
|
|
// register settings fields & sections |
27
|
1 |
|
add_action( 'admin_init', array( $this, 'register_settings' ) ); |
28
|
1 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get field data. Defines and describes the fields that will be registered. |
32
|
|
|
* |
33
|
|
|
* @access public |
34
|
|
|
* @static |
35
|
|
|
* |
36
|
|
|
* @return array $fields The fields and their data. |
37
|
|
|
*/ |
38
|
1 |
|
public static function get_field_data() { |
39
|
|
|
return array( |
40
|
|
|
'glue' => array( |
41
|
1 |
|
'type' => 'text', |
42
|
1 |
|
'title' => __( 'Glue', 'carbon_breadcrumbs' ), |
43
|
1 |
|
'default' => ' > ', |
44
|
1 |
|
'help' => __( 'This is displayed between the breadcrumb items.', 'carbon_breadcrumbs' ), |
45
|
1 |
|
), |
46
|
|
|
'link_before' => array( |
47
|
1 |
|
'type' => 'text', |
48
|
1 |
|
'title' => __( 'Link Before', 'carbon_breadcrumbs' ), |
49
|
1 |
|
'default' => '', |
50
|
1 |
|
'help' => __( 'This is displayed before the breadcrumb item link.', 'carbon_breadcrumbs' ), |
51
|
1 |
|
), |
52
|
|
|
'link_after' => array( |
53
|
1 |
|
'type' => 'text', |
54
|
1 |
|
'title' => __( 'Link After', 'carbon_breadcrumbs' ), |
55
|
1 |
|
'default' => '', |
56
|
1 |
|
'help' => __( 'This is displayed after the breadcrumb item link.', 'carbon_breadcrumbs' ), |
57
|
1 |
|
), |
58
|
|
|
'wrapper_before' => array( |
59
|
1 |
|
'type' => 'text', |
60
|
1 |
|
'title' => __( 'Wrapper Before', 'carbon_breadcrumbs' ), |
61
|
1 |
|
'default' => '', |
62
|
1 |
|
'help' => __( 'This is displayed before displaying the breadcrumb items.', 'carbon_breadcrumbs' ), |
63
|
1 |
|
), |
64
|
|
|
'wrapper_after' => array( |
65
|
1 |
|
'type' => 'text', |
66
|
1 |
|
'title' => __( 'Wrapper After', 'carbon_breadcrumbs' ), |
67
|
1 |
|
'default' => '', |
68
|
1 |
|
'help' => __( 'This is displayed after displaying the breadcrumb items.', 'carbon_breadcrumbs' ), |
69
|
1 |
|
), |
70
|
|
|
'title_before' => array( |
71
|
1 |
|
'type' => 'text', |
72
|
1 |
|
'title' => __( 'Title Before', 'carbon_breadcrumbs' ), |
73
|
1 |
|
'default' => '', |
74
|
1 |
|
'help' => __( 'This is displayed before the breadcrumb item title.', 'carbon_breadcrumbs' ), |
75
|
1 |
|
), |
76
|
|
|
'title_after' => array( |
77
|
1 |
|
'type' => 'text', |
78
|
1 |
|
'title' => __( 'Title After', 'carbon_breadcrumbs' ), |
79
|
1 |
|
'default' => '', |
80
|
1 |
|
'help' => __( 'This is displayed after the breadcrumb item title.', 'carbon_breadcrumbs' ), |
81
|
1 |
|
), |
82
|
|
|
'min_items' => array( |
83
|
1 |
|
'type' => 'text', |
84
|
1 |
|
'title' => __( 'Min Items', 'carbon_breadcrumbs' ), |
85
|
1 |
|
'default' => 2, |
86
|
1 |
|
'help' => __( 'Determines the minimum number of items, required to display the breadcrumb trail.', 'carbon_breadcrumbs' ), |
87
|
1 |
|
), |
88
|
|
|
'last_item_link' => array( |
89
|
1 |
|
'type' => 'checkbox', |
90
|
1 |
|
'title' => __( 'Last Item Link', 'carbon_breadcrumbs' ), |
91
|
1 |
|
'default' => true, |
92
|
1 |
|
'help' => __( 'Whether the last breadcrumb item should be a link.', 'carbon_breadcrumbs' ), |
93
|
1 |
|
), |
94
|
|
|
'display_home_item' => array( |
95
|
1 |
|
'type' => 'checkbox', |
96
|
1 |
|
'title' => __( 'Display Home Item?', 'carbon_breadcrumbs' ), |
97
|
1 |
|
'default' => true, |
98
|
1 |
|
'help' => __( 'Whether the home breadcrumb item should be displayed.', 'carbon_breadcrumbs' ), |
99
|
1 |
|
), |
100
|
|
|
'home_item_title' => array( |
101
|
1 |
|
'type' => 'text', |
102
|
1 |
|
'title' => __( 'Home Item Title', 'carbon_breadcrumbs' ), |
103
|
1 |
|
'default' => __( 'Home', 'carbon_breadcrumbs' ), |
104
|
1 |
|
'help' => __( 'Determines the title of the home item.', 'carbon_breadcrumbs' ), |
105
|
1 |
|
), |
106
|
1 |
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Name of the settings page. |
111
|
|
|
* |
112
|
|
|
* @access public |
113
|
|
|
* @static |
114
|
|
|
* |
115
|
|
|
* @return string $name The name of the options page. |
116
|
|
|
*/ |
117
|
1 |
|
public static function get_page_name() { |
118
|
1 |
|
return 'carbon_breadcrumbs_settings'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Title of the settings page. |
123
|
|
|
* |
124
|
|
|
* @access public |
125
|
|
|
* @static |
126
|
|
|
* |
127
|
|
|
* @return string $title The title of the options page. |
128
|
|
|
*/ |
129
|
1 |
|
public static function get_page_title() { |
130
|
1 |
|
return __( 'Carbon Breadcrumbs', 'carbon_breadcrumbs' ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Register the settings page & default section. |
135
|
|
|
* |
136
|
|
|
* @access public |
137
|
|
|
*/ |
138
|
2 |
|
public function admin_menu() { |
139
|
|
|
|
140
|
|
|
// register settings page |
141
|
2 |
|
add_options_page( |
142
|
2 |
|
self::get_page_title(), |
143
|
2 |
|
self::get_page_title(), |
144
|
2 |
|
'manage_options', |
145
|
2 |
|
self::get_page_name(), |
146
|
2 |
|
array( $this, 'settings_page' ) |
147
|
2 |
|
); |
148
|
|
|
|
149
|
|
|
// register settings section |
150
|
2 |
|
add_settings_section( |
151
|
2 |
|
self::get_page_name(), |
152
|
2 |
|
__( 'General Settings', 'carbon_breadcrumbs' ), |
153
|
2 |
|
'', |
154
|
2 |
|
self::get_page_name() |
155
|
2 |
|
); |
156
|
|
|
|
157
|
2 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Register the settings sections and fields. |
161
|
|
|
* |
162
|
|
|
* @access public |
163
|
|
|
*/ |
164
|
1 |
|
public function register_settings() { |
165
|
|
|
// register fields |
166
|
1 |
|
$field_data = self::get_field_data(); |
167
|
1 |
|
foreach ( $field_data as $field_id => $field ) { |
168
|
1 |
|
$this->fields[] = Carbon_Breadcrumb_Admin_Settings_Field::factory( $field['type'], 'carbon_breadcrumbs_' . $field_id, $field['title'], self::get_page_name() ); |
169
|
1 |
|
} |
170
|
1 |
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Content of the settings page. |
174
|
|
|
* |
175
|
|
|
* @access public |
176
|
|
|
*/ |
177
|
|
|
public function settings_page() { |
178
|
|
|
?> |
179
|
|
|
<div class="wrap"> |
180
|
|
|
<h2><?php echo esc_html( self::get_page_title() ); ?></h2> |
181
|
|
|
</div> |
182
|
|
|
|
183
|
|
|
<form method="POST" action="options.php"> |
184
|
|
|
<?php |
185
|
|
|
settings_fields( self::get_page_name() ); |
186
|
|
|
do_settings_sections( self::get_page_name() ); |
187
|
|
|
submit_button(); |
188
|
|
|
?> |
189
|
|
|
</form> |
190
|
|
|
<?php |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
} |