'Music', 'labels' => array( 'name' => 'Muziek', 'singular_name' => 'muziek', 'add_new_item' => 'Track toevoegen', 'add_new' => 'Track toevoegen', 'all_items' => 'Alle muziek' ), 'public' => true, 'menu_position' => 30, 'supports' => array('title','editor','thumbnail') ) ); } add_action('init', 'build_musicmodule_post_type'); } /* EXTRA VELDEN */ function musicmodule_admin_init() { add_meta_box("musicmodule_itunes_meta", "iTunes", "musicmodule_iTunesPanel", "music", "side", "low"); add_meta_box("musicmodule_cover_meta", "Album cover", "musicmodule_coverPanel", "Music", "side", "low"); add_meta_box("musicmodule_audio_meta", "Audio", "musicmodule_audioPanel", "Music", "side", "low"); } add_action("admin_init", "musicmodule_admin_init"); function musicmodule_iTunesPanel() { global $post; $custom = get_post_custom($post->ID); echo '

'; echo '

'; echo '

'; echo '

'; } function musicmodule_coverPanel() { global $post; $custom = get_post_custom($post->ID); $existing_image_id = $custom['cover_image'][0]; if(is_numeric($existing_image_id) && $existing_image_id > 0) { echo '
'; $arr_existing_image = wp_get_attachment_image_src($existing_image_id, 'thumbnail'); $existing_image_url = $arr_existing_image[0]; echo '
'; echo 'verwijder afbeelding'; echo '

'; } // If there is an existing image, show it if($existing_image) { echo '
Attached Image ID: ' . $existing_image . '
'; } echo 'Voeg een afbeelding toe: '; // See if there's a status message to display $status_message = get_post_meta($post->ID,'_xxxx_attached_image_upload_feedback', true); // Show an error message if there is one if($status_message) { echo '
'; echo $status_message; echo '
'; } // Put in a hidden flag. This helps differentiate between manual saves and auto-saves (in auto-saves, the file wouldn't be passed). echo ''; } function musicmodule_audioPanel() { global $post; $custom = get_post_custom($post->ID); $existing_mp3_audio_id = $custom['audio_mp3_id'][0]; $existing_ogg_audio_id = $custom['audio_ogg_id'][0]; echo '
'; if(is_numeric($existing_mp3_audio_id) && $existing_mp3_audio_id > 0) { echo "
"; //echo 'MP3 bestand'; echo ''; echo ''; echo ''; echo '
'; echo 'verwijder bestand
'; echo "

"; } echo 'Voeg een MP3 bestand toe: '; // See if there's a status message to display $status_message = get_post_meta($post->ID,'_xxxx_attached_mp3_audio_upload_feedback', true); // Show an error message if there is one if($status_message) { echo '
'; echo $status_message; echo '
'; } echo '
'; echo '
'; if(is_numeric($existing_ogg_audio_id) && $existing_ogg_audio_id > 0) { echo "
"; //echo 'OGG bestand
'; echo ''; echo ''; echo ''; echo '
'; echo 'verwijder bestand
'; echo "

"; } echo 'Voeg een OGG bestand toe: '; // See if there's a status message to display $status_message = get_post_meta($post->ID,'_xxxx_attached_ogg_audio_upload_feedback', true); // Show an error message if there is one if($status_message) { echo '
'; echo $status_message; echo '
'; } echo '
'; } function musicmodule_save_details() { global $post; $post_type = $post->post_type; if($post_type == "music") { // Update iTunes URL if(isset($_POST["itunes_url"])) update_post_meta($post->ID, "itunes_url", $_POST["itunes_url"]); if(isset($_POST['itunes_price'])) update_post_meta($post->ID, "itunes_price", $_POST["itunes_price"]); // Update cover image if(isset($_FILES['xxxx_image']) && $_FILES['xxxx_image']['size'] > 0) { $returnArr = uploadAttachment($_FILES['xxxx_image'], null, "Album cover: " . $post->post_title); if($returnArr['attachment_id'] > 0 ) { // Before we update the post meta, trash any previously uploaded image for this post. // You might not want this behavior, depending on how you're using the uploaded images. $existing_uploaded_image = (int) get_post_meta($post->ID,'cover_image', true); if(is_numeric($existing_uploaded_image)) { wp_delete_attachment($existing_uploaded_image); } // Now, update the post meta to associate the new image with the post update_post_meta($post->ID,'cover_image',$returnArr['attachment_id']); update_post_meta($post->ID, "_xxxx_attached_image_upload_feedback", ""); } else { update_post_meta($post->ID, "_xxxx_attached_image_upload_feedback", $returnArr['error']); } } // Update audio if(isset($_FILES['xxxx_mp3_audio']) && $_FILES['xxxx_mp3_audio']['size'] > 0) { $returnArr = uploadAttachment($_FILES['xxxx_mp3_audio'], array('audio/mpeg'), "Audio: " . $post->post_title); if($returnArr['attachment_id'] > 0 ) { // Before we update the post meta, trash any previously uploaded image for this post. // You might not want this behavior, depending on how you're using the uploaded images. $existing_audio_id = (int) get_post_meta($post->ID,'audio_mp3_id', true); if(is_numeric($existing_audio_id)) { wp_delete_attachment($existing_audio_id); } // Now, update the post meta to associate the new image with the post update_post_meta($post->ID,'audio_mp3_id',$returnArr['attachment_id']); update_post_meta($post->ID, "_xxxx_attached_mp3_audio_upload_feedback", ""); } else { update_post_meta($post->ID, "_xxxx_attached_mp3_audio_upload_feedback", $returnArr['error']); } } // Update OGG audio if(isset($_FILES['xxxx_ogg_audio']) && $_FILES['xxxx_ogg_audio']['size'] > 0) { $returnArr = uploadAttachment($_FILES['xxxx_ogg_audio'], array('audio/ogg'), "Audio: " . $post->post_title); if($returnArr['attachment_id'] > 0 ) { // Before we update the post meta, trash any previously uploaded image for this post. // You might not want this behavior, depending on how you're using the uploaded images. $existing_audio_id = (int) get_post_meta($post->ID,'audio_ogg_id', true); if(is_numeric($existing_audio_id)) { wp_delete_attachment($existing_audio_id); } // Now, update the post meta to associate the new image with the post update_post_meta($post->ID,'audio_ogg_id',$returnArr['attachment_id']); update_post_meta($post->ID, "_xxxx_attached_ogg_audio_upload_feedback", ""); } else { update_post_meta($post->ID, "_xxxx_attached_ogg_audio_upload_feedback", $returnArr['error']); } } } } add_action('save_post', 'musicmodule_save_details'); // Checken hoe ervoor te zorgen dat dit maar 1 maal gedaan wordt. function musicmodule_edit_form_multipart_encoding() { echo ' enctype="multipart/form-data"'; } add_action('post_edit_form_tag', 'musicmodule_edit_form_multipart_encoding'); function uploadAttachment($post, $allowed_file_types = null, $file_title_for_media_library = null) { $returnArr = array(); if(!isset($allowed_file_types)) $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png'); // Check if there is a file upload if($post['size'] > 0 ) { // Get the type of the uploaded file. This is returned as "type/extension" $arr_file_type = wp_check_filetype(basename($post['name'])); $uploaded_file_type = $arr_file_type['type']; // If the uploaded file is the right format if(in_array($uploaded_file_type, $allowed_file_types)) { // Options array for the wp_handle_upload function. 'test_upload' => false $upload_overrides = array( 'test_form' => false ); // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array $uploaded_file = wp_handle_upload($post, $upload_overrides); // If the wp_handle_upload call returned a local path for the image if(isset($uploaded_file['file'])) { // The wp_insert_attachment function needs the literal system path, which was passed back from wp_handle_upload $file_name_and_location = $uploaded_file['file']; // Generate a title for the image that'll be used in the media library if(!isset($file_title_for_media_library)) $file_title_for_media_library = 'your title here'; // Set up options array to add this file as an attachment $attachment = array( 'post_mime_type' => $uploaded_file_type, 'post_title' => addslashes($file_title_for_media_library), 'post_content' => '', 'post_status' => 'inherit' ); // Run the wp_insert_attachment function. This adds the file to the media library and generates the thumbnails. If you wanted to attch this image to a post, you could pass the post id as a third param and it'd magically happen. $attach_id = wp_insert_attachment( $attachment, $file_name_and_location ); require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file_name_and_location ); wp_update_attachment_metadata($attach_id, $attach_data); $returnArr['attachment_id'] = $attach_id; return $returnArr; } else { // wp_handle_upload returned some kind of error. the return does contain error details, so you can use it here if you want. $returnArr['attachment_id'] = 0; $returnArr['error'] = 'There was a problem with your upload.'; return $returnArr; } } else { // wrong file type $returnArr['attachment_id'] = 0; $returnArr['error'] = 'Not a valid file type uploaded.'; return $returnArr; } } else { // No file was passed $returnArr['attachment_id'] = 0; $returnArr['error'] = 'No file was passed.'; return $returnArr; } } ?> 'Optredens', 'labels' => array( 'name' => 'Optredens', 'singular_name' => 'Optreden', 'add_new_item' => 'Optreden toevoegen', 'add_new' => 'Optreden toevoegen', 'all_items' => 'Alle optredens' ), 'public' => true, 'menu_position' => 20, 'supports' => array('title','editor','thumbnail') ) ); } add_action('init', 'build_optredens_post_type'); } // Register the column function optreed_column_register( $columns ) { $columns = array( "cb" => "", "title" => "Title", "optreed_datum" => "Datum", "date" => "Publicatie datum" ); return $columns; } add_filter( 'manage_edit-optredens_columns', 'optreed_column_register' ); // Display the column content function optreed_datum_column_display( $column_name, $post_id ) { if ( 'optreed_datum' != $column_name ) return; $optreed_datum = get_post_meta($post_id, 'optreed_datum', true); if ( !$optreed_datum ) $optreed_datum = '' . __( 'undefined', 'my-plugin' ) . ''; echo date("d-M-Y", $optreed_datum); } add_action( 'manage_posts_custom_column', 'optreed_datum_column_display', 10, 2 ); // Register the column as sortable function optreed_datum_column_register_sortable( $columns ) { $columns['optreed_datum'] = 'optreed_datum'; return $columns; } add_filter( 'manage_edit-optredens_sortable_columns', 'optreed_datum_column_register_sortable' ); /* EXTRA VELDEN */ function optreed_admin_init() { add_meta_box("optreed_datum_meta", "Data", "optreed_datumPanel", "Optredens", "side", "low"); add_meta_box("optreed_afbeelding_meta", "Afbeelding", "afbeeldingPanel", "Optredens", "side", "low"); } add_action("admin_init", "optreed_admin_init"); function optreed_datumPanel() { global $post; $custom = get_post_custom($post->ID); //echo '
';
	//print_r($custom);
	//echo '
'; $datum_dag = date("j", $custom["optreed_datum"][0]); $datum_maand = date("n", $custom["optreed_datum"][0]); $datum_jaar = date("Y", $custom["optreed_datum"][0]); echo ''; echo ''; echo ''; echo ''; $tijd_start = $custom["optreed_tijd_start"][0]; $tijd_eind = $custom["optreed_tijd_eind"][0]; echo ''; $locatie = $custom["locatie"][0]; echo ''; echo '
- '; echo ' - '; $huidig_jaar = date("Y"); echo '
'; echo ' tot '; echo '
'; echo '
'; } function afbeeldingPanel($post) { $existing_image_id = get_post_meta($post->ID,'optreden_image', true); if(is_numeric($existing_image_id)) { echo '
'; $arr_existing_image = wp_get_attachment_image_src($existing_image_id, 'thumbnail'); $existing_image_url = $arr_existing_image[0]; echo ''; echo '
'; } // If there is an existing image, show it if($existing_image) { echo '
Attached Image ID: ' . $existing_image . '
'; } echo 'Voeg een afbeelding toe: '; // See if there's a status message to display $status_message = get_post_meta($post->ID,'_xxxx_attached_image_upload_feedback', true); // Show an error message if there is one if($status_message) { echo '
'; echo $status_message; echo '
'; } // Put in a hidden flag. This helps differentiate between manual saves and auto-saves (in auto-saves, the file wouldn't be passed). echo ''; } function optreed_save_details() { global $post; $post_type = $post->post_type; if($post->ID) { switch($post_type) { case 'optredens': if(isset($_POST["optreed_datum_dag"]) && isset($_POST["optreed_datum_maand"]) && isset($_POST["optreed_datum_jaar"])) { $optreed_datum = mktime(0,0,0,$_POST["optreed_datum_maand"],$_POST["optreed_datum_dag"],$_POST["optreed_datum_jaar"]); update_post_meta($post->ID, "optreed_datum", $optreed_datum); } if(isset($_POST["optreed_tijd_start"])) update_post_meta($post->ID, "optreed_tijd_start", $_POST["optreed_tijd_start"]); if(isset($_POST["optreed_tijd_eind"])) update_post_meta($post->ID, "optreed_tijd_eind", $_POST["optreed_tijd_eind"]); if(isset($_POST["locatie"])) update_post_meta($post->ID, "locatie", $_POST["locatie"]); // If the upload field has a file in it if(isset($_FILES['xxxx_image']) && ($_FILES['xxxx_image']['size'] > 0)) { // Get the type of the uploaded file. This is returned as "type/extension" $arr_file_type = wp_check_filetype(basename($_FILES['xxxx_image']['name'])); $uploaded_file_type = $arr_file_type['type']; // Set an array containing a list of acceptable formats $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png'); // If the uploaded file is the right format if(in_array($uploaded_file_type, $allowed_file_types)) { // Options array for the wp_handle_upload function. 'test_upload' => false $upload_overrides = array( 'test_form' => false ); // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array $uploaded_file = wp_handle_upload($_FILES['xxxx_image'], $upload_overrides); // If the wp_handle_upload call returned a local path for the image if(isset($uploaded_file['file'])) { // The wp_insert_attachment function needs the literal system path, which was passed back from wp_handle_upload $file_name_and_location = $uploaded_file['file']; // Generate a title for the image that'll be used in the media library $file_title_for_media_library = 'your title here'; // Set up options array to add this file as an attachment $attachment = array( 'post_mime_type' => $uploaded_file_type, 'post_title' => 'Uploaded image ' . addslashes($file_title_for_media_library), 'post_content' => '', 'post_status' => 'inherit' ); // Run the wp_insert_attachment function. This adds the file to the media library and generates the thumbnails. If you wanted to attch this image to a post, you could pass the post id as a third param and it'd magically happen. $attach_id = wp_insert_attachment( $attachment, $file_name_and_location ); require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file_name_and_location ); wp_update_attachment_metadata($attach_id, $attach_data); // Before we update the post meta, trash any previously uploaded image for this post. // You might not want this behavior, depending on how you're using the uploaded images. $existing_uploaded_image = (int) get_post_meta($post_id,'_xxxx_attached_image', true); if(is_numeric($existing_uploaded_image)) { wp_delete_attachment($existing_uploaded_image); } // Now, update the post meta to associate the new image with the post update_post_meta($post->ID,'optreden_image',$attach_id); // Set the feedback flag to false, since the upload was successful $upload_feedback = false; } else { // wp_handle_upload returned some kind of error. the return does contain error details, so you can use it here if you want. $upload_feedback = 'There was a problem with your upload.'; update_post_meta($post->ID,'optreden_image',$attach_id); } } else { // wrong file type $upload_feedback = 'Please upload only image files (jpg, gif or png).'; update_post_meta($post->ID,'optreden_image',$attach_id); } } else { // No file was passed $upload_feedback = false; } // Update the post meta with any feedback update_post_meta($post->ID,'_xxxx_attached_image_upload_feedback',$upload_feedback); break; default: } } } add_action('save_post', 'optreed_save_details'); function add_edit_form_multipart_encoding() { echo ' enctype="multipart/form-data"'; } add_action('post_edit_form_tag', 'add_edit_form_multipart_encoding'); /******************************* AGENDA WIDGET ********************************/ class WP_Widget_Gigs extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'widget_gigs', 'description' => __('De aankomende optredens')); $control_ops = array('width' => 200, 'height' => 350); parent::__construct('gigs', 'Aankomende optredens', $widget_ops, $control_ops); } function widget( $args, $instance ) { extract($args); $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $posts_per_page = empty($instance['number_of_gigs']) ? '3' : $instance['number_of_gigs']; echo $before_widget; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } $query = new WP_Query( array( 'post_type' => 'optredens', 'meta_compare' => '>', 'meta_value' => time(), 'orderby' => 'meta_value_num', 'meta_key' => 'optreed_datum', 'order' => 'ASC', 'posts_per_page' => $posts_per_page )); echo '
'; while ( $query->have_posts()) { $query->the_post(); $custom = get_post_custom($post->ID); $arr_existing_image = wp_get_attachment_image_src($custom['optreden_image'][0], 'agenda-thumb'); $existing_image_url = $arr_existing_image[0]; echo '
'; $backupPhotos = getRandomPhotoArray(); if(!empty($arr_existing_image)) { echo ''; } else { $image_url = get_bloginfo('template_directory') . "/_images/agenda-items/" . next($backupPhotos); echo ''; } echo ''; echo '
' . get_the_title() . '
'; echo '

' . $custom['optreed_tijd_start'][0] . ' - ' . $custom['optreed_tijd_eind'][0] . '

'; echo '
'; } echo '
'; echo $after_widget; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $title = strip_tags($instance['title']); $number_of_gigs = strip_tags($instance['number_of_gigs']); ?>