Completed
Push — add/related-posts-customize ( 4a306a...1c5144 )
by
unknown
43:30 queued 35:07
created

WordAds_Admin   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A debug_output() 0 21 4
1
<?php
2
3
/**
4
 * The standard set of admin pages for the user if Jetpack is installed
5
 */
6
class WordAds_Admin {
7
8
	/**
9
	 * @since 4.5.0
10
	 */
11
	function __construct() {
12
		global $wordads;
13
14
		if ( current_user_can( 'manage_options' ) && isset( $_GET['ads_debug'] ) ) {
15
			WordAds_API::update_wordads_status_from_api();
16
			add_action( 'admin_notices', array( $this, 'debug_output' ) );
17
		}
18
	}
19
20
	/**
21
	 * Output the API connection debug
22
	 * @since 4.5.0
23
	 */
24
	function debug_output() {
25
		global $wordads, $wordads_status_response;
26
		$response = $wordads_status_response;
27
		if ( empty( $response ) ) {
28
			$response = 'No response from API :(';
29
		} else {
30
			$response = print_r( $response, 1 );
31
		}
32
33
		$status = $wordads->option( 'wordads_approved' ) ?
34
			'<span style="color:green;">Yes</span>' :
35
			'<span style="color:red;">No</span>';
36
37
		$type = $wordads->option( 'wordads_approved' ) ? 'updated' : 'error';
38
		echo <<<HTML
39
		<div class="notice $type is-dismissible">
40
			<p>Status: $status</p>
41
			<pre>$response</pre>
42
		</div>
43
HTML;
44
	}
45
}
46
47
global $wordads_admin;
48
$wordads_admin = new WordAds_Admin();
49