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' ) . + '

'; + + } else { + + $this->message = + '

' . + __( 'Can not save settings! Please refresh this page.', 'woocommerce-for-vietnam' ) . + '

'; + } + } + + /** + * Register the sub-menu under "WooCommerce" + * Link: http://my-site.com/wp-admin/admin.php?page=woocommerce-for-vietnam + */ public function register_submenu_page() { add_submenu_page( 'woocommerce', @@ -35,25 +67,9 @@ class WooViet_Admin_Page { ); } - 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') . - '

' - ; - - } else { - - $this->message = - '

' . - __('Please refresh this page. Can not save settings!', 'woocommerce-for-vietnam') . - '

' - ; - } - } + /** + * Generate the HTML code of the settings page + */ public function admin_page_html() { // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { @@ -61,102 +77,138 @@ class WooViet_Admin_Page { } $settings = WooViet::get_settings(); - //var_dump($settings); exit; - ?> -
-

-
+
+

+ message ?> - - - - - - - - + + +
- - > - -
+ + + + + - - - - - - - + + + + + + - - - - + + + + - - -
+ + > + +
- - > - -
-
- - -
000 of prices to K (or anything)', 'woocommerce-for-vietnam')?> - - > - +
+ + > + +
+
+ + +
000 of prices to K (or anything)', 'woocommerce-for-vietnam' ) ?> + + > + -

- - -
-
the Paypal Standard gateway','woocommerce-for-vietnam'), 'https://docs.woocommerce.com/document/paypal-standard/') ?> - - > - +

+ + +
+
the Paypal Standard gateway', 'woocommerce-for-vietnam' ), 'https://docs.woocommerce.com/document/paypal-standard/' ) ?> + + > + -

- %1$s', $currency); + if ( strtoupper( $currency ) == $settings['vnd_paypal_standard']['currency'] ) { + printf( '', $currency ); } else { - printf('', $currency); + printf( '', $currency ); } } ?> - - -
-
+ + +
+
- -
+ + -
+ + + + -

- -

+

+ +

- -