menu-icons
Last commit date
css
2 years ago
images
4 years ago
includes
2 months ago
js
4 years ago
languages
6 years ago
vendor
2 months ago
CHANGELOG.md
2 months ago
LICENSE
12 years ago
mailin.php
7 years ago
menu-icons.php
2 months ago
readme.md
2 years ago
readme.txt
2 months ago
menu-icons.php
306 lines
| 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.23 |
| 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.23'; |
| 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 | add_filter( 'themeisle_sdk_blackfriday_data', array( __CLASS__, 'add_black_friday_data' ) ); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * Initialize |
| 123 | * |
| 124 | * 1. Get registered types from Icon Picker |
| 125 | * 2. Load settings |
| 126 | * 3. Load front-end functionalities |
| 127 | * |
| 128 | * @since 0.1.0 |
| 129 | * @since 0.9.0 Hook into `icon_picker_init`. |
| 130 | * @wp_hook action icon_picker_init |
| 131 | * @link http://codex.wordpress.org/Plugin_API/Action_Reference |
| 132 | */ |
| 133 | public static function _init() { |
| 134 | /** |
| 135 | * Allow themes/plugins to add/remove icon types |
| 136 | * |
| 137 | * @since 0.1.0 |
| 138 | * @param array $types Icon types |
| 139 | */ |
| 140 | self::$data['types'] = apply_filters( |
| 141 | 'menu_icons_types', |
| 142 | Icon_Picker_Types_Registry::instance()->types |
| 143 | ); |
| 144 | |
| 145 | // Nothing to do if there are no icon types registered. |
| 146 | if ( empty( self::$data['types'] ) ) { |
| 147 | if ( WP_DEBUG ) { |
| 148 | trigger_error( esc_html__( 'Menu Icons: No registered icon types found.', 'menu-icons' ) ); |
| 149 | } |
| 150 | |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | // Load settings. |
| 155 | require_once self::$data['dir'] . 'includes/settings.php'; |
| 156 | Menu_Icons_Settings::init(); |
| 157 | |
| 158 | // Load front-end functionalities. |
| 159 | if ( ! is_admin() ) { |
| 160 | require_once self::$data['dir'] . '/includes/front.php'; |
| 161 | Menu_Icons_Front_End::init(); |
| 162 | } |
| 163 | |
| 164 | do_action( 'menu_icons_loaded' ); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | /** |
| 169 | * Display notice about missing Icon Picker |
| 170 | * |
| 171 | * @since 0.9.1 |
| 172 | * @wp_hook action admin_notice |
| 173 | */ |
| 174 | public static function _notice_missing_icon_picker() { |
| 175 | ?> |
| 176 | <div class="error"> |
| 177 | <p><?php esc_html_e( 'Looks like Menu Icons was installed via Composer. Please activate Icon Picker first.', 'menu-icons' ); ?></p> |
| 178 | </div> |
| 179 | <?php |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Register assets. |
| 184 | */ |
| 185 | public static function _admin_enqueue_scripts() { |
| 186 | $url = self::get( 'url' ); |
| 187 | $suffix = kucrut_get_script_suffix(); |
| 188 | |
| 189 | wp_register_style( |
| 190 | 'menu-icons-dashboard', |
| 191 | "{$url}css/dashboard-notice{$suffix}.css", |
| 192 | false, |
| 193 | self::VERSION |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Render dashboard notice. |
| 199 | */ |
| 200 | public static function _wp_menu_icons_dashboard_notice() { |
| 201 | $theme = get_template(); |
| 202 | if ( 'neve' === $theme ) { |
| 203 | return; |
| 204 | } |
| 205 | $show_notice = true; |
| 206 | if ( ! empty( get_option( self::DISMISS_NOTICE, false ) ) ) { |
| 207 | $show_notice = false; |
| 208 | } |
| 209 | if ( ! empty( get_transient( self::DISMISS_NOTICE ) ) ) { |
| 210 | $show_notice = false; |
| 211 | } |
| 212 | if ( $show_notice ) { |
| 213 | wp_enqueue_style( 'menu-icons-dashboard' ); |
| 214 | add_action( 'admin_notices', array( __CLASS__, '_upsell_admin_notice' ) ); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Ajax request handle for dissmiss dashboard notice. |
| 220 | */ |
| 221 | public static function wp_menu_icons_dismiss_dashboard_notice() { |
| 222 | // Verify WP nonce and store hide notice flag. |
| 223 | if ( isset( $_GET['_wp_notice_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wp_notice_nonce'] ) ), self::DISMISS_NOTICE ) ) { |
| 224 | update_option( self::DISMISS_NOTICE, 1 ); |
| 225 | } |
| 226 | |
| 227 | if ( ! headers_sent() ) { |
| 228 | wp_safe_redirect( admin_url() ); |
| 229 | exit; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Upsell admin notice. |
| 235 | */ |
| 236 | public static function _upsell_admin_notice() { |
| 237 | $neve_theme_url = add_query_arg( |
| 238 | array( |
| 239 | 'theme' => 'neve', |
| 240 | ), |
| 241 | admin_url( 'theme-install.php' ) |
| 242 | ); |
| 243 | |
| 244 | $action_url = add_query_arg( |
| 245 | array( |
| 246 | 'action' => 'menu_icon_hide_notice', |
| 247 | '_wp_notice_nonce' => wp_create_nonce( self::DISMISS_NOTICE ), |
| 248 | ), |
| 249 | admin_url( 'index.php' ) |
| 250 | ); |
| 251 | ?> |
| 252 | <div class="notice notice-info menu-icon-dashboard-notice"> |
| 253 | <h2><?php esc_html_e( 'Thank you for installing Menu Icons!', 'menu-icons' ); ?></h2> |
| 254 | <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> |
| 255 | <a href="<?php echo esc_url( $neve_theme_url ); ?>" class="button button-primary button-large"><?php esc_html_e( 'Preview Neve', 'menu-icons' ); ?></a> |
| 256 | <a href="<?php echo esc_url( $action_url ); ?>" class="notice-dismiss"></a> |
| 257 | </div> |
| 258 | <?php |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Add Black Friday data. |
| 263 | * |
| 264 | * @param array $configs The configuration array for the loaded products. |
| 265 | * |
| 266 | * @return array |
| 267 | */ |
| 268 | public static function add_black_friday_data( $configs ) { |
| 269 | $config = $configs['default']; |
| 270 | $product_slug = basename(dirname(__FILE__)); |
| 271 | |
| 272 | if ( defined( 'NEVE_VERSION' ) ) { |
| 273 | return $configs; |
| 274 | } |
| 275 | |
| 276 | // translators: 1. Number of free licenses, 2. The price of the product. |
| 277 | $config['message'] = sprintf( __( 'You\'re using Menu Icons, and the team behind it is celebrating Black Friday by giving away %1$s licences of Neve Pro. A premium WordPress theme worth %2$s, packed with starter sites, a header builder, and WooCommerce layouts. Claim yours before they run out.', 'menu-icons' ), 100, '$69' ); |
| 278 | $config['cta_label'] = __( 'Get Neve Pro free', 'menu-icons' ); |
| 279 | $config['plugin_meta_message'] = __( 'Black Friday Sale - Get Neve Pro free', 'menu-icons' ); |
| 280 | $config['sale_url'] = add_query_arg( |
| 281 | array( |
| 282 | 'utm_term' => 'free', |
| 283 | ), |
| 284 | tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/neve-claim-bf', 'bfcm', 'menu-icons' ) ) |
| 285 | ); |
| 286 | |
| 287 | $configs[ $product_slug ] = $config; |
| 288 | |
| 289 | return $configs; |
| 290 | } |
| 291 | } |
| 292 | add_action( 'plugins_loaded', array( 'Menu_Icons', '_load' ) ); |
| 293 | |
| 294 | $vendor_file = dirname(__FILE__) . '/vendor/autoload.php'; |
| 295 | |
| 296 | if ( is_readable( $vendor_file ) ) { |
| 297 | require_once $vendor_file; |
| 298 | } |
| 299 | |
| 300 | add_filter( 'themeisle_sdk_products', 'kucrut_register_sdk', 10, 1 ); |
| 301 | function kucrut_register_sdk( $products ) { |
| 302 | |
| 303 | $products[] = __FILE__; |
| 304 | return $products; |
| 305 | } |
| 306 |