• Resolved WayneHarris

    (@wayneharris)


    Hi Max,

    Thank you for sharing your plugin, if I’m not mistaken there is not an option to set the file permission if you are adding media to a post/custom post using the Media Upload via add media button.

    I think the following should work, thought I would share this, but also ask if anyone knows how to resolve an issue I’m having.

    if you save the file permission it saves correctly but does not reload on the select unless you refresh the whole post and access the attachments again.

    /**
     * Rendering function for the Media Vault attachment
     * settings on Media Upload screen
     *
     * @since 0.8.--
     *
     * @uses mgjp_mv_get_the_permission()
     * @uses mgjp_mv_get_the_permissions()
     * @param $post object WP_Post object of current attachment
     *
     */
    add_filter('attachment_fields_to_edit', 'mgjp_mv_render_attachment_protection_attachment_settings', 20, 2);
    
    function mgjp_mv_render_attachment_protection_attachment_settings($form_fields, $post) {
    
    	$permission = get_post_meta( $post->ID, '_mgjp_mv_permission', true );
    
    	$permissions = mgjp_mv_get_the_permissions();
    
    	if ( empty( $permission ) || ! isset( $permissions[$permission] ) )
    		$permission = 'default';
    
    	$form_fields["mgjp_mv_permission_select"]["label"] = __("File Permission");
    	$form_fields["mgjp_mv_permission_select"]["input"] = "html";
    	$form_fields["mgjp_mv_permission_select"]["html"] = "<select name='attachments[{$post->ID}][mgjp_mv_permission_select]' id='attachments[{$post->ID}][mgjp_mv_permission_select]'>";
    
    	$form_fields["mgjp_mv_permission_select"]["html"] .= "<option value='default'>";
    	$form_fields["mgjp_mv_permission_select"]["html"] .= "Use Default Setting";
    	$form_fields["mgjp_mv_permission_select"]["html"] .= "</option>";
    
    	foreach ( $permissions as $key => $data ){
    
    		$form_fields["mgjp_mv_permission_select"]["html"] .= "<option value='$key'";
    		if ($permission == $key) {
    			$form_fields["mgjp_mv_permission_select"]["html"] .= "selected='selected'";
    		}
    		$form_fields["mgjp_mv_permission_select"]["html"] .= ">";
    		$form_fields["mgjp_mv_permission_select"]["html"] .= $data['select'];
    		$form_fields["mgjp_mv_permission_select"]["html"] .= "</option>";
    	};
    
    	$form_fields["mgjp_mv_permission_select"]["html"] .= "</select>";
    
        return $form_fields;
    };
    
    function mgjp_mv_save_attachment_settings( $attachment_id ) {
        if ( isset( $_REQUEST['attachments'][$attachment_id]['mgjp_mv_permission_select'] ) ) {
            $permission = $_REQUEST['attachments'][$attachment_id]['mgjp_mv_permission_select'];
            update_post_meta( $attachment_id, '_mgjp_mv_permission', $permission );
        }
    }
    add_action( 'edit_attachment', 'mgjp_mv_save_attachment_settings' );

    http://wordpress.org/plugins/media-vault/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Max GJ Panas

    (@max-gjp)

    Hey Wayne,

    Thank you for the kind words. No, there isn’t an option yet (version 0.8.6) to upload files to the Media Vault protected folder via the Media Upload Modal.

    Just to clarify, what you want to do is be able to change the permissions of attachments through the Media Upload Modal after they have been uploaded, or do you want to upload files directly into the protected folder?

    Thread Starter WayneHarris

    (@wayneharris)

    Hi,

    Yes, that’s correct I want to be able to set or amend the permission of a new or existing file through the Media Upload Modal when creating a post.

    This would save having to amend the permission settings in the media library after you have uploaded a media file when creating a post.

    The code/functions I posted earlier adds what I’m suggesting. But it’s not complete, as it will save the permission setting when you insert the media into the post, but not refresh the select options if you open the Media Upload Modal again after, unless you refresh the post page.

    Hope I’m being clear enough, hopefully you will see what I mean by testing the function.

    Thread Starter WayneHarris

    (@wayneharris)

    Hi Max,

    Looking at this again I missed an obvious additional issue, although the above updates the meta data for the protected file, it does not call the function to actually move the file to the media vault directory.

    Anyway you probably knew that already.

    Wayne

    Plugin Author Max GJ Panas

    (@max-gjp)

    Hey Wayne,

    Yes, I was composing a message to let you know that just before you sent me the reply. Sorry its been taking me a while, I have been traveling back home for holidays.

    Nonetheless, I have been looking into adding Media Vault settings to the Media Upload Modal similar to what you described in your first post and will update here with more info as soon as possible.

    Thanks

    Thread Starter WayneHarris

    (@wayneharris)

    Hi,

    Not a problem, I’ll look out for the update.

    Wayne

    Plugin Author Max GJ Panas

    (@max-gjp)

    Hey Wayne,

    It’s been a while in the making, but I just got round to adding the finishing touches to the feature you requested, and have pushed it out in version 0.8.9 of Media Vault. Let me know how it is working out!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add File Permission to Media Upload’ is closed to new replies.