Completed
Push — master ( 324b21...97e5ed )
by
unknown
01:55
created

helpers.php ➔ lasso_user_can()   C

Complexity

Conditions 11
Paths 28

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 20
nc 28
nop 2
dl 0
loc 33
rs 5.2653
c 0
b 0
f 0

How to fix   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 15 and the first side effect is on line 417.

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
    unset( $post_types[ 'attachment' ] );
274
275
	/**
276
	 * Set which post types are allowed
277
	 *
278
	 * @since 0.9.4
279
	 *
280
	 * @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered.
281
	 */
282
	$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post') );
0 ignored issues
show
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...
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...
283
	$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types );
284
	foreach( $post_types as $name => $label ) {
285
		if ( ! in_array( $name, $allowed_post_types ) ) {
286
			unset( $post_types[ $name ] );
287
		}
288
	}
289
	return $post_types;
290
}
291
292
function lasso_post_types_rest_base() {
293
	global $wp_post_types;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

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

1. Pass all data via parameters

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

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

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

    public function myFunction() {
        // Do something
    }
}
Loading history...
294
	$post_types = lasso_post_types();
295
	$rest_base = array();
296
	foreach ( $post_types as $post_type) {
297
		$rest_base[$post_type] = $wp_post_types[$post_type]->rest_base;
298
	}
299
    
300
	return $rest_base;
301
}
302
303
////////////////////
304
// INTERNAL
305
////////////////////
306
/**
307
*	Used internally as a callback to build a tab or content area for modal addons
308
*
309
*	@param $tab object
310
*	@param $type string tab or content
311
*	@uses lasso_modal_addons()
312
*	@since 0.9.4
313
*/
314
function lasso_modal_addons_content( $tab = '', $type ){
315
316
	$name = lasso_clean_string( $tab['name'] );
317
318
	if ( 'tab' == $type ) {
319
320
		$out = sprintf( '<li data-addon-name="%s">%s</li>', $name, $tab['name'] );
321
322
	} else if ( 'content' == $type ){
323
324
		$content = isset( $tab['content'] ) && is_callable( $tab['content'] ) ? call_user_func( $tab['content'] ) : false;
325
		$options = isset( $tab['options'] ) && is_callable( $tab['options'] ) ? call_user_func( $tab['options'] ) : false;
326
327
		$out = sprintf( '<div class="lasso--modal__content not-visible" data-addon-content="%s">
328
			%s%s
329
			</div>', $name, $content, lasso_option_form( $name, $options ) );
330
331
	}
332
333
	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...
334
}
335
336
/**
337
*	Helper function to clean a string and replace spaces with dash
338
*
339
*	@param $string string content
340
*	@since 0.9.4
341
*
342
* @return void|string
343
*/
344
function lasso_clean_string( $string = '' ) {
345
346
	if ( empty( $string ) )
347
		return;
348
349
	return sanitize_text_field( strtolower( preg_replace('/[\s_]/', '-', $string ) ) );
350
}
351
352
/**
353
 *	Helper function to switch - to _ after having.
354
 *
355
 * This is the evil twin of lasso_clean_string() and may or may not make your data forever unclean.
356
 *
357
 *	@param $string string content
358
 *	@since 0.9.5
359
 *
360
 * @return void|string
361
 */
362
function lasso_unclean_string( $string = '' ) {
363
364
	if ( empty( $string ) ) {
365
		return;
366
	}
367
368
	return sanitize_text_field( strtolower( str_replace( '-', '_', $string ) ) );
369
}
370
371
372
////////////////////
373
// PLUGGABLE
374
////////////////////
375
376
/**
377
 * Check if the user is logged in and has the correctly passed capability
378
 *
379
 * @param unknown $action string a capability such as edit_posts or publish_posts
380
 * @param unknown $postid int the id of the post object to check against
381
 * @since 0.9.9.7 added filter 'lasso_user_can_filter'
382
 */
383
if ( !function_exists( 'lasso_user_can' ) ):
384
	function lasso_user_can( $action = '', $postid = 0 ) {
385
        $result = false;
386
		if ( empty( $action ) )
387
			$action = 'edit_posts';
388
389
		if ( empty( $postid ) && $action != 'edit_posts' && $action != 'publish_posts')
390
			$postid = get_the_ID();
391
392
		if ( is_user_logged_in() && current_user_can( $action, $postid ) ) {
393
			// check against post types:
394
			$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post', 'page') );
0 ignored issues
show
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...
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...
395
			
396
			if (!current_user_can('edit_pages')) {
397
				$allowed_post_types = array_diff($allowed_post_types,array('page'));
398
			}
399
			
400
            if (!empty($allowed_post_types) && !empty($postid)) {
401
				$type = get_post_type( $postid );
402
                $allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types );
403
				
404
                if ( in_array( $type, $allowed_post_types ) ) {
405
				   $result =  true;
406
			    }
407
            } else {
408
                //we are not checking against a post, return true
409
				$result =  true;
410
        	}
411
		} else {
412
			$result = false;
413
		}
414
		
415
		return apply_filters( 'lasso_user_can_filter', $result,  $action, $postid);
416
	}
417
endif;
418
419
/**
420
*	Empty state message thats shown when no data available
421
*
422
*	@since 0.9.5
423
*/
424
if ( !function_exists('lasso_editor_empty_results') ):
425
426
	function lasso_editor_empty_results( $type = 'posts' ){
427
428
		if ( 'posts' == $type ) {
429
430
			$string = apply_filters('lasso_empty_state_message', __('No posts to show', 'lasso') );
431
			$icon = 'lasso-icon-file-text2';
432
			$button = false;
433
434
		} elseif ( 'revision' == $type ) {
435
436
			$string = apply_filters('lasso_empty_state_message', __('No revisions found', 'lasso') );
437
			$icon = 'lasso-icon-history';
438
			$button = sprintf('<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">%s</a>', __('Close','lasso') );
439
440
		}
441
442
		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...
443
	}
444
445
endif;
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460