'string', 'sanitize_callback' => $sanitize_token, 'show_in_rest' => false, 'default' => '', )); register_setting('affilibee_settings_group', 'affilibee_api_test_token', array( 'type' => 'string', 'sanitize_callback' => $sanitize_token, 'show_in_rest' => false, 'default' => '', )); register_setting('affilibee_settings_group', 'affilibee_test_mode', array( 'type' => 'string', 'sanitize_callback' => $sanitize_yesno, 'show_in_rest' => false, 'default' => 'no', )); } /** * Render the Affilibee settings tab. */ public static function render(): void { if (!current_user_can(self::cap())) { wp_die(esc_html__('Sorry, you are not allowed to access this page.', 'affilibee-for-woocommerce')); } woocommerce_admin_fields(self::get_wc_settings_fields()); } /** * Add our tab to Woo settings. */ public static function add_woocommerce_settings_tab(array $tabs): array { if (current_user_can(self::cap())) { $tabs['affilibee'] = __('Affilibee', 'affilibee-for-woocommerce'); } return $tabs; } /** * Save settings from the tab. */ public static function save(): void { if (!current_user_can(self::cap())) { wp_die(esc_html__('Insufficient permissions.', 'affilibee-for-woocommerce')); } check_admin_referer('woocommerce-settings'); woocommerce_update_options(self::get_wc_settings_fields()); } /** * Define fields rendered by Woo's settings API. */ private static function get_wc_settings_fields(): array { $intro1 = sprintf( /* translators: %s: Affilibee website URL */ __('This plugin integrates Affilibee with WooCommerce. To get started, you’ll need a merchant account on affilibee.com.', 'affilibee-for-woocommerce'), esc_url(Affilibee_Config::AFFILIBEE_URL) ); $intro2 = sprintf( /* translators: %s: documentation URL */ __('Follow the installation instructions in our documentation.', 'affilibee-for-woocommerce'), esc_url(Affilibee_Config::AFFILIBEE_DOC_URL) ); $fields = array( array( 'title' => __('Affilibee Settings', 'affilibee-for-woocommerce'), 'type' => 'title', 'id' => 'affilibee_settings_section', ), array( 'type' => 'title', 'id' => 'affilibee_intro', 'desc' => wp_kses_post('
' . $intro1 . '
' . $intro2 . '
'), ), array( 'title' => __('Test Mode', 'affilibee-for-woocommerce'), 'id' => 'affilibee_test_mode', 'type' => 'checkbox', 'label' => __('Enable Test Mode', 'affilibee-for-woocommerce'), 'desc' => __('When enabled, requests use the API Test Token. Test Mode requests appear in Affilibee’s request log but are not recorded as orders. Use this to verify your setup before going live.', 'affilibee-for-woocommerce'), 'default' => 'no', 'desc_tip' => true, ), array( 'title' => __('API Token', 'affilibee-for-woocommerce'), 'id' => 'affilibee_api_token', 'type' => 'text', 'desc' => __('Enter your Affilibee API Token.', 'affilibee-for-woocommerce'), ), array( 'title' => __('API Test Token', 'affilibee-for-woocommerce'), 'id' => 'affilibee_api_test_token', 'type' => 'text', 'desc' => __('Enter your Affilibee API Test Token.', 'affilibee-for-woocommerce'), ), array( 'type' => 'sectionend', 'id' => 'affilibee_settings_section', ), ); /** * Allow extensions to add/remove settings fields. * * @param array $fields */ return apply_filters('affilibee_settings_fields', $fields); } /** * Show helpful notices about test mode and missing tokens (admins only). */ public static function check_api_token(): void { if (!current_user_can(self::cap())) { return; } $settings_url = admin_url('admin.php?page=wc-settings&tab=affilibee'); $is_test_mode = (get_option('affilibee_test_mode', 'no') === 'yes'); $option_key = $is_test_mode ? 'affilibee_api_test_token' : 'affilibee_api_token'; $token_value = (string) get_option($option_key, ''); if ($is_test_mode) { echo ''; printf( /* translators: %s: settings URL */ esc_html__('Affilibee is currently running in Test Mode. Remember to disable it in the %s when you finish testing.', 'affilibee-for-woocommerce'), sprintf( '%s', esc_url($settings_url), esc_html__('Affilibee settings', 'affilibee-for-woocommerce') ) ); echo '
'; printf( /* translators: 1: token label, 2: settings URL */ esc_html__('Please enter your %1$s in the %2$s to finalize the setup.', 'affilibee-for-woocommerce'), esc_html($label), sprintf( '%s', esc_url($settings_url), esc_html__('Affilibee settings', 'affilibee-for-woocommerce') ) ); echo '