Pubblicare articoli in WordPress da remoto con PHP

Posted on agosto 26, 2010
Filed Under Blog | 4 Comments

Oggi cercheremo di capire come e’ possibile pubblicare articoli da remoto sulle piattaforme WordPress usando PHP. In particolare bastera’ avere un server Web con PHP sulla propria macchina locale e, senza collegarsi direttamente ai sito realizzati con WordPress, preparare il proprio articolo in locale e pubblicarlo direttamente.

Per poter utilizzare lo script occorre abilitare l’estenzione php_xmlrpc e verificare che il nostro blog in WordPress accetti i post. Per far cio’ bastera’ collegarsi all’url:

http://<MIOSITO>/xmlrpc.php

dove <MIOSITO> e’ l’url de sito in WordPress, ad es.: http://www.freescriptphp.com/xmlrpc.php e verificare che compaia a video la scritta:
XML-RPC server accepts POST requests only.

Se cio’ non compare occorre abilitare i protocolli XML-RPC di pubblicazione WordPress presenti nel pannello Impostazioni –> Scrittura.

<?php
$sito = “www.freescriptphp.com“;   // URL DEL SITO SENZA HTTP://
$username = “leofire“;   // USERANAME
$password = “lamiapassword“;   // PASSWORD

$title = “titolo”;   // TITOLO DEL POST
$body = “corpo<br><b>bold</b>”;    // TESTO IN HTML DEL POST
$keywords = “keywords”;   // KEYWORDS DEL POST

// CARICA IL CONTENUTO
$content = array(
‘title’=>$title,
‘description’=>$body,
‘mt_allow_comments’=>1, // 1 per rendere il post commentabile
‘mt_allow_pings’=>0, // 1 per abilitare i trackbacks
‘post_type’=>’post’,
‘post_status’=>’pending’,  // Indica lo status in cui viene messo il post (in questo caso non viene pubblicato subito
‘mt_keywords’=>$keywords,
‘mt.publishPost’=>’review’
);
$params = array(0,$username,$password,$content,false);
$request = xmlrpc_encode_request(‘metaWeblog.newPost’,$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, “http://$sito/xmlrpc.php”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$results = curl_exec($ch);
curl_close($ch);
echo $results;
?>

L’utility invia in POST tramite CURL i dati necessari ad effettuare l’autenticazione e procede alla pubblicazione del post sul nostro sito / blog.

Happy remote post a tutti!

Others Script adv

4 Responses to “Pubblicare articoli in WordPress da remoto con PHP”

  1. guide in Russia on dicembre 4th, 2010 12:37

    Ho appena aggiunto il tuo feed ai miei favoriti. Mi piace molto leggere il tuo post.

  2. leofire on dicembre 11th, 2010 15:01

    Grazie mille per l’add…il problema e’ trovare il tempo per postare! A cosa sarebbe interessato ?

  3. watch shows online on dicembre 19th, 2010 09:55

    Ah! finalmente ho trovato quello che cercavo. A volte ci vuole tanta fatica a trovare anche una minima parte di informazioni utili.

  4. leofire on dicembre 19th, 2010 13:42

    Cerchiamo di fare il possibile; suggerimenti e critiche sono ben accetti! (:

Leave a Reply