Skip to:
Content
Pages
Categories
Search
Top
Bottom

redirect to compose message with prefilled send to field

  • @flamuren

    Participant

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • @emaralive

    Moderator

    @flamuren,

    Support is provided by volunteers and is subject to when someone has time and/or expertise for any given topic request. Additionally, this is not a Job Board, if you require this type of help then you may want to use the following link to make a request of such type:

    WordPress Jobs

    @flamuren

    Participant

    @emaralive thanks and I am aware.

    I thought perhaps someone kind would look at it and see what in the redirect goes wrong and perhaps its something easy for a coder.

    All the other text is for context to make it easier to understand what I am trying to do.

    I mean I can listen to the AI-models and just split the code and put a filter in the function file. But something in me says there must be some way to redirect to your own messages after login with prefilled “send to” value. It feels like something that buddypress would be able to handle nativly?

    @emaralive

    Moderator

    @flamuren,

    Just so you know, I edited your original post to remove your statement regarding the solicitation for hired help.

    @flamuren

    Participant

    Thank you 🙏 (that was a desperate note – sorry)

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar