| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Helper |
| 4 |
* |
| 5 |
* @package Packetery\Module |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
|
| 11 |
namespace Packetery\Module; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class Helper |
| 15 |
* |
| 16 |
* @package Packetery\Module |
| 17 |
*/ |
| 18 |
class Helper { |
| 19 |
|
| 20 |
/** |
| 21 |
* Tells if plugin is active. |
| 22 |
* |
| 23 |
* @param string $pluginRelativePath Relative path of plugin bootstrap file. |
| 24 |
* |
| 25 |
* @return bool |
| 26 |
*/ |
| 27 |
public static function isPluginActive( string $pluginRelativePath ): bool { |
| 28 |
if ( is_multisite() ) { |
| 29 |
$plugins = get_site_option( 'active_sitewide_plugins' ); |
| 30 |
if ( isset( $plugins[ $pluginRelativePath ] ) ) { |
| 31 |
return true; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
if ( ! function_exists( 'get_mu_plugins' ) ) { |
| 36 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 37 |
} |
| 38 |
|
| 39 |
$muPlugins = get_mu_plugins(); |
| 40 |
if ( isset( $muPlugins[ $pluginRelativePath ] ) ) { |
| 41 |
return true; |
| 42 |
} |
| 43 |
|
| 44 |
return in_array( $pluginRelativePath, (array) get_option( 'active_plugins', [] ), true ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Introduced as ManageWP Worker plugin hack fix. |
| 49 |
* |
| 50 |
* @return void |
| 51 |
*/ |
| 52 |
public static function transformGlobalCookies(): void { |
| 53 |
if ( empty( $_COOKIE ) ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
foreach ( $_COOKIE as $key => $value ) { |
| 57 |
// @codingStandardsIgnoreStart |
| 58 |
if ( is_int( $value ) ) { |
| 59 |
$_COOKIE[ $key ] = (string) $value; |
| 60 |
} |
| 61 |
// @codingStandardsIgnoreEnd |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Renders string. |
| 67 |
* |
| 68 |
* @param string $string String to render. |
| 69 |
* |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
public static function renderString( string $string ): void { |
| 73 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 74 |
echo $string; |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|