Multi-site WordPress max. file upload gotcha

Posted in Uncategorized on July 30, 2014 by andkrup

If you’re setting up a wordpress installation as a multi-site installation, you will find that Multi-site WordPress begins to care about your user-uploads.

If you’ve set up your php.ini to not flash file size restrictions in the face of your users, you will have to change some settings from their default values.

Notice that the default threshold is set at a value that may restrict some high-res retina png files. Screen Shot 2014-07-30 at 10.17.57 AM

These settings are imposed on top of the post_max_sizeupload_max_filesize settings in your php.ini, so have this in mind when you’re working with multi-site installations.

Check this page for the settings available:

https://codex.wordpress.org/Network_Admin_Settings_Screen#Upload_Settings

Let your WordPress theme support gettext

Posted in Uncategorized on August 9, 2013 by andkrup

Has anyone tried translating your wordpress theme, using gettext?

I found I had to add a callback to the gettext filter in order to have wordpress recognize my *.mo files:


add_filter('gettext','patched_translate', 10, 3);

function patched_translate($translations, $text, $domain = 'default'){
  $translations = get_translations_for_domain( $domain );
  if($domain == 'default'){
    return $translations->translate($text);
  }
  $translation = $translations->translate( $domain.chr(4).$text );
  if($translation == $domain.chr(4).$text){
    return $text;
  }
  return $translation;
}

Upload and tag a video to facebook via php

Posted in Development, Instructional, Php with tags , , , , , on May 14, 2013 by andkrup

Currently the facebook API documentation doesn’t mention that you can upload a video file to your facebook wall and tag your friends in it. This may be a feature yet to be announced or just hidden.

https://developers.facebook.com/docs/reference/api/video/

The code for connecting to facebook is well-known, here

$facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));
$facebook->setAccessToken($accessToken);
$facebook->setFileUploadSupport(true);

Uploading a video to your feed is done like this:

$args = array();
$args['description'] = $videoDescription;
$args['title'] = $videoTitle;
$args['privacy'] = json_encode(array('value' => 'ALL_FRIENDS'));
$args['file'] = "@$videoPath";
$data = $facebook->api('/me/videos', 'post', $args);

Then after the api() function returns the video-id, you can tag the video object, using the undocumented field tags, like so:

$args = array();
$args['tag_uid'] = "$userId";
$data = $facebook->api("/{$videoId}/tags", 'post', $args);

That’s it

Autoloader for WordPress

Posted in Php with tags , , , on April 10, 2013 by andkrup

The process of creating an autoloader for WordPress is a bit problematic. The WordPress core doesn’t use autoloaders, so when you register one via spl_autoload_register(), the autoloader you define in your plugin or theme, will take control of how the WordPress core loads its internal classes.

Other 3rd-party plugins may also break if your autoloader function tries to load their classes in your namespace/source-path.

However, if you put all your classes into your own unique namespace (as is best practice in most other languages), you shouldn’t have any problems in avoiding invocations where your autoload function tries to load classes not from your distribution.

Here I put all my own classes in a namespace called ‘supervillain’, using a plugin structure as pictured here:

Screen Shot 2013-04-10 at 11.42.38

The SoundcloudPlayer-plugin.php file will be included by WordPress. In there I require_once the bootstrap.php, containing this code:

<?php
function load($className){
    if(false!==stripos($className, 'supervillainhq')){
        require str_replace("\\", '/', dirname(__FILE__) .'/'. __NAMESPACE__ . $className . '.php');
    }
}

spl_autoload_register(__NAMESPACE__."\\load");
?>

Further down in Soundcloudplayer-plugin.php I can create an instance of the SoundcloudPlayer class, defined in SoundcloudPlayer.php like this:

$scplayer = new supervillainhq\SoundcloudPlayer();

The SoundcloudPlayer class is defined like this:

<?php
namespace supervillainhq{
    class SoundcloudPlayer extends WordPressPlugin{
        public function test(){
            return "test";
        }
    }
}
?>

Of course, this still needs testing

Commandline urlencoding/urldecoding alias

Posted in Uncategorized with tags , , , , on April 4, 2013 by andkrup

Here’s a clever bash alias for quick string url- encoding/decoding:

http://ruslanspivak.com/2010/06/02/urlencode-and-urldecode-from-a-command-line/

PhpTasks

Posted in Ant, Development, Php with tags , , , , on February 26, 2013 by andkrup

I am currently writing a batch of ant tasks for Php-development in Eclipse, using PDT.

https://bitbucket.org/andkrup/phptasks

The low-level nature of php makes the workflow of php-development highly indiviual, and any non-framework based workflow which works for one developer, is probably not going to work for the next dveloper. Each developer has his or her own set of (bad) habits. On the other hand, most of us develop a set of routines and our experiences enable us to know which patterns work in what situations.

This collection of tasks help me in my daily work.

It should be noted that some tasks takes for granted some idioms and coding, conventions if you will, that has proven helpful during my php developing experiences. A lot of these tasks will probably work great in conjunction with the code library PhpBasics (https://bitbucket.org/andkrup/phpbasics/), and in the future both of these projects will probably merge into a set framework, god forbid

A3Tasks update

Posted in Actionscript, Ant, Java with tags , , , , on January 5, 2012 by andkrup

Finally had some time to work on the A3Tasks!

A3Tasks is a little set of Ant tasks for Flash development, made by me (hence the 3 A’s; Andkrups Ant tasks for Actionscript).

Have a look at the repository at bitbucket (http://bit.ly/y63Nz4) and tell me what you think.