GP Sample Perk
<?php
add_action( 'gform_editor_js', 'field_settings_js' );
public function field_settings_js() {
?>
<script type="text/javascript">
(function($) {
$(document).ready(function(){
for( i in fieldSettings ) {
fieldSettings[i] += ', .my-custom-field-setting';
}
});
})(jQuery);
</script>
<?php
}
<?php
add_action( 'gform_editor_js', 'field_settings_js' );
public function field_settings_js() {
?>
<script type="text/javascript">
(function($) {
$(document).bind( 'gform_load_field_settings', function( event, field, form ) {
// populates the stored value from the field back into the setting when the field settings are loaded
$( '#my-custom-setting' ).attr( 'checked', field['myCustomSetting'] == true );
// if our desired condition is met, we show the field setting; otherwise, hide it
if( GetInputType( field ) == 'desired_field_type' ) {
$( '.my-custom-field-setting' ).show();
} else {
$( '.my-custom-field-setting' ).hide();
}
} );
})(jQuery);
</script>
<?php
}
<?php
// Folder & Filename
// gp-sample-plugin/gp-sample-plugin.php
// Class name
// GP_Sample_Plugin
// Class name full example:
class GP_Sample_Plugin extends GWPerk { }
<?php
/**
* Plugin Name: GP Sample Perk
* Description: A description of what this perk does.
* Plugin URI: http://gravitywiz.com/documentation/gp-sample-perk/
* Version: 1.2
* Author: Gravity Wiz
* Author URI: http://gravitywiz.com/
* License: GPL2
* Perk: True
*/
if( ! class_exists( 'GWPerk' ) ) {
return;
}
class GP_Sample_Perk extends GWPerk {
public $version = '1.2'
public $min_gravity_perks_version = '1.0';
public $min_gravity_forms_version = '1.8';
public $min_wp_version = '3.7';
private static $instance = null;
public static function get_instance( $perk_file ) {
if( self::$instance == null ) {
self::$instance = new self( $perk_file );
}
return self::$instance;
}
function init() {
// start coding!
}
function documentation() {
return array(
'type' => 'url',
'value' => 'http://gravitywiz.com/documentation/gp-sample-perk/'
);
}
}
<?php
public static function dynamic_setting_actions( $position, $form_id ) {
$action = current_filter() . '_' . $position;
if( did_action( $action ) < 1 ) {
do_action( current_filter() . '_' . $position, $form_id );
//echo current_filter() . '_' . $position . '<br />';
}
}
<?php
add_action( 'gperk_field_settings', 'my_custom_setting' )
function my_custom_setting() {
?>
<li class="my-custom-field-setting field_setting">
<input type="checkbox" id="my-custom-setting" value="1" onclick="SetFieldProperty( 'myCustomSetting', this.checked);">
<label class="inline" for="my-custom-setting">
_e( 'My Custom Setting Label' )
<?php gform_tooltip( 'my-custom-setting-toolip' ); ?>
</label>
</li>
<?php
}