• Resolved johndoe01

    (@johndoe01)


    Greetings, i have identified this other issue.
    When editing adverts from the backend, after I do Update, the phone field gets overriden with my User’s Phone number stored in User’s Profile and Author.
    What worsens the issue is that if i write the original phone in the field, does not have effect and the admin’s phone is set into the field. This seems a critical issue since adverts needs to be moderated and if any modification must be done by admins, the phone field might be a problem in a short term. Here is a video shoeing the issue.
    https://youtu.be/atxWB6dH7IY
    For this i have as a workaround, setting the published status from the Quick Edit option after revising the ad without saving; if there is no need to edit, we go for Quick Edit, but if the ad requires any other editing, the fact that the Poster’s phone gets overriden by admin’s might be a problem.
    I appreciate all the help you can provide.
    Thanks in advance

    • This topic was modified 3 years, 1 month ago by johndoe01.

    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)

    I cannot replicate this problem on any of my websites, do you maybe have some kind of code snippet that prefills the phone number in the [adverts_add] form with the phone number from the user profile? If you do then try disabling it as this might be causing a problem I suppose.

    Thread Starter johndoe01

    (@johndoe01)

    Actually some time ago i asked about locking email and phone fields since they must be prefilled. I don’t recall the exact snippet but i can look for it.
    I’ll let you know in a moment

    Thread Starter johndoe01

    (@johndoe01)

    OK i found what happened. The solution given on this thread
    https://www.ads-software.com/support/topic/autofill-email-and-phone-not-working/
    Was given in order to retrieve the phone for the creating ad form on frontend. But eventually got for backend, therefore, the admin’s phone gets into the actual ad.

    add_filter( "adverts_form_load", function( $form ) {
      if( $form["name"] != "advert" || is_admin() ) {
        return $form;
      }
      foreach( $form["field"] as $k => $f ) {
        /*if( $f["name"] == "adverts_phone" ) {
          $form["field"][$k]["attr"] = array( "readonly" => "readonly" );
        }*/
    	if( $f["name"] == "adverts_email" ) {
          $form["field"][$k]["attr"] = array( "readonly" => "readonly" );
        }  
      }
      return $form;
    } );
    
        
    /*
    add_filter( "adverts_form_bind", function( $form ) {
        //global $current_user;
        $user_id = get_current_user_ID();
    	//echo $user_id;
        $args = array(
        'author'         => $user_id,
        'post_type'      => 'advert-author',
        'post_status'    => array( 'publish', 'advert-hidden' ),
        'posts_per_page' => 1
    );
    $authors = get_posts( $args );
    //var_dump ($authors);	
    $profile_id = $authors[0]->ID;
    
    $profile_phone = get_post_meta( $profile_id, "user_phone", true ); 
        
      $form->set_value( "adverts_phone", $profile_phone );
      return $form;
    } );*/

    The comments are the setting i have disabled.

    Now i disabled only the phone field since the initial solution was set onto functions.php. I’ll try to see if i can retrieve the phone from the author page and set it (somehow) by default

    I won’t mark it as solved yet.

    • This reply was modified 3 years, 1 month ago by johndoe01.
    Thread Starter johndoe01

    (@johndoe01)

    I found a solution. I undid the previous setting, regaining the phone retrieval. Despite i see on the backend my user phone, the wau i had to do to retrieve the phone FROM THE ACTUAL AUTHOR is the following in the single-advert:

    $user_id = get_post( $post_id )->post_author;
        $args = array(
        'author'         =>  $user_id,
        'post_type'      => 'advert-author',
        'post_status'    => array( 'publish', 'advert-hidden' ),
        'posts_per_page' => 1
    
    $username_author = $author_id = $authors[0]->post_title;
    $username_alias = $author_id = $authors[0]->post_name;
    $username_phone	= $author_id = $authors[0]->user_phone;
    

    and then in functions.php the function that calls that segment of the form :

    function inside_contact_form( $post_id ) {    
    
        include_once ADVERTS_PATH . 'includes/class-form.php';
        include_once ADVERTS_PATH . 'includes/class-html.php';
        
        $show_form = false;
        $flash = array( "error" => array(), "info" => array());;
        $email = get_post_meta( $post_id, "adverts_email", true );
        $phone = get_post_meta( $post_id, "adverts_phone", true );
        $message = null;
        $form = new Adverts_Form( Adverts::instance()->get( "form_contact_form" ) );
        $actions_class = "adverts-field-actions";
        $buttons = array(
            array(
                "tag" => "input",
                "name" => "adverts_contact_form",
                "type" => "submit",
                "value" => __( "Send Message", "wpadverts" ),
                "class" => "adverts-button",
                "html" => null
            ),
        );
        
        if( adverts_request( "adverts_contact_form" ) ) {
            
            wp_enqueue_script( 'adverts-contact-form-scroll' );
            
            $form->bind( stripslashes_deep( $_POST ) );
            $valid = $form->validate();
            
            if( $valid ) {
                
                //Adext_Contact_Form::instance()->send_message( get_post( $post_id ), $form );
                do_action( "adext_contact_form_send", $post_id, $form );
                
                $form->bind( array() );
                
                $flash["info"][] = array(
                    "message" => __( "Your message has been sent.", "wpadverts" ),
                    "icon" => "adverts-icon-ok"
                );
                $show_form = true; 
            } else {
                $flash["error"][] = array(
                    "message" => __( "There are errors in your form.", "wpadverts" ),
                    "icon" => "adverts-icon-attention-alt"
                );
                $show_form = true; 
            }
        } else {
            
            if( get_current_user_id() > 0 ) {
                $user = wp_get_current_user();
                /* @var $user WP_User */
                
                $bind = array(
                    "message_name" => $user->display_name,
                    "message_email" => $user->user_email
                );
                
                $form->bind( $bind );
                
            }
        }
        
        ?>
    
        <div id="adverts-contact-form-scroll"></div>
        
        <?php if( adext_contact_form_get_to( $post_id ) ): ?>
    
        <div class="adverts-contact-box adverts-contact-box-toggle" <?php if($show_form): ?>style="display: block"<?php endif ?>>
    		<?php if( adverts_config( "contact_form.show_phone") == "1" && ! empty( $phone ) ): ?>
            <span class="adverts-button" style="background-color: transparent; cursor: auto">
                <?php //esc_html_e( "Phone", "wpadverts" ) ?>
    			<span class="adverts-icon-phone"></span>
                <a href="tel:<?php echo esc_html( $phone ) ?>"><?php global $username_phone;echo $username_phone; ?></a>
                
            </span>
            <?php endif; ?>
            <?php adverts_flash( $flash ) ?>
            <?php include apply_filters( "adverts_template_load", ADVERTS_PATH . 'templates/form.php' ) ?>
        </div>
        <?php endif; ?>
    
        <?php
    }

    I admit that was not the cleanest solution but it will retrieve the phone from who belongs to the post.

    Plugin Author Greg Winiarski

    (@gwin)

    H,
    thanks for the feedback, if i understand correctly then the phone number is now pulled directly from author profile when viewing the Ad details page instead of prefilling it in the [adverts_add] if so then I think this is actually cleaner solution even though the code might be more complex :).

    Thread Starter johndoe01

    (@johndoe01)

    Hi.
    Actually is a combination of both. The original code prefills main and phone when the ad is posted for first time. Then on the Ad view the phone is grabbed from author profile.

    Gee i though it was a mess for the way to grab the pieces.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Editing Adverts from Backend – Phone Field overriden’ is closed to new replies.