* @date 11 November 2012 */ add_theme_support('post-thumbnails'); /** Twitter */ function add_twitter_contactmethod( $contactmethods ) { // Add Twitter if ( !isset( $contactmethods['twitter'] ) ) $contactmethods['twitter'] = 'Twitter @example - do not include @'; // Remove Yahoo IM if ( isset( $contactmethods['yim'] ) ) unset( $contactmethods['yim'] ); // Remove AIM if ( isset( $contactmethods['aim'] ) ) unset( $contactmethods['aim'] ); // Remove Jabber if ( isset( $contactmethods['jabber'] ) ) unset( $contactmethods['jabber'] ); return $contactmethods; } add_filter( 'user_contactmethods', 'add_twitter_contactmethod', 10, 1 ); /** * Upload header image */ if (is_admin()) { function add_post_enctype() { echo ""; } add_action('admin_head', 'add_post_enctype'); } $new_meta_boxes = array( "start" => array( "name" => "start", "type" => "start", ), //Banner Custom Fields "banner" => array( "name" => "big_banner", "std" => "", "type" => "image", "title" => "Cover Image", ), "end" => array( "name" => "end", "type" => "end" ), ); function new_meta_boxes() { global $post, $new_meta_boxes; foreach($new_meta_boxes as $meta_box) { $meta_box_value = get_post_meta($post->ID, $meta_box['name'].'', true); if($meta_box_value == "") { $meta_box_value = $meta_box['std']; } echo ''; if($meta_box['type'] == "start") { echo "
"; } else if($meta_box['type'] == "end") { echo '
'; } else if($meta_box['type'] == "image") { echo $meta_box['before']; echo '
'; if ($meta_box_value) { echo ''; } echo'

'; echo'
'; echo'Upload image here

'; echo'

'; echo'
'; echo'or add a URL to the image here

'; echo '
'; } else if($meta_box['type'] == "text") { echo $meta_box['before']; echo'

'; echo'
'; echo''.$meta_box['description'].'

'; } else if($meta_box['type'] == "checkbox") { echo $meta_box['before']; echo'

'; if ($meta_box_value) { $checked = "checked=\"checked\""; } else { $checked = ""; } echo '
'; echo ''.$meta_box['description'].'

'; } else if($meta_box['type'] == "textarea") { echo $meta_box['before']; echo'

'; echo'
'; echo''.$meta_box['description'].'

'; } } } function create_meta_box() { global $theme_name; if (function_exists('add_meta_box')) { add_meta_box('new-meta-boxes', 'Cover Image', 'new_meta_boxes', 'post', 'normal', 'high'); } } function save_postdata( $post_id ) { global $post, $new_meta_boxes; $post_id = wp_is_post_revision($post_id); foreach($new_meta_boxes as $meta_box) { if ( ! wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) { return $post_id; } if ('page' == $_POST['post_type']) { if ( ! current_user_can( 'edit_page', $post_id )) { return $post_id; } } else { if ( ! current_user_can( 'edit_post', $post_id )) { return $post_id; } } $imageuploadlocation = ""; $metaboxname = ""; $metaboxname_upload = ""; if($meta_box['type'] == 'image') { $metaboxname = $meta_box['name']; $metaboxname_upload = $metaboxname.'_upload'; if ($_FILES[$metaboxname_upload]['name'] != "") { $overrides = array( 'test_form' => false); $imagefile = wp_handle_upload($_FILES[$metaboxname_upload], $overrides); $imageuploadlocation = $imagefile['url']; delete_post_meta($post_id, $metaboxname, get_post_meta($post_id, $metaboxname, true)); add_post_meta($post_id, $metaboxname, $imageuploadlocation, true); } else { $imageuploadlocation = get_post_meta($post_id, $metaboxname, true); delete_post_meta($post_id, $metaboxname, get_post_meta($post_id, $metaboxname, true)); add_post_meta($post_id, $metaboxname, $_POST[$metaboxname], true); } } else { $data = $_POST[$meta_box['name'].'']; if (get_post_meta($post_id, $meta_box['name'].'') == "") { add_post_meta($post_id, $meta_box['name'].'', $data, true); } elseif($data != get_post_meta($post_id, $meta_box['name'].'', true)) { update_post_meta($post_id, $meta_box['name'].'', $data); } elseif($data == "") { delete_post_meta($post_id, $meta_box['name'].'', get_post_meta($post_id, $meta_box['name'].'', true)); } } } } add_action('admin_menu', 'create_meta_box'); add_action('save_post', 'save_postdata', 12); 戼⁲㸯㰊㹢慗湲湩㱧戯㨾†慃湮瑯洠摯晩⁹敨摡牥椠普牯慭楴湯ⴠ栠慥敤獲愠牬慥祤猠湥⁴祢⠠畯灴瑵猠慴瑲摥愠⁴栯浯⽥慷⽲異汢捩桟浴⽬灷挭湯整瑮琯敨敭⽳慷⽲畦据楴湯⹳桰㩰㘲⤴椠戼⼾潨敭眯牡瀯扵楬彣瑨汭眯⵰潣瑮湥⽴桴浥獥眯牡椯摮硥瀮灨⼼㹢漠楬敮㰠㹢㰴戯㰾牢⼠ਾ