WordPress

WordPress (WordPress.org) is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. WordPress was originally created as a blog-publishing system but has evolved to support other types of web content including more traditional mailing lists and forums, media galleries, membership sites, learning management systems (LMS) and online stores.

Examples

n. One that is representative of a group as a whole. n. One serving as a pattern of a specific kind. n. A similar case that constitutes a model or precedent.

Examples

Minimal Cron

Change the following:

function svd_deactivate() {
	wp_clear_scheduled_hook( 'svd_cron' );
}

add_action('init', function() {
	add_filter( 'cron_schedules', 'svd_schedule_cron' );
	add_action( 'svd_cron', 'svd_run_cron' );
	register_deactivation_hook( __FILE__, 'svd_deactivate' );

	if (! wp_next_scheduled ( 'svd_cron' )) {
		wp_schedule_event( time(), 'minute', 'svd_cron' );
	}
});

function svd_schedule_cron( $schedules ) {
	$schedules[ 'minute' ] = array( 'interval' => 1 * MINUTE_IN_SECONDS, 'display' => __( 'Every 1 minute.', 'svd' ) );
	return $schedules;
}

function svd_run_cron( ) {
	// Do your stuff!
}
Examples

Run WP CLI On All Sites Within A Network

 

# update an option.
wp site list --field=url | xargs -I % wp --url=% option update [option name] [option value]
Examples

Hooks for assets

Quick reference for where to hook in styles and scripts:

Where Action
Admin admin_enqueue_scripts
Frontend wp_enqueue_scripts
Block editor (admin) enqueue_block_editor_assets
Blocks (front and admin) enqueue_block_assets

 

Troubleshooting

Troubleshooting

Sync the database schema

In rare situations, the WordPress database schema might not match the schema expected by the applications or plugin. For example switching to multisite, and the wp_users table is missing the spam and deleted colums

To fix this issue locally, create a file in the mu-plugins folder such as mu-plugins/db-upgrade.php with the following contents, and load the site:

<?php
require_once ABSPATH . 'wp-admin/includes/schema.php';
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( wp_get_db_schema( 'global' ) );

After the page is loaded the file can be deleted.

Troubleshooting

Troubleshooting local environment problems

A collection of troubleshooting tips to diagnose issues with a local environment that's not working right.

WP CLI Issues

  1. Try wp cli info, if this fails then the issue is limited to WP CLI or PHP as  this doesn't touch the codebase / DB.

Knowledge

Knowledge is a familiarity, awareness, or understanding of someone or something, such as facts, information, descriptions, or skills, which is acquired through experience or education by perceiving, discovering, or learning.

Knowledge

Nonces

image-1588328055896.png

Nonces are regenerated every 12h, but are valid for 24h, hence that code. (12h = 1 tick, and they’re valid for two ticks)

Knowledge

Move a site to a new domain

Move a site workflow:

  1. Delete existing domain mappings for the site.
  2. wp search replace $old_url $new_url --all-tables; wp cache flush, avoiding trailing slashes.
  3. wp rewrite flush --url=$new_url; wp rewrite flush;
  4. Login to the network site, edit the site, press Save Changes. (not sure why)
  5. Verify site loads and login works.
  6. re-add domain.
  7. restart browsers because of cached redirects.