Award GamiPress on RCPro Membership Renewal

Share This Post

Award GamiPress on RCPro Membership Renewal

Do you think users can also be awarded points/badges/ranks while RCPro Membership renewal? Yes, you can do it now just by using this snippet to award GamiPress on RCPro Membership renewal.

Note: GamiPress and RCPro plugins must be configured in order to use these snippets.

Let’s test all the snippet about how it is working…

Snippet 1: Add renewal trigger

This snippet will add custom trigger to GamiPress.

				
					/**
 * Add Renewal Trigger
 */
function ldninjas_add_new_trigger_membership_renew( $triggers ) {
    $triggers[ __( 'Restrict Content Pro Renewal Awards', 'ldninjas' ) ] = array(
            'rcp_membership_renewal_specific_event' => __( 'When user renew their subscription', 'ldninjas' ),
        );
        
        return $triggers;
}
add_filter( 'gamipress_activity_triggers', 'ldninjas_add_new_trigger_membership_renew' );
				
			

Snippet 2: List Membership levels to the trigger

This snippet will list membership levels to the triggers.

				
					/**
 * List Membership levels to the trigger
 */
function ldninjas_membership_renew_specific_activity_trigger( $specific_triggers ) {
      $specific_triggers['rcp_membership_renewal_specific_event'] = array( 'rcprp_membership' );
      return $specific_triggers;
}
add_filter( 'gamipress_specific_activity_triggers', 'ldninjas_membership_renew_specific_activity_trigger' );
				
			

Snippet 3: Add trigger title to the activity log

This snippet will add triggers title to the activity log.

				
					/**
 * Add trigger title to the activity log
 */
function ldninjas_membership_renew_specific_activity_trigger_label( $specific_trigger_labels ) {
      $specific_trigger_labels['rcp_membership_renewal_specific_event'] = __( 'Get %s renew', 'ldninjas' );
      return $specific_trigger_labels;
}
add_filter( 'gamipress_specific_activity_trigger_label', 'ldninjas_membership_renew_specific_activity_trigger_label' );
				
			

Snippet 4: Add specific trigger title to the activity log

This snippet will add specific triggers title to the activity log.

				
					/**
 * Add specific trigger title to the activity log
 */
function ldninjas_specific_activity_trigger_post_title( $post_title, $specific_id, $trigger_type ) {
    $levels = rcp_get_subscription_levels();
    if( ! $levels ) {
        return;
    }

    foreach( $levels as $level ) {
        $membership_title = $level->name;
        if( ! $membership_title ) {
            continue;
        }

        $post_title = $membership_title;
        return $post_title;
    }
}
add_filter( 'gamipress_specific_activity_trigger_post_title', 'ldninjas_specific_activity_trigger_post_title', 10, 3 );
				
			

Snippet 5: Create custom posts for membership levels

This snippet will create custom post for the membership levels

				
					/**
 * Create custom posts for membership levels
 */
function ldninjas_rcpro_add_post_type() {
    
    global $wpdb;

    if( isset( $_REQUEST['post_type'] ) && in_array( 'rcprp_membership', $_REQUEST['post_type'] ) ) {
        $results = array();
        $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : '';
        $rcp_levels_table_name = rcp_get_levels_db_name();
        $memberships = $wpdb->get_results( $wpdb->prepare(
            "SELECT m.id, m.name
            FROM {$rcp_levels_table_name} AS m
            WHERE m.name LIKE %s",
            "%%{$search}%%"
        ) );

        foreach ( $memberships as $membership ) {
            $results[] = array(
                'ID' => $membership->id,
                'post_title' => $membership->name,
            );
        }
        wp_send_json_success( $results );
        die;
    }
}
add_action( 'wp_ajax_gamipress_get_posts', 'ldninjas_rcpro_add_post_type', 5 );
				
			

Snippet 6: Award points/badges/ranks

This snippet will award points/badges/ranks to the users.

				
					/**
 * Award points/badges/ranks
 */
function ldninjas_rcprc_award_point_to_user( $expiration, $membership_id, $membership ) {
  
    $user_id = $membership->get_customer()->get_user_id();
    if( ! $user_id ) {
        return;
    }

    $object_id = (int)$membership->get_object_id();
    if( ! $object_id ) {
        return;
    }

    gamipress_trigger_event( array(
        'event' => 'rcp_membership_renewal_specific_event',
        'user_id'   => $user_id,
        'specific_id' => $object_id,

    ) );
}
add_action( 'rcp_membership_post_renew', 'ldninjas_rcprc_award_point_to_user', 10, 3 );
				
			

Conclusion

So, All you need to add this code snippet to your theme functions.php file to award GamiPress on RCPro Membership renewal. Enjoy!

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

How to get admin user ID

Share This Post How to get admin User ID? It’s been really difficult for many to get back the admin user ID but it’s so

Award GamiPress on RCPro Membership Renewal

Share This Post Award GamiPress on RCPro Membership Renewal Do you think users can also be awarded points/badges/ranks while RCPro Membership renewal? Yes, you can

Custom Message with myCRED Transfer

Share This Post Custom Message with myCRED Transfer MyCred assigns different points to the users but it’s been sometime noticed that the users want to

Want To Know About Our Services?

small_c_popup-300x296

Let’s Talk To Us With Your Concerns

    Once you send the details, we will be shortly back to you. Thanks!

    small_c_popup-300x296

    Become a valuable part of Team LDninjas

    small_c_popup-300x296

    Be updated with new release by LDninjas!