';
}
// 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 '
";
}
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 '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;
}
}
?>
/*
Plugin Name: Optreed agenda
Plugin URI: http://www.emkedouwe.nl
Description: Agenda voor alle optredens
Version: 1.0
Author: Emke Douwe
Author URI: http://www.emkedouwe.nl
License: GPL2
*/
function optreed_setup() {
add_image_size( 'agenda-thumb', 80, 80, true );
}
add_action( 'after_setup_theme', 'optreed_setup' );
if(function_exists('register_post_type'))
{
function build_optredens_post_type()
{
register_post_type('optredens',
array(
'label' => '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 '
';
}
// 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 '