Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update class-groups-shortcodes.php #16

Closed
wants to merge 2 commits into from

Conversation

eivind1984
Copy link

(Sorry for the duplicate! First time on GitHub, learning as I go..)

As discussed in the comments section (http://www.itthinx.com/plugins/groups-gravityforms/), here's my take on the shortcode file.

As far as I know, all original functinality is intact.

This edit does a couple of things:

Listing groups the user is a member of: Add an option to display a "leave group" button for each group. Use leavebutton="yes" in the shortcode to display it, e.g like this: [groups_user_groups leavebutton="1"]

Listing all groups available: Add an option to display a "join group" button for each group. Use joinbutton="yes" in the shortcode to display it, e.g. like this: [groups_groups joinbutton="1"]

Listing all groups available: Add an option to not display groups the logged in user is already a member of. Use exclude_excisting="yes" in the shortcode to enable it, e.g. like this: [[groups_groups exclude_excisting="1"]

These last two are ment to be used together, as it would make little sense in asking the user to join a group she's already a member of.

I'm no PHP expert, so there's probably improvements to be made on the actual code. Feel free to look into it.

All the best,
Eivind

(Sorry for the duplicate! First time on GitHub, learning as I go..)

As discussed in the comments section (http://www.itthinx.com/plugins/groups-gravityforms/), here's my take on the shortcode file.

As far as I know, all original functinality is intact.

This edit does a couple of things:

Listing groups the user is a member of: Add an option to display a "leave group" button for each group. Use leavebutton="yes" in the shortcode to display it, e.g like this: [groups_user_groups leavebutton="1"]

Listing all groups available: Add an option to display a "join group" button for each group. Use joinbutton="yes" in the shortcode to display it, e.g. like this: [groups_groups joinbutton="1"]

Listing all groups available: Add an option to not display groups the logged in user is already a member of. Use exclude_excisting="yes" in the shortcode to enable it, e.g. like this: [[groups_groups exclude_excisting="1"]

These last two are ment to be used together, as it would make little sense in asking the user to join a group she's already a member of.

I'm no PHP expert, so there's probably improvements to be made on the actual code. Feel free to look into it.

All the best,
Eivind
@eivind1984
Copy link
Author

Hey, I've noticed a tiny glitch in the setup as I wrote it. When you click to join or leave a group, the page reloads, but nothing seems to have happened. Just entering the page URL again (or reloading without resubmitting the form) reveals that it actually did process the request sucessfully, though.

It would be better to have the page print out the updated group situation. I have no imidiate idea on how to fix that, though, do you? @itthinx

@itthinx
Copy link
Owner

itthinx commented Jan 11, 2015

Thanks and I've just had a quick look. I think it would be a good idea to try to implement this using the code that already exists for joining/leaving a group instead of replicating join/leave code within the groups_user_groups method. It's a suggestion and I'm honestly not certain if it would work right now, but I'd give that a try. I'm referring to calling groups_join https://github.com/eivind1984/groups/blob/patch-2/lib/views/class-groups-shortcodes.php#L445 and groups_leave https://github.com/eivind1984/groups/blob/patch-2/lib/views/class-groups-shortcodes.php#L530 instead of reimplementing the related code.

@eivind1984
Copy link
Author

Yeah, that was my preferred method too, but I couldn't get it to work. So, I started this approach in stead, which kind of does the job, but not actually, as you need to include the join/leave shortcodes on the same page in order for the actual joins and leaves to work..

So, I don't think this is anything good enough to get pulled into the master branch after all, but for now it does the job for me, I think. (Still working on new version of the code, but it's the same structure, so the problems are the same.)

So, a new update here. Still the same issues with not reusing codes by calling on the join_group() and leave_group() functions. Somehow, I couldn't get them to work, so, quite a lot of work around.

I also had problems leaving and joining several groups, and figured it had something to do with wp_nonce(). So, I added more detailed nonce's, and the problems are gone now.

There's also an issue with the actual joining and leaving. In order for this code to work, the join and leave shortcodes need to be included on the same page as the other shortcodes. Because these shortcodes are processed after the listings, there's also some logic involved in updating the lists to show/hide the recent join/leave. (But, come to think about it now, I guess I might have saved me that bit of work by putting the leave/join shortcodes before the list shortcodes on the WP page..).

Ah, well. This is mostly rubbish, but in the unlikely chance of someone needing this functionality before you get a chance to do this properly in the master branch, I guess it won't hurt to post the code as is.
@itthinx itthinx closed this May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants