|string $atts Shortcode attributes. */ public function render_shortcode( array|string $atts = array() ): string { $atts = shortcode_atts( array( 'id' => 0, ), (array) $atts, self::SHORTCODE ); $form_id = absint( $atts['id'] ); if ( 0 === $form_id ) { return ''; } $markup = $this->renderer->render( $form_id ); if ( '' === $markup ) { return ''; } $this->enqueue_assets(); /** * Filters the markup returned by the form shortcode. * * The result is passed through {@see Escape::form_markup()}, so markup * outside `formpilot_form_allowed_html` is removed. * * @since 1.0.0 * * @param string $markup Rendered form markup. * @param int $form_id Requested form ID. */ $markup = (string) apply_filters( 'formpilot_shortcode_output', $markup, $form_id ); // Escaped last, after every filter and template override has had its say. return Escape::form_markup( $markup ); } /** * Enqueues the frontend assets. */ public function enqueue_assets(): void { wp_enqueue_style( Assets::FRONTEND_STYLE ); wp_enqueue_script( Assets::FRONTEND_SCRIPT ); wp_enqueue_script( Assets::LOGIC_SCRIPT ); wp_enqueue_script( Assets::STEPS_SCRIPT ); $captcha = SpamGuard::captcha(); if ( $captcha instanceof CaptchaProvider && '' !== $captcha->script_url() ) { wp_enqueue_script( 'formpilot-captcha', $captcha->script_url(), array(), null, // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- Versioning a third party endpoint would break its cache. true ); } wp_localize_script( Assets::FRONTEND_SCRIPT, 'formpilotFrontend', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'action' => SubmissionHandler::ACTION, 'strings' => array( 'sending' => __( 'Sending…', 'devplugins-custom-form-builder' ), 'success' => __( 'Thank you. Your submission has been received.', 'devplugins-custom-form-builder' ), 'error' => __( 'Something went wrong. Please try again.', 'devplugins-custom-form-builder' ), // Distinct from `error`: the request was never made, so telling the // visitor something went wrong would describe a failure that did not // happen. 'checkFields' => __( 'Please check the highlighted fields and try again.', 'devplugins-custom-form-builder' ), 'requiredField' => __( 'Please choose at least one option.', 'devplugins-custom-form-builder' ), 'fileTooLarge' => __( 'This file is too large.', 'devplugins-custom-form-builder' ), ), ) ); wp_localize_script( Assets::STEPS_SCRIPT, 'formpilotSteps', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'validateAction' => StepHandler::VALIDATE_ACTION, 'saveAction' => StepHandler::SAVE_ACTION, 'loadAction' => StepHandler::LOAD_ACTION, 'strings' => array( /* translators: 1: Current step number. 2: Total number of steps. */ 'stepStatus' => __( 'Step %1$s of %2$s', 'devplugins-custom-form-builder' ), 'error' => __( 'Something went wrong. Please try again.', 'devplugins-custom-form-builder' ), /* translators: %1$s: Date the link stops working. */ 'resumeSaved' => __( 'Your answers are saved. Use this link to come back to them before %1$s.', 'devplugins-custom-form-builder' ), 'resumeLoaded' => __( 'We have brought back what you filled in earlier.', 'devplugins-custom-form-builder' ), 'resumeExpired' => __( 'This saved form has expired, so you are starting fresh.', 'devplugins-custom-form-builder' ), ), ) ); } }