Bind user to taxonomy

This topic contains 11 reply and 3 voices, and was last updated by ced 9 years, 6 months ago
Viewing 11 Posts - 1 through 11 (of 11 total)
Author Posts
June 18, 2014 at 2:38 pm 22122
ced Hi, I use the "Bind user taxonomy" plugin wich work fine for wp admin. It binds a user to a custom taxonomy and so, let an editor user manage all the posts for a only given taxonomy. I need to make it work for your plugin by returning only the posts of a given taxonomy. Something like:
function restrict_to_tax( $postarr ) {
$user = wp_get_current_user();
$role = reset( $user->roles );
if ( $role == 'my-role' ) {
//SHOW HERE ALL THE POSTS TAGGED WITH THE TAX
}
return $postarr;
}
add_filter( 'wpuf_dashboard_query', 'restrict_to_tax' );
Second thing, I would like to add "publish" and "pending" buttons for this users to set the statut of each post. Can you help please ?
June 18, 2014 at 4:57 pm 22128
ced ced

unset( $args['author'] );
the idea is not to unset but add the taxonomy of a give custom post type from the user post (filled in the form)
with maybe something like:

$args = array(
	'posts_per_page'   => -1,
	'post_type' => 'post_type',
    'tax_query' => array(
        array(
        'taxonomy' => 'mytax',
        'field' => 'slug'
		),
    ),
June 19, 2014 at 11:24 am 22173
Tareq Hasan Tareq Hasan

As you’ve mentioned in the wpuf_dashboard_query filter, you could just pass the arguments from your 2nd post and it should be filtered. Any problem you are facing?

June 19, 2014 at 7:09 pm 22200
ced ced

Hi Tareq,

I simply can’t make it work.
I’ve tried but it doesn’t work:

function wpufe_dashboard_show_only_tax_to_referents( $args ) {
		$user = wp_get_current_user();
		$role = reset( $user->roles );

		if ( $role == 'referent' ) {
			unset( $args['author'] );
			$args = array(
				'posts_per_page'   => -1,
				'post_type' => 'myposttype',
				'tax_query' => array(
					array(
					'taxonomy' => 'mytaxonomy',
					'field' => 'slug'
					),
				)
			);
		}
	 
		return $args;
	}
	 
	add_filter( 'wpuf_dashboard_query', 'wpufe_dashboard_show_only_tax_to_referents' );
June 19, 2014 at 7:36 pm 22201
ced ced

I need to pass the binded taxonomy in $args.
Here is the function that hides the post in admin for the plugin, not realy clean but it does the job :

function butc_hideposts($posts){
    //l'amministratore può vedere sempre tutto
    if (current_user_can('administrator')) return $posts;  
    $binding_taxonomy = get_option('binduser_taxonomy');
    $bind = butc_getCategory();
    if ($bind==false) return array();
    $visible = array();
    foreach($posts as $post_id => $post) {
	$terms=get_the_terms( $post->ID, $binding_taxonomy);
	if ($terms==false) {
		// non supporta quella taxonomia o non ha binding, lo visualizzo
		$visible[] =$post;
	} else {
		// support la taxonomia, lo filtro
		$tax=array_keys($terms);
		foreach($bind as $k => $v) 
			if (in_array($v,$tax)) $visible[] = $post;
	}
    }
    return $visible;

}
June 20, 2014 at 2:06 pm 22237
Tareq Hasan Tareq Hasan

You are not providing the terms in the first snippet. Here’s what I’ve tried and works:
[php]
function wpufe_dashboard_show_only_tax_to_referents( $args ) {
$user = wp_get_current_user();
$role = reset( $user->roles );

if ( $role == ‘administrator’ ) {
unset( $args[‘author’] );
$args = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘post’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘category’,
‘field’ => ‘slug’,
‘terms’ => ‘culture’
),
)
);
}

return $args;
}

add_filter( ‘wpuf_dashboard_query’, ‘wpufe_dashboard_show_only_tax_to_referents’ );
[/php]

September 26, 2014 at 4:26 pm 27582
ced ced This reply has been marked as private.
September 27, 2014 at 6:07 pm 27624
Sekander Badsha Sekander Badsha This reply has been marked as private.
September 27, 2014 at 6:30 pm 27627
ced ced This reply has been marked as private.
September 27, 2014 at 7:50 pm 27631
ced ced This reply has been marked as private.
September 27, 2014 at 8:32 pm 27635
ced ced This reply has been marked as private.
September 28, 2014 at 12:04 am 27640
ced ced This reply has been marked as private.
Viewing 11 Posts - 1 through 11 (of 11 total)