Changeset 13584
- Timestamp:
- 09/20/2023 01:00:54 AM (19 months ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/actions/compose.php
r13503 r13584 29 29 $feedback = ''; 30 30 $success = false; 31 $is_notice = isset( $_POST['send-notice'] ); 32 $path_chunks = array( bp_get_messages_slug() ); 31 33 32 // Missing subject or content. 33 if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) { 34 $success = false; 34 // List required vars and error messages. 35 $required_vars = array( 36 'subject' => __( 'Please enter a subject line.', 'buddypress' ), 37 'content' => __( 'Please enter some content.', 'buddypress' ), 38 ); 35 39 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 // The username is only needed for private messages. 41 if ( ! $is_notice ) { 42 $required_vars = array_merge( 43 array( 44 'send_to_usernames' => __( 'Please enter a username or Friend\'s name.', 'buddypress' ), 45 ), 46 $required_vars 47 ); 48 } 49 50 // Calculate whether some required vars are missing. 51 $needed_keys = array_intersect_key( $_POST, $required_vars ); 52 $needs_feedback = count( array_filter( $needed_keys ) ) !== count( $required_vars ); 53 54 // Prevent notice errors. 55 $required_args = array_map( 56 'wp_unslash', 57 bp_parse_args( 58 $needed_keys, 59 array( 60 'send_to_usernames' => '', 61 'subject' => '', 62 'content' => '' 63 ) 64 ) 65 ); 66 67 // Use cookies to preserve existing values. 68 messages_add_callback_values( 69 implode( ' ', wp_parse_list( $required_args['send_to_usernames'] ) ), 70 esc_html( $required_args['subject'] ), 71 esc_textarea( $required_args['content'] ) 72 ); 73 74 // Handle required vars. 75 if ( $needs_feedback ) { 76 $success = false; 77 $path_chunks[] = 'compose'; 78 $feedbacks = array( __( 'Your message was not sent.', 'buddypress' ) ); 79 80 foreach ( $required_vars as $required_key => $required_var_feedback ) { 81 if ( ! $required_args[ $required_key ] ) { 82 $feedbacks[] = $required_var_feedback; 83 } 40 84 } 41 85 42 // Subject and content present. 86 // Set the feedback message. 87 $feedback = implode( "\n", $feedbacks ); 88 $redirect_to = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) ); 43 89 } else { 44 90 45 // Setup the link to the logged-in user's messages.46 $path_chunks = array( bp_get_messages_slug() );47 48 91 // Site-wide notice. 49 if ( isset( $_POST['send-notice'] )) {92 if ( $is_notice ) { 50 93 51 94 // Attempt to save the notice and redirect to notices. 52 if ( messages_send_notice( $ _POST['subject'], $_POST['content'] ) ) {95 if ( messages_send_notice( $required_args['subject'], $required_args['content'] ) ) { 53 96 $success = true; 54 97 $feedback = __( 'Notice successfully created.', 'buddypress' ); 55 98 $path_chunks[] = 'notices'; 56 $redirect_to = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) );57 99 58 // Notice could not be sent.100 // Notice could not be sent. 59 101 } else { 60 $success = false; 61 $feedback = __( 'Notice was not created. Please try again.', 'buddypress' ); 102 $success = false; 103 $path_chunks[] = 'compose'; 104 $feedback = __( 'Notice was not created. Please try again.', 'buddypress' ); 62 105 } 63 106 64 // Private conversation. 107 $redirect_to = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) ); 108 109 // Private conversation. 65 110 } else { 66 111 67 112 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' ). 68 $autocomplete_recipients = (array) explode( ',', $_POST['send-to-input'] ); 69 $typed_recipients = (array) explode( ' ', $_POST['send_to_usernames'] ); 70 $recipients = array_merge( $autocomplete_recipients, $typed_recipients ); 113 $autocomplete_recipients = array(); 114 if ( isset( $_POST['send-to-input'] ) && $_POST['send-to-input'] ) { 115 $autocomplete_recipients = (array) explode( ',', $_POST['send-to-input'] ); 116 } 117 118 $typed_recipients = (array) explode( ' ', $required_args['send_to_usernames'] ); 119 $recipients = array_merge( $autocomplete_recipients, $typed_recipients ); 71 120 72 121 /** … … 80 129 81 130 // Attempt to send the message. 82 $send = messages_new_message( array( 83 'recipients' => $recipients, 84 'subject' => $_POST['subject'], 85 'content' => $_POST['content'], 86 'error_type' => 'wp_error', 87 ) ); 131 $send = messages_new_message( 132 array( 133 'recipients' => $recipients, 134 'subject' => $required_args['subject'], 135 'content' => $required_args['content'], 136 'error_type' => 'wp_error', 137 ) 138 ); 88 139 89 140 // Send the message and redirect to it. … … 93 144 $path_chunks[] = 'view'; 94 145 $path_chunks[] = array( $send ); 95 $redirect_to = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) );96 146 97 // Message could not be sent.147 // Message could not be sent. 98 148 } else { 99 $success = false; 100 $feedback = $send->get_error_message(); 149 $success = false; 150 $path_chunks[] = 'compose'; 151 $feedback = $send->get_error_message(); 101 152 } 153 154 $redirect_to = bp_loggedin_user_url( bp_members_get_path_chunks( $path_chunks ) ); 102 155 } 103 156 } -
trunk/src/bp-messages/bp-messages-template.php
r13503 r13584 1004 1004 1005 1005 // Sanitized in bp-messages-filters.php. 1006 $subject = ! empty( $_POST['subject'] ) 1007 ? $_POST['subject'] 1008 : ''; 1006 $subject = ''; 1007 if ( isset( $_POST['subject'] ) && $_POST['subject'] ) { 1008 $subject = $_POST['subject']; 1009 } elseif ( isset( $_COOKIE['bp_messages_subject'] ) && $_COOKIE['bp_messages_subject'] ) { 1010 $subject = $_COOKIE['bp_messages_subject']; 1011 } 1009 1012 1010 1013 /** … … 1035 1038 1036 1039 // Sanitized in bp-messages-filters.php. 1037 $content = ! empty( $_POST['content'] ) 1038 ? $_POST['content'] 1039 : ''; 1040 $content = ''; 1041 if ( isset( $_POST['content'] ) && $_POST['content'] ) { 1042 $content = $_POST['content']; 1043 } elseif ( isset( $_COOKIE['bp_messages_content'] ) && $_COOKIE['bp_messages_content'] ) { 1044 $content = $_COOKIE['bp_messages_content']; 1045 } 1040 1046 1041 1047 /** … … 1680 1686 1681 1687 // Sanitized in bp-messages-filters.php. 1682 $recipients = isset( $_GET['r'] ) 1683 ? $_GET['r'] 1684 : ''; 1688 $recipients = ''; 1689 if ( isset( $_GET['r'] ) && $_GET['r'] ) { 1690 $recipients = $_GET['r']; 1691 } elseif ( isset( $_COOKIE['bp_messages_send_to'] ) && $_COOKIE['bp_messages_send_to'] ) { 1692 $recipients = $_COOKIE['bp_messages_send_to']; 1693 } 1685 1694 1686 1695 /** -
trunk/src/bp-templates/bp-legacy/buddypress/members/single/messages/compose.php
r13295 r13584 11 11 <h2 class="bp-screen-reader-text"><?php 12 12 /* translators: accessibility text */ 13 _e( 'Compose Message', 'buddypress' );13 esc_html_e( 'Compose Message', 'buddypress' ); 14 14 ?></h2> 15 15 … … 25 25 do_action( 'bp_before_messages_compose_content' ); ?> 26 26 27 <label for="send-to-input"><?php _e("Send To (Username or Friend's Name)", 'buddypress' ); ?></label>27 <label for="send-to-input"><?php esc_html_e( 'Send To (Username or Friend\'s Name)', 'buddypress' ); ?></label> 28 28 <ul class="first acfb-holder"> 29 29 <li> … … 34 34 35 35 <?php if ( bp_current_user_can( 'bp_moderate' ) ) : ?> 36 <p><label for="send-notice"><input type="checkbox" id="send-notice" name="send-notice" value="1" /> <?php _e( "This is a notice to all users.", 'buddypress' ); ?></label></p>36 <p><label for="send-notice"><input type="checkbox" id="send-notice" name="send-notice" value="1" /> <?php esc_html_e( "This is a notice to all users.", 'buddypress' ); ?></label></p> 37 37 <?php endif; ?> 38 38 39 <label for="subject"><?php _e( 'Subject', 'buddypress' ); ?></label>39 <label for="subject"><?php esc_html_e( 'Subject', 'buddypress' ); ?></label> 40 40 <input type="text" name="subject" id="subject" value="<?php bp_messages_subject_value(); ?>" /> 41 41 42 <label for="message_content"><?php _e( 'Message', 'buddypress' ); ?></label>42 <label for="message_content"><?php esc_html_e( 'Message', 'buddypress' ); ?></label> 43 43 <textarea name="content" id="message_content" rows="15" cols="40"><?php bp_messages_content_value(); ?></textarea> 44 44
Note: See TracChangeset
for help on using the changeset viewer.