Add to group with click
I’m looking for a simple solution here and hope you can help me. I’m not too keen on high-level coding, but I think there has got to be a way to automatically add a user to a group when they click a link or a button without the “join shortcode.”
Could you please provide me some code I can add to my functions.php or script to a page to enable me the ability to add a user to a group when they click a button or a link?
Thank you so much!
Plugin Author Kento
You can use either of these approaches which rely on the actual implementation of the shortcode in templates:
a) Use do_shortcode() to render the output in a template, for example, to render the button that allows to join the “Premium” group:
<?php echo do_shortcode( '[groups_join group="Premium"]'); ?>
To render the button that allows to leave that group:
<?php echo do_shortcode( '[groups_leave group="Premium"]'); ?>
b) Use Groups’ underlying API functions directly in a template:
Button to join the “Premium” group:
<?php echo Groups_Shortcodes::groups_join( array( 'group' => 'Premium' ) ); ?>
… button to leave it:
<?php echo Groups_Shortcodes::groups_leave( array( 'group' => 'Premium' ) ); ?>
In this way, you still have the benefit of the shortcode that provides the functionality, without being limited to use it directly on the page content.Plugin Author Kento
I’ve expanded on the idea with an example showing a combination of Groups’ blocks and shortcodes in this article https://www.itthinx.com/2023/02/06/1-click-memberships-with-groups-for-wordpress/
The approach outside the WordPress editor is at the bottom of the article, but for those who look for a solution without templates, I think it’s useful to have the reference.
- You must be logged in to reply to this topic.