Carbon_Breadcrumb_Admin_Settings::admin_menu()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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