Skip to content

Instantly share code, notes, and snippets.

@celticwebdesign
Created May 19, 2018 15:51
Show Gist options
  • Save celticwebdesign/7d6644ccca55870c16b03d2a2d7796b1 to your computer and use it in GitHub Desktop.
Save celticwebdesign/7d6644ccca55870c16b03d2a2d7796b1 to your computer and use it in GitHub Desktop.
// https://codex.wordpress.org/Plugin_API/Action_Reference/admin_footer
function my_admin_add_js() {
echo '
<script type="text/javascript">
var ajaxurl = "'.admin_url("admin-ajax.php").'";
var user_id = '.get_current_user_id().';
</script>
<!-- This script should be enqueued properly in the footer -->
<script>
(function ($) {
$("a.thickbox1, a.thickbox2").click(function(e) {
e.preventDefault();
console.log( ajaxurl );
$.ajax({
url : ajaxurl,
type : "post",
data : {
action : "post_love_add_love",
user_id : user_id
},
success : function( response ) {
alert(response)
},
error : function( error ) {
alert(error)
}
});
alert("open");
});
})(jQuery);
</script>
';
}
add_action('admin_footer', 'my_admin_add_js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment