function mpp_media_filter_permalink($link, $post_id) { if (!mpp_is_valid_media($post_id)) { return $link; } $media = mpp_get_media($post_id); if ($media->component != 'sitewide') { return $link; } //in case of sitewide gallery, the permalink is like $gallery_permalink = mpp_get_gallery_permalink($media->gallery_id); return user_trailingslashit(untrailingslashit($gallery_permalink) . '/media/' . $media->slug); }
/** * Maps 'delete_attachment' to mpp_before_media_delete action * Also, cleans up cover, decrements media count and deletes activities associated * * @param type $media_id * @return type */ public function map_before_delete_attachment_action($media_id) { if (!mpp_is_valid_media($media_id)) { //the attachment is not media return; } //this is just a precaution in case some faulty plugin calls it again //if everything is normal, we don't need to check for this if ($this->is_queued($media_id)) { return; // } //push this media to teh queue $this->add_item($media_id, 'media'); /** * mpp_before_media_delete action fires before WordPress starts deleting an attachment which is a valid media( in MediaPress). * Any plugin utilizing this action can access the fully functional media object by using mpp_get_media() on the passed media id * */ do_action('mpp_before_media_delete', $media_id); $storage_manager = mpp_get_storage_manager($media_id); $storage_manager->delete_media($media_id); //delete if it is set as cover delete_metadata('post', null, '_mpp_cover_id', $media_id, true); // delete all for any posts. delete_metadata('post', null, '_mpp_unpublished_media_id', $media_id, true); // delete all for any posts. // //if media has cover, delete the cover $media = mpp_get_media($media_id); $gallery_id = $media->gallery_id; if (mpp_media_has_cover_image($media_id)) { mpp_delete_media(mpp_get_media_cover_id($media_id)); } if (apply_filters('mpp_cleanup_single_media_on_delete', true, $media_id, $gallery_id)) { mpp_gallery_decrement_media_count($gallery_id); if (mediapress()->is_bp_active()) { //delete all activities related to this media //mpp_media_delete_activities( $media_id ); mpp_delete_activity_for_single_published_media($media_id); //delete all activity meta key where this media is associated mpp_media_delete_activity_meta($media_id); } } return; }
/** * Redirect attachment link to single media page */ public function redirect_attachment() { if (is_attachment() && mpp_is_valid_media(get_queried_object_id())) { $redirect_url = mpp_get_media_url(get_queried_object()); mpp_redirect($redirect_url, 301); } }
/** * 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; }
public function delete_media() { //verify nonce if (!wp_verify_nonce($_POST['_wpnonce'], 'mpp-manage-gallery')) { wp_send_json(array('message' => __('Invalid action.', 'mediapress'), 'error' => 1)); exit(0); } $media_id = absint($_POST['media_id']); $media = mpp_get_media($media_id); if (!$media) { wp_send_json(array('message' => __('Invalid Media.', 'mediapress'), 'error' => 1)); exit(0); } if (!mpp_is_valid_media($media->id)) { wp_send_json(array('message' => __('Invalid Media.', 'mediapress'), 'error' => 1)); exit(0); } if (!mpp_user_can_delete_media($media_id)) { wp_send_json(array('message' => __('Unauthorized action.', 'mediapress'), 'error' => 1)); exit(0); } mpp_delete_media($media_id); wp_send_json(array('message' => __('Deleted.', 'mediapress'), 'success' => 1)); exit(0); }