Skip to main content

Get Plugin Status

PropertyValue
descriptionCheck whether a plugin is active by main plugin file path.
tagslib, php, wp, oop
rating

Overview

Check whether a plugin is active from procedural snippets, templates, or utility classes. The generic helper accepts a plugin main-file path, and the explicit helpers cover common plugins used in our builds.

The generic check supports normal and network-active plugins on multisite installs. The procedural variant is designed for copy-paste use in functions.php; the OOP variant is a namespaced utility class.

Variants

<?php
/**
* Plugin status helpers.
*/

/**
* Generic plugin active check.
*
* @param string $plugin_file Plugin main file path.
* @return bool
*/
if ( ! function_exists( 'mac_is_plugin_active' ) ) {

function mac_is_plugin_active( string $plugin_file ): bool {

$plugin_file = ltrim( $plugin_file, '/' );

if ( $plugin_file === '' ) {
return false;
}

/** @var array<string,bool> $cache */
static $cache = [];

if ( isset( $cache[ $plugin_file ] ) ) {
return $cache[ $plugin_file ];
}

if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

if ( function_exists( 'is_plugin_active' ) && is_plugin_active( $plugin_file ) ) {
return $cache[ $plugin_file ] = true;
}

if ( is_multisite() && function_exists( 'is_plugin_active_for_network' ) ) {
if ( is_plugin_active_for_network( $plugin_file ) ) {
return $cache[ $plugin_file ] = true;
}
}

$site_active = (array) get_option( 'active_plugins', [] );
$net_active = (array) get_site_option( 'active_sitewide_plugins', [] );

return $cache[ $plugin_file ] = in_array( $plugin_file, $site_active, true )
|| isset( $net_active[ $plugin_file ] );
}
}

/**
* Explicit plugin status helpers.
*/

// All-in-One WP Migration
if ( ! function_exists( 'mac_is_all_in_one_wp_migration_active' ) ) {
function mac_is_all_in_one_wp_migration_active(): bool {
return mac_is_plugin_active( 'all-in-one-wp-migration/all-in-one-wp-migration.php' )
|| mac_is_plugin_active( 'all-in-one-wp-migration-unlimited-extension/all-in-one-wp-migration-unlimited-extension.php' );
}
}

// Advanced Custom Fields
if ( ! function_exists( 'mac_is_advanced_custom_fields_active' ) ) {
function mac_is_advanced_custom_fields_active(): bool {
return mac_is_plugin_active( 'advanced-custom-fields/acf.php' )
|| mac_is_plugin_active( 'advanced-custom-fields-pro/acf.php' );
}
}

// Admin Columns
if ( ! function_exists( 'mac_is_admin_columns_active' ) ) {
function mac_is_admin_columns_active(): bool {
return mac_is_plugin_active( 'admin-columns-pro/admin-columns-pro.php' );
}
}

// Etch
if ( ! function_exists( 'mac_is_etch_active' ) ) {
function mac_is_etch_active(): bool {
return mac_is_plugin_active( 'etch/etch.php' ) || class_exists( '\Etch\Plugin' );
}
}

// Automatic.CSS
if ( ! function_exists( 'mac_is_automatic_css_active' ) ) {
function mac_is_automatic_css_active(): bool {
return mac_is_plugin_active( 'automaticcss-plugin/automaticcss-plugin.php' );
}
}

// Frames
if ( ! function_exists( 'mac_is_frames_active' ) ) {
function mac_is_frames_active(): bool {
return mac_is_plugin_active( 'frames-plugin/frames-plugin.php' );
}
}

// CommandUI
if ( ! function_exists( 'mac_is_commandui_active' ) ) {
function mac_is_commandui_active(): bool {
return mac_is_plugin_active( 'commandui/commandui.php' );
}
}

// Perfmatters
if ( ! function_exists( 'mac_is_perfmatters_active' ) ) {
function mac_is_perfmatters_active(): bool {
return mac_is_plugin_active( 'perfmatters/perfmatters.php' );
}
}

// Rank Math SEO
if ( ! function_exists( 'mac_is_rank_math_active' ) ) {
function mac_is_rank_math_active(): bool {
return mac_is_plugin_active( 'seo-by-rank-math/rank-math.php' )
|| mac_is_plugin_active( 'seo-by-rank-math-pro/rank-math-pro.php' );
}
}

// ShortPixel
if ( ! function_exists( 'mac_is_shortpixel_active' ) ) {
function mac_is_shortpixel_active(): bool {
return mac_is_plugin_active( 'shortpixel-image-optimizer/shortpixel-plugin.php' );
}
}

// WS Form
if ( ! function_exists( 'mac_is_ws_form_active' ) ) {
function mac_is_ws_form_active(): bool {
return mac_is_plugin_active( 'ws-form/ws-form.php' )
|| mac_is_plugin_active( 'ws-form-pro/ws-form.php' );
}
}

// WP Grid Builder
if ( ! function_exists( 'mac_is_wp_grid_builder_active' ) ) {
function mac_is_wp_grid_builder_active(): bool {
return mac_is_plugin_active( 'wp-grid-builder/wp-grid-builder.php' );
}
}

// Meta Box
if ( ! function_exists( 'mac_is_meta_box_active' ) ) {
function mac_is_meta_box_active(): bool {
return mac_is_plugin_active( 'meta-box/meta-box.php' )
|| mac_is_plugin_active( 'meta-box-aio/meta-box-aio.php' );
}
}

// MotionPage
if ( ! function_exists( 'mac_is_motionpage_active' ) ) {
function mac_is_motionpage_active(): bool {
return mac_is_plugin_active( 'motionpage/motionpage.php' );
}
}

// Patchstack
if ( ! function_exists( 'mac_is_patchstack_active' ) ) {
function mac_is_patchstack_active(): bool {
return mac_is_plugin_active( 'patchstack/patchstack.php' );
}
}

// SureCart
if ( ! function_exists( 'mac_is_surecart_active' ) ) {
function mac_is_surecart_active(): bool {
return mac_is_plugin_active( 'surecart/surecart.php' );
}
}

// SureMembers
if ( ! function_exists( 'mac_is_suremembers_active' ) ) {
function mac_is_suremembers_active(): bool {
return mac_is_plugin_active( 'suremembers/suremembers.php' );
}
}

// SureContact
if ( ! function_exists( 'mac_is_surecontact_active' ) ) {
function mac_is_surecontact_active(): bool {
return mac_is_plugin_active( 'surecontact/surecontact.php' );
}
}

// Ottokit (SureTriggers rebranded)
if ( ! function_exists( 'mac_is_ottokit_active' ) ) {
function mac_is_ottokit_active(): bool {
return mac_is_plugin_active( 'suretriggers/suretriggers.php' );
}
}

// SureTriggers
if ( ! function_exists( 'mac_is_suretriggers_active' ) ) {
function mac_is_suretriggers_active(): bool {
return mac_is_plugin_active( 'suretriggers/suretriggers.php' );
}
}

// Presto Player
if ( ! function_exists( 'mac_is_presto_player_active' ) ) {
function mac_is_presto_player_active(): bool {
return mac_is_plugin_active( 'presto-player-pro/presto-player-pro.php' );
}
}

// Postmark
if ( ! function_exists( 'mac_is_postmark_active' ) ) {
function mac_is_postmark_active(): bool {
return mac_is_plugin_active( 'postmark-approved-wordpress-plugin/postmark-approved-wordpress-plugin.php' );
}
}

// SureMail
if ( ! function_exists( 'mac_is_suremails_active' ) ) {
function mac_is_suremails_active(): bool {
return mac_is_plugin_active( 'suremails/suremails.php' );
}
}

// Fluent SMTP
if ( ! function_exists( 'mac_is_fluent_smtp_active' ) ) {
function mac_is_fluent_smtp_active(): bool {
return mac_is_plugin_active( 'fluent-smtp/fluent-smtp.php' );
}
}