mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-13 03:36:28 +09:00
- fixed content restriction feature for "attachment" post types;
This commit is contained in:
@@ -105,6 +105,11 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
|
||||
if ( ! empty( $post_types[ $current_screen->id ] ) ) {
|
||||
add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 );
|
||||
add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 );
|
||||
|
||||
if ( $current_screen->id == 'attachment' ) {
|
||||
add_action( 'add_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 );
|
||||
add_action( 'edit_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,6 +185,27 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
|
||||
}
|
||||
|
||||
|
||||
function save_attachment_metabox_restrict_content( $post_id ) {
|
||||
// validate nonce
|
||||
if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) )
|
||||
return $post_id;
|
||||
|
||||
$post = get_post( $post_id );
|
||||
|
||||
// validate user
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) )
|
||||
return $post_id;
|
||||
|
||||
if ( ! empty( $_POST['um_content_restriction'] ) )
|
||||
update_post_meta( $post_id, 'um_content_restriction', $_POST['um_content_restriction'] );
|
||||
else
|
||||
delete_post_meta( $post_id, 'um_content_restriction' );
|
||||
|
||||
return $post_id;
|
||||
}
|
||||
|
||||
|
||||
function um_category_access_fields_create() {
|
||||
$data = array();
|
||||
|
||||
|
||||
@@ -318,8 +318,16 @@ if ( ! class_exists( 'Access' ) ) {
|
||||
|
||||
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
|
||||
$post->post_content = $restricted_global_message;
|
||||
|
||||
if ( 'attachment' == $post->post_type ) {
|
||||
remove_filter( 'the_content', 'prepend_attachment' );
|
||||
}
|
||||
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
|
||||
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? $restriction['_um_restrict_custom_message'] : '';
|
||||
|
||||
if ( 'attachment' == $post->post_type ) {
|
||||
remove_filter( 'the_content', 'prepend_attachment' );
|
||||
}
|
||||
}
|
||||
|
||||
$filtered_posts[] = $post;
|
||||
@@ -369,8 +377,16 @@ if ( ! class_exists( 'Access' ) ) {
|
||||
|
||||
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
|
||||
$post->post_content = $restricted_global_message;
|
||||
|
||||
if ( 'attachment' == $post->post_type ) {
|
||||
remove_filter( 'the_content', 'prepend_attachment' );
|
||||
}
|
||||
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
|
||||
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? $restriction['_um_restrict_custom_message'] : '';
|
||||
|
||||
if ( 'attachment' == $post->post_type ) {
|
||||
remove_filter( 'the_content', 'prepend_attachment' );
|
||||
}
|
||||
}
|
||||
|
||||
$filtered_posts[] = $post;
|
||||
|
||||
Reference in New Issue
Block a user