| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WP Notifications Package |
| 4 |
* Description: ... |
| 5 |
* Plugin URI: https://elementor.com/ |
| 6 |
* Author: Elementor.com |
| 7 |
* Version: 1.0.0 |
| 8 |
* License: GPL-3 |
| 9 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.en.html |
| 10 |
* |
| 11 |
* Text Domain: wp-notifications-package |
| 12 |
*/ |
| 13 |
|
| 14 |
use Elementor\WPNotificationsPackage\V120\Notifications; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; // Exit if accessed directly. |
| 18 |
} |
| 19 |
|
| 20 |
class Plugin_Example { |
| 21 |
|
| 22 |
public Notifications $notifications; |
| 23 |
|
| 24 |
public function __construct() { |
| 25 |
$this->init(); |
| 26 |
} |
| 27 |
|
| 28 |
private function init() { |
| 29 |
require __DIR__ . '/vendor/autoload.php'; |
| 30 |
|
| 31 |
$this->notifications = new Notifications( [ |
| 32 |
'app_name' => 'wp-notifications-package', |
| 33 |
'app_version' => '1.2.0', |
| 34 |
'short_app_name' => 'wppe', |
| 35 |
'app_data' => [ |
| 36 |
'plugin_basename' => plugin_basename( __FILE__ ), |
| 37 |
], |
| 38 |
] ); |
| 39 |
|
| 40 |
add_action( 'admin_notices', [ $this, 'display_notifications' ] ); |
| 41 |
add_action( 'admin_footer', [ $this, 'display_dialog' ] ); |
| 42 |
} |
| 43 |
|
| 44 |
public function display_notifications() { |
| 45 |
$notifications = $this->notifications->get_notifications_by_conditions(); |
| 46 |
|
| 47 |
if ( empty( $notifications ) ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
?> |
| 52 |
<div class="notice notice-info is-dismissible"> |
| 53 |
<h3><?php esc_html_e( 'What\'s new:', 'wp-notifications-package' ); ?></h3> |
| 54 |
<ul> |
| 55 |
<?php foreach ( $notifications as $item ) : ?> |
| 56 |
<li><a href="<?php echo esc_url( $item['link'] ?? '#' ); ?>" target="_blank"><?php echo esc_html( $item['title'] ); ?></a></li> |
| 57 |
<?php endforeach; ?> |
| 58 |
</ul> |
| 59 |
</div> |
| 60 |
<?php |
| 61 |
|
| 62 |
// Example with HTML Dialog modal |
| 63 |
?> |
| 64 |
<div class="notice notice-info is-dismissible"> |
| 65 |
<button class="plugin-example-notifications-dialog-open">Open Notification</button> |
| 66 |
</div> |
| 67 |
<?php |
| 68 |
} |
| 69 |
|
| 70 |
public function display_dialog() { |
| 71 |
$notifications = $this->notifications->get_notifications_by_conditions(); |
| 72 |
|
| 73 |
if ( empty( $notifications ) ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
?> |
| 78 |
<style> |
| 79 |
#plugin-example-notifications-dialog { |
| 80 |
padding: 20px; |
| 81 |
border: 1px solid #ccc; |
| 82 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); |
| 83 |
} |
| 84 |
#plugin-example-notifications-dialog::backdrop { |
| 85 |
background: rgba(0, 0, 0, 0.5); |
| 86 |
} |
| 87 |
</style> |
| 88 |
<dialog id="plugin-example-notifications-dialog"> |
| 89 |
<h3><?php esc_html_e( 'What\'s new:', 'wp-notifications-package' ); ?></h3> |
| 90 |
<ul> |
| 91 |
<?php foreach ( $notifications as $item ) : ?> |
| 92 |
<li><a href="<?php echo esc_url( $item['link'] ?? '#' ); ?>" target="_blank"><?php echo esc_html( $item['title'] ); ?></a></li> |
| 93 |
<?php endforeach; ?> |
| 94 |
</ul> |
| 95 |
<button class="close">Close</button> |
| 96 |
</dialog> |
| 97 |
|
| 98 |
<script> |
| 99 |
document.addEventListener( 'DOMContentLoaded', function() { |
| 100 |
const openDialogBtn = document.querySelector( '.plugin-example-notifications-dialog-open' ); |
| 101 |
const closeDialogBtn = document.querySelector( '#plugin-example-notifications-dialog button.close' ); |
| 102 |
const dialog = document.getElementById( 'plugin-example-notifications-dialog' ); |
| 103 |
|
| 104 |
openDialogBtn.addEventListener( 'click', function() { |
| 105 |
dialog.showModal(); |
| 106 |
} ); |
| 107 |
|
| 108 |
closeDialogBtn.addEventListener( 'click', function() { |
| 109 |
dialog.close(); |
| 110 |
} ); |
| 111 |
} ); |
| 112 |
</script> |
| 113 |
<?php |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
new Plugin_Example(); |
| 118 |
|
| 119 |
|