Okay.

Yesterday I made some basic stuff to grab my WordPress blog data with visual basic for applicationsn cos I don’t feel like programming php admin pages for tables.

So let’s make a basic xml-rpc crud plugin and put my agenda on vba remote control.

The basic xml-rpc plugin is simple, plug extra methods into the xml-rpc method array, and write a function per crud-method.


add_filter( 'xmlrpc_methods', 'add_agenda_xmlrpc_methods' );

function add_agenda_xmlrpc_methods( $methods ) {
    $methods['agenda.addAgendaItem'] = 'addAgendaItem';
    $methods['agenda.updateAgendaItem'] = 'updateAgendaItem';
    $methods['agenda.deleteAgendaItem'] = 'deleteAgendaItem';
    $methods['agenda.reportAgendaItem'] = 'reportAgendaItem';
    return $methods;
}

function addAgendaItem($args) { }

function updateAgendaItem($args) { }

function deleteAgendaItem($args) { }

function reportAgendaItem($args) { }

//basic login helper function
function CheckLogin($user, $pwd) {}

There now, if I call on the xmlrpc.php file, the extra methods are added to the callback array and I can use the table CRUD functions from my vba desktop.

function addAgendaItem($args) {

        $blog_id	= (int) $args[0];
        $username	= $args[1];
        $password	= $args[2];
        $AgendaItem     = $args[3];

//remember : add a login check
//(for the example it is irrelevant)

        global $wpdb;
        $sql = "INSERT INTO ".$wpdb->prefix."Agenda (
                `userid`, `tags`, `description`, `firstdate`, `enddate`, `link`, `price`, `location`
                ) VALUES (
                '".$AgendaItem[0]['userid']."',
                '".$AgendaItem[0]['tags']."',
                '".$AgendaItem[0]['description']."',
                '".$AgendaItem[0]['firstdate']."',
                '".$AgendaItem[0]['enddate']."',
                '".$AgendaItem[0]['link']."',
                '".$AgendaItem[0]['price']."',
                '".$AgendaItem[0]['location']."'                
                )";
        $wpdb->query($wpdb->prepare($sql));

        return $wpdb->insert_id;
}

note : the agendaitem is a struct in an array (see below), I use [0] to get the first struct (which is the actual array with field-value pairs, my record with agenda info).

Activate the plugin, and write a simple test


'Type to hold an agenda info record
Type AgendaItem
    userid As String
    tags As String
    Description As String
    firstdate As String
    enddate As String
    link As String
    price As String
    location As String
End Type


Function AddAgendaItem()

txtURL = "http://wwwblog.com/xmlrpc.php"
txtUserName = "MyUsername"
txtPassword = "MyPassword"
  
  Dim objSvrHTTP As ServerXMLHTTP
  Dim strT As String
  Set objSvrHTTP = New ServerXMLHTTP
  
  objSvrHTTP.Open "POST", txtURL, False, CStr(txtUserName), _
   CStr(txtPassword)
  
  objSvrHTTP.setRequestHeader "Accept", "application/xml"
  objSvrHTTP.setRequestHeader "Content-Type", "application/xml"
  
    strT = ""
    strT = strT & ""
    strT = strT & "agenda.addAgendaItem"
    
    strT = strT & ""
    strT = strT & "" & txtBlogId & ""
    strT = strT & "" & txtUserName & ""
    strT = strT & "" & txtPassword & ""

'now we go make the struct, I use a Type (stdobject), normally
'you'd use a recordset

Dim a As AgendaItem

With a
    .userid = 1
    .Description = "rpc testing"
    .firstdate = "2009/10/14"
    .enddate = "2009/10/14"
    .link = "https://www.juust.org/"
    .price = "rpc testing"
    .location = "limmen"
    .tags = "php, xml-rpc"
End With

    strT = strT & ""
    strT = strT & ""
    
    strT = strT & ""

    strT = strT & "userid" & a.userid & ""
    strT = strT & "tags" & a.tags & ""
    strT = strT & "description" & a.Description & ""
    strT = strT & "firstdate" & a.firstdate & ""
    strT = strT & "enddate" & a.enddate & ""
    strT = strT & "link" & a.link & ""
    strT = strT & "price" & a.price & ""
    strT = strT & "location" & a.location & ""

'close the struct    
    strT = strT & ""
    strT = strT & ""

'close the struct array
    strT = strT & ""

'end parameters
    strT = strT & ""

'end method
    strT = strT & ""

'send the lot to the blog  
  objSvrHTTP.send strT

'print the response to debug 
  Debug.Print  objSvrHTTP.responseText

End function

Et voila :

agenda rpc

That’s yer basic Office-Wordpress XML-RPC integration.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top