How to Clean POSTMETA Data of Old Orders After Switching to WooCommerce HPOS

Old Order Deletion Illustration

As of today there is no official guide for this simple need. If you have old orders more than 1000, you are right if you want to get rid of old orders – just to fasten your website.

So i decided to write my own script and apply to my web store with 30K order history.

Step1: I activated HPOS in dual-mode (aka safe mode).

Step2: 1 day passed and i disabled legacy mode and kept HPOS only

Step3: 1 more day passed and i deleted the oldest 5 orders from wp_postmeta.

Step4: Everything looked good, and i did the same for all orders.

Warning: You should take a backup before applying this code:

Continue reading “How to Clean POSTMETA Data of Old Orders After Switching to WooCommerce HPOS”

Allow SFTP root access to the Linux Server – just for your own IP address

If you want to access your Linux server using SFTP and a root user, by default it can be disabled. Due to security reasons most server-providers disable that by default.

So, you can enable it yourself. But as it is not secure, you need to add some restrictions.

Such as, adding this feature only for your own static IP.

So let’s do that. Open your server’s sshd_config file by using this command.

nano /etc/ssh/sshd_config

Under the line Subsystem sftp /usr/lib/openssh/sftp-server you can paste 3 new lines.

Here is how it should look like:

Subsystem sftp  /usr/lib/openssh/sftp-server
Match Address 111.111.111.111
PasswordAuthentication yes
PermitRootLogin yes

Replace 11.111.111.111 with your own static IP address.

Then save and restart SSH by using

service ssh restart

That’s all. Now you can access to your server via SFTP, as a root user if you are connected to internet with your own static IP.

All other users will not be able to connect of course.

Rename existing WordPress Attachments files, titles

Rename wp media object

If you change your website name, or you have to change some strings in existing imagedata of your website, we need to do the following steps:

Step 1: Fetch all attachments

Step 2: Rename all corresponding uploaded files

Step 3: update attachment data so that new files would be recognized by WP

Step 4: Update title, description data as well.

Here is a snippet which implements all 4 steps above.

Continue reading “Rename existing WordPress Attachments files, titles”

How to use Google DNS in Ubuntu/Debian permanently

Few weeks ago in one of the servers we faces strange issue: The website couldn’t send emails using remote SMTP.

First i thought it was related to SMTP port, credentials etc. – but everything was OK there. So then i tries to ping google.com and got surprised. It wasn’t worked. Simple ping didn’t work.

So it was obviously corrupted DNS issue.

First i tried the easier way, which is recommended by developers.google.com, adding Google DNS IP addresses to resolv.conf file

sudo vi /etc/resolv.conf

But it didn’t help.

So i decided to go into deeper and solving it using netplan.

Continue reading “How to use Google DNS in Ubuntu/Debian permanently”

How to create downloadable PDF link that works in all mobile browsers – Chrome, Safari etc.

In some mobile browsers PDF links might not work properly.
Instead of downloading, its tab just disappears immediately after opening. And we get no downloaded PDF.

Auto-close, auto-disappear – whatever you call that – but the problem exists.

So for WordPress websites, here is how to skip this pdf-download block for mobile browsers.

We will use pseudo-page link in order to bypass that block.

I mean, instead of direct links to PDF, we will use pseudo-pdf link which doesn’t look like PDF, but actually returns PDF header and body.

Let’s say that we have a PDF ile in “wp-content/uploads/2022.pdf”.

Continue reading “How to create downloadable PDF link that works in all mobile browsers – Chrome, Safari etc.”

How to modify the output of any WordPress shortcode

Assume we have some plugin called AAA and it has built-in shortcode aaa_content and its usage is like this:

[AAA_content title=”Recent news” id=”23″]

Now we want to change its output HTML.

In WordPress, the output of any 3rd party function can be changed only if it has apply_filters() filtered output. Unfortunately not all functions and shortcodes have such filter in output. So it is almost impossible to modify its output without editing the plugin’s source file.

And as we know, editing the plugin file is always bad idea. The changes will be erased just in the next update.

So we have some different approach for such cases.

For example, here is one idea, which is subject of this blog post.

Creating parent shortcode which handles the output of the original shortcode.

So let’s declare and build that alternative shortcode.

Continue reading “How to modify the output of any WordPress shortcode”