| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
die('-1'); |
| 4 |
} |
| 5 |
|
| 6 |
class QuadMenu_Admin { |
| 7 |
|
| 8 |
public function __construct() { |
| 9 |
|
| 10 |
add_action('wp_ajax_quadmenu_dismiss_notice', array($this, 'ajax_dismiss_notice')); |
| 11 |
|
| 12 |
add_action('admin_enqueue_scripts', array($this, 'register'), -1); |
| 13 |
|
| 14 |
add_action('admin_notices', array($this, 'notices')); |
| 15 |
|
| 16 |
add_action('admin_notices', array($this, 'add_rating_notice')); |
| 17 |
|
| 18 |
add_action('admin_footer', array($this, 'icons')); |
| 19 |
|
| 20 |
add_filter('plugin_action_links_' . QUADMENU_PLUGIN_BASENAME, array($this, 'add_action_links')); |
| 21 |
} |
| 22 |
|
| 23 |
function add_action_links($links) { |
| 24 |
|
| 25 |
$links[] = '<a target="_blank" href="' . QUADMENU_DEMO_URL . '">' . esc_html__('Premium', 'quadmenu') . '</a>'; |
| 26 |
|
| 27 |
$links[] = '<a href="' . admin_url('admin.php?page=' . QUADMENU_PANEL) . '">' . esc_html__('Settings', 'quadmenu') . '</a>'; |
| 28 |
|
| 29 |
return $links; |
| 30 |
} |
| 31 |
|
| 32 |
public function register() { |
| 33 |
|
| 34 |
wp_register_style('quadmenu-modal', QUADMENU_PLUGIN_URL . 'assets/backend/css/modal' . QuadMenu::isMin() . '.css', array(), QUADMENU_PLUGIN_VERSION, 'all'); |
| 35 |
|
| 36 |
wp_register_style('quadmenu-admin', QUADMENU_PLUGIN_URL . 'assets/backend/css/quadmenu-admin' . QuadMenu::isMin() . '.css', array('quadmenu-modal', _QuadMenu()->selected_icons()->ID), QUADMENU_PLUGIN_VERSION, 'all'); |
| 37 |
|
| 38 |
wp_register_script('quadmenu-admin', QUADMENU_PLUGIN_URL . 'assets/backend/js/quadmenu-admin' . QuadMenu::isMin() . '.js', array('jquery', 'jquery-ui-sortable'), QUADMENU_PLUGIN_VERSION, false); |
| 39 |
} |
| 40 |
|
| 41 |
public function icons() { |
| 42 |
|
| 43 |
global $pagenow, $quadmenu_active_locations; |
| 44 |
|
| 45 |
if ($pagenow != 'nav-menus.php') |
| 46 |
return; |
| 47 |
|
| 48 |
if (!is_array($quadmenu_active_locations)) |
| 49 |
return; |
| 50 |
|
| 51 |
if (!count($quadmenu_active_locations)) |
| 52 |
return; |
| 53 |
?> |
| 54 |
<script> |
| 55 |
jQuery(document).ready(function () { |
| 56 |
var $list = jQuery('.menu-theme-locations'), |
| 57 |
locations = <?php echo json_encode(array_keys($quadmenu_active_locations)); ?>, |
| 58 |
icon = '<img src="<?php echo esc_url(QUADMENU_PLUGIN_URL . 'assets/backend/images/icond.png'); ?>" style="width: 1em; height: auto; margin: 1px 0 -1px 0; "/>'; |
| 59 |
|
| 60 |
jQuery.each(locations, function (index, item) { |
| 61 |
$list.find('input#locations-' + item).after(icon); |
| 62 |
}); |
| 63 |
|
| 64 |
}); |
| 65 |
</script> |
| 66 |
<?php |
| 67 |
} |
| 68 |
|
| 69 |
public function notices() { |
| 70 |
|
| 71 |
if ($notices = get_option('quadmenu_admin_notices', false)) { |
| 72 |
foreach ($notices as $notice) { |
| 73 |
|
| 74 |
if (empty($notice['class']) || empty($notice['notice'])) |
| 75 |
continue; |
| 76 |
?> |
| 77 |
<div class="<?php echo esc_attr($notice['class']); ?>"> |
| 78 |
<p><?php esc_html_e($notice['notice']); ?></p> |
| 79 |
</div> |
| 80 |
<?php |
| 81 |
} |
| 82 |
delete_option('quadmenu_admin_notices'); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
static function add_notification($class = 'updated', $notice = false) { |
| 87 |
|
| 88 |
if (!$notice) |
| 89 |
return; |
| 90 |
|
| 91 |
$notices = get_option('quadmenu_admin_notices', array()); |
| 92 |
|
| 93 |
$notices[] = array( |
| 94 |
'class' => $class, |
| 95 |
'notice' => $notice, |
| 96 |
); |
| 97 |
|
| 98 |
update_option('quadmenu_admin_notices', $notices); |
| 99 |
} |
| 100 |
|
| 101 |
function ajax_dismiss_notice() { |
| 102 |
|
| 103 |
if ($notice_id = ( isset($_POST['notice_id']) ) ? sanitize_key($_POST['notice_id']) : '') { |
| 104 |
|
| 105 |
update_user_meta(get_current_user_id(), $notice_id, true); |
| 106 |
|
| 107 |
wp_send_json($notice_id); |
| 108 |
} |
| 109 |
|
| 110 |
wp_die(); |
| 111 |
} |
| 112 |
|
| 113 |
function add_rating_notice() { |
| 114 |
|
| 115 |
if (!get_transient('_quadmenu_first_rating') && !get_user_meta(get_current_user_id(), 'quadmenu-user-rating', true)) { |
| 116 |
?> |
| 117 |
<div id="quadmenu-admin-rating" class="quadmenu-notice notice is-dismissible" data-notice_id="quadmenu-user-rating"> |
| 118 |
<div class="notice-container" style="padding-top: 10px; padding-bottom: 10px; display: flex; justify-content: left; align-items: center;"> |
| 119 |
<div class="notice-image"> |
| 120 |
<img style="border-radius:50%;max-width: 90px;" src="<?php echo QUADMENU_PLUGIN_URL; ?>assets/backend/images/logo.jpg" alt="<?php echo esc_html(QUADMENU_PLUGIN_NAME); ?>>"> |
| 121 |
</div> |
| 122 |
<div class="notice-content" style="margin-left: 15px;"> |
| 123 |
<p> |
| 124 |
<?php printf(esc_html__('Hello! Thank you for choosing the %s plugin!', 'quadmenu'), QUADMENU_PLUGIN_NAME); ?> |
| 125 |
<br/> |
| 126 |
<?php esc_html_e('Could you please give it a 5-star rating on WordPress? We know its a big favor, but we\'ve worked very much and very hard to release this great product and this will boost our motivation and help us promote and continue to improving this product.', 'quadmenu'); ?> |
| 127 |
</p> |
| 128 |
<a href="<?php echo esc_url(QUADMENU_REVIEW_URL); ?>" class="button-primary" target="_blank"> |
| 129 |
<?php esc_html_e('Yes, of course!', 'quadmenu'); ?> |
| 130 |
</a> |
| 131 |
<a href="<?php echo esc_url(QUADMENU_SUPPORT_URL); ?>" class="button-secondary" target="_blank"> |
| 132 |
<?php esc_html_e('Report a bug', 'quadmenu'); ?> |
| 133 |
</a> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<script> |
| 138 |
(function ($) { |
| 139 |
$('.quadmenu-notice').on('click', '.notice-dismiss', function (e) { |
| 140 |
e.preventDefault(); |
| 141 |
|
| 142 |
var notice_id = $(e.delegateTarget).data('notice_id'); |
| 143 |
|
| 144 |
$.ajax({ |
| 145 |
type: 'POST', |
| 146 |
url: ajaxurl, |
| 147 |
data: { |
| 148 |
notice_id: notice_id, |
| 149 |
action: 'quadmenu_dismiss_notice', |
| 150 |
}, |
| 151 |
success: function (response) { |
| 152 |
console.log(response); |
| 153 |
}, |
| 154 |
}); |
| 155 |
}); |
| 156 |
})(jQuery); |
| 157 |
</script> |
| 158 |
<?php |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
new QuadMenu_Admin(); |
| 165 |
|