public function wp_update_nav_menu_item($menu_id = 0, $menu_item_db_id = 0)
 {
     $off_canvas_sidebars = Off_Canvas_Sidebars();
     if (empty($_POST['menu-item-url'][$menu_item_db_id]) || $_POST['menu-item-url'][$menu_item_db_id] != '#off_canvas_control') {
         return;
     }
     // security check
     // as 'wp_update_nav_menu_item' can be called from outside WP admin
     if (current_user_can('edit_theme_options')) {
         check_admin_referer('update-nav_menu', 'update-nav-menu-nonce');
         $available_controls = array();
         foreach ($this->general_settings['sidebars'] as $sidebar => $sidebar_data) {
             $available_controls[$sidebar] = $sidebar_data['label'];
         }
         // Autoselect control when adding a new item
         $default_control = '';
         if (in_array($_POST['menu-item-title'][$menu_item_db_id], $available_controls)) {
             $default_control = $off_canvas_sidebars->get_sidebar_key_by_label($_POST['menu-item-title'][$menu_item_db_id]);
         }
         $options = array('off-canvas-control' => $default_control);
         // default values
         // our jQuery form has not been displayed
         if (empty($_POST['menu-item-off-canvas-control-detect'][$menu_item_db_id])) {
             if (!get_post_meta($menu_item_db_id, '_off_canvas_control_menu_item', true)) {
                 // our options were never saved
                 update_post_meta($menu_item_db_id, '_off_canvas_control_menu_item', $options);
             }
         } else {
             $options['off-canvas-control'] = '';
             // Of only one is available, allways select it
             if (!empty($_POST['menu-item-off-canvas-control'][$menu_item_db_id]) && array_key_exists($_POST['menu-item-off-canvas-control'][$menu_item_db_id], $available_controls)) {
                 $options['off-canvas-control'] = strip_tags(stripslashes($_POST['menu-item-off-canvas-control'][$menu_item_db_id]));
             }
             // Of only one sidebar is available, allways select its control
             /*if (count($available_controls) == 1) {
             			$options['off-canvas-control'] = $off_canvas_sidebars->get_sidebar_key_by_label( $available_controls[0] );
             		}*/
             update_post_meta($menu_item_db_id, '_off_canvas_control_menu_item', $options);
             // allow us to easily identify our nav menu item
         }
     }
 }
 function register_importexport_settings()
 {
     $this->plugin_tabs[$this->importexport_tab] = esc_attr__('Import/Export', 'off-canvas-sidebars');
     if (isset($_GET['gocs_message'])) {
         $gocs_message_class = '';
         $gocs_message = '';
         switch ($_GET['gocs_message']) {
             case 1:
                 $gocs_message_class = 'updated';
                 $gocs_message = esc_attr__('Settings Imported', 'off-canvas-sidebars');
                 break;
             case 2:
                 $gocs_message_class = 'error';
                 $gocs_message = esc_attr__('Invalid Settings File', 'off-canvas-sidebars');
                 break;
             case 3:
                 $gocs_message_class = 'error';
                 $gocs_message = esc_attr__('No Settings File Selected', 'off-canvas-sidebars');
                 break;
             default:
                 break;
         }
         if (!empty($gocs_message)) {
             echo '<div class="' . $gocs_message_class . '"><p>' . esc_html($gocs_message) . '</p></div>';
         }
     }
     // export settings
     if (isset($_GET[$this->plugin_key . '-export'])) {
         header("Content-Disposition: attachment; filename=" . $this->plugin_key . ".txt");
         header('Content-Type: text/plain; charset=utf-8');
         $general = $this->general_settings;
         echo "[START=OCS SETTINGS]\n";
         foreach ($general as $id => $text) {
             echo "{$id}\t" . json_encode($text) . "\n";
         }
         echo "[STOP=OCS SETTINGS]";
         exit;
     }
     // import settings
     if (isset($_POST[$this->plugin_key . '-import'])) {
         if ($_FILES[$this->plugin_key . '-import-file']['tmp_name']) {
             $import = explode("\n", file_get_contents($_FILES[$this->plugin_key . '-import-file']['tmp_name']));
             if (array_shift($import) == "[START=OCS SETTINGS]" && array_pop($import) == "[STOP=OCS SETTINGS]") {
                 $settings = array();
                 foreach ($import as $import_option) {
                     list($key, $value) = explode("\t", $import_option);
                     $settings[$key] = json_decode(sanitize_text_field($value), true);
                 }
                 // Validate global settings
                 $settings = Off_Canvas_Sidebars()->validate_settings($settings, Off_Canvas_Sidebars()->get_default_settings());
                 // Validate sidebar settings
                 if (!empty($settings['sidebars'])) {
                     foreach ($settings['sidebars'] as $sidebar_id => $sidebar_settings) {
                         $settings['sidebars'][$sidebar_id] = Off_Canvas_Sidebars()->validate_settings($sidebar_settings, Off_Canvas_Sidebars()->get_default_sidebar_settings());
                     }
                 }
                 update_option($this->general_key, $settings);
                 $gocs_message = 1;
             } else {
                 $gocs_message = 2;
             }
         } else {
             $gocs_message = 3;
         }
         wp_redirect(admin_url('/themes.php?page=' . $this->plugin_key . '&tab=' . $this->importexport_tab . '&gocs_message=' . esc_attr($gocs_message)));
         exit;
     }
 }
    /**
     * Outputs the options form on admin
     *
     * @param array $instance The widget options
     * @return void
     */
    public function form($instance)
    {
        $off_canvas_sidebars = Off_Canvas_Sidebars();
        $this->load_plugin_data();
        $instance = $this->merge_settings($instance);
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id($this->widget_setting);
        ?>
"><?php 
        _e('Controls', 'off-canvas-sidebars');
        ?>
:</label>&nbsp;
			<?php 
        foreach ($this->general_settings['sidebars'] as $sidebar_id => $value) {
            if (empty($this->general_settings['sidebars'][$sidebar_id]['enable'])) {
                continue;
            }
            ?>
			<span><label for="<?php 
            echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
            ?>
"><input type="checkbox" id="<?php 
            echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
            ?>
" class="off-canvas-control-left" name="<?php 
            echo $this->get_field_name($this->widget_setting) . '[' . $sidebar_id . '][enable]';
            ?>
" value="1" <?php 
            checked($instance[$this->widget_setting][$sidebar_id]['enable'], 1);
            ?>
 /><?php 
            echo $this->general_settings['sidebars'][$sidebar_id]['label'];
            ?>
</label></span> &nbsp;
			<?php 
        }
        ?>

		</p>

		<?php 
        // If no sidebars enabled, no other fields available
        if (!$off_canvas_sidebars->is_sidebar_enabled()) {
            echo '<p>' . $this->general_labels['no_sidebars_available'] . '</p>';
        } else {
            ?>

		<hr />

		<?php 
            foreach ($this->general_settings['sidebars'] as $sidebar_id => $value) {
                if (empty($this->general_settings['sidebars'][$sidebar_id]['enable'])) {
                    continue;
                }
                $hidden = '';
                if (empty($instance[$this->widget_setting][$sidebar_id]['enable'])) {
                    $hidden = 'style="display:none;"';
                }
                ?>
		<div class="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id . '_wrapper';
                ?>
" <?php 
                echo $hidden;
                ?>
>
			<h4 class=""><?php 
                echo ucfirst($sidebar_id);
                ?>
</h4>
			<p>
				<input type="checkbox" id="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_show_label" name="<?php 
                echo $this->get_field_name($this->widget_setting) . '[' . $sidebar_id . '][show_label]';
                ?>
" value="1" <?php 
                checked($instance[$this->widget_setting][$sidebar_id]['show_label'], 1);
                ?>
>
				<label for="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_show_label"><?php 
                _e('Show label', 'off-canvas-sidebars');
                ?>
</label>
			</p>
			<p class="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_label" <?php 
                echo $instance[$this->widget_setting][$sidebar_id]['show_label'] != 1 ? 'style="display: none;"' : '';
                ?>
>
				<label for="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_label"><?php 
                _e('Label text', 'off-canvas-sidebars');
                ?>
</label>
				<input type="text" class="widefat" id="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_label" name="<?php 
                echo $this->get_field_name($this->widget_setting) . '[' . $sidebar_id . '][label]';
                ?>
" value="<?php 
                echo $instance[$this->widget_setting][$sidebar_id]['label'];
                ?>
">
			<p>
				<input type="checkbox" id="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_show_icon" name="<?php 
                echo $this->get_field_name($this->widget_setting) . '[' . $sidebar_id . '][show_icon]';
                ?>
" value="1" <?php 
                checked($instance[$this->widget_setting][$sidebar_id]['show_icon'], 1);
                ?>
>
				<label for="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_show_icon"><?php 
                _e('Show icon', 'off-canvas-sidebars');
                ?>
</label>
			</p>
			<p class="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_icon" <?php 
                echo $instance[$this->widget_setting][$sidebar_id]['show_icon'] != 1 ? 'style="display: none;"' : '';
                ?>
>
				<label for="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_icon"><?php 
                _e('Icon classes', 'off-canvas-sidebars');
                ?>
</label>
				<input type="text" class="widefat" id="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_icon" name="<?php 
                echo $this->get_field_name($this->widget_setting) . '[' . $sidebar_id . '][icon]';
                ?>
" value="<?php 
                echo $instance[$this->widget_setting][$sidebar_id]['icon'];
                ?>
">
			</p>
			<p>
				<input type="checkbox" id="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_button_class" name="<?php 
                echo $this->get_field_name($this->widget_setting) . '[' . $sidebar_id . '][button_class]';
                ?>
" value="1" <?php 
                checked($instance[$this->widget_setting][$sidebar_id]['button_class'], 1);
                ?>
>
				<label for="<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_button_class"><?php 
                _e('Add <code>button</code> class', 'off-canvas-sidebars');
                ?>
</label>
			</p>
			<hr />
		</div>
		<?php 
            }
            ?>

		<p>
			<label>Preview:</label>
			<div id="<?php 
            echo $this->id;
            ?>
-preview" class="<?php 
            echo $this->id_base;
            ?>
-preview" style="background: #f5f5f5; border: 1px solid #eee; padding: 10px;">
				<?php 
            $this->widget(array('before_widget' => '', 'after_widget' => ''), $instance);
            ?>
			</div>
		</p>

		<script type="text/javascript">
		<!--
			(function($) {
				<?php 
            foreach ($instance[$this->widget_setting] as $sidebar_id => $value) {
                ?>
				gocs_show_hide_options('<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
', '<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id . '_wrapper';
                ?>
');
				gocs_show_hide_options('<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_show_label', '<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_label');
				gocs_show_hide_options('<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_show_icon', '<?php 
                echo $this->get_field_id($this->widget_setting) . '_' . $sidebar_id;
                ?>
_icon');
				<?php 
            }
            ?>

				function gocs_show_hide_options(trigger, target) {
					trigger = $('#'+trigger);
					if ( ! trigger.is(':checked') ) {
						$('.'+target).slideUp('fast');
					}
					trigger.bind('change', function() {
						if ( $(this).is(':checked') ) {
							$('.'+target).slideDown('fast');
						} else {
							$('.'+target).slideUp('fast');
						}
					});
				}
			})( jQuery );
		-->
		</script>
		<?php 
        }
        // end fields output
        ?>
		<?php 
    }
    /**
     * Magic method to prevent a fatal error when calling a method that doesn't exist.
     *
     * @since   0.3
     * @access  public
     * @param   string
     * @param   array
     * @return  null
     */
    public function __call($method = '', $args = array())
    {
        _doing_it_wrong(get_class($this) . "::{$method}", esc_html__('Method does not exist.', 'off-canvas-sidebars'), null);
        unset($method, $args);
        return null;
    }
}
// end class
/**
 * Main instance of Off-Canvas Sidebars.
 *
 * Returns the main instance of OCS_Off_Canvas_Sidebars to prevent the need to use globals.
 *
 * @since   0.1.2
 * @return  OCS_Off_Canvas_Sidebars
 */
function Off_Canvas_Sidebars()
{
    return OCS_Off_Canvas_Sidebars::get_instance();
}
Off_Canvas_Sidebars();
 /**
  * Get plugin defaults
  */
 private function load_plugin_data()
 {
     $off_canvas_sidebars = Off_Canvas_Sidebars();
     $this->general_settings = $off_canvas_sidebars->get_settings();
 }