WP theme with Backbone

Well if you use Backbone with _s (https://github.com/tlovett1/_s_backbone) you will not be in problem. They used backbone for some effects and enqueuing is present still. /** * Enqueue scripts and styles. */ function _s_backbone_scripts() { wp_enqueue_style( ‘_s_backbone-style’, get_stylesheet_uri() ); wp_enqueue_script( ‘_s_backbone-navigation’, get_template_directory_uri() . ‘/js/navigation.js’, array(), ‘20120206’, true ); wp_enqueue_script( ‘_s_backbone-skip-link-focus-fix’, get_template_directory_uri() . ‘/js/skip-link-focus-fix.js’, array(), ‘20130115’, … Read more

Is there a hook to process a backbone restful PUT request inside wordpress?

The dynamic wp_ajax_ hooks serve mostly organizational convenience on PHP side. You could choose not to use it, then you would probably have to: hook into admin_init check that DOING_AJAX is true check that request ($_REQUEST[‘action’] and rest of it) is your special kind of request Then either process your request and die() or let … Read more

Elegantly using JavaScript on widget admin forms

One way around this I’ve discovered since posting the above question is to instantiate inline via WP_Widget::form(), with wp_enqueue_script() loading the necessary JavaScript (exactly as mentioned above) — except, and here’s the key part, load the JavaScript in the header instead of the footer (fifth argument of wp_enqueue_script()). Which makes a lot of sense now … Read more

Adding fields to the media uploader with jquery listeners

From Blackbone.js website: render is the core function that your view should override, in order to populate its element (this.el), with the appropriate HTML. The convention is for render to always return this. So, I have modified the code a little bit to add jQuery change listener. function add_gallery_type_option(){ ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> … Read more

Is dynamic forms/entries possible in Widget?

Thank you Dave Romsey and Mark Kaplun for pointing out about not using HTML ID in WordPress Widget. I finally find a solution for my need. Solution: We need to add a preset variables into all of the 3 functions (widget, form, update). In my codes, they are called “spotlight_image_link1, spotlight_image_link2, etc”. Then in the … Read more

What type of template are WP media-modal’s templates?

Here’s an interesting part from http://underscorejs.org/#template If ERB-style delimiters aren’t your cup of tea, you can change Underscore’s template settings to use different symbols to set off interpolated code. Define an interpolate regex to match expressions that should be interpolated verbatim, an escape regex to match expressions that should be inserted after being HTML-escaped, and … Read more

Switch to the library tab in the media uploader

After struggling around for days through the poorly documented media modal source code and using code from the gist (thanks, Fabien), I came up with a solution: JS: wp.media.controller.Custom = wp.media.controller.State.extend({ initialize: function(){ this.props = new Backbone.Model({ custom_data: ” }); this.props.on( ‘change:custom_data’, this.refresh, this ); }, refresh: function() { this.frame.toolbar.get().refresh(); }, // called when the … Read more