Нужен образец кода, показывающий, как отправлять сообщения в Wordpress с помощью Codeigniter

Есть ли у кого-нибудь образец кода, которым они могут поделиться, который показывает, как сделать базовое сообщение в блоге в Wordpress с помощью библиотеки CodeIgniter xml-rpc?

Пока у меня есть это, что всегда приводит к "неправильной комбинации логин / пароль", хотя я использую правильную комбинацию.

function doPost(){

    $this->load->library('xmlrpc');

    $bloguser = "theUserid";
    $blogpass = "thePassword";
    $blogid = 0; //I've tried 0 and 1 here. 
    $post['title'] = "The title of a new post";
    $post['description'] = "The body of the post.";
    $this->xmlrpc->server("http://localhost/blog/xmlrpc.php", 80);
    $this->xmlrpc->method('metaWeblog.newPost');

    $this->xmlrpc->request = array($blogid, $bloguser, $blogpass, $post, TRUE);
    if ( ! $this->xmlrpc->send_request())
    {
        echo $this->xmlrpc->display_error();
    }
    else
    {
        echo '<pre>';
        print_r($this->xmlrpc->display_response());
        echo '</pre>';
    }
}

person user149052    schedule 24.08.2009    source источник


Ответы (1)


После долгого скрежета зубами вроде как работает:

function doPost(){

    $this->load->library('xmlrpc');

    $bloguser = "theUserID";
    $blogpass = "thePassword";
    $blogid = 1; 
    $publishImmediately = TRUE;

    $thePost = array(array('title'  => array('this is the title','string'),
                            'description'    => array('this is the description','string')
                            ),
                     'struct');               


    $myPost = "my post";
    //$this->xmlrpc->set_debug(TRUE);
    $this->xmlrpc->server("http://url.to/xmlrpc.php", 80);
    $this->xmlrpc->method('metaWeblog.newPost');

    $request = array($blogid, $bloguser, $blogpass, $thePost, $publishImmediately);

    $this->xmlrpc->request($request);
    $result = $this->xmlrpc->send_request();

    if ( !$result )
    {
        echo $this->xmlrpc->display_error();
    }
    else
    {
        echo '<pre>';
        print_r($this->xmlrpc->display_response());
        echo '</pre>';
    }
}

Важная часть - отметить структуру элементов фактического сообщения.

person user149052    schedule 24.08.2009
comment
Буду признателен за любую обратную связь, чтобы узнать, есть ли другие / лучшие способы сделать это. - person user149052; 25.08.2009
comment
какие-нибудь Новости? Вы нашли способ лучше? - person MR.GEWA; 20.01.2012