Ejemplo n.º 1
0
 function test_delete_all_settings()
 {
     update_option(WC_POS_Admin_Settings::DB_PREFIX . 'test1', 'dummy');
     update_option(WC_POS_Admin_Settings::DB_PREFIX . 'test2', 'dummy');
     WC_POS_Admin_Settings::delete_all_settings();
     global $wpdb;
     $prefix = WC_POS_Admin_Settings::DB_PREFIX;
     $rows = $wpdb->get_var("\n      SELECT COUNT(*) FROM {$wpdb->options}\n      WHERE option_name\n      LIKE '{$prefix}%'");
     $this->assertEquals($rows, 0);
 }
 /**
  * Add Settings page to admin menu
  */
 public function admin_menu()
 {
     self::$screen_id = add_submenu_page(WC_POS_PLUGIN_NAME, __('Settings'), __('Settings'), 'manage_woocommerce_pos', 'wc_pos_settings', array($this, 'display_settings_page'));
 }
/**
 * @param $id
 * @param $key
 * @return bool
 */
function wc_pos_get_option($id, $key = false)
{
    $handlers = (array) WC_POS_Admin_Settings::handlers();
    if (!array_key_exists($id, $handlers)) {
        return false;
    }
    $settings = $handlers[$id]::get_instance();
    return $settings->get($key);
}
 private function process_admin_settings()
 {
     // validate
     if (!isset($_GET['id'])) {
         return new WP_Error('woocommerce_pos_settings_error', __('There is no settings id', 'woocommerce-pos'), array('status' => 400));
     }
     $id = $_GET['id'];
     $data = WC_POS_Server::get_raw_data();
     // special case: gateway_
     $gateway_id = preg_replace('/^gateway_/', '', strtolower($id), 1, $count);
     if ($count) {
         $handler = new WC_POS_Admin_Settings_Gateways($gateway_id);
         // else, find handler by id
     } else {
         $handlers = (array) WC_POS_Admin_Settings::handlers();
         if (!isset($handlers[$id])) {
             return new WP_Error('woocommerce_pos_settings_error', sprintf(__('No handler found for %s settings', 'woocommerce-pos'), $_GET['id']), array('status' => 400));
         }
         $handler = new $handlers[$id]();
     }
     // Compatibility for clients that can't use PUT/PATCH/DELETE
     $method = strtoupper($_SERVER['REQUEST_METHOD']);
     if (isset($_GET['_method'])) {
         $method = strtoupper($_GET['_method']);
     } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
     }
     // get
     if ($method === 'GET') {
         return $handler->get();
     }
     // set
     if ($method === 'POST' || $method === 'PUT') {
         return $handler->set($data);
     }
     // delete
     if ($method === 'DELETE') {
         return $handler->delete($data);
     }
     return new WP_Error('woocommerce_pos_cannot_' . $method . '_' . $id, __('Settings error', 'woocommerce-pos'), array('status' => 405));
 }
/**
 * @param $id
 * @param $key
 * @return bool
 */
function wc_pos_get_option($id, $key = false)
{
    $handlers = (array) WC_POS_Admin_Settings::handlers();
    if (!array_key_exists($id, $handlers)) {
        return false;
    }
    // Singleton class uses late static binding, ie: PHP 5.3+
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        $settings = $handlers[$id]::get_instance();
    } else {
        $settings = new $handlers[$id]();
    }
    return $settings->get($key);
}