/**
  * Adds Dashboard navigation menus.
  *
  * @since  1.0.0
  */
 public function add_menu_pages()
 {
     global $submenu;
     $limited_mode = false;
     $view = MS_Model_Settings::get_special_view();
     if ($view) {
         // A special view is displayed. Do not display other menu items.
         $pages = array();
         $limited_mode = true;
     } elseif (MS_Plugin::is_wizard()) {
         // Submenus definition: Wizard mode
         $pages = $this->get_setup_menu_pages();
         $limited_mode = true;
     } else {
         // Submenus definition: Normal mode
         $pages = $this->get_default_menu_pages();
         if (MS_Plugin::is_network_wide() && !is_network_admin()) {
             $limited_mode = true;
         }
     }
     /**
      * Allow Add-ons and other plugins to add menu pages.
      *
      * A menu item is defined by an array containing the following members:
      *   'title' => '...',
      *   'slug' => '...',
      *   'function' => callback
      *
      * @var array
      */
     $pages = apply_filters('ms_plugin_menu_pages', $pages, $limited_mode, $this);
     $page_keys = array_keys($pages);
     $slug = '';
     if (isset($page_keys[0]) && $pages[$page_keys[0]]) {
         $slug = $pages[$page_keys[0]]['slug'];
     }
     if (empty($slug)) {
         self::$base_slug = self::MENU_SLUG;
     } else {
         self::$base_slug = self::MENU_SLUG . '-' . $slug;
     }
     /*
      * Create primary menu item: Membership.
      *
      * The menu title is not translatable because of a bug in WordPress core
      * https://core.trac.wordpress.org/ticket/18857
      * Until this bug is closed the title (2nd argument) can't be translated
      */
     add_menu_page('Membership 2', 'Membership 2', $this->capability, self::$base_slug, null, 'dashicons-lock');
     // Create submenus
     foreach ($pages as $page) {
         if (!is_array($page)) {
             continue;
         }
         if (empty($page['link'])) {
             $menu_link = false;
         } else {
             $menu_link = $page['link'];
         }
         $slug = self::MENU_SLUG;
         if (!empty($page['slug'])) {
             $slug .= '-' . $page['slug'];
         }
         add_submenu_page(self::$base_slug, strip_tags($page['title']), $page['title'], $this->capability, $slug, array($this, 'handle_submenu_request'));
         /*
          * WordPress does not support absolute URLs in the admin-menu.
          * So we have to manny modify the menu-link href value if our slug
          * is an absolute URL.
          */
         if ($menu_link) {
             $item = end($submenu[self::$base_slug]);
             $key = key($submenu[self::$base_slug]);
             $submenu[self::$base_slug][$key][2] = $menu_link;
         }
     }
     do_action('ms_controller_plugin_add_menu_pages', $this);
     // Setup the rest of the plugin after the menu was registered.
     do_action('ms_plugin_admin_setup');
 }
 /**
  * Translate the plugin settings before they are saved to DB.
  *
  * @since  1.0.1.0
  *
  * @param  array $obj The serialized data collection.
  * @param  MS_Model_Settings $model The source object.
  * @return array The serialized data collection.
  */
 public function serialize_settings($data, $model)
 {
     if ($this->current_lang == $this->default_lang) {
         return $data;
     }
     // Save the translated values before resetting the model.
     $translations = array();
     foreach ($model->protection_messages as $key => $message) {
         $translations[$key] = $message;
     }
     // Reset the values to Default language.
     $data['protection_messages'] = $model->reset_field('protection_messages');
     // Store translations via WPML.
     if (function_exists('icl_add_string_translation')) {
         foreach ($translations as $key => $tr_message) {
             $string_name = 'ms-set-protection-' . $key;
             do_action('wpml_register_single_string', self::CONTEXT, $string_name, $model->protection_messages[$key]);
             $string_id = icl_get_string_id($model->protection_messages[$key], self::CONTEXT, $string_name);
             if ($string_id) {
                 icl_add_string_translation($string_id, $this->current_lang, $tr_message, ICL_TM_COMPLETE);
             }
         }
     }
     return $data;
 }