BP_REST_Media_Endpoint:: bp_rest_create_media (数组args美元

从上传id中创建媒体id。

描述

参数

args美元

数组(必需)查询变量到查询值的键值数组。

返回

(数组| WP_Error)

文件:bp-media /类/ class-bp-rest-media-endpoint.php

公共功能bp_rest_create_media($ args){$ media_privacy =(!空($ args ['privacy'])?$ args ['privacy']:'公共');$ upload_ids =(!空($ args ['upload_ids'])?$ args ['upload_ids']:'');$ activity_id =(!空($ args ['activity_id'])?$ args ['activity_id']:false);$ content =(!空($ args ['内容'])?$ args ['内容']:false);$ user_id =(!空($ args ['user_id'])?$ args ['user_id']:get_current_user_id());$ id =(!空($ args ['id'])?$ args ['id']:'');$ group_id =(!空($ args ['group_id'])?$ args ['group_id']:false);$ album_id =(!空($ args ['album_id'])?$ args ['album_id']:false);//如果给出了相册ID,则覆盖隐私。if(!空($ args ['album_id']))){$相册= bp_album_get_specific(数组('album_ids'=>数组($ args ['album_id']))))); if ( ! empty( $albums['albums'] ) ) { $album = array_pop( $albums['albums'] ); $media_privacy = $album->privacy; } } // Update Media. if ( ! empty( $id ) ) { $wp_attachment_id = $args['attachment_id']; $wp_attachment_url = wp_get_attachment_url( $wp_attachment_id ); // when the file found to be empty it's means it's not a valid attachment. if ( empty( $wp_attachment_url ) ) { return; } $media_activity_id = $activity_id; // extract the nice title name. $title = get_the_title( $wp_attachment_id ); $media_id = bp_media_add( array( 'id' => $id, 'attachment_id' => $wp_attachment_id, 'title' => $title, 'activity_id' => $media_activity_id, 'album_id' => ( ! empty( $args['album_id'] ) ? $args['album_id'] : false ), 'group_id' => ( ! empty( $args['group_id'] ) ? $args['group_id'] : false ), 'privacy' => $media_privacy, 'user_id' => $user_id, 'error_type' => 'wp_error', ) ); if ( is_int( $media_id ) ) { // save media is saved in attachment. update_post_meta( $wp_attachment_id, 'bp_media_saved', true ); // save media meta for activity. if ( ! empty( $media_activity_id ) ) { update_post_meta( $wp_attachment_id, 'bp_media_activity_id', $media_activity_id ); } $created_media_ids[] = $media_id; } } // created Medias. if ( ! empty( $upload_ids ) ) { $valid_upload_ids = array(); foreach ( $upload_ids as $wp_attachment_id ) { $wp_attachment_url = wp_get_attachment_url( $wp_attachment_id ); // when the file found to be empty it's means it's not a valid attachment. if ( empty( $wp_attachment_url ) ) { continue; } $valid_upload_ids[] = $wp_attachment_id; } if ( ! empty( $valid_upload_ids ) ) { foreach ( $valid_upload_ids as $wp_attachment_id ) { $media_activity_id = false; // make an activity for the media. if ( bp_is_active( 'activity' ) ) { if ( empty( $activity_id ) ) { if ( bp_is_active( 'groups' ) && ! empty( $group_id ) && $group_id > 0 ) { $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $group_id, 'privacy' => 'public' ) ); } else { $activity_id = bp_activity_post_update( array( 'content' => $content ) ); } } if ( count( $valid_upload_ids ) > 1 ) { if ( bp_is_active( 'groups' ) && ! empty( $group_id ) && $group_id > 0 ) { $media_activity_id = groups_post_update( array( 'group_id' => $group_id, 'hide_sitewide' => true, 'privacy' => 'media', ) ); } else { $media_activity_id = bp_activity_post_update( array( 'hide_sitewide' => true, 'privacy' => 'media', ) ); } if ( $media_activity_id ) { // update activity meta. bp_activity_update_meta( $media_activity_id, 'bp_media_activity', '1' ); } } else { $media_activity_id = $activity_id; } } // extract the nice title name. $title = get_the_title( $wp_attachment_id ); $media_id = bp_media_add( array( 'attachment_id' => $wp_attachment_id, 'title' => $title, 'activity_id' => $media_activity_id, 'album_id' => ( ! empty( $args['album_id'] ) ? $args['album_id'] : false ), 'group_id' => ( ! empty( $args['group_id'] ) ? $args['group_id'] : false ), 'privacy' => $media_privacy, 'user_id' => $user_id, 'error_type' => 'wp_error', ) ); if ( is_int( $media_id ) ) { // save media is saved in attachment. update_post_meta( $wp_attachment_id, 'bp_media_saved', true ); // save media meta for activity. if ( ! empty( $activity_id ) ) { update_post_meta( $wp_attachment_id, 'bp_media_parent_activity_id', $activity_id ); if ( $media_activity_id !== $activity_id ) { update_post_meta( $wp_attachment_id, 'bp_media_activity_id', $media_activity_id ); } } $created_media_ids[] = $media_id; } } } } if ( empty( $created_media_ids ) ) { return new WP_Error( 'bp_rest_media_creation_error', __( 'Error creating media, please try again.', 'buddyboss' ), array( 'status' => 400, ) ); } // Link all uploaded media to main activity. if ( ! empty( $activity_id ) && empty( $id ) ) { $created_media_ids_joined = implode( ',', $created_media_ids ); bp_activity_update_meta( $activity_id, 'bp_media_ids', $created_media_ids_joined ); $main_activity = new BP_Activity_Activity( $activity_id ); if ( ! empty( $main_activity ) && empty( $group_id ) ) { $main_activity->privacy = $media_privacy; $main_activity->save(); } } return $created_media_ids; }

更新日志

更新日志
版本 描述
0.1.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队