Skip to content

Commit

Permalink
Set IS_KANA_ENVIRONMENT to true on CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisWiegman committed May 4, 2024
1 parent db0d895 commit 93d2e17
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
34 changes: 32 additions & 2 deletions internal/settings/templates/kana-local-development.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,41 @@
* @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
*/
function action_phpmailer_init( $phpmailer ) {

$phpmailer->isSMTP();
$phpmailer->Host = 'kana-{{ .SiteName }}-mailpit';
$phpmailer->Port = 1025;

}

add_action( 'phpmailer_init', '\KanaCLI\action_phpmailer_init' );

/**
* Login to the WordPress admin automatically when visiting a WordPress admin URL.
*/
function login_to_admin() {
if ( ! getenv('IS_KANA_ENVIRONMENT') === true ) {
return;
}

if ( ! is_admin() || is_user_logged_in() ) {
return;
}

if ( ! function_exists( 'wp_get_environment_type' ) || 'local' !== wp_get_environment_type() ) {
return;
}

$user = wp_signon(
array(
'user_login' => 'admin',
'user_password' => 'password',
'remember' => true,
)
);

if ( ! is_wp_error( $user ) && isset( $_SERVER['REQUEST_URI'] ) ) {
wp_safe_redirect( $_SERVER['REQUEST_URI'] );
exit();
}
}

add_action( 'init', '\KanaCLI\login_to_admin' );
1 change: 1 addition & 0 deletions internal/site/wordpress.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *Site) RunWPCli(command []string, interactive bool, consoleOutput *conso
HostName: fmt.Sprintf("kana-%s-wordpress_cli", s.Settings.Name),
Command: fullCommand,
Env: []string{
"IS_KANA_ENVIRONMENT=true",
fmt.Sprintf("WORDPRESS_DB_HOST=kana-%s-database", s.Settings.Name),
"WORDPRESS_DB_USER=wordpress",
"WORDPRESS_DB_PASSWORD=wordpress",
Expand Down

0 comments on commit 93d2e17

Please sign in to comment.