Run javascript upon successfully set featured image

You could use .ajaxComplete, as mentioned by @onetrickpony in https://wordpress.stackexchange.com/a/36597/57034, except do it globally on document, as mentioned in http://api.jquery.com/ajaxcomplete/, then filter based on action: add_action( ‘admin_print_footer_scripts’, function () { ?> <script type=”text/javascript”> jQuery(function ($) { $(document).ajaxComplete(function (event, xhr, settings) { var match; if (typeof settings.data === ‘string’ && /action=set-post-thumbnail/.test(settings.data) && xhr.responseJSON && typeof xhr.responseJSON.data … Read more

Multiple Media uploader output to input

As per comments try collecting the ids in an array and then setting the text field once: custom_uploader.on(‘select’, function() { var selection = custom_uploader.state().get(‘selection’); var ids = selection.map( function (attachment) { return attachment.id; }); $(“#media-input”).val(ids.join(‘,’)); });

Add JavaScript to single post

One option would be to create a shortcode exclusively for that script. Even thought it’s not an elegant solution, it works. In your functions file (functions.php) of your theme add: function custom_script_shortcode(){ $code=”<script>”; $code .= ‘var foo = “bar”;’ $code .= ‘</script>’; return $code; } add_shortcode(“custom_script_shortcode”, “custom_script”); And in your post editor then add the … Read more

Including Styles and JS files to work ON my plugin interface

Well after a bit of better searching i found the answer, function my_enqueue($hook) { if ( ‘settings_page_data-layer-management’ != $hook ) { return; } wp_enqueue_script( ‘my_custom_script’, plugins_url( ‘js/dlm-window.js’, __FILE__ )); } add_action( ‘admin_enqueue_scripts’, ‘my_enqueue’ ); to explain just incase anyone has this issue. what i had earlier was a ‘front-end’ hook which is just wp_enqueue_scripts for … Read more

CDATA removing new line in script tag in wordpress

This is being caused by core bug #33106 which was unfortunately introduced with the security fixes in 4.1.6 (and 4.2.3). New lines are erroneously being stripped from CDATA blocks in this situation. From the bug ticket: As of 4.2.3, depending on how a CDATA block is used, the stripping of new lines in this content … Read more

print script on wordpress header after user registered

There’s quite a few issues here: do_action(‘user_register’, $user_id ); No need to fire the action yourself (especially with an undefined variable $user_id) – the idea of actions & filters is that you “hook” your function to one, and then let WordPress trigger it when applicable. function MY_Callback(){ $data[‘user_id’] = $user_id; My_print_js($data); } Again $user_id is … Read more