Support » Plugin: WPAdverts - Classifieds Plugin » how to change required fields to unrequired?

  • Resolved farhan905

    (@farhan905)


    i want to unrequired email and description fields, please tell me how i can do it,
    thank you,

    The page I need help with: [log in to see the link]

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

    (@gwin)

    Hi,
    you can make the Description field optional by adding the code below to your theme functions.php file, you, however, cannot make the email field optional as this will cause an error.

    
    add_filter( "adverts_form_load", "customize_adverts_add" );
    function customize_adverts_add( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
      foreach( $form["field"] as $key => $field ) {
        if( $field["name"] == "post_content" ) {
            $form["field"][$key]["validator"] = array();
        }
      }
      return $form;
    }
    
    farhan905

    (@farhan905)

    thank you Greg now Description field unrequired, but how i can do email optional? can i hide the sign In Link showing with account field or just replace this link with my own login page link?

    Plugin Author Greg Winiarski

    (@gwin)

    To make the email optional customize the code from the last message to look like this

    
    add_filter( "adverts_form_load", "customize_adverts_add" );
    function customize_adverts_add( $form ) {
      if( $form['name'] != "advert" ) {
        return $form;
      }
      foreach( $form["field"] as $key => $field ) {
        if( $field["name"] == "post_content" ) {
            $form["field"][$key]["validator"] = array();
        }
        if( $field["name"] == "adverts_email" ) {
            unset( $form["field"][$key]["validator"][0] );
        }
      }
      return $form;
    }
    

    BUT like i wrote earlier having the email field optional might cause some problems when submitting an Ad.

    To replace the “sign in” link in [adverts_add] with a link to your custom login page you can use the code below

    
    add_filter( "login_url", function( $login_url, $redirect, $force_reauth ) {
      $login_url = "https://your/custom/login/url/";
      if ( ! empty( $redirect ) ) {
        $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
      }
      if ( $force_reauth ) {
        $login_url = add_query_arg( 'reauth', '1', $login_url );
      }
      return $login_url;
    }, 10, 3 );
    

    Just replace in the code https://your/custom/login/url/ with your actual login URL.

    farhan905

    (@farhan905)

    when i put email script in function file i getting an error

    >> Your PHP code changes were rolled back due to an error on line 1034 of file wp-content/themes/oceanwp/functions.php. Please fix and try saving again.

    Cannot redeclare customize_adverts_add() (previously declared in wp-content/themes/oceanwp/functions.php:991)

    Plugin Author Greg Winiarski

    (@gwin)

    In the functions.php file, are you replacing the customize_adverts_add() function with the new version i posted in the last message or are you adding it again?

    It looks like you are adding it (instead of replacing) which causes an error.

    oh ok my mistake , thank you for help me

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to change required fields to unrequired?’ is closed to new replies.