/** * Get setting values and apply sanitation * * @since 0.3.0 * @acess private */ private static function _get() { $settings = get_option('menu-icons', null); if (is_null($settings)) { $settings['global'] = self::$defaults['global']; } /** * Check icon types * * A type could be enabled in the settings but disabled by a filter, * so we need to 'fix' it here. */ if (!empty($settings['global']['icon_types'])) { $active_types = array(); $icon_types = Menu_Icons::get('icon_types'); foreach ((array) $settings['global']['icon_types'] as $index => $id) { if (isset($icon_types[$id])) { $active_types[] = $id; } } if ($settings['global']['icon_types'] !== $active_types) { $settings['global']['icon_types'] = $active_types; update_option('menu-icons', $settings); } } self::$settings = $settings; }
/** * Settings init * * @since 0.3.0 */ public static function init() { /** * Allow themes/plugins to override the default settings * * @since 0.9.0 * @param array $default_settings Default settings. */ self::$defaults = apply_filters('menu_icons_settings_defaults', self::$defaults); self::$settings = get_option('menu-icons', self::$defaults); foreach (self::$settings as $key => &$value) { if ('global' === $key) { // Remove unregistered icon types. $value['icon_types'] = array_values(array_intersect(array_keys(Menu_Icons::get('types')), array_filter((array) $value['icon_types']))); } else { // Backward-compatibility. if (isset($value['width']) && !isset($value['svg_width'])) { $value['svg_width'] = $value['width']; } unset($value['width']); } } unset($value); /** * Allow themes/plugins to override the settings * * @since 0.9.0 * @param array $settings Menu Icons settings. */ self::$settings = apply_filters('menu_icons_settings', self::$settings); if (self::is_menu_icons_disabled_for_menu()) { return; } if (!empty(self::$settings['global']['icon_types'])) { require_once Menu_Icons::get('dir') . 'includes/picker.php'; Menu_Icons_Picker::init(); self::$script_deps[] = 'icon-picker'; } add_action('load-nav-menus.php', array(__CLASS__, '_load_nav_menus'), 1); add_action('wp_ajax_menu_icons_update_settings', array(__CLASS__, '_ajax_menu_icons_update_settings')); }