| 1 |
<?php |
| 2 |
|
| 3 |
namespace Bookit\Helpers; |
| 4 |
|
| 5 |
/** |
| 6 |
* Bookit Clean Helper |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
class AddonHelper { |
| 11 |
|
| 12 |
public static $paymentAddon = 'bookit' ; |
| 13 |
private static $renamedAddonPathes = array( |
| 14 |
'bookit' => array( 'bookit-pro-premium', 'bookit' ), |
| 15 |
); |
| 16 |
|
| 17 |
public static function getInstalledPluginBySlug( string $addonSlug ) { |
| 18 |
$installedPlugins = get_plugins(); |
| 19 |
if ( array_key_exists( $addonSlug, $installedPlugins ) || in_array( $addonSlug, $installedPlugins, true ) ) { |
| 20 |
return $installedPlugins [ $addonSlug ]; |
| 21 |
} |
| 22 |
return array(); |
| 23 |
} |
| 24 |
|
| 25 |
public static function isProPaymentsInstalled() { |
| 26 |
return defined( 'BOOKIT_PRO_VERSION' ) ? 'true' : 'false'; |
| 27 |
} |
| 28 |
|
| 29 |
public static function checkIsInstalledPlugin( string $addonSlug ) { |
| 30 |
$installedPlugins = get_plugins(); |
| 31 |
return array_key_exists( $addonSlug, $installedPlugins ) || in_array( $addonSlug, $installedPlugins, true ) ? 'true' : 'false'; |
| 32 |
} |
| 33 |
|
| 34 |
public static function getAddonDataByName( string $addon ) { |
| 35 |
$classNamespacePart = str_replace( '-', '', ucwords( $addon, '-' ) ); |
| 36 |
$addonClass = sprintf( '%s\Classes\Admin\Base', ucwords( $classNamespacePart ) ); |
| 37 |
$addonPath = $addon; |
| 38 |
if ( self::$paymentAddon == $addon ) { |
| 39 |
foreach ( self::$renamedAddonPathes[ $addon ] as $maybeAddonPath ) { |
| 40 |
if ( file_exists( WP_CONTENT_DIR . sprintf( '/plugins/%s/includes/classes/admin/Base.php', $maybeAddonPath ) ) ) { |
| 41 |
$addonPath = $maybeAddonPath; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if ( ! file_exists( WP_CONTENT_DIR . sprintf( '/plugins/%s/includes/classes/admin/Base.php', $addonPath ) ) ) { |
| 47 |
return array( 'isCanUse' => false ); |
| 48 |
} |
| 49 |
|
| 50 |
if ( is_plugin_active( sprintf( '%s/%s.php', $addonPath, $addon ) ) && FreemiusHelper::get_license( FreemiusHelper::get_addon_id_by_name( $addon ) ) != null ) { |
| 51 |
require_once WP_CONTENT_DIR . sprintf( '/plugins/%s/includes/classes/admin/Base.php', $addonPath ); |
| 52 |
if ( class_exists( $addonClass ) ) { |
| 53 |
return $addonClass::getAddonData(); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
return array( 'isCanUse' => false ); |
| 58 |
} |
| 59 |
} |
| 60 |
|