Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active January 24, 2017 16:59
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
[WordPress] Stop Plugin Execution Without a Dependency
<?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;
}
}
<?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