-
Author
Tagged: Private message, subject required
-
October 28, 2014 at 02:37 #33270clyde83Participant
Hi there i seem to get an error when sending private messages between members unless the subject text box is filled. Is there a way to send messages without filling in the subject filled and not get an error?
Many ThanksOctober 28, 2014 at 04:03 #33273sharmstrModeratorThat’s really a Buddypress question. Search over on their forum. Its been asked several times before. I believe most of the responses from the Buddypress team is “its required, deal with it” or you have to hide the subject field and fill it in for them during processing.
https://buddypress.org/support/
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
October 28, 2014 at 04:20 #33274sharmstrModeratorI’ve been meaning to tackle this for awhile now so let me know if you find a solution or not. If not, I’ll see about coming up with something. Personally it drives me bonkers to have to fill it out.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
October 28, 2014 at 14:18 #33291sharmstrModeratorI couldn’t find anything so I wrote a function myself. Put this in your functions.php file.
THIS REMOVES THE DEFAULT MESSAGE COMPOSE SCREEN AND ADDS A CUSTOM ONE. YOU NEED TO REMEMBER TO COMPARE THIS CODE TO ANY NEW BUDDYPRESS CODE WHEN AN UPDATE IS RELEASED
COPY CODE/** * Remove default Messages > Compose screen and add our custom one. */ function change_messages_compose() { global $bp; bp_core_remove_subnav_item( 'messages', 'compose' ); $messages_link = bp_loggedin_user_domain() . $bp->messages->slug . '/'; bp_core_new_subnav_item( array( 'name' => __( 'Compose', 'buddypress' ), 'slug' => 'compose', 'parent_url' => $messages_link, 'parent_slug' => $bp->messages->slug, 'screen_function' => 'custom_messages_screen_compose', 'position' => 30, 'user_has_access' => bp_core_can_edit_settings() )); } add_action( 'bp_setup_nav', 'change_messages_compose', 100 ); /** * Load the custom Messages > Compose screen. */ function custom_messages_screen_compose() { if ( bp_action_variables() ) { bp_do_404(); return; } // Remove any saved message data from a previous session. messages_remove_callback_values(); // Check if the message form has been submitted if ( isset( $_POST['send'] ) ) { // Check the nonce check_admin_referer( 'messages_send_message' ); // If subject is empty, set it to something. if ( empty( $_POST['subject'] ) ) { $_POST['subject'] = " "; } // Check we have what we need if (empty( $_POST['content'] ) ) { bp_core_add_message( __( 'There was an error sending that message, please try again fool.', 'buddypress' ), 'error' ); } else { // If this is a notice, send it if ( isset( $_POST['send-notice'] ) ) { if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) { bp_core_add_message( __( 'Notice sent successfully!', 'buddypress' ) ); bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/' ); } else { bp_core_add_message( __( 'There was an error sending that notice, please try again', 'buddypress' ), 'error' ); } } else { // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ) $autocomplete_recipients = explode( ',', $_POST['send-to-input'] ); $typed_recipients = explode( ' ', $_POST['send_to_usernames'] ); $recipients = array_merge( (array) $autocomplete_recipients, (array) $typed_recipients ); $recipients = apply_filters( 'bp_messages_recipients', $recipients ); $thread_id = messages_new_message( array( 'recipients' => $recipients, 'subject' => $_POST['subject'], 'content' => $_POST['content'] ) ); // Send the message if ( ! empty( $thread_id ) ) { bp_core_add_message( __( 'Message sent successfully!', 'buddypress' ) ); bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/' ); } else { bp_core_add_message( __( 'There was an error sending that message, please try again', 'buddypress' ), 'error' ); } } } } bp_core_load_template( apply_filters( 'messages_template_compose', 'members/single/home' ) ); }
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
October 28, 2014 at 14:54 #33300sharmstrModeratorA few changes.
1 – You should remove the word ‘fool’ on line 48. That’s left over from my testing 🙂
2 – You should add a default subject. It can be anything. If you leave it as a space, there’s nothing to link the open message to and your users wont be able to read the message. I’m using “No subject”.
COPY CODE// If subject is empty, set it to something. if ( empty( $_POST['subject'] ) ) { $_POST['subject'] = "No subject"; }
Alternatively, you could modify the displayed subject in the messages loop to add some text for the view message link to attach to. copy kleo/buddypress/members/single/messages-loop.php to your child theme and replace
COPY CODE<p><a>" title="<?php _e( "View Message", "buddypress" ); ?>"><?php _e( "View Message", "buddypress" ); ?><?php bp_message_thread_subject(); ?></a></p>
with
COPY CODE<p><a>" title="<?php _e( "View Message", "buddypress" ); ?>"><?php _e( "View Message", "buddypress" ); ?>: <?php bp_message_thread_subject(); ?></a></p>
You can change the second ‘View Message’ with anything you like.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
October 28, 2014 at 14:57 #33301sharmstrModeratorThat code didn’t print out correctly, so see attached for what you should change in messages-loop.php
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
Attachments:
You must be logged in to view attached files. -
AuthorPosts
The forum ‘KLEO’ is closed to new topics and replies.