WordPress
.env Files
composer require vlucas/phpdotenv Create .env file in the root directory and add it to your .gitignore.
// .env
WORDPRESS_ENV=development
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PREFIX=
// wp-config.php
require __DIR__ . "/vendor/autoload.php";
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
defined('WORDPRESS_ENV') or define('WORDPRESS_ENV', $_ENV['WORDPRESS_ENV']);
defined('DB_NAME') or define('DB_NAME', $_ENV['DB_NAME']);
defined('DB_USER') or define('DB_USER', $_ENV['DB_USER']);
defined('DB_PASSWORD') or define('DB_PASSWORD', $_ENV['DB_PASSWORD']);
defined('DB_HOST') or define('DB_HOST', $_ENV['DB_HOST']);
$table_prefix = $_ENV['DB_PREFIX'];
Add wp-config.php to Git control.
Installing Sage
composer create-project roots/sage {THEME_NAME}
Expose ACF to Blade templates
// app/Controllers/App.php
protected $acf = true;
Tidy up unused scripts and styles
// app/setup.php
add_action('wp_enqueue_scripts', function () {
// remove jQuery from dependency
wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), null, null, true);
if( !is_admin() ) {
wp_deregister_script('jquery');
}
wp_dequeue_style( 'wp-block-library' );
}, 100);
Extending WordPress API
// create rest api file to contain updates and add to app/resources/functions.php array
add_action('rest_api_init', function () {
register_rest_field('{API_EDNPOINT}', '{NEW_FIELD_NAME}', array(
'get_callback' => function({API_ENDPOINT_CONTEXT}) {
$location_obj = {DEFINE_NEW_FIELD_VALUE};
return (string) $location_obj; // {RETURN UPDATE TO ENDPOINT}
},
));
});