Last active
June 18, 2018 01:10
-
-
Save alexphelps/b5ba193ba009901caa5e to your computer and use it in GitHub Desktop.
Gravity Forms Addon extend Gravity Perks Unique ID for Global Unique ID
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 | |
/* | |
Plugin Name: Global Unique ID for Gravity Perks | |
Plugin URI: http://www.prontomarketing.com | |
Description: Adds the ability to set a starting ID for sequential Unique IDs. | |
Version: 0.1 | |
Author: Pronto Marketing | |
Author URI: http://www.prontomarketing.com | |
*/ | |
if (class_exists("GFForms")) { | |
GFForms::include_addon_framework(); | |
class GFSimpleAddOn extends GFAddOn { | |
protected $_version = "0.1"; | |
protected $_min_gravityforms_version = "1.7.9999"; | |
protected $_slug = "gp-global-unique-id"; | |
protected $_path = "gp-global-unique-id/global-unique-id.php"; | |
protected $_full_path = __FILE__; | |
protected $_title = "Gravity Forms Simple Add-On"; | |
protected $_short_title = "Global Unique ID"; | |
public function init(){ | |
parent::init(); | |
add_filter("gform_submit_button", array($this, "form_submit_button"), 10, 2); | |
add_filter( 'gpui_unique_id_attributes', array($this,'gwiz_unique_id_global_sequential_index'), 10, 3 ); | |
} | |
// Add the text in the plugin settings to the bottom of the form if enabled for this form | |
function form_submit_button($button, $form){ | |
$settings = $this->get_form_settings($form); | |
if(isset($settings["enabled"]) && true == $settings["enabled"]){ | |
$text = $this->get_plugin_setting("global_unique_id"); | |
$button = "<div>{$text}</div>" . $button; | |
} | |
return $button; | |
} | |
public function plugin_settings_fields() { | |
return array( | |
array( | |
"title" => "Global Starting Unique ID", | |
"fields" => array( | |
array( | |
"name" => "global_unique_id", | |
"tooltip" => "This ID will override form specific settings.", | |
"label" => "Global Starting Unique ID", | |
"type" => "text", | |
"class" => "small", | |
) | |
) | |
) | |
); | |
} | |
/** | |
* Gravity Wiz // GP Unique ID // Share a global sequential unique ID across all forms | |
* https://gist.github.com/spivurno/1179e999d795d6a9189a | |
*/ | |
public function gwiz_unique_id_global_sequential_index( $atts, $form_id, $field_id ) { | |
if( $atts['type'] == 'sequential' ) { | |
$atts['starting_number'] = $this->get_plugin_setting("global_unique_id"); | |
$atts['form_id'] = 1; | |
$atts['field_id'] = 1; | |
} | |
return $atts; | |
} | |
} | |
new GFSimpleAddOn(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment