• I have 2 option, which i would like to know out of the 2 is the best.
    But my issue is; I have purchased USERPRO which works great. The USERPRO plugin also allows me to add custom fields into the wp_usermeta which i can display in the wordpress backend for admin purpose.

    my problem is a multi-select field that has all the US states. i used both options below. All of them are returning the word “ARRAY” so i know it sees the field. Just cant get it to display right in the back end. My goal is to allow only ADMINS to edit the user profile backend, while the USERPRO handles all the front end stuff.

    OPTION 1 as a plugin

    class shw_user_meta {
    
     function shw_user_meta() {
     if ( is_admin() )
     {
     add_action('show_user_profile', array(&$this,'action_show_user_profile'));
     add_action('edit_user_profile', array(&$this,'action_show_user_profile'));
     add_action('personal_options_update', array(&$this,'action_process_option_update'));
     add_action('edit_user_profile_update', array(&$this,'action_process_option_update'));
     }
    
     }
    
     function action_show_user_profile($user)
     {
     ?>
     <h3><?php _e('EXTRA PROFILE INFORMATION') ?></h3>
    
     <table>
     <tr>
     <th><label for="member_id"><?php _e('Member ID'); ?></label></th>
     <td><input type="text" name="member_id" id="Memmber ID" value="<?php echo esc_attr(get_the_author_meta('member_id', $user->ID) ); ?>" /></td>
     <th><label for="us_states"><?php _e('US States you Service'); ?></label></th>
     <td><input type="multiple" name="US_States_Serviced[]" id="US States you Service" value="<?php echo esc_attr(get_the_author_meta('US_States_Serviced', $user->ID) ); ?>" /></td>
     <th><label for="user-registered"><?php _e('User Registered'); ?></label></th>
     <td><input type="text" name="user_registered" id="user_registered" value="<?php echo esc_attr(get_the_author_meta('user_registered', $user->ID) ); ?>" /></td>
     </tr>
     </table>
     <?php
     }
    
     function action_process_option_update($user_id)
     {
    if(isset($_POST['member_id'])){
    update_user_meta( $user_id, 'member_id', $_POST['member_id'] );
    }
    
    if(isset($_POST['US_States_Serviced'])){
    update_user_meta( $user_id, 'US_States_Serviced', $_POST['US_States_Serviced'] );
    }
    
    if(isset($_POST['user_registered'])){
    update_user_meta( $user_id, 'user_registered', $_POST['user_registered'] );
    }
     }
    }
    /* Initialise outselves */
    add_action('plugins_loaded', create_function('','global $shw_user_meta_instance; $shw_user_meta_instance = new shw_user_meta();'));
    ?>

    OPTION 2 inserted into the function.php of the theme.

    add_action( 'show_user_profile', 'extra_user_profile_fields' );
    add_action( 'edit_user_profile', 'extra_user_profile_fields' );
    
    function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>
    
    <table class="form-table">
    <tr>
    <th><label for="US_States_Serviced"><?php _e("US State You Service"); ?></label></th>
    <td>
    <input type="text" name="US_States_Serviced" id="US_States_Serviced" value="<?php echo esc_attr( get_the_author_meta( 'US_States_Serviced', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter all states serviced."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="city"><?php _e("City"); ?></label></th>
    <td>
    <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your city."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="province"><?php _e("Province"); ?></label></th>
    <td>
    <input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your province."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="postalcode"><?php _e("Postal Code"); ?></label></th>
    <td>
    <input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your postal code."); ?></span>
    </td>
    </tr>
    </table>

  • The topic ‘Array showing up in my extra meta fields’ is closed to new replies.