Skip to content

Commit

Permalink
Merge pull request #2 from moderntribe/fix/generate-htaccess
Browse files Browse the repository at this point in the history
Generates a .htaccess file if missing in the WP root
  • Loading branch information
borkweb authored May 26, 2020
2 parents 0fa87a7 + 43d5cc9 commit 9c772e1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/commands/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

setup_id();

maybe_generate_htaccess();

// Run the command in the Codeception container.
$root = tric_plugins_dir( tric_target( true ) );

Expand Down
2 changes: 2 additions & 0 deletions src/tric.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function setup_tric_env( $root_dir ) {
exit( 1 );
}

maybe_generate_htaccess();

$plugins_dir = getenv( 'TRIC_PLUGINS_DIR' );
if ( empty( $plugins_dir ) ) {
$plugins_dir = root( '_plugins' );
Expand Down
33 changes: 33 additions & 0 deletions src/wordpress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Functions for WordPress specific actions.
*/

namespace Tribe\Test;

/**
* Generates a .htaccess file in the WP root if missing.
*/
function maybe_generate_htaccess() {
$htaccess_path = root( '_wordpress/.htaccess' );
$htaccess = file_get_contents( $htaccess_path );

if ( $htaccess ) {
return;
}

$htaccess = <<< HTACCESS
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
HTACCESS;

file_put_contents( $htaccess_path, $htaccess );
}
1 change: 1 addition & 0 deletions tric
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require_once __DIR__ . '/src/tric.php';
require_once __DIR__ . '/src/docker.php';
require_once __DIR__ . '/src/plugins.php';
require_once __DIR__ . '/src/shell.php';
require_once __DIR__ . '/src/wordpress.php';

use function Tribe\Test\args;
use function Tribe\Test\colorize;
Expand Down

0 comments on commit 9c772e1

Please sign in to comment.