Completed
Push — master ( 02e1e3...df1849 )
by
unknown
01:57
created

lasso.php ➔ lasso_editor_get_option()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 5
nop 3
dl 20
loc 20
rs 8.8571
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 26 and the first side effect is on line 40.

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
 *
5
 * @package   Editus
6
 * @author    Hyun Supul <[email protected]>, Nick Haskins <[email protected]>
7
 * @link      http://edituswp.com
8
 * @copyright 2015-2017 Aesopinteractive 
9
 *
10
 * Plugin Name:       Editus
11
 * Plugin URI:        http://edituswp.com
12
 * Description:       Front-end editor and story builder.
13
 * Version:           0.9.16.0
14
 * Author:            Aesopinteractive 
15
 * Author URI:        http://aesopinteractive.com
16
 * Text Domain:       lasso
17
 * Domain Path:       /languages
18
 */
19
20
// If this file is called directly, abort.
21
if ( ! defined( 'WPINC' ) ) {
22
	die;
23
}
24
25
// Set some constants
26
define( 'LASSO_VERSION', '0.9.16.0' );
27
define( 'LASSO_DIR', plugin_dir_path( __FILE__ ) );
28
define( 'LASSO_URL', plugins_url( '', __FILE__ ) );
29
define( 'LASSO_FILE', __FILE__ );
30
31
/**
32
 * Load plugin if PHP version is 5.4 or later.
33
 */
34
if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) {
35
36
	include_once( LASSO_DIR . '/bootstrap.php' );
37
38
} else {
39
40
	add_action('admin_head', 'lasso_fail_notice');
41
	function lasso_fail_notice(){
42
43
		printf('<div class="error"><p>Lasso requires PHP 5.4 or higher.</p></div>');
44
45
	}
46
}
47
48
add_filter('register_post_type_args', 'lasso_show_in_rest', 10, 2);
49
function lasso_show_in_rest($args, $post_type){
50
 
51
    $allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( ) );
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

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...
52
	$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types );
53
	if (in_array( $post_type,$allowed_post_types)) {
54
		$args['show_in_rest'] = true;
55
		if ($post_type != 'post' && $post_type != 'page') {
56
			$args['rest_base'] = $post_type;
57
		}
58
	}
59
 
60
    return $args;
61
}
62
63
64 View Code Duplication
function lasso_editor_get_option( $option, $section, $default = '' ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
66
	if ( empty( $option ) )
67
		return;
68
69
	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
70
71
		$options = get_site_option( $section );
72
73
	} else {
74
75
		$options = get_option( $section );
76
	}
77
78
	if ( isset( $options[$option] ) ) {
79
		return $options[$option];
80
	}
81
82
	return $default;
83
}
84
85