Uploading ebooks into WooCommerce and WordPress

Up a Level

I've helped set up a number of WordPress-based commerce sites for authors. One of the first things that always gets in the way is the inability to upload MOBI or EPUB file into WooCommerce to actually set the books.

To get around this is a pretty simple process.





<?php
/*
 Plugin Name: Upload Ebooks
 Version: 0.0.0
 Author: D. Moonfire
 Description: Enables uploading ebooks into WordPress and WooCommerce.
*/

// Add in a hook to add the taxonomies and categories.
add_action('init', 'upload_ebook_init', 0);

function upload_ebook_init()
{
  // This allows up to add the MIME types that can be uploaded.
  add_filter('upload_mimes', 'upload_ebook_upload_mimes');

  // These are completely arbitrary and probably too big.
  ini_set('upload_max_size','100M');
  ini_set('post_max_size','99M');

  // Ebooks sometimes take a little longer to upload.
  ini_set('max_execution_time','300');
}

function upload_ebook_upload_mimes($mimes)
{
  $mimes = array_merge($mimes, array(
    'epub' => 'application/epub+zip',
    'mobi' => 'application/x-mobipocket-ebook'
  ));

  return $mimes;
}
?>

I hope it helps anyone who gets stuck by this. I'm sure there is already a plugin in WordPress's catalog, I just couldn't find it.

Metadata

Categories:

Programming

Tags:

WordPress

Footer

Below are various useful links within this site and to related sites (not all have been converted over to Gemini).

Now

Contact

Biography

Bibliography

Support

Fiction

Fedran

Coding

The Moonfires

Categories

Tags

Privacy

Colophon

License

Mailing List

Link


Source