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-sidebar-details.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
class Custom_Sidebars_Details {
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...
19
20
	/**
21
	 * The class constructor
22
	 */
23
	public function __construct() {
24
25
		add_action( 'save_post', array( $this, 'save_post' ) );
26
27
		foreach ( Custom_Sidebars::get_post_types() as $post_type ) {
28
			add_action( "add_meta_boxes_{$post_type}", array( $this, 'add_meta_boxes' ) );
29
		}
30
31
	}
32
33
	/**
34
	 * Add the metabox to the post edit screen
35
	 *
36
	 * Hooked to add_meta_boxes_{$post_type}
37
	 */
38
	public function add_meta_boxes() {
39
40
		add_meta_box(
41
			'custom-sidebar-details',
42
			__( 'Custom Sidebar', 'custom-sidebar' ),
43
			array( $this, 'render' ),
44
			get_post_type(),
45
			'side',
46
			'default',
47
			array()
48
		);
49
50
	}
51
52
	public function render() {
53
54
		$metabox = $this;
55
		include dirname( __DIR__ ) . '/templates/custom-sidebar-details.php';
56
57
	}
58
59
	public function sidebar_select_options() {
60
61
		global $wp_registered_sidebars;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
62
		
63
		foreach ( $wp_registered_sidebars as $key => $sidebar ) {
64
			printf( '<option value="%1$s"%3$s>%2$s</option>', $key, $sidebar['name'], selected( Custom_Sidebars::get_sidebar(), $key ) );
65
		}
66
67
	}
68
69
    /**
70
     * @param int $post_id
71
     */
72
	public function save_post( $post_id ) {
73
74
		$sidebar_id     = filter_input( INPUT_POST, 'custom-sidebar-select', FILTER_VALIDATE_INT );
75
        $custom_sidebar = filter_input( INPUT_POST, 'custom-sidebar', FILTER_VALIDATE_BOOLEAN );
76
77
		if ( isset( $custom_sidebar ) ) {
78
			$sidebar_id = Custom_Sidebars::get_sidebar_id( $post_id );
79
		}
80
81
		update_post_meta( $post_id, '_custom_sidebar',    $custom_sidebar );
82
		update_post_meta( $post_id, '_custom_sidebar_id', sanitize_text_field( $sidebar_id ) );
83
84
	}
85
86
    /**
87
     * @param  int|null $post_id
88
     * @return bool
89
     */
90
	public static function has_custom_sidebar( $post_id = null ) {
91
92
		$value = false;
93
94
		if ( empty( $post_id ) ) {
95
			$post_id = get_post()->ID;
96
		}
97
98
		if ( get_post_meta( $post_id, '_custom_sidebar', true ) ) {
99
			$value = true;
100
		}
101
102
		return $value;
103
104
	} 
105
106
}
107