Skip to content

Instantly share code, notes, and snippets.

@enqtran
Last active May 5, 2017 04:14
Show Gist options
  • Save enqtran/d91a338c40d19d538f9c92b5958edfa7 to your computer and use it in GitHub Desktop.
Save enqtran/d91a338c40d19d538f9c92b5958edfa7 to your computer and use it in GitHub Desktop.
<?php
if ( !function_exists( 'parse_query_useronly' ) ) {
function parse_query_useronly($wp_query) {
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/edit.php') !== false) {
if (!current_user_can('update_core')) {
global $current_user;
$wp_query->set('author', $current_user->id);
}
}
}
add_filter('parse_query', 'parse_query_useronly');
}
if ( !function_exists( 'users_own_attachments' ) ) {
function users_own_attachments( $wp_query_obj ) {
global $current_user, $pagenow;
if( !in_array( $pagenow, array( 'upload.php', 'admin-ajax.php' ) ) ) {
return;
}
if( !current_user_can('delete_pages') )
$wp_query_obj->set('author', $current_user->ID );
return;
}
add_action('pre_get_posts','users_own_attachments');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment