initialize_settings(); } add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); } /** * Add options page */ public function add_admin_page() { add_options_page( __( 'Advanced Woo Search', 'aws' ), __( 'Advanced Woo Search', 'aws' ), 'manage_options', 'aws-options', array( &$this, 'display_admin_page' ) ); } /** * Generate and display options page */ public function display_admin_page() { $options = $this->options_array(); $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $tabs = array( 'general' => __( 'General', 'aws' ), //'query' => __( 'Query', 'aws' ), //'view' => __( 'View', 'aws' ) ); $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] ); $tabs_html = ''; foreach ( $tabs as $name => $label ) { $tabs_html .= '' . $label . ''; } $tabs_html = ''; if( isset( $_POST["Submit"] ) ) { $update_settings = $this->get_settings(); foreach ( $options[$current_tab] as $values ) { if ( $values['type'] === 'heading' ) { continue; } if ( $values['type'] === 'checkbox' ) { $checkbox_array = array(); foreach ( $values['choices'] as $key => $value ) { $new_value = isset( $_POST[ $values['id'] ][$key] ) ? '1' : '0'; $checkbox_array[$key] = $new_value; } $update_settings[ $values['id'] ] = $checkbox_array; continue; } $new_value = isset( $_POST[ $values['id'] ] ) ? $_POST[ $values['id'] ] : ''; $update_settings[ $values['id'] ] = $new_value; if ( isset( $values['sub_option'] ) ) { $new_value = isset( $_POST[ $values['sub_option']['id'] ] ) ? $_POST[ $values['sub_option']['id'] ] : ''; $update_settings[ $values['sub_option']['id'] ] = $new_value; } } update_option( 'aws_settings', $update_settings ); } echo '
'; echo $tabs_html; echo '
'; echo ''; echo ''; switch ($current_tab) { case('query'): $this->generate_options( $options['query'] ); break; case('view'): $this->generate_options( $options['view'] ); break; default: $this->generate_options( $options['general'] ); } echo ''; echo '
'; echo '

'; echo '
'; echo '
'; } /** * Generate options */ public function generate_options( $options ) { $plugin_options = get_option( 'aws_settings' ); if ( empty( $options ) ) { return; } foreach ( $options as $k => $value ) { switch ( $value['type'] ) { case 'text': ?>



$label ) { ?> >

$label ) { ?> >







options_array(); $default_settings = array(); foreach ( $options as $section ) { foreach ($section as $values) { if ( $values['type'] === 'heading' ) { continue; } $default_settings[$values['id']] = $values['value']; if (isset( $values['sub_option'])) { $default_settings[$values['sub_option']['id']] = $values['sub_option']['value']; } } } update_option( 'aws_settings', $default_settings ); } /* * Add settings link to plugins */ public function add_settings_link( $links, $file ) { $plugin_base = plugin_basename( __FILE__ ); if ( $file == $plugin_base ) { $setting_link = ''.__( 'Settings', 'aws' ).''; array_unshift( $links, $setting_link ); } return $links; } /* * Enqueue admin scripts and styles */ public function admin_enqueue_scripts() { if ( isset( $_GET['page'] ) && $_GET['page'] == 'aws-options' ) { wp_enqueue_style( 'plugin-admin-style', AWS_URL . '/assets/css/admin.css' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-sortable' ); } } } endif; new AWS_Admin();