Completed
Push — master ( 9f3eac...f0c1b5 )
by David
02:49 queued 13s
created

Image_License_Notifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A admin_init() 0 23 2
1
<?php
2
3
namespace Wordlift\Images_Licenses;
4
5
use Wordlift\Wordpress\Page;
6
7
class Image_License_Notifier {
8
9
	/**
10
	 * @var array
11
	 */
12
	private $data;
13
14
	/**
15
	 * @var Page
16
	 */
17
	private $image_license_page;
18
19
	/**
20
	 * Image_License_Notifier constructor.
21
	 *
22
	 * @param array $data
23
	 * @param Page $image_license_page
24
	 */
25
	public function __construct( $data, $image_license_page ) {
26
27
		add_action( 'admin_init', array( $this, 'admin_init', ) );
28
29
		$this->data               = $data;
30
		$this->image_license_page = $image_license_page;
31
32
	}
33
34
	public function admin_init() {
35
36
		$count = count( $this->data );
37
38
		if ( 0 < $count ) {
39
			$that = $this;
40
			add_action( 'admin_notices', function () use ( $count, $that ) {
41
				?>
42
                <div class="notice notice-error">
43
                    <p>
44
						<?php
45
						$image_compliance_link = sprintf( '<a href="%s">', admin_url( 'admin.php?page=' . $that->image_license_page->get_menu_slug() ) )
46
						                         . __( 'License Compliance', 'wordlift' ) . '</a>';
47
						$message               = esc_html__( 'WordLift found %d image(s) that might not comply with their license. Open %s to fix this error.', 'wordlift' );
48
						echo sprintf( $message, $count, $image_compliance_link );
49
						?>
50
                    </p>
51
                </div>
52
				<?php
53
			} );
54
		}
55
56
	}
57
58
}
59