Home Forums Plugin Support WP User Frontend Pro Bind user to taxonomy

This topic is: not resolved

This topic contains 11 replies, has 3 voices, and was last updated by  ced 4 years, 8 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #22122

    ced
    Participant
    Post count: 32

    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 ?

    #22128

    ced
    Participant
    Post count: 32

    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'
    		),
        ),
    #22173

    Tareq Hasan
    Keymaster
    Post count: 2831

    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?

    #22200

    ced
    Participant
    Post count: 32

    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' );
    #22201

    ced
    Participant
    Post count: 32

    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;
    
    }
    #22237

    Tareq Hasan
    Keymaster
    Post count: 2831

    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]

    #27582

    ced
    Participant
    Post count: 32
    This reply has been marked as private.
    #27624

    Sekander Badsha
    Member
    Post count: 2067
    This reply has been marked as private.
    #27627

    ced
    Participant
    Post count: 32
    This reply has been marked as private.
    #27631

    ced
    Participant
    Post count: 32
    This reply has been marked as private.
    #27635

    ced
    Participant
    Post count: 32
    This reply has been marked as private.
    #27640

    ced
    Participant
    Post count: 32
    This reply has been marked as private.
Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Bind user to taxonomy’ is closed to new replies.