Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2012 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2120588 to your computer and use it in GitHub Desktop.
Save anonymous/2120588 to your computer and use it in GitHub Desktop.
<?php
$cfs = array(
'emob_metabox_vendor_first_name' => 'Contact First Name',
'emob_metabox_vendor_last_name' => 'Contact Last Name',
'emob_metabox_vendor_position' => 'Position/Title',
'emob_metabox_vendor_address' => 'Contact Address',
'emob_metabox_vendor_address_2' => 'Contact Address 2',
'emob_metabox_vendor_city' => 'City',
'emob_metabox_vendor_state' => 'State',
'emob_metabox_vendor_zip' => 'Zip',
'emob_metabox_vendor_phone' => 'Contact Phone Number',
'emob_metabox_vendor_email' => 'Contact Email Address',
'emob_metabox_vendor_twitter' => 'Twitter',
'emob_metabox_vendor_linkedin' => 'LinkedIn',
'emob_metabox_vendor_website' => 'Website URL',
'emob_metabox_associated_users' => 'Associated Emobsters',
);
foreach( $cfs as $cfk => $cfv )
{
$sk = str_replace( 'emob_metabox_', '', $cfk );
echo '<label for="' . $cfk . '">' . $cfv . '<label>';
echo '<p>';
switch( $sk )
{
case 'associated_users' :
$associated_users = json_decode( get_post_meta( $post_id, $sk, true) );
echo '<input type="hidden" name="' . $cfk . '" id="' . $cfk . '" value="' . $associated_users . '" class="vendor_metabox_field vendor_metabox_input_field" />';
$linked_users = array();
if( is_array( $associated_users ) && $associated_users )
{
foreach( $associated_users as $user_id )
{
$user = new WP_User( $user_id );
$linked_users[] = '<a href="' . bp_core_get_user_domain( $user_id ) . '">' . $user->user_nicename . '</a>';
}
echo implode( ', ', $linked_users );
}
break;
case 'vendor_state' :
echo '<select name="' . $cfk . '" id="' . $cfk . '" class="vendor_metabox_field vendor_metabox_select_field">';
$state_list = array('AL'=>"Alabama",
'AK'=>"Alaska",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'CA'=>"California",
'CO'=>"Colorado",
'CT'=>"Connecticut",
'DE'=>"Delaware",
'DC'=>"District Of Columbia",
'FL'=>"Florida",
'GA'=>"Georgia",
'HI'=>"Hawaii",
'ID'=>"Idaho",
'IL'=>"Illinois",
'IN'=>"Indiana",
'IA'=>"Iowa",
'KS'=>"Kansas",
'KY'=>"Kentucky",
'LA'=>"Louisiana",
'ME'=>"Maine",
'MD'=>"Maryland",
'MA'=>"Massachusetts",
'MI'=>"Michigan",
'MN'=>"Minnesota",
'MS'=>"Mississippi",
'MO'=>"Missouri",
'MT'=>"Montana",
'NE'=>"Nebraska",
'NV'=>"Nevada",
'NH'=>"New Hampshire",
'NJ'=>"New Jersey",
'NM'=>"New Mexico",
'NY'=>"New York",
'NC'=>"North Carolina",
'ND'=>"North Dakota",
'OH'=>"Ohio",
'OK'=>"Oklahoma",
'OR'=>"Oregon",
'PA'=>"Pennsylvania",
'RI'=>"Rhode Island",
'SC'=>"South Carolina",
'SD'=>"South Dakota",
'TN'=>"Tennessee",
'TX'=>"Texas",
'UT'=>"Utah",
'VT'=>"Vermont",
'VA'=>"Virginia",
'WA'=>"Washington",
'WV'=>"West Virginia",
'WI'=>"Wisconsin",
'WY'=>"Wyoming");
foreach( $state_list as $abbr => $state_name )
{
echo ( strtolower( $abbr ) == strtolower( get_post_meta( $post_id, $sk, true ) ) ) ? '<option value="' . strtolower( $abbr ) . '" selected="selected">' . $state_name . '</option>' : '<option value="' . strtolower( $abbr ) . '">' . $state_name . '</option>';
}
echo '</select>';
break;
default :
echo '<input type="text" id="' . $cfk . '" name="' . $cfk . '" value="' . get_post_meta( $post_id, $sk, true ) . '" class="vendor_metabox_field vendor_metabox_input_field" />';
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment