This is just a short post to explain…

This is just a short post to explain theme and plugin developers how to use my plugin (LocalStorage Plugin), which, btw, made it’s way into the official wp plugin repo – feedback and impressions always welcome. 🙂

Thanks to the awesomeness of amplify.js, it’s easy to have something akin to WP PHP hooks in JavaScript – beyond events and callbacks.

You see, the core of the amplify library offers two methods –  publish and subscribe, which are equivalent to do_action and add_action.For more info, check out amplify.js documentation

The cool thing about it is that you can send parameters, and they’re sent by reference, so it works both as actions and as filters.

In the hooks I’ve added so far, you can modify the post_data which will be saved, or submitted, before the actions take place

a.publish('aboutToSave', action, post_data);

The “plugin” example I’ve chosen to implement backs up the post format and modifies the value when showing the backup (on request).

amplify.subscribe("aboutToSave", function (action, post_data) {
	post_data.post_format = $('input.post-format:checked').val();
});
amplify.subscribe("showBackup", function (action, post_data) {
	$("input.post-format").filter("[value=" + post_data.post_format + "]").prop("checked", true);
});

And this is basically it! I’ll add some more examples later, but this is what it’s mostly about.