Completed
Push — develop ( 1d4633...83eb6a )
by David
02:35 queued 10s
created

Image_License_Notifier::admin_init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
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