Completed
Push — master ( 8f4a49...efac85 )
by
unknown
02:18
created

helpers.php ➔ lasso_user_can()   D

Complexity

Conditions 9
Paths 28

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 20
nc 28
nop 2
dl 0
loc 33
rs 4.909
c 0
b 0
f 0
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 15 and the first side effect is on line 409.

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
/**
4
 * Grab an option from our settings
5
 *
6
 * If we're on multsite we'll grab the site option which is stored in the main blogs site option tables, otherwise
7
 * we'll grab the option which is stored on the single blogs option tables
8
 *
9
 * @param unknown $option  string name of the option
10
 * @param unknown $section string name of the section
11
 * @param unknown $default string/int default option value
12
 * @return the option value
13
 * @since 1.0
14
 */
15
function lasso_editor_get_option( $option, $section, $default = '' ) {
16
17
	if ( empty( $option ) )
18
		return;
19
20
	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
21
22
		$options = get_site_option( $section );
23
24
	} else {
25
26
		$options = get_option( $section );
27
	}
28
29
	if ( isset( $options[$option] ) ) {
30
		return $options[$option];
31
	}
32
33
	return $default;
34
}
35
36
/**
37
 * Check to see if any Lasso galleries exist
38
 *
39
 * @since 1.0
40
 */
41
function lasso_editor_galleries_exist() {
42
43
	$q = new wp_query( array( 'post_type' => 'ai_galleries', 'post_status' => 'publish' ) );
44
45
	if ( $q->have_posts() )
46
		return true;
47
	else
48
		return false;
49
}
50
51
/**
52
 * Return a CSS class of an automatically supported theme
53
 *
54
 * @since 0.8.6
55
 * @return a css class if the theme is supported, false if nothing
56
 */
57
function lasso_get_supported_theme_class() {
58
59
	$name  	= wp_get_theme()->get('Name');
60
	$slug  	= lasso_clean_string( $name );
61
62
	switch ( $slug ) {
63
		case 'aesop-story-theme': // aesop
64
			$out = '.aesop-entry-content';
65
			break;
66
		case 'jorgen': // aesop
67
			$out = '.jorgen-entry-content';
68
			break;
69
		case 'novella': // aesop
70
			$out = '.novella-entry-content';
71
			break;
72
		case 'genji': // aesop
73
			$out = '.genji-entry-content';
74
			break;
75
		case 'kerouac': // aesop
76
			$out = '.kerouac-entry-content';
77
			break;
78
		case 'zealot': // aesop
79
			$out = '.zealot-entry-content';
80
			break;
81
		case 'fable': // aesop
82
			$out = '.fable--entry-content';
83
			break;
84
		case 'canvas': // wootheme..err...Automattic
85
			$out = '.entry';
86
			break;
87
		case 'kleo': // 
88
			$out = '.article-content';
89
			break;
90
		//case 'exposure': // 
91
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
92
		//	break;
93
		//case 'lore': // 
94
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
95
		//	break;
96
		//case 'worldview': // upthemes
97
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
98
		//	break;
99
		//case 'genesis': // genesis
100
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
101
		//	break;
102
		//case 'camera': // array.is
103
		//	$out = '.entry-content';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
104
		//	break;
105
		case 'longform': 
106
			$out = '.entry-content-wrapper';
107
			break;
108
109
	}
110
111
	return apply_filters('lasso_content_class', !empty( $out ) ? $out : false);
112
	//return !empty( $out ) ? $out : false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
113
}
114
115
function lasso_get_supported_theme_title_class() {
116
117
	$name  	= wp_get_theme()->get('Name');
118
	$slug  	= lasso_clean_string( $name );
119
120
	switch ( $slug ) {
121
122
		case 'aesop-story-theme': // aesop
123
			$out = '.aesop-entry-title';
124
			break;
125
		case 'jorgen': // aesop
126
			$out = '.jorgen-entry-title';
127
			break;
128
		case 'genji': // aesop
129
			$out = '.genji-entry-title';
130
			break;
131
		case 'kerouac': // aesop
132
			$out = '.kerouac-entry-title';
133
			break;
134
		case 'zealot': // aesop
135
			$out = '.zealot-entry-title';
136
			break;
137
		case 'fable': // aesop
138
			$out = '.fable--entry-title';
139
			break;
140
		case 'kleo': // 
141
			$out = '.page-title';
142
			break;
143
		case 'longform': // 
144
			$out = '.entry-title';
145
			break;
146
	}
147
148
	return apply_filters('lasso_title_class', !empty( $out ) ? $out : false);
149
}
150
151
//since 0.9.9.6
152
function lasso_get_supported_theme_featured_image_class() {
153
154
	$name  	= wp_get_theme()->get('Name');
155
	$slug  	= lasso_clean_string( $name );
0 ignored issues
show
Unused Code introduced by
$slug is not used, you could remove the assignment.

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

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

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

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

Loading history...
156
157
	return apply_filters('lasso_featured_image_class', !empty( $out ) ? $out : false);
0 ignored issues
show
Bug introduced by
The variable $out seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
158
}
159
160
161
/**
162
*	Return a string of classes with items that Lasso will remove when entering the editor
163
*	so that we don't save them as HTML
164
*
165
*	@since 0.8.7
166
*	@return string of comma separated classes
167
*/
168
function lasso_supported_no_save(){
169
170
	return apply_filters('lasso_dont_save', '.lasso--ignore, .sharedaddy, .us_wrapper, .twitter-tweet, .meta, .edit-link, .ssba, .jp-relatedposts, .fb-comments');
171
}
172
173
/**
174
 * Generic sanitization, useful for sanitization of arrays.
175
 *
176
 * @since 0.9.2
177
 *
178
 * @param array|object|string $data Data to sanatize.
179
 *
180
 * @return array|mixed|object|string|void
181
 */
182
function lasso_sanitize_data( $data ) {
183
	return \lasso\sanatize::do_sanitize( $data );
184
185
}
186
187
/**
188
 *	Return a comma delimited list of categories for a specific post object
189
 *
190
 *	@since 0.9.3
191
 *	@return string of comma delimited category slugs
192
*/
193
function lasso_get_post_objects( $postid = '', $taxonomy = 'category') {
194
195
	if ( empty( $postid ) )
196
		$postid = get_the_ID();
197
198
	$objects = 'category' == $taxonomy ? get_the_category( $postid ) : get_the_tags( $postid );
199
200
	if ( empty( $objects) )
201
		return;
202
203
	$out = '';
204
	foreach( $objects as $object ) {
205
		//$out .= $object->slug.', ';
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
206
		$out .= $object->name.', ';
207
	}
208
209
	return rtrim($out, ', ');
210
211
}
212
213
/**
214
 *	Return an array of categories for autocomplete
215
 *
216
 *	@since 0.9.3
217
 *	@return array all categoiries
218
*/
219
function lasso_get_objects( $taxonomy = 'category' ) {
220
221
	$objects = 'category' == $taxonomy ? get_categories(array('hide_empty' => 0)) : get_tags(array('hide_empty' => 0));
222
223
	if ( empty( $objects) )
224
		return;
225
226
	$out = "";
227
	foreach( $objects as $object ) {
228
		$out .= $object->name.',';
229
	}
230
231
	return $out;
232
}
233
234
235
/**
236
 * Get allowed post types for the post chooser modal.
237
 *
238
 *
239
 * @since 0.9.4
240
 */
241
function lasso_post_types_names() {
242
	$post_types = get_post_types( array(
243
		'public' => true,
244
	), 'objects' );
245
	$post_types = array_combine( array_keys( $post_types ), wp_list_pluck( $post_types, 'label' ) );
246
    unset( $post_types[ 'attachment' ] );
247
248
	/**
249
	 * Set which post types are allowed
250
	 *
251
	 * @since 0.9.4
252
	 *
253
	 * @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered.
254
	 */
255
	$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post', 'page') );
0 ignored issues
show
Documentation introduced by
'allowed_post_types' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('post', 'page') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
256
	$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types );
257
	if (!current_user_can('edit_pages')) {
258
		$allowed_post_types = array_diff($allowed_post_types,array('page'));
259
	}
260
	foreach( $post_types as $name => $label ) {
261
		if ( ! in_array( $name, $allowed_post_types ) ) {
262
			unset( $post_types[ $name ] );
263
		}
264
	}
265
	return $post_types;
266
}
267
268
269
function lasso_post_types() {
270
	$post_types = get_post_types( array(
271
		'public' => true,
272
	), 'names' );
273
	//$post_types = array_combine( array_keys( $post_types ), wp_list_pluck( $post_types, 'label' ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% 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...
274
    unset( $post_types[ 'attachment' ] );
275
276
	/**
277
	 * Set which post types are allowed
278
	 *
279
	 * @since 0.9.4
280
	 *
281
	 * @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered.
282
	 */
283
	$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post') );
0 ignored issues
show
Documentation introduced by
'allowed_post_types' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('post') is of type array<integer,string,{"0":"string"}>, but the function expects a string|object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
284
	$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types );
285
	foreach( $post_types as $name => $label ) {
286
		if ( ! in_array( $name, $allowed_post_types ) ) {
287
			unset( $post_types[ $name ] );
288
		}
289
	}
290
	return $post_types;
291
}
292
293
294
295
////////////////////
296
// INTERNAL
297
////////////////////
298
/**
299
*	Used internally as a callback to build a tab or content area for modal addons
300
*
301
*	@param $tab object
302
*	@param $type string tab or content
303
*	@uses lasso_modal_addons()
304
*	@since 0.9.4
305
*/
306
function lasso_modal_addons_content( $tab = '', $type ){
307
308
	$name = lasso_clean_string( $tab['name'] );
309
310
	if ( 'tab' == $type ) {
311
312
		$out = sprintf( '<li data-addon-name="%s">%s</li>', $name, $tab['name'] );
313
314
	} else if ( 'content' == $type ){
315
316
		$content = isset( $tab['content'] ) && is_callable( $tab['content'] ) ? call_user_func( $tab['content'] ) : false;
317
		$options = isset( $tab['options'] ) && is_callable( $tab['options'] ) ? call_user_func( $tab['options'] ) : false;
318
319
		$out = sprintf( '<div class="lasso--modal__content not-visible" data-addon-content="%s">
320
			%s%s
321
			</div>', $name, $content, lasso_option_form( $name, $options ) );
322
323
	}
324
325
	return $out;
0 ignored issues
show
Bug introduced by
The variable $out does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
326
}
327
328
/**
329
*	Helper function to clean a string and replace spaces with dash
330
*
331
*	@param $string string content
332
*	@since 0.9.4
333
*
334
* @return void|string
335
*/
336
function lasso_clean_string( $string = '' ) {
337
338
	if ( empty( $string ) )
339
		return;
340
341
	return sanitize_text_field( strtolower( preg_replace('/[\s_]/', '-', $string ) ) );
342
}
343
344
/**
345
 *	Helper function to switch - to _ after having.
346
 *
347
 * This is the evil twin of lasso_clean_string() and may or may not make your data forever unclean.
348
 *
349
 *	@param $string string content
350
 *	@since 0.9.5
351
 *
352
 * @return void|string
353
 */
354
function lasso_unclean_string( $string = '' ) {
355
356
	if ( empty( $string ) ) {
357
		return;
358
	}
359
360
	return sanitize_text_field( strtolower( str_replace( '-', '_', $string ) ) );
361
}
362
363
364
////////////////////
365
// PLUGGABLE
366
////////////////////
367
368
/**
369
 * Check if the user is logged in and has the correctly passed capability
370
 *
371
 * @param unknown $action string a capability such as edit_posts or publish_posts
372
 * @param unknown $postid int the id of the post object to check against
373
 * @since 0.9.9.7 added filter 'lasso_user_can_filter'
374
 */
375
if ( !function_exists( 'lasso_user_can' ) ):
376
	function lasso_user_can( $action = '', $postid = 0 ) {
377
        $result = false;
378
		if ( empty( $action ) )
379
			$action = 'edit_posts';
380
381
		if ( empty( $postid ) )
382
			$postid = get_the_ID();
383
384
		if ( is_user_logged_in() && current_user_can( $action, $postid ) ) {
385
			// check against post types:
386
			$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post', 'page') );
0 ignored issues
show
Documentation introduced by
'allowed_post_types' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array('post', 'page') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
387
			
388
			if (!current_user_can('edit_pages')) {
389
				$allowed_post_types = array_diff($allowed_post_types,array('page'));
390
			}
391
			
392
            if (!empty($allowed_post_types) && !empty($postid)) {
393
				$type = get_post_type( $postid );
394
                $allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types );
395
				
396
                if ( in_array( $type, $allowed_post_types ) ) {
397
				   $result =  true;
398
			    }
399
            } else {
400
                //we are not checking against a post, return true
401
				$result =  true;
402
        	}
403
		} else {
404
			$result = false;
405
		}
406
		
407
		return apply_filters( 'lasso_user_can_filter', $result,  $action, $postid);
408
	}
409
endif;
410
411
/**
412
*	Empty state message thats shown when no data available
413
*
414
*	@since 0.9.5
415
*/
416
if ( !function_exists('lasso_editor_empty_results') ):
417
418
	function lasso_editor_empty_results( $type = 'posts' ){
419
420
		if ( 'posts' == $type ) {
421
422
			$string = apply_filters('lasso_empty_state_message', __('No posts to show', 'lasso') );
423
			$icon = 'lasso-icon-file-text2';
424
			$button = false;
425
426
		} elseif ( 'revision' == $type ) {
427
428
			$string = apply_filters('lasso_empty_state_message', __('No revisions found', 'lasso') );
429
			$icon = 'lasso-icon-history';
430
			$button = sprintf('<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">%s</a>', __('Close','lasso') );
431
432
		}
433
434
		return sprintf('<div id="lasso--empty-state" class="lasso--empty-state"><i class="lasso--empty-state-icon lasso-icon %s"></i><p>%s</p>%s</div>', $icon, $string, $button );
0 ignored issues
show
Bug introduced by
The variable $icon does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $string does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $button does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
435
	}
436
437
endif;
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452