/**
 * Saves for the selected actions under Profile > Actions.
 *
 * @since 1.0.0
 * @param $data arr. The POST data.
 * @return html. The content and miscellaneous followups.
 */
function bbconnect_save_new_post()
{
    if (!wp_verify_nonce($_POST['bbconnect_admin_nonce'], 'bbconnect-admin-nonce')) {
        die(__('Terribly sorry.', 'bbconnect'));
    }
    if (isset($_POST['data'])) {
        parse_str($_POST['data'], $postarr);
        $sid = $_POST['sid'];
        $type = $_POST['type'];
        if (isset($postarr['post_ID'])) {
            $postarr['ID'] = $postarr['post_ID'];
            //unset( $postarr['post_ID'] );
        }
        $pid = wp_insert_post($postarr);
        //         $postarr['id'] = $pid;
        bbconnect_save_action_meta(array('post_data' => $postarr, 'override' => true));
        $act = get_post($pid);
        $class = apply_filters('bbconnect_save_new_class', array(), $act);
        bbconnect_profile_action_item(array('act' => $act, 'type' => $type, 'new' => true, 'class' => $class, 'ok_edit' => true, 'action' => 'edit', 'bbconnect_cap' => 'admin'));
        ?>
        <script type="text/javascript">
        jQuery(document).ready(function () {
            // IF THE ELEMENT EXISTS, REMOVE IT & THE PARENT
            if ( jQuery('#post-<?php 
        echo $pid;
        ?>
').length != 0 ) {
                jQuery('#post-<?php 
        echo $pid;
        ?>
').parent('li').remove();
            }

            // CLONE THE NEW ELEMENT
            jQuery('.new-post').clone().prependTo('#<?php 
        echo $sid;
        ?>
 .actions-history-list');

            // UPDATE AND REMOVE THE NEW-POST IDENTIFIER
            jQuery('#<?php 
        echo $sid;
        ?>
 .actions-history-list .new-post').each(function(){
                jQuery(this).find('div[title="post-<?php 
        echo $pid;
        ?>
"]').attr('id','post-<?php 
        echo $pid;
        ?>
').attr('title','');
                jQuery(this).removeClass('new-post').fadeIn('fast');
            });

            // UPGRADE THE ORIGINAL
            var newparent = jQuery('.new-post').parent('.bbconnect-viewer').attr('id');
            jQuery('#'+newparent+' .new-post').each(function(){
                jQuery(this).find('div[title="post-<?php 
        echo $pid;
        ?>
"]').attr('id','new-post-<?php 
        echo $pid;
        ?>
').attr('title','');
                jQuery('#new-post-<?php 
        echo $pid;
        ?>
').prependTo('#'+newparent).fadeIn('fast');
                jQuery(this).remove();
            });

        });
        </script>
    <?php 
    } else {
        echo 'error';
    }
    die;
}
function bbconnect_attachment_save($post, $attachment)
{
    bbconnect_save_action_meta(array('post_data' => $post));
    return $post;
}