Issues (5)

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-custom-sidebars.php (2 issues)

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
This program is free software; you can redistribute it and/or
4
modify it under the terms of the GNU General Public License
5
as published by the Free Software Foundation; either version 2
6
of the License, or (at your option) any later version.
7
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
*/
17
18
/**
19
 * Class Custom_Sidebars
20
 */
21
class Custom_Sidebars {
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...
22
23
	/**
24
	 * @var Custom_Sidebars_Details
25
	 */
26
	private $custom_sidebar_details;
27
28
	/**
29
	 * The default sidebar id
30
	 *
31
	 * @var    string
32
	 * @access private
33
	 * @static
34
	 */
35
	private static $default_sidebar_id;
36
37
	/**
38
	 * The class constructor
39
	 */
40
	public function __construct() {
41
42
		add_action( 'init', array( $this, 'init' ) );
43
		add_action( 'admin_init', array( $this, 'admin_init' ) );
44
		add_filter( 'sidebars_widgets', array( $this, 'sidebars_widgets' ) );
45
46
	}
47
48
	/**
49
	 * Instantiate the custom sidebars metabox class
50
	 *
51
	 * This method is hooked to the WP admin_init action
52
	 */
53
	public function admin_init() {
54
55
		$this->custom_sidebar_details = new Custom_Sidebars_Details();
56
57
	}
58
59
	/**
60
	 * The WP admin_init action callback
61
	 *
62
	 * Get all pages and posts and add sidebars for each individual post
63
	 */
64
	public function init() {
65
66
		$posts = array();
0 ignored issues
show
$posts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67
68
		if ( ! $posts = wp_cache_get( 'sidebars', 'custom_sidebars' ) ) {
69
			$args = array(
70
				'post_type' => Custom_Sidebars::get_post_types(),
71
				'meta_query' => array(
72
					array(
73
						'key'   => '_custom_sidebar',
74
						'value' => true,
75
					)
76
				)
77
			);
78
79
			$query = new WP_Query( $args );
80
81
			if ( $query->have_posts() ) {
82
				$posts = $query->posts;
83
			}
84
85
			wp_cache_set( 'sidebars', 'custom_sidebars' );
86
		}
87
88
		foreach ( $posts as $post ) {
89
			$args = apply_filters( 'custom_sidebar_args', array(
90
				'name'          => sprintf( __( 'Sidebar: %s', 'custom_sidebars' ), $post->post_title ),
91
				'id'            => $this->get_sidebar_id( $post->ID ),
92
				'description'   => sprintf( __( 'This sidebar will appear on the %s single page.', 'cd-sidebar' ), $post->post_title ),
93
				'class'         => '',
94
				'before_widget' => '<aside id="%1$s" class="widget %2$s">',
95
				'after_widget'  => '</aside>',
96
				'before_title'  => '<h2 class="widget-title">',
97
				'after_title'   => '</h2>',
98
			) );
99
100
			register_sidebar( $args );
101
		}
102
103
	}
104
105
	/**
106
	 * Get the sidebar id for a specific post
107
	 *
108
	 * @param  int|null The WP post id
109
	 * @return string   The sidebar id
110
	 */
111
	public function get_sidebar_id( $post_id = null ) {
112
113
		$post = get_post( $post_id );
114
115
		return "custom-sidebar-{$post->ID}";
116
117
	}
118
119
	/**
120
	 * Get the post types for which custom sidebars should be registered
121
	 */
122
	public static function get_post_types() {
123
124
		return apply_filters( 'custom_sidebar_post_types', array_values( get_post_types() ) );
125
126
	}
127
128
	/**
129
	 * Get the sidebar_id assigned to a specific post
130
	 */
131
	public static function get_sidebar( $post_id = null ) {
132
133
		if ( empty( $post_id ) ) {
134
			$post_id = get_post()->ID;
135
		}
136
137
		$sidebar = get_post_meta( $post_id, '_custom_sidebar_id', true );
138
139
		if ( $sidebar == false && isset( self::$default_sidebar_id ) ) {
140
			$sidebar = self::$default_sidebar_id;
141
		}
142
143
		return $sidebar;
144
145
	}
146
	
147
	/**
148
	 * Register a default sidebar to use when a post has no specific sidebar assigned
149
	 */
150
	public static function register_default_sidebar( $sidebar_id ) {
151
152
		self::$default_sidebar_id = $sidebar_id;
153
154
	}
155
156
	/**
157
	 * Filter the sidebar widgets
158
	 *
159
	 * This method is hooked to the WP filter sidebars_widgets. 
160
	 *
161
	 * Since we have no way to know what sidebar is currently being called, this method
162
	 * replaces the array of widgets for ALL registered sidebars with the widgets
163
	 * assigned to the sidebar specified for use on this particular post/page. This is a
164
	 * carpet-bomb approach that should be more specific, but current limitiations in the
165
	 * WP infrastructure require it to be done this way.
166
	 *
167
	 * @param  array $sidebar_widgets
168
	 * @return array $sidebar_widgets The filtered widget array
169
	 * @since  0.3
170
	 */
171
	public function sidebars_widgets( $sidebar_widgets ) {
172
173
		if ( ! is_admin() && ! empty( $this->get_sidebar() ) ) {
174
			foreach ( $sidebar_widgets as $key => $widgets ) {
175
				$sidebar_widgets[ $key ] = $sidebar_widgets[ $this->get_sidebar() ];
176
			}
177
		}
178
179
		return $sidebar_widgets;
180
181
	}
182
183
}
184