Home > OS >  WordPress settings BEFORE installation
WordPress settings BEFORE installation

Time:02-04

I would like to edit the WordPress files before installation to my needs.

For each WordPress installation I am changing certain settings, pages, posts and the theme. So I would like to make these changes once and have my changes applied by the installation.

Here you can find the normal WordPress files: https://de.wordpress.org/download/#download-install

I followed this post to stop posts and pages from being created and also found some code in wp-admin/includes/upgrade.php to define pages to start out with. How to delete the default hello world post BEFORE Wordpress install

From this post I took the info to set the starting theme, which can be found in wp-includes/default-constants.php. But that post had a warning to "NEVER EVER edit the CORE files" – kanlukasz Set WordPress default settings before installing

So my questions are:

  • How to activate plugins on installation?
  • How to edit the settings on installation, like time format, media upload format and avatar format-> false
  • How to properly set the theme before installation?

Happy for every answer or pointers to other topics.

CodePudding user response:

There's three main parts to a WordPress install, which I'll generally (although arbitrarily) identify as pre-work, installation, and setup.

The commands below assume you have WP-CLI installed and available on your system. They make no assumptions about your server, be it Apache, Nginx or IIS (except for rewrite which only works with Apache). At our company we actually use the Symfony CLI binary for local development server since we get a TLS cert and proxy.

As noted in the comments, you can also go down a different path using composer, and the most common one is probably the Bedrock install. I'm not going to touch on that, they've got plenty of documentation.

Pre-work

In this phase you need to get the database setup, create the directory to hold WordPress and download it, and create a wp-config.php file. You can do all of this from the CLI, too, although your commands might vary for the database depending on your version and flavor.

In this example I'm creating a database named t_low with a username and password of the same.

# Setup database
mysql -uroot -p -e "CREATE DATABASE t_low; GRANT ALL PRIVILEGES ON t_low.* TO t_low@localhost IDENTIFIED by 't_low';"

# Download WordPress
mkdir t-low
cd t-low
wp core download

# Create config
wp config create --dbname=t_low --dbuser=t_low --dbpass=t_low

Installation

This is fairly straight-forward, pretty much the options you'd see if you went through the web GUI. On development sites I don't bother with passwords because they just clog up my password manager, too, but could be provided here if you want to.

# Install WordPress
wp core install --url="https://t-low.wip" --title="Demo Site" --admin_user="[email protected]" --admin_email="[email protected]" --skip-email

Setup

At this point, WordPress is technically installed, so this is where you can change/tweak/delete things like plugins, themes and settings. Obviously don't run all of these blindly, take a moment to think through what they do and if they are applicable for you. Most of these are part of my company's default install.

# Install and optionally activate plugins
wp plugin install health-check --activate
wp plugin install one-time-login --activate

# Remove existing plugins
wp plugin delete hello
wp plugin delete akismet

# Remove extra themes
wp theme delete twentytwentyone
wp theme delete twentytwentytwo

# Turn on debugging
wp config set WP_DEBUG true
wp config set WP_DEBUG_LOG true
wp config set WP_DEBUG_DISPLAY true

# Delete sample data
wp post delete $(wp post list --post_type='post' --format=ids)
wp post delete $(wp post list --post_type='page' --format=ids)

# Set rewrite structure
wp rewrite structure '/%year%/%monthnum%/%postname%/'

# Disable avatars
wp option set show_avatars 0

# Change the time format
wp option set time_format "Y-m-d"

Your next question might be "how do I know what options to change" and that one is trickier. Sometimes you can just run wp option list and find an option that is obvious to change. Other times you might need to run that command and save the output somewhere, make the change in the GUI backend, then re-run the command to see the difference.

With all CLI commands you can append --help to get a better understanding of things. You can also find info online, but I think the CLI is more descriptive.

There's also several third-party WP CLI packages to install that you might find helpful, and some plugins even ship with their own. For instance, on most of my sites I install the one-time-login plugin wp plugin install one-time-login --activate so that I can do wp user one-time-login [email protected] to get a magic login link and not have to worry about passwords.

Lastly, you can very easily write your own commands. There's a little bit of boilerplate stuff that you need to get down, but otherwise it is pretty straightforward WP/PHP code then.

Also, for plugins that aren't in the main directly you can still install them via a zip file or URL:

wp plugin install file.zip --activate
wp plugin install https://example.com/file.zip --activate

Some of those plugins, such as ACF, allow you to store activation keys in wp-config.php, which is really awesome. This is not universal, however, and totally up to the plugin developer.

wp config set ACF_PRO_LICENSE "XYZ"
  • Related