WordPress

Optimize Database Performance – Cleaning WP Options Table

We all know WordPress is an application written in PHP and paired with MySQL or MariaDB database. The PHP language reads or writes to the database. This happens on every WordPress request, for example, like the home page that makes up links, content, theme, or plugin, there is always a call in the database.

One database table, in particular, that is overly used on this request is the WP Options table. The WP Options table stores the site data, when this table gets large this will contribute to sluggish response time. Cleaning the WP Options table can improve page generation speed.

Image from https://codex.wordpress.org/Database_Description

This is the only table on the database that is alone or without any table relationship, assuming it would add load if this is linked to another table, a flat table by design. Here is the table definition:

CREATE TABLE `wp_options` (
  `option_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `option_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `option_value` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `autoload` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'yes',
  PRIMARY KEY (`option_id`),
  UNIQUE KEY `option_name` (`option_name`),
  KEY `autoload` (`autoload`)
) ENGINE=InnoDB;
FieldTypeNullKeyDefaultExtra
option_idbigint(20) unsignedPrimaryauto_increment
option_namevarchar(191)Unique
option_valuelongtext
autoloadvarchar(20)Indexyes

By design, three out of one are indexed properly for an optimized SELECT query.

Removing Transients

Transients are temporary data of plugins and themes stored on the WP Options table. Usually, this has expiration dates but if the plugin has been deactivated or uninstalled the value on the table would remain in the database forever. Transients can be easily identified since a “transient” word can be found in the field option_name. To remove execute a DELETE SQL statement.

DELETE FROM wp_options WHERE option_name LIKE ('%\_transient\_%');

Removing Sessions

Sessions are temporary data that is generated from every user visit. This will be automatically be deleted after thirty minutes of user inactivity but that is not the case all the time. Manual removal is needed to clean up the session’s data.

DELETE FROM wp_options WHERE option_name like '_wp_session_%';

Protecting WordPress login page thru Basic Authentication

Take steps to avoid brute force attacks on the WordPress admin dashboard page. This would add an additional layer to site security and avoid traffic excess. Basic Authentication would facilitate HTTP requests to require a username and a password.

Add Basic Authentication via .htaccess

This is applicable to sites using Apache as the web server, this would not work on hosts with Nginx as their web server. Two simple steps:

Create a .htpasswd file then upload it to your webroot folder, this is the folder mostly where “.htaccess" resides.

Add this line to your .htaccess file

<Files wp-login.php>
AuthUserFile /.htpasswd
AuthName "Security Lock"
AuthType Basic
require valid-user
</Files>

Add Basic Authentication on the wp-config.php file

Sometimes as customers don’t have access to server configuration and PHP would be the fallback method.

if(preg_match('/(wp-login.php)/',$_SERVER['REQUEST_URI'])){
    if (!isset($_SERVER['PHP_AUTH_USER']) || ( $_SERVER['PHP_AUTH_USER'] != 'yourusername' && $_SERVER['PHP_AUTH_PW']   != 'yourpassword')) {
	    header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
	    header( 'WWW-Authenticate: Basic realm="Security Lock"' );
        header( 'HTTP/1.0 401 Unauthorized' );          
        exit();          
     }
}

Skipping WordPress Background Updates

What is Site Health?

The WordPress admin interface is designed to assist end-users in self-servicing their sites by addressing typical setup difficulties and other aspects of maintaining a healthy online presence. It also gives developers a consistent place to store debugging information.

SiteHealth Dashboard

Why the need to skip background updates?

Some hosts, specially Pantheon.io handle the core updates by means of applying upstream updates, or in some common practice, more sites are now in version control using git. Site owners don’t want to ignore the whole time and miss out on potential problems.

Code snippet to skip the update

Create a file named sitehealth.php put it in wp-content/mu-plugins and put these lines of code.

<?php
/**
 * Plugin Name: Sitehealth 
 * Plugin URI: https://github.com/careydayrit/
 * Description: Skip core update on sites using Git
 * Version: 0.1
 * Author: Carey Dayrit
 * Author URI: https://careydayrit.com/
 *
 * @package sitehealth
 */
 
add_filter('site_status_tests', 'skip_background_updates_tests', 10, 1 );


function skip_background_updates_tests($tests){
    unset($tests['async']['background_updates']);
    return $tests;
}

Using WordPress for eCommerce

Because of this pandemic, the number of people shopping online has multiplied, and it is still rising to this very moment. With nothing else to do, people tend to visit websites that are selling products that they usually want to buy, such as shoes, dresses, electronic devices, and many more. In this article, you will learn Steps on How to Use WordPress as an eCommerce Store.

Knowing that online shopping is a trend, especially in these times, a lot of people want to get involved with it and would want to know how to create an E-commerce store. Well, then let me teach you how to create your very own eCommerce store by using WordPress. Let’s get started then! 

1. Get a Domain Name and a Hosting Provider

Before you can create a website, it is important to have a hosting provider and a domain name first. Your domain name is what appears on the top bar of your browser, just like this:

domain

Some companies only provide domain name registration, but the majority provide both domain name and web hosting services. Some of the commonly good registrars are Domain.com, GoDaddy, and NameCheap. I would not recommend NetworkSolutions though they are fairly good, they don’t support adding IPv6 on their user interface, you need to email them to have IPv6 value to be added to the domain, they called it glue record. Think carefully about your domain name, because it is how people are going to reach your website.

There are hundreds of thousands of web servers available, the most majority of which match the WordPress basic criteria, but picking one out of the crowd can be difficult. WordPress thrives in a rich hosting environment, it would also depend on the requirement of the application, not all hosting is created equal.

For the hosting provider, I suggest that you use Bluehost.com because WordPress.org officially recommends them. All you have to do is go to their website, bluehost.com, fill up the form, and you are good to go. You can also create your domain name on the site.

After creating your account, there will be a button there that indicates “start building”. Click that button, and you will be taken to the back end of your WordPress account.

2. Install WordPress and choose a Theme

Right after you’ve chosen a Host Provider and a domain name for your eCommerce website, you will then have to secure your WordPress website. You can look it up on Youtube to know-how. Now that you are in your WordPress already, the first thing that you must do is to change the theme. The suggested theme that everyone seems to be using is the Astra theme. This theme is basically what other online store websites look like and I’m sure that it is the website that you want to follow.

Astra is a fast, highly customizable, and super clean theme that is designed to convert better and boost your store’s sales. This is the them

3. Install the Woocommerce plugin

WooCommerce is a flexible, open-source commerce solution built on WordPress.  Based on the plugin page on the WordPress.org website, WooCommerce has over 5 million active installations. It is the most customizable eCommerce platform for building your online business.

Screenshot from the plugin page

WooCommerce isn’t like Shopify or BigCommerce in that it’s not a standalone hosted eCommerce platform. It’s a plugin, or extension, for websites developed using WordPress, the free and open-source content management system that powers the vast majority of websites around the world. It’s simple to get started with WooCommerce once you’ve started creating your website because it’s a plugin. Here’s the URL to their guide https://woocommerce.com/documentation/

Why Choose WordPress for Your Website?

Do you want to start your own blog or create your company’s landing page but you don’t know how? Eyes here, I may have something that can help you. If you want to create a website then I suggest a content management system like WordPress as the software to be used. Let me tell you why.

What is WordPress?

Back when the internet was still emerging, you have to learn how to use codes in order for you to create a website. Codes to change the background of your website, font style, font size, buttons, and many more.

 Now, that we already have advanced technology, we will no longer do codings. We can readily access software such as WordPress, where we can easily create a website. With WordPress, you won’t have to go through coding anymore, you can customize your website and WordPress will automatically do the coding for you. 

WordPress powers over 30% of the entire internet and is one of the most popular website publishing programs in the world. WordPress earned its number 1 spot because it is highly recommended for starters. Many newbies use this software because of its advantages, other than that it is free. WordPress is available online so it is accessible anywhere you are as long as you have access to the internet.

Why is it recommended for beginners?

WordPress has a variety of 11,000 themes and template layouts that would determine the look and style of the website. You are free to choose the themes and layouts that you want. You can tweak the text, choose fonts and font sizes, upload your images or videos, create buttons, and many more so you should try to have fun and explore it a little bit more.

 Whether you like to create a marketing website or a portfolio, plug-ins and widgets are available to help optimize the functionality of your website. It is very beginner-friendly because it has instructions and captions to guide you when you explore and discover the website more. 

Advantage of WordPress

Let us now talk about the advantages of WordPress.

  1. It is free, you can download the software at WordPress.org
  2. WordPress allows you to really own your website and allows you to use your own unique domain name. Some software doesn’t allow you to have your own domain name. An example would be like this, companyname.com or brandname.com
  3. You can use plug-ins and widgets which help in optimizing the functionality of your website.
  4. The monetized ads, where you can earn money if you will be allowed to monetize advertisements on your website. Don’t expect that you will be monetizing your website right off the bat. It will take time and you have to learn more about affiliate links and marketing stuff. If you’re running an online store and you want to use WordPress, it is possible plus WordPress has plug-ins and widgets that enable you to do so.
  5. You will have a variety of choices on what theme you are going to use, you can customize the theme according to your preference. What font styles, size the fonts, font size, colors, buttons you want to add, pretty much everything.

There you have it! If you want to create your own website, you should consider using WordPress. There is a lot of software available online.  Read this article again if you want to weigh the advantages and benefits of other software. Have a nice day!