menu-icons
Last commit date
assets
8 years ago
css
8 years ago
includes
8 years ago
js
8 years ago
languages
8 years ago
vendor
8 years ago
CHANGELOG.md
8 years ago
LICENSE
8 years ago
mailin.php
8 years ago
menu-icons.php
8 years ago
readme.md
8 years ago
readme.txt
8 years ago
menu-icons.php
179 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.11.2 |
| 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 VERSION = '0.11.2'; |
| 31 | |
| 32 | /** |
| 33 | * Holds plugin data |
| 34 | * |
| 35 | * @access protected |
| 36 | * @since 0.1.0 |
| 37 | * @var array |
| 38 | */ |
| 39 | protected static $data; |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * Get plugin data |
| 44 | * |
| 45 | * @since 0.1.0 |
| 46 | * @since 0.9.0 Return NULL if $name is not set in $data. |
| 47 | * @param string $name |
| 48 | * |
| 49 | * @return mixed |
| 50 | */ |
| 51 | public static function get( $name = null ) { |
| 52 | if ( is_null( $name ) ) { |
| 53 | return self::$data; |
| 54 | } |
| 55 | |
| 56 | if ( isset( self::$data[ $name ] ) ) { |
| 57 | return self::$data[ $name ]; |
| 58 | } |
| 59 | |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * Load plugin |
| 66 | * |
| 67 | * 1. Load translation |
| 68 | * 2. Set plugin data (directory and URL paths) |
| 69 | * 3. Attach plugin initialization at icon_picker_init hook |
| 70 | * |
| 71 | * @since 0.1.0 |
| 72 | * @wp_hook action plugins_loaded |
| 73 | * @link http://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded |
| 74 | */ |
| 75 | public static function _load() { |
| 76 | load_plugin_textdomain( 'menu-icons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 77 | |
| 78 | self::$data = array( |
| 79 | 'dir' => plugin_dir_path( __FILE__ ), |
| 80 | 'url' => plugin_dir_url( __FILE__ ), |
| 81 | 'types' => array(), |
| 82 | ); |
| 83 | $vendor_file = dirname(__FILE__) . '/vendor/autoload.php'; |
| 84 | |
| 85 | if ( is_readable( $vendor_file ) ) { |
| 86 | require_once $vendor_file; |
| 87 | } |
| 88 | // Load Icon Picker. |
| 89 | if ( ! class_exists( 'Icon_Picker' ) ) { |
| 90 | $ip_file = self::$data['dir'] . 'includes/library/icon-picker/icon-picker.php'; |
| 91 | |
| 92 | if ( file_exists( $ip_file ) ) { |
| 93 | require_once $ip_file; |
| 94 | } else { |
| 95 | add_action( 'admin_notices', array( __CLASS__, '_notice_missing_icon_picker' ) ); |
| 96 | return; |
| 97 | } |
| 98 | } |
| 99 | Icon_Picker::instance(); |
| 100 | |
| 101 | require_once self::$data['dir'] . 'includes/library/compat.php'; |
| 102 | require_once self::$data['dir'] . 'includes/library/functions.php'; |
| 103 | require_once self::$data['dir'] . 'includes/meta.php'; |
| 104 | |
| 105 | Menu_Icons_Meta::init(); |
| 106 | |
| 107 | add_action( 'icon_picker_init', array( __CLASS__, '_init' ), 9 ); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * Initialize |
| 113 | * |
| 114 | * 1. Get registered types from Icon Picker |
| 115 | * 2. Load settings |
| 116 | * 3. Load front-end functionalities |
| 117 | * |
| 118 | * @since 0.1.0 |
| 119 | * @since 0.9.0 Hook into `icon_picker_init`. |
| 120 | * @wp_hook action icon_picker_init |
| 121 | * @link http://codex.wordpress.org/Plugin_API/Action_Reference |
| 122 | */ |
| 123 | public static function _init() { |
| 124 | /** |
| 125 | * Allow themes/plugins to add/remove icon types |
| 126 | * |
| 127 | * @since 0.1.0 |
| 128 | * @param array $types Icon types |
| 129 | */ |
| 130 | self::$data['types'] = apply_filters( |
| 131 | 'menu_icons_types', |
| 132 | Icon_Picker_Types_Registry::instance()->types |
| 133 | ); |
| 134 | |
| 135 | // Nothing to do if there are no icon types registered. |
| 136 | if ( empty( self::$data['types'] ) ) { |
| 137 | if ( WP_DEBUG ) { |
| 138 | trigger_error( esc_html__( 'Menu Icons: No registered icon types found.', 'menu-icons' ) ); |
| 139 | } |
| 140 | |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | // Load settings. |
| 145 | require_once self::$data['dir'] . 'includes/settings.php'; |
| 146 | Menu_Icons_Settings::init(); |
| 147 | |
| 148 | // Load front-end functionalities. |
| 149 | if ( ! is_admin() ) { |
| 150 | require_once self::$data['dir'] . '/includes/front.php'; |
| 151 | Menu_Icons_Front_End::init(); |
| 152 | } |
| 153 | |
| 154 | do_action( 'menu_icons_loaded' ); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * Display notice about missing Icon Picker |
| 160 | * |
| 161 | * @since 0.9.1 |
| 162 | * @wp_hook action admin_notice |
| 163 | */ |
| 164 | public static function _notice_missing_icon_picker() { |
| 165 | ?> |
| 166 | <div class="error"> |
| 167 | <p><?php esc_html_e( 'Looks like Menu Icons was installed via Composer. Please activate Icon Picker first.', 'menu-icons' ); ?></p> |
| 168 | </div> |
| 169 | <?php |
| 170 | } |
| 171 | } |
| 172 | add_action( 'plugins_loaded', array( 'Menu_Icons', '_load' ) ); |
| 173 | |
| 174 | add_filter( 'themeisle_sdk_products', 'kucrut_register_sdk', 10, 1 ); |
| 175 | function kucrut_register_sdk( $products ) { |
| 176 | |
| 177 | $products[] = __FILE__; |
| 178 | return $products; |
| 179 | } |