| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* SimplyBook pattern replacement. |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace Extendify\Shared\Services\PluginDependencies; |
| 8 |
|
| 9 |
use Extendify\Constants; |
| 10 |
use Extendify\PartnerData; |
| 11 |
use Extendify\Shared\Services\HttpClient; |
| 12 |
use Extendify\Shared\Services\Sanitizer; |
| 13 |
|
| 14 |
defined('ABSPATH') || die('No direct access.'); |
| 15 |
|
| 16 |
/** |
| 17 |
* SimplyBook pattern replacement class. |
| 18 |
*/ |
| 19 |
|
| 20 |
class SimplyBook |
| 21 |
{ |
| 22 |
/** |
| 23 |
* The plugin slug. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
public static $slug = 'simplybook/simplybook.php'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Replace the placeholder for SimplyBook. |
| 31 |
* |
| 32 |
* @param mixed $code - The code data. |
| 33 |
* @param string $key - The plugin key. |
| 34 |
* @param string $newCode - The plugin pattern code. |
| 35 |
* @return mixed |
| 36 |
*/ |
| 37 |
public static function create($code, $key, $newCode) |
| 38 |
{ |
| 39 |
if ($key !== 'simple' || !preg_match('/\[simplybook_widget\]|wp:simplybook\/widget/m', $newCode)) { |
| 40 |
return $code; |
| 41 |
} |
| 42 |
|
| 43 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 44 |
|
| 45 |
// If the plugin is already installed and active, we don't need to install it again. |
| 46 |
if (!is_plugin_active(self::$slug)) { |
| 47 |
$response = PluginInstaller::installPlugin('simplybook', self::$slug); |
| 48 |
if (is_wp_error($response)) { |
| 49 |
return $response; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
return $newCode; |
| 54 |
} |
| 55 |
|
| 56 |
public static function getIndustryCode() |
| 57 |
{ |
| 58 |
if (!empty(\get_option('extendify_simplybook_data', []))) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
$response = HttpClient::post(Constants::AI_HOST . '/api/plugins/simplybook', [ |
| 63 |
'params' => [ |
| 64 |
'title' => \get_bloginfo('name'), |
| 65 |
'wpLanguage' => \get_locale(), |
| 66 |
'version' => \Extendify\Config::$version, |
| 67 |
'siteProfile' => \get_option('extendify_site_profile', []), |
| 68 |
'siteId' => \get_option('extendify_site_id', ''), |
| 69 |
'partnerId' => PartnerData::$id, |
| 70 |
'devbuild' => (bool) is_readable(EXTENDIFY_PATH . '.devbuild'), |
| 71 |
] |
| 72 |
], null, true); |
| 73 |
|
| 74 |
if (empty($response['response'])) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
\update_option('extendify_simplybook_data', Sanitizer::sanitizeUnknown($response['response'] ?? []), false); |
| 79 |
|
| 80 |
return; |
| 81 |
} |
| 82 |
} |
| 83 |
|