[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Messages: Compose action handler. 4 * 5 * @package BuddyPress 6 * @subpackage MessageActions 7 * @since 3.0.0 8 */ 9 10 /** 11 * Handle creating of private messages or sitewide notices 12 * 13 * @since 2.4.0 This function was split from messages_screen_compose(). See #6505. 14 * 15 * @return bool 16 */ 17 function bp_messages_action_create_message() { 18 19 // Bail if not posting to the compose message screen. 20 if ( ! bp_is_post_request() || ! bp_is_messages_component() || ! bp_is_current_action( 'compose' ) ) { 21 return false; 22 } 23 24 // Check the nonce. 25 check_admin_referer( 'messages_send_message' ); 26 27 // Define local variables. 28 $redirect_to = ''; 29 $feedback = ''; 30 $success = false; 31 32 // Missing subject or content. 33 if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) { 34 $success = false; 35 36 if ( empty( $_POST['subject'] ) ) { 37 $feedback = __( 'Your message was not sent. Please enter a subject line.', 'buddypress' ); 38 } else { 39 $feedback = __( 'Your message was not sent. Please enter some content.', 'buddypress' ); 40 } 41 42 // Subject and content present. 43 } else { 44 45 // Setup the link to the logged-in user's messages. 46 $member_messages = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 47 48 // Site-wide notice. 49 if ( isset( $_POST['send-notice'] ) ) { 50 51 // Attempt to save the notice and redirect to notices. 52 if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) { 53 $success = true; 54 $feedback = __( 'Notice successfully created.', 'buddypress' ); 55 $redirect_to = trailingslashit( $member_messages . 'notices' ); 56 57 // Notice could not be sent. 58 } else { 59 $success = false; 60 $feedback = __( 'Notice was not created. Please try again.', 'buddypress' ); 61 } 62 63 // Private conversation. 64 } else { 65 66 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ). 67 $autocomplete_recipients = (array) explode( ',', $_POST['send-to-input'] ); 68 $typed_recipients = (array) explode( ' ', $_POST['send_to_usernames'] ); 69 $recipients = array_merge( $autocomplete_recipients, $typed_recipients ); 70 71 /** 72 * Filters the array of recipients to receive the composed message. 73 * 74 * @since 1.2.10 75 * 76 * @param array $recipients Array of recipients to receive message. 77 */ 78 $recipients = apply_filters( 'bp_messages_recipients', $recipients ); 79 80 // Attempt to send the message. 81 $send = messages_new_message( array( 82 'recipients' => $recipients, 83 'subject' => $_POST['subject'], 84 'content' => $_POST['content'], 85 'error_type' => 'wp_error', 86 ) ); 87 88 // Send the message and redirect to it. 89 if ( true === is_int( $send ) ) { 90 $success = true; 91 $feedback = __( 'Message successfully sent.', 'buddypress' ); 92 $view = trailingslashit( $member_messages . 'view' ); 93 $redirect_to = trailingslashit( $view . $send ); 94 95 // Message could not be sent. 96 } else { 97 $success = false; 98 $feedback = $send->get_error_message(); 99 } 100 } 101 } 102 103 // Feedback. 104 if ( ! empty( $feedback ) ) { 105 106 // Determine message type. 107 $type = ( true === $success ) 108 ? 'success' 109 : 'error'; 110 111 // Add feedback message. 112 bp_core_add_message( $feedback, $type ); 113 } 114 115 // Maybe redirect. 116 if ( ! empty( $redirect_to ) ) { 117 bp_core_redirect( $redirect_to ); 118 } 119 } 120 add_action( 'bp_actions', 'bp_messages_action_create_message' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Dec 26 01:01:04 2024 | Cross-referenced by PHPXref 0.7.1 |