-
-
Save daronspence/5aa334f241a8ccdbef6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class acf_field_gravity_forms extends acf_field { | |
function __construct() { | |
$this->name = 'gravity_forms_field'; | |
$this->label = __( 'Gravity Forms', 'acf' ); | |
$this->category = __( "Relational", 'acf'); | |
$this->defaults = array( | |
'multiple' => 0, | |
'allow_null' => 0 | |
); | |
parent::__construct(); | |
} | |
function render_field( $field ) { | |
$field = array_merge($this->defaults, $field); | |
$choices = array(); | |
if ( class_exists( 'RGFormsModel' ) ){ | |
$forms = RGFormsModel::get_forms( null, 'title' ); | |
} else { | |
return false; | |
} | |
if($forms) { | |
foreach( $forms as $form ) { | |
$choices[ $form->id ] = ucfirst($form->title); | |
} | |
} | |
// override field settings and render | |
$field['choices'] = $choices; | |
$field['type'] = 'select'; | |
?> | |
<select name="<?php echo acf_esc_attr( $field['name'] ); ?>" id="<?php echo $field['name'];?>"> | |
<?php | |
foreach ( $field['choices'] as $key => $value ): | |
$selected = ''; | |
if ( $field['value'] == $key ) | |
$selected = ' selected="selected"'; | |
?> | |
<option value="<?php echo $key; ?>"<?php echo $selected;?>><?php echo $value; ?></option> | |
<?php endforeach; | |
?> | |
</select> | |
<?php | |
} | |
} | |
new acf_field_gravity_forms(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment