Skip to content

Instantly share code, notes, and snippets.

@moskalukigor
Last active October 24, 2018 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moskalukigor/1ab0e894247e64e4d5ec1c8dada28e1d to your computer and use it in GitHub Desktop.
Save moskalukigor/1ab0e894247e64e4d5ec1c8dada28e1d to your computer and use it in GitHub Desktop.
Show only user loaded images in ACF Gallery in frontend using acf_form | And grant user permission to upload files and change published page
<?php
$role = new WP_User( $userID );
$role->add_cap('upload_files', true);
$role->add_cap('edit_published_pages', true);
add_filter( 'posts_where', 'devplus_attachments_wpquery_where' );
function devplus_attachments_wpquery_where( $where ){
global $current_user;
if( is_user_logged_in() ){
// we spreken over een ingelogde user
if( isset( $_POST['action'] ) ){
// library query
if( $_POST['action'] == 'query-attachments' ){
$where .= ' AND post_author='.$current_user->data->ID;
}
}
}
return $where;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment