latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Checking to see if a user is the post author

Home Forums Community Forum Checking to see if a user is the post author

This topic contains 1 reply, has 2 voices. Last updated by  Cristián Lávaque 4 years ago.

Topic Author Topic
Posted: Thursday Dec 20th, 2012 at 6:50 pm #35194

Hi all,

I’m working on a site for which I’ve given users with a particular level of access the ability to edit a post (a publicly available profile to view). I have a form built to allow users to edit the post, and I was wondering if it was possible to restrict access to that form so the link is only visible to the user if that user is the post’s author. Something like this:

[s2If current_user() == author]
  [form display code]
[/s2If]

Is that possible? I’d really appreciate the help. Thanks!

EDIT: I’ve resolved the problem. If anyone else is looking for a solution to an issue like this.

Here’s what I ended up doing:

I created a shortcode to test the current page user. I use that code between s2If blocks that test for the appropriate user level. The code I used in functions.php looks like this:

add_shortcode('profileUpdate', 'profileUpdate');

function profileUpdate() {
    $current_user = get_current_user_id(); //Get the current user's UserID and store it
    $user_name = get_user_by('id', $current_user)->display_name; //Grab and store the current user's display name.
	if($user_name == get_the_author()) { //Test the user name grabbed earlier against the current author's display name
       // Do some stuff here that displays the link to the front-end user edit form
	}
}

The code I use in the edit window:

[s2If current_user_is(s2member_level3) AND current_user_can(access_s2member_ccaps_profile)]
    [profileUpdate]
[/s2If]

That seems to do the trick.

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
Posted: Saturday Dec 22nd, 2012 at 8:48 am #35311

Cool, Richard. Glad you figured it out and thanks for sharing it. :)

Viewing 1 replies (of 1 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.