How to use this code my wordpress theme
<p>I want to follow system add my WordPress site but not connect ajax. How  can I follow my site system . I am trying for a long time, but can not connect to Ajax.</p>

<pre><code>// User Follow Function Wordpress
function bg_follow() {
   $nonce = $_POST['nonce'];

if (!wp_verify_nonce($nonce, 'ajax-nonce'))
    die();

do_action('bg_before_follow', $_POST);

global $wpdb, $user_ID, $user_identity;
$author_id = $_POST['author_id'];

if ($_POST['bg_follow'] == 'follow') {
    //update usermeta following for current user
    $usermeta_following_count = get_user_meta($user_ID, '_Following Count', true);
    $usermeta_following_user_id = get_user_meta($user_ID, '_Following User ID');
    $following_user_id = $usermeta_following_user_id[0];

    if (!is_array($following_user_id))
        $following_user_id = array();

    if (!in_array($author_id, $following_user_id)) {
        array_unshift($following_user_id, $author_id);
        update_user_meta($user_ID, '_Following User ID', $following_user_id);
        update_user_meta($user_ID, '_Following Count', ++$usermeta_following_count);
    }

} else if ($_POST['bg_follow'] == 'unfollow') {     
    //update usermeta following for current user
    $usermeta_following_count = get_user_meta($user_ID, '_Following Count', true);
    $usermeta_following_user_id = get_user_meta($user_ID, '_Following User ID');
    $following_user_id = $usermeta_following_user_id[0];

        unset($following_user_id[array_search($author_id, $following_user_id)]);
        $following_user_id = array_values($following_user_id);

        update_user_meta($user_ID, '_Following User ID', $following_user_id);
        update_user_meta($user_ID, '_Following Count', --$usermeta_following_count);

        //update usermeta followers for author
        $usermeta_followers_count = get_user_meta($author_id, '_Followers Count', true);

        $usermeta_followers_id = get_user_meta($author_id, '_Followers User ID');
        $followers_id = $usermeta_followers_id[0];
        unset($followers_id[array_search($user_ID, $followers_id)]);
        $followers_id = array_values($followers_id);

        update_user_meta($author_id, '_Followers User ID', $followers_id);
        update_user_meta($author_id, '_Followers Count', --$usermeta_followers_count);

        echo 'unfollow_all';
}

do_action('bg_after_follow', $user_ID, $author_id);

exit;
     } add_action('wp_ajax_bg-follow', 'bg_follow');
</code></pre>

<p>Button Function Code</p>

<pre><code>&lt;?php if ($user_info-&gt;ID != $user_ID) { ?&gt;
                &lt;button class="btn btn-success btn-sm follow bg-follow" data-author_id="&lt;?php echo $user_info-&gt;ID ?&gt;" type="button"&gt;&lt;?php if (!$followed) { _e('Follow', 'bg'); } else { _e('Unfollow', 'bg'); } ?&gt;&lt;/button&gt;

        &lt;?php } ?&gt;
</code></pre>

<p>Js Code </p>

<pre><code>//follow for lightbox, posts, author
$(document).on('click', '.ipin-follow', function() {
    if (obj_ipin.u != '0') {
        var follow = $(this);
        var board_parent_id = follow.data('board_parent_id');
        var board_id = follow.data('board_id');
        var author_id = follow.data('author_id');
        var disable_others = follow.data('disable_others');
        follow.attr('disabled', 'disabled');

        if (!follow.hasClass('disabled')) {
            var data = {
                action: 'ipin-follow',
                nonce: obj_ipin.nonce,
                ipin_follow: 'follow',
                board_parent_id: board_parent_id,
                board_id: board_id,
                author_id: author_id,
                disable_others: disable_others
            };

            $.ajax({
                type: 'post',
                url: obj_ipin.ajaxurl,
                data: data,
                success: function() {
                    if (follow.data('board_parent_id') != 0) {
                        follow.addClass('disabled').text(obj_ipin.__UnfollowBoard).removeAttr('disabled');
                    } else {
                        follow.addClass('disabled').text(obj_ipin.__Unfollow).removeAttr('disabled');
                    }

                    //increase followers count in author.php
                    if ($('#ajax-follower-count') &amp;&amp; follow.parent().parent().parent().parent().attr('id') == 'userbar') {
                        $('#ajax-follower-count').html(parseInt($('#ajax-follower-count').html(), 10)+1);
                    }

                    //disable other follow button
                    if (board_parent_id == '0' &amp;&amp; (disable_others != 'no' || $('#userbar .nav li:first').hasClass('active'))) {
                        $('.ipin-follow').each(function() {
                            if ($(this).data('board_parent_id') != 0) {
                                $(this).addClass('disabled').text(obj_ipin.__UnfollowBoard);
                            }
                        });
                    }
                }
            });
        } else {                        
            var data = {
                action: 'ipin-follow',
                nonce: obj_ipin.nonce,
                ipin_follow: 'unfollow',
                board_parent_id: board_parent_id,
                board_id: board_id,
                author_id: author_id
            };

            $.ajax({
                type: 'post',
                url: obj_ipin.ajaxurl,
                data: data,
                success: function(data) {
                    if (follow.data('board_parent_id') != 0) {      
                        follow.removeClass('disabled').text(obj_ipin.__FollowBoard).removeAttr('disabled');
                    } else {
                        follow.removeClass('disabled').text(obj_ipin.__Follow).removeAttr('disabled');
                    }

                    //decrease followers count in author.php
                    if ($('#ajax-follower-count') &amp;&amp; follow.parent().parent().parent().parent().attr('id') == 'userbar') {
                        $('#ajax-follower-count').html(parseInt($('#ajax-follower-count').html(), 10)-1);
                    }

                    //enable other follow button
                    if (data == 'unfollow_all' &amp;&amp; (disable_others != 'no' || $('#userbar .nav li:first').hasClass('active'))) {
                        $('.ipin-follow').each(function() {
                            if ($(this).data('board_parent_id') != 0) {
                                $(this).removeClass('disabled').text(obj_ipin.__FollowBoard);
                            }
                        });
                    }
                }
            });
        }
        return false;
    } else {
        loginPopup();
        return false;
    }
});
</code></pre>

<p>I want use it author.php and single.php </p>