true ) ); wp_register_script( 'btdon-editor', BTDON_URL . 'blocks/editor.js', array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'wp-server-side-render' ), asset_version( 'blocks/editor.js' ), array( 'in_footer' => true ) ); wp_set_script_translations( 'btdon-editor', 'ibanbox', BTDON_DIR . 'languages' ); register_block_type( BTDON_DIR . 'blocks/details' ); } ); add_action( 'enqueue_block_editor_assets', static function () { wp_add_inline_script( 'btdon-editor', 'window.btdonChoices = ' . wp_json_encode( editor_choices() ) . ';', 'before' ); } ); /** * Default text for each editable label of the block, used while the block attribute is empty. * * @param bool $has_link Whether online donation buttons are shown above the bank details. */ function default_labels( bool $has_link ): array { return array( 'heading' => $has_link ? __( 'Or by bank transfer', 'ibanbox' ) : __( 'By bank transfer', 'ibanbox' ), 'linkLabel' => __( 'Donate online', 'ibanbox' ), 'banksLabel' => __( 'Choose your bank', 'ibanbox' ), 'copyLabel' => __( 'Copy account number', 'ibanbox' ), 'qrCaption' => __( 'Scan with your banking app', 'ibanbox' ), 'recipientLabel' => __( 'Recipient', 'ibanbox' ), 'accountLabel' => __( 'Account', 'ibanbox' ), 'bicLabel' => __( 'BIC', 'ibanbox' ), 'amountLabel' => __( 'Amount', 'ibanbox' ), 'otherLabel' => __( 'Other amount', 'ibanbox' ), 'purposeLabel' => __( 'Payment details', 'ibanbox' ), 'referenceLabel' => __( 'Reference', 'ibanbox' ), ); } /** * The accounts and links a block can pick from, as ID => name for the editor's lists. * * @return array{accounts: array, links: array} */ function editor_choices(): array { return array( 'accounts' => array_map( static fn( $account ) => array( 'id' => $account['id'], 'name' => trim( ( '' !== $account['label'] ? $account['label'] . ', ' : '' ) . format_iban( $account['iban'] ) ), ), accounts() ), 'links' => array_map( static fn( $link ) => array( 'id' => $link['id'], 'name' => '' !== $link['label'] ? $link['label'] : ( '' !== platform_for( $link['url'] ) ? platform_for( $link['url'] ) : (string) wp_parse_url( $link['url'], PHP_URL_HOST ) ), ), links() ), ); }