I’m trying to implement twitter like followers function in my website. I have a function like this in my plugin:
function current_profile_user_id() {
return "current profile user id";
}
function button( $args = '' ) {
$defaults = array(
'leaderid' => current_profile_user_id(),
'followerid' => 'logged in user id'
);
return "HTML button";
}
The only way I can pass the current profile user id value, its from the user profile page by using function arguments.
Let’s say the $currentuser->ID returns the current profile page user value but this variable only available in the profile page.
Can anyone tell me how to pass that value to the function current_profile_user_id(), store that value and return the html button?
Please note: Many of my other functions too uses the value returned by current_profile_user_id().
You had better save the value in the session. A function may rely on the global scope, but that is not saved between pages.
You could do something like
and then, as soon as you can, save the profile in session
…ought to work. This way, you can change the persistence of
curr_profileif need be, without having to revisit all of your code.on a maybe-related note
(Not being very clear on what you’re attempting to do and how, I hope this may turn out to be useful)
So you have a list of users and want to display a ‘follow’ template for each. The list of users is retrieved from some sort of database, so you’ll have something like
In that template you will have something like:
or maybe an AJAX call to add that user to the logged user’s follow-list without refreshing the page. Anyway, there will be a server page invoked, and that page will receive a session cookie and the ID the user selected.
So that page will have to note the new following/unfollowing, and it will have everything it needs to do so:
$_REQUEST['id']$_SESSION.It could then execute, for example, a query such as
to persist the information.