BP_Media:保存()

将媒体项保存到数据库中。

描述

返回

(WP_Error | bool)真正的成功。

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

Public function save() {global $wpdb;英国石油美元= buddypress ();$this->id = apply_filters_ref_array('bp_media_id_before_save', array($this->id, &$this)); / /使用实例$this->blog_id = apply_filters_ref_array('bp_media_blog_id_before_save', array($this->blog_id, &$this));$this->attachment_id = apply_filters_ref_array('bp_media_attachment_id_before_save', array($this->attachment_id, &$this));$this->user_id = apply_filters_ref_array('bp_media_user_id_before_save', array($this->user_id, &$this));$this->title = apply_filters_ref_array('bp_media_title_before_save', array($this->title, &$this)); / /将所有的内容都保存下来$this->album_id = apply_filters_ref_array('bp_media_album_id_before_save', array($this->album_id, &$this));$this->activity_id = apply_filters_ref_array('bp_media_activity_id_before_save', array($this->activity_id, &$this));$this->group_id = apply_filters_ref_array('bp_media_group_id_before_save', array($this->group_id, &$this)); $this->privacy = apply_filters_ref_array( 'bp_media_privacy_before_save', array( $this->privacy, &$this ) ); $this->menu_order = apply_filters_ref_array( 'bp_media_menu_order_before_save', array( $this->menu_order, &$this ) ); $this->date_created = apply_filters_ref_array( 'bp_media_date_created_before_save', array( $this->date_created, &$this ) ); /** * Fires before the current media item gets saved. * * Please use this hook to filter the properties above. Each part will be passed in. * * @since BuddyBoss 1.0.0 * * @param BP_Media $this Current instance of the media item being saved. Passed by reference. */ do_action_ref_array( 'bp_media_before_save', array( &$this ) ); if ( 'wp_error' === $this->error_type && $this->errors->get_error_code() ) { return $this->errors; } if ( empty( $this->attachment_id ) //|| empty( $this->activity_id ) //todo: when forums media is saving, it should have activity id assigned if settings enabled need to check this ) { if ( 'bool' === $this->error_type ) { return false; } else { if ( empty( $this->activity_id ) ) { $this->errors->add( 'bp_media_missing_activity' ); } else { $this->errors->add( 'bp_media_missing_attachment' ); } return $this->errors; } } // If we have an existing ID, update the media item, otherwise insert it. if ( ! empty( $this->id ) ) { $q = $wpdb->prepare( "UPDATE {$bp->media->table_name} SET blog_id = %d, attachment_id = %d, user_id = %d, title = %s, album_id = %d, activity_id = %d, group_id = %d, privacy = %s, menu_order = %d, date_created = %s WHERE id = %d", $this->blog_id, $this->attachment_id, $this->user_id, $this->title, $this->album_id, $this->activity_id, $this->group_id, $this->privacy, $this->menu_order, $this->date_created, $this->id ); } else { $q = $wpdb->prepare( "INSERT INTO {$bp->media->table_name} ( blog_id, attachment_id, user_id, title, album_id, activity_id, group_id, privacy, menu_order, date_created ) VALUES ( %d, %d, %d, %s, %d, %d, %d, %s, %d, %s )", $this->blog_id, $this->attachment_id, $this->user_id, $this->title, $this->album_id, $this->activity_id, $this->group_id, $this->privacy, $this->menu_order, $this->date_created ); } if ( false === $wpdb->query( $q ) ) { return false; } // If this is a new media item, set the $id property. if ( empty( $this->id ) ) { $this->id = $wpdb->insert_id; } /** * Fires after an media item has been saved to the database. * * @since BuddyBoss 1.0.0 * * @param BP_Media $this Current instance of media item being saved. Passed by reference. */ do_action_ref_array( 'bp_media_after_save', array( &$this ) ); return true; }

更新日志

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

问题吗?

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