Reputation: 360
I am adding Gravity Forms to Unyson builder but problem is the builder only detects/adds the last form title/id.
Here is the code:
if ( ! defined( 'FW' ) ) {
die( 'Forbidden' );
}
$options = array(
'title' => array(
'type' => 'select',
'value' => 'choice-3',
'attr' => array( 'class' => 'custom-class', 'data-foo' => 'bar' ),
'label' => __('Label', 'fw'),
'desc' => __('Description', 'fw'),
'help' => __('Help tip', 'fw'),
'choices' => array(),
), // title
); // $options
$forms = GFAPI::get_forms();
foreach ($forms as $form) {
$form_id = $form['id'];
$form = GFAPI::get_form( $form_id );
$form_title = $form['title'];
$options['title']['choices'] = array(
$form_id => __($form_title, 'fw'),
);
}
I want to populate the 'choices' array with all the gravity forms titles.
Thank you!
Upvotes: 1
Views: 298
Reputation: 360
I got it. after lot of thinking I realized that I should use array_push instead of array in foreach loop. And yes that fixed the problem. Here is the final & working loop:
foreach ($forms as $form) {
$form_id = $form['id'];
$form = GFAPI::get_form( $form_id );
$form_title = $form['title'];
$form_title_value = __($form_title, 'fw');
array_push( $options['title']['choices'],
$form_id = $form_title_value );
}
array_push() manual: http://php.net/manual/en/function.array-push.php
Upvotes: 1