Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_footer', 'insert_img_click_points' );
- function insert_img_click_points() {
- if ( ! is_user_logged_in() ) return;
- ?>
- <script type="text/javascript">
- jQuery(function($) {
- $( 'a#link img' ).click(function(){
- $.ajax({
- type : "POST",
- data : {
- action : 'points-for-image-click',
- token : <?php echo wp_create_nonce( 'points-for-image-click' ); ?>
- },
- url : ajaxurl
- });
- });
- });
- </script>
- <?php
- }
- /**
- * Ajax Call Handler
- * Whenever triggered, the user ID given for $admin_id receives
- * points.
- * Requires users to be logged in for points to be awarded.
- */
- add_action( 'wp_ajax_points-for-image-click', 'award_points_for_click' );
- function award_points_for_click() {
- // Security
- check_ajax_referer( 'points-for-image-click', 'token' );
- // Make sure myCRED is enabled
- if ( ! function_exists( 'mycred' ) ) die( 0 );
- // Point Type
- $point_type = 'mycred_default';
- // User to receive points
- $admin_id = 1;
- // Load myCRED
- $mycred = mycred( $point_type );
- // Award points
- $mycred->add_creds(
- 'image_click',
- $author_id
- 1,
- 'Image click',
- 0,
- '',
- $point_type
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement