/**
* Adds a new album
*
* @param string $title
* @param bool|int $author_id
* @param bool|type $new
* @param bool|int $post_id
*
* @param bool $context
* @param bool $context_id
*
* @return type
* @global type $rtmedia_interaction
*
*/
function add($title = '', $author_id = false, $new = true, $post_id = false, $context = false, $context_id = false)
{
global $rtmedia_interaction;
/* action to perform any task before adding the album */
do_action('rtmedia_before_add_album');
$author_id = $author_id ? $author_id : $this->get_current_author();
/* Album Details which will be passed to Database query to add the album */
$post_vars = array('post_title' => empty($title) ? esc_html__('Untitled Album', 'buddypress-media') : $title, 'post_type' => 'rtmedia_album', 'post_author' => $author_id, 'post_status' => 'hidden');
/* Check whether to create a new album in wp_post table
* This is the case when a user creates a album of his own. We need to
* create a separte post in wp_post which will work as parent for
* all the media uploaded to that album
*
* */
if ($new) {
$album_id = wp_insert_post($post_vars);
} else {
$album_id = $post_id;
}
$current_album = get_post($album_id, ARRAY_A);
if (false === $context) {
$context = isset($rtmedia_interaction->context->type) ? $rtmedia_interaction->context->type : null;
}
if (false === $context_id) {
$context_id = isset($rtmedia_interaction->context->id) ? $rtmedia_interaction->context->id : null;
}
// add in the media since album is also a media
//defaults
$attributes = array('blog_id' => get_current_blog_id(), 'media_id' => $album_id, 'album_id' => null, 'media_title' => $current_album['post_title'], 'media_author' => $current_album['post_author'], 'media_type' => 'album', 'context' => $context, 'context_id' => $context_id, 'activity_id' => null, 'privacy' => null);
$attributes = apply_filters('rtmedia_before_save_album_attributes', $attributes, $_POST);
// @codingStandardsIgnoreLine
$rtmedia_id = $this->media->insert_album($attributes);
$rtmedia_nav = new RTMediaNav();
$media_count = $rtmedia_nav->refresh_counts($context_id, array('context' => $context, 'media_author' => $context_id));
/* action to perform any task after adding the album */
global $rtmedia_points_media_id;
$rtmedia_points_media_id = $rtmedia_id;
do_action('rtmedia_after_add_album', $this);
return $rtmedia_id;
}