| 1 |
<?php |
| 2 |
/** |
| 3 |
* Fomo Notifications - List Template |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
defined('ABSPATH') || exit; |
| 9 |
|
| 10 |
$is_pro = king_addons_freemius()->can_use_premium_code(); |
| 11 |
$free_limit = 3; |
| 12 |
|
| 13 |
// Get all notifications |
| 14 |
$paged = isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
| 15 |
$search = isset($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
| 16 |
$status_filter = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : ''; |
| 17 |
$type_filter = isset($_GET['type']) ? sanitize_text_field($_GET['type']) : ''; |
| 18 |
|
| 19 |
$args = [ |
| 20 |
'post_type' => 'kng_fomo_notif', |
| 21 |
'posts_per_page' => 20, |
| 22 |
'paged' => $paged, |
| 23 |
'orderby' => 'date', |
| 24 |
'order' => 'DESC' |
| 25 |
]; |
| 26 |
|
| 27 |
if ($search) { |
| 28 |
$args['s'] = $search; |
| 29 |
} |
| 30 |
|
| 31 |
if ($status_filter) { |
| 32 |
$args['meta_query'][] = [ |
| 33 |
'key' => '_kng_fomo_status', |
| 34 |
'value' => $status_filter |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
if ($type_filter) { |
| 39 |
$args['meta_query'][] = [ |
| 40 |
'key' => '_kng_fomo_type', |
| 41 |
'value' => $type_filter |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
$query = new WP_Query($args); |
| 46 |
$notifications = $query->posts; |
| 47 |
$total = $query->found_posts; |
| 48 |
$total_pages = $query->max_num_pages; |
| 49 |
|
| 50 |
// Count stats |
| 51 |
$published_count = wp_count_posts('kng_fomo_notif')->publish; |
| 52 |
$can_create = $is_pro || $published_count < $free_limit; |
| 53 |
?> |
| 54 |
|
| 55 |
<div class="kng-fomo-admin"> |
| 56 |
|
| 57 |
<!-- Navigation --> |
| 58 |
<nav class="kng-fomo-nav"> |
| 59 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo')); ?>" class="kng-fomo-nav-item"> |
| 60 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="9"></rect><rect x="14" y="3" width="7" height="5"></rect><rect x="14" y="12" width="7" height="9"></rect><rect x="3" y="16" width="7" height="5"></rect></svg> |
| 61 |
<?php esc_html_e('Dashboard', 'king-addons'); ?> |
| 62 |
</a> |
| 63 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=list')); ?>" class="kng-fomo-nav-item is-active"> |
| 64 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line><line x1="8" y1="18" x2="21" y2="18"></line><line x1="3" y1="6" x2="3.01" y2="6"></line><line x1="3" y1="12" x2="3.01" y2="12"></line><line x1="3" y1="18" x2="3.01" y2="18"></line></svg> |
| 65 |
<?php esc_html_e('Notifications', 'king-addons'); ?> |
| 66 |
</a> |
| 67 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=wizard')); ?>" class="kng-fomo-nav-item"> |
| 68 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg> |
| 69 |
<?php esc_html_e('Add New', 'king-addons'); ?> |
| 70 |
</a> |
| 71 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=analytics')); ?>" class="kng-fomo-nav-item"> |
| 72 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="20" x2="18" y2="10"></line><line x1="12" y1="20" x2="12" y2="4"></line><line x1="6" y1="20" x2="6" y2="14"></line></svg> |
| 73 |
<?php esc_html_e('Analytics', 'king-addons'); ?> |
| 74 |
</a> |
| 75 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=settings')); ?>" class="kng-fomo-nav-item"> |
| 76 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg> |
| 77 |
<?php esc_html_e('Settings', 'king-addons'); ?> |
| 78 |
</a> |
| 79 |
</nav> |
| 80 |
|
| 81 |
<!-- Page Header --> |
| 82 |
<div class="kng-fomo-section"> |
| 83 |
<div class="kng-fomo-section-header"> |
| 84 |
<div> |
| 85 |
<h1 class="kng-fomo-section-title"><?php esc_html_e('All Notifications', 'king-addons'); ?></h1> |
| 86 |
<p class="kng-fomo-section-subtitle"> |
| 87 |
<?php |
| 88 |
if (!$is_pro) { |
| 89 |
printf( |
| 90 |
/* translators: %1$d: current count, %2$d: max limit */ |
| 91 |
esc_html__('%1$d of %2$d notifications used (Free)', 'king-addons'), |
| 92 |
$published_count, |
| 93 |
$free_limit |
| 94 |
); |
| 95 |
} else { |
| 96 |
printf( |
| 97 |
/* translators: %d: total count */ |
| 98 |
esc_html__('%d notifications', 'king-addons'), |
| 99 |
$total |
| 100 |
); |
| 101 |
} |
| 102 |
?> |
| 103 |
</p> |
| 104 |
</div> |
| 105 |
<?php if ($can_create): ?> |
| 106 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=wizard')); ?>" class="kng-fomo-btn kng-fomo-btn--primary"> |
| 107 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg> |
| 108 |
<?php esc_html_e('Create Notification', 'king-addons'); ?> |
| 109 |
</a> |
| 110 |
<?php else: ?> |
| 111 |
<a href="<?php echo esc_url(king_addons_freemius()->get_upgrade_url()); ?>" class="kng-fomo-btn kng-fomo-btn--primary"> |
| 112 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg> |
| 113 |
<?php esc_html_e('Upgrade for More', 'king-addons'); ?> |
| 114 |
</a> |
| 115 |
<?php endif; ?> |
| 116 |
</div> |
| 117 |
</div> |
| 118 |
|
| 119 |
<!-- Filters --> |
| 120 |
<div class="kng-fomo-card" style="margin-bottom: 24px; padding: 16px 24px;"> |
| 121 |
<form method="get" style="display: flex; gap: 12px; align-items: center; flex-wrap: wrap;"> |
| 122 |
<input type="hidden" name="page" value="king-addons-fomo"> |
| 123 |
<input type="hidden" name="view" value="list"> |
| 124 |
|
| 125 |
<input type="text" name="s" class="kng-fomo-input kng-fomo-input--sm" placeholder="<?php esc_attr_e('Search notifications...', 'king-addons'); ?>" value="<?php echo esc_attr($search); ?>" style="width: 250px;"> |
| 126 |
|
| 127 |
<select name="status" class="kng-fomo-select kng-fomo-input--sm" style="width: auto;"> |
| 128 |
<option value=""><?php esc_html_e('All Statuses', 'king-addons'); ?></option> |
| 129 |
<option value="enabled" <?php selected($status_filter, 'enabled'); ?>><?php esc_html_e('Active', 'king-addons'); ?></option> |
| 130 |
<option value="disabled" <?php selected($status_filter, 'disabled'); ?>><?php esc_html_e('Inactive', 'king-addons'); ?></option> |
| 131 |
</select> |
| 132 |
|
| 133 |
<select name="type" class="kng-fomo-select kng-fomo-input--sm" style="width: auto;"> |
| 134 |
<option value=""><?php esc_html_e('All Types', 'king-addons'); ?></option> |
| 135 |
<option value="notification_bar" <?php selected($type_filter, 'notification_bar'); ?>><?php esc_html_e('Notification Bar', 'king-addons'); ?></option> |
| 136 |
<option value="woocommerce_sales" <?php selected($type_filter, 'woocommerce_sales'); ?>><?php esc_html_e('WooCommerce Sales', 'king-addons'); ?></option> |
| 137 |
<option value="wordpress_comments" <?php selected($type_filter, 'wordpress_comments'); ?>><?php esc_html_e('WordPress Comments', 'king-addons'); ?></option> |
| 138 |
<option value="wporg_downloads" <?php selected($type_filter, 'wporg_downloads'); ?>><?php esc_html_e('WordPress.org Downloads', 'king-addons'); ?></option> |
| 139 |
</select> |
| 140 |
|
| 141 |
<button type="submit" class="kng-fomo-btn kng-fomo-btn--secondary kng-fomo-btn--sm"> |
| 142 |
<?php esc_html_e('Filter', 'king-addons'); ?> |
| 143 |
</button> |
| 144 |
|
| 145 |
<?php if ($search || $status_filter || $type_filter): ?> |
| 146 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=list')); ?>" class="kng-fomo-btn kng-fomo-btn--ghost kng-fomo-btn--sm"> |
| 147 |
<?php esc_html_e('Clear', 'king-addons'); ?> |
| 148 |
</a> |
| 149 |
<?php endif; ?> |
| 150 |
</form> |
| 151 |
</div> |
| 152 |
|
| 153 |
<?php if (!empty($notifications)): ?> |
| 154 |
<!-- Table --> |
| 155 |
<div class="kng-fomo-table-wrap"> |
| 156 |
<table class="kng-fomo-table"> |
| 157 |
<thead> |
| 158 |
<tr> |
| 159 |
<th style="width: 40px;"> |
| 160 |
<input type="checkbox" id="kng-fomo-select-all"> |
| 161 |
</th> |
| 162 |
<th><?php esc_html_e('Notification', 'king-addons'); ?></th> |
| 163 |
<th><?php esc_html_e('Type', 'king-addons'); ?></th> |
| 164 |
<th><?php esc_html_e('Views', 'king-addons'); ?></th> |
| 165 |
<th><?php esc_html_e('Clicks', 'king-addons'); ?></th> |
| 166 |
<th><?php esc_html_e('CTR', 'king-addons'); ?></th> |
| 167 |
<th><?php esc_html_e('Status', 'king-addons'); ?></th> |
| 168 |
<th><?php esc_html_e('Created', 'king-addons'); ?></th> |
| 169 |
<th></th> |
| 170 |
</tr> |
| 171 |
</thead> |
| 172 |
<tbody> |
| 173 |
<?php foreach ($notifications as $notification): |
| 174 |
$type = get_post_meta($notification->ID, '_kng_fomo_type', true); |
| 175 |
$status = get_post_meta($notification->ID, '_kng_fomo_status', true) ?: 'disabled'; |
| 176 |
$views = (int) get_post_meta($notification->ID, '_kng_fomo_views', true); |
| 177 |
$clicks = (int) get_post_meta($notification->ID, '_kng_fomo_clicks', true); |
| 178 |
$ctr = $views > 0 ? round(($clicks / $views) * 100, 1) : 0; |
| 179 |
?> |
| 180 |
<tr data-id="<?php echo esc_attr($notification->ID); ?>"> |
| 181 |
<td> |
| 182 |
<input type="checkbox" class="kng-fomo-select-item" value="<?php echo esc_attr($notification->ID); ?>"> |
| 183 |
</td> |
| 184 |
<td> |
| 185 |
<div class="kng-fomo-table-title"> |
| 186 |
<span class="kng-fomo-table-preview"> |
| 187 |
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"></path><path d="M13.73 21a2 2 0 0 1-3.46 0"></path></svg> |
| 188 |
</span> |
| 189 |
<div> |
| 190 |
<strong><?php echo esc_html($notification->post_title); ?></strong> |
| 191 |
</div> |
| 192 |
</div> |
| 193 |
</td> |
| 194 |
<td><?php echo esc_html(ucfirst(str_replace('_', ' ', $type))); ?></td> |
| 195 |
<td><?php echo esc_html(number_format_i18n($views)); ?></td> |
| 196 |
<td><?php echo esc_html(number_format_i18n($clicks)); ?></td> |
| 197 |
<td> |
| 198 |
<span style="color: <?php echo $ctr >= 5 ? 'var(--kng-fomo-success)' : ($ctr >= 2 ? 'var(--kng-fomo-warning)' : 'var(--kng-fomo-text-secondary)'); ?>; font-weight: 600;"> |
| 199 |
<?php echo esc_html($ctr . '%'); ?> |
| 200 |
</span> |
| 201 |
</td> |
| 202 |
<td> |
| 203 |
<label class="kng-fomo-toggle"> |
| 204 |
<input type="checkbox" data-id="<?php echo esc_attr($notification->ID); ?>" <?php checked($status, 'enabled'); ?>> |
| 205 |
<span class="kng-fomo-toggle-slider"></span> |
| 206 |
</label> |
| 207 |
</td> |
| 208 |
<td style="color: var(--kng-fomo-text-secondary);"> |
| 209 |
<?php echo esc_html(human_time_diff(strtotime($notification->post_date), current_time('timestamp')) . ' ' . __('ago', 'king-addons')); ?> |
| 210 |
</td> |
| 211 |
<td> |
| 212 |
<div class="kng-fomo-table-actions"> |
| 213 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=wizard&edit=' . $notification->ID)); ?>" class="kng-fomo-table-action kng-fomo-edit" title="<?php esc_attr_e('Edit', 'king-addons'); ?>"> |
| 214 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg> |
| 215 |
</a> |
| 216 |
<button type="button" class="kng-fomo-table-action kng-fomo-duplicate" title="<?php esc_attr_e('Duplicate', 'king-addons'); ?>"> |
| 217 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg> |
| 218 |
</button> |
| 219 |
<button type="button" class="kng-fomo-table-action kng-fomo-table-action--danger kng-fomo-delete" title="<?php esc_attr_e('Delete', 'king-addons'); ?>"> |
| 220 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg> |
| 221 |
</button> |
| 222 |
</div> |
| 223 |
</td> |
| 224 |
</tr> |
| 225 |
<?php endforeach; ?> |
| 226 |
</tbody> |
| 227 |
</table> |
| 228 |
</div> |
| 229 |
|
| 230 |
<!-- Pagination --> |
| 231 |
<?php if ($total_pages > 1): ?> |
| 232 |
<div style="margin-top: 24px; display: flex; justify-content: center; gap: 8px;"> |
| 233 |
<?php |
| 234 |
$base_url = admin_url('admin.php?page=king-addons-fomo&view=list'); |
| 235 |
if ($search) $base_url .= '&s=' . urlencode($search); |
| 236 |
if ($status_filter) $base_url .= '&status=' . urlencode($status_filter); |
| 237 |
if ($type_filter) $base_url .= '&type=' . urlencode($type_filter); |
| 238 |
|
| 239 |
for ($i = 1; $i <= $total_pages; $i++): |
| 240 |
?> |
| 241 |
<a href="<?php echo esc_url($base_url . '&paged=' . $i); ?>" class="kng-fomo-btn kng-fomo-btn--sm <?php echo $paged === $i ? 'kng-fomo-btn--primary' : 'kng-fomo-btn--ghost'; ?>"> |
| 242 |
<?php echo esc_html($i); ?> |
| 243 |
</a> |
| 244 |
<?php endfor; ?> |
| 245 |
</div> |
| 246 |
<?php endif; ?> |
| 247 |
|
| 248 |
<?php else: ?> |
| 249 |
<!-- Empty State --> |
| 250 |
<div class="kng-fomo-empty"> |
| 251 |
<div class="kng-fomo-empty-icon"> |
| 252 |
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"></path><path d="M13.73 21a2 2 0 0 1-3.46 0"></path></svg> |
| 253 |
</div> |
| 254 |
<h3 class="kng-fomo-empty-title"> |
| 255 |
<?php echo $search || $status_filter || $type_filter ? esc_html__('No notifications found', 'king-addons') : esc_html__('No notifications yet', 'king-addons'); ?> |
| 256 |
</h3> |
| 257 |
<p class="kng-fomo-empty-desc"> |
| 258 |
<?php echo $search || $status_filter || $type_filter ? esc_html__('Try adjusting your filters or search terms.', 'king-addons') : esc_html__('Create your first notification to start building social proof and urgency.', 'king-addons'); ?> |
| 259 |
</p> |
| 260 |
<?php if (!$search && !$status_filter && !$type_filter && $can_create): ?> |
| 261 |
<a href="<?php echo esc_url(admin_url('admin.php?page=king-addons-fomo&view=wizard')); ?>" class="kng-fomo-btn kng-fomo-btn--primary"> |
| 262 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg> |
| 263 |
<?php esc_html_e('Create Your First Notification', 'king-addons'); ?> |
| 264 |
</a> |
| 265 |
<?php endif; ?> |
| 266 |
</div> |
| 267 |
<?php endif; ?> |
| 268 |
|
| 269 |
</div> |
| 270 |
|
| 271 |
<script> |
| 272 |
// Bulk selection |
| 273 |
document.getElementById('kng-fomo-select-all')?.addEventListener('change', function() { |
| 274 |
document.querySelectorAll('.kng-fomo-select-item').forEach(cb => { |
| 275 |
cb.checked = this.checked; |
| 276 |
}); |
| 277 |
}); |
| 278 |
</script> |
| 279 |
|