Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
PluginStatus
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 check
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2namespace NewfoldLabs\WP\Module\Patterns\Data;
3
4/**
5 * Class PluginStatus
6 *
7 * Provides utility methods to check the installation and activation status of WordPress plugins.
8 *
9 * @package NewfoldLabs\WP\Module\Patterns\Data
10 */
11class PluginStatus {
12
13    /**
14     * Check the status of a plugin.
15     *
16     * @param string $slug Plugin slug, e.g., 'jetpack/jetpack.php'.
17     * @return string Plugin status: 'installed', 'active', 'inactive', or 'not_installed'.
18     */
19    public static function check( $slug ) {
20
21        // Check if the plugin is installed
22        if ( ! array_key_exists( $slug, get_plugins() ) ) {
23            return 'not_installed';
24        }
25
26        // Check if the plugin is active
27        if ( is_plugin_active( $slug ) ) {
28            return 'active';
29        }
30
31        // The plugin is installed but inactive
32        return 'inactive';
33    }
34}