Javascript WP Object Documentation?
http://codex.wordpress.org/Javascript_Reference/wp It’s a work in progress. Contribute if you can!
http://codex.wordpress.org/Javascript_Reference/wp It’s a work in progress. Contribute if you can!
Do not put the Customizer ready event handler inside of the jQuery event handler. The Customizer ready will trigger at jQuery ready, so you are adding the event handler too late. Just do: wp.customize.bind(‘ready’, function(){ console.log(‘ready’); }); Your JS needs to be enqueued with customize-controls script as its dependency. Enqueue at the customize_controls_enqueue_scripts action.
You should be forewarned that not all plugins/themes use enqueue. When I first started dealing with all the JavaScripts and CSS files outputed I just hooked into the enqueued files. This resulted in me only getting 2 out of 10 JavaScript files and 1 out of 3 CSS files. Here is some quick PoCs. Neither … Read more
Based on the code provided it looks like you are misunderstanding how wp_localize_script works. The signature of the function looks like this: wp_localize_script( $handle, $name, $data ); Where $handle is the name of a JavaScript file you have registered or enqueued before calling wp_localize_script. Take a look at the example in the codex (I’ve added … Read more
To extend on @gmazzap suggestion on not using globals when you can use wp_scripts(), there is a shortcut for wp_scripts() for adding conditional comments called wp_script_add_data and likewise wp_style_add_data for conditional styles. So the correct way to use conditionals as of WordPress 4.2 is like this: /** * IE enqueue HTML5shiv with conditionals * @link … Read more
There is a dequeue method available … I’m just not sure why it isn’t wrapped in a wp_dequeue_script() method. (I might create a ticket for this issue, actually) But yes, using wp_deregister_script will accomplish what you’re trying to do. Just remember, if you ever do want to use WP’s built-in jQuery later you’ll need to … Read more
wp_enqueue_style and wp_enqueue_script accepts many parameters and it’s very important to use them in correct order otherwise these functions will fail. Here are complete set of parameters for each function. wp_enqueue_style( $handle, $src, $deps, $ver, $media ); wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); In your wp_enqueue_style you define $handle, $src correctly but $deps to … Read more
I don’t think using React.js without Node.js (or at least V8 or rhino etc) counts as isomorphic, as isomorphic means that you are building JavaScript to run in the browser AND on the server. Specifically, using WordPress certainly means you aren’t doing isomorphic javascript (its PHP software). What you could do is use WordPress as … Read more
How to use wp.hooks.addAction? It’s basically like so, just like you’ve attempted: // Hook to the hook_name action. wp.hooks.addAction( ‘hook_name’, ‘namespace’, function(){ console.log( ‘Foo Bar’ ); } ); // Trigger the hook_name action. wp.hooks.doAction( ‘hook_name’ ); Or for hooks which provides one or more parameters to the callback: // Hook to the hook_name action. wp.hooks.addAction( … Read more
Add the following to your theme functions.php: function fb_change_mce_options($initArray) { $ext=”script[charset|defer|language|src|type]”; if ( isset( $initArray[‘extended_valid_elements’] ) ) { $initArray[‘extended_valid_elements’] .= ‘,’ . $ext; } else { $initArray[‘extended_valid_elements’] = $ext; } return $initArray; } add_filter(‘tiny_mce_before_init’, ‘fb_change_mce_options’);