PluginProbe
Menu Icons by Themeisle – Add Icons to Navigation Menus / 0.13.15
Menu Icons by Themeisle – Add Icons to Navigation Menus v0.13.15
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
273 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.15
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.15';
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 $theme = get_template();
200 if ( 'neve' === $theme ) {
201 return;
202 }
203 $show_notice = true;
204 if ( ! empty( get_option( self::DISMISS_NOTICE, false ) ) ) {
205 $show_notice = false;
206 }
207 if ( ! empty( get_transient( self::DISMISS_NOTICE ) ) ) {
208 $show_notice = false;
209 }
210 if ( $show_notice ) {
211 wp_enqueue_style( 'menu-icons-dashboard' );
212 add_action( 'admin_notices', array( __CLASS__, '_upsell_admin_notice' ) );
213 }
214 }
215
216 /**
217 * Ajax request handle for dissmiss dashboard notice.
218 */
219 public static function wp_menu_icons_dismiss_dashboard_notice() {
220 // Verify WP nonce and store hide notice flag.
221 if ( isset( $_GET['_wp_notice_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wp_notice_nonce'] ) ), self::DISMISS_NOTICE ) ) {
222 update_option( self::DISMISS_NOTICE, 1 );
223 }
224
225 if ( ! headers_sent() ) {
226 wp_safe_redirect( admin_url() );
227 exit;
228 }
229 }
230
231 /**
232 * Upsell admin notice.
233 */
234 public static function _upsell_admin_notice() {
235 $neve_theme_url = add_query_arg(
236 array(
237 'theme' => 'neve',
238 ),
239 admin_url( 'theme-install.php' )
240 );
241
242 $action_url = add_query_arg(
243 array(
244 'action' => 'menu_icon_hide_notice',
245 '_wp_notice_nonce' => wp_create_nonce( self::DISMISS_NOTICE ),
246 ),
247 admin_url( 'index.php' )
248 );
249 ?>
250 <div class="notice notice-info menu-icon-dashboard-notice">
251 <h2><?php esc_html_e( 'Thank you for installing Menu Icons!', 'menu-icons' ); ?></h2>
252 <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>
253 <a href="<?php echo esc_url( $neve_theme_url ); ?>" class="button button-primary button-large"><?php esc_html_e( 'Preview Neve', 'menu-icons' ); ?></a>
254 <a href="<?php echo esc_url( $action_url ); ?>" class="notice-dismiss"></a>
255 </div>
256 <?php
257 }
258 }
259 add_action( 'plugins_loaded', array( 'Menu_Icons', '_load' ) );
260
261 $vendor_file = dirname(__FILE__) . '/vendor/autoload.php';
262
263 if ( is_readable( $vendor_file ) ) {
264 require_once $vendor_file;
265 }
266
267 add_filter( 'themeisle_sdk_products', 'kucrut_register_sdk', 10, 1 );
268 function kucrut_register_sdk( $products ) {
269
270 $products[] = __FILE__;
271 return $products;
272 }
273