Hello Tosin,
Try using this code:
add_action( 'bp_member_header_actions', function () { $user_id = bp_displayed_user_id(); $donation_page_link = add_query_arg( array( 'user_id' => $user_id, 'nonce' => wp_create_nonce( 'donate-' . $user_id ), ), get_page_link( 68 ) // Replace by your donation page link. ); $r = array( 'id' => 'donation_link', 'component' => 'members', 'must_be_logged_in' => true, 'link_text' => _x( 'Donate', 'button', 'buddypress' ), 'link_href' => esc_url( $donation_page_link ), ); echo bp_get_button( $r ); } ); add_filter( 'the_content', function ( $content ) { // Our donation page link. if ( ! is_page( 68 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) { return $content; } $user = get_user_by( 'id', absint( $_GET['user_id'] ) ); if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) { return $content; } ob_start(); // Replace group_id to your group id. echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" ); $shortcode_content = ob_get_clean(); return $content . $shortcode_content; } );
Regards
RaviRavi you are God sent thanks the code worked perfectly.
The only thing missing now is if a user has not added his bank account and a potential donor clicks the donate button, the (send-donation) page returns an empty or blank page.
It would be better to echo the shortcode only when a valid profile data is available for output
otherwise this statement should be echo in the page.(This member has not updated his/her bank details)
EXAMPLE
1.echo do_shortcode( “[bp-shortcodes-profile user_id={$user->ID} group_id=2]” );
2. If no profile data is available then
3. echo the statement (This member has not updated his/her bank details)Thanks
Hello Tosin,
Thank you for the kind words. Please use the following code it will return the message if the mandatory field of account details is empty. Please do let me know if it helps or not.
add_action( 'bp_member_header_actions', function () { $user_id = bp_displayed_user_id(); $donation_page_link = add_query_arg( array( 'user_id' => $user_id, 'nonce' => wp_create_nonce( 'donate-' . $user_id ), ), get_page_link( 68 ) // Replace by your donation page link. ); $r = array( 'id' => 'donation_link', 'component' => 'members', 'must_be_logged_in' => true, 'link_text' => _x( 'Donate', 'button', 'buddypress' ), 'link_href' => esc_url( $donation_page_link ), ); echo bp_get_button( $r ); } ); add_filter( 'the_content', function ( $content ) { // Our donation page link. if ( ! is_page( 68 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) { return $content; } $user = get_user_by( 'id', absint( $_GET['user_id'] ) ); if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) { return $content; } // Replace field id with your one mandatory for donation. If empty return your message. if ( empty( xprofile_get_field_data( 8, $user->ID ) ) ) { return $content . __( 'This member has not updated his/her bank details' ); } ob_start(); // Replace group_id to your group id. echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" ); $shortcode_content = ob_get_clean(); return $content . $shortcode_content; } );
Regards
RaviI tried modifying the code but it wasn’t ok
see modified code something is wrongadd_action( 'bp_member_header_actions', function () { $user_id = bp_displayed_user_id(); $donation_page_link = add_query_arg( array( 'user_id' => $user_id, 'nonce' => wp_create_nonce( 'donate-' . $user_id ), ), get_page_link( 36918 ) // Replace by your donation page link. ); $r = array( 'id' => 'donation_link', 'component' => 'members', 'must_be_logged_in' => true, 'link_text' => _x( 'Send Money', 'button', 'buddypress' ), 'link_href' => esc_url( $donation_page_link ), ); echo bp_get_button( $r ); } ); add_filter( 'the_content', function ( $content ) { // Our donation page link. if ( ! is_page( 36918 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) { return $content; } $user = get_user_by( 'id', absint( $_GET['user_id'] ) ); if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) { return $content; } // Replace field id with your one mandatory for donation. If empty return your message. if ( empty( xprofile_get_field_data( 3217, $user->ID ) ) ) { return $content . __( 'Bank name has not been provided' ); } if ( empty( xprofile_get_field_data( 3218, $user->ID ) ) ) { return $content . __( 'Account number has not been provided' ); } if ( empty( xprofile_get_field_data( 3219, $user->ID ) ) ) { return $content . __( 'Account name has not been provided' ); } if ( empty( xprofile_get_field_data( 3220, $user->ID ) ) ) { return $content . __( 'Paystack URL has not been provided' ); } if ( empty( xprofile_get_field_data( 4447, $user->ID ) ) ) { return $content . __( 'Cryptocurrency name has not been provided' ); } if ( empty( xprofile_get_field_data( 4446, $user->ID ) ) ) { return $content . __( 'Cryptocurrency address has not been provided' ); } ob_start(); // Replace group_id to your group id. echo do_shortcode( "[bpsc-user-avatar user_id={$user->ID} group_id=2]" ); echo do_shortcode( "[bpsc-user-display-name user_id={$user->ID} group_id=2]" ); echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" ); $shortcode_content = ob_get_clean(); return $content . $shortcode_content; } );
NOTE: all the bank profile data are separate single input text fields
The issue is
1. IF a user has added bank name, account number and account name without adding remaining paystack and cryptocurrency data
2. After clicking donate button and (send-donate) page loads the available bank name, account number and account name is not displayed instead, only the text (Bank name has not been provided) is displayed for all 6 profile data fields.If only one profile data field is empty or not added while some are added, the added/available profile fields are not displayed. One missing profile data prevents other legitimate/available profile field data from being displayed.
On page load, Both available profile field data should be displayed while
Non available profile data should echo/output their corresponding statement e.g Account number has not been provided.Hello Tosin,
Try the following code:
add_filter( 'the_content', function ( $content ) { // Our donation page link. if ( ! is_page( 36918 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) { return $content; } $user = get_user_by( 'id', absint( $_GET['user_id'] ) ); if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) { return $content; } $missing_details = array(); // Replace field id with your one mandatory for donation. If empty return your message. if ( empty( xprofile_get_field_data( 3217, $user->ID ) ) ) { $missing_details[] = __( 'Bank name has not been provided' ); } if ( empty( xprofile_get_field_data( 3218, $user->ID ) ) ) { $missing_details[] = __( 'Account number has not been provided' ); } if ( empty( xprofile_get_field_data( 3219, $user->ID ) ) ) { $missing_details[] = __( 'Account name has not been provided' ); } if ( empty( xprofile_get_field_data( 3220, $user->ID ) ) ) { $missing_details[] = __( 'Paystack URL has not been provided' ); } if ( empty( xprofile_get_field_data( 4447, $user->ID ) ) ) { $missing_details[] = __( 'Cryptocurrency name has not been provided' ); } if ( empty( xprofile_get_field_data( 4446, $user->ID ) ) ) { $missing_details[] = __( 'Cryptocurrency address has not been provided' ); } if ( ! empty( $missing_details ) ) { return $content . __( 'Following details are missing' ) . join( ' & ', $missing_details ); } ob_start(); // Replace group_id to your group id. echo do_shortcode( "[bpsc-user-avatar user_id={$user->ID} group_id=2]" ); echo do_shortcode( "[bpsc-user-display-name user_id={$user->ID} group_id=2]" ); echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" ); $shortcode_content = ob_get_clean(); return $content . $shortcode_content; } );
Regards
Ravisome users provided only their bank name and account number data without providing paystack and cryptocurrency details but the available data/info is not being displayed
The code you provided is ok
NOW
If at least one of the xprofile payment fields data is available do not show any of the $missing_details text and output/display only the available profile data/info.Hello Tosin,
The following code will help to render shortcode if any of the field’s data is available:
add_filter( 'the_content', function ( $content ) { // Our donation page link. if ( ! is_page( 36918 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) { return $content; } $user = get_user_by( 'id', absint( $_GET['user_id'] ) ); if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) { return $content; } $bank_name = xprofile_get_field_data( 3217, $user->ID ); $account_number = xprofile_get_field_data( 3218, $user->ID ); $account_name = xprofile_get_field_data( 3219, $user->ID ); $paystack_url = xprofile_get_field_data( 3220, $user->ID ); $crypto_currency_name = xprofile_get_field_data( 4447, $user->ID ); $crypto_currency_address = xprofile_get_field_data( 4446, $user->ID ); $missing_details = array(); // Replace field id with your one mandatory for donation. If empty return your message. if ( empty( $bank_name ) ) { $missing_details[] = __( 'Bank name has not been provided' ); } if ( empty( $account_number ) ) { $missing_details[] = __( 'Account number has not been provided' ); } if ( empty( $account_name ) ) { $missing_details[] = __( 'Account name has not been provided' ); } if ( empty( $paystack_url ) ) { $missing_details[] = __( 'Paystack URL has not been provided' ); } if ( empty( $crypto_currency_name ) ) { $missing_details[] = __( 'Cryptocurrency name has not been provided' ); } if ( empty( $crypto_currency_address ) ) { $missing_details[] = __( 'Cryptocurrency address has not been provided' ); } $render_shortcode = false; if ( $bank_name || $account_number || $account_name || $paystack_url || $crypto_currency_name || $crypto_currency_address ) { $render_shortcode = true; } if ( ! $render_shortcode ) { return $content . __( 'Following details are missing' ) . join( ' & ', $missing_details ); } ob_start(); // Replace group_id to your group id. echo do_shortcode( "[bpsc-user-avatar user_id={$user->ID} group_id=2]" ); echo do_shortcode( "[bpsc-user-display-name user_id={$user->ID} group_id=2]" ); echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" ); $shortcode_content = ob_get_clean(); return $content . $shortcode_content; } );
Regards
Ravi
You must be logged in to reply to this topic.