diff --git a/inc/class-wooviet-admin-page.php b/inc/class-wooviet-admin-page.php index 6c9d500..9fe3477 100644 --- a/inc/class-wooviet-admin-page.php +++ b/inc/class-wooviet-admin-page.php @@ -13,17 +13,49 @@ if ( ! defined( 'ABSPATH' ) ) { */ class WooViet_Admin_Page { + /** + * @var string The message to display after saving settings + */ var $message = ''; + /** + * WooViet_Admin_Page constructor. + */ public function __construct() { - - if (isset($_REQUEST['wooviet_nonce']) && isset ($_REQUEST['action']) && 'wooviet_save_settings' == $_REQUEST['action']) + // Catch and run the save_settings() action + if ( isset( $_REQUEST['wooviet_nonce'] ) && isset ( $_REQUEST['action'] ) && 'wooviet_save_settings' == $_REQUEST['action'] ) { $this->save_settings(); + } - add_action('admin_menu', array($this, 'register_submenu_page')); + add_action( 'admin_menu', array( $this, 'register_submenu_page' ) ); } + /** + * Save settings for the plugin + */ + public function save_settings() { + if ( wp_verify_nonce( $_REQUEST['wooviet_nonce'], 'wooviet_save_settings' ) ) { + update_option( 'woocommerce-for-vietnam', $_REQUEST['settings'] ); + + $this->message = + '
' . + __( 'Settings saved', 'woocommerce-for-vietnam' ) . + '
' . + __( 'Can not save settings! Please refresh this page.', 'woocommerce-for-vietnam' ) . + '
' . - __('Settings saved', 'woocommerce-for-vietnam') . - '
' . - __('Please refresh this page. Can not save settings!', 'woocommerce-for-vietnam') . - '