Skip to content

Commit 21e89f5

Browse files
committed
Adding a readme that will be cleaned out by the configuration script
1 parent 1c6b900 commit 21e89f5

File tree

6 files changed

+201
-1
lines changed

6 files changed

+201
-1
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
setup:
2+
php ./configure.php
3+
4+
.PHONY: setup

README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
1+
<!--delete-->
2+
# Create WordPress Project
3+
4+
This is a skeleton WordPress project that can be used to quickly scaffold
5+
WordPress projects that work with Alley's
6+
[create-wordpress-plugin](https://github.com/alleyinteractive/create-wordpress-plugin)
7+
and
8+
[create-wordpress-theme](https://github.com/alleyinteractive/create-wordpress-theme)
9+
starter kits.
10+
11+
This template is rooted at the `wp-content` and supports both Pantheon and
12+
WordPress VIP hosting environments with deployment workflows for each. It is
13+
powered by [Composer](https://getcomposer.org/) to manage dependencies and
14+
[Turborepo](https://turbo.build/repo) to build front-end assets in your project. The template includes both GitHub Actions and Buddy workflows for continuous integration and deployment.
15+
16+
Also included is a configuration script to easily replace all placeholders throughout the project and scaffold out your plugin/theme.
17+
18+
## Getting Started
19+
20+
Follow these steps to get started:
21+
22+
1. Press the "Use template" button at the top of this repo to create a new repo
23+
with the contents of this skeleton.
24+
2. Run `make` (or `php ./configure.php`) to run the configuration script that
25+
will replace all placeholders throughout all the files.
26+
3. Have fun creating your WordPress site! 🎊
27+
28+
<!--/delete-->
29+
130
# create-wordpress-project
2-
A starter structure for the wp-content directory on a new WordPress project.
31+
32+
A skeleton for WordPress projects rooted at `wp-content` using Alley's best
33+
practices for WordPress development.
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Configuration for wp_get_environment_type().
4+
*
5+
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
6+
*
7+
* @package example-project
8+
*/
9+
10+
// Negotiate environment source based on Pantheon/WordPress VIP hosting environment.
11+
$environment_source = '';
12+
if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) ) {
13+
$environment_source = VIP_GO_APP_ENVIRONMENT;
14+
} elseif ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
15+
$environment_source = $_ENV['PANTHEON_ENVIRONMENT'];
16+
}
17+
18+
// Set the environment type to one of the wp_get_environment_type allowed values based on environment config.
19+
$environment_type = match ( $environment_source ) {
20+
'dev', 'preprod', 'test' => 'staging',
21+
'develop' => 'development',
22+
'live', 'production' => 'production',
23+
default => 'local',
24+
};
25+
define( 'WP_ENVIRONMENT_TYPE', $environment_type );
26+
27+
// Don't pollute global scope.
28+
unset( $environment_source, $environment_type );

client-mu-plugins/001-composer.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Composer Autoloader
4+
*
5+
* Load's Composer's autoloader if it exists and prompts the user to install it
6+
* if it doesn't.
7+
*
8+
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
9+
*
10+
* @package example-project
11+
*/
12+
13+
$composer_autoloader_path = dirname( __DIR__ ) . '/vendor/autoload.php';
14+
15+
// Display a friendly error message if Composer is not installed locally.
16+
if ( 'local' === wp_get_environment_type() ) {
17+
if ( ! file_exists( $composer_autoloader_path ) ) {
18+
wp_die(
19+
'Composer is not installed. Please run <code>composer install</code> locally in the <code>wp-content</code> folder for this project.'
20+
);
21+
}
22+
23+
/** @var array{
24+
* config?: array{
25+
* platform?: array{
26+
* php?: string,
27+
* }
28+
* }
29+
* } $composer Composer configuration from composer.json, which may specify the platform PHP version.
30+
*/
31+
$composer = json_decode( file_get_contents( dirname( __DIR__ ) . '/composer.json' ) ?: '', true );
32+
$required_version = $composer['config']['platform']['php'] ?? '8.0.0';
33+
34+
// Display a friendly error message if the wrong PHP version is used locally.
35+
if ( version_compare( PHP_VERSION, $required_version, '<' ) ) {
36+
wp_die(
37+
sprintf(
38+
'This site requires a PHP version >= %s. You are running %s. Please switch to <code>%s</code> on your machine.',
39+
esc_html( $required_version ),
40+
PHP_VERSION,
41+
esc_html( $required_version ),
42+
),
43+
);
44+
}
45+
46+
// Unset all variables to prevent any external usage.
47+
unset( $composer, $required_version );
48+
}
49+
50+
// Load the Composer autoloader or add a notice if it doesn't exist.
51+
if ( file_exists( $composer_autoloader_path ) ) {
52+
require_once $composer_autoloader_path;
53+
} else {
54+
// Include an error notice.
55+
add_action(
56+
'admin_notices',
57+
function() {
58+
if ( 'local' === wp_get_environment_type() ) {
59+
printf(
60+
'<div class="notice notice-error"><p>%s</p></div>',
61+
esc_html( 'Composer needs to be installed for the site.' )
62+
);
63+
} else {
64+
printf(
65+
'<div class="notice notice-error"><p>%s</p></div>',
66+
esc_html( 'Composer is not installed on the site! Please contact the site administrator.' )
67+
);
68+
}
69+
}
70+
);
71+
}
72+
73+
// Don't pollute global scope.
74+
unset( $composer_autoloader_path );

client-mu-plugins/index.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Silence is golden.

client-mu-plugins/plugin-loader.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Must-use plugin loader for example-project.
4+
*
5+
* @package example-project
6+
*/
7+
8+
/**
9+
* Returns a list of plugin main file paths (under the plugins directory) to load via code.
10+
*
11+
* @return string[]
12+
*/
13+
function create_wordpress_project_core_plugins(): array {
14+
return [
15+
// 'example-project/example-project.php',
16+
];
17+
}
18+
19+
// Load as many standard plugins via code as possible.
20+
foreach ( create_wordpress_project_core_plugins() as $plugin ) {
21+
$plugin_path = dirname( __DIR__ ) . '/plugins/' . $plugin;
22+
23+
if ( 0 === validate_file( $plugin_path ) && file_exists( $plugin_path ) ) {
24+
require_once dirname( __DIR__ ) . '/plugins/' . $plugin;
25+
}
26+
}
27+
28+
/**
29+
* Ensure code activated plugins are shown as such on core plugins screens.
30+
*
31+
* @link https://github.com/Automattic/vip-go-mu-plugins/blob/2414bba6ec4ed582eb31c27e3990c9e3ed42dbd1/vip-plugins/vip-plugins.php#L153
32+
*
33+
* @param array{
34+
* activate?: string,
35+
* deactivate?: string,
36+
* delete?: string,
37+
* network_active?: string,
38+
* } $actions An array of plugin action links.
39+
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
40+
*
41+
* @return array{
42+
* activate?: string,
43+
* deactivate?: string,
44+
* delete?: string,
45+
* network_active?: string,
46+
* create_wordpress_project_code_activated_plugin?: string,
47+
* } Modified list of plugin action links.
48+
*/
49+
function create_wordpress_project_plugin_action_links( array $actions, string $plugin_file ): array {
50+
if ( in_array( $plugin_file, create_wordpress_project_core_plugins(), true ) ) {
51+
unset( $actions['activate'] );
52+
unset( $actions['deactivate'] );
53+
unset( $actions['delete'] );
54+
unset( $actions['network_active'] );
55+
$actions['create_wordpress_project_code_activated_plugin'] = 'Enabled via code';
56+
}
57+
58+
return $actions;
59+
}
60+
add_filter( 'plugin_action_links', 'create_wordpress_project_plugin_action_links', 10, 2 );
61+
add_filter( 'network_admin_plugin_action_links', 'create_wordpress_project_plugin_action_links', 10, 2 );

0 commit comments

Comments
 (0)