Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download WP core #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ For deploying WordPress websites.
cp vendor/studio24/deployer-recipes/examples/wordpress.php ./deploy.php
```

See [WordPress recipe](recipes/wordpress.md) docs.

[Source](../recipe/wordpress.php)

### Laravel:
Expand Down
62 changes: 62 additions & 0 deletions docs/recipes/wordpress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# WordPress

Deploy a WordPress site

## Recipe

```
require 'vendor/studio24/deployer-recipes/recipe/wordpress.php';
```

## Requirements
WP-CLI must be available on the remote server.

## Configuration
This recipe downloads WordPress on deployment, by default to the folder `web/wordpress/`. You can change this via:

```php
// WordPress core folder
set('wordpress_core_folder', 'web/wordpress/');
```

## WP CLI
If you need to call any [WP CLI](https://wp-cli.org/) commands this recipe includes the `wp()` function to allow you to do this.

Usage:

```php
wp('command');
```

E.g. to run `wp core version`

```php
wp('core version');
```

This automatically sets the current environment using the `stage` variable. You can pass this manually as the second param:

```php
wp('core version', 'staging');
```

## Run Composer

If you need to run Composer in the root folder add `deploy:vendors` to the deploy task in your `deploy.php` file:

```php
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'deploy:publish',
]);
```

To run Composer in a sub-folder (which isn't recommended)

```php
// Custom (non-root) composer installs
set('composer_paths', [
'web/wp-content/plugins/s24-wp-image-optimiser'
]);
```
35 changes: 34 additions & 1 deletion recipe/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Deployer;

require_once 'recipe/wordpress.php';
require_once 'recipe/common.php';
require_once __DIR__ . '/common.php';

// Shared files that need to persist between deployments
Expand Down Expand Up @@ -36,3 +36,36 @@
'shared/web/wp-content/uploads/' => 'web/wp-content/uploads'
],
]);

// WordPress core folder
set('wordpress_core_folder', 'web/wordpress/');

// Download WordPress Core files
task('deploy:download_wordpress', function() {
$path = "{{release_path}}/{{wordpress_core_folder}}";

// @see https://developer.wordpress.org/cli/commands/core/download/
wp('core download --skip-content --path=' . $path);

writeln('Downloaded WordPress version:');
wp('core version');
});
after('deploy:update_code', 'deploy:download_wordpress');

/**
* Run WP CLI
*
* @param string $command wp command, e.g. core download
* @param ?string $stage environment, e.g. production. Defaults to the current stage name
* @return void
* @throws Exception\Exception
* @throws Exception\RunException
* @throws Exception\TimeoutException
*/
function wp(string $command, ?string $stage = null)
{
if (null === $stage) {
$stage = get('stage', 'production');
}
run(sprintf('WP_ENV=%s wp %s', $stage, $command), real_time_output: true);
}