redirect to compose message with prefilled send to field
-
Hi,
I am a total novice in coding. Please bare with me now. I have used copilot, gemini and chatgpt to help me build a custom page from zero.
The page shows registrered employers on my website. (Wpjm+buddypress)
If a user is not logged in the message button on the employer profile card on the custom page will read “please login to message this employer”.
If pressed you go to the login with a redirect to your own compose message page with prefilled to field with the username of the employer.
The issue here is I cant get it to work. Tried 1000s of different variants but the AI models wont give me a solution. They tell me it cant be made and that I have to split the redirect code with some code on the page and some code in the function file.
HOWEVER! This is where it gets weird. The first round of code help I got it managed to solve this without function file. But I cant find the solution again since I am stupid/novice enough to not save work as I make new changes…
I wonder if any kind soul would see if they can help me solve this. The page for reference is here: https://arbetssokande.nu/registrerade-arbetsgivare/
One of the code I have used that wont work:
<?php if ( bp_is_active( 'messages' ) && isset( $user ) ): ?> <?php $recipient_username = $user->user_nicename; $query_args = array( 'r' => $recipient_username, ); $query_string = http_build_query( $query_args ); if ( is_user_logged_in() ): $compose_url = bp_loggedin_user_domain() . bp_get_messages_slug() . '/nytt-meddelande/?' . $query_string; ?> <a href="<?php echo esc_url( $compose_url ); ?>" class="bp-message-button">Skicka meddelande</a> <?php else: $redirect_url = home_url( '/' . bp_get_messages_slug() . '/nytt-meddelande/?' . $query_string ); $login_url = wp_login_url( $redirect_url ); ?> <a href="<?php echo esc_url( $login_url ); ?>" class="bp-message-button">Logga in för att skicka meddelande</a> <?php endif; ?> <?php endif; ?>
The message button works if you are logged in. As also does the “see job ads” of the chosen employer (both logged in or logged out and redirected).
Am I stupid/remember wrong that the redirect for message worked one time some days ago? I feel so stupid its sad.
Please help if you can.
Best regards,flamuren
- You must be logged in to reply to this topic.