3, 'title' => __( 'Re:Maily Contact Form', 'remaily' ), 'description' => __( 'A form made with Re:Maily.', 'remaily' ), 'category' => 'widgets', 'keywords' => [ 'form', 'contact', 'remaily', 'email', 're', 'cf' ], // The hash finds the form, after an export and import too; the post ID is only for the editor's links 'attributes' => [ 'id' => [ 'type' => 'integer', 'default' => 0 ], 'hash' => [ 'type' => 'string', 'default' => '' ], ], 'supports' => [ 'html' => false, 'align' => [ 'wide', 'full' ], ], 'render_callback' => [ __CLASS__, 'render' ], ] ); } /** * The block's markup, in the block wrapper (alignment, the block's own classes) * * @param array $attributes Block attributes * * @return string */ public static function render( $attributes ) { $html = Renderer::render( (string) ( $attributes['hash'] ?? '' ) ); return '' === $html ? '' : '
' . $html . '
'; } /** * The editor script */ public static function enqueue_editor() { Assets::enqueue( 'remaily-blocks' ); } /** * What the editor script reads (window.remailyBlocks) * * @return array */ public static function script_data() { $forms = get_posts( [ 'post_type' => PostType::NAME, 'post_status' => 'publish', 'posts_per_page' => 200, 'orderby' => 'title', 'order' => 'ASC' ] ); return [ 'forms' => array_map( static fn( $post ) => [ 'id' => $post->ID, 'hash' => Form::hash_of( $post->ID ), 'title' => $post->post_title ?: '#' . $post->ID ], $forms ), 'editUrl' => admin_url( 'admin.php?page=' . Admin::PAGE . '&form=' ), 'newUrl' => Admin::new_url(), 'canEdit' => current_user_can( Admin::CAPABILITY ), // The Re:Maily mark, the same as Elementor's and WPBakery's 'icon' => Icons::logo_url() ]; } }