/**
  * Maps the before_delete_post action to mpp_before_gallery_delete action
  * It also does the cleanup of attachments as wp_delete_post() does not delete attachments
  * 
  * @param int $gallery_id post id
  * @return unknown
  */
 public function map_before_delete_post_action($gallery_id)
 {
     //is this called or a valid gallery?
     if (!$gallery_id || !mpp_is_valid_gallery($gallery_id)) {
         return;
     }
     $gallery = mpp_get_gallery($gallery_id);
     //we are certain that it is called for gallery
     //fire the MediaPress gallery delete action
     if ($this->is_queued($gallery_id)) {
         //this action is already being executed for the current gallery, no need to do that again
         return;
     }
     $this->add_item($gallery_id, 'gallery');
     do_action('mpp_before_gallery_delete', $gallery_id);
     //after that action, we delete all attachment
     global $wpdb;
     //1// delete all media
     $storage_manager = null;
     $media_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d", $gallery_id));
     //we need the storage manager to notify it that it do do any final cleanup after the gallery delete
     //should we keep a reference to the storage manager for each gallery? what will happen for a gallery that contains local/remote media?
     //for the time being we are not keeping a reference but this method is doing exactly the same and I am not sure which approach will be fbetter for futuer
     if (!empty($media_ids)) {
         $mid = $media_ids[0];
         $storage_manager = mpp_get_storage_manager($mid);
     }
     //delete all media
     foreach ($media_ids as $media_id) {
         wp_delete_attachment($media_id);
         //delete all media
     }
     if (mediapress()->is_bp_active()) {
         //delete all gallery activity
         mpp_gallery_delete_activity($gallery_id);
         //delete all associated activity meta
         //mpp_gallery_delete_activity_meta( $gallery_id );
     }
     //Delete wall gallery meta
     mpp_delete_wall_gallery_id(array('component' => $gallery->component, 'component_id' => $gallery->component_id, 'gallery_id' => $gallery->id, 'media_type' => $gallery->type));
     //do any final cleanup, deletegate to the storage manager
     if ($storage_manager) {
         $storage_manager->delete_gallery($gallery);
     }
     return;
 }
Ejemplo n.º 2
0
/**
 * Filter comment open/close status
 * 
 * If BuddyPress is active, the WordPress comments on gallery/attachment is always disabled and we use the BuddyPress activity instead
 * 
 * @param type $open
 * @param type $post_id
 * @return int
 */
function mpp_filter_comment_settings($open, $post_id)
{
    $is_bp = 0;
    //if BuddyPress is active
    if (mediapress()->is_bp_active()) {
        $is_bp = 1;
    }
    if (mpp_is_valid_gallery($post_id)) {
        if (!mpp_get_option('enable_gallery_comment') || $is_bp) {
            $open = 0;
        }
    } elseif (mpp_is_valid_media($post_id)) {
        if (!mpp_get_option('enable_media_comment') || $is_bp) {
            $open = 0;
        }
    }
    return $open;
}
/**
 * Check if given gallery is sitewide gallery
 * 
 * @param int | WP_Post $id
 * @return boolean
 */
function mpp_is_sitewide_gallery($id)
{
    if (!mpp_is_valid_gallery($id)) {
        return false;
    }
    //assume it is a valid gallery
    $gallery = mpp_get_gallery($id);
    if (!empty($gallery) && $gallery->component == 'sitewide') {
        return true;
    }
    return false;
}