Passed
Push — add/multiplan ( c6d0fb...d178ab )
by Warwick
07:56
created
vendor/CMB2/includes/types/CMB2_Type_Counter_Base.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -30,47 +30,47 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @return string
32 32
 	 */
33
-	public function char_counter_markup( $val ) {
33
+	public function char_counter_markup($val) {
34 34
 		$markup = '';
35 35
 
36
-		if ( ! $this->field->args( 'char_counter' ) ) {
36
+		if ( ! $this->field->args('char_counter')) {
37 37
 			return $markup;
38 38
 		}
39 39
 
40
-		$type     = (string) $this->field->args( 'char_counter' );
41
-		$field_id = $this->_id( '', false );
42
-		$char_max = (int) $this->field->prop( 'char_max' );
43
-		if ( $char_max ) {
40
+		$type     = (string) $this->field->args('char_counter');
41
+		$field_id = $this->_id('', false);
42
+		$char_max = (int) $this->field->prop('char_max');
43
+		if ($char_max) {
44 44
 			$char_max = 'data-max="' . $char_max . '"';
45 45
 		}
46 46
 
47
-		switch ( $type ) {
47
+		switch ($type) {
48 48
 			case 'words':
49 49
 				$label = $char_max
50
-					? $this->_text( 'words_left_text', esc_html__( 'Words left', 'cmb2' ) )
51
-					: $this->_text( 'words_text', esc_html__( 'Words', 'cmb2' ) );
50
+					? $this->_text('words_left_text', esc_html__('Words left', 'cmb2'))
51
+					: $this->_text('words_text', esc_html__('Words', 'cmb2'));
52 52
 				break;
53 53
 			default:
54 54
 				$type  = 'characters';
55 55
 				$label = $char_max
56
-					? $this->_text( 'characters_left_text', esc_html__( 'Characters left', 'cmb2' ) )
57
-					: $this->_text( 'characters_text', esc_html__( 'Characters', 'cmb2' ) );
56
+					? $this->_text('characters_left_text', esc_html__('Characters left', 'cmb2'))
57
+					: $this->_text('characters_text', esc_html__('Characters', 'cmb2'));
58 58
 				break;
59 59
 		}
60 60
 
61 61
 		$msg = $char_max
62
-			? sprintf( '<span class="cmb2-char-max-msg">%s</span>', $this->_text( 'characters_truncated_text', esc_html__( 'Your text may be truncated.', 'cmb2' ) ) )
62
+			? sprintf('<span class="cmb2-char-max-msg">%s</span>', $this->_text('characters_truncated_text', esc_html__('Your text may be truncated.', 'cmb2')))
63 63
 			: '';
64 64
 
65
-		$length = strlen( $val );
66
-		$width  = $length > 1 ? ( 8 * strlen( (string) $length ) ) + 15 : false;
65
+		$length = strlen($val);
66
+		$width  = $length > 1 ? (8 * strlen((string) $length)) + 15 : false;
67 67
 
68 68
 		$markup .= '<p class="cmb2-char-counter-wrap">';
69 69
 		$markup .= sprintf(
70 70
 			'<label><span class="cmb2-char-counter-label">%2$s:</span> <input id="%1$s" data-field-id="%3$s" data-counter-type="%4$s" %5$s class="cmb2-char-counter" type="text" value="%6$s" readonly="readonly" style="%7$s"></label>%8$s',
71
-			esc_attr( 'char-counter-' . $field_id ),
71
+			esc_attr('char-counter-' . $field_id),
72 72
 			$label,
73
-			esc_attr( $field_id ),
73
+			esc_attr($field_id),
74 74
 			$type,
75 75
 			$char_max,
76 76
 			$length,
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 		$markup .= '</p>';
81 81
 
82 82
 		// Enqueue the required JS.
83
-		$this->field->add_js_dependencies( array(
83
+		$this->field->add_js_dependencies(array(
84 84
 			'word-count',
85 85
 			'wp-util',
86 86
 			'cmb2-char-counter',
87
-		) );
87
+		));
88 88
 
89 89
 		$this->has_counter = true;
90 90
 
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @return array              Potentially modified attributes.
102 102
 	 */
103
-	public function maybe_update_attributes_for_char_counter( $attributes ) {
104
-		$char_counter = $this->char_counter_markup( $attributes['value'] );
103
+	public function maybe_update_attributes_for_char_counter($attributes) {
104
+		$char_counter = $this->char_counter_markup($attributes['value']);
105 105
 
106 106
 		// Has character counter?
107
-		if ( $char_counter ) {
108
-			$attributes['class'] = ! empty( $attributes['class'] ) ? $attributes['class'] . ' cmb2-count-chars' : ' cmb2-count-chars';
107
+		if ($char_counter) {
108
+			$attributes['class'] = ! empty($attributes['class']) ? $attributes['class'] . ' cmb2-count-chars' : ' cmb2-count-chars';
109 109
 
110 110
 			// Enforce max chars?
111 111
 			$max = $this->enforce_max();
112
-			if ( $max ) {
112
+			if ($max) {
113 113
 				$attributes['maxlength'] = $max;
114 114
 			}
115 115
 			$attributes['desc'] = $char_counter . $attributes['desc'];
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	 * @return bool Whether to enforce max characters.
127 127
 	 */
128 128
 	public function enforce_max() {
129
-		$char_max = (int) $this->field->args( 'char_max' );
129
+		$char_max = (int) $this->field->args('char_max');
130 130
 
131 131
 		// Enforce max chars?
132
-		return ( $this->field->args( 'char_max_enforce' ) && $char_max > 0
133
-			&& 'words' !== $this->field->args( 'char_counter' ) )
132
+		return ($this->field->args('char_max_enforce') && $char_max > 0
133
+			&& 'words' !== $this->field->args('char_counter'))
134 134
 			? $char_max
135 135
 			: false;
136 136
 	}
Please login to merge, or discard this patch.
vendor/CMB2/includes/types/CMB2_Type_Base.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 	 * @param CMB2_Types $types Object for the field type.
41 41
 	 * @param array      $args  Array of arguments for the type.
42 42
 	 */
43
-	public function __construct( CMB2_Types $types, $args = array() ) {
43
+	public function __construct(CMB2_Types $types, $args = array()) {
44 44
 		$this->types      = $types;
45
-		$args['rendered'] = isset( $args['rendered'] ) ? (bool) $args['rendered'] : true;
45
+		$args['rendered'] = isset($args['rendered']) ? (bool) $args['rendered'] : true;
46 46
 		$this->args       = $args;
47 47
 	}
48 48
 
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 	 * @param  string|CMB2_Type_Base $rendered Rendered output.
62 62
 	 * @return string|CMB2_Type_Base           Rendered output or this object.
63 63
 	 */
64
-	public function rendered( $rendered ) {
64
+	public function rendered($rendered) {
65 65
 		$this->field->register_js_data();
66 66
 
67
-		if ( $this->args['rendered'] ) {
68
-			return is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered;
67
+		if ($this->args['rendered']) {
68
+			return is_a($rendered, __CLASS__) ? $rendered->rendered : $rendered;
69 69
 		}
70 70
 
71
-		$this->rendered = is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered;
71
+		$this->rendered = is_a($rendered, __CLASS__) ? $rendered->rendered : $rendered;
72 72
 
73 73
 		return $this;
74 74
 	}
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 * @param  array  $type_overrides Type override arguments.
93 93
 	 * @return array                  Parsed and filtered arguments.
94 94
 	 */
95
-	public function parse_args( $element, $type_defaults, $type_overrides = array() ) {
96
-		$args = $this->parse_args_from_overrides( $type_overrides );
95
+	public function parse_args($element, $type_defaults, $type_overrides = array()) {
96
+		$args = $this->parse_args_from_overrides($type_overrides);
97 97
 
98 98
 		/**
99 99
 		 * Filter attributes for a field type.
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 		 * @param array  $field             The `CMB2_Field` object.
106 106
 		 * @param object $field_type_object This `CMB2_Types` object.
107 107
 		 */
108
-		$args = apply_filters( "cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types );
108
+		$args = apply_filters("cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types);
109 109
 
110
-		$args = wp_parse_args( $args, $type_defaults );
110
+		$args = wp_parse_args($args, $type_defaults);
111 111
 
112
-		if ( ! empty( $args['js_dependencies'] ) ) {
113
-			$this->field->add_js_dependencies( $args['js_dependencies'] );
112
+		if ( ! empty($args['js_dependencies'])) {
113
+			$this->field->add_js_dependencies($args['js_dependencies']);
114 114
 		}
115 115
 
116 116
 		return $args;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	 * @param  array $type_overrides Type override arguments.
124 124
 	 * @return array                 Parsed arguments
125 125
 	 */
126
-	protected function parse_args_from_overrides( $type_overrides = array() ) {
127
-		$type_overrides = empty( $type_overrides ) ? $this->args : $type_overrides;
126
+	protected function parse_args_from_overrides($type_overrides = array()) {
127
+		$type_overrides = empty($type_overrides) ? $this->args : $type_overrides;
128 128
 
129
-		if ( true !== $this->field->args( 'disable_hash_data_attribute' ) ) {
129
+		if (true !== $this->field->args('disable_hash_data_attribute')) {
130 130
 			$type_overrides['data-hash'] = $this->field->hash_id();
131 131
 		}
132 132
 
133
-		$field_overrides = $this->field->args( 'attributes' );
133
+		$field_overrides = $this->field->args('attributes');
134 134
 
135
-		return ! empty( $field_overrides )
136
-			? wp_parse_args( $field_overrides, $type_overrides )
135
+		return ! empty($field_overrides)
136
+			? wp_parse_args($field_overrides, $type_overrides)
137 137
 			: $type_overrides;
138 138
 	}
139 139
 
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
 	 * @throws Exception Throws an exception if the field is invalid.
146 146
 	 * @return mixed
147 147
 	 */
148
-	public function __call( $method, $arguments ) {
149
-		switch ( $method ) {
148
+	public function __call($method, $arguments) {
149
+		switch ($method) {
150 150
 			case '_id':
151 151
 			case '_name':
152 152
 			case '_desc':
153 153
 			case '_text':
154 154
 			case 'concat_attrs':
155
-				return call_user_func_array( array( $this->types, $method ), $arguments );
155
+				return call_user_func_array(array($this->types, $method), $arguments);
156 156
 			default:
157
-				throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), __CLASS__, $method ) );
157
+				throw new Exception(sprintf(esc_html__('Invalid %1$s method: %2$s', 'cmb2'), __CLASS__, $method));
158 158
 		}
159 159
 	}
160 160
 
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
 	 * @throws Exception Throws an exception if the field is invalid.
166 166
 	 * @return mixed
167 167
 	 */
168
-	public function __get( $field ) {
169
-		switch ( $field ) {
168
+	public function __get($field) {
169
+		switch ($field) {
170 170
 			case 'field':
171 171
 				return $this->types->field;
172 172
 			default:
173
-				throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
173
+				throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field));
174 174
 		}
175 175
 	}
176 176
 
Please login to merge, or discard this patch.
vendor/CMB2/includes/types/CMB2_Type_Picker_Base.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -20,37 +20,37 @@
 block discarded – undo
20 20
 	 * @param  array  $args Optional arguments to modify (else use $this->field->args['attributes'])
21 21
 	 * @return array         Array of field attributes
22 22
 	 */
23
-	public function parse_picker_options( $arg = 'date', $args = array() ) {
23
+	public function parse_picker_options($arg = 'date', $args = array()) {
24 24
 		$att    = 'data-' . $arg . 'picker';
25
-		$update = empty( $args );
25
+		$update = empty($args);
26 26
 		$atts   = array();
27
-		$format = $this->field->args( $arg . '_format' );
27
+		$format = $this->field->args($arg . '_format');
28 28
 
29
-		if ( $js_format = CMB2_Utils::php_to_js_dateformat( $format ) ) {
29
+		if ($js_format = CMB2_Utils::php_to_js_dateformat($format)) {
30 30
 
31
-			if ( $update ) {
32
-				$atts = $this->field->args( 'attributes' );
31
+			if ($update) {
32
+				$atts = $this->field->args('attributes');
33 33
 			} else {
34
-				$atts = isset( $args['attributes'] )
34
+				$atts = isset($args['attributes'])
35 35
 					? $args['attributes']
36 36
 					: $atts;
37 37
 			}
38 38
 
39 39
 			// Don't override user-provided datepicker values
40
-			$data = isset( $atts[ $att ] )
41
-				? json_decode( $atts[ $att ], true )
40
+			$data = isset($atts[$att])
41
+				? json_decode($atts[$att], true)
42 42
 				: array();
43 43
 
44
-			$data[ $arg . 'Format' ] = $js_format;
45
-			$atts[ $att ] = function_exists( 'wp_json_encode' )
46
-				? wp_json_encode( $data )
47
-				: json_encode( $data );
44
+			$data[$arg . 'Format'] = $js_format;
45
+			$atts[$att] = function_exists('wp_json_encode')
46
+				? wp_json_encode($data)
47
+				: json_encode($data);
48 48
 		}
49 49
 
50
-		if ( $update ) {
50
+		if ($update) {
51 51
 			$this->field->args['attributes'] = $atts;
52 52
 		}
53 53
 
54
-		return array_merge( $args, $atts );
54
+		return array_merge($args, $atts);
55 55
 	}
56 56
 }
Please login to merge, or discard this patch.
vendor/CMB2/includes/types/CMB2_Type_File.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -18,28 +18,28 @@  discard block
 block discarded – undo
18 18
 	 * @param  array $args Override arguments.
19 19
 	 * @return string      Form input element
20 20
 	 */
21
-	public function render( $args = array() ) {
22
-		$args    = empty( $args ) ? $this->args : $args;
21
+	public function render($args = array()) {
22
+		$args    = empty($args) ? $this->args : $args;
23 23
 		$field   = $this->field;
24 24
 		$options = (array) $field->options();
25 25
 
26
-		$a = $this->args = $this->parse_args( 'file', array(
26
+		$a = $this->args = $this->parse_args('file', array(
27 27
 			'class'           => 'cmb2-upload-file regular-text',
28 28
 			'id'              => $this->_id(),
29 29
 			'name'            => $this->_name(),
30 30
 			'value'           => $field->escaped_value(),
31 31
 			'id_value'        => null,
32
-			'desc'            => $this->_desc( true ),
32
+			'desc'            => $this->_desc(true),
33 33
 			'size'            => 45,
34 34
 			'js_dependencies' => 'media-editor',
35
-			'preview_size'    => $field->args( 'preview_size' ),
36
-			'query_args'      => $field->args( 'query_args' ),
35
+			'preview_size'    => $field->args('preview_size'),
36
+			'query_args'      => $field->args('query_args'),
37 37
 
38 38
 			// if options array and 'url' => false, then hide the url field.
39
-			'type'            => array_key_exists( 'url', $options ) && false === $options['url']
39
+			'type'            => array_key_exists('url', $options) && false === $options['url']
40 40
 				? 'hidden'
41 41
 				: 'text',
42
-		), $args );
42
+		), $args);
43 43
 
44 44
 		// get an array of image size meta data, fallback to 'large'.
45 45
 		$this->args['img_size_data'] = $img_size_data = parent::get_image_size_data(
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
 		$output = '';
51 51
 
52
-		$output .= parent::render( array(
52
+		$output .= parent::render(array(
53 53
 			'type'             => $a['type'],
54 54
 			'class'            => $a['class'],
55 55
 			'value'            => $a['value'],
@@ -57,35 +57,35 @@  discard block
 block discarded – undo
57 57
 			'name'             => $a['name'],
58 58
 			'size'             => $a['size'],
59 59
 			'desc'             => '',
60
-			'data-previewsize' => sprintf( '[%d,%d]', $img_size_data['width'], $img_size_data['height'] ),
60
+			'data-previewsize' => sprintf('[%d,%d]', $img_size_data['width'], $img_size_data['height']),
61 61
 			'data-sizename'    => $img_size_data['name'],
62
-			'data-queryargs'   => ! empty( $a['query_args'] ) ? json_encode( $a['query_args'] ) : '',
62
+			'data-queryargs'   => ! empty($a['query_args']) ? json_encode($a['query_args']) : '',
63 63
 			'js_dependencies'  => $a['js_dependencies'],
64
-		) );
64
+		));
65 65
 
66 66
 		// Now remove the data-iterator attribute if it exists.
67 67
 		// (Possible if being used within a custom field)
68 68
 		// This is not elegant, but compensates for CMB2_Types::_id
69 69
 		// automagically & inelegantly adding the data-iterator attribute.
70 70
 		// Single responsibility principle? pffft.
71
-		$parts            = explode( '"', $this->args['id'] );
71
+		$parts            = explode('"', $this->args['id']);
72 72
 		$this->args['id'] = $parts[0];
73 73
 
74 74
 		$output .= sprintf(
75 75
 			'<input class="cmb2-upload-button button-secondary" type="button" value="%1$s" />',
76
-			esc_attr( $this->_text( 'add_upload_file_text', esc_html__( 'Add or Upload File', 'cmb2' ) ) )
76
+			esc_attr($this->_text('add_upload_file_text', esc_html__('Add or Upload File', 'cmb2')))
77 77
 		);
78 78
 
79 79
 		$output .= $a['desc'];
80 80
 		$output .= $this->get_id_field_output();
81 81
 
82
-		$output .= '<div id="' . esc_attr( $field->id() ) . '-status" class="cmb2-media-status">';
83
-		if ( ! empty( $a['value'] ) ) {
82
+		$output .= '<div id="' . esc_attr($field->id()) . '-status" class="cmb2-media-status">';
83
+		if ( ! empty($a['value'])) {
84 84
 			$output .= $this->get_file_preview_output();
85 85
 		}
86 86
 		$output .= '</div>';
87 87
 
88
-		return $this->rendered( $output );
88
+		return $this->rendered($output);
89 89
 	}
90 90
 
91 91
 	/**
@@ -96,28 +96,28 @@  discard block
 block discarded – undo
96 96
 	 * @return string
97 97
 	 */
98 98
 	public function get_file_preview_output() {
99
-		if ( ! $this->is_valid_img_ext( $this->args['value'] ) ) {
99
+		if ( ! $this->is_valid_img_ext($this->args['value'])) {
100 100
 
101
-			return $this->file_status_output( array(
101
+			return $this->file_status_output(array(
102 102
 				'value'     => $this->args['value'],
103 103
 				'tag'       => 'div',
104 104
 				'cached_id' => $this->args['id'],
105
-			) );
105
+			));
106 106
 		}
107 107
 
108
-		if ( $this->args['id_value'] ) {
109
-			$image = wp_get_attachment_image( $this->args['id_value'], $this->args['preview_size'], null, array(
108
+		if ($this->args['id_value']) {
109
+			$image = wp_get_attachment_image($this->args['id_value'], $this->args['preview_size'], null, array(
110 110
 				'class' => 'cmb-file-field-image',
111
-			) );
111
+			));
112 112
 		} else {
113
-			$image = '<img style="max-width: ' . absint( $this->args['img_size_data']['width'] ) . 'px; width: 100%;" src="' . esc_url( $this->args['value'] ) . '" class="cmb-file-field-image" alt="" />';
113
+			$image = '<img style="max-width: ' . absint($this->args['img_size_data']['width']) . 'px; width: 100%;" src="' . esc_url($this->args['value']) . '" class="cmb-file-field-image" alt="" />';
114 114
 		}
115 115
 
116
-		return $this->img_status_output( array(
116
+		return $this->img_status_output(array(
117 117
 			'image'     => $image,
118 118
 			'tag'       => 'div',
119 119
 			'cached_id' => $this->args['id'],
120
-		) );
120
+		));
121 121
 	}
122 122
 
123 123
 	/**
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
 		 */
137 137
 		$this->types->field = $this->get_id_field();
138 138
 
139
-		$output = parent::render( array(
139
+		$output = parent::render(array(
140 140
 			'type'  => 'hidden',
141 141
 			'class' => 'cmb2-upload-file-id',
142 142
 			'value' => $this->types->field->value,
143 143
 			'desc'  => '',
144
-		) );
144
+		));
145 145
 
146 146
 		// We need to put the original field object back
147 147
 		// or other fields in a custom field will be broken.
@@ -162,24 +162,24 @@  discard block
 block discarded – undo
162 162
 		// reset field args for attachment id.
163 163
 		$args = array(
164 164
 			// if we're looking at a file in a group, we need to get the non-prefixed id.
165
-			'id' => ( $this->field->group ? $this->field->args( '_id' ) : $this->args['id'] ) . '_id',
165
+			'id' => ($this->field->group ? $this->field->args('_id') : $this->args['id']) . '_id',
166 166
 			'disable_hash_data_attribute' => true,
167 167
 		);
168 168
 
169 169
 		// and get new field object
170 170
 		// (need to set it to the types field property).
171
-		$id_field = $this->field->get_field_clone( $args );
171
+		$id_field = $this->field->get_field_clone($args);
172 172
 
173
-		$id_value = absint( null !== $this->args['id_value'] ? $this->args['id_value'] : $id_field->escaped_value() );
173
+		$id_value = absint(null !== $this->args['id_value'] ? $this->args['id_value'] : $id_field->escaped_value());
174 174
 
175 175
 		// we don't want to output "0" as a value.
176
-		if ( ! $id_value ) {
176
+		if ( ! $id_value) {
177 177
 			$id_value = '';
178 178
 		}
179 179
 
180 180
 		// if there is no id saved yet, try to get it from the url.
181
-		if ( $this->args['value'] && ! $id_value ) {
182
-			$id_value = CMB2_Utils::image_id_from_url( esc_url_raw( $this->args['value'] ) );
181
+		if ($this->args['value'] && ! $id_value) {
182
+			$id_value = CMB2_Utils::image_id_from_url(esc_url_raw($this->args['value']));
183 183
 		}
184 184
 
185 185
 		$id_field->value = $id_value;
Please login to merge, or discard this patch.
vendor/CMB2/includes/helper-functions.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @param  string $path Path to append.
17 17
  * @return string        Directory with optional path appended
18 18
  */
19
-function cmb2_dir( $path = '' ) {
19
+function cmb2_dir($path = '') {
20 20
 	return CMB2_DIR . $path;
21 21
 }
22 22
 
@@ -26,22 +26,22 @@  discard block
 block discarded – undo
26 26
  * @since  1.0.0
27 27
  * @param  string $class_name Name of the class being requested.
28 28
  */
29
-function cmb2_autoload_classes( $class_name ) {
30
-	if ( 0 !== strpos( $class_name, 'CMB2' ) ) {
29
+function cmb2_autoload_classes($class_name) {
30
+	if (0 !== strpos($class_name, 'CMB2')) {
31 31
 		return;
32 32
 	}
33 33
 
34 34
 	$path = 'includes';
35 35
 
36
-	if ( 'CMB2_Type' === $class_name || 0 === strpos( $class_name, 'CMB2_Type_' ) ) {
36
+	if ('CMB2_Type' === $class_name || 0 === strpos($class_name, 'CMB2_Type_')) {
37 37
 		$path .= '/types';
38 38
 	}
39 39
 
40
-	if ( 'CMB2_REST' === $class_name || 0 === strpos( $class_name, 'CMB2_REST_' ) ) {
40
+	if ('CMB2_REST' === $class_name || 0 === strpos($class_name, 'CMB2_REST_')) {
41 41
 		$path .= '/rest-api';
42 42
 	}
43 43
 
44
-	include_once( cmb2_dir( "$path/{$class_name}.php" ) );
44
+	include_once(cmb2_dir("$path/{$class_name}.php"));
45 45
 }
46 46
 
47 47
 /**
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
  * @param string $key Option key to fetch.
75 75
  * @return CMB2_Option object Options class for setting/getting options for metabox
76 76
  */
77
-function cmb2_options( $key ) {
78
-	return CMB2_Options::get( $key );
77
+function cmb2_options($key) {
78
+	return CMB2_Options::get($key);
79 79
 }
80 80
 
81 81
 /**
@@ -94,23 +94,23 @@  discard block
 block discarded – undo
94 94
  *
95 95
  * @return string        oEmbed string
96 96
  */
97
-function cmb2_get_oembed( $args = array() ) {
98
-	$oembed = cmb2_ajax()->get_oembed_no_edit( $args );
97
+function cmb2_get_oembed($args = array()) {
98
+	$oembed = cmb2_ajax()->get_oembed_no_edit($args);
99 99
 
100 100
 	// Send back our embed.
101
-	if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) {
101
+	if ($oembed['embed'] && $oembed['embed'] != $oembed['fallback']) {
102 102
 		return '<div class="cmb2-oembed">' . $oembed['embed'] . '</div>';
103 103
 	}
104 104
 
105 105
 	$error = sprintf(
106 106
 		/* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */
107
-		esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ),
107
+		esc_html__('No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2'),
108 108
 		$oembed['fallback'],
109 109
 		'<a href="https://wordpress.org/support/article/embeds/" target="_blank">codex.wordpress.org/Embeds</a>'
110 110
 	);
111 111
 
112
-	if ( isset( $args['wp_error'] ) && $args['wp_error'] ) {
113
-		return new WP_Error( 'cmb2_get_oembed_result', $error, compact( 'oembed', 'args' ) );
112
+	if (isset($args['wp_error']) && $args['wp_error']) {
113
+		return new WP_Error('cmb2_get_oembed_result', $error, compact('oembed', 'args'));
114 114
 	}
115 115
 
116 116
 	// Otherwise, send back error info that no oEmbeds were found.
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
  *
126 126
  * @param array $args oEmbed args.
127 127
  */
128
-function cmb2_do_oembed( $args = array() ) {
129
-	echo cmb2_get_oembed( $args );
128
+function cmb2_do_oembed($args = array()) {
129
+	echo cmb2_get_oembed($args);
130 130
 }
131
-add_action( 'cmb2_do_oembed', 'cmb2_do_oembed' );
131
+add_action('cmb2_do_oembed', 'cmb2_do_oembed');
132 132
 
133 133
 /**
134 134
  * A helper function to get an option from a CMB2 options array
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param  mixed  $default    Optional default fallback value.
140 140
  * @return array               Options array or specific field
141 141
  */
142
-function cmb2_get_option( $option_key, $field_id = '', $default = false ) {
143
-	return cmb2_options( $option_key )->get( $field_id, $default );
142
+function cmb2_get_option($option_key, $field_id = '', $default = false) {
143
+	return cmb2_options($option_key)->get($field_id, $default);
144 144
 }
145 145
 
146 146
 /**
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
  * @param  boolean $single     Whether data should not be an array.
154 154
  * @return boolean             Success/Failure
155 155
  */
156
-function cmb2_update_option( $option_key, $field_id, $value, $single = true ) {
157
-	if ( cmb2_options( $option_key )->update( $field_id, $value, false, $single ) ) {
158
-		return cmb2_options( $option_key )->set();
156
+function cmb2_update_option($option_key, $field_id, $value, $single = true) {
157
+	if (cmb2_options($option_key)->update($field_id, $value, false, $single)) {
158
+		return cmb2_options($option_key)->set();
159 159
 	}
160 160
 
161 161
 	return false;
@@ -172,18 +172,18 @@  discard block
 block discarded – undo
172 172
  *                             Defaults to metabox object type.
173 173
  * @return CMB2_Field|null     CMB2_Field object unless metabox config cannot be found
174 174
  */
175
-function cmb2_get_field( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
175
+function cmb2_get_field($meta_box, $field_id, $object_id = 0, $object_type = '') {
176 176
 
177 177
 	$object_id = $object_id ? $object_id : get_the_ID();
178
-	$cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox( $meta_box, $object_id );
178
+	$cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox($meta_box, $object_id);
179 179
 
180
-	if ( ! $cmb ) {
180
+	if ( ! $cmb) {
181 181
 		return;
182 182
 	}
183 183
 
184
-	$cmb->object_type( $object_type ? $object_type : $cmb->mb_object_type() );
184
+	$cmb->object_type($object_type ? $object_type : $cmb->mb_object_type());
185 185
 
186
-	return $cmb->get_field( $field_id );
186
+	return $cmb->get_field($field_id);
187 187
 }
188 188
 
189 189
 /**
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
  *                             Defaults to metabox object type.
198 198
  * @return mixed               Maybe escaped value
199 199
  */
200
-function cmb2_get_field_value( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
201
-	$field = cmb2_get_field( $meta_box, $field_id, $object_id, $object_type );
200
+function cmb2_get_field_value($meta_box, $field_id, $object_id = 0, $object_type = '') {
201
+	$field = cmb2_get_field($meta_box, $field_id, $object_id, $object_type);
202 202
 	return $field->escaped_value();
203 203
 }
204 204
 
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
  * @param  array $meta_box_config Metabox Config array.
210 210
  * @return CMB2 object            Instantiated CMB2 object
211 211
  */
212
-function new_cmb2_box( array $meta_box_config ) {
213
-	return cmb2_get_metabox( $meta_box_config );
212
+function new_cmb2_box(array $meta_box_config) {
213
+	return cmb2_get_metabox($meta_box_config);
214 214
 }
215 215
 
216 216
 /**
@@ -223,27 +223,27 @@  discard block
 block discarded – undo
223 223
  *                             Defaults to metabox object type.
224 224
  * @return CMB2 object
225 225
  */
226
-function cmb2_get_metabox( $meta_box, $object_id = 0, $object_type = '' ) {
226
+function cmb2_get_metabox($meta_box, $object_id = 0, $object_type = '') {
227 227
 
228
-	if ( $meta_box instanceof CMB2 ) {
228
+	if ($meta_box instanceof CMB2) {
229 229
 		return $meta_box;
230 230
 	}
231 231
 
232
-	if ( is_string( $meta_box ) ) {
233
-		$cmb = CMB2_Boxes::get( $meta_box );
232
+	if (is_string($meta_box)) {
233
+		$cmb = CMB2_Boxes::get($meta_box);
234 234
 	} else {
235 235
 		// See if we already have an instance of this metabox.
236
-		$cmb = CMB2_Boxes::get( $meta_box['id'] );
236
+		$cmb = CMB2_Boxes::get($meta_box['id']);
237 237
 		// If not, we'll initate a new metabox.
238
-		$cmb = $cmb ? $cmb : new CMB2( $meta_box, $object_id );
238
+		$cmb = $cmb ? $cmb : new CMB2($meta_box, $object_id);
239 239
 	}
240 240
 
241
-	if ( $cmb && $object_id ) {
242
-		$cmb->object_id( $object_id );
241
+	if ($cmb && $object_id) {
242
+		$cmb->object_id($object_id);
243 243
 	}
244 244
 
245
-	if ( $cmb && $object_type ) {
246
-		$cmb->object_type( $object_type );
245
+	if ($cmb && $object_type) {
246
+		$cmb->object_type($object_type);
247 247
 	}
248 248
 
249 249
 	return $cmb;
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
  * @param  array $data_to_sanitize Array of field_id => value data for sanitizing (likely $_POST data).
258 258
  * @return mixed                   Array of sanitized values or false if no CMB2 object found
259 259
  */
260
-function cmb2_get_metabox_sanitized_values( $meta_box, array $data_to_sanitize ) {
261
-	$cmb = cmb2_get_metabox( $meta_box );
262
-	return $cmb ? $cmb->get_sanitized_values( $data_to_sanitize ) : false;
260
+function cmb2_get_metabox_sanitized_values($meta_box, array $data_to_sanitize) {
261
+	$cmb = cmb2_get_metabox($meta_box);
262
+	return $cmb ? $cmb->get_sanitized_values($data_to_sanitize) : false;
263 263
 }
264 264
 
265 265
 /**
@@ -271,17 +271,17 @@  discard block
 block discarded – undo
271 271
  * @param  array $args      Optional arguments array.
272 272
  * @return string             CMB2 html form markup
273 273
  */
274
-function cmb2_get_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
274
+function cmb2_get_metabox_form($meta_box, $object_id = 0, $args = array()) {
275 275
 
276 276
 	$object_id = $object_id ? $object_id : get_the_ID();
277
-	$cmb       = cmb2_get_metabox( $meta_box, $object_id );
277
+	$cmb       = cmb2_get_metabox($meta_box, $object_id);
278 278
 
279 279
 	ob_start();
280 280
 	// Get cmb form.
281
-	cmb2_print_metabox_form( $cmb, $object_id, $args );
281
+	cmb2_print_metabox_form($cmb, $object_id, $args);
282 282
 	$form = ob_get_clean();
283 283
 
284
-	return apply_filters( 'cmb2_get_metabox_form', $form, $object_id, $cmb );
284
+	return apply_filters('cmb2_get_metabox_form', $form, $object_id, $cmb);
285 285
 }
286 286
 
287 287
 /**
@@ -292,59 +292,59 @@  discard block
 block discarded – undo
292 292
  * @param  int   $object_id Object ID.
293 293
  * @param  array $args      Optional arguments array.
294 294
  */
295
-function cmb2_print_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
295
+function cmb2_print_metabox_form($meta_box, $object_id = 0, $args = array()) {
296 296
 
297 297
 	$object_id = $object_id ? $object_id : get_the_ID();
298
-	$cmb = cmb2_get_metabox( $meta_box, $object_id );
298
+	$cmb = cmb2_get_metabox($meta_box, $object_id);
299 299
 
300 300
 	// if passing a metabox ID, and that ID was not found.
301
-	if ( ! $cmb ) {
301
+	if ( ! $cmb) {
302 302
 		return;
303 303
 	}
304 304
 
305
-	$args = wp_parse_args( $args, array(
305
+	$args = wp_parse_args($args, array(
306 306
 		'form_format' => '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<input type="submit" name="submit-cmb" value="%4$s" class="button-primary"></form>',
307
-		'save_button' => esc_html__( 'Save', 'cmb2' ),
307
+		'save_button' => esc_html__('Save', 'cmb2'),
308 308
 		'object_type' => $cmb->mb_object_type(),
309
-		'cmb_styles'  => $cmb->prop( 'cmb_styles' ),
310
-		'enqueue_js'  => $cmb->prop( 'enqueue_js' ),
311
-	) );
309
+		'cmb_styles'  => $cmb->prop('cmb_styles'),
310
+		'enqueue_js'  => $cmb->prop('enqueue_js'),
311
+	));
312 312
 
313 313
 	// Set object type explicitly (rather than trying to guess from context).
314
-	$cmb->object_type( $args['object_type'] );
314
+	$cmb->object_type($args['object_type']);
315 315
 
316 316
 	// Save the metabox if it's been submitted
317 317
 	// check permissions
318 318
 	// @todo more hardening?
319 319
 	if (
320
-		$cmb->prop( 'save_fields' )
320
+		$cmb->prop('save_fields')
321 321
 		// check nonce.
322
-		&& isset( $_POST['submit-cmb'], $_POST['object_id'], $_POST[ $cmb->nonce() ] )
323
-		&& wp_verify_nonce( $_POST[ $cmb->nonce() ], $cmb->nonce() )
322
+		&& isset($_POST['submit-cmb'], $_POST['object_id'], $_POST[$cmb->nonce()])
323
+		&& wp_verify_nonce($_POST[$cmb->nonce()], $cmb->nonce())
324 324
 		&& $object_id && $_POST['object_id'] == $object_id
325 325
 	) {
326
-		$cmb->save_fields( $object_id, $cmb->object_type(), $_POST );
326
+		$cmb->save_fields($object_id, $cmb->object_type(), $_POST);
327 327
 	}
328 328
 
329 329
 	// Enqueue JS/CSS.
330
-	if ( $args['cmb_styles'] ) {
330
+	if ($args['cmb_styles']) {
331 331
 		CMB2_Hookup::enqueue_cmb_css();
332 332
 	}
333 333
 
334
-	if ( $args['enqueue_js'] ) {
334
+	if ($args['enqueue_js']) {
335 335
 		CMB2_Hookup::enqueue_cmb_js();
336 336
 	}
337 337
 
338
-	$form_format = apply_filters( 'cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb );
338
+	$form_format = apply_filters('cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb);
339 339
 
340
-	$format_parts = explode( '%3$s', $form_format );
340
+	$format_parts = explode('%3$s', $form_format);
341 341
 
342 342
 	// Show cmb form.
343
-	printf( $format_parts[0], esc_attr( $cmb->cmb_id ), esc_attr( $object_id ) );
343
+	printf($format_parts[0], esc_attr($cmb->cmb_id), esc_attr($object_id));
344 344
 	$cmb->show_form();
345 345
 
346
-	if ( isset( $format_parts[1] ) && $format_parts[1] ) {
347
-		printf( str_ireplace( '%4$s', '%1$s', $format_parts[1] ), esc_attr( $args['save_button'] ) );
346
+	if (isset($format_parts[1]) && $format_parts[1]) {
347
+		printf(str_ireplace('%4$s', '%1$s', $format_parts[1]), esc_attr($args['save_button']));
348 348
 	}
349 349
 
350 350
 }
@@ -358,15 +358,15 @@  discard block
 block discarded – undo
358 358
  * @param  array $args      Optional arguments array.
359 359
  * @return string
360 360
  */
361
-function cmb2_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
362
-	if ( ! isset( $args['echo'] ) || $args['echo'] ) {
363
-		cmb2_print_metabox_form( $meta_box, $object_id, $args );
361
+function cmb2_metabox_form($meta_box, $object_id = 0, $args = array()) {
362
+	if ( ! isset($args['echo']) || $args['echo']) {
363
+		cmb2_print_metabox_form($meta_box, $object_id, $args);
364 364
 	} else {
365
-		return cmb2_get_metabox_form( $meta_box, $object_id, $args );
365
+		return cmb2_get_metabox_form($meta_box, $object_id, $args);
366 366
 	}
367 367
 }
368 368
 
369
-if ( ! function_exists( 'date_create_from_format' ) ) {
369
+if ( ! function_exists('date_create_from_format')) {
370 370
 
371 371
 	/**
372 372
 	 * Reimplementation of DateTime::createFromFormat for PHP < 5.3. :(
@@ -377,11 +377,11 @@  discard block
 block discarded – undo
377 377
 	 *
378 378
 	 * @return DateTime
379 379
 	 */
380
-	function date_create_from_format( $date_format, $date_value ) {
380
+	function date_create_from_format($date_format, $date_value) {
381 381
 
382 382
 		$schedule_format = str_replace(
383
-			array( 'M', 'Y', 'm', 'd', 'H', 'i', 'a' ),
384
-			array( '%b', '%Y', '%m', '%d', '%H', '%M', '%p' ),
383
+			array('M', 'Y', 'm', 'd', 'H', 'i', 'a'),
384
+			array('%b', '%Y', '%m', '%d', '%H', '%M', '%p'),
385 385
 			$date_format
386 386
 		);
387 387
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 		 * %Y, %m and %d correspond to date()'s Y m and d.
390 390
 		 * %I corresponds to H, %M to i and %p to a
391 391
 		 */
392
-		$parsed_time = strptime( $date_value, $schedule_format );
392
+		$parsed_time = strptime($date_value, $schedule_format);
393 393
 
394 394
 		$ymd = sprintf(
395 395
 			/**
@@ -398,19 +398,19 @@  discard block
 block discarded – undo
398 398
 			 * 4 or 2 characters, as needed
399 399
 			 */
400 400
 			'%04d-%02d-%02d %02d:%02d:%02d',
401
-			$parsed_time['tm_year'] + 1900,  // This will be "111", so we need to add 1900.
402
-			$parsed_time['tm_mon'] + 1,      // This will be the month minus one, so we add one.
401
+			$parsed_time['tm_year'] + 1900, // This will be "111", so we need to add 1900.
402
+			$parsed_time['tm_mon'] + 1, // This will be the month minus one, so we add one.
403 403
 			$parsed_time['tm_mday'],
404 404
 			$parsed_time['tm_hour'],
405 405
 			$parsed_time['tm_min'],
406 406
 			$parsed_time['tm_sec']
407 407
 		);
408 408
 
409
-		return new DateTime( $ymd );
409
+		return new DateTime($ymd);
410 410
 	}
411 411
 }// End if.
412 412
 
413
-if ( ! function_exists( 'date_timestamp_get' ) ) {
413
+if ( ! function_exists('date_timestamp_get')) {
414 414
 
415 415
 	/**
416 416
 	 * Returns the Unix timestamp representing the date.
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @return int
422 422
 	 */
423
-	function date_timestamp_get( DateTime $date ) {
424
-		return $date->format( 'U' );
423
+	function date_timestamp_get(DateTime $date) {
424
+		return $date->format('U');
425 425
 	}
426 426
 }// End if.
Please login to merge, or discard this patch.
vendor/CMB2/includes/rest-api/CMB2_REST_Controller_Fields.php 1 patch
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -24,57 +24,57 @@  discard block
 block discarded – undo
24 24
 	public function register_routes() {
25 25
 		$args = array(
26 26
 			'_embed' => array(
27
-				'description' => __( 'Includes the box object which the fields are registered to in the response.', 'cmb2' ),
27
+				'description' => __('Includes the box object which the fields are registered to in the response.', 'cmb2'),
28 28
 			),
29 29
 			'_rendered' => array(
30
-				'description' => __( 'When the \'_rendered\' argument is passed, the renderable field attributes will be returned fully rendered. By default, the names of the callback handers for the renderable attributes will be returned.', 'cmb2' ),
30
+				'description' => __('When the \'_rendered\' argument is passed, the renderable field attributes will be returned fully rendered. By default, the names of the callback handers for the renderable attributes will be returned.', 'cmb2'),
31 31
 			),
32 32
 			'object_id' => array(
33
-				'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ),
33
+				'description' => __('To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2'),
34 34
 			),
35 35
 			'object_type' => array(
36
-				'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ),
36
+				'description' => __('To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2'),
37 37
 			),
38 38
 		);
39 39
 
40 40
 		// Returns specific box's fields.
41
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/', array(
41
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/', array(
42 42
 			array(
43 43
 				'methods'             => WP_REST_Server::READABLE,
44
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
45
-				'callback'            => array( $this, 'get_items' ),
44
+				'permission_callback' => array($this, 'get_items_permissions_check'),
45
+				'callback'            => array($this, 'get_items'),
46 46
 				'args'                => $args,
47 47
 			),
48
-			'schema' => array( $this, 'get_item_schema' ),
49
-		) );
48
+			'schema' => array($this, 'get_item_schema'),
49
+		));
50 50
 
51 51
 		$delete_args = $args;
52 52
 		$delete_args['object_id']['required'] = true;
53 53
 		$delete_args['object_type']['required'] = true;
54 54
 
55 55
 		// Returns specific field data.
56
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array(
56
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array(
57 57
 			array(
58 58
 				'methods'             => WP_REST_Server::READABLE,
59
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
60
-				'callback'            => array( $this, 'get_item' ),
59
+				'permission_callback' => array($this, 'get_item_permissions_check'),
60
+				'callback'            => array($this, 'get_item'),
61 61
 				'args'                => $args,
62 62
 			),
63 63
 			array(
64 64
 				'methods'             => WP_REST_Server::EDITABLE,
65
-				'permission_callback' => array( $this, 'update_item_permissions_check' ),
66
-				'callback'            => array( $this, 'update_item' ),
67
-				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
65
+				'permission_callback' => array($this, 'update_item_permissions_check'),
66
+				'callback'            => array($this, 'update_item'),
67
+				'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
68 68
 				'args'                => $args,
69 69
 			),
70 70
 			array(
71 71
 				'methods'             => WP_REST_Server::DELETABLE,
72
-				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
73
-				'callback'            => array( $this, 'delete_item' ),
72
+				'permission_callback' => array($this, 'delete_item_permissions_check'),
73
+				'callback'            => array($this, 'delete_item'),
74 74
 				'args'                => $delete_args,
75 75
 			),
76
-			'schema' => array( $this, 'get_item_schema' ),
77
-		) );
76
+			'schema' => array($this, 'get_item_schema'),
77
+		));
78 78
 	}
79 79
 
80 80
 	/**
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @param  WP_REST_Request $request Full data about the request.
87 87
 	 * @return WP_Error|boolean
88 88
 	 */
89
-	public function get_items_permissions_check( $request ) {
90
-		$this->initiate_rest_read_box( $request, 'fields_read' );
89
+	public function get_items_permissions_check($request) {
90
+		$this->initiate_rest_read_box($request, 'fields_read');
91 91
 		$can_access = true;
92 92
 
93 93
 		/**
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 * @param bool   $can_access Whether this CMB2 endpoint can be accessed.
99 99
 		 * @param object $controller This CMB2_REST_Controller object.
100 100
 		 */
101
-		return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_fields_permissions_check', $can_access );
101
+		return $this->maybe_hook_callback_and_apply_filters('cmb2_api_get_fields_permissions_check', $can_access);
102 102
 	}
103 103
 
104 104
 	/**
@@ -109,31 +109,31 @@  discard block
 block discarded – undo
109 109
 	 * @param  WP_REST_Request $request Full data about the request.
110 110
 	 * @return WP_Error|WP_REST_Response
111 111
 	 */
112
-	public function get_items( $request ) {
113
-		if ( ! $this->rest_box ) {
114
-			$this->initiate_rest_read_box( $request, 'fields_read' );
112
+	public function get_items($request) {
113
+		if ( ! $this->rest_box) {
114
+			$this->initiate_rest_read_box($request, 'fields_read');
115 115
 		}
116 116
 
117
-		if ( is_wp_error( $this->rest_box ) ) {
117
+		if (is_wp_error($this->rest_box)) {
118 118
 			return $this->rest_box;
119 119
 		}
120 120
 
121 121
 		$fields = array();
122
-		foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) {
122
+		foreach ($this->rest_box->cmb->prop('fields', array()) as $field) {
123 123
 
124 124
 			// Make sure this field can be read.
125
-			$this->field = $this->rest_box->field_can_read( $field['id'], true );
125
+			$this->field = $this->rest_box->field_can_read($field['id'], true);
126 126
 
127 127
 			// And make sure current user can view this box.
128
-			if ( $this->field && $this->get_item_permissions_check_filter() ) {
129
-				$fields[ $field['id'] ] = $this->server->response_to_data(
128
+			if ($this->field && $this->get_item_permissions_check_filter()) {
129
+				$fields[$field['id']] = $this->server->response_to_data(
130 130
 					$this->prepare_field_response(),
131
-					isset( $this->request['_embed'] )
131
+					isset($this->request['_embed'])
132 132
 				);
133 133
 			}
134 134
 		}
135 135
 
136
-		return $this->prepare_item( $fields );
136
+		return $this->prepare_item($fields);
137 137
 	}
138 138
 
139 139
 	/**
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 	 * @param  WP_REST_Request $request Full details about the request.
146 146
 	 * @return WP_Error|boolean
147 147
 	 */
148
-	public function get_item_permissions_check( $request ) {
149
-		$this->initiate_rest_read_box( $request, 'field_read' );
150
-		if ( ! is_wp_error( $this->rest_box ) ) {
151
-			$this->field = $this->rest_box->field_can_read( $this->request->get_param( 'field_id' ), true );
148
+	public function get_item_permissions_check($request) {
149
+		$this->initiate_rest_read_box($request, 'field_read');
150
+		if ( ! is_wp_error($this->rest_box)) {
151
+			$this->field = $this->rest_box->field_can_read($this->request->get_param('field_id'), true);
152 152
 		}
153 153
 
154 154
 		return $this->get_item_permissions_check_filter();
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 * @param  bool $can_access Whether the current request has access to view the field by default.
164 164
 	 * @return WP_Error|boolean
165 165
 	 */
166
-	public function get_item_permissions_check_filter( $can_access = true ) {
166
+	public function get_item_permissions_check_filter($can_access = true) {
167 167
 		/**
168 168
 		 * By default, no special permissions needed.
169 169
 		 *
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		 * @param bool   $can_access Whether this CMB2 endpoint can be accessed.
173 173
 		 * @param object $controller This CMB2_REST_Controller object.
174 174
 		 */
175
-		return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_field_permissions_check', $can_access );
175
+		return $this->maybe_hook_callback_and_apply_filters('cmb2_api_get_field_permissions_check', $can_access);
176 176
 	}
177 177
 
178 178
 	/**
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 	 * @param  WP_REST_Request $request Full data about the request.
184 184
 	 * @return WP_Error|WP_REST_Response
185 185
 	 */
186
-	public function get_item( $request ) {
187
-		$this->initiate_rest_read_box( $request, 'field_read' );
186
+	public function get_item($request) {
187
+		$this->initiate_rest_read_box($request, 'field_read');
188 188
 
189
-		if ( is_wp_error( $this->rest_box ) ) {
189
+		if (is_wp_error($this->rest_box)) {
190 190
 			return $this->rest_box;
191 191
 		}
192 192
 
193
-		return $this->prepare_read_field( $this->request->get_param( 'field_id' ) );
193
+		return $this->prepare_read_field($this->request->get_param('field_id'));
194 194
 	}
195 195
 
196 196
 	/**
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
 	 * @param  WP_REST_Request $request Full details about the request.
203 203
 	 * @return WP_Error|boolean
204 204
 	 */
205
-	public function update_item_permissions_check( $request ) {
206
-		$this->initiate_rest_read_box( $request, 'field_value_update' );
207
-		if ( ! is_wp_error( $this->rest_box ) ) {
208
-			$this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true );
205
+	public function update_item_permissions_check($request) {
206
+		$this->initiate_rest_read_box($request, 'field_value_update');
207
+		if ( ! is_wp_error($this->rest_box)) {
208
+			$this->field = $this->rest_box->field_can_edit($this->request->get_param('field_id'), true);
209 209
 		}
210 210
 
211
-		$can_update = current_user_can( 'edit_others_posts' );
211
+		$can_update = current_user_can('edit_others_posts');
212 212
 
213 213
 		/**
214 214
 		 * By default, 'edit_others_posts' is required capability.
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 		 * @param bool   $can_update Whether this CMB2 endpoint can be accessed.
219 219
 		 * @param object $controller This CMB2_REST_Controller object.
220 220
 		 */
221
-		return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_update_field_value_permissions_check', $can_update );
221
+		return $this->maybe_hook_callback_and_apply_filters('cmb2_api_update_field_value_permissions_check', $can_update);
222 222
 	}
223 223
 
224 224
 	/**
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
 	 * @param  WP_REST_Request $request Full data about the request.
230 230
 	 * @return WP_Error|WP_REST_Response
231 231
 	 */
232
-	public function update_item( $request ) {
233
-		$this->initiate_rest_read_box( $request, 'field_value_update' );
232
+	public function update_item($request) {
233
+		$this->initiate_rest_read_box($request, 'field_value_update');
234 234
 
235
-		if ( ! $this->request['value'] ) {
236
-			return new WP_Error( 'cmb2_rest_update_field_error', __( 'CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2' ), array(
235
+		if ( ! $this->request['value']) {
236
+			return new WP_Error('cmb2_rest_update_field_error', __('CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2'), array(
237 237
 				'status' => 400,
238
-			) );
238
+			));
239 239
 		}
240 240
 
241
-		return $this->modify_field_value( 'updated' );
241
+		return $this->modify_field_value('updated');
242 242
 	}
243 243
 
244 244
 	/**
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	 * @param  WP_REST_Request $request Full details about the request.
251 251
 	 * @return WP_Error|boolean
252 252
 	 */
253
-	public function delete_item_permissions_check( $request ) {
254
-		$this->initiate_rest_read_box( $request, 'field_value_delete' );
255
-		if ( ! is_wp_error( $this->rest_box ) ) {
256
-			$this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true );
253
+	public function delete_item_permissions_check($request) {
254
+		$this->initiate_rest_read_box($request, 'field_value_delete');
255
+		if ( ! is_wp_error($this->rest_box)) {
256
+			$this->field = $this->rest_box->field_can_edit($this->request->get_param('field_id'), true);
257 257
 		}
258 258
 
259
-		$can_delete = current_user_can( 'delete_others_posts' );
259
+		$can_delete = current_user_can('delete_others_posts');
260 260
 
261 261
 		/**
262 262
 		 * By default, 'delete_others_posts' is required capability.
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 		 * @param bool   $can_delete Whether this CMB2 endpoint can be accessed.
267 267
 		 * @param object $controller This CMB2_REST_Controller object.
268 268
 		 */
269
-		return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_delete_field_value_permissions_check', $can_delete );
269
+		return $this->maybe_hook_callback_and_apply_filters('cmb2_api_delete_field_value_permissions_check', $can_delete);
270 270
 	}
271 271
 
272 272
 	/**
@@ -277,10 +277,10 @@  discard block
 block discarded – undo
277 277
 	 * @param  WP_REST_Request $request Full data about the request.
278 278
 	 * @return WP_Error|WP_REST_Response
279 279
 	 */
280
-	public function delete_item( $request ) {
281
-		$this->initiate_rest_read_box( $request, 'field_value_delete' );
280
+	public function delete_item($request) {
281
+		$this->initiate_rest_read_box($request, 'field_value_delete');
282 282
 
283
-		return $this->modify_field_value( 'deleted' );
283
+		return $this->modify_field_value('deleted');
284 284
 	}
285 285
 
286 286
 	/**
@@ -291,39 +291,39 @@  discard block
 block discarded – undo
291 291
 	 * @param  string $activity The modification activity (updated or deleted).
292 292
 	 * @return WP_Error|WP_REST_Response
293 293
 	 */
294
-	public function modify_field_value( $activity ) {
294
+	public function modify_field_value($activity) {
295 295
 
296
-		if ( ! $this->request['object_id'] || ! $this->request['object_type'] ) {
297
-			return new WP_Error( 'cmb2_rest_modify_field_value_error', __( 'CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2' ), array(
296
+		if ( ! $this->request['object_id'] || ! $this->request['object_type']) {
297
+			return new WP_Error('cmb2_rest_modify_field_value_error', __('CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2'), array(
298 298
 				'status' => 400,
299
-			) );
299
+			));
300 300
 		}
301 301
 
302
-		if ( is_wp_error( $this->rest_box ) ) {
302
+		if (is_wp_error($this->rest_box)) {
303 303
 			return $this->rest_box;
304 304
 		}
305 305
 
306 306
 		$this->field = $this->rest_box->field_can_edit(
307
-			$this->field ? $this->field : $this->request->get_param( 'field_id' ),
307
+			$this->field ? $this->field : $this->request->get_param('field_id'),
308 308
 			true
309 309
 		);
310 310
 
311
-		if ( ! $this->field ) {
312
-			return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array(
311
+		if ( ! $this->field) {
312
+			return new WP_Error('cmb2_rest_no_field_by_id_error', __('No field found by that id.', 'cmb2'), array(
313 313
 				'status' => 403,
314
-			) );
314
+			));
315 315
 		}
316 316
 
317
-		$this->field->args[ "value_{$activity}" ] = (bool) 'deleted' === $activity
317
+		$this->field->args["value_{$activity}"] = (bool) 'deleted' === $activity
318 318
 			? $this->field->remove_data()
319
-			: $this->field->save_field( $this->request['value'] );
319
+			: $this->field->save_field($this->request['value']);
320 320
 
321 321
 		// If options page, save the $activity options
322
-		if ( 'options-page' == $this->request['object_type'] ) {
323
-			$this->field->args[ "value_{$activity}" ] = cmb2_options( $this->request['object_id'] )->set();
322
+		if ('options-page' == $this->request['object_type']) {
323
+			$this->field->args["value_{$activity}"] = cmb2_options($this->request['object_id'])->set();
324 324
 		}
325 325
 
326
-		return $this->prepare_read_field( $this->field );
326
+		return $this->prepare_read_field($this->field);
327 327
 	}
328 328
 
329 329
 	/**
@@ -334,16 +334,16 @@  discard block
 block discarded – undo
334 334
 	 * @param  string\CMB2_Field Field id or Field object.
335 335
 	 * @return WP_Error|WP_REST_Response
336 336
 	 */
337
-	public function prepare_read_field( $field ) {
338
-		$this->field = $this->rest_box->field_can_read( $field, true );
337
+	public function prepare_read_field($field) {
338
+		$this->field = $this->rest_box->field_can_read($field, true);
339 339
 
340
-		if ( ! $this->field ) {
341
-			return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array(
340
+		if ( ! $this->field) {
341
+			return new WP_Error('cmb2_rest_no_field_by_id_error', __('No field found by that id.', 'cmb2'), array(
342 342
 				'status' => 403,
343
-			) );
343
+			));
344 344
 		}
345 345
 
346
-		return $this->prepare_item( $this->prepare_field_response() );
346
+		return $this->prepare_item($this->prepare_field_response());
347 347
 	}
348 348
 
349 349
 	/**
@@ -355,10 +355,10 @@  discard block
 block discarded – undo
355 355
 	 * @return array      Response array.
356 356
 	 */
357 357
 	public function prepare_field_response() {
358
-		$field_data = $this->prepare_field_data( $this->field );
359
-		$response = rest_ensure_response( $field_data );
358
+		$field_data = $this->prepare_field_data($this->field);
359
+		$response = rest_ensure_response($field_data);
360 360
 
361
-		$response->add_links( $this->prepare_links( $this->field ) );
361
+		$response->add_links($this->prepare_links($this->field));
362 362
 
363 363
 		return $response;
364 364
 	}
@@ -372,55 +372,55 @@  discard block
 block discarded – undo
372 372
 	 *
373 373
 	 * @return array             Array of field data.
374 374
 	 */
375
-	protected function prepare_field_data( CMB2_Field $field ) {
375
+	protected function prepare_field_data(CMB2_Field $field) {
376 376
 		$field_data = array();
377
-		$params_to_ignore = array( 'show_in_rest', 'options' );
377
+		$params_to_ignore = array('show_in_rest', 'options');
378 378
 		$params_to_rename = array(
379 379
 			'label_cb' => 'label',
380 380
 			'options_cb' => 'options',
381 381
 		);
382 382
 
383 383
 		// Run this first so the js_dependencies arg is populated.
384
-		$rendered = ( $cb = $field->maybe_callback( 'render_row_cb' ) )
384
+		$rendered = ($cb = $field->maybe_callback('render_row_cb'))
385 385
 			// Ok, callback is good, let's run it.
386
-			? $this->get_cb_results( $cb, $field->args(), $field )
386
+			? $this->get_cb_results($cb, $field->args(), $field)
387 387
 			: false;
388 388
 
389 389
 		$field_args = $field->args();
390 390
 
391
-		foreach ( $field_args as $key => $value ) {
392
-			if ( in_array( $key, $params_to_ignore, true ) ) {
391
+		foreach ($field_args as $key => $value) {
392
+			if (in_array($key, $params_to_ignore, true)) {
393 393
 				continue;
394 394
 			}
395 395
 
396
-			if ( 'options_cb' === $key ) {
396
+			if ('options_cb' === $key) {
397 397
 				$value = $field->options();
398
-			} elseif ( in_array( $key, CMB2_Field::$callable_fields, true ) ) {
398
+			} elseif (in_array($key, CMB2_Field::$callable_fields, true)) {
399 399
 
400
-				if ( isset( $this->request['_rendered'] ) ) {
401
-					$value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result( $key );
402
-				} elseif ( is_array( $value ) ) {
400
+				if (isset($this->request['_rendered'])) {
401
+					$value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result($key);
402
+				} elseif (is_array($value)) {
403 403
 					// We need to rewrite callbacks as string as they will cause
404 404
 					// JSON recursion errors.
405
-					$class = is_string( $value[0] ) ? $value[0] : get_class( $value[0] );
405
+					$class = is_string($value[0]) ? $value[0] : get_class($value[0]);
406 406
 					$value = $class . '::' . $value[1];
407 407
 				}
408 408
 			}
409 409
 
410
-			$key = isset( $params_to_rename[ $key ] ) ? $params_to_rename[ $key ] : $key;
410
+			$key = isset($params_to_rename[$key]) ? $params_to_rename[$key] : $key;
411 411
 
412
-			if ( empty( $value ) || is_scalar( $value ) || is_array( $value ) ) {
413
-				$field_data[ $key ] = $value;
412
+			if (empty($value) || is_scalar($value) || is_array($value)) {
413
+				$field_data[$key] = $value;
414 414
 			} else {
415
-				$field_data[ $key ] = sprintf( __( 'Value Error for %s', 'cmb2' ), $key );
415
+				$field_data[$key] = sprintf(__('Value Error for %s', 'cmb2'), $key);
416 416
 			}
417 417
 		}
418 418
 
419
-		if ( $field->args( 'has_supporting_data' ) ) {
420
-			$field_data = $this->get_supporting_data( $field_data, $field );
419
+		if ($field->args('has_supporting_data')) {
420
+			$field_data = $this->get_supporting_data($field_data, $field);
421 421
 		}
422 422
 
423
-		if ( $this->request['object_id'] && $this->request['object_type'] ) {
423
+		if ($this->request['object_id'] && $this->request['object_type']) {
424 424
 			$field_data['value'] = $field->get_rest_value();
425 425
 		}
426 426
 
@@ -437,18 +437,18 @@  discard block
 block discarded – undo
437 437
 	 *
438 438
 	 * @return array                  Array of field data.
439 439
 	 */
440
-	public function get_supporting_data( $field_data, $field ) {
440
+	public function get_supporting_data($field_data, $field) {
441 441
 
442 442
 		// Reset placement of this property.
443
-		unset( $field_data['has_supporting_data'] );
443
+		unset($field_data['has_supporting_data']);
444 444
 		$field_data['has_supporting_data'] = true;
445 445
 
446 446
 		$field = $field->get_supporting_field();
447 447
 		$field_data['supporting_data'] = array(
448
-			'id' => $field->_id( '', false ),
448
+			'id' => $field->_id('', false),
449 449
 		);
450 450
 
451
-		if ( $this->request['object_id'] && $this->request['object_type'] ) {
451
+		if ($this->request['object_id'] && $this->request['object_type']) {
452 452
 			$field_data['supporting_data']['value'] = $field->get_rest_value();
453 453
 		}
454 454
 
@@ -464,20 +464,20 @@  discard block
 block discarded – undo
464 464
 	 *
465 465
 	 * @return array             Array of links
466 466
 	 */
467
-	protected function prepare_links( $field ) {
467
+	protected function prepare_links($field) {
468 468
 		$boxbase      = $this->namespace_base . '/' . $this->rest_box->cmb->cmb_id;
469 469
 		$query_string = $this->get_query_string();
470 470
 
471 471
 		$links = array(
472 472
 			'self' => array(
473
-				'href' => rest_url( trailingslashit( $boxbase ) . 'fields/' . $field->_id( '', false ) . $query_string ),
473
+				'href' => rest_url(trailingslashit($boxbase) . 'fields/' . $field->_id('', false) . $query_string),
474 474
 			),
475 475
 			'collection' => array(
476
-				'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ),
476
+				'href' => rest_url(trailingslashit($boxbase) . 'fields' . $query_string),
477 477
 			),
478 478
 			'up' => array(
479 479
 				'embeddable' => true,
480
-				'href' => rest_url( $boxbase . $query_string ),
480
+				'href' => rest_url($boxbase . $query_string),
481 481
 			),
482 482
 		);
483 483
 
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 	 *
499 499
 	 * @return bool                The possibly-modified filter value (if the _cb param is a non-callable).
500 500
 	 */
501
-	public function maybe_hook_registered_callback( $filter, $default_val ) {
502
-		$default_val = parent::maybe_hook_registered_callback( $filter, $default_val );
501
+	public function maybe_hook_registered_callback($filter, $default_val) {
502
+		$default_val = parent::maybe_hook_registered_callback($filter, $default_val);
503 503
 
504
-		if ( $this->field ) {
504
+		if ($this->field) {
505 505
 
506 506
 			// Hook field specific filter callbacks.
507
-			$val = $this->field->maybe_hook_parameter( $filter, $default_val );
508
-			if ( null !== $val ) {
507
+			$val = $this->field->maybe_hook_parameter($filter, $default_val);
508
+			if (null !== $val) {
509 509
 				$default_val = $val;
510 510
 			}
511 511
 		}
@@ -522,12 +522,12 @@  discard block
 block discarded – undo
522 522
 	 *
523 523
 	 * @return void
524 524
 	 */
525
-	public function maybe_unhook_registered_callback( $filter ) {
526
-		parent::maybe_unhook_registered_callback( $filter );
525
+	public function maybe_unhook_registered_callback($filter) {
526
+		parent::maybe_unhook_registered_callback($filter);
527 527
 
528
-		if ( $this->field ) {
528
+		if ($this->field) {
529 529
 			// Unhook field specific filter callbacks.
530
-			$this->field->maybe_hook_parameter( $filter, null, 'remove_filter' );
530
+			$this->field->maybe_hook_parameter($filter, null, 'remove_filter');
531 531
 		}
532 532
 	}
533 533
 
Please login to merge, or discard this patch.
vendor/CMB2/includes/rest-api/CMB2_REST.php 1 patch
Spacing   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @return CMB2_Hookup_Base $hookup The hookup object.
98 98
 	 */
99
-	public static function maybe_init_and_hookup( CMB2 $cmb ) {
100
-		if ( $cmb->prop( 'show_in_rest' ) && function_exists( 'rest_get_server' ) ) {
99
+	public static function maybe_init_and_hookup(CMB2 $cmb) {
100
+		if ($cmb->prop('show_in_rest') && function_exists('rest_get_server')) {
101 101
 
102
-			$hookup = new self( $cmb );
102
+			$hookup = new self($cmb);
103 103
 
104 104
 			return $hookup->universal_hooks();
105 105
 		}
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 	 *
115 115
 	 * @param CMB2 $cmb The CMB2 object to be registered for the API.
116 116
 	 */
117
-	public function __construct( CMB2 $cmb ) {
117
+	public function __construct(CMB2 $cmb) {
118 118
 		$this->cmb = $cmb;
119
-		self::$boxes[ $cmb->cmb_id ] = $this;
119
+		self::$boxes[$cmb->cmb_id] = $this;
120 120
 
121
-		$show_value = $this->cmb->prop( 'show_in_rest' );
121
+		$show_value = $this->cmb->prop('show_in_rest');
122 122
 
123
-		$this->rest_read = self::is_readable( $show_value );
124
-		$this->rest_edit = self::is_editable( $show_value );
123
+		$this->rest_read = self::is_readable($show_value);
124
+		$this->rest_edit = self::is_editable($show_value);
125 125
 	}
126 126
 
127 127
 	/**
@@ -133,15 +133,15 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	public function universal_hooks() {
135 135
 		// hook up the CMB rest endpoint classes
136
-		$this->once( 'rest_api_init', array( __CLASS__, 'init_routes' ), 0 );
136
+		$this->once('rest_api_init', array(__CLASS__, 'init_routes'), 0);
137 137
 
138
-		if ( function_exists( 'register_rest_field' ) ) {
139
-			$this->once( 'rest_api_init', array( __CLASS__, 'register_cmb2_fields' ), 50 );
138
+		if (function_exists('register_rest_field')) {
139
+			$this->once('rest_api_init', array(__CLASS__, 'register_cmb2_fields'), 50);
140 140
 		}
141 141
 
142 142
 		$this->declare_read_edit_fields();
143 143
 
144
-		add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 );
144
+		add_filter('is_protected_meta', array($this, 'is_protected_meta'), 10, 3);
145 145
 
146 146
 		return $this;
147 147
 	}
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
 	public static function init_routes() {
157 157
 		$wp_rest_server = rest_get_server();
158 158
 
159
-		$boxes_controller = new CMB2_REST_Controller_Boxes( $wp_rest_server );
159
+		$boxes_controller = new CMB2_REST_Controller_Boxes($wp_rest_server);
160 160
 		$boxes_controller->register_routes();
161 161
 
162
-		$fields_controller = new CMB2_REST_Controller_Fields( $wp_rest_server );
162
+		$fields_controller = new CMB2_REST_Controller_Fields($wp_rest_server);
163 163
 		$fields_controller->register_routes();
164 164
 	}
165 165
 
@@ -173,60 +173,60 @@  discard block
 block discarded – undo
173 173
 	public static function register_cmb2_fields() {
174 174
 		$alltypes = $taxonomies = array();
175 175
 
176
-		foreach ( self::$boxes as $cmb_id => $rest_box ) {
176
+		foreach (self::$boxes as $cmb_id => $rest_box) {
177 177
 
178 178
 			// Hook box specific filter callbacks.
179
-			$callback = $rest_box->cmb->prop( 'register_rest_field_cb' );
180
-			if ( is_callable( $callback ) ) {
181
-				call_user_func( $callback, $rest_box );
179
+			$callback = $rest_box->cmb->prop('register_rest_field_cb');
180
+			if (is_callable($callback)) {
181
+				call_user_func($callback, $rest_box);
182 182
 				continue;
183 183
 			}
184 184
 
185
-			$types = array_flip( $rest_box->cmb->box_types( array( 'post' ) ) );
185
+			$types = array_flip($rest_box->cmb->box_types(array('post')));
186 186
 
187
-			if ( isset( $types['user'] ) ) {
188
-				unset( $types['user'] );
189
-				self::$type_boxes['user'][ $cmb_id ] = $cmb_id;
187
+			if (isset($types['user'])) {
188
+				unset($types['user']);
189
+				self::$type_boxes['user'][$cmb_id] = $cmb_id;
190 190
 			}
191 191
 
192
-			if ( isset( $types['comment'] ) ) {
193
-				unset( $types['comment'] );
194
-				self::$type_boxes['comment'][ $cmb_id ] = $cmb_id;
192
+			if (isset($types['comment'])) {
193
+				unset($types['comment']);
194
+				self::$type_boxes['comment'][$cmb_id] = $cmb_id;
195 195
 			}
196 196
 
197
-			if ( isset( $types['term'] ) ) {
198
-				unset( $types['term'] );
197
+			if (isset($types['term'])) {
198
+				unset($types['term']);
199 199
 
200 200
 				$taxonomies = array_merge(
201 201
 					$taxonomies,
202
-					CMB2_Utils::ensure_array( $rest_box->cmb->prop( 'taxonomies' ) )
202
+					CMB2_Utils::ensure_array($rest_box->cmb->prop('taxonomies'))
203 203
 				);
204 204
 
205
-				self::$type_boxes['term'][ $cmb_id ] = $cmb_id;
205
+				self::$type_boxes['term'][$cmb_id] = $cmb_id;
206 206
 			}
207 207
 
208
-			if ( ! empty( $types ) ) {
209
-				$alltypes = array_merge( $alltypes, array_flip( $types ) );
210
-				self::$type_boxes['post'][ $cmb_id ] = $cmb_id;
208
+			if ( ! empty($types)) {
209
+				$alltypes = array_merge($alltypes, array_flip($types));
210
+				self::$type_boxes['post'][$cmb_id] = $cmb_id;
211 211
 			}
212 212
 		}
213 213
 
214
-		$alltypes = array_unique( $alltypes );
214
+		$alltypes = array_unique($alltypes);
215 215
 
216
-		if ( ! empty( $alltypes ) ) {
217
-			self::register_rest_field( $alltypes, 'post' );
216
+		if ( ! empty($alltypes)) {
217
+			self::register_rest_field($alltypes, 'post');
218 218
 		}
219 219
 
220
-		if ( ! empty( self::$type_boxes['user'] ) ) {
221
-			self::register_rest_field( 'user', 'user' );
220
+		if ( ! empty(self::$type_boxes['user'])) {
221
+			self::register_rest_field('user', 'user');
222 222
 		}
223 223
 
224
-		if ( ! empty( self::$type_boxes['comment'] ) ) {
225
-			self::register_rest_field( 'comment', 'comment' );
224
+		if ( ! empty(self::$type_boxes['comment'])) {
225
+			self::register_rest_field('comment', 'comment');
226 226
 		}
227 227
 
228
-		if ( ! empty( self::$type_boxes['term'] ) ) {
229
-			self::register_rest_field( $taxonomies, 'term' );
228
+		if ( ! empty(self::$type_boxes['term'])) {
229
+			self::register_rest_field($taxonomies, 'term');
230 230
 		}
231 231
 	}
232 232
 
@@ -241,12 +241,12 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @return void
243 243
 	 */
244
-	protected static function register_rest_field( $object_types, $object_type ) {
245
-		register_rest_field( $object_types, 'cmb2', array(
246
-			'get_callback'    => array( __CLASS__, "get_{$object_type}_rest_values" ),
247
-			'update_callback' => array( __CLASS__, "update_{$object_type}_rest_values" ),
244
+	protected static function register_rest_field($object_types, $object_type) {
245
+		register_rest_field($object_types, 'cmb2', array(
246
+			'get_callback'    => array(__CLASS__, "get_{$object_type}_rest_values"),
247
+			'update_callback' => array(__CLASS__, "update_{$object_type}_rest_values"),
248 248
 			'schema'          => null, // @todo add schema
249
-		) );
249
+		));
250 250
 	}
251 251
 
252 252
 	/**
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
 	 * @return void
258 258
 	 */
259 259
 	protected function declare_read_edit_fields() {
260
-		foreach ( $this->cmb->prop( 'fields' ) as $field ) {
261
-			$show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null;
260
+		foreach ($this->cmb->prop('fields') as $field) {
261
+			$show_in_rest = isset($field['show_in_rest']) ? $field['show_in_rest'] : null;
262 262
 
263
-			if ( false === $show_in_rest ) {
263
+			if (false === $show_in_rest) {
264 264
 				continue;
265 265
 			}
266 266
 
267
-			if ( $this->can_read( $show_in_rest ) ) {
267
+			if ($this->can_read($show_in_rest)) {
268 268
 				$this->read_fields[] = $field['id'];
269 269
 			}
270 270
 
271
-			if ( $this->can_edit( $show_in_rest ) ) {
271
+			if ($this->can_edit($show_in_rest)) {
272 272
 				$this->edit_fields[] = $field['id'];
273 273
 			}
274 274
 		}
@@ -284,14 +284,14 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * @return bool               Whether field is readable.
286 286
 	 */
287
-	protected function can_read( $show_in_rest ) {
287
+	protected function can_read($show_in_rest) {
288 288
 		// if 'null', then use default box value.
289
-		if ( null === $show_in_rest ) {
289
+		if (null === $show_in_rest) {
290 290
 			return $this->rest_read;
291 291
 		}
292 292
 
293 293
 		// Else check if the value represents readable.
294
-		return self::is_readable( $show_in_rest );
294
+		return self::is_readable($show_in_rest);
295 295
 	}
296 296
 
297 297
 	/**
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
 	 *
305 305
 	 * @return bool               Whether field is editable.
306 306
 	 */
307
-	protected function can_edit( $show_in_rest ) {
307
+	protected function can_edit($show_in_rest) {
308 308
 		// if 'null', then use default box value.
309
-		if ( null === $show_in_rest ) {
309
+		if (null === $show_in_rest) {
310 310
 			return $this->rest_edit;
311 311
 		}
312 312
 
313 313
 		// Else check if the value represents editable.
314
-		return self::is_editable( $show_in_rest );
314
+		return self::is_editable($show_in_rest);
315 315
 	}
316 316
 
317 317
 	/**
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
 	 *
327 327
 	 * @return mixed
328 328
 	 */
329
-	public static function get_post_rest_values( $object, $field_name, $request, $object_type ) {
330
-		if ( 'cmb2' === $field_name ) {
331
-			return self::get_rest_values( $object, $request, $object_type, 'post' );
329
+	public static function get_post_rest_values($object, $field_name, $request, $object_type) {
330
+		if ('cmb2' === $field_name) {
331
+			return self::get_rest_values($object, $request, $object_type, 'post');
332 332
 		}
333 333
 	}
334 334
 
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
 	 *
345 345
 	 * @return mixed
346 346
 	 */
347
-	public static function get_user_rest_values( $object, $field_name, $request, $object_type ) {
348
-		if ( 'cmb2' === $field_name ) {
349
-			return self::get_rest_values( $object, $request, $object_type, 'user' );
347
+	public static function get_user_rest_values($object, $field_name, $request, $object_type) {
348
+		if ('cmb2' === $field_name) {
349
+			return self::get_rest_values($object, $request, $object_type, 'user');
350 350
 		}
351 351
 	}
352 352
 
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 	 *
363 363
 	 * @return mixed
364 364
 	 */
365
-	public static function get_comment_rest_values( $object, $field_name, $request, $object_type ) {
366
-		if ( 'cmb2' === $field_name ) {
367
-			return self::get_rest_values( $object, $request, $object_type, 'comment' );
365
+	public static function get_comment_rest_values($object, $field_name, $request, $object_type) {
366
+		if ('cmb2' === $field_name) {
367
+			return self::get_rest_values($object, $request, $object_type, 'comment');
368 368
 		}
369 369
 	}
370 370
 
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
 	 *
381 381
 	 * @return mixed
382 382
 	 */
383
-	public static function get_term_rest_values( $object, $field_name, $request, $object_type ) {
384
-		if ( 'cmb2' === $field_name ) {
385
-			return self::get_rest_values( $object, $request, $object_type, 'term' );
383
+	public static function get_term_rest_values($object, $field_name, $request, $object_type) {
384
+		if ('cmb2' === $field_name) {
385
+			return self::get_rest_values($object, $request, $object_type, 'term');
386 386
 		}
387 387
 	}
388 388
 
@@ -398,27 +398,27 @@  discard block
 block discarded – undo
398 398
 	 *
399 399
 	 * @return mixed
400 400
 	 */
401
-	protected static function get_rest_values( $object, $request, $object_type, $main_object_type = 'post' ) {
402
-		if ( ! isset( $object['id'] ) ) {
401
+	protected static function get_rest_values($object, $request, $object_type, $main_object_type = 'post') {
402
+		if ( ! isset($object['id'])) {
403 403
 			return;
404 404
 		}
405 405
 
406 406
 		$values = array();
407 407
 
408
-		if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) {
409
-			foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) {
410
-				$rest_box = self::$boxes[ $cmb_id ];
408
+		if ( ! empty(self::$type_boxes[$main_object_type])) {
409
+			foreach (self::$type_boxes[$main_object_type] as $cmb_id) {
410
+				$rest_box = self::$boxes[$cmb_id];
411 411
 
412
-				if ( ! $rest_box->cmb->is_box_type( $object_type ) ) {
412
+				if ( ! $rest_box->cmb->is_box_type($object_type)) {
413 413
 					continue;
414 414
 				}
415 415
 
416
-				$result = self::get_box_rest_values( $rest_box, $object['id'], $main_object_type );
417
-				if ( ! empty( $result ) ) {
418
-					if ( empty( $values[ $cmb_id ] ) ) {
419
-						$values[ $cmb_id ] = $result;
416
+				$result = self::get_box_rest_values($rest_box, $object['id'], $main_object_type);
417
+				if ( ! empty($result)) {
418
+					if (empty($values[$cmb_id])) {
419
+						$values[$cmb_id] = $result;
420 420
 					} else {
421
-						$values[ $cmb_id ] = array_merge( $values[ $cmb_id ], $result );
421
+						$values[$cmb_id] = array_merge($values[$cmb_id], $result);
422 422
 					}
423 423
 				}
424 424
 			}
@@ -438,23 +438,23 @@  discard block
 block discarded – undo
438 438
 	 *
439 439
 	 * @return array                       Array of box rest values.
440 440
 	 */
441
-	public static function get_box_rest_values( $rest_box, $object_id = 0, $main_object_type = 'post' ) {
441
+	public static function get_box_rest_values($rest_box, $object_id = 0, $main_object_type = 'post') {
442 442
 
443
-		$rest_box->cmb->object_id( $object_id );
444
-		$rest_box->cmb->object_type( $main_object_type );
443
+		$rest_box->cmb->object_id($object_id);
444
+		$rest_box->cmb->object_type($main_object_type);
445 445
 
446 446
 		$values = array();
447 447
 
448
-		foreach ( $rest_box->read_fields as $field_id ) {
449
-			$field = $rest_box->cmb->get_field( $field_id );
450
-			$field->object_id( $object_id );
451
-			$field->object_type( $main_object_type );
448
+		foreach ($rest_box->read_fields as $field_id) {
449
+			$field = $rest_box->cmb->get_field($field_id);
450
+			$field->object_id($object_id);
451
+			$field->object_type($main_object_type);
452 452
 
453
-			$values[ $field->id( true ) ] = $field->get_rest_value();
453
+			$values[$field->id(true)] = $field->get_rest_value();
454 454
 
455
-			if ( $field->args( 'has_supporting_data' ) ) {
455
+			if ($field->args('has_supporting_data')) {
456 456
 				$field = $field->get_supporting_field();
457
-				$values[ $field->id( true ) ] = $field->get_rest_value();
457
+				$values[$field->id(true)] = $field->get_rest_value();
458 458
 			}
459 459
 		}
460 460
 
@@ -474,9 +474,9 @@  discard block
 block discarded – undo
474 474
 	 *
475 475
 	 * @return bool|int
476 476
 	 */
477
-	public static function update_post_rest_values( $values, $object, $field_name, $request, $object_type ) {
478
-		if ( 'cmb2' === $field_name ) {
479
-			return self::update_rest_values( $values, $object, $request, $object_type, 'post' );
477
+	public static function update_post_rest_values($values, $object, $field_name, $request, $object_type) {
478
+		if ('cmb2' === $field_name) {
479
+			return self::update_rest_values($values, $object, $request, $object_type, 'post');
480 480
 		}
481 481
 	}
482 482
 
@@ -493,9 +493,9 @@  discard block
 block discarded – undo
493 493
 	 *
494 494
 	 * @return bool|int
495 495
 	 */
496
-	public static function update_user_rest_values( $values, $object, $field_name, $request, $object_type ) {
497
-		if ( 'cmb2' === $field_name ) {
498
-			return self::update_rest_values( $values, $object, $request, $object_type, 'user' );
496
+	public static function update_user_rest_values($values, $object, $field_name, $request, $object_type) {
497
+		if ('cmb2' === $field_name) {
498
+			return self::update_rest_values($values, $object, $request, $object_type, 'user');
499 499
 		}
500 500
 	}
501 501
 
@@ -512,9 +512,9 @@  discard block
 block discarded – undo
512 512
 	 *
513 513
 	 * @return bool|int
514 514
 	 */
515
-	public static function update_comment_rest_values( $values, $object, $field_name, $request, $object_type ) {
516
-		if ( 'cmb2' === $field_name ) {
517
-			return self::update_rest_values( $values, $object, $request, $object_type, 'comment' );
515
+	public static function update_comment_rest_values($values, $object, $field_name, $request, $object_type) {
516
+		if ('cmb2' === $field_name) {
517
+			return self::update_rest_values($values, $object, $request, $object_type, 'comment');
518 518
 		}
519 519
 	}
520 520
 
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 	 *
532 532
 	 * @return bool|int
533 533
 	 */
534
-	public static function update_term_rest_values( $values, $object, $field_name, $request, $object_type ) {
535
-		if ( 'cmb2' === $field_name ) {
536
-			return self::update_rest_values( $values, $object, $request, $object_type, 'term' );
534
+	public static function update_term_rest_values($values, $object, $field_name, $request, $object_type) {
535
+		if ('cmb2' === $field_name) {
536
+			return self::update_rest_values($values, $object, $request, $object_type, 'term');
537 537
 		}
538 538
 	}
539 539
 
@@ -550,24 +550,24 @@  discard block
 block discarded – undo
550 550
 	 *
551 551
 	 * @return bool|int
552 552
 	 */
553
-	protected static function update_rest_values( $values, $object, $request, $object_type, $main_object_type = 'post' ) {
554
-		if ( empty( $values ) || ! is_array( $values ) ) {
553
+	protected static function update_rest_values($values, $object, $request, $object_type, $main_object_type = 'post') {
554
+		if (empty($values) || ! is_array($values)) {
555 555
 			return;
556 556
 		}
557 557
 
558
-		$object_id = self::get_object_id( $object, $main_object_type );
558
+		$object_id = self::get_object_id($object, $main_object_type);
559 559
 
560
-		if ( ! $object_id ) {
560
+		if ( ! $object_id) {
561 561
 			return;
562 562
 		}
563 563
 
564 564
 		$updated = array();
565 565
 
566
-		if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) {
567
-			foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) {
568
-				$result = self::santize_box_rest_values( $values, self::$boxes[ $cmb_id ], $object_id, $main_object_type );
569
-				if ( ! empty( $result ) ) {
570
-					$updated[ $cmb_id ] = $result;
566
+		if ( ! empty(self::$type_boxes[$main_object_type])) {
567
+			foreach (self::$type_boxes[$main_object_type] as $cmb_id) {
568
+				$result = self::santize_box_rest_values($values, self::$boxes[$cmb_id], $object_id, $main_object_type);
569
+				if ( ! empty($result)) {
570
+					$updated[$cmb_id] = $result;
571 571
 				}
572 572
 			}
573 573
 		}
@@ -587,16 +587,16 @@  discard block
 block discarded – undo
587 587
 	 *
588 588
 	 * @return mixed|bool                  Array of updated statuses if successful.
589 589
 	 */
590
-	public static function santize_box_rest_values( $values, $rest_box, $object_id = 0, $main_object_type = 'post' ) {
590
+	public static function santize_box_rest_values($values, $rest_box, $object_id = 0, $main_object_type = 'post') {
591 591
 
592
-		if ( ! array_key_exists( $rest_box->cmb->cmb_id, $values ) ) {
592
+		if ( ! array_key_exists($rest_box->cmb->cmb_id, $values)) {
593 593
 			return false;
594 594
 		}
595 595
 
596
-		$rest_box->cmb->object_id( $object_id );
597
-		$rest_box->cmb->object_type( $main_object_type );
596
+		$rest_box->cmb->object_id($object_id);
597
+		$rest_box->cmb->object_type($main_object_type);
598 598
 
599
-		return $rest_box->sanitize_box_values( $values );
599
+		return $rest_box->sanitize_box_values($values);
600 600
 	}
601 601
 
602 602
 	/**
@@ -607,13 +607,13 @@  discard block
 block discarded – undo
607 607
 	 * @param  array $values Array of values being provided.
608 608
 	 * @return array           Array of updated/sanitized values.
609 609
 	 */
610
-	public function sanitize_box_values( array $values ) {
610
+	public function sanitize_box_values(array $values) {
611 611
 		$updated = array();
612 612
 
613 613
 		$this->cmb->pre_process();
614 614
 
615
-		foreach ( $this->edit_fields as $field_id ) {
616
-			$updated[ $field_id ] = $this->sanitize_field_value( $values, $field_id );
615
+		foreach ($this->edit_fields as $field_id) {
616
+			$updated[$field_id] = $this->sanitize_field_value($values, $field_id);
617 617
 		}
618 618
 
619 619
 		$this->cmb->after_save();
@@ -631,25 +631,25 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @return mixed             The results of saving/sanitizing a field value.
633 633
 	 */
634
-	protected function sanitize_field_value( array $values, $field_id ) {
635
-		if ( ! array_key_exists( $field_id, $values[ $this->cmb->cmb_id ] ) ) {
634
+	protected function sanitize_field_value(array $values, $field_id) {
635
+		if ( ! array_key_exists($field_id, $values[$this->cmb->cmb_id])) {
636 636
 			return;
637 637
 		}
638 638
 
639
-		$field = $this->cmb->get_field( $field_id );
639
+		$field = $this->cmb->get_field($field_id);
640 640
 
641
-		if ( 'title' == $field->type() ) {
641
+		if ('title' == $field->type()) {
642 642
 			return;
643 643
 		}
644 644
 
645
-		$field->object_id( $this->cmb->object_id() );
646
-		$field->object_type( $this->cmb->object_type() );
645
+		$field->object_id($this->cmb->object_id());
646
+		$field->object_type($this->cmb->object_type());
647 647
 
648
-		if ( 'group' == $field->type() ) {
649
-			return $this->sanitize_group_value( $values, $field );
648
+		if ('group' == $field->type()) {
649
+			return $this->sanitize_group_value($values, $field);
650 650
 		}
651 651
 
652
-		return $field->save_field( $values[ $this->cmb->cmb_id ][ $field_id ] );
652
+		return $field->save_field($values[$this->cmb->cmb_id][$field_id]);
653 653
 	}
654 654
 
655 655
 	/**
@@ -662,15 +662,15 @@  discard block
 block discarded – undo
662 662
 	 *
663 663
 	 * @return mixed               The results of saving/sanitizing the group field value.
664 664
 	 */
665
-	protected function sanitize_group_value( array $values, CMB2_Field $field ) {
665
+	protected function sanitize_group_value(array $values, CMB2_Field $field) {
666 666
 		$fields = $field->fields();
667
-		if ( empty( $fields ) ) {
667
+		if (empty($fields)) {
668 668
 			return;
669 669
 		}
670 670
 
671
-		$this->cmb->data_to_save[ $field->_id( '', false ) ] = $values[ $this->cmb->cmb_id ][ $field->_id( '', false ) ];
671
+		$this->cmb->data_to_save[$field->_id('', false)] = $values[$this->cmb->cmb_id][$field->_id('', false)];
672 672
 
673
-		return $this->cmb->save_group_field( $field );
673
+		return $this->cmb->save_group_field($field);
674 674
 	}
675 675
 
676 676
 	/**
@@ -682,8 +682,8 @@  discard block
 block discarded – undo
682 682
 	 * @param string $meta_key  Meta key.
683 683
 	 * @param string $meta_type Meta type.
684 684
 	 */
685
-	public function is_protected_meta( $protected, $meta_key, $meta_type ) {
686
-		if ( $this->field_can_edit( $meta_key ) ) {
685
+	public function is_protected_meta($protected, $meta_key, $meta_type) {
686
+		if ($this->field_can_edit($meta_key)) {
687 687
 			return false;
688 688
 		}
689 689
 
@@ -700,22 +700,22 @@  discard block
 block discarded – undo
700 700
 	 *
701 701
 	 * @return int                 The object ID if found.
702 702
 	 */
703
-	public static function get_object_id( $object, $object_type = 'post' ) {
704
-		switch ( $object_type ) {
703
+	public static function get_object_id($object, $object_type = 'post') {
704
+		switch ($object_type) {
705 705
 			case 'user':
706 706
 			case 'post':
707
-				if ( isset( $object->ID ) ) {
708
-					return intval( $object->ID );
707
+				if (isset($object->ID)) {
708
+					return intval($object->ID);
709 709
 				}
710 710
 			case 'comment':
711
-				if ( isset( $object->comment_ID ) ) {
712
-					return intval( $object->comment_ID );
711
+				if (isset($object->comment_ID)) {
712
+					return intval($object->comment_ID);
713 713
 				}
714 714
 			case 'term':
715
-				if ( is_array( $object ) && isset( $object['term_id'] ) ) {
716
-					return intval( $object['term_id'] );
717
-				} elseif ( isset( $object->term_id ) ) {
718
-					return intval( $object->term_id );
715
+				if (is_array($object) && isset($object['term_id'])) {
716
+					return intval($object['term_id']);
717
+				} elseif (isset($object->term_id)) {
718
+					return intval($object->term_id);
719 719
 				}
720 720
 		}
721 721
 
@@ -732,8 +732,8 @@  discard block
 block discarded – undo
732 732
 	 *
733 733
 	 * @return mixed                            False if field can't be read or true|CMB2_Field object.
734 734
 	 */
735
-	public function field_can_read( $field_id, $return_object = false ) {
736
-		return $this->field_can( 'read_fields', $field_id, $return_object );
735
+	public function field_can_read($field_id, $return_object = false) {
736
+		return $this->field_can('read_fields', $field_id, $return_object);
737 737
 	}
738 738
 
739 739
 	/**
@@ -746,8 +746,8 @@  discard block
 block discarded – undo
746 746
 	 *
747 747
 	 * @return mixed                            False if field can't be edited or true|CMB2_Field object.
748 748
 	 */
749
-	public function field_can_edit( $field_id, $return_object = false ) {
750
-		return $this->field_can( 'edit_fields', $field_id, $return_object );
749
+	public function field_can_edit($field_id, $return_object = false) {
750
+		return $this->field_can('edit_fields', $field_id, $return_object);
751 751
 	}
752 752
 
753 753
 	/**
@@ -761,12 +761,12 @@  discard block
 block discarded – undo
761 761
 	 *
762 762
 	 * @return mixed                            False if field can't be read or edited or true|CMB2_Field object.
763 763
 	 */
764
-	protected function field_can( $type = 'read_fields', $field_id, $return_object = false ) {
765
-		if ( ! in_array( $field_id instanceof CMB2_Field ? $field_id->id() : $field_id, $this->{$type}, true ) ) {
764
+	protected function field_can($type = 'read_fields', $field_id, $return_object = false) {
765
+		if ( ! in_array($field_id instanceof CMB2_Field ? $field_id->id() : $field_id, $this->{$type}, true)) {
766 766
 			return false;
767 767
 		}
768 768
 
769
-		return $return_object ? $this->cmb->get_field( $field_id ) : true;
769
+		return $return_object ? $this->cmb->get_field($field_id) : true;
770 770
 	}
771 771
 
772 772
 	/**
@@ -778,8 +778,8 @@  discard block
 block discarded – undo
778 778
 	 *
779 779
 	 * @return CMB2_REST|false The CMB2_REST object or false.
780 780
 	 */
781
-	public static function get_rest_box( $cmb_id ) {
782
-		return isset( self::$boxes[ $cmb_id ] ) ? self::$boxes[ $cmb_id ] : false;
781
+	public static function get_rest_box($cmb_id) {
782
+		return isset(self::$boxes[$cmb_id]) ? self::$boxes[$cmb_id] : false;
783 783
 	}
784 784
 
785 785
 	/**
@@ -789,9 +789,9 @@  discard block
 block discarded – undo
789 789
 	 *
790 790
 	 * @param string $cmb_id A CMB2 instance id.
791 791
 	 */
792
-	public static function remove( $cmb_id ) {
793
-		if ( array_key_exists( $cmb_id, self::$boxes ) ) {
794
-			unset( self::$boxes[ $cmb_id ] );
792
+	public static function remove($cmb_id) {
793
+		if (array_key_exists($cmb_id, self::$boxes)) {
794
+			unset(self::$boxes[$cmb_id]);
795 795
 		}
796 796
 	}
797 797
 
@@ -816,12 +816,12 @@  discard block
 block discarded – undo
816 816
 	 *
817 817
 	 * @return boolean       Whether value is considered readable.
818 818
 	 */
819
-	public static function is_readable( $value ) {
820
-		return ! empty( $value ) && ! in_array( $value, array(
819
+	public static function is_readable($value) {
820
+		return ! empty($value) && ! in_array($value, array(
821 821
 			WP_REST_Server::CREATABLE,
822 822
 			WP_REST_Server::EDITABLE,
823 823
 			WP_REST_Server::DELETABLE,
824
-		), true );
824
+		), true);
825 825
 	}
826 826
 
827 827
 	/**
@@ -835,11 +835,11 @@  discard block
 block discarded – undo
835 835
 	 *
836 836
 	 * @return boolean       Whether value is considered editable.
837 837
 	 */
838
-	public static function is_editable( $value ) {
839
-		return in_array( $value, array(
838
+	public static function is_editable($value) {
839
+		return in_array($value, array(
840 840
 			WP_REST_Server::EDITABLE,
841 841
 			WP_REST_Server::ALLMETHODS,
842
-		), true );
842
+		), true);
843 843
 	}
844 844
 
845 845
 	/**
@@ -850,15 +850,15 @@  discard block
 block discarded – undo
850 850
 	 *
851 851
 	 * @return mixed
852 852
 	 */
853
-	public function __get( $field ) {
854
-		switch ( $field ) {
853
+	public function __get($field) {
854
+		switch ($field) {
855 855
 			case 'read_fields':
856 856
 			case 'edit_fields':
857 857
 			case 'rest_read':
858 858
 			case 'rest_edit':
859 859
 				return $this->{$field};
860 860
 			default:
861
-				throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $field );
861
+				throw new Exception('Invalid ' . __CLASS__ . ' property: ' . $field);
862 862
 		}
863 863
 	}
864 864
 
Please login to merge, or discard this patch.
vendor/CMB2/includes/rest-api/CMB2_REST_Controller.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! class_exists( 'WP_REST_Controller' ) ) {
2
+if ( ! class_exists('WP_REST_Controller')) {
3 3
 	// Shim the WP_REST_Controller class if wp-api plugin not installed, & not in core.
4
-	require_once cmb2_dir( 'includes/shim/WP_REST_Controller.php' );
4
+	require_once cmb2_dir('includes/shim/WP_REST_Controller.php');
5 5
 }
6 6
 
7 7
 /**
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @since 2.2.3
104 104
 	 */
105
-	public function __construct( WP_REST_Server $wp_rest_server ) {
105
+	public function __construct(WP_REST_Server $wp_rest_server) {
106 106
 		$this->server = $wp_rest_server;
107 107
 	}
108 108
 
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @return void
121 121
 	 */
122
-	public function maybe_hook_callback_and_apply_filters( $filter, $default_access ) {
123
-		if ( ! $this->rest_box && $this->request->get_param( 'cmb_id' ) ) {
124
-			$this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) );
122
+	public function maybe_hook_callback_and_apply_filters($filter, $default_access) {
123
+		if ( ! $this->rest_box && $this->request->get_param('cmb_id')) {
124
+			$this->rest_box = CMB2_REST::get_rest_box($this->request->get_param('cmb_id'));
125 125
 		}
126 126
 
127
-		$default_access = $this->maybe_hook_registered_callback( $filter, $default_access );
127
+		$default_access = $this->maybe_hook_registered_callback($filter, $default_access);
128 128
 
129 129
 		/**
130 130
 		 * Apply the permissions check filter.
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 		 * @param bool   $default_access Whether this CMB2 endpoint can be accessed.
135 135
 		 * @param object $controller     This CMB2_REST_Controller object.
136 136
 		 */
137
-		$default_access = apply_filters( $filter, $default_access, $this );
137
+		$default_access = apply_filters($filter, $default_access, $this);
138 138
 
139
-		$this->maybe_unhook_registered_callback( $filter );
139
+		$this->maybe_unhook_registered_callback($filter);
140 140
 
141 141
 		return $default_access;
142 142
 	}
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
 	 *
156 156
 	 * @return bool                The possibly-modified filter value (if the '*_cb' param is non-callable).
157 157
 	 */
158
-	public function maybe_hook_registered_callback( $filter, $default_val ) {
159
-		if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) {
158
+	public function maybe_hook_registered_callback($filter, $default_val) {
159
+		if ( ! $this->rest_box || is_wp_error($this->rest_box)) {
160 160
 			return $default_val;
161 161
 		}
162 162
 
163 163
 		// Hook box specific filter callbacks.
164
-		$val = $this->rest_box->cmb->maybe_hook_parameter( $filter, $default_val );
165
-		if ( null !== $val ) {
164
+		$val = $this->rest_box->cmb->maybe_hook_parameter($filter, $default_val);
165
+		if (null !== $val) {
166 166
 			$default_val = $val;
167 167
 		}
168 168
 
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @return void
180 180
 	 */
181
-	public function maybe_unhook_registered_callback( $filter ) {
182
-		if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) {
181
+	public function maybe_unhook_registered_callback($filter) {
182
+		if ( ! $this->rest_box || is_wp_error($this->rest_box)) {
183 183
 			return;
184 184
 		}
185 185
 
186 186
 		// Unhook box specific filter callbacks.
187
-		$this->rest_box->cmb->maybe_hook_parameter( $filter, null, 'remove_filter' );
187
+		$this->rest_box->cmb->maybe_hook_parameter($filter, null, 'remove_filter');
188 188
 	}
189 189
 
190 190
 	/**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @param  mixed $data
196 196
 	 * @return array $data
197 197
 	 */
198
-	public function prepare_item( $data ) {
199
-		return $this->prepare_item_for_response( $data, $this->request );
198
+	public function prepare_item($data) {
199
+		return $this->prepare_item_for_response($data, $this->request);
200 200
 	}
201 201
 
202 202
 	/**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
 	 * @param  mixed $cb Callable function/method.
208 208
 	 * @return mixed     Results of output buffer after calling function/method.
209 209
 	 */
210
-	public function get_cb_results( $cb ) {
210
+	public function get_cb_results($cb) {
211 211
 		$args = func_get_args();
212
-		array_shift( $args ); // ignore $cb
212
+		array_shift($args); // ignore $cb
213 213
 		ob_start();
214
-		call_user_func_array( $cb, $args );
214
+		call_user_func_array($cb, $args);
215 215
 
216 216
 		return ob_get_clean();
217 217
 	}
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
 	 * @param  WP_REST_Request $request  Request object.
226 226
 	 * @return WP_REST_Response $response
227 227
 	 */
228
-	public function prepare_item_for_response( $data, $request = null ) {
229
-		$data = $this->filter_response_by_context( $data, $this->request['context'] );
228
+	public function prepare_item_for_response($data, $request = null) {
229
+		$data = $this->filter_response_by_context($data, $this->request['context']);
230 230
 
231 231
 		/**
232 232
 		 * Filter the prepared CMB2 item response.
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		 * @param object $request        The WP_REST_Request object
238 238
 		 * @param object $cmb2_endpoints This endpoints object
239 239
 		 */
240
-		return apply_filters( 'cmb2_rest_prepare', rest_ensure_response( $data ), $this->request, $this );
240
+		return apply_filters('cmb2_rest_prepare', rest_ensure_response($data), $this->request, $this);
241 241
 	}
242 242
 
243 243
 	/**
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	 *
251 251
 	 * @return void
252 252
 	 */
253
-	protected function initiate_rest_read_box( $request, $request_type ) {
254
-		$this->initiate_rest_box( $request, $request_type );
253
+	protected function initiate_rest_read_box($request, $request_type) {
254
+		$this->initiate_rest_box($request, $request_type);
255 255
 
256
-		if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_read ) {
257
-			$this->rest_box = new WP_Error( 'cmb2_rest_no_read_error', __( 'This box does not have read permissions.', 'cmb2' ), array(
256
+		if ( ! is_wp_error($this->rest_box) && ! $this->rest_box->rest_read) {
257
+			$this->rest_box = new WP_Error('cmb2_rest_no_read_error', __('This box does not have read permissions.', 'cmb2'), array(
258 258
 				'status' => 403,
259
-			) );
259
+			));
260 260
 		}
261 261
 	}
262 262
 
@@ -270,13 +270,13 @@  discard block
 block discarded – undo
270 270
 	 *
271 271
 	 * @return void
272 272
 	 */
273
-	protected function initiate_rest_edit_box( $request, $request_type ) {
274
-		$this->initiate_rest_box( $request, $request_type );
273
+	protected function initiate_rest_edit_box($request, $request_type) {
274
+		$this->initiate_rest_box($request, $request_type);
275 275
 
276
-		if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_edit ) {
277
-			$this->rest_box = new WP_Error( 'cmb2_rest_no_write_error', __( 'This box does not have write permissions.', 'cmb2' ), array(
276
+		if ( ! is_wp_error($this->rest_box) && ! $this->rest_box->rest_edit) {
277
+			$this->rest_box = new WP_Error('cmb2_rest_no_write_error', __('This box does not have write permissions.', 'cmb2'), array(
278 278
 				'status' => 403,
279
-			) );
279
+			));
280 280
 		}
281 281
 	}
282 282
 
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 	 *
291 291
 	 * @return void
292 292
 	 */
293
-	protected function initiate_rest_box( $request, $request_type ) {
294
-		$this->initiate_request( $request, $request_type );
293
+	protected function initiate_rest_box($request, $request_type) {
294
+		$this->initiate_request($request, $request_type);
295 295
 
296
-		$this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) );
296
+		$this->rest_box = CMB2_REST::get_rest_box($this->request->get_param('cmb_id'));
297 297
 
298
-		if ( ! $this->rest_box ) {
298
+		if ( ! $this->rest_box) {
299 299
 
300
-			$this->rest_box = new WP_Error( 'cmb2_rest_box_not_found_error', __( 'No box found by that id. A box needs to be registered with the "show_in_rest" parameter configured.', 'cmb2' ), array(
300
+			$this->rest_box = new WP_Error('cmb2_rest_box_not_found_error', __('No box found by that id. A box needs to be registered with the "show_in_rest" parameter configured.', 'cmb2'), array(
301 301
 				'status' => 403,
302
-			) );
302
+			));
303 303
 
304 304
 		} else {
305 305
 
306
-			if ( isset( $this->request['object_id'] ) ) {
307
-				$this->rest_box->cmb->object_id( sanitize_text_field( $this->request['object_id'] ) );
306
+			if (isset($this->request['object_id'])) {
307
+				$this->rest_box->cmb->object_id(sanitize_text_field($this->request['object_id']));
308 308
 			}
309 309
 
310
-			if ( isset( $this->request['object_type'] ) ) {
311
-				$this->rest_box->cmb->object_type( sanitize_text_field( $this->request['object_type'] ) );
310
+			if (isset($this->request['object_type'])) {
311
+				$this->rest_box->cmb->object_type(sanitize_text_field($this->request['object_type']));
312 312
 			}
313 313
 		}
314 314
 	}
@@ -323,18 +323,18 @@  discard block
 block discarded – undo
323 323
 	 *
324 324
 	 * @return void
325 325
 	 */
326
-	public function initiate_request( $request, $request_type ) {
326
+	public function initiate_request($request, $request_type) {
327 327
 		$this->request = $request;
328 328
 
329
-		if ( ! isset( $this->request['context'] ) || empty( $this->request['context'] ) ) {
329
+		if ( ! isset($this->request['context']) || empty($this->request['context'])) {
330 330
 			$this->request['context'] = 'view';
331 331
 		}
332 332
 
333
-		if ( ! self::$request_type ) {
333
+		if ( ! self::$request_type) {
334 334
 			self::$request_type = $request_type;
335 335
 		}
336 336
 
337
-		if ( ! self::$route ) {
337
+		if ( ! self::$route) {
338 338
 			self::$route = $this->request->get_route();
339 339
 		}
340 340
 	}
@@ -375,21 +375,21 @@  discard block
 block discarded – undo
375 375
 			'type'                 => 'object',
376 376
 			'properties'           => array(
377 377
 				'description' => array(
378
-					'description' => __( 'A human-readable description of the object.', 'cmb2' ),
378
+					'description' => __('A human-readable description of the object.', 'cmb2'),
379 379
 					'type'        => 'string',
380 380
 					'context'     => array(
381 381
 						'view',
382 382
 					),
383 383
 				),
384 384
 				'name' => array(
385
-					'description' => __( 'The id for the object.', 'cmb2' ),
385
+					'description' => __('The id for the object.', 'cmb2'),
386 386
 					'type'        => 'integer',
387 387
 					'context'     => array(
388 388
 						'view',
389 389
 					),
390 390
 				),
391 391
 				'name' => array(
392
-					'description' => __( 'The title for the object.', 'cmb2' ),
392
+					'description' => __('The title for the object.', 'cmb2'),
393 393
 					'type'        => 'string',
394 394
 					'context'     => array(
395 395
 						'view',
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 			),
399 399
 		);
400 400
 
401
-		return $this->add_additional_fields_schema( $schema );
401
+		return $this->add_additional_fields_schema($schema);
402 402
 	}
403 403
 
404 404
 	/**
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 	 *
414 414
 	 * @return array          Array of links
415 415
 	 */
416
-	abstract protected function prepare_links( $object );
416
+	abstract protected function prepare_links($object);
417 417
 
418 418
 	/**
419 419
 	 * Get whitelisted query strings from URL for appending to link URLS.
@@ -432,11 +432,11 @@  discard block
 block discarded – undo
432 432
 
433 433
 		$query_string = '';
434 434
 
435
-		foreach ( $defaults as $key => $value ) {
436
-			if ( isset( $this->request[ $key ] ) ) {
435
+		foreach ($defaults as $key => $value) {
436
+			if (isset($this->request[$key])) {
437 437
 				$query_string .= $query_string ? '&' : '?';
438 438
 				$query_string .= $key;
439
-				if ( $value = sanitize_text_field( $this->request[ $key ] ) ) {
439
+				if ($value = sanitize_text_field($this->request[$key])) {
440 440
 					$query_string .= '=' . $value;
441 441
 				}
442 442
 			}
Please login to merge, or discard this patch.
vendor/CMB2/includes/rest-api/CMB2_REST_Controller_Boxes.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @since 2.2.3
37 37
 	 */
38
-	public function __construct( WP_REST_Server $wp_rest_server ) {
38
+	public function __construct(WP_REST_Server $wp_rest_server) {
39 39
 		$this->namespace_base = $this->namespace . '/' . $this->rest_base;
40
-		parent::__construct( $wp_rest_server );
40
+		parent::__construct($wp_rest_server);
41 41
 	}
42 42
 
43 43
 	/**
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	public function register_routes() {
49 49
 		$args = array(
50 50
 			'_embed' => array(
51
-				'description' => __( 'Includes the registered fields for the box in the response.', 'cmb2' ),
51
+				'description' => __('Includes the registered fields for the box in the response.', 'cmb2'),
52 52
 			),
53 53
 		);
54 54
 
@@ -58,30 +58,30 @@  discard block
 block discarded – undo
58 58
 		// $args['context']['default'] = 'view';
59 59
 		// $args['context']['enum'] = array( 'view', 'embed' );
60 60
 		// Returns all boxes data.
61
-		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
61
+		register_rest_route($this->namespace, '/' . $this->rest_base, array(
62 62
 			array(
63 63
 				'methods'             => WP_REST_Server::READABLE,
64
-				'permission_callback' => array( $this, 'get_items_permissions_check' ),
65
-				'callback'            => array( $this, 'get_items' ),
64
+				'permission_callback' => array($this, 'get_items_permissions_check'),
65
+				'callback'            => array($this, 'get_items'),
66 66
 				'args'                => $args,
67 67
 			),
68
-			'schema' => array( $this, 'get_item_schema' ),
69
-		) );
68
+			'schema' => array($this, 'get_item_schema'),
69
+		));
70 70
 
71 71
 		$args['_rendered'] = array(
72
-			'description' => __( 'Includes the fully rendered attributes, \'form_open\', \'form_close\', as well as the enqueued \'js_dependencies\' script handles, and \'css_dependencies\' stylesheet handles.', 'cmb2' ),
72
+			'description' => __('Includes the fully rendered attributes, \'form_open\', \'form_close\', as well as the enqueued \'js_dependencies\' script handles, and \'css_dependencies\' stylesheet handles.', 'cmb2'),
73 73
 		);
74 74
 
75 75
 		// Returns specific box's data.
76
-		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array(
76
+		register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array(
77 77
 			array(
78 78
 				'methods'             => WP_REST_Server::READABLE,
79
-				'permission_callback' => array( $this, 'get_item_permissions_check' ),
80
-				'callback'            => array( $this, 'get_item' ),
79
+				'permission_callback' => array($this, 'get_item_permissions_check'),
80
+				'callback'            => array($this, 'get_item'),
81 81
 				'args'                => $args,
82 82
 			),
83
-			'schema' => array( $this, 'get_item_schema' ),
84
-		) );
83
+			'schema' => array($this, 'get_item_schema'),
84
+		));
85 85
 	}
86 86
 
87 87
 	/**
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 * @param  WP_REST_Request $request Full data about the request.
93 93
 	 * @return WP_Error|boolean
94 94
 	 */
95
-	public function get_items_permissions_check( $request ) {
96
-		$this->initiate_request( $request, __FUNCTION__ );
95
+	public function get_items_permissions_check($request) {
96
+		$this->initiate_request($request, __FUNCTION__);
97 97
 
98 98
 		/**
99 99
 		 * By default, no special permissions needed.
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		 * @param bool   $can_access Whether this CMB2 endpoint can be accessed.
104 104
 		 * @param object $controller This CMB2_REST_Controller object.
105 105
 		 */
106
-		return apply_filters( 'cmb2_api_get_boxes_permissions_check', true, $this );
106
+		return apply_filters('cmb2_api_get_boxes_permissions_check', true, $this);
107 107
 	}
108 108
 
109 109
 	/**
@@ -114,34 +114,34 @@  discard block
 block discarded – undo
114 114
 	 * @param  WP_REST_Request $request Full data about the request.
115 115
 	 * @return WP_Error|WP_REST_Response
116 116
 	 */
117
-	public function get_items( $request ) {
118
-		$this->initiate_request( $request, 'boxes_read' );
117
+	public function get_items($request) {
118
+		$this->initiate_request($request, 'boxes_read');
119 119
 
120 120
 		$boxes = CMB2_REST::get_all();
121
-		if ( empty( $boxes ) ) {
122
-			return new WP_Error( 'cmb2_rest_no_boxes', __( 'No boxes found.', 'cmb2' ), array(
121
+		if (empty($boxes)) {
122
+			return new WP_Error('cmb2_rest_no_boxes', __('No boxes found.', 'cmb2'), array(
123 123
 				'status' => 403,
124
-			) );
124
+			));
125 125
 		}
126 126
 
127 127
 		$boxes_data = array();
128 128
 
129 129
 		// Loop and prepare boxes data.
130
-		foreach ( $boxes as $this->rest_box ) {
130
+		foreach ($boxes as $this->rest_box) {
131 131
 			if (
132 132
 				// Make sure this box can be read
133 133
 				$this->rest_box->rest_read
134 134
 				// And make sure current user can view this box.
135
-				&& $this->get_item_permissions_check_filter( $this->request )
135
+				&& $this->get_item_permissions_check_filter($this->request)
136 136
 			) {
137 137
 				$boxes_data[] = $this->server->response_to_data(
138 138
 					$this->get_rest_box(),
139
-					isset( $this->request['_embed'] )
139
+					isset($this->request['_embed'])
140 140
 				);
141 141
 			}
142 142
 		}
143 143
 
144
-		return $this->prepare_item( $boxes_data );
144
+		return $this->prepare_item($boxes_data);
145 145
 	}
146 146
 
147 147
 	/**
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 	 * @param  WP_REST_Request $request Full details about the request.
154 154
 	 * @return WP_Error|boolean
155 155
 	 */
156
-	public function get_item_permissions_check( $request ) {
157
-		$this->initiate_rest_read_box( $request, 'box_read' );
156
+	public function get_item_permissions_check($request) {
157
+		$this->initiate_rest_read_box($request, 'box_read');
158 158
 
159 159
 		return $this->get_item_permissions_check_filter();
160 160
 	}
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @param  bool $can_access Whether the current request has access to view the box by default.
169 169
 	 * @return WP_Error|boolean
170 170
 	 */
171
-	public function get_item_permissions_check_filter( $can_access = true ) {
171
+	public function get_item_permissions_check_filter($can_access = true) {
172 172
 		/**
173 173
 		 * By default, no special permissions needed.
174 174
 		 *
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		 * @param bool   $can_access Whether this CMB2 endpoint can be accessed.
178 178
 		 * @param object $controller This CMB2_REST_Controller object.
179 179
 		 */
180
-		return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_box_permissions_check', $can_access );
180
+		return $this->maybe_hook_callback_and_apply_filters('cmb2_api_get_box_permissions_check', $can_access);
181 181
 	}
182 182
 
183 183
 	/**
@@ -188,14 +188,14 @@  discard block
 block discarded – undo
188 188
 	 * @param  WP_REST_Request $request Full data about the request.
189 189
 	 * @return WP_Error|WP_REST_Response
190 190
 	 */
191
-	public function get_item( $request ) {
192
-		$this->initiate_rest_read_box( $request, 'box_read' );
191
+	public function get_item($request) {
192
+		$this->initiate_rest_read_box($request, 'box_read');
193 193
 
194
-		if ( is_wp_error( $this->rest_box ) ) {
194
+		if (is_wp_error($this->rest_box)) {
195 195
 			return $this->rest_box;
196 196
 		}
197 197
 
198
-		return $this->prepare_item( $this->get_rest_box() );
198
+		return $this->prepare_item($this->get_rest_box());
199 199
 	}
200 200
 
201 201
 	/**
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
 
211 211
 		$boxes_data = $cmb->meta_box;
212 212
 
213
-		if ( isset( $this->request['_rendered'] ) && $this->namespace_base !== ltrim( CMB2_REST_Controller::get_intial_route(), '/' ) ) {
214
-			$boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) );
215
-			$boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) );
213
+		if (isset($this->request['_rendered']) && $this->namespace_base !== ltrim(CMB2_REST_Controller::get_intial_route(), '/')) {
214
+			$boxes_data['form_open'] = $this->get_cb_results(array($cmb, 'render_form_open'));
215
+			$boxes_data['form_close'] = $this->get_cb_results(array($cmb, 'render_form_close'));
216 216
 
217 217
 			global $wp_scripts, $wp_styles;
218 218
 			$before_css = $wp_styles->queue;
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 
221 221
 			CMB2_JS::enqueue();
222 222
 
223
-			$boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) );
224
-			$boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) );
223
+			$boxes_data['js_dependencies'] = array_values(array_diff($wp_scripts->queue, $before_js));
224
+			$boxes_data['css_dependencies'] = array_values(array_diff($wp_styles->queue, $before_css));
225 225
 		}
226 226
 
227 227
 		// TODO: look into 'embed' parameter.
228 228
 		// http://demo.wp-api.org/wp-json/wp/v2/posts?_embed
229
-		unset( $boxes_data['fields'] );
229
+		unset($boxes_data['fields']);
230 230
 		// Handle callable properties.
231
-		unset( $boxes_data['show_on_cb'] );
231
+		unset($boxes_data['show_on_cb']);
232 232
 
233
-		$response = rest_ensure_response( $boxes_data );
233
+		$response = rest_ensure_response($boxes_data);
234 234
 
235
-		$response->add_links( $this->prepare_links( $cmb ) );
235
+		$response->add_links($this->prepare_links($cmb));
236 236
 
237 237
 		return $response;
238 238
 	}
@@ -246,22 +246,22 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 * @return array          Array of links
248 248
 	 */
249
-	protected function prepare_links( $cmb ) {
249
+	protected function prepare_links($cmb) {
250 250
 		$boxbase      = $this->namespace_base . '/' . $cmb->cmb_id;
251 251
 		$query_string = $this->get_query_string();
252 252
 
253 253
 		return array(
254 254
 			// Standard Link Relations -- http://v2.wp-api.org/extending/linking/
255 255
 			'self' => array(
256
-				'href' => rest_url( $boxbase . $query_string ),
256
+				'href' => rest_url($boxbase . $query_string),
257 257
 			),
258 258
 			'collection' => array(
259
-				'href' => rest_url( $this->namespace_base . $query_string ),
259
+				'href' => rest_url($this->namespace_base . $query_string),
260 260
 			),
261 261
 			// Custom Link Relations -- http://v2.wp-api.org/extending/linking/
262 262
 			// TODO URL should document relationship.
263 263
 			'https://cmb2.io/fields' => array(
264
-				'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ),
264
+				'href' => rest_url(trailingslashit($boxbase) . 'fields' . $query_string),
265 265
 				'embeddable' => true,
266 266
 			),
267 267
 		);
Please login to merge, or discard this patch.