ID, '_wplt_file_url', true ); $file_size = get_post_meta( $post->ID, '_wplt_file_size', true ); global $post; $plupload_init = array( 'runtimes' => 'html5, silverlight, flash, html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-container', 'file_data_name' => 'async-upload', 'multiple_queues' => false, 'max_file_size' => wp_max_upload_size() . 'b', 'url' => admin_url( 'admin-ajax.php' ), 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), 'filters' => array( array( 'title' => __( 'Allowed Files' ), 'extensions' => '*' ) ), 'multipart' => true, 'urlstream_upload' => true, // additional post data to send to our ajax hook 'multipart_params' => array( '_ajax_nonce' => wp_create_nonce( 'wplt_download_upload' ), 'action' => 'wplt_download_upload', 'post_id' => $post->ID ), ); // Pass to plupload $plupload_init = apply_filters( 'plupload_init', $plupload_init ); ?>
0 ) { // Set upload dir add_filter( 'upload_dir', 'wplt_set_upload_dir' ); // Upload the file $file = wp_handle_upload( $_FILES['async-upload'], array( 'test_form' => false ) ); // Check for success if( isset( $file['file'] ) ) { // Post ID $post_id = $_REQUEST['post_id']; // Add/update post meta update_post_meta( $post_id, '_wplt_file_url', $file['url'] ); update_post_meta( $post_id, '_wplt_file_size', $_FILES['async-upload']['size'] ); update_post_meta( $post_id, '_wplt_file_type', $file['type'] ); } } } add_action( 'save_post', 'wplt_meta_box_file_save' ); /** * Render stats meta box * * @param object $post current post object * * @return void */ function wplt_meta_box_stats( $post ) { $file_count = get_post_meta( $post->ID, '_wplt_file_count', true ); ?>