-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmenu-icons.php
272 lines (232 loc) · 6.84 KB
/
menu-icons.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/**
* Menu Icons
*
* @package Menu_Icons
* @version 0.10.2
* @author Dzikri Aziz <[email protected]>
*
*
* Plugin name: Menu Icons
* Plugin URI: https://github.com/Codeinwp/wp-menu-icons
* Description: Spice up your navigation menus with pretty icons, easily.
* Version: 0.13.16
* Author: ThemeIsle
* Author URI: https://themeisle.com
* License: GPLv2
* Text Domain: menu-icons
* Domain Path: /languages
* WordPress Available: yes
* Requires License: no
*/
/**
* Main plugin class
*/
final class Menu_Icons {
const DISMISS_NOTICE = 'menu-icons-dismiss-notice';
const VERSION = '0.13.16';
/**
* Holds plugin data
*
* @access protected
* @since 0.1.0
* @var array
*/
protected static $data;
/**
* Get plugin data
*
* @since 0.1.0
* @since 0.9.0 Return NULL if $name is not set in $data.
* @param string $name
*
* @return mixed
*/
public static function get( $name = null ) {
if ( is_null( $name ) ) {
return self::$data;
}
if ( isset( self::$data[ $name ] ) ) {
return self::$data[ $name ];
}
return null;
}
/**
* Load plugin
*
* 1. Load translation
* 2. Set plugin data (directory and URL paths)
* 3. Attach plugin initialization at icon_picker_init hook
*
* @since 0.1.0
* @wp_hook action plugins_loaded
* @link http://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
*/
public static function _load() {
load_plugin_textdomain( 'menu-icons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
self::$data = array(
'dir' => plugin_dir_path( __FILE__ ),
'url' => plugin_dir_url( __FILE__ ),
'types' => array(),
);
Icon_Picker::instance();
require_once self::$data['dir'] . 'includes/library/compat.php';
require_once self::$data['dir'] . 'includes/library/functions.php';
require_once self::$data['dir'] . 'includes/meta.php';
Menu_Icons_Meta::init();
// Font awesome backward compatible functionalities.
require_once self::$data['dir'] . 'includes/library/font-awesome/backward-compatible-icons.php';
require_once self::$data['dir'] . 'includes/library/font-awesome/font-awesome.php';
Menu_Icons_Font_Awesome::init();
add_action( 'icon_picker_init', array( __CLASS__, '_init' ), 9 );
add_action( 'admin_enqueue_scripts', array( __CLASS__, '_admin_enqueue_scripts' ) );
add_action( 'wp_dashboard_setup', array( __CLASS__, '_wp_menu_icons_dashboard_notice' ) );
add_action( 'admin_action_menu_icon_hide_notice', array( __CLASS__, 'wp_menu_icons_dismiss_dashboard_notice' ) );
add_filter(
'wp_menu_icons_load_promotions',
function() {
return array( 'otter' );
}
);
add_filter(
'wp_menu_icons_dissallowed_promotions', function () {
return array( 'om-editor', 'om-image-block' );
}
);
}
/**
* Initialize
*
* 1. Get registered types from Icon Picker
* 2. Load settings
* 3. Load front-end functionalities
*
* @since 0.1.0
* @since 0.9.0 Hook into `icon_picker_init`.
* @wp_hook action icon_picker_init
* @link http://codex.wordpress.org/Plugin_API/Action_Reference
*/
public static function _init() {
/**
* Allow themes/plugins to add/remove icon types
*
* @since 0.1.0
* @param array $types Icon types
*/
self::$data['types'] = apply_filters(
'menu_icons_types',
Icon_Picker_Types_Registry::instance()->types
);
// Nothing to do if there are no icon types registered.
if ( empty( self::$data['types'] ) ) {
if ( WP_DEBUG ) {
trigger_error( esc_html__( 'Menu Icons: No registered icon types found.', 'menu-icons' ) );
}
return;
}
// Load settings.
require_once self::$data['dir'] . 'includes/settings.php';
Menu_Icons_Settings::init();
// Load front-end functionalities.
if ( ! is_admin() ) {
require_once self::$data['dir'] . '/includes/front.php';
Menu_Icons_Front_End::init();
}
do_action( 'menu_icons_loaded' );
}
/**
* Display notice about missing Icon Picker
*
* @since 0.9.1
* @wp_hook action admin_notice
*/
public static function _notice_missing_icon_picker() {
?>
<div class="error">
<p><?php esc_html_e( 'Looks like Menu Icons was installed via Composer. Please activate Icon Picker first.', 'menu-icons' ); ?></p>
</div>
<?php
}
/**
* Register assets.
*/
public static function _admin_enqueue_scripts() {
$url = self::get( 'url' );
$suffix = kucrut_get_script_suffix();
wp_register_style(
'menu-icons-dashboard',
"{$url}css/dashboard-notice{$suffix}.css",
false,
self::VERSION
);
}
/**
* Render dashboard notice.
*/
public static function _wp_menu_icons_dashboard_notice() {
$theme = get_template();
if ( 'neve' === $theme ) {
return;
}
$show_notice = true;
if ( ! empty( get_option( self::DISMISS_NOTICE, false ) ) ) {
$show_notice = false;
}
if ( ! empty( get_transient( self::DISMISS_NOTICE ) ) ) {
$show_notice = false;
}
if ( $show_notice ) {
wp_enqueue_style( 'menu-icons-dashboard' );
add_action( 'admin_notices', array( __CLASS__, '_upsell_admin_notice' ) );
}
}
/**
* Ajax request handle for dissmiss dashboard notice.
*/
public static function wp_menu_icons_dismiss_dashboard_notice() {
// Verify WP nonce and store hide notice flag.
if ( isset( $_GET['_wp_notice_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wp_notice_nonce'] ) ), self::DISMISS_NOTICE ) ) {
update_option( self::DISMISS_NOTICE, 1 );
}
if ( ! headers_sent() ) {
wp_safe_redirect( admin_url() );
exit;
}
}
/**
* Upsell admin notice.
*/
public static function _upsell_admin_notice() {
$neve_theme_url = add_query_arg(
array(
'theme' => 'neve',
),
admin_url( 'theme-install.php' )
);
$action_url = add_query_arg(
array(
'action' => 'menu_icon_hide_notice',
'_wp_notice_nonce' => wp_create_nonce( self::DISMISS_NOTICE ),
),
admin_url( 'index.php' )
);
?>
<div class="notice notice-info menu-icon-dashboard-notice">
<h2><?php esc_html_e( 'Thank you for installing Menu Icons!', 'menu-icons' ); ?></h2>
<p><?php esc_html_e( 'Have you heard about our latest FREE theme - Neve? Using a mobile-first approach, compatibility with AMP and popular page-builders, Neve makes website building accessible for everyone.', 'menu-icons' ); ?></p>
<a href="<?php echo esc_url( $neve_theme_url ); ?>" class="button button-primary button-large"><?php esc_html_e( 'Preview Neve', 'menu-icons' ); ?></a>
<a href="<?php echo esc_url( $action_url ); ?>" class="notice-dismiss"></a>
</div>
<?php
}
}
add_action( 'plugins_loaded', array( 'Menu_Icons', '_load' ) );
$vendor_file = dirname(__FILE__) . '/vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
add_filter( 'themeisle_sdk_products', 'kucrut_register_sdk', 10, 1 );
function kucrut_register_sdk( $products ) {
$products[] = __FILE__;
return $products;
}