Пример #1
0
 /**
  * Load plugin
  *
  * 1. Load translation
  * 2. Set plugin data (directory and URL paths)
  * 3. Attach plugin initialization at icon_picker_init hook
  *
  * @since   0.1.0
  * @wp_hook action plugins_loaded
  * @link    http://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
  */
 public static function _load()
 {
     load_plugin_textdomain('menu-icons', false, dirname(plugin_basename(__FILE__)) . '/languages/');
     self::$data = array('dir' => plugin_dir_path(__FILE__), 'url' => plugin_dir_url(__FILE__), 'types' => array());
     // Load Icon Picker.
     if (!class_exists('Icon_Picker')) {
         $ip_file = self::$data['dir'] . 'includes/library/icon-picker/icon-picker.php';
         if (file_exists($ip_file)) {
             require_once $ip_file;
         } else {
             add_action('admin_notices', array(__CLASS__, '_notice_missing_icon_picker'));
             return;
         }
     }
     Icon_Picker::instance();
     require_once self::$data['dir'] . 'includes/library/compat.php';
     require_once self::$data['dir'] . 'includes/library/functions.php';
     require_once self::$data['dir'] . 'includes/meta.php';
     Menu_Icons_Meta::init();
     add_action('icon_picker_init', array(__CLASS__, '_init'), 9);
 }
Пример #2
0
 /**
  * Add icon to menu item title
  *
  * @since   0.1.0
  * @since   0.9.0   Renamed the method to `add_icon()`.
  * @wp_hook filter  the_title
  * @param   string  $title     Menu item title.
  * @param   int     $id        Menu item ID.
  *
  * @return string
  */
 public static function _add_icon($title, $id)
 {
     $meta = Menu_Icons_Meta::get($id);
     $icon = self::get_icon($meta);
     if (empty($icon)) {
         return $title;
     }
     $title_class = !empty($meta['hide_label']) ? self::$hidden_label_class : '';
     $title_wrapped = sprintf('<span%s>%s</span>', !empty($title_class) ? sprintf(' class="%s"', esc_attr($title_class)) : '', $title);
     if ('after' === $meta['position']) {
         $title_with_icon = "{$title_wrapped}{$icon}";
     } else {
         $title_with_icon = "{$icon}{$title_wrapped}";
     }
     /**
      * Allow plugins/themes to override menu item markup
      *
      * @since 0.8.0
      *
      * @param string  $title_with_icon Menu item markup after the icon is added.
      * @param integer $id              Menu item ID.
      * @param array   $meta            Menu item metadata values.
      * @param string  $title           Original menu item title.
      *
      * @return string
      */
     $title_with_icon = apply_filters('menu_icons_item_title', $title_with_icon, $id, $meta, $title);
     return $title_with_icon;
 }
Пример #3
0
 /**
  * Save menu item's icons metadata
  *
  * @since   0.1.0
  * @access  protected
  * @wp_hook action    wp_update_nav_menu_item
  * @link    http://codex.wordpress.org/Plugin_API/Action_Reference/wp_update_nav_menu_item
  *
  * @param int   $menu_id         Nav menu ID.
  * @param int   $menu_item_db_id Menu item ID.
  * @param array $menu_item_args  Menu item data.
  */
 public static function _save($menu_id, $menu_item_db_id, $menu_item_args)
 {
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     $screen = get_current_screen();
     if (!$screen instanceof WP_Screen || 'nav-menus' !== $screen->id) {
         return;
     }
     check_admin_referer('update-nav_menu', 'update-nav-menu-nonce');
     // Sanitize
     if (!empty($_POST['menu-icons'][$menu_item_db_id])) {
         $value = array_map('sanitize_text_field', wp_unslash((array) $_POST['menu-icons'][$menu_item_db_id]));
     } else {
         $value = array();
     }
     Menu_Icons_Meta::update($menu_item_db_id, $value);
 }