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