private function _embed_params($params = null, $parent = null)
 {
     $po = JWP6_Plugin::$player_options;
     if (is_null($params)) {
         $params = $this->config;
         unset($params['description']);
     }
     $new_params = array();
     foreach ($params as $param => $value) {
         if (!$param) {
             continue;
         }
         $check_param = is_null($parent) ? $param : $parent . "__" . $param;
         // If the value is an array, we recurse into a deeper level
         if (is_array($value)) {
             $new_value = $this->_embed_params($value, $check_param);
             if (is_array($new_value) && count($new_value)) {
                 $new_params[$param] = $new_value;
             }
             // Check if this param has a value that should exclude it's complete parent.
         } else {
             if ($parent && isset($po[$parent]['not_if'][$param]) && $value == $po[$parent]['not_if'][$param]) {
                 return null;
                 // if the param exists in the player options, it's a built-in option and we can
                 // perform additional checks
             } else {
                 if (array_key_exists($check_param, JWP6_Plugin::$player_options)) {
                     // Check to see if the option is available for this license.
                     if (JWP6_Plugin::option_available($check_param)) {
                         $check_for_default = isset($po[$check_param]['discard_if_default']) && $po[$check_param]['discard_if_default'] ? true : false;
                         if (!$check_for_default || $value != $po[$check_param]['default']) {
                             if (true === $value && isset($po[$check_param]['embedval'])) {
                                 $value = json_decode($po[$check_param]['embedval']);
                             }
                             $new_params[$param] = $value;
                         }
                     }
                     // no further checking the param was set by the user and we assume he/she
                     // knows what he/she is doing.
                 } else {
                     $new_params[$param] = $value;
                 }
             }
         }
     }
     return $new_params;
 }
 private function _init_edit_page()
 {
     // Basic settings
     $cannot_edit = false;
     if ($this->imported_players && array_key_exists($this->player->get('description'), $this->imported_players)) {
         $cannot_edit = 'You cannot edit the description of this player, because this is an imported JW5 player configuration and the description is used to map your old shortcodes to this player.';
     } else {
         if (!$this->player->get_id()) {
             $cannot_edit = 'You cannot edit the description of the default editor.';
         }
     }
     if ($cannot_edit) {
         $description_field = new JWP6_Form_Field_Uneditable('description', array('value' => $this->player->get('description'), 'why_not' => $cannot_edit));
     } else {
         $description_field = new JWP6_Form_Field('description', array('value' => $this->player->get('description'), 'validation' => "sanitize_text_field", 'placeholder' => "Use this short description as a reminder to identify the player.", 'class' => 'wide'));
     }
     $aspectratio_field = new JWP6_Form_Field_Select('aspectratio', array('label' => 'Player Size', 'value' => $this->player->get('aspectratio'), 'options' => JWP6_Plugin::$player_options['aspectratio']['options'], 'default' => JWP6_Plugin::$player_options['aspectratio']['default'], 'help_text' => JWP6_Plugin::$player_options['aspectratio']['help_text']));
     $width_field = new JWP6_Form_Field('width', array('label' => 'Fixed width', 'value' => $this->player->get('width'), 'validation' => array('JWP6_Plugin', 'validate_int'), 'unit' => 'pixels wide.', 'class' => 'small right', 'only_if' => array('aspectratio' => 'NULL')));
     $height_field = new JWP6_Form_Field('height', array('label' => 'Fixed height', 'value' => $this->player->get('height'), 'validation' => array('JWP6_Plugin', 'validate_int'), 'unit' => 'pixels high.', 'class' => 'small right', 'only_if' => array('aspectratio' => 'NULL')));
     // LAYOUT
     $skin_field = JWP6_Plugin::option_available('skin') ? new JWP6_Form_Field_Select('skin', array('value' => $this->player->get('skin'), 'options' => JWP6_Plugin::$player_options['skin']['options'], 'default' => JWP6_Plugin::$player_options['skin']['default'])) : null;
     $controls_field = new JWP6_Form_Field_Toggle('controls', array('value' => $this->player->get('controls'), 'text' => JWP6_Plugin::$player_options['controls']['text'], 'help_text' => JWP6_Plugin::$player_options['controls']['help_text']));
     $stretching_field = new JWP6_Form_Field_Select('stretching', array('value' => $this->player->get('stretching'), 'options' => JWP6_Plugin::$player_options['stretching']['options'], 'default' => JWP6_Plugin::$player_options['stretching']['default'], 'help_text' => JWP6_Plugin::$player_options['stretching']['help_text']));
     // PLAYBACK
     $autostart_field = new JWP6_Form_Field_Toggle('autostart', array('value' => $this->player->get('autostart'), 'text' => JWP6_Plugin::$player_options['autostart']['text'], 'help_text' => JWP6_Plugin::$player_options['autostart']['help_text']));
     $fallback_field = new JWP6_Form_Field_Toggle('fallback', array('value' => $this->player->get('fallback'), 'text' => JWP6_Plugin::$player_options['fallback']['text']));
     $mute_field = new JWP6_Form_Field_Toggle('mute', array('value' => $this->player->get('mute'), 'text' => JWP6_Plugin::$player_options['mute']['text']));
     $primary_field = new JWP6_Form_Field_Radio('primary', array('value' => $this->player->get('primary'), 'label' => 'Default rendering mode', 'options' => JWP6_Plugin::$player_options['primary']['options'], 'default' => JWP6_Plugin::$player_options['primary']['default'], 'help_text' => JWP6_Plugin::$player_options['primary']['help_text'], 'description_is_value' => true));
     $repeat_field = new JWP6_Form_Field_Toggle('repeat', array('value' => $this->player->get('repeat'), 'text' => JWP6_Plugin::$player_options['repeat']['text']));
     // TODO: STARTPARAM
     $listbar_position_field = new JWP6_Form_Field_Select('listbar__position', array('value' => $this->player->get('listbar__position'), 'options' => JWP6_Plugin::$player_options['listbar__position']['options'], 'default' => JWP6_Plugin::$player_options['listbar__position']['default'], 'help_text' => JWP6_Plugin::$player_options['listbar__position']['help_text']));
     $listbar_size_field = new JWP6_Form_Field('listbar__size', array('value' => $this->player->get('listbar__size'), 'validation' => array('JWP6_Plugin', 'validate_int'), 'default' => JWP6_Plugin::$player_options['listbar__size']['default'], 'unit' => 'pixels.', 'class' => 'small right', 'help_text' => JWP6_Plugin::$player_options['listbar__size']['help_text']));
     // LISTBAR
     // LOGO & RIGHTCLICK
     if (JWP6_Plugin::option_available('logo')) {
         $logo_file_field = new JWP6_Form_Field('logo__file', array('value' => $this->player->get('logo__file'), 'validation' => array('JWP6_Plugin', 'validate_empty_or_url'), 'placeholder' => "URL to the file to use for the image", 'class' => 'wide', 'help_text' => JWP6_Plugin::$player_options['logo__file']['help_text']));
         $logo_hide_field = new JWP6_Form_Field_Toggle('logo__hide', array('value' => $this->player->get('logo__hide'), 'text' => JWP6_Plugin::$player_options['logo__hide']['text']));
         $logo_link_field = new JWP6_Form_Field('logo__link', array('value' => $this->player->get('logo__link'), 'validation' => array('JWP6_Plugin', 'validate_empty_or_url'), 'placeholder' => "URL you want the logo to link to.", 'class' => 'wide', 'help_text' => JWP6_Plugin::$player_options['logo__link']['help_text']));
         $logo_margin_field = new JWP6_Form_Field('logo__margin', array('value' => $this->player->get('logo__margin'), 'validation' => array('JWP6_Plugin', 'validate_int'), 'unit' => 'pixels.', 'class' => 'small right', 'help_text' => JWP6_Plugin::$player_options['logo__margin']['help_text']));
         $logo_position_field = new JWP6_Form_Field_Select('logo__position', array('value' => $this->player->get('logo__position'), 'options' => JWP6_Plugin::$player_options['logo__position']['options'], 'default' => JWP6_Plugin::$player_options['logo__position']['default'], 'help_text' => JWP6_Plugin::$player_options['logo__position']['help_text'], 'description_is_value' => true));
         // FIELDSETS
         $this->logo_settings_fields = array('logo_file_field' => $logo_file_field, 'logo_hide_field' => $logo_hide_field, 'logo_link_field' => $logo_link_field, 'logo_margin_field' => $logo_margin_field, 'logo_position_field' => $logo_position_field);
     }
     // Advertising
     if (JWP6_Plugin::option_available('advertising')) {
         $advertising_client_field = new JWP6_Form_Field_Select('advertising__client', array('value' => $this->player->get('advertising__client'), 'options' => JWP6_Plugin::$player_options['advertising__client']['options'], 'default' => JWP6_Plugin::$player_options['advertising__client']['default']));
         $advertising_tag_field = new JWP6_Form_Field('advertising__tag', array('value' => $this->player->get('advertising__tag'), 'validation' => array('JWP6_Plugin', 'validate_empty_or_url'), 'placeholder' => "URL of your vast/googima tag", 'class' => 'wide', 'help_text' => JWP6_Plugin::$player_options['advertising__tag']['help_text']));
         $this->advertising_fields = array('advertising_client_field' => $advertising_client_field, 'advertising_tag_field' => $advertising_tag_field);
     }
     // GOOGLE ANALYTICS & SHARING
     $this->other_settings_fields = array();
     if (JWP6_Plugin::option_available('ga')) {
         $ga_field = new JWP6_Form_Field_Toggle('ga', array('value' => $this->player->get('ga'), 'text' => JWP6_Plugin::$player_options['ga']['text'], 'label' => 'Google Analytics'));
         $this->other_settings_fields['ga_field'] = $ga_field;
     }
     if (JWP6_Plugin::option_available('sharing')) {
         $sharing_field = new JWP6_Form_Field_Toggle('sharing', array('value' => $this->player->get('sharing'), 'text' => JWP6_Plugin::$player_options['sharing']['text'], 'label' => 'Sharing'));
         $this->other_settings_fields['sharing_field'] = $sharing_field;
     }
     if ($this->player->get('streamer')) {
         $this->other_settings_fields['streamer_field'] = new JWP6_Form_Field_Uneditable('streamer', array('value' => $this->player->get('streamer'), 'why_not' => "This is an imported JW Player 5 that had a custom streamer setting. JW player 6 only supports this setting as a legacy setting."));
     }
     $this->basic_settings_fields = array('description_field' => $description_field, 'aspectratio_field' => $aspectratio_field, 'width_field' => $width_field, 'height_field' => $height_field);
     $this->layout_settings_fields = array('skin_field' => $skin_field, 'controls_field' => $controls_field, 'stretching_field' => $stretching_field);
     $this->playback_settings_fields = array('autostart_field' => $autostart_field, 'fallback_field' => $fallback_field, 'mute_field' => $mute_field, 'primary_field' => $primary_field, 'repeat_field' => $repeat_field);
     $this->listbar_settings_fields = array('listbar_position_field' => $listbar_position_field, 'listbar_size_field' => $listbar_size_field);
     $this->form_fields = array_merge($this->basic_settings_fields, $this->layout_settings_fields, $this->playback_settings_fields, $this->listbar_settings_fields);
     if (JWP6_Plugin::option_available('logo')) {
         $this->form_fields = array_merge($this->form_fields, $this->logo_settings_fields);
     }
     if (JWP6_Plugin::option_available('advertising')) {
         $this->form_fields = array_merge($this->form_fields, $this->advertising_fields);
     }
     if (count($this->other_settings_fields)) {
         $this->form_fields = array_merge($this->form_fields, $this->other_settings_fields);
     }
 }