Page 1 of 12 12311 ... LastLast
Results 1 to 10 of 114

Thread: How to Add an extra field in the user profile and inherit them in ads

  1. #1
    dikiyforester's Avatar
    Join Date
    Oct 2011
    Location
    Russian Federation
    Posts
    2,229
    Thanks
    89
    Thanked 593 Times in 491 Posts

    Lightbulb How to Add an extra field in the user profile and inherit them in ads

    Inherit the address (and other extra fields) of the user in the ad is very useful for those users who have a lot of ads.
    This allows the user does not enter every time one and same values ​​and inherit them from their profile.

    There are two questions:
    1. How do I add additional fields in the user profile?
    2. How to inherit them?

    In this tutorial I will share my solution.
    I will create a text field 'phone _number', 'user _city', 'user _adress', 'user _office', and a drop-down list of 'user _state'.
    To avoid mistakes of the list of states will be taken from the values ​​'cp _state'.
    When filling out forms, user can leave these values, or replace with new ones.
    You can create any other fields.


    1. How do I add additional fields in the user profile

    Need to modify the file classipress\includes\theme-profile.php

    1.1 Find the array declaration '$appthemes_extended_profile_fields = array(' and replace the code:
    PHP Code:
    $appthemes_extended_profile_fields = array(
        
    'twitter_id' => array(
            
    'title'=> __('Twitter:','appthemes'),
            
    'type' => 'text',
            
    'description' => __('Enter your Twitter username without the URL.','appthemes')
        ),
        
    'facebook_id' => array(
            
    'title'=> __('Facebook:','appthemes'),
            
    'type' => 'text',
            
    'description' =>  sprintf(__("Enter your Facebook username without the URL. <br />Don't have one yet? <a target='_blank' href='%s'>Get a custom URL.</a>",'appthemes'), 'http://www.facebook.com/username/')
        ),
        
    'paypal_email' => array(
            
    'title'=> __('PayPal Email:','appthemes'),
            
    'type' => 'text',
            
    'description' =>  __('Used for purchasing ads via PayPal (if enabled).','appthemes')
        ),

        
    'active_membership_pack' => array(
            
    'title'=> __('Active Membership Pack:','appthemes'),
            
    'protected' => 'yes',
            
    'type' => 'active_membership_pack',
            
    'description' =>  __('Custom Membership Pack active for the user. Can only be changed by admins.','appthemes')
        ),
        
    'membership_expires' => array(
            
    'title'=> __('Membership Pack Expires Date:','appthemes'),
            
    'protected' => 'yes',
            
    'type' => 'date',
            
    'description' =>  __('Date for unlimited/dealer posting (if enabled). Can only be changed by admins.','appthemes')
        ),
    /////////Your's extra fields////////////
        
    'phone_number' => array(                            
            
    'title'=> 'phone number:',
            
    'type' => 'text',
            
    'description' =>  'Enter phone number'
        
    ),
        
    'user_state' => array(
            
    'title'=> 'State:',
            
    'type' => 'statedropdown',
            
    'description' =>  'Select a state'
        
    ),
        
    'user_city' => array(
            
    'title'=> 'City:',
            
    'type' => 'text',
            
    'description' =>  'Enter city'
        
    ),
        
    'user_adress' => array(
            
    'title'=> 'Adress:',
            
    'type' => 'text',
            
    'description' =>  'Enter adress'
        
    ),
        
    'user_office' => array(
            
    'title'=> 'Office:',
            
    'type' => 'text',
            
    'description' =>  'Enter office'
        
    )
    ///////////////////////////////////////////////////////
    ); 
    1.2 Find tis code:
    PHP Code:
                        case 'active_membership_pack':
                    ?>
                                    <input type="text" name="<?php echo $field_id?>" id="<?php echo $field_id?>" value="<?php esc_attr_e$the_value ); ?>" class="regular-text" size="35" <?php if(!empty($protected)) echo 'style="display: none;"'?> /><br />
                                    <input type="text" name="<?php echo $field_id?>_display" id="<?php echo $field_id?>" value="<?php esc_attr_e$the_display_value ); ?>" class="regular-text" size="35" disabled="disabled" /><br />
                                    <span class="description"><?php echo $field_values['description']; ?></span>
                    <?php
                        
    break;
    Below insert:

    PHP Code:
                        case 'statedropdown':
                        global $wpdb;
                        $regions = $wpdb->get_var( $wpdb->prepare( "SELECT field_values FROM ". $wpdb->prefix . "cp_ad_fields WHERE field_name = 'cp_state';" ) );
                        if ( $regions ) {

                    ?>
                                  <select name="<?php echo $field_id?>" id="<?php echo $field_id?>" >
                                         <option value="">-- <?php _e('Select''appthemes'?> --</option>
                                              <?php
                                              $options 
    explode','$regions);

                                              foreach ( 
    $options as $option ) {
                                                  
                                              
    ?>
                                              <option <?php if ($the_value == trim($option)) echo "selected='selected'"?> value="<?php esc_attr_e($option); ?>"><?php esc_attr_e($option); ?></option>
                                              <?php
                                              
    }
                                              
    ?>
                                    </select>
                                    <br />
                                    <span class="description"><?php echo $field_values['description']; ?></span>
                    <?php
                        
    }
                        break;

    2. Inherit fields

    2.1 Add function pt_fields_defaults () in functions.php file of your child theme

    PHP Code:
    function pt_fields_defaults($field_name,$user) {
      if (
    $user->ID){ 
        switch(
    $field_name){
        case 
    'cp_city':
            if (
    $user->user_city) return $user->user_city;
        break;
        case 
    'cp_street':
            if (
    $user->user_adress) return $user->user_adress;
        break;
        case 
    'cp_office':
            if (
    $user->user_office) return $user->user_office;
        break;
        case 
    'cp_state':
            if (
    $user->user_state) return $user->user_state;
        break;   
      
        }
      }


    Need to modify the file classipress\includes\forms\step-functions.php

    2.2 Find this code:

    PHP Code:
     function cp_formbuilder($results) {
            global 
    $wpdb;

            foreach ( 
    $results as $result ) {
            
    ?> 
    Replace:
    PHP Code:
     function cp_formbuilder($results) {
            global 
    $wpdb;
                
    $current_user wp_get_current_user();
            foreach ( 
    $results as $result ) {
    $opt pt_fields_defaults($result->field_name,$current_user);
    ?> 


    2.3 Changes the attribute 'value' for the text box

    Find:

    PHP Code:
                case 'text box':
                ?>
                    <input name="<?php esc_attr_e($result->field_name); ?>" id="<?php esc_attr_e($result->field_name); ?>" type="text" minlength="<?php if (empty($result->field_min_length)) echo '2'; else echo esc_attr($result->field_min_length); ?>" value="<?php if (isset($_POST[$result->field_name])) echo esc_attr($_POST[$result->field_name]); ?>" class="text <?php if ($result->field_req) echo 'required' ?>" />
    then
    PHP Code:
    value="<?php if (isset($_POST[$result->field_name])) echo esc_attr($_POST[$result->field_name]); ?>"
    replace:
    PHP Code:
    value="<?php if (isset($_POST[$result->field_name])) echo esc_attr($_POST[$result->field_name]); else echo esc_attr($opt);?>"


    2.4 Drop-down to be set by default by adding the tag "option" attribute selected = "selected". Selects a value from the user profile

    Find
    PHP Code:
     case 'drop-down':
                ?>

                    <select name="<?php esc_attr_e($result->field_name); ?>" id="<?php esc_attr_e($result->field_name); ?>" class="dropdownlist <?php if ($result->field_req) echo 'required' ?>">
                        <option value="">-- <?php _e('Select''appthemes'?> --</option>
                        <?php
                        $options 
    explode','$result->field_values );

                        foreach ( 
    $options as $option ) {
                        
    ?>
                            <option value="<?php esc_attr_e($option); ?>"><?php esc_attr_e($option); ?></option>
                        <?php
                        
    }
                        
    ?>
                    </select>
                    <div class="clr"></div>

                <?php
                
    break;
    then
    PHP Code:
    <option value="<?php esc_attr_e($option); ?>"><?php esc_attr_e($option); ?></option>
    replace:
    PHP Code:
    <option <?php if (trim($option) == $opt ) echo "selected='selected'"?> value="<?php esc_attr_e($option); ?>"><?php esc_attr_e($option); ?></option>

    FINALLY!!!!!!!

    OK send your questions and comments

  2. The Following 18 Users Say Thank You to dikiyforester For This Useful Post:

    bluecafe (February 6th, 2012), dbatista (March 27th, 2012), dhenz123 (January 14th, 2014), dreamrooms (April 14th, 2012), dubya (January 23rd, 2012), eaport (March 14th, 2012), einstein (February 13th, 2012), emilianoaguirre (July 11th, 2012), Fanatic (January 21st, 2012), favorigrup (January 31st, 2012), fedeogue (January 28th, 2012), kipfx (March 11th, 2012), petiscodigital (September 20th, 2012), rubencio (January 23rd, 2012), terrywil25 (August 4th, 2012), trustedsamurai (May 5th, 2012), vienna (January 17th, 2012), websitu (April 3rd, 2012)

  3. #2
    jomarkosabel's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    40,978
    Thanks
    170
    Thanked 3,407 Times in 3,278 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!
    Please help our moderating team work more efficiently by not sending us support questions via PM. You can read more about how AppThemes support works here. However, you can send a PM to follow up and remind me if I missed your support request/thread.

    Thank you and have a nice day.

  4. #3
    Amateur villem's Avatar
    Join Date
    Jan 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  5. #4
    Veteran vienna's Avatar
    Join Date
    May 2010
    Location
    Vienna, Austria
    Posts
    718
    Thanks
    19
    Thanked 177 Times in 118 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  6. #5
    dikiyforester's Avatar
    Join Date
    Oct 2011
    Location
    Russian Federation
    Posts
    2,229
    Thanks
    89
    Thanked 593 Times in 491 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  7. The Following User Says Thank You to dikiyforester For This Useful Post:

    yuki18 (January 18th, 2012)

  8. #6
    Junior Member yuki18's Avatar
    Join Date
    Jun 2011
    Location
    Japan
    Posts
    34
    Thanks
    9
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  9. #7
    dikiyforester's Avatar
    Join Date
    Oct 2011
    Location
    Russian Federation
    Posts
    2,229
    Thanks
    89
    Thanked 593 Times in 491 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  10. #8
    dikiyforester's Avatar
    Join Date
    Oct 2011
    Location
    Russian Federation
    Posts
    2,229
    Thanks
    89
    Thanked 593 Times in 491 Posts

    Only if you need the required fields in the profile!

    You must be an AppThemes customer and logged in to view this response. Join today!

  11. The Following 2 Users Say Thank You to dikiyforester For This Useful Post:

    dubya (January 23rd, 2012), emilianoaguirre (July 10th, 2012)

  12. #9
    Junior Member yuki18's Avatar
    Join Date
    Jun 2011
    Location
    Japan
    Posts
    34
    Thanks
    9
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  13. #10
    dikiyforester's Avatar
    Join Date
    Oct 2011
    Location
    Russian Federation
    Posts
    2,229
    Thanks
    89
    Thanked 593 Times in 491 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  14. The Following User Says Thank You to dikiyforester For This Useful Post:

    indeedrealty (March 23rd, 2013)

Page 1 of 12 12311 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Paypal field in user profile
    By kmaisch in forum ClassiPress General Discussion
    Replies: 8
    Last Post: April 5th, 2013, 12:47 PM
  2. Extra comment Field ( drop down list) Guys use your brain
    By hazara in forum ClassiPress General Discussion
    Replies: 1
    Last Post: October 17th, 2011, 09:54 PM
  3. Add a extra field to the search option
    By dschn1978 in forum ClassiPress General Discussion
    Replies: 1
    Last Post: October 13th, 2010, 09:32 AM