SlideShare a Scribd company logo
1 of 15
WordPress Custom Page Settings
Salesforce + Gravity Forms API
Integration Showcase
#HANOI #WORDPRESS MEETUP
10 April 2019
Khoi Nguyen
Technical Lead
Solis Lab
About Me
Nguyễn Minh Khôi
khoipro.com
khoiprodotcom@gmail.com
#Fullstack #Frontend #Developer
Technical Lead
solislab.com
Locale Manager
vi.wordpress.org
Blogger
codetot.com, wphub.vn, hosttot.vn
2
Custom Page Settings
• Adding Administrator Menu Items
(https://codex.wordpress.org/Adding_Administration_Menus)
• Creating Options Pages
(https://codex.wordpress.org/Creating_Options_Pages)
• Register Sections
• Register Fields
3
Administrator Menu Items
General Functions
● add_menu_page()
● add_object_page()
● add_utility_page()
● remove_menu_page()
● add_submenu_page()
● remove_submenu_page()
4
Menu Page
Sub-Menu Page
Administrator Menu Items
WordPress Administration Menus
● add_dashboard_page()
● add_posts_page()
● add_media_page()
● add_pages_page()
● add_comments_page()
● add_theme_page()
● add_plugins_page()
● add_users_page()
● add_management_page()
● add_options_page()
5
Code Example
Administrator Menu Items
add_action( 'admin_menu', ‘salesforce_api_page_setup’ );
function salesforce_api_page_setup() {
add_options_page('Salesforce API', 'Salesforce API',
'manage_options', 'salesforce-api', ‘salesforce_api_page’);
}
function salesforce_api_page() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access
this page.' ) );
}
?>
<div class="wrap">
<p>Here is where the form would go if I actually had
options.</p>
</div>
<?php
6
Code Example
Creating Options Page
<div class="wrap">
<h1>My Settings</h1>
<form method="post" action="options.php">
<?php
// This prints out all hidden setting fields
settings_fields(‘salesforce_api_settings’);
// This will output all input fields
do_settings_sections( 'salesforce_api_section' );
// This will output a submit button
submit_button();
?>
</form>
</div>
7
Code Example
Creating Options Page
add_action( 'admin_init', array( $this,
‘salesforce_api_register_fields’ ) );
function salesforce_api_register_fields() {
register_setting(
‘salesforce_api_settings’, // Option group
‘salesforce_api_consumer_key’, // Option name
array(
‘type’ => ‘string’,
‘Sanitize’ => ‘sanitize_text_field’ // Prevent
)
);
add_settings_section(
'salesforce_api_section', // ID
'Salesforce API Settings', // Title
function() { return ‘’; }, // Callback
'salesforce-api' // Page
);
}
8
add_settings_field(
‘salesforce_api_consumer_key’, // ID
'Consumer Key’, // Label
‘render_input’,’
'salesforce-api', // Page
'salesforce_api_section’ // Section,
array(
‘id’ => ‘salesforce_api_consumer_key’
)
);
function render_input($item) {
$value = get_option($item[‘id’]);
echo ‘<input class=”regular-text”
type=”text” value=”’ . $value . ’”>’;
}
Walkthrough
See how it actually works in a real practice.
9
Salesforce API + Gravity Form
10
Salesforce API
Gravity Form
(WordPress plugin)
WordPress Website
(for example: https://demo.test)
OAuth 2 Token Access
gform_pre_submission() hook
Allowed
permissions
from Salesforce
Steps
1. Register Custom Page Settings
2.Register basic Custom Field Settings and Section
3.Register Gravity Form select setting
4.Setup ?action=authorize to get access token
5.Setup ?action=revoke to revoke access token
6.Setup an All Object select
7.Setup a Fields Object select
8.Setup Mapping fields Field Setting
9.Mapping Existing Gravity Form Fields with fields
from Lead
11
Dev Notes
WordPress wp-admin Environment
get_query_var(‘action’) not working. Using $_GET[‘action’] instead.
To make a redirect, using:
wp_redirect($url);
die();
To add query arguments to url:
add_query_arg(array(‘action’, ‘revoke’), admin_url(‘/options-
general.php’))
12
Dev Notes
Gravity Form Submission
To send a submission to another third party, trigger action:
gform_pre_submission()
13
Dev Notes
Salesforce API
- App Settings:
- Remove timeout of refresh/access token.
- Setup “Relax IP restriction”
- Setup a correct callback, can be multiple callbacks
- Using HTTPS connection
- API Request Response
- The body request contains `message` to read the error. Can be
read through wp_remote_retrieve_body($response) function
- Error output: WordPress provides add_settings_error() to display
a message in the default style.
14
Follow more resources
#WPVN - vi.wordpress.org
SOLIS LAB - solislab.com
CODE TỐT - codetot.net
WPHUB - wphub.vn
15

More Related Content

Similar to WordPress - Custom Page Settings + Salesforce API Integration

Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
Oro Inc.
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
fool2nd
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
fiyuer
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
Angularjs Live Project
Angularjs Live ProjectAngularjs Live Project
Angularjs Live Project
Mohd Manzoor Ahmed
 

Similar to WordPress - Custom Page Settings + Salesforce API Integration (20)

Simple Contact Us Plugin Development
Simple Contact Us Plugin DevelopmentSimple Contact Us Plugin Development
Simple Contact Us Plugin Development
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
 
Breaking the limits_of_page_objects
Breaking the limits_of_page_objectsBreaking the limits_of_page_objects
Breaking the limits_of_page_objects
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Empowering users: modifying the admin experience
Empowering users: modifying the admin experienceEmpowering users: modifying the admin experience
Empowering users: modifying the admin experience
 
A test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobileA test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobile
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014
 
Sahana Eden - Introduction to the Code
Sahana Eden - Introduction to the CodeSahana Eden - Introduction to the Code
Sahana Eden - Introduction to the Code
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
 
Parallelminds.web partdemo1
Parallelminds.web partdemo1Parallelminds.web partdemo1
Parallelminds.web partdemo1
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
Extending eZ Platform v2 with Symfony and React
Extending eZ Platform v2 with Symfony and ReactExtending eZ Platform v2 with Symfony and React
Extending eZ Platform v2 with Symfony and React
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
WordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcodeWordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcode
 
Angularjs Live Project
Angularjs Live ProjectAngularjs Live Project
Angularjs Live Project
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

WordPress - Custom Page Settings + Salesforce API Integration

  • 1. WordPress Custom Page Settings Salesforce + Gravity Forms API Integration Showcase #HANOI #WORDPRESS MEETUP 10 April 2019 Khoi Nguyen Technical Lead Solis Lab
  • 2. About Me Nguyễn Minh Khôi khoipro.com khoiprodotcom@gmail.com #Fullstack #Frontend #Developer Technical Lead solislab.com Locale Manager vi.wordpress.org Blogger codetot.com, wphub.vn, hosttot.vn 2
  • 3. Custom Page Settings • Adding Administrator Menu Items (https://codex.wordpress.org/Adding_Administration_Menus) • Creating Options Pages (https://codex.wordpress.org/Creating_Options_Pages) • Register Sections • Register Fields 3
  • 4. Administrator Menu Items General Functions ● add_menu_page() ● add_object_page() ● add_utility_page() ● remove_menu_page() ● add_submenu_page() ● remove_submenu_page() 4 Menu Page Sub-Menu Page
  • 5. Administrator Menu Items WordPress Administration Menus ● add_dashboard_page() ● add_posts_page() ● add_media_page() ● add_pages_page() ● add_comments_page() ● add_theme_page() ● add_plugins_page() ● add_users_page() ● add_management_page() ● add_options_page() 5
  • 6. Code Example Administrator Menu Items add_action( 'admin_menu', ‘salesforce_api_page_setup’ ); function salesforce_api_page_setup() { add_options_page('Salesforce API', 'Salesforce API', 'manage_options', 'salesforce-api', ‘salesforce_api_page’); } function salesforce_api_page() { if ( !current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } ?> <div class="wrap"> <p>Here is where the form would go if I actually had options.</p> </div> <?php 6
  • 7. Code Example Creating Options Page <div class="wrap"> <h1>My Settings</h1> <form method="post" action="options.php"> <?php // This prints out all hidden setting fields settings_fields(‘salesforce_api_settings’); // This will output all input fields do_settings_sections( 'salesforce_api_section' ); // This will output a submit button submit_button(); ?> </form> </div> 7
  • 8. Code Example Creating Options Page add_action( 'admin_init', array( $this, ‘salesforce_api_register_fields’ ) ); function salesforce_api_register_fields() { register_setting( ‘salesforce_api_settings’, // Option group ‘salesforce_api_consumer_key’, // Option name array( ‘type’ => ‘string’, ‘Sanitize’ => ‘sanitize_text_field’ // Prevent ) ); add_settings_section( 'salesforce_api_section', // ID 'Salesforce API Settings', // Title function() { return ‘’; }, // Callback 'salesforce-api' // Page ); } 8 add_settings_field( ‘salesforce_api_consumer_key’, // ID 'Consumer Key’, // Label ‘render_input’,’ 'salesforce-api', // Page 'salesforce_api_section’ // Section, array( ‘id’ => ‘salesforce_api_consumer_key’ ) ); function render_input($item) { $value = get_option($item[‘id’]); echo ‘<input class=”regular-text” type=”text” value=”’ . $value . ’”>’; }
  • 9. Walkthrough See how it actually works in a real practice. 9
  • 10. Salesforce API + Gravity Form 10 Salesforce API Gravity Form (WordPress plugin) WordPress Website (for example: https://demo.test) OAuth 2 Token Access gform_pre_submission() hook Allowed permissions from Salesforce
  • 11. Steps 1. Register Custom Page Settings 2.Register basic Custom Field Settings and Section 3.Register Gravity Form select setting 4.Setup ?action=authorize to get access token 5.Setup ?action=revoke to revoke access token 6.Setup an All Object select 7.Setup a Fields Object select 8.Setup Mapping fields Field Setting 9.Mapping Existing Gravity Form Fields with fields from Lead 11
  • 12. Dev Notes WordPress wp-admin Environment get_query_var(‘action’) not working. Using $_GET[‘action’] instead. To make a redirect, using: wp_redirect($url); die(); To add query arguments to url: add_query_arg(array(‘action’, ‘revoke’), admin_url(‘/options- general.php’)) 12
  • 13. Dev Notes Gravity Form Submission To send a submission to another third party, trigger action: gform_pre_submission() 13
  • 14. Dev Notes Salesforce API - App Settings: - Remove timeout of refresh/access token. - Setup “Relax IP restriction” - Setup a correct callback, can be multiple callbacks - Using HTTPS connection - API Request Response - The body request contains `message` to read the error. Can be read through wp_remote_retrieve_body($response) function - Error output: WordPress provides add_settings_error() to display a message in the default style. 14
  • 15. Follow more resources #WPVN - vi.wordpress.org SOLIS LAB - solislab.com CODE TỐT - codetot.net WPHUB - wphub.vn 15