Created
August 11, 2017 13:30
-
-
Save asadowski10/1ee36c268767c2923996241b05517b60 to your computer and use it in GitHub Desktop.
Protect media uploaded with content editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: BE API - Media Vault protect media from editor | |
* Description: Allow to protect media uploaded with content editor | |
* Plugin URI: http://www.beapi.fr | |
* Version: 1.0.0 | |
* Author: BeAPI | |
* Author URI: http://www.beapi.fr | |
*/ | |
add_action( 'added_post_meta', 'bea_added_post_meta', 10, 4 ); | |
function bea_added_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) { | |
if ( ! function_exists( 'mgjp_mv_move_attachment_to_protected' ) ) { | |
return false; | |
} | |
remove_action( 'added_post_meta', 'bea_added_post_meta', 15 ); | |
if ( '_wp_attachment_metadata' !== $meta_key ) { | |
return false; | |
} | |
if ( 'attachment' !== get_post_type( $object_id ) ) { | |
return false; | |
} | |
mgjp_mv_move_attachment_to_protected( $object_id ); | |
update_post_meta( $object_id, '_mgjp_mv_permission', 'logged-in' ); | |
add_action( 'added_post_meta', 'bea_added_post_meta', 15, 4 ); | |
} |
Having an odd situation where certain file types aren't protected (.csv, .docs, etc) but others are OK (.jpg, pdf). Commenting out this line:
if ( '_wp_attachment_metadata' !== $meta_key ) { return false; }
works but I'm not sure whether there are any implications for this. Any thoughts?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to add this action as well to get it to work for me:
add_action( 'updated_post_meta', 'bea_added_post_meta', 10, 4 );