GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f6fad4...6b3106 )
by Marko
07:00
created

Tabify_Edit_Screen_Feature_Permissions   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 56
c 1
b 0
f 0
dl 0
loc 110
rs 10
wmc 20

6 Methods

Rating   Name   Duplication   Size   Complexity  
A settings_tab_title_after() 0 15 3
A get_roles() 0 13 3
A settings_tab_title_box() 0 10 3
B posttype_tabs() 0 32 8
A enqueue_scripts() 0 16 2
A __construct() 0 8 1
1
<?php
2
3
class Tabify_Edit_Screen_Feature_Permissions {
4
5
	public function __construct() {
6
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

6
		/** @scrutinizer ignore-call */ 
7
  add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
Loading history...
7
8
		add_action( 'tabify_settings_tab_title_box', array( $this, 'settings_tab_title_box' ) );
9
		add_action( 'tabify_settings_tab_title_after', array( $this, 'settings_tab_title_after' ), 10, 3 );
10
11
		// Remove meta boxes when no permissions
12
		add_filter( 'tabify_tab_posttype_tabs', array( $this, 'posttype_tabs' ), 10, 2 );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

12
		/** @scrutinizer ignore-call */ 
13
  add_filter( 'tabify_tab_posttype_tabs', array( $this, 'posttype_tabs' ), 10, 2 );
Loading history...
13
	}
14
15
16
	public function enqueue_scripts() {
17
		$screen = get_current_screen();
0 ignored issues
show
Bug introduced by
The function get_current_screen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
		$screen = /** @scrutinizer ignore-call */ get_current_screen();
Loading history...
18
19
		if ( 'settings_page_tabify-edit-screen' != $screen->base ) {
20
			return;
21
		}
22
23
		wp_register_script( 'tabify-edit-screen-permissions', plugins_url( '/permissions.js', __FILE__ ), array( 'jquery' ), '1.0' );
0 ignored issues
show
Bug introduced by
The function wp_register_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
		/** @scrutinizer ignore-call */ 
24
  wp_register_script( 'tabify-edit-screen-permissions', plugins_url( '/permissions.js', __FILE__ ), array( 'jquery' ), '1.0' );
Loading history...
Bug introduced by
The function plugins_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
		wp_register_script( 'tabify-edit-screen-permissions', /** @scrutinizer ignore-call */ plugins_url( '/permissions.js', __FILE__ ), array( 'jquery' ), '1.0' );
Loading history...
24
		wp_enqueue_script( 'tabify-edit-screen-permissions' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
		/** @scrutinizer ignore-call */ 
25
  wp_enqueue_script( 'tabify-edit-screen-permissions' );
Loading history...
25
26
		$data = array(
27
			'everyone'  => __( 'Everyone', 'tabify-edit-screen' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
			'everyone'  => /** @scrutinizer ignore-call */ __( 'Everyone', 'tabify-edit-screen' ),
Loading history...
28
			'onerole'   => __( '1 role', 'tabify-edit-screen' ),
29
			'multirole' => __( '%s role', 'tabify-edit-screen' )
30
		);
31
		wp_localize_script( 'tabify-edit-screen-permissions', 'tabify_permissions', $data );
0 ignored issues
show
Bug introduced by
The function wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
		/** @scrutinizer ignore-call */ 
32
  wp_localize_script( 'tabify-edit-screen-permissions', 'tabify_permissions', $data );
Loading history...
32
	}
33
34
35
	public function settings_tab_title_box( $tab ) {
36
		if ( $tab['permissions'] && is_array( $tab['permissions'] ) ) {
37
			$count = count( $tab['permissions'] );
38
			$btn_permissions = sprintf( _n( '1 role', '%s roles', $count, 'tabify-edit-screen' ), $count );
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
			$btn_permissions = sprintf( /** @scrutinizer ignore-call */ _n( '1 role', '%s roles', $count, 'tabify-edit-screen' ), $count );
Loading history...
39
		}
40
		else {
41
			$btn_permissions = __( 'Everyone', 'tabify-edit-screen' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
			$btn_permissions = /** @scrutinizer ignore-call */ __( 'Everyone', 'tabify-edit-screen' );
Loading history...
42
		}
43
44
		echo '<button class="tabify-tab-permissions button button-secondary hide-if-no-js" type="button">' . $btn_permissions . '</button>';
45
	}
46
47
	public function settings_tab_title_after( $tab, $section, $type ) {
48
		echo '<div class="tabify-tab-permission-box">';
49
50
		$all_roles = $this->get_roles();
51
		foreach ( $all_roles as $key => $role ) {
52
			$name    = 'tabify[' . $type . '][' . $section . '][tabs][' . $tab['id'] . '][permissions][]';
53
			$checked = in_array( $key, $tab['permissions'] ) ? ' checked="checked"' : '';
54
55
			echo '<label>';
56
			echo '<input  name="' . $name . '" type="checkbox" value="' . $key . '"' . $checked . '/>';
57
			echo $role['name'];
58
			echo '</label>';
59
		}
60
61
		echo '</div>';
62
	}
63
64
65
	public function posttype_tabs( $tabs, $post_type ) {
66
		foreach( $tabs as $index => $tab ) {
67
			if ( ! isset( $tab['permissions'] ) ) {
68
				continue;
69
			}
70
71
			$current_user = wp_get_current_user();
0 ignored issues
show
Bug introduced by
The function wp_get_current_user was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
			$current_user = /** @scrutinizer ignore-call */ wp_get_current_user();
Loading history...
72
			foreach ( $current_user->roles as $role ) {
73
				if ( in_array( $role, $tab['permissions'] ) ) {
74
					continue 2;
75
				}
76
			}
77
78
			foreach ( $tab['items'] as $item ) {
79
				if ( 'titlediv' == $item ) {
80
					remove_post_type_support( $post_type, 'title' );
0 ignored issues
show
Bug introduced by
The function remove_post_type_support was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
					/** @scrutinizer ignore-call */ 
81
     remove_post_type_support( $post_type, 'title' );
Loading history...
81
				}
82
				elseif ( 'postdivrich' == $item ) {
83
					remove_post_type_support( $post_type, 'editor' );
84
				}
85
				else {
86
					// Just guess the context of the meta box
87
					remove_meta_box( $item, $post_type, 'normal' );
0 ignored issues
show
Bug introduced by
The function remove_meta_box was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
					/** @scrutinizer ignore-call */ 
88
     remove_meta_box( $item, $post_type, 'normal' );
Loading history...
88
					remove_meta_box( $item, $post_type, 'advanced' );
89
					remove_meta_box( $item, $post_type, 'side' );
90
				}
91
			}
92
93
			unset( $tabs[ $index ] );
94
		}
95
96
		return $tabs;
97
	}
98
99
100
	private function get_roles() {
101
		if ( ! function_exists( 'wp_roles' ) ) {
102
			global $wp_roles;
103
104
			if ( ! isset( $wp_roles ) ) {
105
				$wp_roles = new WP_Roles();
0 ignored issues
show
Bug introduced by
The type WP_Roles was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
106
			}
107
		}
108
		else {
109
			$wp_roles = wp_roles();
110
		}
111
112
		return $wp_roles->roles;
113
	}
114
115
}
116