Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error when activating a theme or plugin that doesn't exist #1391

Merged
merged 12 commits into from
May 16, 2024
Prev Previous commit
Next Next commit
Merge branch 'trunk' into fix/1347-check-if-exists-before-activating
  • Loading branch information
bgrgicak committed May 16, 2024
commit d416e765f1bd012903e1f0313dc5a6afdc050181
11 changes: 6 additions & 5 deletions packages/playground/blueprints/src/lib/steps/activate-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ require_once( ${phpVar(docroot)}. "/wp-admin/includes/plugin.php" );
wp_set_current_user( get_users(array('role' => 'Administrator') )[0]->ID );

$plugin_path = ${phpVar(pluginPath)};
$response = null;
$response = false;
if (!is_dir($plugin_path)) {
$response = activate_plugin($plugin_path);
}

if (is_null($response)) {
} else {
// A plugin name was provided instead of a path
foreach ( ( glob( $plugin_path . '/*.php' ) ?: array() ) as $file ) {
$info = get_plugin_data( $file, false, false );
if ( ! empty( $info['Name'] ) ) {
Expand All @@ -59,7 +58,9 @@ wp_set_current_user( get_users(array('role' => 'Administrator') )[0]->ID );
}
}

if ( is_wp_error( $response ) || is_null( $response ) ) {
if ( false === $response ) {
throw new Exception( 'Plugin not found' );
}else if ( is_wp_error( $response ) ) {
throw new Exception( $response->get_error_message() );
}

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.