WordPress Users, Roles and Capabilities

Tags: ,

I find the capabilities one of the most difficult to grasp concepts in WordPress development. On one hand, you have the capabilities of a custom post type and on the other hand you have the capabilities of a user or user role. And then you have the 2 other capabilities options you can set when registering a custom […]

Show custom post types in category archives

Tags: ,

Custom post types are not displayed in the category and tag archives by default, even if you indicated in the register_post_type call that it should support these taxonomies. The way to include them in the category and tag archives is to use the pre_get_posts action: add_action('pre_get_posts', 'mycode_pre_get_posts'); function mycode_pre_get_posts($query) { if ((is_home() || is_category() || […]

Single selected taxonomy in WordPress

Tags: ,

The category taxonomy is by default a multiselect widget that uses checkboxes. There are some ways to only allow one selection, like implementing your own Walker_Category_Checklist. But the most simple solution is just replace the checkbox inputs with radio input boxes with some Javascript. In the example below, I have a taxonomy "level" that I want […]

Laravel dynamically detect environment

Tags: ,

Laravel 5.2 comes with a .env file and tells you to not check it in. The idea behind it, is that you will have another .env file on your development, testing and production server. But if you want to dynamically detect and set your environment, this does not work too well. To make dynamically detection and […]

Laravel change paths

Tags: ,

Change storage path To change the storage path in Laravel (tested with version 5.2 and 5.3) you have to extend the Application class and then override the storagePath() method. You can do this all in the bootstrap/app.php file: class MyApplication extends \Illuminate\Foundation\Application {   public function storagePath() {     return $this->basePath . '/../storage';   } […]

Sami - a PHP API documentation generator

Tags: ,

I recently was looking for a way to create clear and nice looking API documentation from a library I made (BSF GitHub and API docs). I looked into phpDocumentor 2, apigen, doxygen and Sami and decided to go for this last one. It has a real nice looking default theme and is themeable with twig. But […]

UTC date in javascript, php, mysql and sqlite

Tags: , , ,

It can be very challenging to work with dates and times across different timezones. In this post I explain some of the things I do to make this work. I focus on Javascript, PHP, MySQL and SQLite development. MySQL The most important action first - put the connection session in UTC mode: set time_zone = […]

Store mcrypt values from PHP in MySQL

Tags: ,

The mcrypt functions return a binary string, so you can store it in a VARBINARY or BLOB field or as VARCHAR or TEXT if you first base64 encode it. When using the CBC (Cipher Block Chaining) mode, the input is divided into blocks of X bytes. The last block is then padded with NULL bytes […]