-
-
Save tommcfarlin/448d580a82b5ac615be127a0786cd3c5 to your computer and use it in GitHub Desktop.
[WordPress] Stop Plugin Execution Without a Dependency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function __construct( $container ) { | |
$this->can_run = true; | |
// If the dependency isn't installed, then add a message and flag execution to stop. | |
$this->messenger = $container->get( 'settings-messenger'); | |
if ( ! class_exists( 'Acme_Dependency' ) ) { | |
$this->messenger->add_error_message( 'The dependency is not installed.' ); | |
$this->can_run = false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function init() { | |
if ( ! $this->can_run ) { | |
return; | |
} | |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment