, so this file emits *
blocks only: no table markup. * * PHP 7.4 compatible. * * @package EbookStore */ if ( ! defined( 'ABSPATH' ) ) { exit; } settings_fields( 'ebook-settings-group-brevo' ); do_settings_sections( 'ebook-settings-group-brevo' ); $brevo_api_key = trim( (string) get_option( 'brevo_api_key', '' ) ); $brevo_list = trim( (string) get_option( 'brevo_lists', '' ) ); $brevo_enabled = (string) get_option( 'brevo_integration_enabled', $brevo_list !== '' ? '1' : '' ); $has_api_key = ( $brevo_api_key !== '' ); // Only ask Brevo for the lists once a key has actually been saved. Without a // key the lookup can only fail, and an empty dropdown just confuses people. $brevo_lists = $has_api_key ? ebook_store_get_brevo_lists() : false; $lists_loaded = is_array( $brevo_lists ); $list_count = $lists_loaded ? count( $brevo_lists ) : 0; $list_options = array( '' => __( 'Do not add buyers to any list', 'ebook-store' ) ); if ( $lists_loaded ) { foreach ( $brevo_lists as $list ) { $list_id = isset( $list->id ) ? (string) $list->id : ''; if ( $list_id === '' ) { continue; } $list_options[ $list_id ] = isset( $list->name ) && $list->name !== '' ? (string) $list->name : sprintf( /* translators: %s: numeric Brevo list ID. */ __( 'List %s', 'ebook-store' ), $list_id ); } } $general_tab_url = ebook_store_get_settings_tab_url( 'General' ); ebook_store_render_hero( array( 'eyebrow' => __( 'Brevo', 'ebook-store' ), 'title' => __( 'Add buyers to a Brevo contact list', 'ebook-store' ), 'intro' => __( 'After someone pays for a book, Ebook Store can pass their email address to Brevo so they land in your newsletter list automatically. Connect your account first, then pick the list.', 'ebook-store' ), 'aside' => function () use ( $has_api_key, $lists_loaded, $list_count, $brevo_list, $brevo_enabled, $list_options ) { ?> __( 'Step 1', 'ebook-store' ), 'title' => __( 'Connect your Brevo account', 'ebook-store' ), 'intro' => __( 'The API key is the password Ebook Store uses to talk to Brevo on your behalf. Use a key from the same Brevo account that holds the list you want buyers added to.', 'ebook-store' ), 'id' => 'ebook-brevo-connection', 'pro' => true, ) ); ebook_store_steps( __( 'Where to find your API key', 'ebook-store' ), array( esc_html__( 'Sign in to Brevo and open the account menu in the top-right corner.', 'ebook-store' ), esc_html__( 'Choose "SMTP & API", then the "API keys" tab.', 'ebook-store' ), esc_html__( 'Select "Generate a new API key", give it a name such as "Ebook Store", and copy the key that appears.', 'ebook-store' ), esc_html__( 'Brevo shows the full key only once. Paste it below straight away and save this page.', 'ebook-store' ), ) ); ebook_store_grid_open( 1 ); ebook_store_field( array( 'type' => 'text', 'name' => 'brevo_api_key', 'id' => 'brevo_api_key', 'label' => __( 'Brevo API key', 'ebook-store' ), 'value' => $brevo_api_key, 'placeholder' => 'xkeysib-0000000000000000000000000000000000000000000000000000000000000000-XXXXXXXXXXXXXXXX', 'mono' => true, 'wide' => true, 'pro' => true, 'help' => esc_html__( 'Brevo keys start with "xkeysib-". If the key is wrong, expired or deleted in Brevo, no buyer is added to your list and the status panel above turns red. Nothing else on your shop is affected.', 'ebook-store' ), ) ); ebook_store_grid_close(); if ( ! $has_api_key ) { // Chicken and egg: the list dropdown can only be filled in once a key has // been saved, so ask for the key first and show nothing else. ebook_store_callout( esc_html__( 'Paste your API key above and press "Save Changes". This page then reloads with the contact lists from your Brevo account, and you can choose the one buyers should be added to.', 'ebook-store' ), 'info', __( 'Save your key first:', 'ebook-store' ) ); /* * These two settings belong to this tab's option group, so WordPress would * blank them out on save if the form did not submit them. While the key is * missing the controls are hidden, so keep the saved values here. */ ?> __( 'Step 2', 'ebook-store' ), 'title' => __( 'Choose the list buyers are added to', 'ebook-store' ), 'intro' => __( 'These are the contact lists Ebook Store can see in your Brevo account. Pick one, then switch the sync on.', 'ebook-store' ), 'id' => 'ebook-brevo-list', 'pro' => true, ) ); if ( ! $lists_loaded ) { ebook_store_callout( esc_html__( 'Ebook Store could not read the contact lists from Brevo with the saved key. Check that the key was copied in full, that it has not been deleted in Brevo, and that your server is allowed to make outgoing web requests. Correct the key above, save, and this list will fill in.', 'ebook-store' ), 'warning', __( 'Brevo did not answer:', 'ebook-store' ) ); } elseif ( $list_count === 0 ) { ebook_store_callout( esc_html__( 'The connection works, but this Brevo account has no contact lists yet. Create one in Brevo under "Contacts", then reload this page.', 'ebook-store' ), 'warning', __( 'No lists in this account:', 'ebook-store' ) ); } ebook_store_toggle_grid_open(); ebook_store_toggle( array( 'name' => 'brevo_integration_enabled', 'id' => 'brevo_integration_enabled', 'title' => __( 'Add paying buyers to Brevo', 'ebook-store' ), 'description' => __( 'Only paid orders are sent, and only after checkout completes. Turn this off at any time to stop sending without losing your settings.', 'ebook-store' ), 'checked' => $brevo_enabled, 'pro' => true, ) ); ebook_store_toggle_grid_close(); ebook_store_grid_open( 1 ); ebook_store_field( array( 'type' => 'select', 'name' => 'brevo_lists', 'id' => 'brevo_lists', 'label' => __( 'Contact list for buyers', 'ebook-store' ), 'value' => $brevo_list, 'options' => $list_options, 'wide' => true, 'pro' => true, 'help' => esc_html__( 'Buyers are added to this list only. If you leave it on "Do not add buyers to any list", nothing is sent to Brevo even when the switch above is on. Renaming the list inside Brevo is safe; deleting it is not, because the saved choice then points at a list that no longer exists.', 'ebook-store' ), ) ); ebook_store_grid_close(); ebook_store_section_close(); } /* * What actually happens, in plain words. */ ebook_store_section_open( array( 'eyebrow' => __( 'Good to know', 'ebook-store' ), 'title' => __( 'What happens after a sale', 'ebook-store' ), 'intro' => __( 'A short summary of the rules Ebook Store follows, so there are no surprises for you or your buyers.', 'ebook-store' ), 'id' => 'ebook-brevo-behaviour', ) ); ebook_store_callout( '', 'soft' ); if ( ! ebook_store_has_pro_license() ) { ebook_store_callout( sprintf( /* translators: %s: link to the General settings tab. */ esc_html__( 'The Brevo settings on this page stay locked until a Pro license key is saved on the %s. The lock also applies to submitted form data, so these values cannot be changed without a license.', 'ebook-store' ), '' . esc_html__( 'General tab', 'ebook-store' ) . '' ), 'warning', __( 'Pro feature:', 'ebook-store' ) ); } ebook_store_section_close();