WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
showing fields only to logged users (3 posts)

  1. shemesh
    Member
    Posted 1 year ago #

    hi,
    i want to show/hide fields for users that are logged in/out.
    i know i can edit the code, for example i've added this to modules/submit.php:

    if ( !is_user_logged_in() ) {
        return;
    }

    inside wpcf7_submit_shortcode_handler() just before return $html;

    but this will be overwritten with a new cf7 update.
    but is it the best way??

    maybe there is some short-code attribute to show/hide according to user logged or not?

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 1 year ago #

    Most theme add a class like "logged-in" to the body element when logged-in user is accessing. So how about adding this style to theme's stylesheet?

    body.logged-in input.wpcf7-submit {
        display: none;
    }

    You can change it as you like.

  3. shemesh
    Member
    Posted 1 year ago #

    nice! this css works to show the submit button only for logged users:

    input.wpcf7-submit {
        display: none;
    }
    body.logged-in input.wpcf7-submit {
        display: inline;
    }

    but...
    1) once again - if i update the theme files i will loose this functionality.
    2) what if i have several field elements, with the same class, but want to make only some of them available according to logged user? sure, i can do this by adding id, but this would make me very much coupled.

    would be nice (and easy to implement) if each cf7 field will get an option: "show only to logged users".
    or maybe a step further: filter by permission.

    is there a way to write cf7 plugin that does that?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.