| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codelight\GDPR\Admin; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 |
|
| 7 |
class AdminNotice |
| 8 |
{ |
| 9 |
protected $template; |
| 10 |
|
| 11 |
protected $data; |
| 12 |
|
| 13 |
/** |
| 14 |
* AdminNotice constructor. |
| 15 |
*/ |
| 16 |
public function __construct() |
| 17 |
{ |
| 18 |
if (did_action('admin_notices')) { |
| 19 |
trigger_error('AdminNotice class called incorrectly - admin_notices action has already ran!', E_USER_ERROR); |
| 20 |
} |
| 21 |
|
| 22 |
add_action('admin_notices', [$this, 'render'], 9999); |
| 23 |
} |
| 24 |
|
| 25 |
public function add($template, $data = []) |
| 26 |
{ |
| 27 |
$this->template = $template; |
| 28 |
$this->data = $data; |
| 29 |
} |
| 30 |
|
| 31 |
public function render() |
| 32 |
{ |
| 33 |
if (!$this->template) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
echo gdpr('view')->render('admin/notices/header'); |
| 38 |
echo gdpr('view')->render($this->template, $this->data); |
| 39 |
echo gdpr('view')->render('admin/notices/footer'); |
| 40 |
} |
| 41 |
} |
| 42 |
|