initialize_settings(); } add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); } /** * Add options page */ public function add_admin_page() { add_menu_page( __( 'Adv. Woo Search', 'aws' ), __( 'Adv. Woo Search', 'aws' ), 'manage_options', 'aws-options', array( &$this, 'display_admin_page' ), 'dashicons-search' ); } /** * Generate and display options page */ public function display_admin_page() { $options = $this->options_array(); $tabs = array( 'general' => __( 'General', 'aws' ), 'form' => __( 'Search Form', 'aws' ), 'results' => __( 'Search Results', 'aws' ) ); $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] ); $tabs_html = ''; foreach ( $tabs as $name => $label ) { $tabs_html .= '' . $label . ''; } $tabs_html .= '' . __( 'Get Premium', 'aws' ) . ''; $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 ); do_action( 'aws_settings_saved' ); } echo '
'; echo $tabs_html; echo '
'; echo ''; echo ''; switch ($current_tab) { case('form'): $this->generate_options( $options['form'] ); break; case('results'): $this->generate_options( $options['results'] ); break; default: $this->update_table(); $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 ) { ?> >









'; echo '' . __( 'Reindex table', 'aws' ) . ''; echo ''; echo '
0%


'; echo '' . __( 'Update all data in plugins index table. Index table - table with products data where plugin is searching all typed terms.
Use this button if you think that plugin not shows last actual data in its search results.
CAUTION: this can take large amount of time.', 'aws' ) . '

' . __( 'Products in index:', 'aws' ) . ' ' . AWS_Helpers::get_indexed_products_count() . ''; echo '
'; echo ''; echo ''; echo ''; echo '' . __( 'Clear cache', 'aws' ) . ''; echo ''; echo '

'; echo '' . __( 'Clear cache for all search results.', 'aws' ) . ''; echo ''; echo ''; } /* * Options array that generate settings page */ public function options_array() { require_once AWS_DIR .'/includes/options.php'; return $options; } /* * Register plugin settings */ public function register_settings() { register_setting( 'aws_settings', 'aws_settings' ); } /* * Get plugin settings */ public function get_settings() { $plugin_options = get_option( 'aws_settings' ); return $plugin_options; } /** * Initialize settings to their default values */ public function initialize_settings() { $options = $this->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 ); } /* * 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', array(), AWS_VERSION ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'plugin-admin-scripts', AWS_URL . '/assets/js/admin.js', array('jquery'), AWS_VERSION ); wp_localize_script( 'plugin-admin-scripts', 'aws_vars', array( 'ajaxurl' => admin_url('admin-ajax.php' ) ) ); } } } endif; new AWS_Admin();