Skip to content

Commit

Permalink
Clean up code to prevent potential null pointer exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wpscholar committed Apr 27, 2023
1 parent 333086a commit 76228a4
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ function unregister( string $name ) {
*/
function activate( string $name ) {

$module = ModuleRegistry::get( $name );
if ( ModuleRegistry::has( $name ) ) {

// Activate module
$module->isActive = true;
options()->set( $name, true );
/** @var Module $module */
$module = ModuleRegistry::get( $name );

// Activate module
$module->isActive = true;
options()->set( $name, true );
}
}

/**
Expand All @@ -51,11 +55,16 @@ function activate( string $name ) {
*/
function deactivate( string $name ) {

$module = ModuleRegistry::get( $name );
if ( ModuleRegistry::has( $name ) ) {

/** @var Module $module */
$module = ModuleRegistry::get( $name );

// Deactivate module
$module->isActive = false;
options()->set( $name, false );
// Deactivate module
$module->isActive = false;
options()->set( $name, false );

}
}

/**
Expand All @@ -66,9 +75,7 @@ function deactivate( string $name ) {
* @return bool
*/
function isActive( string $name ) {
$module = ModuleRegistry::get( $name );

return $module->get( 'isActive', false );
return ModuleRegistry::getActive()->has( $name );
}

/**
Expand Down

0 comments on commit 76228a4

Please sign in to comment.