Issues (4138)

classes/admin/class-settings.php (41 issues)

1
<?php
2
/**
3
 * Contains the settings class for LSX
4
 *
5
 * @package lsx-health-plan
6
 */
7
8
namespace lsx_health_plan\classes\admin;
9
10
/**
11
 * Contains the settings for each post type \lsx_health_plan\classes\admin\Settings().
12
 */
13
class Settings {
14
15
	/**
16
	 * Holds class instance
17
	 *
18
	 * @since 1.0.0
19
	 *
20
	 * @var      object \lsx_health_plan\classes\admin\Settings()
21
	 */
22
	protected static $instance = null;
23
24
	/**
25
	 * Option key, and option page slug
26
	 *
27
	 * @var string
28
	 */
29
	protected $screen_id = 'lsx_health_plan_settings';
30
31
	/**
32
	 * An array of the post types for the Global Downloads field.
33
	 *
34
	 * @var array
35
	 */
36
	public $download_types = array();
37
38
	/**
39
	 * An array of the post types for the Global Defaults field.
40
	 *
41
	 * @var array
42
	 */
43
	//public $default_types = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
No space found before comment text; expected "// public $default_types = array();" but found "//public $default_types = array();"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
44
45
	/**
46
	 * An array of the endpoints for the Endpoint Translation field.
47
	 *
48
	 * @var array
49
	 */
50
	public $endpoints = array();
51
52
	/**
53
	 * Constructor
54
	 */
55
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
56
		$this->load_classes();
57
		add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) );
58
		add_action( 'lsx_hp_settings_page', array( $this, 'generate_tabs' ), 1, 1 );
59
60
		add_action( 'lsx_hp_settings_page_general_top', array( $this, 'general_settings' ), 1, 1 );
61
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
62
63
	/**
64
	 * Return an instance of this class.
65
	 *
66
	 * @since 1.0.0
67
	 *
68
	 * @return    object \lsx_health_plan\classes\admin\Settings()    A single instance of this class.
69
	 */
70
	public static function get_instance() {
71
		// If the single instance hasn't been set, set it now.
72
		if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
73
			self::$instance = new self();
74
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
75
		return self::$instance;
76
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
77
78
	/**
79
	 * Loads the variable classes and the static classes.
80
	 */
81
	private function load_classes() {
0 ignored issues
show
Expected 0 blank lines after opening function brace; 1 found
Loading history...
82
83
		$this->post_types = array(
0 ignored issues
show
Bug Best Practice introduced by
The property post_types does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
84
			'my-plans',
85
			'workout',
86
			'exercise',
87
			'meal',
88
			'recipe',
89
			//'tip',
0 ignored issues
show
No space found before comment text; expected "// 'tip'," but found "//'tip',"
Loading history...
90
			'recipe',
91
		);
92
93
		foreach ( $this->post_types as $post_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
94
			$this->$post_type = require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/settings/class-' . $post_type . '.php';
95
		}
96
97
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
98
99
	/**
100
	 * Hook in and register a submenu options page for the Page post-type menu.
101
	 */
102
	public function register_settings_page() {
103
		$cmb = new_cmb2_box(
104
			array(
105
				'id'           => $this->screen_id,
106
				'title'        => esc_html__( 'Settings', 'lsx-health-plan' ),
107
				'object_types' => array( 'options-page' ),
108
				'option_key'   => 'lsx_health_plan_options', // The option key and admin menu page slug.
109
				'parent_slug'  => 'edit.php?post_type=plan', // Make options page a submenu item of the themes menu.
110
				'capability'   => 'manage_options', // Cap required to view options-page.
111
			)
112
		);
113
		do_action( 'lsx_hp_settings_page', $cmb );
114
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
115
116
	/**
117
	 * Registers the general settings.
118
	 *
119
	 * @param object $cmb new_cmb2_box().
120
	 * @return void
121
	 */
122
	public function general_settings( $cmb ) {
123
		$cmb->add_field(
124
			array(
125
				'name'        => __( 'Exercises', 'lsx-health-plan' ),
126
				'id'          => 'exercise_enabled',
127
				'type'        => 'checkbox',
128
				'value'       => 1,
129
				'default'     => 0,
130
				'description' => __( 'Enabling the exercise post type will automatically replace the Video post type.', 'lsx-health-plan' ),
131
			)
132
		);
133
134
		$cmb->add_field(
135
			array(
136
				'name'        => __( 'Disable Workouts', 'lsx-health-plan' ),
137
				'id'          => 'workout_disabled',
138
				'type'        => 'checkbox',
139
				'value'       => 1,
140
				'default'     => 0,
141
				'description' => __( 'Disable workout post type if you are wanting a minimal site.', 'lsx-health-plan' ),
142
			)
143
		);
144
145
		$cmb->add_field(
146
			array(
147
				'name'        => __( 'Disable Recipes', 'lsx-health-plan' ),
148
				'id'          => 'recipe_disabled',
149
				'type'        => 'checkbox',
150
				'value'       => 1,
151
				'default'     => 0,
152
				'description' => __( 'Disable recipe post type if you are wanting a minimal site.', 'lsx-health-plan' ),
153
			)
154
		);
155
156
		$cmb->add_field(
157
			array(
158
				'name'        => __( 'Disable Meals', 'lsx-health-plan' ),
159
				'id'          => 'meal_disabled',
160
				'type'        => 'checkbox',
161
				'value'       => 1,
162
				'default'     => 0,
163
				'description' => __( 'Disable meal post type if you are wanting a minimal site.', 'lsx-health-plan' ),
164
			)
165
		);
166
		
0 ignored issues
show
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
167
168
		$cmb->add_field(
169
			array(
170
				'name'      =>  __( 'Login Slug', 'lsx-health-plan' ),
0 ignored issues
show
Expected 1 space after "=>"; 2 found
Loading history...
171
				'id'        => 'login_slug',
172
				'type'      => 'input',
173
				'value'     => '',
174
				'default'   => 'login',
175
				'after_row' => __( '<p style="font-style: italic;">If you have changed any URL slugs, please remember re-save your permalinks in Settings > Permalinks.</p>', 'lsx-health-plan' ),
176
			)
177
		);
178
179
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
180
181
	/**
182
	 * Enable Business Directory Search settings only if LSX Search plugin is enabled.
183
	 *
184
	 * @param object $cmb The CMB2() class.
185
	 * @param string $section either engine,archive or single.
0 ignored issues
show
Superfluous parameter comment
Loading history...
186
	 * @return void
187
	 */
188
	public function generate_tabs( $cmb ) {
189
		$tabs = $this->get_settings_tabs();
190
191
		foreach ( $tabs as $tab_key => $tab ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
192
			$cmb->add_field(
193
				array(
194
					'id'          => 'settings_' . $tab_key . '_title',
195
					'type'        => 'title',
196
					'name'        => $tab['title'],
197
					'default'     => $tab['title'],
198
					'description' => $tab['desc'],
199
				)
200
			);
201
			do_action( 'lsx_hp_settings_page_' . $tab_key . '_top', $cmb );
202
203
			do_action( 'lsx_hp_settings_page_' . $tab_key . '_middle', $cmb );
204
205
			do_action( 'lsx_hp_settings_page_' . $tab_key . '_bottom', $cmb );
206
207
			$cmb->add_field(
208
				array(
209
					'id'   => 'settings_' . $tab_key . '_closing',
210
					'type' => 'tab_closing',
211
				)
212
			);
213
		}
214
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
215
216
217
	/**
218
	 * Returns the tabs and their descriptions.
219
	 *
220
	 * @return array
221
	 */
222
	public function get_settings_tabs() {
223
		$tabs = array(
224
			'general' => array(
225
				'title' => __( 'General', 'lsx-health-plan' ),
226
				'desc'  => __( 'Control the sitewide settings for the LSX HP site.', 'lsx-health-plan' ),
227
			),
228
		);
229
230
		foreach ( $this->post_types as $post_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
231
			switch ( $post_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
232
				case 'my-plans':
233
					$page_url    = get_post_type_archive_link( 'plan' );
234
					$description = sprintf(
235
						/* translators: %s: The subscription info */
236
						__( 'Control the settings for your <a target="_blank" href="%1$s">%2$s</a> pages.', 'lsx-search' ),
237
						$page_url,
0 ignored issues
show
It seems like $page_url can also be of type false; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

237
						/** @scrutinizer ignore-type */ $page_url,
Loading history...
238
						__( 'plan', 'lsx-health-plan' )
239
					);
240
					$tabs[ $post_type ] = array(
241
						'title' => __( 'My Plans', 'lsx-health-plan' ),
242
						'desc'  => $description,
243
					);
244
					break;
245
				default:
246
					//if ( ! in_array( $post_type, \lsx\search\includes\get_restricted_post_types() ) ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
No space found before comment text; expected "// if ( ! in_array( $post_type, \lsx\search\includes\get_restricted_post_types() ) ) {" but found "//if ( ! in_array( $post_type, \lsx\search\includes\get_restricted_post_types() ) ) {"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
247
						$temp_post_type = get_post_type_object( $post_type );
248
						if ( ! is_wp_error( $temp_post_type ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
249
							$page_url    = get_post_type_archive_link( $temp_post_type->name );
250
							$description = sprintf(
251
								/* translators: %s: The subscription info */
252
								__( 'Control the settings for your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search' ),
253
								$page_url,
254
								$temp_post_type->label
255
							);
256
257
							$tabs[ $post_type ] = array(
258
								'title' => $temp_post_type->label,
259
								'desc'  => $description,
260
							);
261
						}
0 ignored issues
show
No blank line found after control structure
Loading history...
262
					//}
0 ignored issues
show
No space found before comment text; expected "// }" but found "//}"
Loading history...
263
					break;
264
			}
265
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
266
		return $tabs;
267
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
268
}
269