generalFields = [ [ 'id' => 'active-button', 'label' => __('Show button on checkout', "ws-inpost-map"), 'description' => '', 'type' => 'checkbox', ] ]; $this->fields = [ [ 'id' => 'button-font-size', 'label' => __('Button font size', "ws-inpost-map"), 'description' => '', 'type' => 'number', 'default' => "12", ], [ 'id' => 'button-font-weight', 'label' => __('Button font weight', "ws-inpost-map"), 'description' => '', 'type' => 'select', 'options' => [ "100" => "Thin", "200" => "Extra Light", "300" => "Light", "400" => "Normal", "500" => "Medium", "600" => "Semi Bold", "700" => "Bold", "800" => "Extra Bold ", "900 " => "Heavy", ], 'default' => "400", ], [ 'id' => 'button-text-color', 'label' => __('Button text color', "ws-inpost-map"), 'description' => '', 'type' => 'color', 'default' => "#ffffff", ], [ 'id' => 'button-background-color', 'label' => __('Button background color', "ws-inpost-map"), 'description' => '', 'type' => 'color', 'default' => "#000000", ], [ 'id' => 'button-padding', 'label' => __('Button padding', "ws-inpost-map"), 'description' => '', 'type' => 'number', 'default' => "10", ], [ 'id' => 'button-border', 'label' => __('Border on button', "ws-inpost-map"), 'description' => '', 'type' => 'checkbox', ], [ 'id' => 'button-border-color', 'label' => __('Button border color', "ws-inpost-map"), 'description' => '', 'type' => 'color', 'default' => "#000000", ], [ 'id' => 'button-border-size', 'label' => __('Button border size', "ws-inpost-map"), 'description' => '', 'type' => 'number', 'default' => "2", ], [ 'id' => 'button-border-radius', 'label' => __('Button border radius', "ws-inpost-map"), 'description' => '', 'type' => 'number', 'default' => "10", ], [ 'id' => 'button-opacity-value', 'label' => __('Button opacity on hover value (value / 100)', "ws-inpost-map"), 'description' => '', 'type' => 'number', 'default' => "100", ], [ 'id' => 'button-text-color-hover', 'label' => __('Button text color on hover', "ws-inpost-map"), 'description' => '', 'type' => 'color', 'default' => "#000000", ], [ 'id' => 'button-background-color-hover', 'label' => __('Button background color on hover', "ws-inpost-map"), 'description' => '', 'type' => 'color', 'default' => "#ffffff", ] ]; add_action('admin_init', [$this, 'settings_init']); add_action('admin_menu', [$this, 'options_page']); add_action('woocommerce_after_checkout_form', [$this, 'addCustomStyles']); add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); } public function saveDefaultData() { $fieldsToSaveInWpOptions = []; foreach ($this->fields as $field) { if (isset($field['default'])) { $fieldsToSaveInWpOptions[$field['id']] = $field['default']; } } if (false === get_option(self::WSINPOST_SETTINGS_KEY)) { update_option(self::WSINPOST_SETTINGS_KEY, $fieldsToSaveInWpOptions); } } public function admin_enqueue_scripts($screen) { if ('toplevel_page_ws-inpost-settings' !== $screen) return; wp_enqueue_script('ws-inpost-settings-js', WSIM_INPOST_MAP_PLUGIN_DIR_URL . 'assets/js/admin/sections.js', array(), false, true); wp_enqueue_style('ws-inpost-settings-style', WSIM_INPOST_MAP_PLUGIN_DIR_URL . 'assets/css/admin/sections.css'); } /** * Register the settings and all fields. * * @return void */ public function settings_init(): void { register_setting('ws-inpost-settings', self::WSINPOST_SETTINGS_KEY); add_settings_section( 'ws-inpost-general-section', __('General', 'ws-inpost-map'), [$this, 'render_section'], 'ws-inpost-settings' ); add_settings_section( 'ws-inpost-button-section', __('Button', 'ws-inpost-map'), [$this, 'render_section'], 'ws-inpost-settings' ); add_settings_section( 'ws-licence-section', __('Pro Version', 'ws-inpost-map'), [$this, 'renderLicenceSection'], 'ws-inpost-settings' ); $this->addSettingFields($this->generalFields, [$this, 'render_field'], 'ws-inpost-settings', 'ws-inpost-general-section'); $this->addSettingFields($this->fields, [$this, 'render_field'], 'ws-inpost-settings', 'ws-inpost-button-section'); } public function addSettingFields($fields, $callback, $manuPage, $section) { foreach ($fields as $field) { add_settings_field( $field['id'], $field['label'], $callback, $manuPage, $section, [ 'label_for' => $field['id'], 'class' => 'wporg_row', 'field' => $field, ] ); } } /** * Add a subpage to the WordPress Settings menu. */ public function options_page(): void { add_menu_page( 'Settings', __('WS Inpost Settings', "ws-inpost-map"), $this->capability, 'ws-inpost-settings', [$this, 'render_options_page'], 'dashicons-location', '80', ); } /** * Render the settings page. */ public function render_options_page(): void { if (!current_user_can($this->capability)) { return; } if (isset($_GET['settings-updated'])) { add_settings_error('ws_messages', 'ws_message', __('Settings Saved', 'ws-inpost-map'), 'updated'); } global $wp_settings_sections; if (isset($_GET['page']) && sanitize_text_field($_GET['page']) === "ws-inpost-settings") { $page = sanitize_text_field($_GET['page']); $sections = $wp_settings_sections[$page]; } else { return; } ?>
>
self::WSINPOST_SETTINGS_KEY[$field["id"]], 'textarea_rows' => 5, ) ); break; } case "email": { ?>