sprintf( __( '%s (inactive)', 'swatchline' ), $current ) ) + $types; } $html = ''; } private static function description(): string { return __( 'How the values show on the product page. Set a colour or image for each value under Configure terms. Dropdown leaves WooCommerce\'s own dropdown.', 'swatchline' ); } public function add_field(): void { echo '
'; echo self::select( 'select' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in select(). echo '

' . esc_html( self::description() ) . '

'; } public function edit_field(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- which attribute the screen edits. $id = isset( $_GET['edit'] ) ? absint( wp_unslash( $_GET['edit'] ) ) : 0; echo ''; echo self::select( $id ? Swatches::attribute_type( $id ) : 'select' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in select(). echo '

' . esc_html( self::description() ) . '

'; } /** The posted type, when the form was posted with the given nonce action; null otherwise. */ private static function posted( string $action ): ?string { if ( ! isset( $_POST[ self::FIELD ], $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), $action ) ) { return null; } if ( ! current_user_can( 'manage_product_terms' ) ) { return null; } return sanitize_key( wp_unslash( $_POST[ self::FIELD ] ) ); } /** @param int $id */ public function added( $id ): void { $type = self::posted( 'woocommerce-add-new_attribute' ); if ( null !== $type ) { Swatches::set_attribute_type( (int) $id, $type ); } } /** @param int $id */ public function updated( $id ): void { $type = self::posted( 'woocommerce-save-attribute_' . (int) $id ); if ( null !== $type ) { Swatches::set_attribute_type( (int) $id, $type ); } } /** @param int $id */ public function deleted( $id ): void { Swatches::set_attribute_type( (int) $id, 'select' ); } }