Changeset 13342 for trunk/src/bp-blogs/bp-blogs-activity.php
- Timestamp:
- 10/22/2022 09:45:12 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-blogs/bp-blogs-activity.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-activity.php
r13108 r13342 116 116 117 117 /** 118 * Returns the blog URL and name which relates to a post or comment activity. 119 * 120 * @since 11.0.0 121 * 122 * @param BP_Activity_Activity $activity The activity object. 123 * @return array The blog URL and name which relates to a post or comment activity. 124 */ 125 function bp_blogs_activity_get_site_link_meta( $activity = null ) { 126 $attributes = array( 127 'blog_url' => '', 128 'blog_name' => '', 129 ); 130 131 if ( ! isset( $activity->item_id, $activity->component ) || ! $activity->item_id || 'blogs' !== $activity->component ) { 132 return $attributes; 133 } 134 135 if ( isset( $activity->blog_url ) ) { 136 $attributes['blog_url'] = $activity->blog_url; 137 } else { 138 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 139 140 if ( ! $blog_url ) { 141 $blog_url = get_home_url( $activity->item_id ); 142 bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url ); 143 } else { 144 $attributes['blog_url'] = $blog_url; 145 } 146 } 147 148 if ( isset( $activity->blog_name ) ) { 149 $attributes['blog_name'] = $activity->blog_name; 150 } else { 151 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 152 153 if ( ! $blog_name ) { 154 $blog_name = get_blog_option( $activity->item_id, 'blogname' ); 155 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 156 } else { 157 $attributes['blog_name'] = $blog_name; 158 } 159 } 160 161 return $attributes; 162 } 163 164 /** 118 165 * Format 'new_blog' activity actions. 119 166 * … … 122 169 * @param string $action Static activity action. 123 170 * @param object $activity Activity data object. 124 * @return string 171 * @return string Constructed activity action. 125 172 */ 126 173 function bp_blogs_format_activity_action_new_blog( $action, $activity ) { 127 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 128 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 174 list( $blog_url, $blog_name ) = array_values( bp_blogs_activity_get_site_link_meta( $activity ) ); 129 175 130 176 $action = sprintf( … … 143 189 144 190 if ( isset( $recorded_blog ) ) { 145 $action = apply_filters( 'bp_blogs_activity_created_blog_action', $action, $recorded_blog, $blog_name, bp_blogs_get_blogmeta( $activity->item_id, 'description' ) ); 191 $blog_description = bp_blogs_get_blogmeta( $activity->item_id, 'description' ); 192 $action = apply_filters_deprecated( 'bp_blogs_activity_created_blog_action', array( $action, $recorded_blog, $blog_name, $blog_description ), '2.0.0', 'bp_blogs_format_activity_action_new_blog' ); 146 193 } 147 194 } … … 168 215 */ 169 216 function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) { 170 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );171 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );172 173 if ( empty( $blog_url ) || empty( $blog_name ) ) {174 $blog_url = get_home_url( $activity->item_id );175 $blog_name = get_blog_option( $activity->item_id, 'blogname' );176 177 bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url );178 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );179 }180 181 /**182 * When the post is published we are faking an activity object183 * to which we add 2 properties :184 * - the post url185 * - the post title186 * This is done to build the 'post link' part of the activity187 * action string.188 * NB: in this case the activity has not yet been created.189 */190 if ( isset( $activity->post_url ) ) {191 $post_url = $activity->post_url;192 193 /**194 * The post_url property is not set, we need to build the url195 * thanks to the post id which is also saved as the secondary196 * item id property of the activity object.197 */198 } else {199 $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );200 }201 202 // Should be the case when the post has just been published.203 if ( isset( $activity->post_title ) ) {204 $post_title = $activity->post_title;205 206 // If activity already exists try to get the post title from activity meta.207 } else if ( ! empty( $activity->id ) ) {208 $post_title = bp_activity_get_meta( $activity->id, 'post_title' );209 }210 211 /**212 * In case the post was published without a title213 * or the activity meta was not found.214 */215 if ( empty( $post_title ) ) {216 // Defaults to no title.217 $post_title = __( '(no title)', 'buddypress' );218 219 switch_to_blog( $activity->item_id );220 221 $post = get_post( $activity->secondary_item_id );222 if ( is_a( $post, 'WP_Post' ) ) {223 // Does the post have a title ?224 if ( ! empty( $post->post_title ) ) {225 $post_title = $post->post_title;226 }227 228 // Make sure the activity exists before saving the post title in activity meta.229 if ( ! empty( $activity->id ) ) {230 bp_activity_update_meta( $activity->id, 'post_title', $post_title );231 }232 }233 234 restore_current_blog();235 }236 237 // Build the 'post link' part of the activity action string.238 $post_link = '<a href="' . esc_url( $post_url ) . '">' . esc_html( $post_title ) . '</a>';239 240 217 $user_link = bp_core_get_userlink( $activity->user_id ); 241 218 242 219 // Build the complete activity action string. 243 220 if ( is_multisite() ) { 221 list( $blog_url, $blog_name ) = array_values( bp_blogs_activity_get_site_link_meta( $activity ) ); 222 244 223 $action = sprintf( 245 /* translators: 1: the activity user link. 2: the post link. 3: theblog link. */246 esc_html_x( '%1$s wrote a new post , %2$s, on the site %3$s', '`new_blog_post` activity action', 'buddypress' ),224 /* translators: 1: the activity user link. 2: the blog link. */ 225 esc_html_x( '%1$s wrote a new post on the site %2$s', 'Multisite `new_blog_post` activity action', 'buddypress' ), 247 226 $user_link, 248 $post_link,249 227 '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' 250 228 ); 251 229 } else { 252 230 $action = sprintf( 253 /* translators: 1: the activity user link. 2: the post link. */ 254 esc_html_x( '%1$s wrote a new post, %2$s', '`new_blog_post` activity action', 'buddypress' ), 255 $user_link, 256 $post_link 231 /* translators: 1: the activity user link. */ 232 esc_html_x( '%s wrote a new post', '`new_blog_post` activity action', 'buddypress' ), 233 $user_link 257 234 ); 258 235 } … … 265 242 266 243 if ( ! empty( $post ) && ! is_wp_error( $post ) ) { 267 $action = apply_filters( 'bp_blogs_activity_new_post_action', $action, $post, $post_url ); 244 $post_url = add_query_arg( 'p', $post->ID, trailingslashit( get_home_url( $activity->item_id ) ) ); 245 $action = apply_filters_deprecated( 'bp_blogs_activity_new_post_action', array( $action, $post, $post_url ), '2.0.0', 'bp_blogs_format_activity_action_new_blog_post' ); 268 246 } 269 247 } … … 301 279 * NB: in this case the activity has not yet been created. 302 280 */ 303 304 $blog_url = false; 305 306 // Try to get the blog url from the activity object. 307 if ( isset( $activity->blog_url ) ) { 308 $blog_url = $activity->blog_url; 309 } else { 310 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 311 } 312 313 $blog_name = false; 314 315 // Try to get the blog name from the activity object. 316 if ( isset( $activity->blog_name ) ) { 317 $blog_name = $activity->blog_name; 318 } else { 319 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 320 } 321 322 if ( empty( $blog_url ) || empty( $blog_name ) ) { 323 $blog_url = get_home_url( $activity->item_id ); 324 $blog_name = get_blog_option( $activity->item_id, 'blogname' ); 325 326 bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url ); 327 bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 328 } 329 330 $post_url = false; 281 list( $blog_url, $blog_name ) = array_values( bp_blogs_activity_get_site_link_meta( $activity ) ); 282 $post_url = false; 331 283 332 284 // Try to get the post url from the activity object. … … 402 354 403 355 if ( ! empty( $comment ) && ! is_wp_error( $comment ) ) { 404 $action = apply_filters ( 'bp_blogs_activity_new_comment_action', $action, $comment, $post_url . '#' . $activity->secondary_item_id);356 $action = apply_filters_deprecated( 'bp_blogs_activity_new_comment_action', array( $action, $comment, $post_url . '#' . $activity->secondary_item_id ), '2.0.0', 'bp_blogs_format_activity_action_new_blog_comment' ); 405 357 } 406 358 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)