WordPress

Useful WordPress-related topics

WP-CLI

====================================================================================

WP-CLI Installation guide

------------------------------------------------------------------------------------------------------------------------------------------------

Dump or import wp databases

wp db export backup.sql

------------------------------------------------------------------------------------------------------------------------------------------------

wp db import backup.sql 

Home & base URL

Check or set home URL
wp option get home 
wp option update homeurl domainname 
Check or set base URL
wp option get siteurl 
wp option update baseurl domainname 

------------------------------------------------------------------------------------------------------------------------------------------------

search and replace on database:

wp search-replace stringtoreplace replacementstring --skip-columns=guid --all-tables --allow-root

------------------------------------------------------------------------------------------------------------------------------------------------

Changing WordPress Admin/User Passwords

------------------------------------------------------------------------------------------------------------------------------------------------

Changing WordPress Admin Password

The WordPress admin password can be changed via the WordPress database directly, or via WP-CLI:

====================================================================================

WP-CLI

https://developer.wordpress.org/cli/commands/user/reset-password/ 

If WP-CLI is installed, the below command can be used to change the admin password:

wp user reset-password

(user has to be specified)

Options
<user>… - one or more user logins or IDs.
--skip-email -Don’t send an email notification to the affected user(s).
--show-password -Show the new password(s).
--porcelain -Output only the new password(s)
------------------------------------------------------------------------------------------------------------------------------------------------

# Reset the password for two users and send them the change email.
$ wp user reset-password admin editor
Reset password for admin.
Reset password for editor.
Success: Passwords reset for 2 users.

# Reset the password for one user, displaying only the new password, and not sending the change email.
$ wp user reset-password admin --skip-email --porcelain
yV6BP*!d70wg

# Reset password for all users.
$ wp user reset-password $(wp user list --format=ids)
Reset password for admin
Reset password for editor
Reset password for subscriber
Success: Passwords reset for 3 users.

# Reset password for all users with a particular role.
$ wp user reset-password $(wp user list --format=ids --role=administrator)
Reset password for admin
Success: Password reset for 1 user.

====================================================================================

MySQL - Editing WordPress Database Directly

use wordpress_database;
UPDATE wp_users SET user_pass = MD5('new_password') WHERE user_login = 'your_admin_username';

====================================================================================

WordPress Debug Mode

====================================================================================

WordPress Debug Mode

WordPress comes with a built-in debugging feature, with a few options we can set for viewing debug logs.

All of these changes are made within the wp-config.php file - 

NOTE: You must insert this BEFORE /* That's all, stop editing! Happy blogging. */ in the wp-config.php file.

Enable debug mode with standard debug log output on website (shows any debug errors on the website itself by default)

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

Change WP_DEBUG display method on site: - Prevents debug errors from being displayed on the website itself:

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Set WP-DEBUG log file:

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

====================================================================================