Add File Permission to Media Upload
-
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' );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Add File Permission to Media Upload’ is closed to new replies.