Settings_Page.php
199 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Square |
| 4 | * |
| 5 | * This source file is subject to the GNU General Public License v3.0 |
| 6 | * that is bundled with this package in the file license.txt. |
| 7 | * It is also available through the world-wide-web at this URL: |
| 8 | * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later |
| 9 | * If you did not receive a copy of the license and are unable to |
| 10 | * obtain it through the world-wide-web, please send an email |
| 11 | * to license@woocommerce.com so we can send you a copy immediately. |
| 12 | * |
| 13 | * DISCLAIMER |
| 14 | * |
| 15 | * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer |
| 16 | * versions in the future. If you wish to customize WooCommerce Square for your |
| 17 | * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/ |
| 18 | * |
| 19 | * @author WooCommerce |
| 20 | * @copyright Copyright: (c) 2019, Automattic, Inc. |
| 21 | * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later |
| 22 | */ |
| 23 | |
| 24 | namespace WooCommerce\Square\Admin; |
| 25 | |
| 26 | defined( 'ABSPATH' ) || exit; |
| 27 | |
| 28 | use WooCommerce\Square; |
| 29 | |
| 30 | /** |
| 31 | * The settings page class. |
| 32 | * |
| 33 | * @see \WooCommerce\Square\Settings handles settings registration |
| 34 | * |
| 35 | * @since 2.0.0 |
| 36 | */ |
| 37 | class Settings_Page extends \WC_Settings_Page { |
| 38 | |
| 39 | |
| 40 | /** @var Square\Settings settings handler instance */ |
| 41 | protected $settings_handler; |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * Constructs the settings page. |
| 46 | * |
| 47 | * @since 2.0.0 |
| 48 | * |
| 49 | * @param Square\Settings $settings_handler a settings handler instance, for displaying and saving the settings |
| 50 | */ |
| 51 | public function __construct( Square\Settings $settings_handler ) { |
| 52 | |
| 53 | $this->id = Square\Plugin::PLUGIN_ID; |
| 54 | $this->label = __( 'Square', 'woocommerce-square' ); |
| 55 | $this->settings_handler = $settings_handler; |
| 56 | |
| 57 | parent::__construct(); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Outputs the settings page. |
| 63 | * |
| 64 | * @internal |
| 65 | * |
| 66 | * @since 2.0.0 |
| 67 | */ |
| 68 | public function output() { |
| 69 | global $current_section; |
| 70 | |
| 71 | if ( 'update' === $current_section ) { |
| 72 | $this->output_update_section(); |
| 73 | } else { |
| 74 | $this->output_general_section(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * Outputs the general settings section. |
| 81 | * |
| 82 | * @since 2.0.0 |
| 83 | */ |
| 84 | private function output_general_section() { |
| 85 | |
| 86 | $this->settings_handler->admin_options(); |
| 87 | self::output_import_products_modal_template(); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /** |
| 92 | * Outputs the "Update" settings section. |
| 93 | * |
| 94 | * @since 2.0.0 |
| 95 | */ |
| 96 | private function output_update_section() { |
| 97 | global $hide_save_button; |
| 98 | |
| 99 | // removes the save/update button from the screen |
| 100 | $hide_save_button = true; |
| 101 | |
| 102 | Sync_Page::output(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /** |
| 107 | * Saves the settings. |
| 108 | * |
| 109 | * @internal |
| 110 | * |
| 111 | * @since 2.0.0 |
| 112 | */ |
| 113 | public function save() { |
| 114 | |
| 115 | $this->settings_handler->process_admin_options(); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * Gets the settings. |
| 121 | * |
| 122 | * @since 2.0.0 |
| 123 | * |
| 124 | * @return array |
| 125 | */ |
| 126 | public function get_settings() { |
| 127 | |
| 128 | return (array) apply_filters( 'woocommerce_get_settings_square', $this->settings_handler->get_form_fields() ); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | /** |
| 133 | * Gets the settings sections. |
| 134 | * |
| 135 | * @internal |
| 136 | * |
| 137 | * @since 2.0.0 |
| 138 | * |
| 139 | * @return array |
| 140 | */ |
| 141 | public function get_sections() { |
| 142 | |
| 143 | $sections = array( |
| 144 | '' => __( 'Settings', 'woocommerce-square' ), // this key is intentionally blank |
| 145 | 'update' => __( 'Update', 'woocommerce-square' ), |
| 146 | ); |
| 147 | |
| 148 | /** |
| 149 | * Filters the WooCommerce Square settings sections. |
| 150 | * |
| 151 | * @since 2.0.0 |
| 152 | * |
| 153 | * @param array $sections settings sections |
| 154 | */ |
| 155 | return (array) apply_filters( 'woocommerce_get_sections_square', $sections ); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | /** |
| 160 | * Outputs a backbone modal template for importing products from Square. |
| 161 | * |
| 162 | * @since 2.0.0 |
| 163 | */ |
| 164 | private static function output_import_products_modal_template() { |
| 165 | |
| 166 | ?> |
| 167 | <script type="text/template" id="tmpl-wc-square-import-products"> |
| 168 | <div class="wc-backbone-modal"> |
| 169 | <div class="wc-backbone-modal-content"> |
| 170 | <section class="wc-backbone-modal-main" role="main"> |
| 171 | <header class="wc-backbone-modal-header"> |
| 172 | <h1><?php esc_html_e( 'Import Products From Square', 'woocommerce-square' ); ?></h1> |
| 173 | <button class="modal-close modal-close-link dashicons dashicons-no-alt"> |
| 174 | <span class="screen-reader-text"><?php esc_html_e( 'Close modal window', 'woocommerce-square' ); ?></span> |
| 175 | </button> |
| 176 | </header> |
| 177 | <article> |
| 178 | <p><?php esc_html_e( 'You are about to import all new products, variations and categories from Square. This will create a new product in WooCommerce for every product retrieved from Square. If you have products in the trash from the previous imports, these will be ignored in the import.', 'woocommerce-square' ); ?></p> |
| 179 | <hr> |
| 180 | <h4><?php esc_html_e( 'Do you wish to import existing product updates from Square?', 'woocommerce-square' ); ?></h4> |
| 181 | <?php /* translators: Placeholders: %1$s - <a> tag linking to WooCommerce Square docs, %2%s - closing </a> tag */ ?> |
| 182 | <p><?php printf( esc_html__( 'Doing so will update existing WooCommerce products with the latest information from Square. %1$sView Documentation%2$s.', 'woocommerce-square' ), '<a href="https://docs.woocommerce.com/document/woocommerce-square/#section-4">', '</a>' ); ?></p> |
| 183 | <label for="wc-square-import-product-updates"><input type="checkbox" id="wc-square-import-product-updates" /><?php esc_html_e( 'Update existing products during import.', 'woocommerce-square' ); ?></label> |
| 184 | </article> |
| 185 | <footer> |
| 186 | <div class="inner"> |
| 187 | <button id="btn-close" class="button button-large"><?php esc_html_e( 'Cancel', 'woocommerce-square' ); ?></button> |
| 188 | <button id="btn-ok" class="button button-large button-primary"><?php esc_html_e( 'Import Products', 'woocommerce-square' ); ?></button> |
| 189 | </div> |
| 190 | </footer> |
| 191 | </section> |
| 192 | </div> |
| 193 | </div> |
| 194 | <div class="wc-backbone-modal-backdrop modal-close"></div> |
| 195 | </script> |
| 196 | <?php |
| 197 | } |
| 198 | } |
| 199 |