Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

includes/class-settings.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * The settings page class
4
 *
5
 * @license GPLv2 or later
6
 * @since   0.2
7
 */
8
class CPT_Date_Archive_Settings {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
	/**
11
	 * A singleton instance
12
	 *
13
	 * @var    CPT_Date_Archive_Settings
14
	 * @static
15
	 * @access private
16
	 * @since  0.2
17
	 */
18
	private static $instance = null;
19
20
	/**
21
	 * The page object
22
	 *
23
	 * @var    stdClass
24
	 * @access private
25
	 * @since  0.2
26
	 */
27
	private $page;
28
29
	/**
30
	 * The class constructor
31
	 *
32
	 * @access public
33
	 * @since  0.2
34
	 */
35
	protected function __construct() {
36
37
		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
38
		add_action( 'update_option_cpt_date_archive_post_types', array( $this, 'update_option' ) );
39
40
		$this->page     = new stdClass;
41
		$this->page->id = 'cpt_date_archives';
42
	}
43
44
	/**
45
	 * Add the options page, options groups, sections, and fields
46
	 *
47
	 * Hooked to WP admin_menu action
48
	 *
49
	 * @access public
50
	 * @since  0.2
51
	 */
52
	public function admin_menu() {
53
54
		register_setting( $this->page->id, 'cpt_date_archive_post_types', array( $this, 'sanitize_input' ) );
55
56
		add_options_page( __( 'CPT Date Archives Settings', 'cpt_date_archives' ), __( 'CPT Date Archives', 'cpt_date_archives' ),  'manage_options', $this->page->id, array( $this, 'render' ) );
57
		add_settings_section( 'general', __( 'General', 'cpt_date_archives' ), null, $this->page->id );
58
		add_settings_field( 'post-types', __( 'Post Types', 'cpt_date_archives' ), array( $this, 'render_field_post_types' ), $this->page->id, 'general' );
59
60
	}
61
62
	/**
63
	 * Render the settings page
64
	 *
65
	 * @access public
66
	 * @since  0.2
67
	 */
68
	public function render() {
69
70
		$page = $this->page;
71
72
		include dirname( __DIR__ ) . '/templates/settings-page.php';
73
74
	}
75
76
	/**
77
	 * Render the post types field
78
	 *
79
	 * @access public
80
	 * @since  0.2
81
	 */
82
	public function render_field_post_types() {
83
84
		$post_types = get_post_types( array( 'public' => 'true', '_builtin' => false ), 'objects' );
85
		$selected   = $this->get_post_type_objects();
86
87
		esc_html_e( __( 'Inputs are disabled for post types that do not support archives.', 'cpt_date_archive_post_types' ) );
88
89
		foreach ( $post_types as $post_type ) {
90
			if ( $this->has_date_archive( $post_type ) ) {
91
				$post_type->checked = true;
92
			}
93
94
			include dirname( __DIR__ ) . '/templates/post-types-field.php';
95
		}
96
97
	}
98
99
	/**
100
	 * Sanitize the post types field input
101
	 *
102
	 * @param  array $input
103
	 * @access public
104
	 * @since  0.2
105
	 */
106
	public function sanitize_input( $input ) {
107
108
		if ( ! empty( $input ) ) {
109
			foreach ( $input as $key => $post_type ) {
110
				$input[ $key ] = sanitize_text_field( $post_type );
111
			}
112
		}
113
114
		return $input;
115
116
	}
117
118
	/**
119
	 * Get the post type objects that are set to support date archives
120
	 *
121
	 * @return stdClass[]
122
	 * @access public
123
	 * @since  0.2
124
	 */
125
	public function get_post_type_objects() {
126
127
		$post_types = $this->get_post_types();
128
129
		foreach ( $post_types as $key => $post_type ) {
130
			$post_types[ $key ] = get_post_type_object( $post_type );
131
		}
132
133
		return $post_types;
134
135
	}
136
137
	/**
138
	 * Get the post post type names that are set to support date archives
139
	 *
140
	 * @return string[]
141
	 * @access public
142
	 * @since 0.2
143
	 */
144
	public function get_post_types() {
145
146
		return get_option( 'cpt_date_archive_post_types', array() );
147
148
	}
149
150
	/**
151
	 * Does a particular post type have a date archive?
152
	 *
153
	 * @return bool
154
	 * @access public
155
	 * @since  0.2
156
	 */
157
	public function has_date_archive( $post_type ) {
158
159
		$value = false;
160
161
		if ( ! is_object( $post_type ) ) {
162
			$post_type = get_post_type_object( $post_type );
163
		}
164
165
		if ( in_array( $post_type->name, $this->get_post_types() ) ) {
166
			$value = true;
167
		}
168
169
		return $value;
170
171
	}
172
173
	/**
174
	 * Delete the rewrite rules when updating the plugin settings
175
	 *
176
	 * Hooked to WP 'updated_option_cpt_date_archive_post_types' action.
177
	 *
178
	 * @access public
179
	 * @since  0.2
180
	 */
181
	public function update_option() {
182
183
			delete_option( 'rewrite_rules' );
184
185
	}
186
187
	/**
188
	 * Prevent cloning of the singleton instance
189
	 *
190
	 * @access private
191
	 * @since  0.2
192
	 */
193
	private function __clone() {}
194
195
	/**
196
	 * Prevent unserializing of the singleton instance
197
	 *
198
	 * @access private
199
	 * @since  0.2
200
	 */
201
	private function __wakeup () {}
202
203
	/**
204
	 * Singleton model
205
	 *
206
	 * @access public
207
	 * @since  0.2
208
	 */
209
	public static function init() {
210
211
		if ( ! isset( self::$instance ) ) {
212
			self::$instance = new CPT_Date_Archive_Settings;
213
		}
214
215
		return self::$instance;
216
217
	}
218
219
}
220