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
Branch master (f6fad4)
by Marko
01:08
created

enqueue_scripts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 0
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' ) );
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 );
13
	}
14
15
16
	public function enqueue_scripts() {
17
		$screen = get_current_screen();
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' );
24
		wp_enqueue_script( 'tabify-edit-screen-permissions' );
25
26
		$data = array(
27
			'everyone'  => __( 'Everyone', 'tabify-edit-screen' ),
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 );
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 );
39
		}
40
		else {
41
			$btn_permissions = __( 'Everyone', 'tabify-edit-screen' );
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();
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' );
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' );
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();
106
			}
107
		}
108
		else {
109
			$wp_roles = wp_roles();
110
		}
111
112
		return $wp_roles->roles;
113
	}
114
115
}
116