Completed
Push — master ( 196a0a...af77e8 )
by Zack
11:10 queued 04:43
created

GravityView_View_Data::maybe_get_view_id()   C

Complexity

Conditions 22
Paths 63

Size

Total Lines 76
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 33.2869

Importance

Changes 0
Metric Value
cc 22
eloc 40
nc 63
nop 1
dl 0
loc 76
ccs 25
cts 35
cp 0.7143
crap 33.2869
rs 5.1969
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/** If this file is called directly, abort. */
4
if ( ! defined( 'ABSPATH' ) ) {
5
	die;
6
}
7
8
class GravityView_View_Data {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
9
10
	static $instance = NULL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $instance.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
11
12
	protected $views = array();
13
14
	/**
15
	 *
16
	 * @param null $passed_post
17
	 */
18 2
	private function __construct( $passed_post = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
19
20 2
		if( !empty( $passed_post ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
21
22 2
			$id_or_id_array = $this->maybe_get_view_id( $passed_post );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::maybe_get_view_id() has been deprecated.

This method has been deprecated.

Loading history...
23
24 2
			if( !empty( $id_or_id_array ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
25 2
				$this->add_view( $id_or_id_array );
26
			}
27
		}
28
29 2
	}
30
31
	/**
32
	 * @return boolean
33
	 */
34 2
	public function has_multiple_views() {
35
36
		//multiple views
37 2
		return count( $this->get_views() ) > 1 ? true : false;
38
	}
39
40
41
	/**
42
	 * Figure out what the View ID is for a variable, if any.
43
	 *
44
	 * Can be:
45
	 *      - WP_Post (Either a `gravityview` post type or not)
46
	 *      - Multi-dimensional array of WP_Post objects
47
	 *      - Array with `view_id` or `id` key(s) set
48
	 *      - String of content that may include GravityView shortcode
49
	 *      - Number representing the Post ID or View ID
50
	 *
51
	 * @param mixed $passed_post See method description
52
	 *
53
	 * @deprecated
54
	 * @see \GV\View_Collection::from_post and \GV\Shortcode::parse
55
	 *
56
	 * @return int|null|array ID of the View. If there are multiple views in the content, array of IDs parsed.
57
	 */
58 3
	public function maybe_get_view_id( $passed_post ) {
59 3
		$ids = array();
60
61 3
		if( ! empty( $passed_post ) ) {
62
63 3
			if( is_numeric( $passed_post ) ) {
64 1
				$passed_post = get_post( $passed_post );
65
			}
66
67
			// Convert WP_Posts into WP_Posts[] array
68 3
			if( $passed_post instanceof WP_Post ) {
0 ignored issues
show
Bug introduced by
The class WP_Post does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
69 3
				$passed_post = array( $passed_post );
70
			}
71
72 3
			if( is_array( $passed_post ) ) {
73
74 3
				foreach ( $passed_post as &$post) {
0 ignored issues
show
introduced by
No space before closing parenthesis is prohibited
Loading history...
75 3
					if ( false /** Do not use for now. See issue #848 */ && function_exists( 'gravityview' ) && $post instanceof WP_Post ) {
0 ignored issues
show
Bug introduced by
The class WP_Post does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
76
						$views = \GV\View_Collection::from_post( $post );
77
						foreach ( $views->all() as $view ) {
78
							$ids []= $view->ID;
0 ignored issues
show
introduced by
Expected 1 space before "="; 0 found
Loading history...
79
						}
80
					} else {
81
						/** Deprecated, see \GV\View_Collection::from_post */
82 3
						if( ( get_post_type( $post ) === 'gravityview' ) ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
83 3
							$ids[] = $post->ID;
84
						} else{
85
							// Parse the Post Content
86 1
							$id = $this->parse_post_content( $post->post_content );
87 1
							if( $id ) {
88 1
								$ids = array_merge( $ids, (array) $id );
89
							}
90
91
							// Parse the Post Meta
92 1
							$id = $this->parse_post_meta( $post->ID );
93 1
							if( $id ) {
94 3
								$ids = array_merge( $ids, (array) $id );
95
							}
96
						}
97
					}
98
99
				}
100
101
			} else {
102
103 1
				if ( is_string( $passed_post ) ) {
104
105 1
					if ( false /** Do not use for now. See issue #848 */ && function_exists( 'gravityview' ) ) {
106
						$shortcodes = \GV\Shortcode::parse( $passed_post );
107
						foreach ( $shortcodes as $shortcode ) {
108
							if ( $shortcode->name == 'gravityview' && !empty( $shortcode->atts['id'] ) )
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
109
								$ids []= $shortcode->atts['id'];
0 ignored issues
show
introduced by
Expected 1 space before "="; 0 found
Loading history...
110
						}
111
					} else {
112
						/** Deprecated, use \GV\Shortcode::parse. */
113 1
						$id = $this->parse_post_content( $passed_post );
114 1
						if( $id ) {
115 1
							$ids = array_merge( $ids, (array) $id );
116
						}
117
					}
118
119
				} else {
120
					$id = $this->get_id_from_atts( $passed_post );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::get_id_from_atts() has been deprecated with message: Also dead code, was probably superceded by GravityView_View_Data::parse_post_content

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
121
					$ids[] = intval( $id );
122
				}
123
			}
124
		}
125
126 3
		if( empty($ids) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
127
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
128
		}
129
130
		// If it's just one ID, return that.
131
		// Otherwise, return array of IDs
132 3
		return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
133
	}
134
135
	/**
136
	 * @return GravityView_View_Data
137
	 */
138 2
	public static function getInstance( $passed_post = NULL ) {
0 ignored issues
show
Coding Style introduced by
The function name getInstance is in camel caps, but expected get_instance instead as per the coding standard.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
139
140 2
		if( empty( self::$instance ) ) {
141 2
			self::$instance = new GravityView_View_Data( $passed_post );
142
		}
143
144 2
		return self::$instance;
145
	}
146
147 2
	function get_views() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
148 2
		return $this->views;
149
	}
150
151
	function get_view( $view_id, $atts = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
152
153
		if( ! is_numeric( $view_id) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
154
			do_action('gravityview_log_error', sprintf('GravityView_View_Data[get_view] $view_id passed is not numeric.', $view_id) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
155
			return false;
156
		}
157
158
		// Backup: the view hasn't been fetched yet. Doing it now.
159
		if ( ! isset( $this->views[ $view_id ] ) ) {
160
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] View #%s not set yet.', $view_id) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
161
			return $this->add_view( $view_id, $atts );
162
		}
163
164
		if ( empty( $this->views[ $view_id ] ) ) {
165
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] Returning; View #%s was empty.', $view_id) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
166
			return false;
167
		}
168
169
		return $this->views[ $view_id ];
170
	}
171
172
	/**
173
	 * Determines if a post, identified by the specified ID, exist
174
	 * within the WordPress database.
175
	 *
176
	 * @see http://tommcfarlin.com/wordpress-post-exists-by-id/ Fastest check available
177
	 * @param    int    $view_id    The ID of the post to check
178
	 * @return   bool   True if the post exists; otherwise, false.
179
	 * @since    1.0.0
180
	 */
181 2
	function view_exists( $view_id ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
182 2
		return is_string( get_post_status( $view_id ) );
183
	}
184
185
	/**
186
	 *
187
	 * Add a view to the views array
188
	 *
189
	 * @param int|array $view_id View ID or array of View IDs
190
	 * @param array|string $atts Combine other attributes (eg. from shortcode) with the view settings (optional)
191
	 * @return array
192
	 */
193 2
	function add_view( $view_id, $atts = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
194
195
		// Handle array of IDs
196 2
		if( is_array( $view_id ) ) {
197
			foreach( $view_id as $id ) {
198
199
				$this->add_view( $id, $atts );
200
			}
201
202
			return $this->views;
203
		}
204
205
		// The view has been set already; returning stored view.
206 2
		if ( !empty( $this->views[ $view_id ] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
207
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
208
			return $this->views[ $view_id ];
209
		}
210
211 2
		if( ! $this->view_exists( $view_id ) ) {
212
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
213
			return false;
214
		}
215
216 2
		$form_id = gravityview_get_form_id( $view_id );
217
218 2
		if( empty( $form_id ) ) {
219
220
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
221
222
			return false;
223
		}
224
225
		// Get the settings for the View ID
226 2
		$view_settings = gravityview_get_template_settings( $view_id );
227
228 2
		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Settings pulled in from View #%s', $view_id), $view_settings );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
229
230
		// Merge the view settings with the defaults
231 2
		$view_defaults = wp_parse_args( $view_settings, self::get_default_args() );
232
233 2
		do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] View Defaults after merging View Settings with the default args.', $view_defaults );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
234
235 2
		if( ! empty( $atts ) && is_array( $atts ) ) {
236
237
			do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts before merging  with the $view_defaults', $atts );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
238
239
			// Get the settings from the shortcode and merge them with defaults.
240
			$atts = shortcode_atts( $view_defaults, $atts );
241
242
			do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts after merging  with the $view_defaults', $atts );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
243
244
		} else {
245
246
			// If there are no passed $atts, the defaults will be used.
247 2
			$atts = $view_defaults;
248
249
		}
250
251 2
		unset( $atts['id'], $view_defaults, $view_settings );
252
253
		$data = array(
254 2
			'id' => $view_id,
255 2
			'view_id' => $view_id,
256 2
			'form_id' => $form_id,
257 2
			'template_id' => gravityview_get_template_id( $view_id ),
258 2
			'atts' => $atts,
259 2
			'fields' => $this->get_fields( $view_id ),
260 2
			'widgets' => gravityview_get_directory_widgets( $view_id ),
261 2
			'form' => gravityview_get_form( $form_id ),
262
		);
263
264 2
		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] View #%s being added.', $view_id), $data );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
265
266 2
		$this->views[ $view_id ] = $data;
267
268 2
		return $this->views[ $view_id ];
269
	}
270
271
	/**
272
	 * Get the visible fields for a View
273
	 * @uses  gravityview_get_directory_fields() Fetch the configured fields for a View
274
	 * @uses  GravityView_View_Data::filter_fields() Only show visible fields
275
	 * @param  int $view_id View ID
276
	 * @return array          Array of fields as passed by `gravityview_get_directory_fields()`
277
	 */
278 2
	function get_fields( $view_id ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
279
280 2
		$dir_fields = gravityview_get_directory_fields( $view_id );
281 2
		do_action( 'gravityview_log_debug', '[render_view] Fields: ', $dir_fields );
282
283
		// remove fields according to visitor visibility permissions (if logged-in)
284 2
		$dir_fields = $this->filter_fields( $dir_fields );
285 2
		do_action( 'gravityview_log_debug', '[render_view] Fields after visibility filter: ', $dir_fields );
286
287 2
		return $dir_fields;
288
	}
289
290
	/**
291
	 * Filter area fields based on specified conditions
292
	 *
293
	 * @access public
294
	 * @param array $dir_fields
295
	 * @return array
296
	 */
297 2
	private function filter_fields( $dir_fields ) {
298
299 2
		if( empty( $dir_fields ) || !is_array( $dir_fields ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
300
			return $dir_fields;
301
		}
302
303 2
		foreach( $dir_fields as $area => $fields ) {
304
305 2
			foreach( (array)$fields as $uniqid => $properties ) {
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
306
307 2
				if( $this->hide_field_check_conditions( $properties ) ) {
308 2
					unset( $dir_fields[ $area ][ $uniqid ] );
309
				}
310
311
			}
312
		}
313
314 2
		return $dir_fields;
315
316
	}
317
318
319
	/**
320
	 * Check whether a certain field should not be presented based on its own properties.
321
	 *
322
	 * @access public
323
	 * @param array $properties
324
	 * @return boolean True: (field should be hidden) or False: (field should be presented)
325
	 */
326 2
	private function hide_field_check_conditions( $properties ) {
327
328
		// logged-in visibility
329 2
		if( ! empty( $properties['only_loggedin'] ) && ! GVCommon::has_cap( $properties['only_loggedin_cap'] ) ) {
330
			return true;
331
		}
332
333 2
		return false;
334
	}
335
336
	/**
337
	 * @deprecated Also dead code, was probably superceded by GravityView_View_Data::parse_post_content
338
	 */
339
	function get_id_from_atts( $atts ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
340
341
		$atts = is_array( $atts ) ? $atts : shortcode_parse_atts( $atts );
342
343
		// Get the settings from the shortcode and merge them with defaults.
344
		$atts = wp_parse_args( $atts, self::get_default_args() );
345
346
		$view_id = ! empty( $atts['view_id'] ) ? (int)$atts['view_id'] : NULL;
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
347
348
		if( empty( $view_id ) && !empty( $atts['id'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
349
			$view_id = (int)$atts['id'];
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
350
		}
351
352
		if( empty( $view_id ) ) {
353
			do_action('gravityview_log_error', 'GravityView_View_Data[get_id_from_atts] Returning; no ID defined (Atts)', $atts );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
354
			return;
355
		}
356
357
		return $view_id;
358
	}
359
360
	/**
361
	 * Parse content to determine if there is a GV shortcode to allow for enqueing necessary files in the head.
362
	 *
363
	 * @uses gravityview_has_shortcode_r() Check whether shortcode exists (recursively)
364
	 * @uses shortcode_parse_atts() Parse each GV shortcode
365
	 * @uses  gravityview_get_template_settings() Get the settings for the View ID
366
	 * @param  string $content $post->post_content content
367
	 * @return int|null|array If a single View is found, the ID of the View. If there are multiple views in the content, array of IDs parsed. If not found, NULL
368
	 */
369
	public function parse_post_content( $content ) {
370
371
		/**
372
		 * @hack This is so that the shortcode is registered for the oEmbed preview in the Admin
373
		 * @since 1.6
374
		 */
375
		if( ! shortcode_exists('gravityview') && class_exists( 'GravityView_Shortcode' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
376
			new GravityView_Shortcode;
377
		}
378
379
		$shortcodes = gravityview_has_shortcode_r( $content, 'gravityview' );
380
381
		if( empty( $shortcodes ) ) {
382
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
383
		}
384
385
		do_action('gravityview_log_debug', 'GravityView_View_Data[parse_post_content] Parsing content, found shortcodes:', $shortcodes );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
386
387
		$ids = array();
388
389
		foreach ($shortcodes as $key => $shortcode) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
390
391
			$shortcode[3] = htmlspecialchars_decode( $shortcode[3], ENT_QUOTES );
392
393
			$args = shortcode_parse_atts( $shortcode[3] );
394
395
			if( empty( $args['id'] ) ) {
396
				do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_content] Returning; no ID defined in shortcode atts for Post #%s (Atts)', $post->ID ), $shortcode );
0 ignored issues
show
Bug introduced by
The variable $post does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
397
				continue;
398
			}
399
400
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[parse_post_content] Adding view #%s with shortcode args', $args['id']), $args );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
401
402
			// Store the View to the object for later fetching.
403
			$this->add_view( $args['id'], $args );
404
405
			$ids[] = $args['id'];
406
		}
407
408
		if( empty($ids) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
409
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
410
		}
411
412
		// If it's just one ID, return that.
413
		// Otherwise, return array of IDs
414
		return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
415
416
	}
417
418
	/**
419
	 * Parse specific custom fields (Post Meta) to determine if there is a GV shortcode to allow for enqueuing necessary files in the head.
420
	 * @since 1.15.1
421
	 * @uses \GravityView_View_Data::parse_post_content
422
	 * @param int $post_id WP_Post ID
423
	 * @return int|null|array If a single View is found, the ID of the View. If there are multiple views in the content, array of IDs parsed. If not found, or meta not parsed, NULL
424
	 */
425
	private function parse_post_meta( $post_id ) {
426
427
		/**
428
		 * @filter `gravityview/data/parse/meta_keys` Define meta keys to parse to check for GravityView shortcode content
429
		 * This is useful when using themes that store content that may contain shortcodes in custom post meta
430
		 * @param[in,out] array $meta_keys Array of key values to check. If empty, do not check. Default: empty array
431
		 * @param[in] int $post_id ID of the post being checked
432
		 */
433
		$meta_keys = (array)apply_filters( 'gravityview/data/parse/meta_keys', array(), $post_id );
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
434
435
		if( empty( $meta_keys ) ) {
436
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
437
		}
438
439
		do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_meta] Search for GravityView shortcodes on the following custom fields keys:', $meta_keys );
440
441
		$meta_content = '';
442
443
		foreach( $meta_keys as $key ) {
444
			$meta = get_post_meta( $post_id, $key , true );
445
			if( ! is_string( $meta ) ) {
446
				continue;
447
			}
448
			$meta_content .= $meta . ' ';
449
		}
450
451
		if( empty( $meta_content ) ) {
452
			do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_meta] Returning; Empty custom fields for Post #%s (Custom fields keys:)', $post_id ), $meta_keys );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
453
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
454
		}
455
456
		do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_meta] Combined content retrieved from custom fields:', $meta_content );
457
458
		return $this->parse_post_content( $meta_content );
459
460
	}
461
462
	/**
463
	 * Checks if the passed post id has the passed View id embedded.
464
	 *
465
	 * Returns
466
	 *
467
	 * @since 1.6.1
468
	 *
469
	 * @param string $post_id Post ID where the View is embedded
470
	 * @param string $view_id View ID
471
	 *
472
	 * @return bool|WP_Error If valid, returns true. If invalid, returns WP_Error containing error message.
473
	 */
474 1
	public static function is_valid_embed_id( $post_id = '', $view_id = '', $empty_is_valid = true ) {
475
476 1
		$message = NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
477
478
		// Not invalid if not set!
479 1
		if( empty( $post_id ) || empty( $view_id ) ) {
480
481
			if( $empty_is_valid ) {
482
				return true;
483
			}
484
485
			$message = esc_html__( 'The ID is required.', 'gravityview' );
486
		}
487
488 1
		if( ! $message ) {
489 1
			$status = get_post_status( $post_id );
490
491
			// Nothing exists with that post ID.
492 1
			if ( ! is_numeric( $post_id ) ) {
493
				$message = esc_html__( 'You did not enter a number. The value entered should be a number, representing the ID of the post or page the View is embedded on.', 'gravityview' );
494
495
				// @todo Convert to generic article about Embed IDs
496
				$message .= ' ' . gravityview_get_link( 'http://docs.gravityview.co/article/222-the-search-widget', __( 'Learn more&hellip;', 'gravityview' ), 'target=_blank' );
497
			}
498
		}
499
500 1
		if( ! $message ) {
501
502
			// Nothing exists with that post ID.
503 1
			if ( empty( $status ) || in_array( $status, array( 'revision', 'attachment' ) ) ) {
504
				$message = esc_html__( 'There is no post or page with that ID.', 'gravityview' );
505
			}
506
507
		}
508
509 1
		if( ! $message ) {
510 1
			if ( false /** Do not use for now. See issue #848 */ && function_exists( 'gravityview' ) && $post = get_post( $post_id ) )  {
511
				$views = GV\View_Collection::from_post( $post );
512
				$view_ids_in_post = array_map( function( $view ) { return $view->ID; }, $views->all() );
513
			} else {
514
				/** ::maybe_get_view_id deprecated. */
515 1
				$view_ids_in_post = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::maybe_get_view_id() has been deprecated.

This method has been deprecated.

Loading history...
516
			}
517
518
			// The post or page specified does not contain the shortcode.
519 1
			if ( false === in_array( $view_id, (array) $view_ids_in_post ) ) {
520 1
				$message = sprintf( esc_html__( 'The Post ID entered is not valid. You may have entered a post or page that does not contain the selected View. Make sure the post contains the following shortcode: %s', 'gravityview' ), '<br /><code>[gravityview id="' . intval( $view_id ) . '"]</code>' );
521
			}
522
		}
523
524 1
		if( ! $message ) {
525
526
			// It's a View
527 1
			if( 'gravityview' === get_post_type( $post_id ) ) {
528
				$message = esc_html__( 'The ID is already a View.', 'gravityview' );;
529
			}
530
531
		}
532
533 1
		if( $message ) {
534 1
			return new WP_Error( 'invalid_embed_id', $message );
535
		}
536
537 1
		return true;
538
	}
539
540
	/**
541
	 * Get a specific default setting
542
	 * @param  string  $key          The key of the setting array item
543
	 * @param  boolean $with_details Include details
544
	 * @return mixed|array                If using $with_details, return array. Otherwise, mixed.
545
	 */
546
	public static function get_default_arg( $key, $with_details = false ) {
547
548
		$args = self::get_default_args( $with_details );
549
550
		if( !isset( $args[ $key ] ) ) { return NULL; }
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
551
552
		return $args[ $key ];
553
	}
554
555
	/**
556
	 * Retrieve the default args for shortcode and theme function
557
	 *
558
	 * @param boolean $with_details True: Return array with full default settings information, including description, name, etc. False: Return an array with only key => value pairs.
559
	 * @param string $group Only fetch
560
	 *
561
	 * @return array $args Associative array of default settings for a View
562
	 *      @param[out] string $label Setting label shown in admin
563
	 *      @param[out] string $type Gravity Forms field type
564
	 *      @param[out] string $group The field group the setting is associated with. Default: "default"
565
	 *      @param[out] mixed  $value The default value for the setting
566
	 *      @param[out] string $tooltip Tooltip displayed for the setting
567
	 *      @param[out] boolean $show_in_shortcode Whether to show the setting in the shortcode configuration modal
568
	 *      @param[out] array  $options Array of values to use when generating select, multiselect, radio, or checkboxes fields
569
	 *      @param[out] boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering.
570
	 */
571 5
	public static function get_default_args( $with_details = false, $group = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
572
573
		/**
574
		 * @filter `gravityview_default_args` Modify the default settings for new Views
575
		 * @param[in,out] array $default_args Array of default args.
576
		 */
577 5
		$default_settings = apply_filters( 'gravityview_default_args', array(
578
			'id' => array(
579 5
				'label' => __('View ID', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
580 5
				'type' => 'number',
581 5
				'group'	=> 'default',
582
				'value' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
583
				'tooltip' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
584
				'show_in_shortcode' => false,
585 5
			),
586
			'page_size' => array(
587 5
				'label' 	=> __('Number of entries per page', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
588 5
				'type' => 'number',
589 5
				'class'	=> 'small-text',
590 5
				'group'	=> 'default',
591 5
				'value' => 25,
592
				'show_in_shortcode' => true,
593
			),
594
			'offset' => array(
595 5
				'label' 	=> __('Offset entries starting from', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
596 5
				'type' => 'number',
597 5
				'class'	=> 'small-text',
598 5
				'group'	=> 'default',
599 5
				'value' => 0,
600
				'show_in_shortcode' => false,
601
			),
602
			'lightbox' => array(
603 5
				'label' => __( 'Enable lightbox for images', 'gravityview' ),
604 5
				'type' => 'checkbox',
605 5
				'group'	=> 'default',
606 5
				'value' => 1,
607
				'tooltip' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
608
				'show_in_shortcode' => true,
609
			),
610
			'show_only_approved' => array(
611 5
				'label' => __( 'Show only approved entries', 'gravityview' ),
612 5
				'type' => 'checkbox',
613 5
				'group'	=> 'default',
614 5
				'value' => 0,
615
				'show_in_shortcode' => true,
616
			),
617
			'admin_show_all_statuses' => array(
618 5
				'label' => __( 'Show all entries to administrators', 'gravityview' ),
619 5
				'desc'	=> __('Administrators will be able to see entries with any approval status.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
620 5
				'tooltip' => __('Logged-out visitors and non-administrators will only see approved entries, while administrators will see entries with all statuses. This makes it easier for administrators to moderate entries from a View.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
621 5
				'requires' => 'show_only_approved',
622 5
				'type' => 'checkbox',
623 5
				'group'	=> 'default',
624 5
				'value' => 0,
625
				'show_in_shortcode' => false,
626
			),
627
			'hide_until_searched' => array(
628 5
				'label' => __( 'Hide View data until search is performed', 'gravityview' ),
629 5
				'type' => 'checkbox',
630 5
				'group'	=> 'default',
631 5
				'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ),
632 5
				'value' => 0,
633
				'show_in_shortcode' => false,
634
			),
635
			'hide_empty' => array(
636 5
				'label' 	=> __( 'Hide empty fields', 'gravityview' ),
637 5
				'group'	=> 'default',
638 5
				'type'	=> 'checkbox',
639 5
				'value' => 1,
640
				'show_in_shortcode' => false,
641
			),
642
			'user_edit' => array(
643 5
				'label'	=> __( 'Allow User Edit', 'gravityview' ),
644 5
				'group'	=> 'default',
645 5
				'desc'	=> __('Allow logged-in users to edit entries they created.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
646 5
				'value'	=> 0,
647 5
				'tooltip' => __('Display "Edit Entry" fields to non-administrator users if they created the entry. Edit Entry fields will always be displayed to site administrators.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
648 5
				'type'	=> 'checkbox',
649
				'show_in_shortcode' => true,
650
			),
651
			'user_delete' => array(
652 5
				'label'	=> __( 'Allow User Delete', 'gravityview' ),
653 5
				'group'	=> 'default',
654 5
				'desc'	=> __('Allow logged-in users to delete entries they created.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
655 5
				'value'	=> 0,
656 5
				'tooltip' => __('Display "Delete Entry" fields to non-administrator users if they created the entry. Delete Entry fields will always be displayed to site administrators.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
657 5
				'type'	=> 'checkbox',
658
				'show_in_shortcode' => true,
659
			),
660
			'sort_field' => array(
661 5
				'label'	=> __('Sort by field', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
662 5
				'type' => 'select',
663 5
				'value' => '',
664 5
				'group'	=> 'sort',
665
				'options' => array(
666 5
					'' => __( 'Default', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
667 5
					'date_created' => __( 'Date Created', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
668
				),
669
				'show_in_shortcode' => true,
670
			),
671
			'sort_direction' => array(
672 5
				'label' 	=> __('Sort direction', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
673 5
				'type' => 'select',
674 5
				'value' => 'ASC',
675 5
				'group'	=> 'sort',
676
				'options' => array(
677 5
					'ASC' => __('ASC', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
678 5
					'DESC' => __('DESC', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
679
					//'RAND' => __('Random', 'gravityview'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
680
				),
681
				'show_in_shortcode' => true,
682
			),
683
			'sort_columns' => array(
684 5
				'label' 	=> __( 'Enable sorting by column', 'gravityview' ),
685 5
				'left_label' => __( 'Column Sorting', 'gravityview' ),
686 5
				'type' => 'checkbox',
687
				'value' => false,
688 5
				'group'	=> 'sort',
689
				'tooltip' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
690
				'show_in_shortcode' => true,
691
				'show_in_template' => array( 'default_table' ),
692
			),
693
			'start_date' => array(
694 5
				'label' 	=> __('Filter by Start Date', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
695 5
				'class'	=> 'gv-datepicker',
696 5
				'desc'	=> __('Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
697 5
				'type' => 'text',
698 5
				'value' => '',
699 5
				'group'	=> 'filter',
700
				'show_in_shortcode' => true,
701
			),
702
			'end_date' => array(
703 5
				'label' 	=> __('Filter by End Date', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
704 5
				'class'	=> 'gv-datepicker',
705 5
				'desc'	=> __('Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
706 5
				'type' => 'text',
707 5
				'value' => '',
708 5
				'group'	=> 'filter',
709
				'show_in_shortcode' => true,
710
			),
711
			'class' => array(
712 5
				'label' 	=> __('CSS Class', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
713 5
				'desc'	=> __('CSS class to add to the wrapping HTML container.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
714 5
				'group'	=> 'default',
715 5
				'type' => 'text',
716 5
				'value' => '',
717
				'show_in_shortcode' => false,
718
			),
719
			'search_value' => array(
720 5
				'label' 	=> __('Search Value', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
721 5
				'desc'	=> __('Define a default search value for the View', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
722 5
				'type' => 'text',
723 5
				'value' => '',
724 5
				'group'	=> 'filter',
725
				'show_in_shortcode' => false,
726
			),
727
			'search_field' => array(
728 5
				'label' 	=> __('Search Field', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
729 5
				'desc'	=> __('If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
730 5
				'type' => 'number',
731 5
				'value' => '',
732 5
				'group'	=> 'filter',
733
				'show_in_shortcode' => false,
734
			),
735
			'single_title' => array(
736 5
				'label'	=> __('Single Entry Title', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
737 5
				'type'	=> 'text',
738 5
				'desc'	=> __('When viewing a single entry, change the title of the page to this setting. Otherwise, the title will not change between the Multiple Entries and Single Entry views.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
739 5
				'group'	=> 'default',
740 5
				'value'	=> '',
741
				'show_in_shortcode' => false,
742
				'full_width' => true,
743
			),
744
			'back_link_label' => array(
745 5
				'label'	=> __('Back Link Label', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
746 5
				'group'	=> 'default',
747 5
				'desc'	=> __('The text of the link that returns to the multiple entries view.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
748 5
				'type'	=> 'text',
749 5
				'value'	=> '',
750
				'show_in_shortcode' => false,
751
				'full_width' => true,
752
			),
753
			'embed_only' => array(
754 5
				'label'	=> __('Prevent Direct Access', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
755 5
				'group'	=> 'default',
756 5
				'desc'	=> __('Only allow access to this View when embedded using the shortcode.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
757 5
				'type'	=> 'checkbox',
758 5
				'value'	=> '',
759
				'show_in_shortcode' => false,
760
				'full_width' => true,
761
			),
762
			'post_id' => array(
763
				'type' => 'number',
764
				'value' => '',
765
				'show_in_shortcode' => false,
766
			),
767
		));
768
769
		// By default, we only want the key => value pairing, not the whole array.
770 5
		if( empty( $with_details ) ) {
771
772 5
			$defaults = array();
773
774 5
			foreach( $default_settings as $key => $value ) {
775 5
				$defaults[ $key ] = $value['value'];
776
			}
777
778 5
			return $defaults;
779
780
		}
781
		// But sometimes, we want all the details.
782
		else {
783
784
			foreach ($default_settings as $key => $value) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
785
786
				// If the $group argument is set for the method,
787
				// ignore any settings that aren't in that group.
788
				if( !empty( $group ) && is_string( $group ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
789
					if( empty( $value['group'] ) || $value['group'] !== $group ) {
790
						unset( $default_settings[ $key ] );
791
					}
792
				}
793
794
			}
795
796
			return $default_settings;
797
798
		}
799
	}
800
801
802
}
803