Forums

XML RPC and PHP (9 posts)

  1. jhbalaji
    Member
    Posted 2 years ago #

    Hello,
    I am using the WP 2.9 and i need to use XML RPC Feature in WP to posts the Blog Post
    When i use PHP and XML RPC it does not works

    I have enabled the XML RPC feature in WP and here is the PHP Code i used

    Can some one say how can i fix this??

    <?php
        $username = "testuser";
        $password = "itestpaass";
        $rpurl = "http://domain.com/xmlrpc.php";
        $categories = "info";
        $title = "We want a test post";
        $categories = "Test";
        $body = "This is the body of the post"
    
    function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1))
    {
    
        $params = array('','',$username,$password,1);
        $request = xmlrpc_encode_request('blogger.newPost',$params);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        curl_setopt($ch, CURLOPT_URL, $rpcurl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);
        curl_exec($ch);
        curl_close($ch);
    
    };
    
    ?>

    Thanks in advance!

  2. Joseph Scott
    Member
    Posted 2 years ago #

    What sort of error gets returned? Did you look at the raw XML your script is sending to verify that it looks right?

    Have you considered using the IXR library for XML-RPC calls? It ships with WP (it is in wp-includes/class-IXR.php).

  3. jhbalaji
    Member
    Posted 2 years ago #

    Joseph i mailed you from your Blog

    Also can i get more details about the IR Library

    thanks :)

  4. Joseph Scott
    Member
    Posted 2 years ago #

  5. jhbalaji
    Member
    Posted 2 years ago #

    The problem seems to be from my Host, DreamHost those Guys refuse to activate XML extension in php.ini and bluffing other things!
    Even i followed their Wiki But it did not worked for me even after following them
    But it works fine from my localhost using XAMPP

    Any alternative suggestion!
    Thanks any way! :)

  6. jhbalaji
    Member
    Posted 2 years ago #

    Ooops!! Even in localhost its not working now!
    I am in need of your help!

  7. Joseph Scott
    Member
    Posted 2 years ago #

    You'll need to provide more information, like what exactly the HTTP response was to the XML-RPC request.

  8. onlyjf
    Member
    Posted 1 year ago #

    <?php

    function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8')
    {
    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

    $content = array(
    'title'=>$title,
    'description'=>$body,
    'mt_allow_comments'=>0,
    'mt_allow_pings'=>0,
    'post_type'=>'post',
    'mt_keywords'=>$keywords,
    'categories'=>array($category)
    );

    $params = array(0,$username,$password,$content,true);
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, $rpcurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    $results = curl_exec($ch);
    curl_close($ch);
    return $results;
    }

    $title = 'test';
    $body = 'test';
    $rpcurl = 'http://address/xmlrpc.php';
    $username = 'test';
    $password = 'test';
    $category = 'test';

    $chk = wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8');

    if($chk){
    echo $chk;
    }else{
    echo 'failed';
    }

    ?>

    You should try this one..

  9. asksuperuser
    Member
    Posted 1 year ago #

    I prefer using a direct connection to the database with a destop script:
    http://askblogautomation.com/blog/create-a-new-wordpress-post-programmatically/

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags