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
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"
)
)
)
);
}
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