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

Add a class_exists to check if plugin is active (like is callable) #754

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion class-tgm-plugin-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,8 @@ public function register( $plugin ) {
'force_deactivation' => false, // Boolean.
'external_url' => '', // String.
'is_callable' => '', // String|Array.
'class_exists' => '', // String.
'is_defined' => '', // String.
);

// Prepare the received data.
Expand Down Expand Up @@ -1864,7 +1866,10 @@ public function is_plugin_installed( $slug ) {
* @return bool True if active, false otherwise.
*/
public function is_plugin_active( $slug ) {
return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) );
return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) )
|| ( ! empty( $this->plugins[ $slug ]['class_exists'] ) && class_exists( $this->plugins[ $slug ]['class_exists'] ) )
|| ( ! empty( $this->plugins[ $slug ]['is_defined'] ) && defined( $this->plugins[ $slug ]['is_defined'] ) )
|| is_plugin_active( $this->plugins[ $slug ]['file_path'] ) );
}

/**
Expand Down
2 changes: 2 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function my_theme_register_required_plugins() {
'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
'external_url' => '', // If set, overrides default API URL and points to an external URL.
'is_callable' => '', // If set, this callable will be be checked for availability to determine if a plugin is active.
'class_exists' => '', // Same behavior as is_callable, this checks if a class exists to determine if a plugin is active.
'is_defined' => '', // Same behavior as is_callable, this checks if a constant is defined to determine if a plugin is active.
),

// This is an example of how to include a plugin from an arbitrary external source in your theme.
Expand Down