BP_媒体::删除(大堆$args=数组(),布尔美元自=错误的)
从数据库中删除媒体项。
描述
若要删除特定媒体项,请传递“id”参数。否则,请使用筛选器。
参数
- $args
-
(大堆)(可选)
默认值:array()
- 美元自
-
(布尔)(可选)从中删除的上下文。附件、活动等。
默认值:false
回来
(数组| bool)成功时删除的媒体ID数组,失败时为false。
来源
文件:bp-media/classes/class-bp-media.php
公共静态函数delete($args=array()){global$wpdb;$bp=buddypress();$r=wp\u parse\u args($args,array('id'=>false,'blog\u id'=>false,'attachment\u id'=>false,'user\u id'=>false,'title'=>false,'album\u id'=>false,'activity\u id'=>false,'group\u id'=>false,'privacy'>false,';//从where查询参数设置空数组。$where args=array();//ID.if(!empty($r['ID']){$where args[]=$wpdb->prepare($r['ID']);//blog ID.if(!empty($r['blog\u ID']){$where args[]=$wpdb->prepare($blog\u ID=%d',$r['blog\u ID'])}//附件ID.if(!empty($r['blog\u-ID']){$where\u-args[]=$wpdb->prepare(“附件id=%d”,$r['attachment\u id'])}//User id.if(!empty($r['User\u id']){$where\u args[]=$wpdb->prepare(“用户id=%d”,$r['User\u id'])}//title.if(!empty($r['title']){$where\u args[]=$wpdb->prepare($title=%s),$r['title'])}//album id.if(!empty($r['album['id']){where[]=$wpdb->prepare(“相册id=%d”、$r['album_id'])}//活动id.if(!empty($r['activity_id']){$where_args[]=$wpdb->prepare(“活动id=%d”、$r['activity_id']);//组id.if(!empty($r['group_id']){$where_args[]=$wpdb->prepare(“组id=%d”、$r['group_id']);//隐私(!empty($r[]){$where_args[]=$wpdb->prepare(“privacy=%s”,$r['privacy']);}//Date created.if(!empty($r['Date_created']){$where_args[]=$wpdb->prepare(“Date_created=%s”,“r['Date_created'])if//if(empty($where_args)){return false;}//加入where参数进行查询。$where_-sql='where'。加入('AND',$where_args);//获取所有被删除的媒体,以便执行更多操作。$medias=$wpdb->get_结果(“从{$bp->media->table_name}{$where_sql}中选择*);/***允许删除拦截媒体项目的操作。**@自BuddyBoss 1.0.0以来**@param array$medias媒体数组。*@param array$r解析参数数组。*/do_Action_ref_array('bp_media_before_delete',array($medias,$r));//尝试从数据库中删除媒体。$deleted=$wpdb->query(“delete from{$bp->media->table_name}{$where_sql}”);//如果未删除任何内容,则自动跳转。if(empty($deleted)){return false;}/***操作以允许截取刚删除的媒体项目。**@since BuddyBoss 1.0.0**@param array$medias media media media media数组。*@param array$r解析参数数组。*/do_Action_ref_数组('bp_media_delete后的数组($medias,$r));//从$medias数组中取出媒体id。$media_id=wp_parse_id_list(wp_list_pull($medias,'id'));$activity_id=wp_parse_id_list(wp_list_pull($medias,'activity_id'));$attachment_id=wp_parse_id_list_list(wp_list_pull($medias,'attachment_id');//处理伴随的附件和元删除。如果(!empty($attachment_id)){//遍历附件id并尝试删除。foreach($attachment_id as$attachment_id){if(bp_处于活动状态('activity')){$parent_activity_id=get_post_meta($attachment_id,'bp_media_parent_activity_id',true);if(!empty($parent_activity_activity_activity_id)){$activity_media_id=bp_activity_-get_meta($parent_activity_id,'bp_media_id',true);if(!empty($activity_media_id)){$activity_media_id=explode(',',$activity_media_id);$activity_media_id=array_diff($activity_media_id,$media_id);if(!empty($activity_media_id)){$activity_media_id=内爆(',',$activity_media_id);$activity_media_id);bp_更新_元($parent_activity_id,'bp_media_id',$activity_media_id);}else{$activity_id[]=$parent_activity_id;}}}wp_delete_post($attachment_id,true);}//如果(!empty($activity_id)&&bp_处于活动状态('activity')){foreach($activity_id为$activity_id){$activity=new bp_活动($int),则删除相关活动$activity_id);//检查访问权限。if(bp_activity_user_can_delete($activity)){/**此操作记录在bp activity/bp-activity-actions.php*/do_action('bp_activity_-before_activity_delete_activity',$activity->id,$activity->user_id);//删除活动注释。if('activity_-comment'==$activity->type){if(bp_activity_delete_comment($activity->item_id,$activity->id)){/**此操作记录在bp activity/bp-activity-actions.php*/do_action('bp_activity_activity_delete_activity',$activity->id,$activity->user_id);//删除活动。}否则{if(bp_activity_delete)(数组)('id'=>$activity->id,'user\u id'=>$activity->user\u id)){/**此操作记录在bp activity/bp-activity-actions.php*/do\u action('bp\u activity\u activity\u delete\u activity',$activity->id,$activity->user\u id);}}}}}}}}返回$media\u id;}
变更日志
版本 | 描述 |
---|---|
BuddyBoss 1.0.0 | 介绍。 |