| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Promotions\InPluginUpsells; |
| 4 |
|
| 5 |
use Give\Helpers\EnqueueScript; |
| 6 |
use Give\Helpers\Utils; |
| 7 |
|
| 8 |
class LegacyFormEditor |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* Load scripts |
| 13 |
* |
| 14 |
* @since 2.27.1 |
| 15 |
*/ |
| 16 |
public function loadScripts() |
| 17 |
{ |
| 18 |
$data = [ |
| 19 |
'apiRoot' => esc_url_raw(rest_url('give-api/v2')), |
| 20 |
'apiNonce' => wp_create_nonce('wp_rest'), |
| 21 |
]; |
| 22 |
|
| 23 |
EnqueueScript::make( |
| 24 |
'give-in-plugin-upsells-legacy-form-editor', |
| 25 |
'build/assets/dist/js/donation-options.js' |
| 26 |
) |
| 27 |
->loadInFooter() |
| 28 |
->registerTranslations() |
| 29 |
->registerLocalizeData('GiveLegacyFormEditor', $data) |
| 30 |
->enqueue(); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* |
| 35 |
* @since 2.27.1 |
| 36 |
* |
| 37 |
*/ |
| 38 |
public function renderDonationOptionsRecurringRecommendation() |
| 39 |
{ |
| 40 |
$isDismissed = get_option('givewp_form_editor_donation_options_recurring_recommendation', false); |
| 41 |
$recurringAddonIsActive = Utils::isPluginActive('give-recurring/give-recurring.php'); |
| 42 |
|
| 43 |
if ($recurringAddonIsActive | $isDismissed) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
require_once GIVE_PLUGIN_DIR . 'src/Promotions/InPluginUpsells/resources/views/donation-options-form-editor.php'; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* @since 3.2.1 replaced logic to be give_forms post_type specific |
| 52 |
* @since 2.27.1 |
| 53 |
*/ |
| 54 |
public static function isShowing(): bool |
| 55 |
{ |
| 56 |
global $post, $pagenow; |
| 57 |
|
| 58 |
return $post && |
| 59 |
in_array($pagenow, ['post-new.php', 'post.php'], true) && |
| 60 |
'give_forms' === get_post_type($post); |
| 61 |
} |
| 62 |
} |
| 63 |
|