From c60d187b51a3f9e143f24e98e5a15c1aeaa9a04b Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Sat, 10 May 2025 00:56:32 +0530 Subject: [PATCH 1/2] `gpuid-generate-post-workflow.php`: Added snippet to delay generation of Unique ID until a workflow step is complete. --- gp-unique-id/gpuid-generate-post-workflow.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 gp-unique-id/gpuid-generate-post-workflow.php diff --git a/gp-unique-id/gpuid-generate-post-workflow.php b/gp-unique-id/gpuid-generate-post-workflow.php new file mode 100644 index 000000000..eff6349b8 --- /dev/null +++ b/gp-unique-id/gpuid-generate-post-workflow.php @@ -0,0 +1,73 @@ +_args = wp_parse_args( $args, array( + 'form_id' => false, + 'field_id' => false, + 'step_id' => false, + ) ); + + if ( ! $this->_args['form_id'] || ! $this->_args['field_id'] || ! $this->_args['step_id'] ) { + return; + } + + add_action( 'init', array( $this, 'init' ) ); + + } + + public function init() { + + add_filter( 'gpui_unique_id', array( $this, 'prevent_unique_id_generation' ), 10, 3 ); + add_action( 'gravityflow_step_complete', array( $this, 'maybe_generate_unique_id' ), 10, 4 ); + + } + + public function prevent_unique_id_generation( $unique, $form_id, $field_id ) { + + if ( $form_id == $this->_args['form_id'] && $field_id == $this->_args['field_id'] && ! gravity_flow()->is_workflow_detail_page() ) { + return ''; + } + + return $unique; + } + + public function maybe_generate_unique_id( $step_id, $entry_id, $form_id, $status ) { + + if ( $step_id == $this->_args['step_id'] && $form_id == $this->_args['form_id'] ) { + $entry = GFAPI::get_entry( $entry_id ); + if ( ! is_wp_error( $entry ) && empty( $entry[ $this->_args['field_id'] ] ) ) { + $uid_field = GFAPI::get_field( $form_id, $this->_args['field_id'] ); + $uid_field->save_value( GFAPI::get_entry( $entry_id ), $uid_field, false ); + } + } + } + +} + +# Configuration + +new GPUID_Generate_Post_Workflow( array( + 'form_id' => 5, // Replace with your form ID. + 'field_id' => 3, // Replace with your Unique ID field ID. + 'step_id' => 3 // Replace with your Gravity Flow step ID. +) ); From 3ebe1cd65df893ccd6d0d74f0135fb55fed6e0e6 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Sat, 24 May 2025 00:26:21 +0530 Subject: [PATCH 2/2] `gpuid-generate-post-workflow.php`: Added snippet to delay generation of Unique ID until a workflow step is complete. --- gp-unique-id/gpuid-generate-post-workflow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gp-unique-id/gpuid-generate-post-workflow.php b/gp-unique-id/gpuid-generate-post-workflow.php index eff6349b8..755576e9e 100644 --- a/gp-unique-id/gpuid-generate-post-workflow.php +++ b/gp-unique-id/gpuid-generate-post-workflow.php @@ -53,7 +53,7 @@ public function prevent_unique_id_generation( $unique, $form_id, $field_id ) { public function maybe_generate_unique_id( $step_id, $entry_id, $form_id, $status ) { - if ( $step_id == $this->_args['step_id'] && $form_id == $this->_args['form_id'] ) { + if ( (int) $step_id === $this->_args['step_id'] && (int) $form_id === $this->_args['form_id'] ) { $entry = GFAPI::get_entry( $entry_id ); if ( ! is_wp_error( $entry ) && empty( $entry[ $this->_args['field_id'] ] ) ) { $uid_field = GFAPI::get_field( $form_id, $this->_args['field_id'] );