Articles of backbone

How to check an ajax nonce in PHP

I’m modifying the media modal adding a new menu item to add external attachments to the media library. From the JS code I’m calling a PHP function that touches the database and accepts three parameters (url, post id and nonce). My question is, how can I check the nonce from the PHP code? Another question, […]

Show only images and videos in a wp.media window

I’m using the following JS code to open a wp.media window to allow users to select images and videos for a gallery. Everything is working as expected, but I’m unable to restrict the window to show images and videos only, it’s showing everything. Any ideas on what might be wrong? Thanks in advance JS: $( […]

Pros and cons of using Backbone for WordPress theming

I’ve been noticing how Backbone seems to be the latest trend for WordPress theme development. A few data points: Backbone.js and WordPress development resources Theme Foundry’s Collections theme. Automattic’s upcoming O2 theme seems to use Backbone.js also. Happy Table’s job posting looking for front-end developer requires Backbone experience. I have done my homework and knew […]

Refreshing collections in the admin media manager

I know this question is very similar to this previously asked question; however, I was wondering if there was a more up-to-date/official way to refresh content programmatically in the WordPress admin media manager. In my specific instance, I’m trying to integrate the Getty Images plugin with a select attachment modal (e.g., Featured Image). Currently, I’ve […]

WP theme with Backbone

What would be the best way to insure that a Backbone WP theme cooperates with standard shortcodes and other WP plugins that include script and style tags in header and footer. I know Backbone plays nicely with jQuery scripts, but I’m unsure in how well will it operate in a situation when there are jQuery […]

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

I play around with Backbone.js (Great !) and want to synchronize my model data with the wordpress ajax api (3.6.1) on the server-side. Adapted to this http://addyosmani.github.io/backbone-fundamentals/#restful-persistence, here is my backbone example: var new_posts; var post; (function($){ var Post = Backbone.Model.extend({ id: ”, title: ”, }); var Posts = Backbone.Collection.extend({ model: Post, url: APP.ajaxurl + […]

Elegantly using JavaScript on widget admin forms

I’m working on a project involving a lot of widgets, and I’m thinking it’d be really great to have a “More options” section built using jQuery UI Accordion that expands when clicked. So, I’ve enqueued ‘jquery-ui-accordion’ using the ‘admin_enqueue_scripts’ action: function add_my_deps() { wp_enqueue_script(‘jquery-ui-accordion’); } add_action( ‘admin_enqueue_scripts’, ‘add_my_deps’ ); …And my JavaScript looks something like […]

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

I was looking at the WordPress templates (html that’s written to the page instead of awkwardly adding strings in JS). There are a lot of templates like this in a post editor for example: <script type=”text/html” id=”tmpl-uploader-status-error”> <span class=”upload-error-filename”>{{{ data.filename }}}</span> <span class=”upload-error-message”>{{ data.message }}</span> </script> Now, I know these can be referenced with wp.media.template(‘uploader-status-error’)( […]

Adding fields to the media uploader with jquery listeners

So I have the code to successfully add a select field to my media uploader (gallery view) which is cool, but I also need to add some jquery listeners to that field. I’m using the ‘print_media_templates’ hook to add my markup and js, and I want to add a jQuery listener to the select field, […]

Open media frame and select an attachment

I’m using the following piece of code to open a media frame when clicking a link with a data-attachment_id attribute. This attribute holds the id of an attachment that I want to select when the frame opens: jQuery(document).ready(function($){ $( ‘#gallery_images_container’ ).on( ‘click’, ‘a.edit’, function( event ) { var $el = $( this ); var selected […]