Category Archives: wordpress

Send a multipart/form-data request in PHP


To List your current indexes with ‘standard’ flavor use a GET request to the List Indexes API.

$url_listindexes = '';
$params1 = 'flavor=standard&apikey='.$apikey;
$response = file_get_contents($url_listindexes .'?'.$params1);
if($response) { $json = json_decode($response); if($json){ $indexes = $json->index; } return $indexes; }


POST multipart/form-data with native PHP

function send_multipart_post_message($sync_or_async, $json1){
$url = "".$sync_or_async."/addtotextindex/v1";
// using WordPress custom functions to retrieve index and apikey
$index1 = wp_idolondemand_get_setting('index');
$apikey = wp_idolondemand_get_setting('apikey');
$eol = "\r\n";
$data = '';
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="apikey"' . $eol . $eol;
$data .= $apikey . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="index"' . $eol . $eol;
$data .= $index1 . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="json"; filename="allposts.json"' . $eol;
$data .= 'Content-Type: application/json' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= base64_encode($json1) . $eol;
// alternatively use 8bit encoding
//$data .= 'Content-Transfer-Encoding: 8bit' . $eol . $eol;
//$data .= $json1 . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol;
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary=' . $mime_boundary,
'content' => $data
//'proxy' => 'tcp://localhost:8888' //use with Charles to catch http traffic
$ctx = stream_context_create($params);
$response = file_get_contents($url, FILE_TEXT, $ctx);
return $response;

Continue reading

Upgrade from Lion to Mountain Lion

Apache overwrites the Lion configurations and I needed to reconfigure Apache to run my localhost websites. Among other the AllowOverride All permissions in /etc/apache2/httpd.conf and /etc/apache2/extra/httpd-vhosts.conf caused my WordPress Permalinks to throw 404 Not Found errors.
If Apache is not running, start the server manually with

sudo apachectl start

Disk Permissions were broken, causing me to be unable to access among other the Applications folder from Finder. I could access the folder from the command line and was able to run the Disk Utility and repair Disk Permissions.

open -a /Applications/Utilities/Disk\

Reinstall X11 from

Reinstall Command Line Tools from Xcode > Preferences > Downloads > Components to reinstall gcc.

WordPress: Hello World Widget

Hello World Widget Area

To add widgets to your theme, you must have or create a ‘widget area’ as a widget placeholder and a widget to add to your widget area.

In the functions.php file of your theme, you can create a custom widget area by using the following code.

if (function_exists('register_sidebar')) {
'name'=> 'Hello World Widget Area',
'id' => 'hello_world',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div id="div_hello_world_title">',
'after_title' => '</div>',

Hello World Widget

This simple method does not use the extension of the WP_Widget class, which is the preferred method.
In the functions.php file of your theme, add the following code for the HelloWorld Widget.

function widget_helloworld() {
echo "Hello World!";
if (function_exists('register_sidebar_widget')) {
register_sidebar_widget(__('Hello World Widget'), 'widget_helloworld');

To add your widget to the dynamic sidebar:
– Go to your WordPress Dashboard > Appearance > Widgets, and
– Drag’n’drop the Hello World Widget to the dynamic sidebar on the right.

Hello World Template

Finally, you need a template to include your widget area. Create a helloworld.php file and include the following code.

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Hello World Widget Area')) : ?>
<!-- if widgets are not available -->
<?php endif; ?>