bp_activity_edit_update_document( $document_ids )
Update document and activity for document updation and deletion while editing the activity.
Description
Parameters
- $document_ids
-
(Required)
Return
(mixed)
Source
File: bp-activity/bp-activity-filters.php
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 | function bp_activity_edit_update_document( $document_ids ) { global $bp_activity_edit , $bp_activity_post_update_id ; if ( ( true === $bp_activity_edit || isset( $_POST [ 'edit' ] ) ) && ! empty ( $bp_activity_post_update_id ) ) { $old_document_ids = bp_activity_get_meta( $bp_activity_post_update_id , 'bp_document_ids' , true ); $old_document_ids = explode ( ',' , $old_document_ids ); if ( ! empty ( $old_document_ids ) ) { // old document count 1 and new document uploaded count is greater than 1. if ( 1 === count ( $old_document_ids ) && 1 < count ( $document_ids ) ) { $old_document_id = $old_document_ids [0]; // check if old document id is in new document uploaded. if ( in_array( $old_document_id , $document_ids ) ) { // Create new document activity for old document because it has only parent activity to show right now. $old_document = new BP_Document( $old_document_id ); $args = array ( 'hide_sitewide' => true, 'privacy' => 'document' ); if ( ! empty ( $old_document ->group_id ) && bp_is_active( 'groups' ) ) { $args [ 'item_id' ] = $old_document ->group_id; $args [ 'type' ] = 'activity_update' ; $current_group = groups_get_group( $old_document ->group_id ); $args [ 'action' ] = sprintf( __( '%1$s posted an update in the group %2$s' , 'buddyboss' ), bp_core_get_userlink( $old_document ->user_id ), '<a href="' . bp_get_group_permalink( $current_group ) . '">' . esc_attr( $current_group ->name ) . '</a>' ); $activity_id = groups_record_activity( $args ); } else { $activity_id = bp_activity_post_update( $args ); } // document activity for old document is created and it is being assigned to the old document. // And document activity is being saved with needed data to figure out everything for it. if ( $activity_id ) { $old_document ->activity_id = $activity_id ; $old_document ->save(); $document_activity = new BP_Activity_Activity( $activity_id ); $document_activity ->secondary_item_id = $bp_activity_post_update_id ; $document_activity ->save(); // update activity meta to tell it is document activity. bp_activity_update_meta( $activity_id , 'bp_document_activity' , '1' ); // save attachment meta for activity. update_post_meta( $old_document ->attachment_id, 'bp_document_activity_id' , $activity_id ); //save parent activity id in attachment meta. update_post_meta( $old_document ->attachment_id, 'bp_document_parent_activity_id' , $bp_activity_post_update_id ); } } // old document count is greater than 1 and new document uploaded count is only 1 now. } else if ( 1 < count ( $old_document_ids ) && 1 === count ( $document_ids ) ) { $new_document_id = $document_ids [0]; // check if new document is in old document uploaded, if yes then delete that document's document activity first. if ( in_array( $new_document_id , $old_document_ids ) ) { $new_document = new BP_Document( $new_document_id ); $document_activity_id = $new_document ->activity_id; // delete document's assigned document activity. remove_action( 'bp_activity_after_delete' , 'bp_document_delete_activity_document' ); bp_activity_delete( array ( 'id' => $document_activity_id ) ); add_action( 'bp_activity_after_delete' , 'bp_document_delete_activity_document' ); //save parent activity id in document. $new_document ->activity_id = $bp_activity_post_update_id ; $new_document ->save(); //save parent activity id in attachment meta. update_post_meta( $new_document ->attachment_id, 'bp_document_parent_activity_id' , $bp_activity_post_update_id ); } } } } return $document_ids ; } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.