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
Push — master ( 6b3106...cb8a62 )
by Marko
01:46
created

head_action_begin()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 5
eloc 7
c 5
b 0
f 0
nc 3
nop 1
dl 0
loc 10
rs 9.6111
1
<?php
2
3
class Tabify_Edit_Screen_Feature_Detection {
4
	/**
5
	 * Set hooks
6
	 *
7
	 * @since 0.9.0
8
	 */
9
	public function __construct() {
10
		add_action( 'current_screen', array( $this, 'head_action_begin_settings_page' ) );
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

10
		/** @scrutinizer ignore-call */ 
11
  add_action( 'current_screen', array( $this, 'head_action_begin_settings_page' ) );
Loading history...
11
		add_action( 'current_screen', array( $this, 'head_action_begin_edit_page' ) );
12
13
		// Hook for requesting missing hooks
14
		add_action( 'tabify_add_meta_boxes', array( $this, 'add_missing_meta_boxes' ) );
15
16
		// Checking & storing unattached meta boxes on the edit page
17
		add_action( 'tabify_unattached_metaboxes', array( $this, 'unattached_metaboxes' ) );
18
	}
19
20
	/**
21
	 * Checks if script for edit page need to be enqueued
22
	 *
23
	 * @since 1.0.0
24
	 */
25
	public function head_action_begin_settings_page( $screen ) {
26
		if ( 'settings_page_tabify-edit-screen' == $screen->base ) {
27
			$this->enqueue_script();
28
		}
29
	}
30
31
	/**
32
	 * Actions to return JSON output on post type new/edit screen
33
	 *
34
	 * @since 1.0.0
35
	 */
36
	public function head_action_begin_edit_page( $screen ) {
37
		if ( ( 'post' == $screen->base || 'media' == $screen->base ) && isset( $_GET['test_metaboxes'] ) ) {
38
			ob_end_clean(); // For when warnings are displayed
39
			ob_start();
40
41
			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

41
			/** @scrutinizer ignore-call */ 
42
   add_filter( 'tabify_tab_posttype_show', '__return_true', 1000 );
Loading history...
42
			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

42
			/** @scrutinizer ignore-call */ 
43
   add_action( 'admin_head', array( $this, 'head_action' ), 110 );
Loading history...
43
		}
44
	}
45
46
	/**
47
	 * Enqueue script to load detected meta boxes and display them in the settings page
48
	 *
49
	 * @since 0.9.0
50
	 */
51
	private function enqueue_script() {
52
		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

52
		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

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

53
		/** @scrutinizer ignore-call */ 
54
  wp_enqueue_script( 'tabify-edit-screen-detection' );
Loading history...
54
55
		$posttype_links = array();
56
57
		$args = array(
58
			'show_ui' => true
59
		);
60
		$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

60
		$posttypes_objects = /** @scrutinizer ignore-call */ get_post_types( $args, 'objects' );
Loading history...
61
		$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

61
		$posttypes_objects = /** @scrutinizer ignore-call */ apply_filters( 'tabify_posttypes', $posttypes_objects );
Loading history...
62
63
		foreach ( $posttypes_objects as $posttype ) {
64
			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

64
			if ( /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $posttype->name ) !== false ) {
Loading history...
65
				continue;
66
			}
67
68
			$args = array(
69
				'post_type'      => $posttype->name,
70
				'orderby'        => 'rand',
71
				'posts_per_page' => '1',
72
				'post_status'    => 'any'
73
			);
74
			$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

74
			$post = /** @scrutinizer ignore-call */ get_posts( $args );
Loading history...
75
76
			if ( ! empty( $post ) ) {
77
				$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

77
				$url = /** @scrutinizer ignore-call */ get_edit_post_link( $post[0], 'raw' );
Loading history...
78
				$url = add_query_arg( 'test_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

78
				$url = /** @scrutinizer ignore-call */ add_query_arg( 'test_metaboxes', 'true', $url );
Loading history...
79
				$posttype_links[ $posttype->name ] = $url;
80
			}
81
			else {
82
				$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

82
				$url = /** @scrutinizer ignore-call */ admin_url('post-new.php');
Loading history...
83
				$url = add_query_arg( 'post_type', $posttype->name, $url );
84
				$url = add_query_arg( 'test_metaboxes', 'true', $url );
85
				$posttype_links[ $posttype->name ] = $url;
86
			}
87
		}
88
89
		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

89
		/** @scrutinizer ignore-call */ 
90
  wp_localize_script( 'tabify-edit-screen-detection', 'tabify_detection', array(
Loading history...
90
			'posttype_links' => $posttype_links
91
		) );
92
	}
93
94
	/**
95
	 * Load the JSON data for the settings page
96
	 *
97
	 * @since 0.9.0
98
	 */
99
	public function head_action() {
100
		global $wp_meta_boxes;
101
102
		$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

102
		$screen = /** @scrutinizer ignore-call */ get_current_screen();
Loading history...
103
104
		ob_end_clean();
105
106
		echo wp_json_encode( get_transient( 'tabify_detection_' . $screen->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

106
		echo wp_json_encode( /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $screen->post_type ) );
Loading history...
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

106
		echo /** @scrutinizer ignore-call */ wp_json_encode( get_transient( 'tabify_detection_' . $screen->post_type ) );
Loading history...
107
108
		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...
109
	}
110
111
	/**
112
	 * Add missing meta boxes as meta boxes on the edit screen so it doesn't disappear on first load
113
	 *
114
	 * @since 0.9.0
115
	 */
116
	public function add_missing_meta_boxes( $post_type ) {
117
		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

117
		if ( is_array( $metaboxes = /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $post_type ) ) ) {
Loading history...
118
			foreach ( $metaboxes as $id => $metabox ) {
119
				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...
120
					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

120
					/** @scrutinizer ignore-call */ 
121
     add_meta_box( $id, $metabox->title, '__return_false', $post_type, $metabox->priority, $metabox->context );
Loading history...
121
				}
122
			}
123
		}
124
	}
125
126
	/**
127
	 * Check and save missing 
128
	 *
129
	 * @since 0.9.0
130
	 */
131
	public function unattached_metaboxes( $unattached_metaboxes ) {
132
		$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

132
		$screen = /** @scrutinizer ignore-call */ get_current_screen();
Loading history...
133
		$previous_metaboxes = get_transient( 'tabify_detection_' . $screen->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

133
		$previous_metaboxes = /** @scrutinizer ignore-call */ get_transient( 'tabify_detection_' . $screen->post_type );
Loading history...
134
135
		$metaboxes = array();
136
137
		if ( $unattached_metaboxes ) {
138
			$metaboxes = $this->get_metaboxes( $screen->post_type );
139
140
			foreach ( $metaboxes as $metabox_id => $metabox ) {
141
				if ( ! isset( $unattached_metaboxes[ $metabox_id ] )  ) {
142
					unset( $metaboxes[ $metabox_id ] );
143
				}
144
			}
145
		}
146
147
		if ($metaboxes != $previous_metaboxes) {
148
			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

148
			/** @scrutinizer ignore-call */ 
149
   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...
149
		}
150
	}
151
152
	/**
153
	 * 
154
	 *
155
	 * @since 0.9.0
156
	 */
157
	private function get_metaboxes( $post_type ) {
158
		global $wp_meta_boxes;
159
160
		$metaboxes = array();
161
162
		foreach ( $wp_meta_boxes[ $post_type ] as $context => $priorities ) {
163
			foreach ( $priorities as $priority => $_metaboxes ) {
164
				foreach ( $_metaboxes as $metabox ) {
165
					// Metabox has been removed
166
					if ( ! isset( $metabox['id'] ) ) {
167
						continue;
168
					}
169
170
					$metaboxes[ $metabox['id'] ] = (object) array(
171
						'title'    => $metabox['title'],
172
						'priority' => $priority,
173
						'context'  => $context
174
					);
175
				}
176
			}
177
		}
178
179
		return $metaboxes;
180
	}
181
182
}