Categorias:

Função para detectar se um plugin existe no WordPress

A função para detectar se um plugin existe:

/**
 * Detect active plugin by class, function or constant existence.
 *
 * @author Difluir
 * @link https://code.difluir.com/
 *
 * @param array $plugins Array of array for constants, classes and / or functions to check for plugin existence.
 * @return bool True if plugin exists or false if plugin constant, class or function not detected.
 */
if ( ! function_exists('difluir_detect_plugin') ) :
	function difluir_detect_plugin( array $plugins ) {
		// Check for classes.
		if ( isset( $plugins['classes'] ) ) {
			foreach ( $plugins['classes'] as $name ) {
				if ( class_exists( $name ) ) {
					return true;
				}
			}
		}

		// Check for functions.
		if ( isset( $plugins['functions'] ) ) {
			foreach ( $plugins['functions'] as $name ) {
				if ( function_exists( $name ) ) {
					return true;
				}
			}
		}

		// Check for constants.
		if ( isset( $plugins['constants'] ) ) {
			foreach ( $plugins['constants'] as $name ) {
				if ( defined( $name ) ) {
					return true;
				}
			}
		}

		// No class, function or constant found to exist.
		return false;
	}
endif;

Verificando se um plugin existe:

$seo_plugin_exist = difluir_detect_plugin(
	// Add to this array to add new plugin checks.
	[
		// Classes to detect.
		'classes'   => [
			'All_in_One_SEO_Pack',
			'All_in_One_SEO_Pack_p',
			'HeadSpace_Plugin',
			'Platinum_SEO_Pack',
			'wpSEO',
			'SEO_Ultimate',
		],
		// Functions to detect.
		'functions' => [
			'aioseo',
			'wpseo_activate'
		],
		// Constants to detect.
		'constants' => [
			'WPSEO_VERSION',
			'SEOPRESS_VERSION'
		],
	]
);

if ( $seo_plugin_exist == true ) {
	echo 'SEO plugin exist.';
} else {
	echo 'None SEO plugin.';
}