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
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
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