diff --git a/acf-gravity_forms.php b/acf-gravity_forms.php
index 0f5e005..a4cd110 100755
--- a/acf-gravity_forms.php
+++ b/acf-gravity_forms.php
@@ -1,48 +1,44 @@
';
- $html .= '
';
- $html .= _e( 'Warning: Gravity Forms is not installed or activated. This plugin does not function without Gravity Forms!' );
- $html .= '
';
- $html .= '';
- echo $html;
-
- }
+add_action( 'acf/register_fields', 'register_fields_gravity_forms' );
+
+function gff_activate()
+{
+ if ( class_exists( 'RGFormsModel' ) )
+ {
+ return true;
+ }
+ else
+ {
+ $html = '';
+ $html .= '
';
+ $html .= _e( 'Warning: Gravity Forms is not installed or activated. This plugin does not function without Gravity Forms!' );
+ $html .= '
';
+ $html .= '
';
+
+ echo $html;
+ }
}
+
register_activation_hook( __FILE__, 'gff_activate' );
-?>
\ No newline at end of file
diff --git a/gravity_forms-v4.php b/gravity_forms-v4.php
index b4d6358..d8f1b09 100755
--- a/gravity_forms-v4.php
+++ b/gravity_forms-v4.php
@@ -1,207 +1,180 @@
name = 'gravity_forms_field';
- $this->label = __('Gravity Forms');
- $this->category = __("Relational",'acf'); // Basic, Content, Choice, etc
- $this->defaults = array(
- 'allow_multiple' => 0,
- 'allow_null' => 0
- );
-
- // do not delete!
- parent::__construct();
- }
-
-
- /*
- * create_options()
- *
- * Create extra options for your field. This is rendered when editing a field.
- * The value of $field['name'] can be used (like bellow) to save extra data to the $field
- *
- * @type action
- * @since 3.6
- * @date 23/01/13
- *
- * @param $field - an array holding all the field's data
- */
-
- function create_options( $field )
- {
- // defaults?
- $field = array_merge($this->defaults, $field);
-
-
- // key is needed in the field names to correctly save the data
- $key = $field['name'];
-
-
- // Create Field Options HTML
- ?>
-
-
-
-
-
- 'radio',
- 'name' => 'fields['.$key.'][allow_null]',
- 'value' => $field['allow_null'],
- 'choices' => array(
- 1 => __("Yes",'acf'),
- 0 => __("No",'acf'),
- ),
- 'layout' => 'horizontal',
- ));
- ?>
-
-
-
-
-
-
-
- 'radio',
- 'name' => 'fields['.$key.'][multiple]',
- 'value' => $field['multiple'],
- 'choices' => array(
- 1 => __("Yes",'acf'),
- 0 => __("No",'acf'),
- ),
- 'layout' => 'horizontal',
- ));
- ?>
-
-
- defaults, $field);
- $choices = array();
-
- if (class_exists('RGFormsModel')) {
-
- $forms = RGFormsModel::get_forms(1);
-
- } else {
- echo "Warning: Gravity Forms is not installed or activated. This field does not function without Gravity Forms! ";
- }
-
-
- if(isset($forms))
+ var $settings,
+ $defaults;
+
+ /**
+ * __construct()
+ *
+ * Set name / label needed for actions / filters
+ *
+ * @since 3.6
+ * @date 23/01/13
+ */
+ function __construct()
{
- foreach( $forms as $form )
- {
- $choices[ $form->id ] = ucfirst($form->title);
- }
+ $this->name = 'gravity_forms_field';
+ $this->label = __( 'Gravity Forms' );
+ $this->category = __( 'Relational', 'acf' );
+ $this->defaults = array(
+ 'allow_multiple' => 0,
+ 'allow_null' => 0
+ );
+
+ parent::__construct();
}
- // override field settings and render
- $field['choices'] = $choices;
- $field['type'] = 'select';
-
- do_action('acf/create_field', $field);
- }
-
-
- /*
- * format_value_for_api()
- *
- * This filter is applied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
- *
- * @type filter
- * @since 3.6
- * @date 23/01/13
- *
- * @param $value - the value which was loaded from the database
- * @param $post_id - the $post_id from which the value was loaded
- * @param $field - the field array holding all the field options
- *
- * @return $value - the modified value
- */
-
- function format_value_for_api( $value, $field )
+ /**
+ * create_options()
+ *
+ * Create extra options for your field. This is rendered when editing a field.
+ * The value of $field['name'] can be used (like bellow) to save extra data to the $field
+ *
+ * @type action
+ * @since 3.6
+ * @date 23/01/13
+ *
+ * @param $field - an array holding all the field's data
+ */
+ function create_options( $field )
{
+ $field = array_merge( $this->defaults, $field );
+ $key = $field['name'];
+?>
+
+
+
+
+
+ 'radio',
+ 'name' => 'fields[' . $key . '][allow_null]',
+ 'value' => $field['allow_null'],
+ 'choices' => array(
+ 1 => __( 'Yes', 'acf' ),
+ 0 => __( 'No', 'acf' ),
+ ),
+ 'layout' => 'horizontal',
+ ) );
+ ?>
+
+
+
+
+
+
+
+ 'radio',
+ 'name' => 'fields[' . $key . '][multiple]',
+ 'value' => $field['multiple'],
+ 'choices' => array(
+ 1 => __( 'Yes', 'acf' ),
+ 0 => __( 'No', 'acf' ),
+ ),
+ 'layout' => 'horizontal',
+ ) );
+ ?>
+
+
+ $v){
- $form = GFAPI::get_form( $v );
- //Add it if it's not an error object
- if( !is_wp_error($form) ){
- $form_objects[$k] = $form;
- }
- }
- //Return false if the array is empty
- if( !empty($form_objects) ){
- return $form_objects;
- }else{
- return false;
- }
-
-
- //Else return single form object
- }else{
-
- $form = GFAPI::get_form(intval($value));
- //Return the form object if it's not an error object. Otherwise return false.
- if( !is_wp_error($form) ){
- return $form;
- }else{
- return false;
- }
-
- }
-
+ /**
+ * create_field()
+ *
+ * Create the HTML interface for your field
+ *
+ * @param $field - an array holding all the field's data
+ *
+ * @type action
+ * @since 3.6
+ * @date 23/01/13
+ */
+ function create_field( $field )
+ {
+ $field = array_merge( $this->defaults, $field );
+ $choices = array();
+
+ if ( class_exists( 'RGFormsModel' ) )
+ {
+ $forms = RGFormsModel::get_forms( 1 );
+ }
+ else
+ {
+ echo 'Warning: Gravity Forms is not installed or activated. This field does not function without Gravity Forms! ';
+ }
+
+ if ( isset( $forms ) )
+ {
+ foreach ( $forms as $form )
+ {
+ $choices[$form->id] = ucfirst( $form->title );
+ }
+ }
+
+ $field['choices'] = $choices;
+ $field['type'] = 'select';
+
+ do_action( 'acf/create_field', $field );
}
+ /**
+ * format_value_for_api()
+ *
+ * This filter is applied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
+ *
+ * @type filter
+ * @since 3.6
+ * @date 23/01/13
+ *
+ * @param $value - the value which was loaded from the database
+ * @param $post_id - the $post_id from which the value was loaded
+ * @param $field - the field array holding all the field options
+ *
+ * @return $value - the modified value
+ */
+ function format_value_for_api( $value, $field )
+ {
+ if ( ! $value OR empty( $value ) )
+ {
+ return false;
+ }
+
+ if ( is_array( $value ) && ! empty( $value ) )
+ {
+ $form_objects = array();
+
+ foreach ( $value as $k => $v )
+ {
+ $form = GFAPI::get_form( $v );
+
+ if ( ! is_wp_error( $form ) )
+ {
+ $form_objects[$k] = $form;
+ }
+ }
+
+ return ( ! empty( $form_objects ) ) ? $form_objects : false;
+ }
+ else
+ {
+ $form = GFAPI::get_form( intval( $value ) );
+
+ return ( ! is_wp_error( $form ) ) ? $form : false;
+ }
+ }
}
-// create field
new acf_field_gravity_forms();
-?>
\ No newline at end of file
diff --git a/gravity_forms-v5.php b/gravity_forms-v5.php
index 5b461da..c01ec78 100644
--- a/gravity_forms-v5.php
+++ b/gravity_forms-v5.php
@@ -1,205 +1,188 @@
name = 'gravity_forms_field';
- $this->label = __('Gravity Forms');
- $this->category = __("Relational",'acf'); // Basic, Content, Choice, etc
- $this->defaults = array(
- 'allow_multiple' => 0,
- 'allow_null' => 0
- );
- // do not delete!
- parent::__construct();
- }
-
-
- /*
- * render_field_settings()
- *
- * Create extra settings for your field. These are visible when editing a field
- *
- * @type action
- * @since 3.6
- * @date 23/01/13
- *
- * @param $field (array) the $field being edited
- * @return n/a
- */
-
- function render_field_settings( $field ) {
-
- /*
- * acf_render_field_setting
- *
- * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings.
- * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array.
- *
- * More than one setting can be added by copy/paste the above code.
- * Please note that you must also have a matching $defaults value for the field name (font_size)
- */
-
- acf_render_field_setting( $field, array(
- 'label' => 'Allow Null?',
- 'type' => 'radio',
- 'name' => 'allow_null',
- 'choices' => array(
- 1 => __("Yes",'acf'),
- 0 => __("No",'acf'),
- ),
- 'layout' => 'horizontal'
- ));
- acf_render_field_setting( $field, array(
- 'label' => 'Allow Multiple?',
- 'type' => 'radio',
- 'name' => 'allow_multiple',
- 'choices' => array(
- 1 => __("Yes",'acf'),
- 0 => __("No",'acf'),
- ),
- 'layout' => 'horizontal'
- ));
- }
-
- /*
- * render_field()
- *
- * Create the HTML interface for your field
- *
- * @param $field (array) the $field being rendered
- *
- * @type action
- * @since 3.6
- * @date 23/01/13
- *
- * @param $field (array) the $field being edited
- * @return n/a
- */
-
- function render_field( $field ) {
-
-
- /*
- * Review the data of $field.
- * This will show what data is available
- */
-
- // vars
- $field = array_merge($this->defaults, $field);
- $choices = array();
- //Show notice if Gravity Forms is not activated
- if (class_exists('RGFormsModel')) {
-
- $forms = RGFormsModel::get_forms(1);
-
- } else {
- echo "Warning: Gravity Forms is not installed or activated. This field does not function without Gravity Forms! ";
- }
-
- //Prevent undefined variable notice
- if(isset($forms)){
- foreach( $forms as $form ){
- $choices[ intval($form->id) ] = ucfirst($form->title);
- }
+/**
+ * Description: ACF field to select one or many Gravity Forms
+ * Version: 1.1.0
+ * Author: @adam_pope of @stormuk
+ * Author URI: http://www.stormconsultancy.co.uk
+ * License: MIT
+ * License URI: http://opensource.org/licenses/MIT
+ */
+class acf_field_gravity_forms extends acf_field
+{
+ /**
+ * __construct()
+ *
+ * This function will setup the field type data
+ *
+ * @type function
+ * @date 5/03/2014
+ * @since 5.0.0
+ *
+ * @param n/a
+ * @return n/a
+ */
+ function __construct()
+ {
+ $this->name = 'gravity_forms_field';
+ $this->label = __( 'Gravity Forms' );
+ $this->category = __( 'Relational', 'acf' );
+ $this->defaults = array(
+ 'allow_multiple' => 0,
+ 'allow_null' => 0
+ );
+
+ parent::__construct();
}
- // override field settings and render
- $field['choices'] = $choices;
- $field['type'] = 'select';
- if ( $field['allow_multiple'] ) {
- $multiple = 'multiple="multiple" data-multiple="1"';
- echo " ";
- }
- else $multiple = '';
- ?>
- ">
- - Select -';
-
- foreach ($field['choices'] as $key => $value){
- $selected = '';
- if ( (is_array($field['value']) && in_array($key, $field['value'])) || $field['value'] == $key )
- $selected = ' selected="selected"';
- ?>
- >
-
-
- $v){
- $form = GFAPI::get_form( $v );
- //Add it if it's not an error object
- if( !is_wp_error($form) ){
- $form_objects[$k] = $form;
- }
- }
- //Return false if the array is empty
- if( !empty($form_objects) ){
- return $form_objects;
- }else{
- return false;
- }
-
-
- //Else return single form object
- }else{
-
- $form = GFAPI::get_form(intval($value));
- //Return the form object if it's not an error object. Otherwise return false.
- if( !is_wp_error($form) ){
- return $form;
- }else{
- return false;
- }
-
- }
-
+
+ /**
+ * render_field_settings()
+ *
+ * Create extra settings for your field. These are visible when editing a field
+ *
+ * @type action
+ * @since 3.6
+ * @date 23/01/13
+ *
+ * @param $field (array) the $field being edited
+ * @return n/a
+ */
+ function render_field_settings( $field )
+ {
+ /**
+ * acf_render_field_setting()
+ *
+ * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings.
+ * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array.
+ *
+ * More than one setting can be added by copy/paste the above code.
+ * Please note that you must also have a matching $defaults value for the field name (font_size)
+ */
+ acf_render_field_setting( $field, array(
+ 'label' => 'Allow Null?',
+ 'type' => 'radio',
+ 'name' => 'allow_null',
+ 'choices' => array(
+ 1 => __( 'Yes', 'acf' ),
+ 0 => __( 'No', 'acf' ),
+ ),
+ 'layout' => 'horizontal'
+ ) );
+
+ acf_render_field_setting( $field, array(
+ 'label' => 'Allow Multiple?',
+ 'type' => 'radio',
+ 'name' => 'allow_multiple',
+ 'choices' => array(
+ 1 => __( 'Yes', 'acf' ),
+ 0 => __( 'No', 'acf' ),
+ ),
+ 'layout' => 'horizontal'
+ ) );
+ }
+
+ /**
+ * render_field()
+ *
+ * Create the HTML interface for your field
+ *
+ * @param $field (array) the $field being rendered
+ *
+ * @type action
+ * @since 3.6
+ * @date 23/01/13
+ *
+ * @param $field (array) the $field being edited
+ * @return n/a
+ */
+ function render_field( $field )
+ {
+ $field = array_merge( $this->defaults, $field );
+ $choices = array();
+
+ if ( class_exists( 'RGFormsModel' ) )
+ {
+ $forms = RGFormsModel::get_forms( 1 );
+ }
+ else
+ {
+ echo 'Warning: Gravity Forms is not installed or activated. This field does not function without Gravity Forms! ';
+ }
+
+ if ( isset( $forms ) )
+ {
+ foreach ( $forms as $form )
+ {
+ $choices[intval( $form->id )] = ucfirst( $form->title );
+ }
+ }
+
+ $field['choices'] = $choices;
+ $field['type'] = 'select';
+ $multiple = '';
+
+ if ( $field['allow_multiple'] )
+ {
+ $multiple = 'multiple="multiple" data-multiple="1"';
+
+ echo ' ';
+ }
+?>
+ >
+
+ Select ...
+
+ $value ) : ?>
+ >
+
+
+ $v )
+ {
+ $form = GFAPI::get_form( $v );
+
+ if ( ! is_wp_error( $form ) )
+ {
+ $form_objects[$k] = $form;
+ }
+ }
+
+ return ( ! empty( $form_objects ) ) ? $form_objects : false;
+ }
+ else
+ {
+ $form = GFAPI::get_form( intval( $value ) );
+
+ return ( ! is_wp_error( $form ) ) ? $form : false;
+ }
+ }
}
-// create field
-new acf_field_gravity_forms();
\ No newline at end of file
+
+new acf_field_gravity_forms();