WPML for WordPress is a powerful plugin to build a multi-language setup. But it still comes short in some areas, especially when it comes to a custom integration into plugins or when using custom post-types.
Normally this function should return the id of the linked translated content, but has not worked for me in some cases (especially when AJAX is involved).
1 |
icl_object_id( $id, 'custom_post_type', false, $translation_lang ); |
A simple SELECT helps to get that id yourself :)
1 2 3 4 5 6 7 8 |
// original_id - main post id // $translation_lang - translated language code ... de, nl ... global $wpdb; $translation = $wpdb->get_results("SELECT * from wp_icl_translations where trid = (SELECT trid from wp_icl_translations where element_id = '".$original_id."' and element_type='post_page') and language_code='".$translation_lang."'"); $post = get_post($translation[0]->element_id, ARRAY_A); |
The GitHub repository from Saša Stamenković provides a nice list of all countries with names and ISO 3166-1 codes.
Available formats are:
Sometimes when personalizing or translating interfaces, IP geolocation is required.
Besides their subscription based products Maxmind also provides a free IP Geolocation database set. The set is offered under the Creative Commons Attribution-ShareAlike 3.0 Unported License. The free databases maps IPv4 + IPv6 addresses and is being updated once a month. GeoLite Free Downloadable Databases
Another free set of data is provided by IP2location Lite. It is free for personal or commercial use with attribution required
The JSON spec allows integers, fractional numbers, strings, arrays, but when it comes to dates things are handled differently. There really is no date format in the JSON spec. Would be nice if every JSON date output would conform to ISO8601 :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Ruby 2011-07-14 19:43:37 +0100 //ISO 8601 2011-07-14T19:43:37+0100 // Javascript Date Object new Date(1310669017000) // Javascript built-in JSON object 2012-04-23T18:25:43.511Z // .NET JavaScriptSerializer Date(1310669017000) // .NET DataContractJsonSerializer Date(1335205592410-0500) |
Some of these can easily be converted to a PHP timestamp using strtotime(), others require some more magic.
Here is a way to transform the .NET variant, something that has been haunting me in a current project ;)
1 2 3 4 |
preg_match('~(\d+)\d{3}((?:\+|-)\d+)~', $date, $match); $dt = new DateTime('@' . $match[1]); $dt = new DateTime($dt->format('Y-m-d H:i:s') . ' ' . $match[2]); $date = strtotime($dt->format('r')); |
Due to the wide usage of JSON as an exchange format, I really hope we will see a spec update in the future :)
Bootstrap can not be added directly to the admin of a plugin, but you can wrap your plugin in a container and compile the Bootstrap CSS to use it as a wrapper.
I do my compiling using SimpLess
In the past you could do this using SimpLess directly (my-own-bootstrap.less).
1 2 3 |
.bootstrap-wrapper { @import (less) url( 'bootstrap.css' ); } |
This fails with the latest version of Bootstrap. But you can just paste the Bootstrap CSS into the LESS file and compile it that way.
1 2 3 |
.bootstrap-wrapper { // Paste Bootstrap CSS here } |
Run it through SimpLess and after that the new CSS can be enqueued in WordPress ! This also works nicely with themes from Bootswatch.
1 |
wp_enqueue_style( $this->plugin_slug .'-my-bootstrapstyle', plugins_url( 'css/my-bootstrapstyle.css', __FILE__ ), array(), $this->version ); |
Enjoy!