WORDPRESS User specific access via ID to specific contact forms CFDB7

Solution:

It looks like Contact Forms 7 is your plugin for the forms portion while CFDB7 is an accompanying plugin that writes the form submissions to the WP database.

Get the Form ID

There are a couple ways to get the form ID. It looks like the easiest path is to look at the shortcode that the CF7 creates. You can see it in their documentation here. The code is something like 

Error: Contact form not found.

 with id being the form ID (4 in this case).

Show the Right Form to the Right Person

Assuming you know the user ids and the related form ids you want to show them, you could write a very simple shortcode plugin to display the right forms for the right people. It’d be something like this untested code below.

//[user-form-display]
function user_form_display( $atts ){
     $user_id = get_current_user_id();  
     if ($user_id == 2){
       echo do_shortcode('

Error: Contact form not found.

'
); } else if ($user_id == 4){ echo do_shortcode('

Error: Contact form not found.

'
); } } add_shortcode( 'user-form-display', 'user_form_display' );

You could then put the shortcode in the regular post field and not edit either the CF7 plugin nor mess with the theme files.

You could also make the shortcode fancier and tie user ids to form ids directly in the shortcode arguments. That would take a bit more effort but is probably worth it.

Getting the Form Data You could modify the $args to include form ids based on an association with a user id or multiple user ids. The form ids should be a field in that table. That’s the example indicated below.

Alternately you could modify how the information is returned based on the same relationships by setting up the if/then statements in the $data_value lines. This is easier probably but messier in the long run.

function specfic_table_data()
    {
        global $wpdb;

        $user_id = get_current_user_id();

        if($user_id == 1){
          $form_ids = array(4,6);//only returns forms with id 4 and 6 when it's user w id 1
        }         

        $cfdb         = apply_filters( 'cfdb7_database', $wpdb );
        $data         = array();
        $table_name   = $cfdb->prefix.'db7_forms';


        $args = array(
            'post_type'=> 'wpcf7_contact_form',
            'order'    => 'ASC',
            'posts_per_page' => 10,
            'post__in'      => $form_ids,           
        );

        $the_query = new WP_Query( $args );

        while ( $the_query->have_posts() ) : $the_query->the_post();
            $form_post_id = get_the_id();
            $totalItems   = $cfdb->get_var("SELECT COUNT(*) FROM $table_name WHERE form_post_id = $form_post_id");
            $title = get_the_title();
            $link  = "<a class='row-title' href=admin.php?page=cfdb7-list.php&fid=$form_post_id>%s</a>";
            $data_value['name']  = sprintf( $link, $title );
            $data_value['count'] = sprintf( $link, $totalItems );
            $data[] = $data_value;
        endwhile;