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
- What’s the preferred method of writing AJAX-enabled plugins?
- WP_User_Query and non-unique usermeta data
- AJAX Call Via Vanilla JavaScript In WordPress Plugin Development
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Ajax Load More and Masonry: is it possible to load admin-ajax.php in the front end?
- $current_user var returns NULL
- How to save Clicks of a download link button while it doesn’t matter if we refresh the page or again login/logout
- ‘Lazy loading’ list of posts with pagination
- Multisite functions to communicate with individual site functions
- Find out if request is for custom post type archive before query runs
- How to include admin-ajax when loading external javascript
- How to create popup same as wordpress popup feature
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- ajax front-end increment views on click
- medoo framework in WP plugin
- Check if email address exists front end with AJAX in a plugin
- Average Account Age
- How can i list random post from multiple category?
- WooCommerce get_price returning wrong price when used via ajax
- How to keep users unique id stored in session in addition to IP in WordPress plugin?
- New User Form – Custom Menu Page
- How to Create a Custom Panel and Fields in Post Page [Plugin]
- wordpress, search form using ajax
- Search for categories
- Best place for if/else piece of code related to custom plugin?
- WordPress Integration with Google Groups
- Best place to load wp_ajax_the_ajax_hook action in plugin
- jQuery.post not working within shortcode – WordPress Ajax
- How can I inject options into an select tag inside the widget form?
- Init plugin again after ajax call finish
- How to create a custom shortcode based on the layout?
- Using color picker in plugin, does input attribute order matter?
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- AJAX call – failling to call do_action
- ACF: post query, hide duplicate values [closed]
- What are the Best Practises When Using AJAX in Plugin Development?
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- How to insert multiple postmeta values with one query?
- Multisite – maximum number of users with specific role
- Does having more than 30 Admin Ajax affects site performance (plugin)?
- How to display checked posts on another page over AJAX? (like comparasion style)
- Replacing global wp_query
- Ajax save data to database on document ready, no data being saved
- Using WordPress to build membership Page
- 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?
- WordPress API functions not working at AJAX functions.php call
- wp_ajax action responds with 0
- Why AJAX response 0!
- Remove specific administrator’s capability
- Creating teams of users in WordPress
- 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
- AJAX call inside plugin class is not getting to it’s response function
- How do I reinit WordPress plugins dynamically using jS?
- How to implement data residency in my WordPress site
- adding dynamic/multiple slug values in ‘option_none_value’
- how to create user profile pages and display them based on users roles
- User updating their profile wipes my custom fields
- 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
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Ajax call to php function doesn’t work PHP code
- Get shortcode attribute for AJAX call
- Compare Ajax Data Results
- Why can’t I call a function from inside my registered AJAX function?
- User / membership Plugin [closed]
- How to see in Edit Comments if comment is from User and her Roles
- WordPress environment not loading properly
- WordPress Feedback popup with date saved into table
- Defined user role to access plugin’s pages
- Javascript not working
- WordPress ajax not working in registration
- 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?
- How can i see/log all requests coming from a registration form (not from the UI)?
- w3 total cache and post__not_in
- ajax request not returning the result
- How do I convince this button to do something when it is clicked?
- WP_Query Date Filtering Inclusive Being Ignored
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- My AJAX API plugin isn’t working
- ajax sends data to plugin
- Making a Custom Post Type Publish Loop
- Help me with my first very basic plugin
- Want to add post to user dashboard
- Jquery post responses 500 error after some time and lastly an 503 error
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- Ajax Called in Plugin php file
- Ajax Load More stopped working (Plugin with repeater template, shows hidden Button)