rcp_edit_membership_after

Used to add additional content to the "Membership Details" page.

Parameters:

  • $membership (RCP_Membership) - Membership object.

Example:

Displays a text field showing the value of the "company" membership meta key.

function ag_rcp_edit_membership_after( $membership ) {
        $meta_value = rcp_get_membership_meta( $membership->get_id(), 'company', true ); // Your value here.
	?>
	<tr>
		<th scope="row" class="row-title">
			<label for="rcp-company"><?php _e( 'Company:', 'rcp' ); ?></label>
		</th>
		<td>
			<input type="text" name="rcp_company" id="rcp-company" value="<?php echo esc_attr( $meta_value ); ?>"/>
		</td>
	</tr>
	<?php
}
add_action( 'rcp_edit_membership_after', 'ag_rcp_edit_membership_after' );

Note: the above code just handles displaying the custom field. Saving requires another step. For example:

function ag_rcp_save_custom_membership_field() {
	// Permission check. -- do not edit
	if ( ! wp_verify_nonce( $_POST['rcp_edit_membership_nonce'], 'rcp_edit_membership' ) ) {
		wp_die( __( 'Nonce verification failed.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
	}

	if ( ! current_user_can( 'rcp_manage_members' ) ) {
		wp_die( __( 'You do not have permission to perform this action.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
	}

	// Check which membership is being saved. -- do not edit
	if ( empty( $_POST['membership_id'] ) ) {
		wp_die( __( 'Invalid membership ID.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 400 ) );
	}

	$membership_id = absint( $_POST['membership_id'] );
	$membership    = rcp_get_membership( $membership_id );

	if ( empty( $membership ) ) {
		wp_die( __( 'Invalid membership.', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 400 ) );
	}

	/*
	 * All checks are done! Now you can save your custom value.
	 * Edit this to customize your meta key and $_POST value key.
	 */
	if ( ! empty( $_POST['rcp_company'] ) ) {
		rcp_update_membership_meta( $membership->get_id(), 'company', sanitize_text_field( $_POST['rcp_company'] ) );
	} else {
		rcp_delete_membership_meta( $membership->get_id(), 'company' );
	}
}
add_action( 'rcp_action_edit_membership', 'ag_rcp_save_custom_membership_field', 9 );
Powered by Zendesk