%s', esc_url( admin_url( 'admin.php?page=' . self::PAGE_SLUG ) ), esc_html__( 'Settings', 'aam-partial-cod' ) ); array_unshift( $links, $link ); return $links; } /** * Register the settings page as a WooCommerce submenu. */ public function register_page() { add_submenu_page( 'woocommerce', __( 'BD COD Visibility', 'aam-partial-cod' ), __( 'BD COD Visibility', 'aam-partial-cod' ), 'manage_woocommerce', self::PAGE_SLUG, array( $this, 'render_page' ) ); } /** * Register the visibility option with the Settings API. */ public function register_settings() { register_setting( self::SETTINGS_GROUP, BD_PCOD_Helpers::OPTION_VISIBILITY, array( 'type' => 'array', 'sanitize_callback' => array( $this, 'sanitize' ), 'default' => array(), ) ); } /** * Sanitize posted toggles into a structured array, filling absent (unchecked) * boxes with 0 so every known gateway/method has an explicit value. * * @param mixed $input Raw posted value. * @return array{gateways:array,methods:array} */ public function sanitize( $input ) { $input = is_array( $input ) ? $input : array(); $in_gates = isset( $input['gateways'] ) ? (array) $input['gateways'] : array(); $in_meths = isset( $input['methods'] ) ? (array) $input['methods'] : array(); $clean = array( 'gateways' => array(), 'methods' => array(), ); foreach ( array_keys( BD_PCOD_Helpers::gateways() ) as $gateway_id ) { $clean['gateways'][ $gateway_id ] = empty( $in_gates[ $gateway_id ] ) ? 0 : 1; } foreach ( array_keys( BD_PCOD_Helpers::get_methods_config() ) as $method ) { $clean['methods'][ $method ] = empty( $in_meths[ $method ] ) ? 0 : 1; } return $clean; } /** * Render the settings page. */ public function render_page() { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } ?>

$config ) : ?>