pfeifferNet

upgrade-db.php

Upgrade the database.

  • This script will abort on a production site.
  • The release documentation will specify the required user (if any) to run this script.
  • Run this from the command line using the command:

wp eval-file upgrade-db.php [--user={user_name}]

Tags
since
6.0.0
copyright

2025 Keith Pfeiffer

Table of Contents

Constants

OPTION_NAME  = 'pnet_db_version'
DB version option name.
REQUIRED_USER  = 'devmaster'
Required user name.
REQUIRED_VERSION  = '6.8.0'
Required db version.

Functions

is_production()  : bool
Check if this is a production site.
is_upgrade_required()  : bool
Check if upgrade is required.
is_correct_user()  : bool
Check if the correct user is running this script.
upgrade_database()  : void
Upgrade the database.
do_upgrades()  : bool
Perform the upgrades.
set_word_count_metadata()  : bool
Set word count metadata for all posts.
delete_jetpack_artefacts()  : bool
Remove Jetpack artefacts.

Constants

OPTION_NAME

DB version option name.

public string OPTION_NAME = 'pnet_db_version'
Tags
since
6.0.0

REQUIRED_USER

Required user name.

public string REQUIRED_USER = 'devmaster'
  • If this is set, the upgrader will only run if the current user matches this name.
  • Only set this if the upgrader calls functions that have user capability checks.
Tags
since
6.8.0

REQUIRED_VERSION

Required db version.

public string REQUIRED_VERSION = '6.8.0'
  • This MUST be set to the plugin version if upgrader is to run. Leave as a value less than the current version to skip upgrade.
Tags
since
6.0.0

Functions

is_production()

Check if this is a production site.

is_production() : bool
Tags
since
6.2.0
Return values
bool

True if this is a production site, false otherwise.

is_upgrade_required()

Check if upgrade is required.

is_upgrade_required() : bool
Tags
since
6.0.0
Return values
bool

True If stored version is less than the required version, false otherwise.

is_correct_user()

Check if the correct user is running this script.

is_correct_user() : bool
  • If REQUIRED_USER is set, the upgrader will only run if the current user matches this name.
Tags
since
6.8.0
Return values
bool

True if the current user matches the required user, false otherwise.

upgrade_database()

Upgrade the database.

upgrade_database() : void
  • Abort if this is a production site.
  • Abort if upgrade is not needed.
  • If REQUIRED_USER is set, the upgrader will only run if the current user matches this name.
  • Delete this file after successful upgrade.
Tags
since
6.0.0
since
6.2.0

Abort if this is a production site.

since
6.8.0

Check if the correct user is running this script.

since
6.8.0

Delete the script after successful upgrade.

do_upgrades()

Perform the upgrades.

do_upgrades() : bool
  • Call functions from here to perform the actual database upgrades.
  • Bail if any function fails.
Tags
since
6.0.0
since
6.2.0

Upgrade gallery posts to use gallery post format and use correct tag.

since
6.3.0

Add GitHub API token date.

since
6.7.0

Add related posts to post meta table and define the number of them to display.

since
6.7.0

Add cron jobs to update selected content and transients.

since
6.8.0

Add word count metadata bulk update.

since
6.8.0

Remove Jetpack artefacts.

Return values
bool

True if upgrade was successful, false otherwise.

set_word_count_metadata()

Set word count metadata for all posts.

set_word_count_metadata() : bool
Tags
since
6.8.0
Return values
bool

True if successful, false otherwise.

delete_jetpack_artefacts()

Remove Jetpack artefacts.

delete_jetpack_artefacts() : bool
  • Remove Jetpack comment metadata.
  • Remove Jetpack post metadata.
Tags
since
6.8.0
Return values
bool

True if successful, false otherwise.


        
On this page

Search results