WordPress2024-03-28T17:39:17Zhttps://d.moonfire.us/tags/wordpress/D. MoonfireCreative Commons Attribution-NonCommercial-ShareAlike 4.0 InternationalUploading ebooks into WooCommerce and WordPress2014-07-04T05:00:00Zhttps://d.moonfire.us/blog/2014/07/04/enabling-epub-and-mobi-uploads-to-wordpress-and-woocommerce/How to enable MOBI and EPUB uploads into WooCommerce.<p>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.</p>
<p>To get around this is a pretty simple process.</p>
<ol>
<li>In <code>wp-content/plugins</code>, create a directory like <code>local-upload-ebooks</code>.</li>
<li>Create <code>local-upload-ebooks/local-upload-eboooks.php</code> and edit it.</li>
<li>Put the text below into it and save it.</li>
<li>Go into your Plugin Manager and enable the plugin.</li>
</ol>
<pre><code class="language-php"><?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;
}
?>
</code></pre>
<p>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.</p>
The drawbacks of WordPress2014-05-21T05:00:00Zhttps://d.moonfire.us/blog/2014/05/21/the-drawbacks-of-wordpress/WordPress works well for many people, but now that I have been targeted by automated scripts trying to get in, maybe it's time to consider something else?<p>About two weeks ago, a bunch of script kiddies decided to point their automated tools at my WordPress site. Fortunately, I have <a href="https://wordpress.org/plugins/better-wp-security/">iThemes Security</a> which locks out accounts. But, they figured out my original login and just kept hammering it which caused my account to lock out for another hour until it was going to be seven days before I could log in again.</p>
<p>Even after fixing that, I'm still getting constant attempts to break into the systems from a stunning number of different sites. Which kind of annoys me. Because WordPress is so easy, it is easy to write a tool to try logging into the account and then just keep hammering it until something break. It doesn't matter that my passwords look like line noise, they are still trying.</p>
<h1>Trying things out</h1>
<p>One of the things I did with the <a href="http://sand-and-blood.fedran.com/">Sand and Blood</a> and <a href="http://fedran.com/">Fedran</a> websites was to try a <a href="http://jekyllrb.com/">Jekyll-based</a> site. Actually, I'm creating a <a href="https://github.com/dmoonfire/mfgames-jeykll-website">hodgepodge setup</a> that uses Perl, Python, Jekyll, and a number of other things that work the way I like to.</p>
<p>I like static sites. It is really hard to break into an HTML page. Plus they are <em>really</em> fast. Since I'm on shared hosting, my WordPress sites are getting slow the last few months.</p>
<h1>Drawbacks</h1>
<p>The drawbacks is that I have to generate them somewhere. My laptop works well enough, but it is one additional step above just logging into a site and "doing things." It also won't work for SMWM and others who don't need to know the little details.</p>
<h1>Plans</h1>
<p>I'm tried of the attempts to break in, but I can't get rid of it entirely. So, I'm going to change most of the sites to a static one and just leave the dynamic sites for those who need it.</p>
<p>Not sure when I'm going to do this, but I'm getting tired of the emails.</p>
WordPress mass uploading2012-07-12T05:00:00Zhttps://d.moonfire.us/blog/2012/07/12/wordpress-mass-uploading/<p>I'm a lazy person. I can't really describe it any other way. I don't like doing the same thing over and over again. It is tedious and my time is better spent on other things. However, I'm always changing. It might be a new technology, file format, or organization. For example, in the process of <a href="http://d.moonfire.us/blog/2012/05/01/an-obsession-with-data-a-k-a-writers-write">analyzing how many words I've written over the years</a> I touched on the problems of repeatedly changing file formats . I want to keep them consistent instead of in a ton of different formats. My previous analysis would have been a lot harder if I had five different formats. And I'm not going to change this part of me. If I decided to Creole is a horrible format to write in (actually, I want to move to Markdown since that is the most popular format right now), I will translate every story, novel, and chapter to the new format.</p>
<p><em>The only reason I haven't switched over is because I'm in the middle of a serial and I thought it would be cool to show the progression of the serial over time and I don't want to worry about renames when I do it.</em></p>
<p>Changing websites is one of those things. With the DokuWiki site, I had the Creole parser plugin so I just made a couple changes and uploaded them directly into the file host. This is actually one of DokuWiki's strengths. When I had a new story or chapter, all I had to do was <code>scp</code> the file up and visit the site. It was there and it took no effort.</p>
<p>Using WordPress is a much harder. I can't just <code>scp</code> the files up and have them show up. I need to go through the website (or at least the API) and create the page. And then copy/paste it in and change the formatting (I rarely use italics but I do use them). And that is fine for the 5-6 stories I have on <a href="http://d.moonfire.us/">http://d.moonfire.us/</a>. For the other byline, I would have hundreds of files to upload.</p>
<p>And I'm too lazy to do that.</p>
<p><!--more-->Fortunately, I had a lot of things working for me</p>
<ul>
<li>WordPress has a <a href="http://codex.wordpress.org/XML-RPC_Support">XML-RPC API</a> which lets me create and update pages. It also supports custom taxonomies such as the <a href="http://d.moonfire.us/blog/2012/07/09/wordpress-custom-taxonomies">ones I use</a>.</li>
<li>My Git repository is organized like my website.</li>
<li>I have a build process (hacky at the moment) that takes my .txt, .md, and .creole files and puts them into a properly organized <code>build/</code> directory as DocBook files.</li>
<li>The stories that go on the website are marked with a DocBook <code><subjectset/></code> which also controls the build process.</li>
</ul>
<p>Given that, I want to upload '/local/build/directory/fiction/thomas-the-baker.xml' to http://d.moonfire.us/fiction/thomas-the-baker. I dropped extensions years ago, mainly so I can change formats, but also because I think it creates a cleaner looking URL.</p>
<p>The main part is creating the pages. I'm not going to post a lot of source code this time, mainly because I rolled all of the code into <a href="http://mfgames.com/mfgames-writing">MfGames Writing</a> in the brand new <code>mfgames-docbook-wordpress</code> utility.</p>
<pre>$ cd /local/build/directory
$ mfgames-docbook-writing upload --username=myuser --password=mypass --blog=myblogid fiction/thomas-the-baker.xml
... output
$</pre>
<p>This works because '/fiction' was already created. There is a fair amount that is happening here, but each step is relatively simple. One of the first things <code>mfgames-docbook-wordpress</code> does is download a list of all the pages already there. It also grabs the taxonomies that applie to the post type we are uploaded (in this case, it is <a href="https://github.com/dmoonfire/mfgames-writing/issues/16">hard-coded</a> to "page").</p>
<p>For each file, we create a WordPress-specific version of the file (via XSLT) that doesn't include the common headers and footer elements. We also calculate the SHA256 on the source document.</p>
<p>From there, it figures out the path for the file. If the page doesn't exist on the WordPress installation, it creates a new pages and uploads it. If it already exists, it checks the hash to see if it changed. If it has, then it uploads the new version. Otherwise, it skips it.</p>
<p>You'll notice I had to add a <code>--username</code> and <code>--password</code> options to my file. I expanded my <a href="http://mfgames.com/mfgames-tools-python">MfGames Python Tools</a> to get around that. Now, it can check for an INI file in a variety of locations and pre-populate the values. In this case, I have just a few key ones.</p>
<pre>[Defaults]
username=myusername
password=mypassword
blog=myblog
root_directory=/local/build/directory</pre>
<p>Now, I can be inside a directory and just run the command and it will create the proper path.</p>
<pre>$ cd fiction
$ mfgames-docbook-wordpress upload thomas-the-baker.xml
...
$</pre>
<p>In the end, it means that when I finish a chapter on my serial, I just have to go into the proper directory and type <code>make</code> which then converts the files to DocBook XML and then tries to upload the entire website. Only pages that changed will upload and they are live right away. So, it took a few days to get to this point, but it simplifies things going forward.</p>
<pre>$ make
... magic happens
$</pre>
<p>... at least until I change everything again.</p>
WordPress custom taxonomies2012-07-09T05:00:00Zhttps://d.moonfire.us/blog/2012/07/09/wordpress-custom-taxonomies/<p>One of my short term goals is to migrate a DokuWiki site over to WordPress. The decision to do this was somewhat complicated, but it came down to me not wanting to maintain too many systems. DokuWiki is great for what I used it for, but I'm maintaining seven websites now and I need to reduce my overhead since I need to focus on other things (writing, programming). I finished the second to last one (<a href="http://nobelpencr.org/">The Nobel Pen</a> on Saturday and started into the one I've been stalling on.</p>
<p><!--more-->Migrating my byline is actually a (relatively) major task. There are about a hundred short stories, a number of novels, and quite a few essays. In addition, almost everything is arranged into way too many taxonomies that make sense for that byline but not for anything else I do.</p>
<p><em>You might wonder why in the world I have so much tagging. Well, when I burn out I usually start cleaning. Plus, I wanted to see which views I wasn't writing about so I could. It ended up being a few months effort spread out since 1993, so it doesn't feel like I spent that much time on it.</em></p>
<p>WordPress handles custom taxonomies very well, but it needed some custom work. I could use a plugin to manage it, but after trying a few plugins, I decided to do it the "hard way." Now, the general suggestion is to do it in a custom theme, but I decided to create a plugin to manage it (local-sitename). This way, if I change the theme (which I have done twice now) I don't have to move over the taxonomies.</p>
<p>The basic local theme would go into <code>wp-content/local-sitename/local-customizations.php</code>. It needs a comment block which dictates what shows up on the plugin list inside WordPress.</p>
<pre>/*
Plugin Name: Local Customizations (sitename)
Version: 0.0.0
Author: D. Moonfire
Description: Adds in the site-specific customizations for http://sitename/.
*/
</pre>
<p>The plugin file also has a hook which is called when the plugin is activated for a given site.</p>
<pre>// Add in a hook to add the taxonomies and categories.
add_action("init", "sitename_init", 0);
<p>function sitename_init()
{
// Register the taxonomies associated with pages.
create_taxonomy(“format”, “formats”, “Format”, “Formats”, false);
create_taxonomy(“language”, “languages”, “Language”, “Languages”, true);
create_taxonomy(“magic”, “magic”, “Magic”, “Magic”, true);
// quite a few more taxonomies</p>
<p>// We need pages to have archives so we can use the taxonomies.
$page_type = get_post_type_object(“page”);
$page_type->has_archive = true;
}</p>
</pre>
<p>The last parameter of <code>create_taxonomy</code> determines if it is a hierarchy taxonomy or a flat one. For format (e.g., Story, Essay, Novel), it doesn't make sense to have a tree-like structure. But for languages and magical systems (actually most of my taxonomies), I use the parent/child relationship since I kept track of related languages (Romance Languages verses French).</p>
<p>Creating the taxonomy is pretty simple. I have a helper function to do most of the hard work for me:</p>
<pre>function create_taxonomy($key, $slug, $singular, $plural, $is_tree)
{
register_taxonomy(
$key,
array("page"),
array(
"hierarchical" => $is_tree,
"labels" => array(
"name" => $plural,
"singular_name" => $singular,
"search_items" => "Search $plural",
"popular_items" => "Popular $plural",
"all_items" => "All $plural",
"edit_item" => "Edit $singular",
"update_item" => "Update $singular",
"add_new_item" => "Add New $singular",
"new_item_name" => "New $singular Name",
"separate_items_with_commas" => "Separate $plural with commas",
"add_or_remove_items" => "Add or remove $plural",
"choose_from_most_used" => "Choose from most common $plural",
"menu_name" => "$plural"
),
"public" => true,
"show_in_nav_menus" => true,
"show_ui" => true,
"query_var" => true,
"rewrite" => array("slug" => $slug, "with_front" => false)));
}
</pre>
<p>This creates a pretty taxonomy. The new taxonomies show up under the "Pages" menu on the Dashboard and each one shows up on the right of each post. Now, you may notice that I have "page" in two places. Normally, taxonomies aren't associated with the "page" post type. Most of the examples, they have them assigned to custom post types.</p>
<p>For <a href="http://d.moonfire.us/">D. Moonfire</a>, I used a custom post type instead of messing with page. Because of how WordPress works, a custom post type has to have a slug, which is why all my story URLs start with "/fiction/". For the D. Moonfire site, this way okay because I didn't have many links out there and I use a relatively flat story organization. For the other site, which has mostly kept unbroken links based on setting. I've also used much of that structure since 2002-2004, so I couldn't really use the "/fiction/". In this case, I used page directly. I did the same with <a href="http://mfgames.com/">Moonfire Games</a> and the projects because of the historical links.</p>
<p><em>I try really hard not to break links. Even knowing that not many people visit my sites, I still feel the need for consistent URLs.</em></p>
<p>If you go to the website for <a href="http://mfgames.com/mfgames-writing">MfGames Writing</a>, you can see taxonomies in use on the right hand side. Clicking on the links brings up a list of pages with that category (say License). To get this to work, I had to use the <code>$page_type->has_archive = true</code> line above.</p>
Distraction powers, activate!2009-07-24T05:00:00Zhttps://d.moonfire.us/blog/2009/07/24/distraction-powers-activate/<div style="padding: 2px;float: right">
<div style="border: 1px solid #cccccc;width: 20em;margin: 2px 5px 2px 0;padding: 1px;clear: left;float: left;background: white;height: 18px">
<div style="font-family: Tahoma, sans;float: left;margin-left: 2px">Weight Loss (8.3 of 14.7 kg)</div>
<div style="font-size: 10px;background-color: #d8e4a8;height: 18px;width: 56.5%"></div>
</div>
<div style="border: 1px solid #CCCCCC;width: 20em;margin: 2px 5px 2px 0;padding: 1px;clear: left;float: left;background: white;height: 18px">
<div style="font-family: Tahoma, sans;float: left;margin-left: 2px">Commission (4,227 of 15,000 words)</div>
<div style="font-size: 10px;background-color: #e3d1a8;height: 18px;width: 28.1%"></div>
</div>
<div style="border: 1px solid #CCCCCC;width: 20em;margin: 2px 5px 2px 0;padding: 1px;clear: left;float: left;background: white;height: 18px">
<div style="font-family: Tahoma, sans;float: left;margin-left: 2px"><a href="http://tracker.mfgames.com/roadmap_page.php">MfGames.Tools</a></div>
<div style="font-size: 10px;background-color: #bae3a8;height: 18px;width: 0%"></div>
</div>
</div>
<p>Well, Friday has come around and I can't say I got everything done that I hoped. Not that I ever seem to finish my entire to do list when I have weeks like this, but I got a reasonable amount of them that I don't feel that I completely and utterly wasted the weekend. Given the number of times I got distracted over at <a href="http://armorgames.com/">Armor Games</a> and <a href="http://www.kongregate.com/">Kongregate</a>, I'm going to say I got to the "fun" things. Just not the ones that I planned on enjoying, like playing on the PlayStation or programming a game. Oh well.</p>
<p>My commission is kicking my ass. Four days of working on it and I can't say that I've gotten more than a quarter done. And I'm not exactly happy with the bits I do have, but I'll keep plugging on it.</p>
<p>I did get pretty good progress on a theme framework for web applications (I'm calling it WTF for web template framework). I have a <a href="http://d.moonfire.us/">DokuWiki</a> and <a href="http://d.moonfire.us/blog/">WordPress</a> themes that use the same centralized style and it seems to work out pretty well. It even has a <a href="http://themes.brokentypewriterpress.com/rough_blue/">test page</a> to test the style.</p>
<p>Tonight, I'm going to dinner with the in-laws and tomorrow we have board game night (*squee*), so this week is pretty much over for projects.</p>
More ljxp changes, now with avatars!2009-07-18T05:00:00Zhttps://d.moonfire.us/blog/2009/07/18/more-ljxp-changes-now-with-avatars/<div style="padding: 2px;float: right">
<div style="border: 1px solid #cccccc;width: 20em;margin: 2px 5px 2px 0;padding: 1px;clear: left;float: left;background: white;height: 18px">
<div style="font-family: Tahoma, sans;float: left;margin-left: 2px">Weight Loss (6.3 of 14.7 kg)</div>
<div style="font-size: 10px;background-color: #d8e4a8;height: 18px;width: 41.0%"></div>
</div>
<div style="border: 1px solid #CCCCCC;width: 20em;margin: 2px 5px 2px 0;padding: 1px;clear: left;float: left;background: white;height: 18px">
<div style="font-family: Tahoma, sans;float: left;margin-left: 2px">Commission (823 of 15,000 words)</div>
<div style="font-size: 10px;background-color: #e3d1a8;height: 18px;width: 5.1%"></div>
</div>
<div style="border: 1px solid #CCCCCC;width: 20em;margin: 2px 5px 2px 0;padding: 1px;clear: left;float: left;background: white;height: 18px">
<div style="font-family: Tahoma, sans;float: left;margin-left: 2px"><a href="http://tracker.mfgames.com/roadmap_page.php">MfGames.Tools</a></div>
<div style="font-size: 10px;background-color: #bae3a8;height: 18px;width: 0%"></div>
</div>
</div>
<p>Finished up another little change, the ability to pick and choose LiveJournal avatars from inside WordPress. This way, I don't have to write up a post, post it, then go over to LiveJournal to make it private (last week's change) and pick an avatar (this change). It all happens in the same place, which makes it easier for me to post quickly.</p>
<p>Despite the fact I get almost <em>no</em> comments on my main <a href="http://d.moonfire.us/blog/">blog</a>, I still prefer to have that as my primary and LiveJournal being a secondary mirror. It could just be me being picky, but despite the fact I'm not on Facebook or MySpace, I still want to have my blog on my domain. But, all those delicious comments and online friends are over on LiveJournal, so I bridge the two in the way that I'm comfortable with.</p>
<p>This also means I really should stop stalling and work on my commission or write a program.</p>
Reorganization2008-09-19T05:00:00Zhttps://d.moonfire.us/blog/2008/09/19/reorganization/<p>Last night, I trashed my baby squid god and started over from scratch. I just couldn't get everything to line up and I realize that starting with the high detail 1/8th model is the wrong way to go. Two hours later, I had just about the entire low-poly model done, a basic armature working (which I'm going to redo later), and it in the range of 600 triangles (I'm aiming for 1000 maximum for this model). It isn't quite as incredible as the model in my head, but its fairly close to something usable which is more important.</p>
<p>I did realize something. Squids don't have eyelids or eyebrows and this is actually going to cause me some problems with expressing emotions. Furthermore, I'm using eyes from the vampire squid which are basically... just blue orbs. And the mouth is under the mantle, so it can't be used either. (Gave up on the tongue for now.) So, if I do any closeups of the figure, I'm going to have a big struggle to make it look lovable (which is what I'm hoping for). (As a side note, I'm having a bit of trouble the Klein baby bottle, so I might give up on that unless I can find a good model to steal.)</p>
<p>I also reorganized the categories on my blog. Since WordPress now has categories and tags, I moved the tags into the tag section and left the big categories behind. This means the tag cloud is a lot smaller and those on LiveJournal won't be able to see the tags, but it seems much cleaner to me.</p>
<p>I might start putting up my % complete bars again. This weekend, I need to put at least a few hours on story commissions, go to a family reunion, and write a story for scienceprincess. Do a bit on Scroll of the Lands. And work on the BSG of course. Ah, too many projects and obsessions, <em>this</em> I know.</p>