From c7761c5d6c44fe4e957cdcc9deb064b76c522a7f Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 2 Nov 2026 13:35:55 -0400 Subject: [PATCH] feat: add hooks to extend the Confirmation action Add the frm_on_submit_types filter so add-ons can change the Confirmation action types and their settings, and the frm_on_submit_page_output filter so they can replace the output of the page type. Pass the running Confirmation action to run_success_action() as on_submit_action so that output can depend on the action's settings. Co-Authored-By: Claude Opus 5.5 --- classes/controllers/FrmFormsController.php | 25 +++++++++++++++++-- .../frm-form-actions/on_submit_settings.php | 11 ++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/classes/controllers/FrmFormsController.php b/classes/controllers/FrmFormsController.php index 058048ef25..8c0e49401a 100644 --- a/classes/controllers/FrmFormsController.php +++ b/classes/controllers/FrmFormsController.php @@ -2986,6 +2986,7 @@ public static function trigger_redirect( $form, $params, $args ) { * * @since 2.05 * @since 6.0 `$args['force_delay_redirect']` is added. + * @since x.x `$args['on_submit_action']` is added. * * @param array $args { * The args. @@ -2996,6 +2997,7 @@ public static function trigger_redirect( $form, $params, $args ) { * @type string $action The action event. Accepts `create` or `update`. * @type array $fields The array of fields. * @type int $force_delay_redirect Force to show the message before redirecting in case redirect method runs. + * @type object $on_submit_action The Confirmation action being run, when there is one. * } */ public static function run_success_action( $args ) { @@ -3159,7 +3161,8 @@ public static function run_on_submit_actions( $args ) { FrmOnSubmitHelper::populate_on_submit_data( $args['form']->options ); self::run_success_action( $args ); } elseif ( 1 === count( $args['conf_method'] ) ) { - FrmOnSubmitHelper::populate_on_submit_data( $args['form']->options, reset( $args['conf_method'] ) ); + $args['on_submit_action'] = reset( $args['conf_method'] ); + FrmOnSubmitHelper::populate_on_submit_data( $args['form']->options, $args['on_submit_action'] ); $args['conf_method'] = $args['form']->options['success_action']; self::run_success_action( $args ); } else { @@ -3224,6 +3227,7 @@ public static function run_single_on_submit_action( $args, $action ) { private static function get_run_success_action_args( $args, $action ) { $new_args = $args; + $new_args['on_submit_action'] = $action; FrmOnSubmitHelper::populate_on_submit_data( $new_args['form']->options, $action, $args['action'] ); $opt = 'update' === $args['action'] ? 'edit_' : 'success_'; @@ -3254,7 +3258,24 @@ private static function load_page_after_submit( $args ) { // phpcs:ignore Universal.Operators.StrictComparisons if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) { - $page = get_post( $args['form']->options[ $opt . '_page_id' ] ); + $page = get_post( $args['form']->options[ $opt . '_page_id' ] ); + + /** + * Allows replacing the output of a Confirmation action that shows page content. + * + * @since x.x + * + * @param string|null $output Return a string to show it instead of the page content. + * @param WP_Post $page The selected post. + * @param array $args See {@see FrmFormsController::run_success_action()}. + */ + $output = apply_filters( 'frm_on_submit_page_output', null, $page, $args ); + + if ( is_string( $output ) ) { + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + return; + } + $old_post = $post; $post = $page; $content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] ); diff --git a/classes/views/frm-form-actions/on_submit_settings.php b/classes/views/frm-form-actions/on_submit_settings.php index 255c89f8da..1a6ca2708f 100644 --- a/classes/views/frm-form-actions/on_submit_settings.php +++ b/classes/views/frm-form-actions/on_submit_settings.php @@ -35,6 +35,17 @@ ), ); +/** + * Filters the Confirmation action types and the settings shown for each. + * + * @since x.x + * + * @param array $types Action types keyed by type, each with `label`, `icon` and `sub_settings`. + * @param object $instance Form action post object. + * @param array $args Contains `form`, `action_key`, `values`. + */ +$types = apply_filters( 'frm_on_submit_types', $types, $instance, $args ); + $col_count = count( $types ); if ( $col_count <= 4 ) {