Completed
Push — milestone/2.0 ( 8a1186...26a446 )
by
unknown
04:33
created

Widget_Container::to_json()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Carbon_Fields\Container;
4
5
/**
6
 * Widget container class
7
 */
8
class Widget_Container extends Container {
9
10
	/**
11
	 * Create a new widget
12
	 *
13
	 * @param string $unique_id Unique ID of the widget
14
	 * @param string $title Ignored
15
	 * @param string $type Container type
16
	 **/
17
	public function __construct( $unique_id, $title, $type ) {
18
		$this->id = $unique_id;
19
		$this->title = '';
20
		$this->type = $type;
21
	}
22
23
	/**
24
	 * Perform instance initialization
25
	 **/
26
	public function init() {
27
		$this->_attach();
28
		$this->render();
29
30
		return $this;
31
	}
32
33
	/**
34
	 * Perform checks whether the container should be attached during the current request
35
	 *
36
	 * @return bool True if the container is allowed to be attached
37
	 **/
38
	public function is_valid_attach_for_request() {
39
		$screen = get_current_screen();
40
		$request_action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
1 ignored issue
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
41
		$is_widget_save = ( $request_action === 'save-widget' );
42
43
		return $screen && $screen->id === 'widgets' || $is_widget_save;
44
	}
45
46
	/**
47
	 * Check container attachment rules against object id
48
	 *
49
	 * @return bool
50
	 **/
51
	public function is_valid_attach_for_object( $object_id = null ) {
52
		return true;
53
	}
54
55
	/**
56
	 * Output the container markup
57
	 **/
58
	public function render() {
59
		include \Carbon_Fields\DIR . '/templates/Container/widget.php';
60
	}
61
62
	/**
63
	 * Returns an array that holds the container data, suitable for JSON representation.
64
	 * This data will be available in the Underscore template and the Backbone Model.
65
	 *
66
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
67
	 * @return array
68
	 */
69
	public function to_json( $load ) {
70
		return parent::to_json( false );
71
	}
72
}
73
74