| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Onboarding class |
| 5 |
* |
| 6 |
* @package Give |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Give\Onboarding\Setup; |
| 10 |
|
| 11 |
use Give\Campaigns\CampaignsAdminPage; |
| 12 |
use Give\Framework\Permissions\Facades\UserPermissions; |
| 13 |
|
| 14 |
defined('ABSPATH') || exit; |
| 15 |
|
| 16 |
/** |
| 17 |
* Organizes WordPress actions and helper methods for Onboarding. |
| 18 |
* |
| 19 |
* @since 2.8.0 |
| 20 |
*/ |
| 21 |
class Page |
| 22 |
{ |
| 23 |
|
| 24 |
const ENABLED = 'enabled'; |
| 25 |
const DISABLED = 'disabled'; |
| 26 |
|
| 27 |
/** |
| 28 |
* Dismiss the Setup Page. |
| 29 |
* |
| 30 |
* @since 4.10.0 redirect to campaigns page |
| 31 |
* @since 2.8.0 |
| 32 |
*/ |
| 33 |
public function dismissSetupPage() |
| 34 |
{ |
| 35 |
if (wp_verify_nonce($_GET['_wpnonce'], 'dismiss_setup_page')) { |
| 36 |
give_update_option('setup_page_enabled', self::DISABLED); |
| 37 |
|
| 38 |
wp_redirect(CampaignsAdminPage::getUrl()); |
| 39 |
exit; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Helper method for checking the if the Setup Page is enabled. |
| 45 |
* |
| 46 |
* @since 2.8.0 |
| 47 |
* |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public static function getSetupPageEnabledOrDisabled() |
| 51 |
{ |
| 52 |
return give_get_option('setup_page_enabled', self::DISABLED); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Add Setup submenu page to admin menu |
| 57 |
* |
| 58 |
* @since 4.14.0 update permission capability to use facade |
| 59 |
* @since 2.8.0 |
| 60 |
*/ |
| 61 |
public function add_page() |
| 62 |
{ |
| 63 |
add_submenu_page( |
| 64 |
'edit.php?post_type=give_forms', |
| 65 |
esc_html__('Set up GiveWP', 'give'), |
| 66 |
esc_html__('Setup', 'give'), |
| 67 |
UserPermissions::settings()->manageCap(), |
| 68 |
'give-setup', |
| 69 |
[$this, 'render_page'] |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Enqueue scripts and styles. |
| 75 |
* |
| 76 |
* @since 2.8.0 |
| 77 |
*/ |
| 78 |
public function enqueue_scripts() |
| 79 |
{ |
| 80 |
if (!isset($_GET['page']) || 'give-setup' !== $_GET['page']) { |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
wp_enqueue_style( |
| 85 |
'give-admin-setup-style', |
| 86 |
GIVE_PLUGIN_URL . 'build/assets/dist/css/admin-setup.css', |
| 87 |
[], |
| 88 |
GIVE_VERSION |
| 89 |
); |
| 90 |
wp_enqueue_style('givewp-admin-fonts'); |
| 91 |
wp_enqueue_script( |
| 92 |
'give-admin-setup-script', |
| 93 |
GIVE_PLUGIN_URL . 'build/assets/dist/js/admin-setup.js', |
| 94 |
['jquery'], |
| 95 |
GIVE_VERSION, |
| 96 |
$in_footer = true |
| 97 |
); |
| 98 |
|
| 99 |
wp_enqueue_script( |
| 100 |
'give-admin-add-ons-script', |
| 101 |
GIVE_PLUGIN_URL . 'build/assets/dist/js/admin-add-ons.js', |
| 102 |
['jquery'], |
| 103 |
GIVE_VERSION, |
| 104 |
$in_footer = true |
| 105 |
); |
| 106 |
|
| 107 |
$localized_data = [ |
| 108 |
'notices' => [ |
| 109 |
'invalid_license' => __( 'Sorry, you entered an invalid key.', 'give' ), |
| 110 |
'download_file' => __( 'Success! You have activated your license key and are receiving updates and priority support. <a href="{link}">Click here</a> to download your add-on.', 'give' ), |
| 111 |
'addon_activated' => __( '{pluginName} add-on activated successfully.', 'give' ), |
| 112 |
'addon_activation_error' => __( 'The add-on did not activate successfully.', 'give' ), |
| 113 |
], |
| 114 |
]; |
| 115 |
|
| 116 |
wp_localize_script( 'give-admin-add-ons-script', 'give_addon_var', $localized_data ); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Render the submenu page |
| 121 |
* |
| 122 |
* @since 2.8.0 |
| 123 |
*/ |
| 124 |
public function render_page() |
| 125 |
{ |
| 126 |
$view = give()->make(PageView::class); |
| 127 |
echo $view->render(); |
| 128 |
} |
| 129 |
} |
| 130 |
|