PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Multisite - Auto load form, but not create new

  1. I'm playing around with WordPress network. I would like to import a 'contact' form for all new blogs set up. The admin should be able to view and edit entries, but not be able to create new forms.

    Is this possible?

    Posted 7 years ago on Wednesday November 23, 2011 | Permalink
  2. Sorry, you caught us outside of normal support hours, and on a US Holiday today. Thanks for your patience.

    If you use a plugin like Members by Justin Tadlock, you can easily remove capabilities from specific roles, or add a new role. There are separate permissions for create_form and view_entries (and lots of other ones too) so you should be able to do what you want. Here's a screenshot of the permissions in my installation. http://min.us/m9k2NT5Dl

    However, I have not tried this with multi-site, so I have no idea how it will work.

    Posted 7 years ago on Friday November 25, 2011 | Permalink
  3. Might be fun if you gave it a go?

    In the mean time, can you supply a snippet of code that will remove 'gravityforms_create_form' from a user's caps (not role). And confirm that that will deny access to gf_new_form admin page?

    Posted 7 years ago on Friday July 6, 2012 | Permalink
  4. David Peralty
    Administrator

    Sorry, can you give more information regarding why the previous solution didn't work for you?

    Posted 7 years ago on Friday July 6, 2012 | Permalink
  5. David Peralty
    Administrator

    Here are the details regarding editing caps.
    http://codex.wordpress.org/Function_Reference/add_cap

    Posted 7 years ago on Friday July 6, 2012 | Permalink
  6. Here is a snippet that doesn't work:

    add_action( 'admin_init', 'do_cap_stuff' );
    function do_cap_stuff(){
      global $user_ID;
      if( !is_super_admin() ) :
        $user = new WP_User( $user_ID );
        $user->add_cap( 'gravityforms_create_form', false );
      endif;
    }
    Posted 7 years ago on Thursday July 12, 2012 | Permalink
  7. Can you echo $user_ID and see if it contains the actual User ID? I don't recognize that variable name as a built in global in WordPress. How are you getting the user ID into this function?

    Posted 7 years ago on Thursday July 12, 2012 | Permalink
  8. http://codex.wordpress.org/Function_Reference/get_currentuserinfo

    Also places the individual attributes into the following separate global variables:
    
    $user_login
    $user_ID
    $user_email

    Yes I have checked that $user_ID exists.

    Posted 7 years ago on Thursday July 12, 2012 | Permalink
  9. Can't believe I feel I have to say this, but no this doesn't work either:

    add_action( 'admin_init', 'do_cap_stuff' );
    function do_cap_stuff(){
      global $user_ID;
      get_currentuserinfo();
      if( !is_super_admin() ) :
        $user = new WP_User( $user_ID );
        $user->add_cap( 'gravityforms_create_form', false );
      endif;
    }
    Posted 7 years ago on Thursday July 12, 2012 | Permalink
  10. David Peralty
    Administrator

    What if you changed it to :

    add_action( 'admin_init', 'do_cap_stuff' );
    function do_cap_stuff(){
      global $current_user;
      get_currentuserinfo();
      if( !is_super_admin() ) :
        $user = new WP_User( $current_user->ID );
        $user->add_cap( 'gravityforms_create_form', false );
      endif;
    }
    Posted 7 years ago on Thursday July 12, 2012 | Permalink
  11. No, that's pretty much the same as the snippets I write above. It doesn't work. I haven't checked capabilities internally, but the user can still create new forms.

    if( !is_super_admin() ) :
        $user = new WP_User( $current_user->ID );
        $res = $user->add_cap( 'gravityforms_create_form', false );
        error_log( "UID: {$current_user->ID}: ".print_r($res,1) );
      endif;

    Logs this: UID: 14:

    Posted 7 years ago on Thursday July 12, 2012 | Permalink
  12. Sorry about this comment Miramedia. I just hadn't seen it used before, I didn't doubt it existed and just wanted to make sure we have the user ID. If we have the user ID then we must have a problem with the capabilities.

    Are the capabilities for that user actually being changed? If so, then maybe the wrong capability is being removed and that's why the user still can't create forms?

    Posted 7 years ago on Friday July 13, 2012 | Permalink
  13. You can see which capability I am trying to remove. It's in the code: gravityforms_create_form.

    Is there a way to remove the capability to create forms, but leave all other caps?

    Posted 6 years ago on Wednesday March 6, 2013 | Permalink
  14. Instead of this:

    [php]
    $user = new WP_User( $current_user->ID );
    $res = $user->add_cap( 'gravityforms_create_form', false );

    Can you try:

    [php]
    $user = new WP_User( $current_user->ID );
    $user->remove_cap( 'gravityforms_create_form' );

    http://codex.wordpress.org/Function_Reference/remove_cap

    Posted 6 years ago on Tuesday March 12, 2013 | Permalink