Skip to main content
added 9 characters in body
Source Link
Bjorn
  • 535
  • 4
  • 10

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

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.

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

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

Source Link
Bjorn
  • 535
  • 4
  • 10

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.

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