| @@ -160,8 +160,29 @@ | ||
| 160 | 160 | $post_types = array( self::CPT ); |
| 161 | 161 | return $post_types; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | + /** | |
| 165 | + * Look up a direct message by its URL. | |
| 166 | + * | |
| 167 | + * Messages live in their own post type which is not part of the frontend post | |
| 168 | + * types, so Feed::url_to_postid() doesn't consider them by default. | |
| 169 | + * | |
| 170 | + * @param string $url The URL of the message. | |
| 171 | + * | |
| 172 | + * @return int|null The post ID or null if it wasn't found. | |
| 173 | + */ | |
| 174 | + public static function url_to_postid( $url ) { | |
| 175 | + $only_messages = function () { | |
| 176 | + return array( self::CPT ); | |
| 177 | + }; | |
| 178 | + | |
| 179 | + add_filter( 'friends_frontend_post_types', $only_messages, 999 ); | |
| 180 | + $post_id = Feed::url_to_postid( $url ); | |
| 181 | + remove_filter( 'friends_frontend_post_types', $only_messages, 999 ); | |
| 182 | + | |
| 183 | + return $post_id; | |
| 184 | + } | |
| 164 | 185 | |
| 165 | 186 | public function save_incoming_message( User $friend_user, $message, $subject = '', $feed_url = null, $remote_url = null, $reply_to = null ) { |
| 166 | 187 | $post_data = array( |
| 167 | 188 | 'post_type' => self::CPT, |