SlideShare a Scribd company logo
1 of 21
Extending Gravity
Forms
A CODE DEEP DIVE
Paul Bearne @pbearne
Sr. Web Developer @ metronews.ca
Plugin author of Author Avatars List ( http://wordpress.org/plugins/author-avatars/ )
WP Site Verification tool ( http://wordpress.org/plugins/wp-site-verification-tool/ )
Agenda
Gravity forms demo
Options overload demo
Options overload code
Metro AR demo
AR from code
Class overload demo
Class overload code
DEMO
GRAVITY FORMS
add_filter( 'gform_pre_render', array( $this, ‘overload_gform_select_with_basecamp_user_list’), 10 );
public function overload_gform_select_with_basecamp_user_list( $form ){
$new_user_choices = null;
// check we have a basecamp class
$this->create_basecamp();
// lets get all basecamp users for this project
$message = $this->basecamp->getPeople(); // whole account
if( null == $message ){
return $form;
}
// loop basecamp users
foreach( $message as $basecamp_user ){
$isSelected = ($this->current_user->user_email == $basecamp_user->email_address)?true:false;
$new_user_choices[] = array(
"text"=>esc_html( $basecamp_user->name ),
"value"=>absint( $basecamp_user->id ),
"isSelected"=>( bool )$isSelected,
"price"=>""
);
}
// loop all field and look for users
foreach( $form['fields'] as &$field ){
if( in_array( $field['inputName'], $this->basecamp_user_fields ) ){
$field['choices'] = $new_user_choices;
}
}
return $form;
}
add_filter( 'gform_pre_render', 'overload_gform_select_with_user_list', 10 );
function overload_gform_select_with_user_list( $form ){
$new_user_choices = null;
// create an array of new option values
$new_user_choices[] = array( 'text‘=>'admin', 'value'=>1, 'isSelected'=>false, 'price'=>'' );
$new_user_choices[] = array( 'text'=>'Paul Bearne', 'value'=>2, 'isSelected'=>true, 'price'=>'' );
$new_user_choices[] = array( 'text'=>'Username', 'value'=>3, 'isSelected'=>false, 'price'=>'' );
// loop all fields and look for Parameter Name
foreach( $form['fields'] as &$field ){
if( in_array( $field['inputName'], 'Parameter_Name') ){
$field['choices'] = $new_user_choices;
}
}
return $form;
}
DEMO
METRO AR FORM
<?php
require_once 'external-web-services/PostNewTarget.php';
class mec_send_to_external_api
{
private $form_id;// id of the gravity form being used
function __construct()
{
// store the form id in options
$options = get_option('basecamp_form_options');
$this->form_id = ( isset( $options['ar'] ) )?$options['ar']:1;
add_action('gform_after_submission_'.$this->form_id, array( $this, mec_send_to_external_api'
), 10, 2 );
);
}
public function mec_send_to_external_api( $entry, $form ){
// map the gravity form fields to nice names
$target_name = $entry[8];
$target_short_title = $entry[14];
$target_french_short_title = $entry[15];
$target_long_title = $entry[16];
$target_french_long_title = $entry[17];
$target_image_url = $entry[2];
$target_opacity = ( float )$entry[9];
$target_overlay_type = $entry[10];
$overlay_web_url = $entry[1];
$overlay_web_internal_links = explode( ',', '' );
$overlay_web_external_links = explode( ',', '' );
$overlay_web_interactive = true;
$overlay_video_url = ( 0 < strlen( $entry[12] ) )?$entry[12]:$entry[3];
$overlay_image_url = $entry[7];
$overlay_gallery = json_decode( $entry[5] );
$overlay_gallery_caption = '';
$overlay_opacity = ( float )$entry[11];
// which overtype are we loading
switch ( $target_overlay_type ) {
case 'gallery':
$src_urls = null;
if( empty( $overlay_gallery ) ){
wp_die( "No Images in upload for gallery", 'Upload failed' );
}
$overlay_gallery = array_reverse($overlay_gallery,true);
foreach ($overlay_gallery as $key => $image_url) {
$images = null;
$resizes = make_image_resizes( parse_url( $image_url, PHP_URL_PATH ) );
$folder_URL = implode( '/',( explode( '/', $image_url, -1 ) ) );
if(false == $resizes){
wp_die( "image resize failed", 'Upload failed' );
}
foreach ($resizes as $row) {
$images[ $row['width'] ] = $folder_URL.'/'.$row['file'] ;
}
$images["src"] = $image_url ;
$images["caption"] = $overlay_gallery_caption ;
$src_urls[] = $images;
}
$type = array("images" => $src_urls );
break;
case 'video':
$type["src"] = $overlay_video_url ;
break;
case 'image':
$resizes = make_image_resizes( parse_url( $overlay_image_url, PHP_URL_PATH ) );
$folder_URL = implode( '/',( explode( '/', $overlay_image_url, -1 ) ) );
foreach ($resizes as $row) {
$type[ $row['width'] ] = $folder_URL.$row['file'] ;
}
$type["src"] = $overlay_image_url ;
break;
case 'web':
$type["src"] = $overlay_web_url ;
$type["force_internal"] = $overlay_web_internal_links;
$type["force_external"] = $overlay_web_external_links;
$type["interactive_while_tracking"] = $overlay_web_interactive;
break;
default:
$type = array(); // just in case
break;
}
$metadata = array( $target_overlay_type => $type );
$metadata['tracking_opacity'] = $target_opacity;
$metadata['centered_opacity'] = $overlay_opacity;
$metadata['title'] = $target_short_title;
$metadata['title_fr'] = $target_french_short_title;
$metadata['title_long'] = $target_long_title;
$metadata['title_long_fr'] = $target_french_long_title;
$response_text = "";
$date = new DateTime( "now", new DateTimeZone( "GMT" ) );
$external = new PostNewTarget();
$external->targetName = $target_name.$date->format( " Y-m-d-H:i:s" );
$external->imageLocation = $target_image_url;
$external->application_metadata = json_encode( $metadata );
$response = $external->push();
$response_text = $response->getBody();
}
}
$mec_send_to_external_api = new mec_send_to_external_api();
<?php
// note the 2 at the end it tell the add action to pass 2 values to the function
add_action('gform_after_submission_1', 'send_to_external_api', 10, 2 );
}
function send_to_external_api( $entry, $form ){
// 2 option radio button note the 18.1
$do_publish = ( isset( $entry['18.1'] ) && true == $entry['18.1'] )? false : true;
// esc text
$metadata['target_name'] = esc_html( $entry[8] );
// alsway cast numbers
$metadata['overlay_opacity'] = ( float )$entry[11];
// how to test for a value and switch
$metadata['video_url'] = ( 0 < strlen( $entry[12] ) )?$entry[12]:$entry[3];
// URL end up commara seperated
$metadata['_web_links'] = explode( ',', '' );
//file upload is a json srting so needs to decoding
$metadata['gallery'] = json_decode( $entry[5] );
// if you need to switch on a value been there just look for it in array
// works for selects / radio button and check boxs as you set the return values
$metadata['value_set'] = ( in_array( 'look_for_me', $entry, true ) )?true:false;
// encode value so we can send them
$args['body'] = json_encode( $metadata );
$url = 'http://somerandomserver.com/api';
//http://codex.wordpress.org/HTTP_API
//http://codex.wordpress.org/Function_Reference/wp_remote_post
wp_remote_post( $url, $args );
}
<?php
// 175 id of form
// 1 the id of form element
// send 4 values to function
add_filter("gform_field_validation_175_1", "custom_validation", 10, 4);
function custom_validation($result, $value, $form, $field){
// check have been passed is_valid as an array object
// perform a test
if(array_key_exists( "is_valid", $result ) && intval($value) > 10){
// make it invalid
$result["is_valid"] = false;
// and nice message
$result["message"] = "Please enter a value less than 10";
}
// return the update array
return $result;
}
https://github.com/rocketgenius/simpleaddon/blob/master/simpleaddon.php
https://github.com/rocketgenius/simpleaddon
<?php
/*
Plugin Name: Gravity Forms Simple Add-On
Plugin URI: http://www.gravityforms.com
Description: A simple add-on to demonstrate the use of the Add-On Framework
Version: 1.1
Author: Rocketgenius
Author URI: http://www.rocketgenius.com
------------------------------------------------------------------------
Copyright 2012-2013 Rocketgenius Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (class_exists("GFForms")) {
GFForms::include_addon_framework();
class GFSimpleAddOn extends GFAddOn {
protected $_version = "1.1";
protected $_min_gravityforms_version = "1.7.9999";
protected $_slug = "simpleaddon";
protected $_path = "asimpleaddon/asimpleaddon.php";
protected $_full_path = __FILE__;
protected $_title = "Gravity Forms Simple Add-On";
protected $_short_title = "Simple Add-On";
public function init(){
parent::init();
add_filter("gform_submit_button", array($this, "form_submit_button"), 10, 2);
}
// 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("mytextbox");
$button = "<div>{$text}</div>" . $button;
}
return $button;
}
public function plugin_page() {
?>
This page appears in the Forms menu
<?php
}
public function form_settings_fields($form) {
return array(
array(
"title" => "Simple Form Settings",
"fields" => array(
array(
"label" => "My checkbox",
"type" => "checkbox",
"name" => "enabled",
"tooltip" => "This is the tooltip",
"choices" => array(
array(
"label" => "Enabled",
"name" => "enabled"
)
)
),……….
public function settings_my_custom_field_type(){
?>
<div>
My custom field contains a few settings:
</div>
<?php
$this->settings_text(
array(
"label" => "A textbox sub-field",
"name" => "subtext",
"default_value" => "change me"
)
);
$this->settings_checkbox(
array(
"label" => "A checkbox sub-field",
"choices" => array(
array(
"label" => "Activate",
"name" => "subcheck",
"default_value" => true
)
)
)
);
}
public function plugin_settings_fields() {
return array(
array(
"title" => "Simple Add-On Settings",
"fields" => array(
array(
"name" => "mytextbox",
"tooltip" => "This is the tooltip",
"label" => "This is the label",
"type" => "text",
"class" => "small"
)
)
)
);
}
public function scripts() {
$scripts = array(
array("handle" => "my_script_js",
"src" => $this->get_base_url() . "/js/my_script.js",
"version" => $this->_version,
"deps" => array("jquery"),
"strings" => array(
'first' => __("First Choice", "simpleaddon"),
'second' => __("Second Choice", "simpleaddon"),
'third' => __("Third Choice", "simpleaddon")
),
"enqueue" => array(
array(
"admin_page" => array("form_settings"),
"tab" => "simpleaddon"
)
)
),
);
return array_merge(parent::scripts(), $scripts);
}
public function styles() {
$styles = array(
array("handle" => "my_styles_css",
"src" => $this->get_base_url() . "/css/my_styles.css",
"version" => $this->_version,
"enqueue" => array(
array("field_types" => array("poll"))
)
)
);
return array_merge(parent::styles(), $styles);
}
}
new GFSimpleAddOn();
}
Questions?
The Add-On frameworkis gearedtowards developersbuildingGravity Forms Add-Ons.It has a setof classesthatcan be extended and makethe taskof creatingan Add-On muchsimplerthan before.
The followingdocumentationpage shouldgive you a good overviewand it also linksto a coupleof sampleAdd-Onsthatyou can download from Git Hub to see thingsin action.
http://www.gravityhelp.com/documentation/page/Add-On_Framework
The WebAPI allows remoteprogramaticaccessto Gravity Form.It can be usedfor example,to implementa mobileapp,or anytimeyou needto performoperationson yourGravity Forms sitefrom a remotesite.
The followingdocumentationpage shouldgive you a good overview:
http://www.gravityhelp.com/documentation/page/Web_API
gform_pre_render–
http://www.gravityhelp.com/documentation/page/Gform_pre_render
gform_field_validation- Allows customvalidationto be doneon a specificfield.
http://www.gravityhelp.com/documentation/page/Gform_field_validation
gform_after_submission- Allows tasksto be performedaftera successfulsubmission.
http://www.gravityhelp.com/documentation/page/Gform_after_submission
Slides@ http://www.slideshare.net/pbearne
Email: pbearne@gmail.com

More Related Content

What's hot

Business Rules with Brick
Business Rules with BrickBusiness Rules with Brick
Business Rules with Brickbrian d foy
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeYoav Farhi
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Colin O'Dell
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介Jace Ju
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilorRazvan Raducanu, PhD
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteLeonardo Proietti
 
Goodbye hook_menu() - Routing and Menus in Drupal 8
Goodbye hook_menu() - Routing and Menus in Drupal 8Goodbye hook_menu() - Routing and Menus in Drupal 8
Goodbye hook_menu() - Routing and Menus in Drupal 8Exove
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en TruuksSlimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en TruuksThemePartner
 
Apostrophe
ApostropheApostrophe
Apostrophetompunk
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
Modules and injector
Modules and injectorModules and injector
Modules and injectorEyal Vardi
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 

What's hot (20)

Business Rules with Brick
Business Rules with BrickBusiness Rules with Brick
Business Rules with Brick
 
Php Enums
Php EnumsPhp Enums
Php Enums
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor14. CodeIgniter adaugarea inregistrarilor
14. CodeIgniter adaugarea inregistrarilor
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Goodbye hook_menu() - Routing and Menus in Drupal 8
Goodbye hook_menu() - Routing and Menus in Drupal 8Goodbye hook_menu() - Routing and Menus in Drupal 8
Goodbye hook_menu() - Routing and Menus in Drupal 8
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en TruuksSlimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 

Similar to WordPress overloading Gravityforms using hooks, filters and extending classes

Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Yevhen Kotelnytskyi
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Yevhen Kotelnytskyi
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPresswpnepal
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof MenżykPROIDEA
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 

Similar to WordPress overloading Gravityforms using hooks, filters and extending classes (20)

Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 

More from Paul Bearne

Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp HamiltonPaul Bearne
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stackPaul Bearne
 
Unit tests with vagrant
Unit tests with vagrantUnit tests with vagrant
Unit tests with vagrantPaul Bearne
 
How To Set a Vagrant Development System
How To Set a Vagrant Development SystemHow To Set a Vagrant Development System
How To Set a Vagrant Development SystemPaul Bearne
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created itPaul Bearne
 
WortdPress Child themes: Why and How
WortdPress Child themes: Why and HowWortdPress Child themes: Why and How
WortdPress Child themes: Why and HowPaul Bearne
 
Author Avatars List demo slides
Author Avatars List demo slidesAuthor Avatars List demo slides
Author Avatars List demo slidesPaul Bearne
 

More from Paul Bearne (10)

Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
WP json api
WP json apiWP json api
WP json api
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Unit tests with vagrant
Unit tests with vagrantUnit tests with vagrant
Unit tests with vagrant
 
How To Set a Vagrant Development System
How To Set a Vagrant Development SystemHow To Set a Vagrant Development System
How To Set a Vagrant Development System
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
WortdPress Child themes: Why and How
WortdPress Child themes: Why and HowWortdPress Child themes: Why and How
WortdPress Child themes: Why and How
 
Daughter Themes
Daughter ThemesDaughter Themes
Daughter Themes
 
Author Avatars List demo slides
Author Avatars List demo slidesAuthor Avatars List demo slides
Author Avatars List demo slides
 

Recently uploaded

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Recently uploaded (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

WordPress overloading Gravityforms using hooks, filters and extending classes

  • 2. Paul Bearne @pbearne Sr. Web Developer @ metronews.ca Plugin author of Author Avatars List ( http://wordpress.org/plugins/author-avatars/ ) WP Site Verification tool ( http://wordpress.org/plugins/wp-site-verification-tool/ )
  • 3. Agenda Gravity forms demo Options overload demo Options overload code Metro AR demo AR from code Class overload demo Class overload code
  • 5. add_filter( 'gform_pre_render', array( $this, ‘overload_gform_select_with_basecamp_user_list’), 10 ); public function overload_gform_select_with_basecamp_user_list( $form ){ $new_user_choices = null; // check we have a basecamp class $this->create_basecamp(); // lets get all basecamp users for this project $message = $this->basecamp->getPeople(); // whole account if( null == $message ){ return $form; } // loop basecamp users foreach( $message as $basecamp_user ){ $isSelected = ($this->current_user->user_email == $basecamp_user->email_address)?true:false; $new_user_choices[] = array( "text"=>esc_html( $basecamp_user->name ), "value"=>absint( $basecamp_user->id ), "isSelected"=>( bool )$isSelected, "price"=>"" ); } // loop all field and look for users foreach( $form['fields'] as &$field ){ if( in_array( $field['inputName'], $this->basecamp_user_fields ) ){ $field['choices'] = $new_user_choices; } } return $form; }
  • 6. add_filter( 'gform_pre_render', 'overload_gform_select_with_user_list', 10 ); function overload_gform_select_with_user_list( $form ){ $new_user_choices = null; // create an array of new option values $new_user_choices[] = array( 'text‘=>'admin', 'value'=>1, 'isSelected'=>false, 'price'=>'' ); $new_user_choices[] = array( 'text'=>'Paul Bearne', 'value'=>2, 'isSelected'=>true, 'price'=>'' ); $new_user_choices[] = array( 'text'=>'Username', 'value'=>3, 'isSelected'=>false, 'price'=>'' ); // loop all fields and look for Parameter Name foreach( $form['fields'] as &$field ){ if( in_array( $field['inputName'], 'Parameter_Name') ){ $field['choices'] = $new_user_choices; } } return $form; }
  • 8. <?php require_once 'external-web-services/PostNewTarget.php'; class mec_send_to_external_api { private $form_id;// id of the gravity form being used function __construct() { // store the form id in options $options = get_option('basecamp_form_options'); $this->form_id = ( isset( $options['ar'] ) )?$options['ar']:1; add_action('gform_after_submission_'.$this->form_id, array( $this, mec_send_to_external_api' ), 10, 2 ); ); } public function mec_send_to_external_api( $entry, $form ){ // map the gravity form fields to nice names $target_name = $entry[8]; $target_short_title = $entry[14]; $target_french_short_title = $entry[15]; $target_long_title = $entry[16]; $target_french_long_title = $entry[17]; $target_image_url = $entry[2]; $target_opacity = ( float )$entry[9]; $target_overlay_type = $entry[10]; $overlay_web_url = $entry[1]; $overlay_web_internal_links = explode( ',', '' ); $overlay_web_external_links = explode( ',', '' ); $overlay_web_interactive = true; $overlay_video_url = ( 0 < strlen( $entry[12] ) )?$entry[12]:$entry[3]; $overlay_image_url = $entry[7]; $overlay_gallery = json_decode( $entry[5] ); $overlay_gallery_caption = ''; $overlay_opacity = ( float )$entry[11]; // which overtype are we loading switch ( $target_overlay_type ) { case 'gallery': $src_urls = null; if( empty( $overlay_gallery ) ){ wp_die( "No Images in upload for gallery", 'Upload failed' ); } $overlay_gallery = array_reverse($overlay_gallery,true); foreach ($overlay_gallery as $key => $image_url) { $images = null; $resizes = make_image_resizes( parse_url( $image_url, PHP_URL_PATH ) ); $folder_URL = implode( '/',( explode( '/', $image_url, -1 ) ) ); if(false == $resizes){ wp_die( "image resize failed", 'Upload failed' ); } foreach ($resizes as $row) { $images[ $row['width'] ] = $folder_URL.'/'.$row['file'] ; } $images["src"] = $image_url ; $images["caption"] = $overlay_gallery_caption ; $src_urls[] = $images; } $type = array("images" => $src_urls ); break; case 'video': $type["src"] = $overlay_video_url ; break;
  • 9. case 'image': $resizes = make_image_resizes( parse_url( $overlay_image_url, PHP_URL_PATH ) ); $folder_URL = implode( '/',( explode( '/', $overlay_image_url, -1 ) ) ); foreach ($resizes as $row) { $type[ $row['width'] ] = $folder_URL.$row['file'] ; } $type["src"] = $overlay_image_url ; break; case 'web': $type["src"] = $overlay_web_url ; $type["force_internal"] = $overlay_web_internal_links; $type["force_external"] = $overlay_web_external_links; $type["interactive_while_tracking"] = $overlay_web_interactive; break; default: $type = array(); // just in case break; } $metadata = array( $target_overlay_type => $type ); $metadata['tracking_opacity'] = $target_opacity; $metadata['centered_opacity'] = $overlay_opacity; $metadata['title'] = $target_short_title; $metadata['title_fr'] = $target_french_short_title; $metadata['title_long'] = $target_long_title; $metadata['title_long_fr'] = $target_french_long_title; $response_text = ""; $date = new DateTime( "now", new DateTimeZone( "GMT" ) ); $external = new PostNewTarget(); $external->targetName = $target_name.$date->format( " Y-m-d-H:i:s" ); $external->imageLocation = $target_image_url; $external->application_metadata = json_encode( $metadata ); $response = $external->push(); $response_text = $response->getBody(); } } $mec_send_to_external_api = new mec_send_to_external_api();
  • 10. <?php // note the 2 at the end it tell the add action to pass 2 values to the function add_action('gform_after_submission_1', 'send_to_external_api', 10, 2 ); } function send_to_external_api( $entry, $form ){ // 2 option radio button note the 18.1 $do_publish = ( isset( $entry['18.1'] ) && true == $entry['18.1'] )? false : true; // esc text $metadata['target_name'] = esc_html( $entry[8] ); // alsway cast numbers $metadata['overlay_opacity'] = ( float )$entry[11]; // how to test for a value and switch $metadata['video_url'] = ( 0 < strlen( $entry[12] ) )?$entry[12]:$entry[3]; // URL end up commara seperated $metadata['_web_links'] = explode( ',', '' ); //file upload is a json srting so needs to decoding $metadata['gallery'] = json_decode( $entry[5] ); // if you need to switch on a value been there just look for it in array // works for selects / radio button and check boxs as you set the return values $metadata['value_set'] = ( in_array( 'look_for_me', $entry, true ) )?true:false; // encode value so we can send them $args['body'] = json_encode( $metadata ); $url = 'http://somerandomserver.com/api'; //http://codex.wordpress.org/HTTP_API //http://codex.wordpress.org/Function_Reference/wp_remote_post wp_remote_post( $url, $args ); }
  • 11. <?php // 175 id of form // 1 the id of form element // send 4 values to function add_filter("gform_field_validation_175_1", "custom_validation", 10, 4); function custom_validation($result, $value, $form, $field){ // check have been passed is_valid as an array object // perform a test if(array_key_exists( "is_valid", $result ) && intval($value) > 10){ // make it invalid $result["is_valid"] = false; // and nice message $result["message"] = "Please enter a value less than 10"; } // return the update array return $result; }
  • 12. https://github.com/rocketgenius/simpleaddon/blob/master/simpleaddon.php https://github.com/rocketgenius/simpleaddon <?php /* Plugin Name: Gravity Forms Simple Add-On Plugin URI: http://www.gravityforms.com Description: A simple add-on to demonstrate the use of the Add-On Framework Version: 1.1 Author: Rocketgenius Author URI: http://www.rocketgenius.com ------------------------------------------------------------------------ Copyright 2012-2013 Rocketgenius Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  • 13. if (class_exists("GFForms")) { GFForms::include_addon_framework(); class GFSimpleAddOn extends GFAddOn { protected $_version = "1.1"; protected $_min_gravityforms_version = "1.7.9999"; protected $_slug = "simpleaddon"; protected $_path = "asimpleaddon/asimpleaddon.php"; protected $_full_path = __FILE__; protected $_title = "Gravity Forms Simple Add-On"; protected $_short_title = "Simple Add-On"; public function init(){ parent::init(); add_filter("gform_submit_button", array($this, "form_submit_button"), 10, 2); } // 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("mytextbox"); $button = "<div>{$text}</div>" . $button; } return $button; }
  • 14. public function plugin_page() { ?> This page appears in the Forms menu <?php } public function form_settings_fields($form) { return array( array( "title" => "Simple Form Settings", "fields" => array( array( "label" => "My checkbox", "type" => "checkbox", "name" => "enabled", "tooltip" => "This is the tooltip", "choices" => array( array( "label" => "Enabled", "name" => "enabled" ) ) ),……….
  • 15. public function settings_my_custom_field_type(){ ?> <div> My custom field contains a few settings: </div> <?php $this->settings_text( array( "label" => "A textbox sub-field", "name" => "subtext", "default_value" => "change me" ) ); $this->settings_checkbox( array( "label" => "A checkbox sub-field", "choices" => array( array( "label" => "Activate", "name" => "subcheck", "default_value" => true ) ) ) ); }
  • 16. public function plugin_settings_fields() { return array( array( "title" => "Simple Add-On Settings", "fields" => array( array( "name" => "mytextbox", "tooltip" => "This is the tooltip", "label" => "This is the label", "type" => "text", "class" => "small" ) ) ) ); }
  • 17. public function scripts() { $scripts = array( array("handle" => "my_script_js", "src" => $this->get_base_url() . "/js/my_script.js", "version" => $this->_version, "deps" => array("jquery"), "strings" => array( 'first' => __("First Choice", "simpleaddon"), 'second' => __("Second Choice", "simpleaddon"), 'third' => __("Third Choice", "simpleaddon") ), "enqueue" => array( array( "admin_page" => array("form_settings"), "tab" => "simpleaddon" ) ) ), ); return array_merge(parent::scripts(), $scripts); }
  • 18. public function styles() { $styles = array( array("handle" => "my_styles_css", "src" => $this->get_base_url() . "/css/my_styles.css", "version" => $this->_version, "enqueue" => array( array("field_types" => array("poll")) ) ) ); return array_merge(parent::styles(), $styles); } } new GFSimpleAddOn(); }
  • 20. The Add-On frameworkis gearedtowards developersbuildingGravity Forms Add-Ons.It has a setof classesthatcan be extended and makethe taskof creatingan Add-On muchsimplerthan before. The followingdocumentationpage shouldgive you a good overviewand it also linksto a coupleof sampleAdd-Onsthatyou can download from Git Hub to see thingsin action. http://www.gravityhelp.com/documentation/page/Add-On_Framework The WebAPI allows remoteprogramaticaccessto Gravity Form.It can be usedfor example,to implementa mobileapp,or anytimeyou needto performoperationson yourGravity Forms sitefrom a remotesite. The followingdocumentationpage shouldgive you a good overview: http://www.gravityhelp.com/documentation/page/Web_API gform_pre_render– http://www.gravityhelp.com/documentation/page/Gform_pre_render gform_field_validation- Allows customvalidationto be doneon a specificfield. http://www.gravityhelp.com/documentation/page/Gform_field_validation gform_after_submission- Allows tasksto be performedaftera successfulsubmission. http://www.gravityhelp.com/documentation/page/Gform_after_submission