public generate_post_array ( type $uploaded, type $file_object ) : type | ||
$uploaded | type | |
$file_object | type | |
Результат | type |
function generate_post_array($uploaded, $file_object)
{
if ($uploaded['album_id']) {
$model = new RTMediaModel();
$parent_details = $model->get(array('id' => $uploaded['album_id']));
if (is_array($parent_details) && count($parent_details) > 0) {
$album_id = $parent_details[0]->media_id;
} else {
$album_id = 0;
}
} else {
$album_id = 0;
}
if (!in_array($uploaded['context'], array('profile', 'group'), true)) {
$album_id = $uploaded['context_id'];
}
$attachments = array();
foreach ($file_object as $index => $file) {
$uploaded['title'] = wp_kses($uploaded['title'], wp_kses_allowed_html());
// filter description for allowed html tags
$uploaded['description'] = wp_kses($uploaded['description'], wp_kses_allowed_html());
$attachments[$index] = array('post_mime_type' => $file['type'], 'guid' => esc_url_raw($file['url']), 'post_title' => sanitize_text_field($uploaded['title'] ? $uploaded['title'] : preg_replace('/\\.[^.\\s]{3,4}$/', '', $file['name'])), 'post_content' => $uploaded['description'] ? $uploaded['description'] : '', 'post_parent' => intval($album_id), 'post_author' => intval($uploaded['media_author']));
if (!empty($uploaded['date'])) {
$attachments[$index]['post_date'] = $uploaded['date'];
}
}
return $attachments;
}