Here are some pointers:
Why are you using output buffering in tb_get_follow_unfollow_links()? I see no reason this is needed.
In tb_get_follow_unfollow_links() only echo 1 button. On page load use php to decide what classes and button text you have to set.
With jQuery change the button when you get a successfull ajax return. Change the button class, so you can trigger a different ajax call on click.
Use .on to get events from dynamic (loaded from ajax) elements: $( "#container" ).on( "click", ".element", function() {});.
Your second question is easy to detect with some debugging.
To check if the user already subscribed, you can do something like this:
$following = get_user_meta( $user_id, '_tb_following', true );
if( ! in_array( $id_to_check, $following )) { // user not subscribed, do it now }
Regards, Bjorn
Related Posts:
- delete_user_meta Delete one value out of array
- AJAX search posts and pages
- Using AJAX to generate front end / viewer end pages
- woocommerce search by sku and title ajax
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- Update User Meta Via Ajax
- How to load wp_editor via AJAX
- Is there a way (plugin?) to restrict a user to being able to edit just one page?
- WP_query parameters for date range
- Keep one user logged for a year?
- insert data in database table from plugin with WP3.1
- Loading shortcode with ajax
- How to add a sub menu with AJAX?
- Create Proper WordPress Ajax Request in JavaScript, NOT jQuery
- Execute a function using ajax
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- What’s the point of using WordPress’s built in admin-ajax.php?
- Admin-ajax.php is dying “0” without processing function
- Removing WordPress Plugin Menu Item for a specific user
- How to remove an Ajax action
- Can I run multiple queries with $wpdb->prepare?
- Get Plugin Information from Multiple Sites Externally
- How to expire all wordpress user passwords instantly?
- How can I reuse the WordPress search form for a custom plugin / widget?
- Ajax gives 400 error
- Reset WordPress website
- Why plugin ajax response is -1?
- WordPress Ajax Callback
- How to transfer all user data between wordpress installations?
- Getting user roles in plugin files
- plugin ajax to external php file always return null
- Auto delete WordPress users according to time
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to associate more than one user to a post?
- Shortcode button dosent work for all posts. Work for first post only
- WooCommerce shop page orderby [closed]
- When to use action hooks and plugins
- Simple ajax call not working in wordpress plugin
- Not getting author rank when using return
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- Form isn’t inserting data into database with ajax plugin
- What’s the best way to implement AJAX in WordPress?
- __callStatic method handler passed to add_action causes bug in PHP
- wp_set_auth_cookie causes 403 error in the wooCommerce checkout
- jquery not calling php function
- How can I copy all users to newly created site on a multisite network in WordPress?
- Ajax with plugins returns 0
- WordPress + JavaScipt + AJAX + MySQL: insert query for form
- Enable users to change change and add taxonomies of posts
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- AJAX call – failling to call do_action
- What are the Best Practises When Using AJAX in Plugin Development?
- How to insert multiple postmeta values with one query?
- Does having more than 30 Admin Ajax affects site performance (plugin)?
- How to display checked posts on another page over AJAX? (like comparasion style)
- where do I send my ajax calls
- Replacing global wp_query
- Ajax save data to database on document ready, no data being saved
- How to get specific string/value from an array? php [closed]
- How to request admin-ajax.php correctly when wordpress URL and site URL are different?
- Passing PHP Variables to AJAX Loaded Pages
- Call ajax on the frontend
- Personalized Author Area
- Ajax request sends url rather than data
- grab or load text on demand
- Can’t save changes or modify settings in Dashboard but Pages and Posts are fine
- admin-ajax.php 500 error when new users try to register
- Send Array from JS to php file then insert it in wp database through a plugin
- wc_get_template_part doesnt display the content [duplicate]
- Cannot pass value variable to WP AJAX functions
- how to create user profile pages and display them based on users roles
- Conditionally load public and admin code with AJAX working on both sides
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- Comment restrictions Wodpress
- How to pass multiple custom fields as shortcode’s parameters
- Is it possible to custom set query for a WordPress REST API response?
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Get shortcode attribute for AJAX call
- ajax voting for custom post type
- User / membership Plugin [closed]
- How to see in Edit Comments if comment is from User and her Roles
- WordPress environment not loading properly
- How can I save cookies to members
- Defined user role to access plugin’s pages
- Ajax specific template not loading in replacement of index.php
- Shortcode in a blog post, footer and related products stop working
- How to delete only user meta value (not key) from usermeta table in wordpress?
- Ajax return 0 in plugin – ajax only used in wp-admin
- w3 total cache and post__not_in
- WP_Query Date Filtering Inclusive Being Ignored
- Like/Dislike Bar not working when updating
- How to set different users for different pages?
- Help me with my first very basic plugin
- How to change response of admin-ajax request?
- Share or sync user table data with another user table
- Inline AJAX script passing variables to PHP
- Not applying update field (acf) in my plugin
- How to filter posts with a wp query by a custom dropdown type field with the magic fields plugin
- Ajax response from Media Selection does not update ALL information more than once