array( __CLASS__, 'render_block' ) ) ); add_shortcode( self::SHORTCODE, array( __CLASS__, 'render_shortcode' ) ); add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'editor_data' ) ); } /** The block on the page: just the embed script for its form. */ public static function render_block( $attributes ) { $attributes = is_array( $attributes ) ? $attributes : array(); return Embed::render( array( 'form' => isset( $attributes['formId'] ) ? $attributes['formId'] : '', 'mode' => isset( $attributes['mode'] ) ? $attributes['mode'] : Embed::MODE_INLINE, 'label' => isset( $attributes['label'] ) ? $attributes['label'] : '', 'position' => isset( $attributes['position'] ) ? $attributes['position'] : 'bottom-right', 'trigger' => isset( $attributes['trigger'] ) ? $attributes['trigger'] : Embed::TRIGGER_CLICK, 'delay' => isset( $attributes['delay'] ) ? $attributes['delay'] : null, 'scroll' => isset( $attributes['scroll'] ) ? $attributes['scroll'] : null, 'frequency' => isset( $attributes['frequency'] ) ? $attributes['frequency'] : null, ) ); } public static function render_shortcode( $atts ) { $atts = shortcode_atts( array( 'form' => '', 'mode' => Embed::MODE_INLINE, 'label' => '', 'position' => 'bottom-right', 'trigger' => Embed::TRIGGER_CLICK, 'delay' => '', 'scroll' => '', 'frequency' => '', 'launcher' => 'yes', ), is_array( $atts ) ? $atts : array(), self::SHORTCODE ); return Embed::render( $atts ); } /** * What the block's editor script needs: the published forms (cached for * a minute), where previews come from, and its words in the site's * language - translated here in PHP, so the plugin's one translation * file covers the block too. */ public static function editor_data() { $forms = array(); foreach ( Admin_Page::get_forms() as $form ) { $forms[] = array( 'id' => $form['id'], 'name' => $form['name'], 'preview' => Embed::preview_url( $form['id'] ), ); } $data = array( 'connected' => Settings::is_connected(), 'settings' => admin_url( 'admin.php?page=' . Admin_Page::MENU_SLUG ), 'forms' => $forms, 'text' => array( 'title' => __( '404 Emails form', '404-emails' ), 'form' => __( 'Form', '404-emails' ), 'chooseForm' => __( '— Choose a form —', '404-emails' ), 'showIt' => __( 'Show it', '404-emails' ), 'inline' => __( 'In the page', '404-emails' ), 'popup' => __( 'As a pop-up', '404-emails' ), 'floating' => __( 'As a corner button', '404-emails' ), 'buttonText' => __( 'Button text', '404-emails' ), 'buttonHelp' => __( 'The button that opens the form. Leave empty for "Subscribe".', '404-emails' ), 'corner' => __( 'Corner', '404-emails' ), 'bottomRight' => __( 'Bottom right', '404-emails' ), 'bottomLeft' => __( 'Bottom left', '404-emails' ), 'opens' => __( 'Opens', '404-emails' ), 'onClick' => __( 'When the button is clicked', '404-emails' ), 'afterDelay' => __( 'After a few seconds', '404-emails' ), 'afterScroll' => __( 'When they scroll down the page', '404-emails' ), 'onExit' => __( 'When they are about to leave', '404-emails' ), 'seconds' => __( 'Seconds', '404-emails' ), 'percent' => __( 'How far down (%)', '404-emails' ), 'every' => __( 'Show again after (days)', '404-emails' ), 'everyHelp' => __( '0 shows it on every visit. People who sign up or close it wait this long.', '404-emails' ), 'notConnected' => __( 'Connect this site to 404 Emails first.', '404-emails' ), 'openSettings' => __( 'Open 404 Emails settings', '404-emails' ), 'noForms' => __( 'No published forms yet. Publish a form in 404 Emails, then reload this page.', '404-emails' ), 'pickPrompt' => __( 'Choose which signup form to show.', '404-emails' ), 'previewTitle' => __( 'Signup form preview', '404-emails' ), 'popupNote' => __( 'Opens as a pop-up on the published page.', '404-emails' ), 'floatingNote' => __( 'Shows as a button in the corner of the published page.', '404-emails' ), 'defaultButton' => __( 'Subscribe', '404-emails' ), ), ); wp_add_inline_script( 'emails404-form-editor-script', 'window.emails404Block = ' . wp_json_encode( $data ) . ';', 'before' ); } }