@@ -14,6 +14,11 @@ class GPEB_Filter_By_Nested_Entry {
1414 private $ nested_target_field_id ;
1515
1616 public function __construct ( $ config = array () ) {
17+ // check if required parameters are provided
18+ if ( empty ( $ config ['parent_form_id ' ] ) || empty ( $ config ['nested_form_id ' ] ) || empty ( $ config ['parent_hidden_field_id ' ] ) || empty ( $ config ['nested_target_field_id ' ] ) ) {
19+ return ;
20+ }
21+
1722 $ this ->parent_form_id = rgar ( $ config , 'parent_form_id ' );
1823 $ this ->nested_form_id = rgar ( $ config , 'nested_form_id ' );
1924 $ this ->parent_hidden_field_id = rgar ( $ config , 'parent_hidden_field_id ' );
@@ -42,6 +47,10 @@ public function modify_filter_form( $form ) {
4247 foreach ( $ form ['fields ' ] as &$ field ) {
4348 if ( $ field ->id == $ this ->parent_hidden_field_id ) {
4449 $ nested_form_field = GFAPI ::get_field ( $ this ->nested_form_id , $ this ->nested_target_field_id );
50+ if ( ! $ nested_form_field ) {
51+ error_log ( sprintf ( 'Nested form field with ID %d not found in form %d. ' , $ this ->nested_target_field_id , $ this ->nested_form_id ) );
52+ continue ;
53+ }
4554 $ field = $ nested_form_field ;
4655 $ field ->id = $ this ->parent_hidden_field_id ;
4756 }
@@ -69,6 +78,11 @@ public function filter_entries_by_nested_value( $entries, $gf_queryer ) {
6978 ),
7079 ) );
7180
81+ if ( is_wp_error ( $ nested_entries ) ) {
82+ error_log ( sprintf ( 'Error retrieving nested entries: %s ' , $ nested_entries ->get_error_message () ) );
83+ return $ entries ;
84+ }
85+
7286 $ entries = array ();
7387 $ parent_entry_ids = array ();
7488
0 commit comments