| 1 |
<?php |
| 2 |
|
| 3 |
namespace QuadLayers\QuadMenu; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
die( '-1' ); |
| 7 |
} |
| 8 |
|
| 9 |
use QuadLayers\QuadMenu\Plugin; |
| 10 |
/** |
| 11 |
* Admin Class ex QuadMenu_Admin |
| 12 |
*/ |
| 13 |
class Admin { |
| 14 |
|
| 15 |
private static $instance; |
| 16 |
|
| 17 |
public function __construct() { |
| 18 |
|
| 19 |
add_action( 'admin_enqueue_scripts', array( $this, 'register' ), -1 ); |
| 20 |
|
| 21 |
add_action( 'admin_notices', array( $this, 'notices' ) ); |
| 22 |
|
| 23 |
add_action( 'admin_footer', array( $this, 'icons' ) ); |
| 24 |
} |
| 25 |
|
| 26 |
public function register() { |
| 27 |
|
| 28 |
$admin = include QUADMENU_PLUGIN_DIR . 'build/backend/index.asset.php'; |
| 29 |
|
| 30 |
wp_register_style( 'quadmenu-modal', QUADMENU_PLUGIN_URL . 'assets/backend/css/modal' . Plugin::isMin() . '.css', array(), QUADMENU_PLUGIN_VERSION, 'all' ); |
| 31 |
|
| 32 |
wp_register_style( 'quadmenu-admin', QUADMENU_PLUGIN_URL . 'build/backend/style.css', array( 'quadmenu-modal', Plugin::instance()->selected_icons()->ID ), QUADMENU_PLUGIN_VERSION, 'all' ); |
| 33 |
|
| 34 |
wp_register_script( 'quadmenu-admin', QUADMENU_PLUGIN_URL . 'build/backend/index.js', $admin['dependencies'], $admin['version'], false ); |
| 35 |
} |
| 36 |
|
| 37 |
public function icons() { |
| 38 |
|
| 39 |
global $pagenow, $quadmenu_active_locations; |
| 40 |
|
| 41 |
if ( $pagenow != 'nav-menus.php' ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
if ( ! is_array( $quadmenu_active_locations ) ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! count( $quadmenu_active_locations ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
?> |
| 53 |
<script> |
| 54 |
jQuery(document).ready(function () { |
| 55 |
var $list = jQuery('.menu-theme-locations'), |
| 56 |
locations = <?php echo json_encode( array_keys( $quadmenu_active_locations ) ); ?>, |
| 57 |
icon = '<img src="<?php echo esc_url( QUADMENU_PLUGIN_URL . 'assets/backend/img/icond.png' ); ?>" style="width: 1em; height: auto; margin: 1px 0 -1px 0; "/>'; |
| 58 |
|
| 59 |
jQuery.each(locations, function (index, item) { |
| 60 |
$list.find('input#locations-' + item).after(icon); |
| 61 |
}); |
| 62 |
}); |
| 63 |
</script> |
| 64 |
<?php |
| 65 |
} |
| 66 |
|
| 67 |
public function notices() { |
| 68 |
if ( $notices = get_option( 'quadmenu_admin_notices', false ) ) { |
| 69 |
foreach ( $notices as $notice ) { |
| 70 |
if ( empty( $notice['class'] ) || empty( $notice['notice'] ) ) { |
| 71 |
continue; |
| 72 |
} |
| 73 |
?> |
| 74 |
<div class="<?php echo esc_attr( $notice['class'] ); ?>"> |
| 75 |
<p><?php esc_html_e( $notice['notice'] ); ?></p> |
| 76 |
</div> |
| 77 |
<?php |
| 78 |
} |
| 79 |
delete_option( 'quadmenu_admin_notices' ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
static function add_notification( $class = 'updated', $notice = false ) { |
| 84 |
|
| 85 |
if ( ! $notice ) { |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
$notices = get_option( 'quadmenu_admin_notices', array() ); |
| 90 |
|
| 91 |
$notices[] = array( |
| 92 |
'class' => $class, |
| 93 |
'notice' => $notice, |
| 94 |
); |
| 95 |
|
| 96 |
update_option( 'quadmenu_admin_notices', $notices ); |
| 97 |
} |
| 98 |
|
| 99 |
public static function instance() { |
| 100 |
if ( ! isset( self::$instance ) ) { |
| 101 |
self::$instance = new self(); |
| 102 |
} |
| 103 |
return self::$instance; |
| 104 |
} |
| 105 |
} |
| 106 |
|