_real_escape( $string ); $sql = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '%$search%'"; $results = $wpdb->get_results( $sql, ARRAY_A ); return $results; } } if( !function_exists('WP_Improved_Settings\wpimpsettings_find_option_like') ){ function wpimpsettings_find_option_like( $string ) { // ugly hack to fetch plugin_name_index options global $wpdb; $search = $wpdb->_real_escape( $string ); $sql = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '$search%'"; $results = $wpdb->get_results( $sql, ARRAY_A ); $return = array(); if( $results ) foreach ( $results as $result ) { $name = str_replace($string .'_', '', $result['option_name'] ); $explode = explode('_', $name ); $value = $result['option_value']; $return[$explode[0]][$explode[1]] = $value; } return $return; } } if ( !class_exists( 'WP_Improved_Settings\WP_Improved_Settings' ) ) { class WP_Improved_Settings { // loosely based on wc-dynamic-pricing-and-discounts/classes/rp-wcdpd-settings.class.php public $settingsStructure = array(); public $extendedActions = array(); public $plugins_paths = array(); public $WC_Improved_Settings_API; public $isMainMenu = false; public $plugin_id; public $menu_order = 20; public $minimum_capability = 'manage_options'; public $option_page = ''; public $defaultSettingsTab = ''; public $parent_menu = ''; public $post_type = false; /*Dashboard: 'index.php' Posts: 'edit.php' Media: 'upload.php' Pages: 'edit.php?post_type=page' Comments: 'edit-comments.php' Custom Post Types: 'edit.php?post_type=your_post_type' Appearance: 'themes.php' Plugins: 'plugins.php' Users: 'users.php' Tools: 'tools.php' Settings: 'options-general.php' Network Settings: 'settings.php' WooCommerce : 'woocommerce' */ public function __construct() { // Register settings add_action( 'admin_init', array( $this, 'loadSettings' ) ); add_action( 'admin_init', array( $this, 'registerSettings' ) ); $this->plugins_paths = apply_filters('zebench_plugins_paths', array() ); // Add link to menu global $wp_filter; $real_order = $this->menu_order; while( isset( $wp_filter['admin_menu']->callbacks[$real_order] ) ) { $real_order++; } add_action( 'admin_menu', array( $this, 'addToMenu' ), $real_order ); // Pass configuration to Javascript //add_action( 'admin_enqueue_scripts', array( $this, 'configuration_to_javascript' ), 999 ); // Enqueue templates to be rendered in footer //add_action( 'admin_footer', array( $this, 'render_templates_in_footer' ) ); // Settings export call if ( !empty( $_REQUEST['export_settings'] ) ) { add_action( 'wp_loaded', array( $this, 'export' ) ); } // Settings import call if ( !empty( $_FILES[$this->option_page]['name']['import'] ) ) { add_action( 'wp_loaded', array( $this, 'import' ) ); } // Print settings import notice if ( isset( $_REQUEST[$this->option_page .'_imported'] ) ) { add_action( 'admin_notices', array( $this, 'print_import_notice' ) ); } if ( !class_exists( 'WP_Improved_Settings\WC_Improved_Settings_API' )) { require_once( dirname( __FILE__ ) . '/wp-improved-settings-api.class.php' ); } $this->WC_Improved_Settings_API = new WC_Improved_Settings_API( $this->getPluginID(), $this->getSettingsStructure() ); $key_name = $this->plugin_id . '_options_save'; if ( isset( $_REQUEST['save'] ) && isset( $_REQUEST[$key_name] ) && $_REQUEST[$key_name] ) { $this->saveSettings(); // echo " saving"; if ( method_exists( $this, 'on_save' ) ) { // echo "on save update"; $this->on_save(); } add_action( 'admin_notices', array( $this, 'print_saved_notice' ) ); } add_action( 'admin_notices', array( $this, 'maybe_print_notices' ) ); // Migration notices //add_action( 'admin_notices', array( $this, 'maybe_display_migration_notice' ), 1 ); // Delete migration notice //$this->hide_migration_notice(); } function getPluginID() { return $this->plugin_id; } function getOptionPage() { return $this->option_page; } function getMinimumCapability() { return $this->minimum_capability; } function saveSettings() { $nonce = isset( $_REQUEST['_zenonce'] ) ? $_REQUEST['_zenonce'] : false; if ( ! wp_verify_nonce( $nonce, 'zesave_settings' ) ) { $error_msg = __( 'Unable to submit this form, please refresh and try again.' ); return; } $this->WC_Improved_Settings_API->process_admin_options(); //$this->process_admin_options(); } /* function me() { $this->loadSettings(); $this->WC_Improved_Settings_API = WC_Improved_Settings_API( $this->getPluginID(), $this->getSettingsStructure() ); return $this->WC_Improved_Settings_API->process_admin_options(); }*/ function maybe_print_notices() { } function print_saved_notice() { ?>