Skip to content

Commit

Permalink
Add UpdateWordPressPlugin command
Browse files Browse the repository at this point in the history
  • Loading branch information
AzGasim committed Sep 13, 2024
1 parent ba4d08d commit 43e87b2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 29 deletions.
8 changes: 7 additions & 1 deletion config/press.php
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,16 @@
*/

'redirect_index' => env('REDIRECT_INDEX', false),
'redirect_to_wp' => env('REDIRECT_TO_WP', false),
'redirect_login' => env('REDIRECT_LOGIN', false),
'redirect_logout' => env('REDIRECT_LOGOUT', false),
'redirect_editor' => env('REDIRECT_EDITOR', false),
// Deprecated
'redirect_to_wp' => env('REDIRECT_TO_WP', false),
// New
'redirect_after_login' => env('REDIRECT_AFTER_LOGIN', ''),
// Default: '' means: go to Moox Admin
// Frontend: 'frontend' means: go to frontend (currently WordPress)
// Admin: 'wpadmin' means: go to wp-admin

/*
|--------------------------------------------------------------------------
Expand Down
48 changes: 28 additions & 20 deletions packages/press/config/press.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -93,7 +93,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -140,7 +140,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -187,7 +187,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -234,7 +234,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -281,7 +281,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -344,7 +344,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -391,7 +391,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -478,7 +478,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -525,7 +525,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -572,7 +572,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -619,7 +619,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -666,7 +666,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -713,7 +713,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -760,7 +760,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -807,7 +807,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -854,7 +854,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -901,7 +901,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -948,7 +948,7 @@
| Tabs
|--------------------------------------------------------------------------
|
| Define the tabs for the Resource table. They are optional, but
| Define the tabs for the Expiry table. They are optional, but
| pretty awesome to filter the table by certain values.
| You may simply do a 'tabs' => [], to disable them.
|
Expand Down Expand Up @@ -1088,10 +1088,16 @@
*/

'redirect_index' => env('REDIRECT_INDEX', false),
'redirect_to_wp' => env('REDIRECT_TO_WP', false),
'redirect_login' => env('REDIRECT_LOGIN', false),
'redirect_logout' => env('REDIRECT_LOGOUT', false),
'redirect_editor' => env('REDIRECT_EDITOR', false),
// Deprecated
'redirect_to_wp' => env('REDIRECT_TO_WP', false),
// New
'redirect_after_login' => env('REDIRECT_AFTER_LOGIN', ''),
// Default: '' means: go to Moox Admin
// Frontend: 'frontend' means: go to frontend (currently WordPress)
// Admin: 'wpadmin' means: go to wp-admin

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -1127,6 +1133,7 @@
'Author' => serialize(['author' => true]),
'Contributor' => serialize(['contributor' => true]),
'Subscriber' => serialize(['subscriber' => true]),
'No role for this site' => serialize(['' => true]),
],

'wp_user_levels' => [
Expand Down Expand Up @@ -1297,4 +1304,5 @@
],
],
],
'ip_whitelist' => config('user-session.whitelisted_ips'),
];
32 changes: 32 additions & 0 deletions packages/press/src/Commands/UpdateWordPressPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function handle()
$this->welcome();
$this->checkDotenv();
$env = $this->getDotenv();
$this->pressPluginInstall();
$this->updateWpConfig();
$this->sayGoodbye();
}

Expand Down Expand Up @@ -140,6 +142,36 @@ public function pressPluginInstall(): void
File::copyDirectory($pluginSource, $pluginDestination);
}

public function updateWpConfig(): void
{
info('Updating the wp-config.php file...');

$wpPath = env('WP_PATH', '/public/wp');
$fullWpPath = base_path(trim($wpPath, '/'));

$wpconfigPath = $fullWpPath.'/wp-config.php';

$configSource = __DIR__.'/../../wordpress/wp-config.php';
$configDestination = $wpconfigPath;

if (! File::exists($configSource)) {
alert('The source wp-config.php file does not exist.');
exit(1);
}

if (File::exists($configDestination)) {
info('Deleting the existing wp-config.php file...');
File::delete($configDestination);
}

if (File::copy($configSource, $configDestination)) {
info('wp-config.php file updated successfully.');
} else {
alert('Error occurred while copying the wp-config.php file.');
exit(1);
}
}

public function sayGoodbye(): void
{
note('Moox Press WordPress Plugin updated successfully. Enjoy!');
Expand Down
31 changes: 23 additions & 8 deletions packages/press/wordpress/plugins/moox-press/moox-press.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
$redirectLogout = REDIRECT_LOGOUT;
}

if (defined('REDIRECT_AFTER_LOGIN')) {
$redirectAfterLogin = REDIRECT_AFTER_LOGIN;
}

function moox_lock_wp_frontend()
{
global $lockWp;
Expand All @@ -48,14 +52,17 @@ function moox_lock_wp_frontend()

function moox_auth_token()
{

global $authWp;
global $adminSlug;
global $redirectAfterLogin;

if ($authWp === 'true') {

if (isset($_GET['auth_token'])) {
$token = $_GET['auth_token'];
$rememberMe = isset($_GET['remember_me']) && $_GET['remember_me'] === 'true'; // Check for remember me parameter

$parts = explode('.', $token);

if (count($parts) === 2) {
$payload = $parts[0];
$signature = $parts[1];
Expand All @@ -65,20 +72,28 @@ function moox_auth_token()
$user_id = base64_decode($payload);

wp_clear_auth_cookie();
wp_set_auth_cookie($user_id);

if ($rememberMe) {
wp_set_auth_cookie($user_id, true);
} else {
wp_set_auth_cookie($user_id, false);
}
if ($redirectAfterLogin === '') {
wp_redirect('https://'.$_SERVER['SERVER_NAME'].$adminSlug);

wp_redirect(admin_url());
} elseif ($redirectAfterLogin === 'frontend') {
wp_redirect(home_url());

} elseif ($redirectAfterLogin === 'wpadmin') {
wp_redirect(admin_url());
}
exit;

}
}

}

}

}

add_action('init', 'moox_auth_token');

function moox_redirect_logout()
Expand Down
3 changes: 3 additions & 0 deletions packages/press/wordpress/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'ADMIN_SLUG' => getenv('ADMIN_SLUG'),
'LOCK_WP' => getenv('LOCK_WP'),
'AUTH_WP' => getenv('AUTH_WP'),
'REDIRECT_AFTER_LOGIN' => getenv('REDIRECT_AFTER_LOGIN'),
'REDIRECT_INDEX' => getenv('REDIRECT_INDEX'),
'REDIRECT_TO_WP' => getenv('REDIRECT_TO_WP'),
'REDIRECT_LOGIN' => getenv('REDIRECT_LOGIN'),
Expand Down Expand Up @@ -63,6 +64,7 @@
'ADMIN_SLUG' => $_ENV['ADMIN_SLUG'],
'LOCK_WP' => $_ENV['LOCK_WP'],
'AUTH_WP' => $_ENV['AUTH_WP'],
'REDIRECT_AFTER_LOGIN' => $_ENV['REDIRECT_AFTER_LOGIN'],
'REDIRECT_INDEX' => $_ENV['REDIRECT_INDEX'],
'REDIRECT_TO_WP' => $_ENV['REDIRECT_TO_WP'],
'REDIRECT_LOGIN' => $_ENV['REDIRECT_LOGIN'],
Expand Down Expand Up @@ -104,6 +106,7 @@

define('LOCK_WP', isset($env['LOCK_WP']) ? $env['LOCK_WP'] : false);
define('AUTH_WP', isset($env['AUTH_WP']) ? $env['AUTH_WP'] : false);
define('REDIRECT_AFTER_LOGIN', isset($env['REDIRECT_AFTER_LOGIN']) ? $env['REDIRECT_AFTER_LOGIN'] : '');
define('REDIRECT_INDEX', isset($env['REDIRECT_INDEX']) ? $env['REDIRECT_INDEX'] : false);
define('REDIRECT_TO_WP', isset($env['REDIRECT_TO_WP']) ? $env['REDIRECT_TO_WP'] : false);
define('REDIRECT_LOGIN', isset($env['REDIRECT_LOGIN']) ? $env['REDIRECT_LOGIN'] : false);
Expand Down

0 comments on commit 43e87b2

Please sign in to comment.