Integration · Lightning · Salesforce

Salesforce Integration with WordPress

This post will help you to integrate Salesforce with WordPress and access the blogs in Salesforce from WordPress. Here we are getting the blog from a linked WordPress account and displaying it in a lightning modal popup in Salesforce.

Steps to be implemented:

1. Create an app in WordPress application manager [create App]. Redirect URL for this application will be the lightning component application URL which was created to run the whole process. After the application is created we can get the OAuth information which includes client id and client secret.

Below images will show how to create Application in wordpress.

This slideshow requires JavaScript.

2. Add the following endpoints in remote site settings in salesforce org.


3.  For better understanding I have a lightning component with three buttons which will authorize, get the access token and get the blogs from the wordpress.

Lightning Component:

<aura:component controller="accesstoken" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="url" type="String" />
    <aura:attribute name="accesstoken" type="String" />
    <aura:attribute name="content" type="string" />
    <aura:attribute name="code" type="string" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:layout verticalAlign="center" horizontalAlign="center" >
        <lightning:layoutitem padding="around-small" >
            <lightning:layout verticalAlign="center" horizontalAlign="center">
                <lightning:button label="Authorize" 
                                  class="slds-button slds-show" 

                <lightning:button label="Request AccessToken" 
                                  class="slds-button slds-show" 

                <lightning:button label="Get Blog" 
                                  class="slds-button slds-show" 

    <div class="slds-hide" aura:id="conmodal" style="height: 1800px;">
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <header class="slds-modal__header" style="background: #05668D;">
                    <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate" style="color:white;"><b>Blog</b></h2>
                <div class="slds-modal__content slds-p-around_medium" aura:id="modal-content-id-1">

                    <div class="slds-container--center slds-container--small slds-m-top--small">
                        <aura:unescapedHtml value="{!v.content}"/>


                <footer class="slds-modal__footer slds-show" aura:id="footer1">

                    <button class="slds-button button1" aura:id="button-modal-1" style="background: #05668D;color:white;width:130px;" onclick="{!c.hideModal}">

        <div class="slds-backdrop slds-backdrop_open"></div>


Below image is our lightning app with the three buttons.


4. On click of Authorize button we are hitting the wordpress endpoint for authorization.

Client side controller:

Authorize: function(component, event, helper){




After approving we will be redirected to our lightning application. Now we need the Access Token to make API calls. For getting the access token we need the authorization code which we got in the redirected page URL.

5. Now click on the Request Access Token button.

Client side Controller:

  GetAccess: function(component, event, helper){
        var action=component.get("c.getaccess");
            var state=response.getState();
                var result=response.getReturnValue();



Apex code:

   public static string getaccess(string code)
        string clientid=$CLIENTID;
        String redirect_uri = $APPURL;
        String endPoint = '';
        string clientSecret=$CLIENTSECRET;
        String requestTokenBody = 'client_id='+clientid+'&redirect_uri='+redirect_uri+'&client_secret='+
        Http http = new Http();
        httpRequest httpReq = new httpRequest();
        HttpResponse response = new HttpResponse();
        response = http.send(httpReq);
        Map TokenInfo = (Map)JSON.deserializeUntyped(response.getBody());
        string access=String.valueOf(TokenInfo.get('access_token'));
        return access;

6. Now in response we will get the access token. With the help of the access token we will get the blog details.

   send : function(component, event, helper) {

        var action=component.get("c.getBlogs");
        var access=component.get("v.accesstoken");
        var url="";
            var state=response.getState();
                var result=response.getReturnValue();




The above example illustrate how to get the blog details. we are displaying the blog in the modal popup on click of Get Blog button.

    public static string getBlogs(string url,string access)
        Http http = new Http();
        httpRequest httpReq = new httpRequest();
        httpReq.setHeader('Authorization','Bearer '+access);
        HttpResponse response = new HttpResponse();
        response = http.send(httpReq);
        Map lisdata=(Map)JSON.deserializeUntyped(String.valueOf(response.getBody()));
        list values=(list)lisdata.get('posts');
        map smap=(Map)values[0];
        string result=string.valueof(smap.get('content'));
        return result;

Displaying blog in Modal popup:






2 thoughts on “Salesforce Integration with WordPress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s