Rename an Amazon Lightsail instance

Amazon Lightsail is a perfect solution for a newbies to cloud computing like me. It offers a very simplified interface and overall approach into creation and management of fully featured VPSes (Virtual Private Servers) without the overhead and hassle of using more complex and more professional solutions like Amazon EC2.

The most important part of its greatness, next to simplicity, is pricing. The smallest possible option (just a virtual server with:

  • 512 MB memory and 1 core processor
  • 20 GB SSD disk and 1 TB of outbound traffic per month

which is far enough to host a simple-to-middle WordPress site will cost you 3.5 USD per month only. One static IP (with the possibility of using your own domain thus) is added free of charge.

You will be billed more only if your site has enough interest to go beyond that 1 TB outgoing traffic or if you decide that you need more computing power. Other than that — just a plain three and a half buck per month.

However, there’s a little glitch when you create your instance with an incorrect or misleading name, because the process of renaming Amazon Lightsail instance includes a few steps and some downtime on your website.

Read More “Rename an Amazon Lightsail instance”

File upload blocked despite ALLOW_UNFILTERED_UPLOADS set to true

Some file types are reporting its MIME type different than it is associated with given file extension in WordPress database. Such file upload will be blocked for security reasons (.epub file in my case):

X.epub: Sorry, this file type is not permitted for security reasons

A special ALLOW_UNFILTERED_UPLOADS flag is used in WordPress in such situations. You should try it first. If you still have not satisfying results (i.e. you still can’t upload a file of certain type) then it may mean some MIME table changes made by either your plugin or theme or even a nasty bug in WordPress itself.

In all cases, using must-use plugin with some small filter should solve the problem.

Read More “File upload blocked despite ALLOW_UNFILTERED_UPLOADS set to true”

Increasing “Max upload file size” in WordPress the right way

To all those disbelievers — yes, uploading 1 GB or bigger files to WordPress is possible! :)

And you don’t have to play with some workarounds like uploading files through FTP and hard-linking them with your post. You can upload large file right in WordPress built-in file uploader.

However, a lot of steps may be needed before you will be able to achieve this.

Read More “Increasing “Max upload file size” in WordPress the right way”

Rules for pasting large text to Gutenberg / WordPress

Here’s the rule of thumb:

  1. Gutenberg changes pasted large text into separate blocks, if you have two line separation between paragraphs,
  2. If you have single line paragraph separation then Gutenberg will paste whole text into single block.

If you’re pasting from Word or other rich editor then everything should be OK. But, if you’re pasting from some non-rich text editor (I am using Notepad++) and you have a single line paragraph separation then a short trick must be done prior pasting text to Gutenberg.

Read more

Enabling XML-RPC access to your WordPress.org blog

Many on-line guides (like this one) says to simply go to Settings > Writing and under Remote Publishing to check the XML-RPC protocol checkbox, in order to enable XML-RPC access to your blog.

After that you should be able to access http://yourblog.com/xmlrpc.php without any problems. When you try to do this via browser, you will most likely see “XML-RPC server accepts POST requests only” message. But, that is still a good news, which clearly confirms that XML-RPC access to your blog is enabled. Otherwise (i.e. without correct enable of XML-RPC) you would hit 403 Forbidden error instead.

If this isn’t working or if you need more fine-grained control over XML-RPC access to your blog then you may find some ideas worth to consider in this short article.

Read More “Enabling XML-RPC access to your WordPress.org blog”

Replacement for mb_strimwidth() which is part of php-mbstring package

One of blogs in my WordPress network is using some old, free theme that was using mb_strimwidth() function. This function is part of php-mbstring package which turned out to be disabled by default in my hosting configuration for PHP 7.2 (it is enabled by default for PHP 5.6).

After enabling PHP 7.2 in my hosting configuration it turned out one of my blogs stopped showing content (showing those damn two small smilies instead). After enabling wp_debug mode it turned out that theme was using mb_strimwidth() that was part of disabled php-mbstring package.

The mb_strlen is not part of that package, seems to be part of core PHP and can be used as a workaround.

Read More “Replacement for mb_strimwidth() which is part of php-mbstring package”

Markdown formatting in block elements in WordPress

Markdown formatter in WordPress (Jetpack’s one) by default does not format parts inside block elements:

<div style="margin-left: 50px">
Thus, _this_ will **not** work!
</div>

But, with addition of markdown="1" you can enable the magic:

<div style="margin-left: 50px" markdown="1">
And _this_ **will** work!
</div>

I love simple solutions!

Redirect from post to an external URL

Why would you like to redirect a page’s visitor to an external URL instead of presenting post content?

Well, they may be a dozens of reasons. I found one. I was building a simple product showcase page with cool image scroller based on WordPress and Modest theme from Elegant Themes. Since image scroller contained not only image, but also title and two line entry, it was based on actual posts.

I wanted my users to see these texts, but to not be able to access posts itself. Because there was nothing more than just this image, title and two-line description. That’s why I used URL redirection.

Read More “Redirect from post to an external URL”

Test page for Markdown on Save Improved plugin

This is a dummy example post body, that can be used for testing Markdown rendering in any WordPress post or in any Markdown supporting page at all. I wrote it months ago and started using it for testing Markdown on Save Improved plugin. But then in turned out, that this quick sheet can be used virtually everwhere, where Markdown can be used. Just paste everything or selected part to test and verify Markdown in your blog, website, service etc.

Read More “Test page for Markdown on Save Improved plugin”

Print correct date in languages other than English

Unlike in English, full date written in many other languages (i.e. in Polish) has month written in genitive case. Neither WordPress (the_time()) nor PHP itself (date() on which the_time() is built on) supports writing dates in such format, so you’ve got to help yourself. This isn’t a hard task and there are many approaches to solve this problem across Internet. Here, I present on of the solution, ready to be used both in one, single theme or across entire WordPress Network.

Read More “Print correct date in languages other than English”

Hiding blog from guests or setting up ‘Under Construction’ site

WPRecipes has a quick and clean example of using shortcodes in WordPress in general and a particular example of restricting part of post (text, media or anything) to be visible only to registered users. This is quite nice example of doing so, without need of extra plugin for this purpose. You could also learn from here an overall knowledge of using shortcodes in WordPress, if you’re not familiar with that.

Keep in mind that this tips is for hiding part of post from guests. If you want to hide entire post, simply publish it as Private (all posts and pages are published as Public by default) — look in post or page settings.

Read More “Hiding blog from guests or setting up ‘Under Construction’ site”

Fixing small but annoying issues in Dashboard in WordPress Network

There are three small, but annoying things in Admin Dashboard that I always encounter, when dealing with WordPress Network installation:

  • My Sites menu items order,
  • slow loading of that menu,
  • WordPress sites’ Dashboards language.

All three issues can be easily fixed. But, you’ll need some deeper knowledge of WordPress and deal with some plugins (both hand-written and downloadable).

Alphabetic order of My Sites menu

First thing is how to sort My Sites menu items alphabetically?

The question, what order is used to sort My Sites menu in WordPress Network Dashboard remains unanswered. Items order in that menu changes as you’re making changes to your sites, but probably even WordPress authors can’t answer what sort order is used there. We only know for sure, that it isn’t alphabetical — the most wise and most obvious.

Here is a simple solution (network plugin) to solve this problem. Just copy this:

/*
 * Plugin Name: Sort My-Sites
 * Description: Sorts the My Sites listing alphabetically.
 * Author: Otto
 */

add_filter('get_blogs_of_user','sort_my_sites');

function sort_my_sites($blogs)
{
    $f = create_function('$a,$b', 'return strcasecmp($a->blogname, $b->blogname);');

    uasort($blogs, $f);

    return $blogs;
}

and paste it into text editor.

Save it under any name (sort-my-sites.php for example), put to a subdirectory (sort-my-sites) and ZIP it (sort-my-sites.zip). Then install and network enable such plugin. And voila!

This solution is a slight modification of this WordPress StackExchange answer.

My Sites menu items count

If you have many sites in your network and number of My Sites menu grows, you may even face the problem that your entire Dashboard loads visually slower only because Network Admin bar consumes much time and resources to build up My Sites menu.

In this case you may consider Joshua Lynch’s solution.

It utilizes similar approach as above and introduces some new filters, that removes all sites from My Sites menu and places commonly used items to it instead.

Dashboards’ Language

Very irritating (at least to me) is that when you (or your user) sets blogs language to different than English, not only blog is translated, but also is admin’s dashboard. Translations authors are paying much less attention to quality and update of dashboard’s translations, so translated dashboard may not only be confusing, but also improperly translated or with missing strings.

All these problems can be avoided, by forcing each dashboard to English, no matter, what language blogs are using. This can be done with a small and simple plugin called Admin in English.

Note: If you search the web for this plugin name, you may find some sites, outside WordPress.org, that shows some nice examples on how to force all dashboards to use the same, non-default (not English) language. I remember, that I run into article showing how to have all dashboards in Russian, while network blogs were all in Russian, English and German.

Multi-site multi-language Markdown-styled WordPress network

I’ve set myself quite big goal. To setup:

  • multi-site WordPress network (with top-level domain mapping),
  • with multi-language support,
  • that will use Markdown,
  • with auto-generated table of contents, based on headers and
  • with “coming soon” / “under construction” page for not ready sites.

To achieve my goal, I needed a bit tweaked version of WordPress (network) plus a bunch of plugins.

Read More “Multi-site multi-language Markdown-styled WordPress network”

Object-oriented plugin template for WordPress

I love WordPress, but the worst thing about it is that it is written with the most shitty code, I have ever seen.

WordPress development started years ago, and though during past years object-oriented programming has become de facto standard, WordPress still remains full of shit code and shitfull coding techniques. I can understand it about core code. After all — rewriting whole WordPress to OOP could be too big piece of cake. But I completely can’t understand it, why plugin’s authors follows this and write their plugins with pretty much the same shit code?

In this situation, any attempt of making things better is very welcomed (at least by me). The Object Oriented Plugin Template Solution plugin (or actually — plugin template), I ran into today, sounds like such promising star in a dark, dully sky of shit-code.

I recommend this plugin template to every WordPress plugin author. Even though it’s pretty new (published today) it looks very, very promising.

Autosave and revisions in WordPress

WordPress by definition performs automatic saves of each post being currently edited and also, for each post update, it creates a revision. This enlarges database and sometimes can make life a little bit harder, because both WordPress and browser can get a little bit wako on any of these mechanisms. So, here is a quick way of disabling these features.

This post is based on Revision Management in Wrodpress Codex. Refer to it for details.

Read More “Autosave and revisions in WordPress”