Latest Posts

Some advice for junior developers new on the job by Henrik on November 15th, 2017First of all, the below applies to a quite high stakes setting in a financially related company, a place were we don't move fast and break things if we want to continue being in business.

Setting up Ansible for MySQL by Henrik on September 14th, 2016In this how to we're going to manage in total 16 different LXC nodes on two different host machines.

A Function Browser for Emacs by Henrik on April 9th, 2016In my emacs init file for 2015 post I state:
However it would be kind of nice to be able to run a command to open a new buffer with links to line numbers for all definitions in the current file, shouldn’t be too hard to implement either, we’ll see if I manage in 2015.

Hacking Wordpress The Ugly And Quick Way by Henrik on August 4th, 2015Recently I've started a little project to see how I can do with IDN affiliate sites where there is a lot less competition than in English.

Functional HTML Rendering with PHP by Henrik on August 4th, 2015When you're working with a programming language that doesn't have templating per default and you're not in the mood - or don't see the need - for templating your first course of actions is to write something to obviate having to print and concatenate everything.

Update: Check out the HTTP Client article for more on how the below setup is later used to make life easier.

The work on SEO tools continues. The requirements for the current expansion is as follows and has to do with posting content to multiple wordpress blogs:

1.) We need to be able to upload a bunch of zipped html documents that will be randomly assigned to various blogs based on language. Article creation also needs to be done manually for complete control when it comes to publishing more important content to special blogs.

2.) In order for #1 to work we need an interface where we can add blogs, articles and WordPress MU installations. Each article will belong to a blog and each blog will belong to an MU install.

3.) Each MU install needs to have a script that will receive the information we post from SEO tools.

Each of the above items is an article in itself but let’s start with #2 first, I will use the connection between article and blog in the following listings (the relation between MU installations and blogs works exactly the same way).

The main thing here is the collection_select call to get the drop down of blogs (wp_sites). The first argument refers to the table to insert into (wp_article in our case), the second is the name of the column that refers to the blog table (wp_sites). The third is what collection to use to create the select, in our case all blogs, finally we pass a hash of options. In our case the hash only contains a setting that will make a default first option to avoid accidentally selecting the first site in the drop down.

When we list articles we also want to display the name of the site each article belongs to, the wp_site_id won’t mean much to us:

The main piece of code here is WpSite.find(wp_article.wp_site_id).name which will fetch the name of the site the article in question is connected to. We use the Active Record find method to do that. If simply passed a number it will by convention assume we want the record with the id of that number where the id column is also called simply ‘id’.