Title: Feature Request &#8211; Toggle contact form
Last modified: January 29, 2019

---

# Feature Request – Toggle contact form

 *  Resolved [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/)
 * I am enjoying working with this plugin. The documentation and snippets are great.
 * I was wondering if it would be possible to enable individual users to select 
   whether or not they wish to use the contact form?
 * Even with captcha, some people would prefer not to use it. Limiting it to logged
   in users only is not really viable for most advertisers.
 * Thanks in advance.

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11147549)
 * Hi,
    it is possible to make the contact form visible for logged in users only,
   enabling/disabling it on per Ad or user basis is not really possible (at least
   not without some more complex custom programming) i am afraid.
 * If you would like to show the contact options to logged in users only then you
   can add the code below in your theme functions.php file
 *     ```
       add_action( "init", "my_toggle_contact", 1000 );
       function my_toggle_contact() {
           if( get_current_user_id() == 0 ) {
               remove_action('adverts_tpl_single_bottom', 'adverts_single_contact_information');
               remove_action('adverts_tpl_single_bottom', 'adext_contact_form');
           } 
       }
       ```
   
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11147564)
 * Hi Greg,
 * Yes I had seen the post on that. That’s why I posted it as a feature request.
 * Was worth a shot. Maybe something for a future version?
 * Thanks.
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11147608)
 * I am actually planning to refine how the contact options on Ad details page will
   show to give administrator and users more control over it, but right now i am
   afraid i cannot really tell when this feature will be available.
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11147628)
 * That’s promising to hear.
 * Maybe you could make it a paid addon to justify the extra work?
 * I look forward to seeing how it evolves.
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11148405)
 * I was just thinking about possible ways to achieve this, and thought about using
   custom roles.
 * Would it be possible to create a filter for my child functions.php file that 
   would disable the form for a new role called “private” for instance?
 * I don’t know enough about coding to create my own filter, only using someone 
   else’s.
 * Posting it here would also help others in the future.
 * Thanks.
 *  [webam](https://wordpress.org/support/users/webam/)
 * (@webam)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11148821)
 * I add myself to the discussion to ask for something. That of hiding the contacts
   to unregistered users is interesting, but I would like to insert a message saying“
   to view the seller’s contacts and you must log in or register.” Register or log
   in (with redirect link) ”
 * It can be done?
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11149684)
 * Getting closer, but can’t get it to work.
 * Take original test:
 * `if( get_current_user_id() == 0 ) {`
 * And need to add:
 * `if( current_user_can( 'edit_posts' ) ) {`
 * But don’t know how to word it without crashing the site.
 * Even simply replacing the test with my new one causes a crash.
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11149988)
 * Okay, I got it to work using an older function:
 *     ```
       add_action( "init", "my_contact_form_init", 1000 );
       function my_contact_form_init() {
       if ( !current_user_can( 'edit_posts' ) ) {
               remove_all_actions( "adverts_tpl_single_bottom" );
           }
       }
       ```
   
 * This only allows my “private” user, a contributor, to see the form.
 * Not sure that’s what I was setting out to do. It’s 2am here and my brain is fried.
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11151560)
 * Okay, in the cold light of day, this is not what I want. Instead of that user
   being the only one to see the form, I need it to be the only user that doesn’t**
   display** the form.
 * So a user-role based filter is not the answer.
 * It needs to be linked to the advert **owner** instead, so that guests or other
   logged in users cannot see the form for that owner.
 * Too hard for me 🙂
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11152178)
 * If you have a Custom Fields extension or can add a new field to [adverts_add]
   using Forms API and enabling/disabling the contact options on per Ad basis would
   work for you then you can use the code below to do that
 *     ```
       add_action( "init", "my_contact_form_init", 1000 );
       function my_contact_form_init() {
         if ( ! is_singular( 'advert' ) ) {
           return;
         }
   
         $post = get_post( get_the_ID() );
   
         if ( get_post_meta( $post->ID, "show_contact_options", true ) != "1" ) {
             remove_all_actions( "adverts_tpl_single_bottom" );
             add_action( "adverts_tpl_single_bottom", "contact_form_disabled_info" );
         } 
       }
       function contact_form_disabled_info() {
         echo "User disabled contact form options for this Ad.";
       }
       ```
   
 * Additionally, if you have the Authors extension you can add the “show_contact_options”
   custom field to the Author form and then it will be possible to enable/disable
   the contact options on per user basis (instead of per Ad basis).
 * You would just need to change the line
 *     ```
       $post = get_post( get_the_ID() );
       ```
   
 * to
 *     ```
       $post_author_id = get_post_field( 'post_author', get_the_ID() );
       $args = array(
         'author'         =>  $post_author_id,
         'post_type'      => 'advert-author',
         'posts_per_page' => 1,
         'post_status'    => array( 'publish', 'advert-hidden' ),
       );
       $author_page = get_posts( $args );
       $post = $author_page[0];
       ```
   
 *  Thread Starter [Graham](https://wordpress.org/support/users/sandgroper/)
 * (@sandgroper)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11153792)
 * Hi Greg,
 * I have done away with the contact form altogether and decided to assign advertisers
   an email forwarding address instead.
 * I then created a custom text field called Contact Email by following your documentation
   example.
 * That gives users an address to use, but is not clickable for spambots. It also
   means they can leave it empty if they don’t want to be contacted by email.
 * Thanks for your help and I hope your suggestions help other people.
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11156409)
 * Ok great, i am marking this thread as resolved then.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Feature Request – Toggle contact form’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

 * 12 replies
 * 3 participants
 * Last reply from: [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/feature-request-toggle-contact-form/#post-11156409)
 * Status: resolved