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.
Passed
Branch master (6b3106)
by Marko
06:06 queued 03:45
created

get_metaboxes()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 3
b 0
f 0
nc 5
nop 1
dl 0
loc 23
rs 9.5555
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' ) );
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

7
		/** @scrutinizer ignore-call */ 
8
  add_action( 'current_screen', array( $this, 'head_action_begin' ) );
Loading history...
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 );
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

22
			/** @scrutinizer ignore-call */ 
23
   add_filter( 'tabify_tab_posttype_show', '__return_true', 1000 );
Loading history...
23
			add_action( 'admin_head', array( $this, 'head_action' ), 110 );
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

23
			/** @scrutinizer ignore-call */ 
24
   add_action( 'admin_head', array( $this, 'head_action' ), 110 );
Loading history...
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' );
0 ignored issues
show
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

31
		wp_register_script( 'tabify-edit-screen-detection', /** @scrutinizer ignore-call */ plugins_url( '/detection.js', __FILE__ ), array( 'jquery' ), '1.0' );
Loading history...
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

31
		/** @scrutinizer ignore-call */ 
32
  wp_register_script( 'tabify-edit-screen-detection', plugins_url( '/detection.js', __FILE__ ), array( 'jquery' ), '1.0' );
Loading history...
32
		wp_enqueue_script( 'tabify-edit-screen-detection' );
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

32
		/** @scrutinizer ignore-call */ 
33
  wp_enqueue_script( 'tabify-edit-screen-detection' );
Loading history...
33
34
		$posttype_links = array();
35
36
		$args = array(
37
			'show_ui' => true
38
		);
39
		$posttypes_objects = get_post_types( $args, 'objects' );
0 ignored issues
show
Bug introduced by
The function get_post_types 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

39
		$posttypes_objects = /** @scrutinizer ignore-call */ get_post_types( $args, 'objects' );
Loading history...
40
		$posttypes_objects = apply_filters( 'tabify_posttypes', $posttypes_objects );
0 ignored issues
show
Bug introduced by
The function apply_filters 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

40
		$posttypes_objects = /** @scrutinizer ignore-call */ apply_filters( 'tabify_posttypes', $posttypes_objects );
Loading history...
41
42
		foreach ( $posttypes_objects as $posttype ) {
43
			if ( get_transient( 'tabify_detection_' . $posttype->name ) !== false ) {
0 ignored issues
show
Bug introduced by
The function get_transient 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

43
			if ( /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $posttype->name ) !== false ) {
Loading history...
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 );
0 ignored issues
show
Bug introduced by
The function get_posts 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

53
			$post = /** @scrutinizer ignore-call */ get_posts( $args );
Loading history...
54
55
			if ( ! empty( $post ) ) {
56
				$url = get_edit_post_link( $post[0], 'raw' );
0 ignored issues
show
Bug introduced by
The function get_edit_post_link 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

56
				$url = /** @scrutinizer ignore-call */ get_edit_post_link( $post[0], 'raw' );
Loading history...
57
				$url = add_query_arg( 'tes_metaboxes', 'true', $url );
0 ignored issues
show
Bug introduced by
The function add_query_arg 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

57
				$url = /** @scrutinizer ignore-call */ add_query_arg( 'tes_metaboxes', 'true', $url );
Loading history...
58
				$posttype_links[ $posttype->name ] = $url;
59
			}
60
			else {
61
				$url = admin_url('post-new.php');
0 ignored issues
show
Bug introduced by
The function admin_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

61
				$url = /** @scrutinizer ignore-call */ admin_url('post-new.php');
Loading history...
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(
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

68
		/** @scrutinizer ignore-call */ 
69
  wp_localize_script( 'tabify-edit-screen-detection', 'tabify_detection', array(
Loading history...
69
			'posttype_links' => $posttype_links
70
		) );
71
	}
72
73
	public function head_action() {
74
		global $wp_meta_boxes;
75
76
		$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

76
		$screen = /** @scrutinizer ignore-call */ get_current_screen();
Loading history...
77
78
		ob_end_clean();
79
80
		echo wp_json_encode( get_transient( 'tabify_detection_' . $screen->post_type ) );
0 ignored issues
show
Bug introduced by
The function wp_json_encode 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
		echo /** @scrutinizer ignore-call */ wp_json_encode( get_transient( 'tabify_detection_' . $screen->post_type ) );
Loading history...
Bug introduced by
The function get_transient 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
		echo wp_json_encode( /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $screen->post_type ) );
Loading history...
81
82
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
83
	}
84
85
86
	public function add_missing_meta_boxes( $post_type ) {
87
		if ( is_array( $metaboxes = get_transient( 'tabify_detection_' . $post_type ) ) ) {
0 ignored issues
show
Bug introduced by
The function get_transient 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
		if ( is_array( $metaboxes = /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $post_type ) ) ) {
Loading history...
88
			foreach ( $metaboxes as $id => $metabox ) {
89
				if ( ! isset( $wp_meta_boxes[ $post_type ][ $metabox->context ][ $metabox->priority ][ $id ] ) ) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $wp_meta_boxes seems to never exist and therefore isset should always be false.
Loading history...
90
					add_meta_box( $id, $metabox->title, '__return_false', $post_type, $metabox->priority, $metabox->context );
0 ignored issues
show
Bug introduced by
The function add_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

90
					/** @scrutinizer ignore-call */ 
91
     add_meta_box( $id, $metabox->title, '__return_false', $post_type, $metabox->priority, $metabox->context );
Loading history...
91
				}
92
			}
93
		}
94
	}
95
96
	public function unattached_metaboxes( $unattached_metaboxes ) {
97
		$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

97
		$screen = /** @scrutinizer ignore-call */ get_current_screen();
Loading history...
98
99
		if ( get_transient( 'tabify_detection_' . $screen->post_type ) !== false ) {
0 ignored issues
show
Bug introduced by
The function get_transient 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

99
		if ( /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $screen->post_type ) !== false ) {
Loading history...
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 );
0 ignored issues
show
Bug introduced by
The function set_transient 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

115
		/** @scrutinizer ignore-call */ 
116
  set_transient( 'tabify_detection_' . $screen->post_type, $metaboxes, WEEK_IN_SECONDS );
Loading history...
Bug introduced by
The constant WEEK_IN_SECONDS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
}