„WP-CLI is a set of command-line tools for managing WordPress installations“
1 2 3 4 5 6 7 8 9 10 |
Available commands: wp blog create|delete wp cache add|decr|delete|flush|get|incr|replace|set|type wp comment create|delete|trash|untrash|spam|unspam|approve|unapprove|count|status|last wp core download|config|is-installed|install|install-network|version|update|update-db wp db create|drop|reset|optimize|repair|connect|cli|query|export|import wp eval-file ... See 'wp help <command>' for more information on a specific command. |
Using WordPress as a headless system, is nothing new. You can easily build out your own REST API or use the long available HTTP REST API 1.0+ for WordPress.
But with the new HTTP REST API 2.0+ its getting really easy to build out your own REST API Namespace and assign routes for all your JSON needs.
The new REST API will make its appearance in WordPress 4.4, but you can start now by adding the plugin to your system. When the plugin detects 4.4+ it will only load functionality not already present in the core.
A route tells the API to respond to a given request with a specific function (endpoint). This adds the permalink structure to WordPress so that your functionality can be accessed via an url like this: http://yourdoman.com/wp-json/yourplugin/v1/myfunction/your_parameter
1 2 3 4 5 6 |
add_action( 'rest_api_init', function () { register_rest_route( 'your_namespace/v1', '/your_endpoint/(?P<your_parameter>\d+)', array( 'methods' => 'GET', 'callback' => 'your_endpoint', ) ); } ); |
The Endpoint is the callback handled by the route. Each endpoint can have additional parameters attached:
The return values from the endpoint are converted into JSON. You can use the WP_REST_Response object , this wraps normal body data and allows you to return a custom status code.
1 2 3 4 5 6 7 8 9 10 11 |
function your_endpoint( $data ) { $posts = get_posts( array( 'author' => $data['your_parameter'], ) ); if ( empty( $posts ) ) { return new WP_Error( 'your_endpoint_no_data', 'No Data', array( 'status' => 404 ) ); } return new WP_REST_Response( $posts, 200 ); } |
Really powerful stuff, that makes it easy to detach WordPress and the actual client using the data provided by it.
You can read more about it here.
Some options to get those translatable strings out of your templates. I will be adding new things, as I discover them :)
Flarum is new elegant next-generation forum software. It provides a touch optimized two pane layout with floating composer.
The backend runs on PHP/MySQL.
Timber / Twig templates are normally not recognized by Poedit. Its just a matter of tweaking the C/C++ extractor within the settings panel.
Add TWIG to the filetypes: *.c;*.cpp;*.h;*.hpp;*.cc;*.C;*.cxx;*.hxx;*.twig
Gettext calls, like {{__(„Points Conversion Rate“, „wplms-extras“)}} in Timber, are being extracted from your templates after that.
Easier than using the gettext extractor :)
1 2 3 4 5 |
$function = new Twig_SimpleFunction('__', function ($args) { return __($args); }); $twig->addFunction($function); |
Excel needs to know that you are using non-ASCII characters in your CSV or it will not display them correctly :)
Add the BOM(Byte Order Mark) to the first line, notifying Excel that you are offering a UTF-8 encoded file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//headers header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Description: File Transfer'); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=your.csv;'); header('Content-Transfer-Encoding: binary'); //open file pointer to standard output $fp = fopen('php://output', 'w'); //add BOM to fix UTF-8 in Excel fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) )); |
I am currently working on a WPLMS enhancement for a customer, that allows to simplify the payout of instructor commissions. The whole system runs on the MyCred Points System and students pay for courses with Points. The problem is how to easily payout the instructor commissions via PayPal.
There is currently no addon for MyCred available that does that magic, so I build one myself.
At the moment the payment process via PayPal is completely manual, due to budget constraints. I am basically generating a custom „Send Money“ link that prefills the PayPal email and amount to send.
The interface itself handles the payout sessions, tracks the instructor balance, paid and unpaid points.
Here some images to illustrate the admin dashboard:
This list the instructors and their point balance and allows to start the payment process.
Payout sessions make sure, that only one session can be started per instructor, as the instructor could earn new points during the process. The points converted can be changed, allowing you to payout a fixed amount of points.
Its a 3 step process. Login at PayPal. Open the „Send money“ dialog and send money to instructor. Confirm that you manually send the money and than register the payment and payout points in the system.
The session can be cancelled at any point. You can also leave the session open and continue at a later point.
On the frontend I added an interface to the BuddyPress Profile, that allows the instructor to track his payouts and balance.
The whole setup could be updated using PayPal Adaptive Payments, to make the whole process completely automated. Something to consider for the future :) Pretty happy with the manual process so far and it will be a great help for my customer to keep track of the commission payouts.
The whole setup is currently targeted for WPLMS, but can easily be adapted to other setups using the MyCred Points System.
1 2 3 4 5 6 |
add_action('init', 'pluginStartSession', 1); function pluginStartSession() { if(!session_id()) { session_start(); } } |
1 2 3 4 5 6 |
add_action('wp_logout', 'pluginEndSession'); add_action('wp_login', 'pluginEndSession'); function pluginEndSession() { session_destroy (); } |
Now go ahead and use $_SESSION freely in your plugin. Here a nice additional class to encrypt session data.
HyperDB is a plugin for spreading your websites load across several servers and databases. Its currently used in production on WordPress.com.
Just started experimenting with it :)