Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tb_is_following( $user_id, $follow_id ) {
- $following = tb_get_following( $user_id, $follow_id );
- $ret = false; // is not following by default
- if ( is_array( $following ) && in_array( $follow_id, $following ) ) {
- $ret = true; // is following
- }
- return $ret;
- }
- function tb_process_new_follow() {
- if ( isset( $_POST['user_id'] ) && isset( $_POST['follow_id'] ) ) {
- if( tb_follow_user( absint( $_POST['user_id'] ), absint( $_POST['follow_id'] ) ) ) {
- echo 'success';
- } else {
- echo 'failed';
- }
- }
- die();
- }
- add_action('wp_ajax_follow', 'tb_process_new_follow');
- function tb_process_unfollow() {
- if ( isset( $_POST['user_id'] ) && isset( $_POST['follow_id'] ) ) {
- if( tb_unfollow_user( absint( $_POST['user_id'] ), absint( $_POST['follow_id'] ) ) ) {
- echo 'success';
- } else {
- echo 'failed';
- }
- }
- die();
- }
- add_action('wp_ajax_unfollow', 'tb_process_unfollow');
- jQuery(document).ready(function($) {
- /*******************************
- follow / unfollow a user
- *******************************/
- $( '.follow-links a' ).on('click', function(e) {
- e.preventDefault();
- var $this = $(this);
- var data = {
- action: $this.hasClass('follow') ? 'follow' : 'unfollow',
- user_id: $this.data('user-id'),
- follow_id: $this.data('follow-id'),
- nonce: tb_vars.nonce
- };
- $.post( tb_vars.ajaxurl, data, function(response) {
- console.log(data);
- if( response == 'success' ) {
- $('.follow-links a').toggle();
- } else {
- console.log( tb_vars.processing_error );
- }
- } );
- });
- });
Add Comment
Please, Sign In to add comment