Advanced::add_fields()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 47
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 31
nc 4
nop 0
dl 0
loc 47
rs 8.6845
c 0
b 0
f 0
1
<?php
2
/**
3
 * General Settings Page
4
 *
5
 * @package SimpleCalendar/Admin
6
 */
7
namespace SimpleCalendar\Admin\Pages;
8
9
use SimpleCalendar\Abstracts\Admin_Page;
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
/**
16
 * General settings.
17
 *
18
 * Handles the plugin general settings and outputs the markup the settings page.
19
 *
20
 * @since 3.0.0
21
 */
22
class Advanced extends Admin_Page {
23
24
	/**
25
	 * Constructor.
26
	 *
27
	 * @since 3.0.0
28
	 */
29
	public function __construct() {
30
		$this->id           = 'advanced';
31
		$this->option_group = 'settings';
32
		$this->label        = __( 'Advanced', 'google-calendar-events' );
33
		//$this->description  = __( 'Advanced settings.', 'google-calendar-events' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
		$this->sections     = $this->add_sections();
35
		$this->fields       = $this->add_fields();
36
	}
37
38
	/**
39
	 * Add sections.
40
	 *
41
	 * @since  3.0.0
42
	 *
43
	 * @return array
44
	 */
45
	public function add_sections() {
46
		return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id .'_sections', array(
47
			'assets' => array(
48
				'title'       => __( 'Styles', 'google-calendar-events' ),
49
				'description' => __( 'Manage front end assets that handle the calendars appearance.', 'google-calendar-events' )
50
			),
51
			'installation' => array(
52
				'title'       => __( 'Installation', 'google-calendar-events' ),
53
				'description' => __( 'Manage your data (plugin settings and saved calendars).', 'google-calendar-events' )
54
			)
55
		) );
56
	}
57
58
	/**
59
	 * Add fields.
60
	 *
61
	 * @since  3.0.0
62
	 *
63
	 * @return array
64
	 */
65
	public function add_fields() {
66
67
		$fields       = array();
68
		$this->values = get_option( 'simple-calendar_' . $this->option_group . '_' . $this->id );
69
70
		foreach ( $this->sections  as $section => $a ) :
71
72
			if ( 'assets' == $section ) {
73
74
				$fields[ $section ] = array(
75
					'disable_css' => array(
76
						'title'   => __( 'Disable CSS', 'google-calendar-events' ),
77
						'tooltip' => __( 'If ticked, this option will prevent all front end stylesheets to load. This also includes all add-on stylesheets.', 'google-calendar-events' ),
78
						'type'    => 'checkbox',
79
						'name'    => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][disable_css]',
80
						'id'      => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $section . '-disable-css',
81
						'value'   => $this->get_option_value( $section, 'disable_css' )
82
					),
83
				);
84
85
			} elseif ( 'installation' == $section ) {
86
87
				$fields[ $section ] = array(
88
					'delete_settings' => array(
89
						'title'   => __( 'Delete settings', 'google-calendar-events' ),
90
						'tooltip' => __( 'Tick this option if you want to wipe this plugin settings from database when uninstalling.', 'google-calendar-events' ),
91
						'type'    => 'checkbox',
92
						'name'    => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][delete_settings]',
93
						'id'      => 'simple-calendar-' . $this->option_group . '-' . $this->id . '-' . $section . '-delete-settings',
94
						'value'   => $this->get_option_value( $section, 'delete_settings' ),
95
					),
96
					'erase_data' => array(
97
						'title'   => __( 'Erase calendar data', 'google-calendar-events' ),
98
						'tooltip' => __( 'By default your data will be retained in database even after uninstall. Tick this option if you want to delete all your calendar data when uninstalling.', 'google-calendar-events' ),
99
						'type'    => 'checkbox',
100
						'name'    => 'simple-calendar_' . $this->option_group . '_' . $this->id . '[' . $section . '][erase_data]',
101
						'id'      => 'simple-calendar_' . $this->option_group . '_' . $this->id . '-delete-data',
102
						'value'   => $this->get_option_value( $section, 'erase_data' ),
103
					)
104
				);
105
106
			}
107
108
		endforeach;
109
110
		return apply_filters( 'simcal_add_' . $this->option_group . '_' . $this->id . '_fields', $fields );
111
	}
112
113
}
114