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”

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”