{ type: "message", html } or { type: "redirect", url }. */ public static function build( Submission_Context $ctx ) { $visible = clone $ctx; $visible->entry_id = 0; $attributes = $ctx->form->attributes; if ( 'redirect' === ( $attributes['confirmationType'] ?? 'message' ) ) { $url = self::redirect_target( $attributes, $visible ); if ( null !== $url ) { return [ 'type' => 'redirect', 'url' => $url, ]; } } return [ 'type' => 'message', 'html' => self::message_html( $visible ), ]; } /** * Where a redirect confirmation goes, or null to show the message. * * @param array $attributes Form attributes. * @param Submission_Context $ctx Submission. * @return string|null */ private static function redirect_target( array $attributes, Submission_Context $ctx ) { $page_id = (int) ( $attributes['redirectPageId'] ?? 0 ); if ( $page_id > 0 ) { $post = get_post( $page_id ); if ( ! $post instanceof \WP_Post || 'publish' !== $post->post_status || ! is_post_type_viewable( $post->post_type ) || '' !== (string) $post->post_password ) { return null; } $link = get_permalink( $post ); return is_string( $link ) && '' !== $link ? $link : null; } $template = (string) ( $attributes['redirectUrl'] ?? '' ); return '' === trim( $template ) ? null : Merge_Tags::redirect_url( $template, $ctx ); } /** * The confirmation message as HTML. * * @param Submission_Context $ctx Submission. * @return string */ private static function message_html( Submission_Context $ctx ) { $html = ''; foreach ( $ctx->form->confirmation_blocks as $block ) { if ( is_array( $block ) ) { $html .= render_block( $block ); } } if ( '' === trim( wp_strip_all_tags( $html, true ) ) && false === stripos( $html, ''; } return Merge_Tags::replace( $html, $ctx, 'html' ); } }