Have you ever tried to automate WordPress upgrade tasks or deployments? I did, it was a big pain.
Sometimes I would find myself updating WordPress options on 54 different blogs trough the admin interface. Completely tired of it I created a little tool to automate these kind of things trough the command line interface (like every self respecting developer would do). The wp-cli project was born.
Read the rest of this entry »
As a freelancer you try to do your job as best as possible, but is that enough to compete with the other freelancers around? I have been freelancing as well, so seeing the case from both sides is quite interesting.
In the last few years we had to hire freelancers for different types of work and amongst them there was a stunning difference in style. So how can you be the perfect freelancer? It is a combination of style, communication and great work.
Read the rest of this entry »
We just updated our htaccess tester to support the HTTP_REFERER variable in your rewrite rules. To do so we simply added a new field underneath the field for the htaccess. You can type any url in this field, which will be used in the script as the HTTP_REFERER variable. The field is optional, if you leave it empty the HTTP_REFERER variable will also be empty.
Read the rest of this entry »
Last wednesday we where struggling with some complex rewrite rules. To test them we had to setup a local server and keep hitting that refresh button after each change. The only thing we could see is if the url was rewritten to the right location or not, but there was no way to actually see what’s happening. So we went on a hunt for a htaccess tester, something like Rubular which we use for regular expressions.
To our surprise there was no simple app to test rewrite rules, so we decided to dedicate our wednesday afternoon to build one, here is the result: htaccess.madewithlove.be.
Read the rest of this entry »
We are currently working on a WordPress project where visitors need to be able to upload images for a competition. Their data is stored as a custom post type but we wondered how we’d store their image uploads? We can’t upload them trough regular php and add a meta to the post linking to the image, but what about WordPress’s different image sizes and media management?
The solution turns out to be really easy if we use the WordPress function media_handle_upload. It works with the normal $_FILES array, resizes your image, and gives back the attachment id.
Read the rest of this entry »
A while ago Jonas and I where discussing hosting control panels over lunch. Most of them are unappealing and unusable for average internet users. A few web hosting companies also write their own control panels, they have no choice. This happens because every hosting environment is so unique that sometimes using an existing control panel simply isn’t viable.
About 6 years ago I remember writing a script to dynamically generate email aliases from a mysql database, on a shared server. All the members of our boys scout group could fill out out their email address in their profile and they would automatically get an alias on our domain by doing so.
About a year later I wrote a control panel for my clients on my reseller package. By using the DirectAdmin API I allowed my clients to manage their email accounts and view their usage statistics. Those where my end-clients, small business owners that would get lost in DirectAdmin itself.
Since then a lot has changed on the field of server management itself but the market of hosting control panels hasn’t changed much. We think it’s time for a change. Instead of hacking all this stuff wouldn’t it be great to, for example, be able to install a plugin on WordPress to manage your mail accounts?
Read the rest of this entry »
In this post I’d like to talk about 2 very useful libraries we found here at the madewithlove HQ in the past week: WideImage and Simple Paypal Payments.
The first one is a very nice image manipulation library built that uses GD2. A few years ago I wrote my own library to do something similar, but recently I had to use transparency masking on profile pictures uploaded by users. This was something my library couldn’t do. Instead of refactoring my code, a small search turned up the WideImage library and now in a few lines of code I can combine any image with a mask. It provides exactly what I need and I waved goodbye to my old library.
The second library, Simple Paypal Payments, addresses one of the most cumbersome and expensive problems in web development: communicating with the PayPal API. I say expensive because the amount of time you lose with trying to get a useful result out of the bloated, almost incomprehensible, API is staggering and quite unique in these modern days of nice, RESTful API’s. The Simple Paypal Payments library offers some relief if all you’re interested in is the Express Checkout API, which I think is the one used by most small PayPal victims web shops. It offers a very basic interface to handle payments, allowing you to simply add products and call a method to start the process. The only thing I missed was an option to change the currency, but that was only a small hack away.
I hope I helped someone by pointing out these interesting libraries. If you know a better library, feel free to tell us in the comments.
// @todo Merge with wp_delete_user() ?
Like they suggest in their comment the wpmu_delete_user function is not ready yet. When deleting a user, WordPress does not allow you to reassign the user’s content to another user. My rewrite below is a merge with the wp_delete_user that lets you do so.
function wpmu_delete_user($id, $reassign) {
global $wpdb;
$id = (int) $id;
do_action( 'wpmu_delete_user', $id );
$blogs = get_blogs_of_user( $id );
if ( ! empty( $blogs ) ) {
foreach ( $blogs as $blog ) {
switch_to_blog( $blog->userblog_id );
remove_user_from_blog( $id, $blog->userblog_id );
if ( 'novalue' === $reassign || null === $reassign ) {
$post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) );
if ( $post_ids ) {
foreach ( $post_ids as $post_id )
wp_delete_post($post_id);
}
// Clean links
$link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) );
if ( $link_ids ) {
foreach ( $link_ids as $link_id )
wp_delete_link($link_id);
}
} else {
$reassign = (int) $reassign;
$wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) );
$wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) );
}
restore_current_blog();
}
}
// FINALLY, delete user
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) );
clean_user_cache( $id );
// allow for commit transaction
do_action( 'deleted_user', $id );
return true;
}
I think it would be even better to use the wp_delete_user function in this function instead of just copying the code, by doing that the hooks would be triggered for each blog which would allow each’s plugins to do their thing.
As a front-end developer for multiple designers sometimes I’m given designs and layouts for sites that follow a grid system, like 960.gs.
Sometimes I debate with myself whether they’re using a grid system because they are aware of the advantages a system like that brings, or because it’s a trend. But either way, since some of them don’t understand how a grid system works, I thought I’d write a tutorial on simple guidelines they can follow, to make their front-end developer’s life easier.
Read the rest of this entry »