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

Tabify_Edit_Screen_Feature_Detection   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 25
lcom 0
cbo 0
dl 0
loc 141
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A get_metaboxes() 0 24 5
A __construct() 0 10 1
A head_action_begin() 0 12 5
A enqueue_script() 0 42 4
A head_action() 0 11 1
A add_missing_meta_boxes() 0 9 4
A unattached_metaboxes() 0 21 5
1
<?php
2
3
class Tabify_Edit_Screen_Feature_Detection {
4
5
	public function __construct() {
6
		// Actions to return JSON output on post type new/edit screen
7
		add_action( 'current_screen', array( $this, 'head_action_begin' ) );
8
9
		// Hook for requesting missing hooks
10
		add_action( 'tabify_add_meta_boxes', array( $this, 'add_missing_meta_boxes' ) );
11
12
		// Checking & storing unattached meta boxes on the edit page
13
		add_action( 'tabify_unattached_metaboxes', array( $this, 'unattached_metaboxes' ) );
14
	}
15
16
17
	public function head_action_begin( $screen ) {
18
		if ( ( 'post' == $screen->base || 'media' == $screen->base ) && isset( $_GET['tes_metaboxes'] ) ) {
19
			ob_end_clean(); // For when warnings are displayed
20
			ob_start();
21
22
			add_filter( 'tabify_tab_posttype_show', '__return_true', 1000 );
23
			add_action( 'admin_head', array( $this, 'head_action' ), 110 );
24
		}
25
		else if ( 'settings_page_tabify-edit-screen' == $screen->base ) {
26
			$this->enqueue_script();
27
		}
28
	}
29
30
	private function enqueue_script() {
31
		wp_register_script( 'tabify-edit-screen-detection', plugins_url( '/detection.js', __FILE__ ), array( 'jquery' ), '1.0' );
32
		wp_enqueue_script( 'tabify-edit-screen-detection' );
33
34
		$posttype_links = array();
35
36
		$args = array(
37
			'show_ui' => true
38
		);
39
		$posttypes_objects = get_post_types( $args, 'objects' );
40
		$posttypes_objects = apply_filters( 'tabify_posttypes', $posttypes_objects );
41
42
		foreach ( $posttypes_objects as $posttype ) {
43
			if ( get_transient( 'tabify_detection_' . $posttype->name ) !== false ) {
44
				continue;
45
			}
46
47
			$args = array(
48
				'post_type'      => $posttype->name,
49
				'orderby'        => 'rand',
50
				'posts_per_page' => '1',
51
				'post_status'    => 'any'
52
			);
53
			$post = get_posts( $args );
54
55
			if ( ! empty( $post ) ) {
56
				$url = get_edit_post_link( $post[0], 'raw' );
57
				$url = add_query_arg( 'tes_metaboxes', 'true', $url );
58
				$posttype_links[ $posttype->name ] = $url;
59
			}
60
			else {
61
				$url = admin_url('post-new.php');
62
				$url = add_query_arg( 'post_type', $posttype->name, $url );
63
				$url = add_query_arg( 'tes_metaboxes', 'true', $url );
64
				$posttype_links[ $posttype->name ] = $url;
65
			}
66
		}
67
68
		wp_localize_script( 'tabify-edit-screen-detection', 'tabify_detection', array(
69
			'posttype_links' => $posttype_links
70
		) );
71
	}
72
73
	public function head_action() {
74
		global $wp_meta_boxes;
75
76
		$screen = get_current_screen();
77
78
		ob_end_clean();
79
80
		echo wp_json_encode( get_transient( 'tabify_detection_' . $screen->post_type ) );
81
82
		exit;
83
	}
84
85
86
	public function add_missing_meta_boxes( $post_type ) {
87
		if ( is_array( $metaboxes = get_transient( 'tabify_detection_' . $post_type ) ) ) {
88
			foreach ( $metaboxes as $id => $metabox ) {
89
				if ( ! isset( $wp_meta_boxes[ $post_type ][ $metabox->context ][ $metabox->priority ][ $id ] ) ) {
90
					add_meta_box( $id, $metabox->title, '__return_false', $post_type, $metabox->priority, $metabox->context );
91
				}
92
			}
93
		}
94
	}
95
96
	public function unattached_metaboxes( $unattached_metaboxes ) {
97
		$screen = get_current_screen();
98
99
		if ( get_transient( 'tabify_detection_' . $screen->post_type ) !== false ) {
100
			return;
101
		}
102
103
		$metaboxes = array();
104
105
		if ( $unattached_metaboxes ) {
106
			$metaboxes = $this->get_metaboxes( $screen->post_type );
107
108
			foreach ( $metaboxes as $metabox_id => $metabox ) {
109
				if ( ! isset( $unattached_metaboxes[ $metabox_id ] )  ) {
110
					unset( $metaboxes[ $metabox_id ] );
111
				}
112
			}
113
		}
114
115
		set_transient( 'tabify_detection_' . $screen->post_type, $metaboxes, WEEK_IN_SECONDS );
116
	}
117
118
	private function get_metaboxes( $post_type ) {
119
		global $wp_meta_boxes;
120
121
		$metaboxes = array();
122
123
		foreach ( $wp_meta_boxes[ $post_type ] as $context => $priorities ) {
124
			foreach ( $priorities as $priority => $_metaboxes ) {
125
				foreach ( $_metaboxes as $metabox ) {
126
					// Metabox has been removed
127
					if ( ! isset( $metabox['id'] ) ) {
128
						continue;
129
					}
130
131
					$metaboxes[ $metabox['id'] ] = (object) array(
132
						'title'    => $metabox['title'],
133
						'priority' => $priority,
134
						'context'  => $context
135
					);
136
				}
137
			}
138
		}
139
140
		return $metaboxes;
141
	}
142
143
}