PluginProbe
Menu Icons by Themeisle – Add Icons to Navigation Menus / 0.13.1
Menu Icons by Themeisle – Add Icons to Navigation Menus v0.13.1
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
264 lines 6.6 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.1
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.1';
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 'menu_icons_load_promotions',
107 function() {
108 return array( 'otter' );
109 }
110 );
111 }
112
113
114 /**
115 * Initialize
116 *
117 * 1. Get registered types from Icon Picker
118 * 2. Load settings
119 * 3. Load front-end functionalities
120 *
121 * @since 0.1.0
122 * @since 0.9.0 Hook into `icon_picker_init`.
123 * @wp_hook action icon_picker_init
124 * @link http://codex.wordpress.org/Plugin_API/Action_Reference
125 */
126 public static function _init() {
127 /**
128 * Allow themes/plugins to add/remove icon types
129 *
130 * @since 0.1.0
131 * @param array $types Icon types
132 */
133 self::$data['types'] = apply_filters(
134 'menu_icons_types',
135 Icon_Picker_Types_Registry::instance()->types
136 );
137
138 // Nothing to do if there are no icon types registered.
139 if ( empty( self::$data['types'] ) ) {
140 if ( WP_DEBUG ) {
141 trigger_error( esc_html__( 'Menu Icons: No registered icon types found.', 'menu-icons' ) );
142 }
143
144 return;
145 }
146
147 // Load settings.
148 require_once self::$data['dir'] . 'includes/settings.php';
149 Menu_Icons_Settings::init();
150
151 // Load front-end functionalities.
152 if ( ! is_admin() ) {
153 require_once self::$data['dir'] . '/includes/front.php';
154 Menu_Icons_Front_End::init();
155 }
156
157 do_action( 'menu_icons_loaded' );
158 }
159
160
161 /**
162 * Display notice about missing Icon Picker
163 *
164 * @since 0.9.1
165 * @wp_hook action admin_notice
166 */
167 public static function _notice_missing_icon_picker() {
168 ?>
169 <div class="error">
170 <p><?php esc_html_e( 'Looks like Menu Icons was installed via Composer. Please activate Icon Picker first.', 'menu-icons' ); ?></p>
171 </div>
172 <?php
173 }
174
175 /**
176 * Register assets.
177 */
178 public static function _admin_enqueue_scripts() {
179 $url = self::get( 'url' );
180 $suffix = kucrut_get_script_suffix();
181
182 wp_register_style(
183 'menu-icons-dashboard',
184 "{$url}css/dashboard-notice{$suffix}.css",
185 false,
186 self::VERSION
187 );
188 }
189
190 /**
191 * Render dashboard notice.
192 */
193 public static function _wp_menu_icons_dashboard_notice() {
194 $show_notice = true;
195 if ( ! empty( get_option( self::DISMISS_NOTICE, false ) ) ) {
196 $show_notice = false;
197 }
198 if ( ! empty( get_transient( self::DISMISS_NOTICE ) ) ) {
199 $show_notice = false;
200 }
201 if ( $show_notice ) {
202 wp_enqueue_style( 'menu-icons-dashboard' );
203 add_action( 'admin_notices', array( __CLASS__, '_upsell_admin_notice' ) );
204 }
205 }
206
207 /**
208 * Ajax request handle for dissmiss dashboard notice.
209 */
210 public static function wp_menu_icons_dismiss_dashboard_notice() {
211 // Verify WP nonce and store hide notice flag.
212 if ( isset( $_GET['_wp_notice_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wp_notice_nonce'] ) ), self::DISMISS_NOTICE ) ) {
213 update_option( self::DISMISS_NOTICE, 1 );
214 }
215
216 if ( ! headers_sent() ) {
217 wp_safe_redirect( admin_url() );
218 exit;
219 }
220 }
221
222 /**
223 * Upsell admin notice.
224 */
225 public static function _upsell_admin_notice() {
226 $neve_theme_url = add_query_arg(
227 array(
228 'theme' => 'neve',
229 ),
230 admin_url( 'theme-install.php' )
231 );
232
233 $action_url = add_query_arg(
234 array(
235 'action' => 'menu_icon_hide_notice',
236 '_wp_notice_nonce' => wp_create_nonce( self::DISMISS_NOTICE ),
237 ),
238 admin_url( 'index.php' )
239 );
240 ?>
241 <div class="notice notice-info menu-icon-dashboard-notice">
242 <h2><?php esc_html_e( 'Thank you for installing Menu Icons!', 'menu-icons' ); ?></h2>
243 <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>
244 <a href="<?php echo esc_url( $neve_theme_url ); ?>" class="button button-primary button-large"><?php esc_html_e( 'Preview Neve', 'menu-icons' ); ?></a>
245 <a href="<?php echo esc_url( $action_url ); ?>" class="notice-dismiss"></a>
246 </div>
247 <?php
248 }
249 }
250 add_action( 'plugins_loaded', array( 'Menu_Icons', '_load' ) );
251
252 $vendor_file = dirname(__FILE__) . '/vendor/autoload.php';
253
254 if ( is_readable( $vendor_file ) ) {
255 require_once $vendor_file;
256 }
257
258 add_filter( 'themeisle_sdk_products', 'kucrut_register_sdk', 10, 1 );
259 function kucrut_register_sdk( $products ) {
260
261 $products[] = __FILE__;
262 return $products;
263 }
264