• Resolved befeleme

    (@befeleme)


    Hi,
    please!
    My problem is:

    User with acount (he has username) is logged and want post new ad. In add form default displayed field Contact person with Username.
    User can change username for other name.

    My idea is: Not allow to users change his your username and only display it. Its any easy way for this?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you can make the Contact Person field in the [adverts_add] form read-only by adding the code below in your theme functions.php file (or even better by creating a new blank plugin and pasting it there https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/)

    
    add_filter( "adverts_form_load", "make_readonly_name" );
    function make_readonly_name( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
      if( is_admin() ) {
        return $form;
      }
      foreach( $form["field"] as $key => $field ) {
        if( in_array($field["name"], array( "adverts_person" ) ) ) {
            $form["field"][$key]["attr"] = array( "readonly" => "readonly" );
        }
      }
      return $form;
    }
    
    Thread Starter befeleme

    (@befeleme)

    Hi Greg,

    thank you very much. Great support for your plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Not allow to users change his your username’ is closed to new replies.