Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Index
- <div id="id"></div>
- // Script.JS
- /*
- * How to use that thing.
- */
- jQuery(document).ready(function(){
- jQuery.ajax({
- url: php_vars.adminajax,
- data:{action:"mycred_dejatuwow_point"},
- success:function(e){
- jQuery("#id").html(e);
- }
- });
- });
- //functions.php
- <?php
- function enqueueWP(){
- /*
- * Enqueuing a script that require jQuery working, not need to link jQuery CDN as before.
- */
- wp_enqueue_script(
- 'script',
- get_template_directory_uri() .'/js/script.js',
- array('jquery'), // This load hosted jQuery script
- null,
- true
- );
- /*
- * Create a Javascript Variable used by script.js
- */
- $datas = array(
- 'adminajax' => admin_url( 'admin-ajax.php' ), /* Create the array */
- );
- wp_localize_script(
- 'script', // HANDLE: Where the var must be used
- 'php_vars', // Name of the array
- $datas // Var Passed
- );
- }
- add_action('wp_enqueue_scripts','enqueueWP');
- /*
- * Passing this var to result in script.js
- */
- function mycred_dejatuwow_point() {
- echo "USER ID: ".get_current_user_id()."<br>";
- }
- add_action( 'wp_ajax_mycred_dejatuwow_point', 'mycred_dejatuwow_point'); // If called from admin panel
- add_action( 'wp_ajax_nopriv_mycred_dejatuwow_point', 'mycred_dejatuwow_point');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement