plugin install

This commit is contained in:
Tony Volpe
2024-06-18 17:29:05 -04:00
parent e1aaedd1ae
commit 41f50eacc4
5880 changed files with 1057631 additions and 39681 deletions

View File

@@ -0,0 +1,158 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Setup_Wizard;
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Service_Provider;
use Gravity_Forms\Gravity_Forms\Embed_Form\Config\GF_Setup_Wizard_Endpoints_Config;
use Gravity_Forms\Gravity_Forms\Setup_Wizard\Config\GF_Setup_Wizard_Config;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
use Gravity_Forms\Gravity_Forms\Setup_Wizard\Config\GF_Setup_Wizard_Config_I18N;
use Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints\GF_Setup_Wizard_Endpoint_Save_Prefs;
use Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints\GF_Setup_Wizard_Endpoint_Validate_License;
use Gravity_Forms\Gravity_Forms\License\GF_License_Service_Provider;
/**
* Class GF_Setup_Wizard_Service_Provider
*
* Service provider for the Setup_Wizard Service.
*
* @package Gravity_Forms\Gravity_Forms\Setup_Wizard;
*/
class GF_Setup_Wizard_Service_Provider extends GF_Service_Provider {
// Configs
const SETUP_WIZARD_CONFIG = 'setup_wizard_config';
const SETUP_WIZARD_ENDPOINTS_CONFIG = 'setup_wizard_endpoints_config';
const SETUP_WIZARD_CONFIG_I18N = 'setup_wizard_config_i18n';
// Endpoints
const SAVE_PREFS_ENDPOINT = 'setup_wizard_save_prefs_endpoint';
const VALIDATE_LICENSE_ENDPOINT = 'setup_wizard_validate_license_endpoint';
/**
* Array mapping config class names to their container ID.
*
* @since
*
* @var string[]
*/
protected $configs = array(
self::SETUP_WIZARD_CONFIG => GF_Setup_Wizard_Config::class,
self::SETUP_WIZARD_ENDPOINTS_CONFIG => GF_Setup_Wizard_Endpoints_Config::class,
self::SETUP_WIZARD_CONFIG_I18N => GF_Setup_Wizard_Config_I18N::class,
);
/**
* Register services to the container.
*
* @since
*
* @param GF_Service_Container $container
*/
public function register( GF_Service_Container $container ) {
// Configs
require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-setup-wizard-config.php' );
require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-setup-wizard-endpoints-config.php' );
require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-setup-wizard-config-i18n.php' );
// Endpoints
require_once( plugin_dir_path( __FILE__ ) . '/endpoints/class-gf-setup-wizard-endpoint-save-prefs.php' );
require_once( plugin_dir_path( __FILE__ ) . '/endpoints/class-gf-setup-wizard-endpoint-validate-license.php' );
$container->add( self::SAVE_PREFS_ENDPOINT, function () {
$api = new \Gravity_Api();
return new GF_Setup_Wizard_Endpoint_Save_Prefs( $api );
} );
$container->add( self::VALIDATE_LICENSE_ENDPOINT, function () use ( $container ) {
return new GF_Setup_Wizard_Endpoint_Validate_License( $container->get( GF_License_Service_Provider::LICENSE_API_CONNECTOR ) );
} );
$this->register_wizard_app( $container );
$this->add_configs( $container );
}
private function register_wizard_app( GF_Service_Container $container ) {
$dev_min = defined( 'GF_SCRIPT_DEBUG' ) && GF_SCRIPT_DEBUG ? '' : '.min';
$args = array(
'app_name' => 'setup_wizard',
'script_name' => 'gform_gravityforms_admin_vendors',
'object_name' => 'gform_admin_config',
'chunk' => './setup-wizard',
'enqueue' => array( $this, 'should_enqueue_setup_wizard' ),
'css' => array(
'handle' => 'setup_wizard_styles',
'src' => \GFCommon::get_base_url() . "/assets/css/dist/setup-wizard{$dev_min}.css",
'deps' => array( 'gform_admin_components' ),
'ver' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? filemtime( \GFCommon::get_base_path() . "/assets/css/dist/setup-wizard{$dev_min}.css" ) : \GFForms::$version,
),
'root_element' => 'setup-wizard',
);
$this->register_app( $args );
}
public function should_enqueue_setup_wizard() {
if ( ! \GFForms::is_gravity_page() ) {
return false;
}
// Don't display on the system status page.
if ( rgget( 'page' ) == 'gf_system_status' ) {
return false;
}
if ( rgget( 'page' ) == 'gf_settings' && rgar( $_COOKIE, GF_Setup_Wizard_Config::INVALID_KEY_COOKIE ) ) {
return false;
}
if ( defined( 'GF_DISPLAY_SETUP_WIZARD' ) && GF_DISPLAY_SETUP_WIZARD ) {
return true;
}
return (bool) get_option( 'gform_pending_installation' );
}
/**
* Initialize any actions or hooks.
*
* @since
*
* @param GF_Service_Container $container
*
* @return void
*/
public function init( GF_Service_Container $container ) {
add_action( 'wp_ajax_' . GF_Setup_Wizard_Endpoint_Save_Prefs::ACTION_NAME, function () use ( $container ) {
$container->get( self::SAVE_PREFS_ENDPOINT )->handle();
} );
add_action( 'wp_ajax_' . GF_Setup_Wizard_Endpoint_Validate_License::ACTION_NAME, function () use ( $container ) {
$container->get( self::VALIDATE_LICENSE_ENDPOINT )->handle();
} );
}
/**
* For each config defined in $configs, instantiate and add to container.
*
* @since
*
* @param GF_Service_Container $container
*
* @return void
*/
private function add_configs( GF_Service_Container $container ) {
foreach ( $this->configs as $name => $class ) {
$container->add( $name, function () use ( $container, $class ) {
return new $class( $container->get( GF_Config_Service_Provider::DATA_PARSER ) );
} );
$container->get( GF_Config_Service_Provider::CONFIG_COLLECTION )->add_config( $container->get( $name ) );
}
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Setup_Wizard\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* Config items for the Installation Wizard I18N
*
* @since 2.7
*/
class GF_Setup_Wizard_Config_I18N extends GF_Config {
/**
* Script handle.
*
* @var string
*/
protected $name = 'gform_admin_config';
/**
* Handle of script to be localized.
*
* @var string
*/
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
/**
* Determine if the config should enqueue its data.
*
* @since 2.7
*
* @return bool
*/
public function should_enqueue() {
return \GFForms::is_gravity_page();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'setup_wizard' => array(
'i18n' => array(
// Buttons.
'next' => __( 'Next', 'gravityforms' ),
'previous' => __( 'Previous', 'gravityforms' ),
'close_button' => __( 'Close', 'gravityforms' ),
'invalid_key' => __( 'Invalid License Key', 'gravityforms' ),
'redirect_prompt' => __( 'Back To Dashboard', 'gravityforms' ),
'toggle_fullscreen' => __( 'Toggle Fullscreen', 'gravityforms' ),
// Screen 01.
'welcome_title' => __( 'Welcome to Gravity Forms', 'gravityforms' ),
'welcome_copy' => __( 'Thank you for choosing Gravity Forms. We know youre going to love our form builder and all it has to offer!', 'gravityforms' ),
'most_accessible' => __( 'Create surveys and quizzes', 'gravityforms' ),
'column_layouts' => __( 'Accept online payments', 'gravityforms' ),
'take_payments' => __( 'Build custom business solutions', 'gravityforms' ),
'enter_license' => __( 'Enter License Key', 'gravityforms' ),
'enter_license_plhdr' => __( 'Paste your license key here', 'gravityforms' ),
'license_instructions' => __( 'Enter your license key below to enable Gravity Forms.', 'gravityforms' ),
'activate_license' => __( 'Activate License', 'gravityforms' ),
'key_validated' => __( 'License Key Validated', 'gravityforms' ),
'check_license' => __( 'Checking License', 'gravityforms' ),
'email_message_title' => __( 'Get 20% Off Gravity Forms!', 'gravityforms' ),
'email_message' => __( 'To continue installation enter your email below and get 20% off any new license.', 'gravityforms' ),
'email_message_plhldr' => __( 'Email address', 'gravityforms' ),
'email_message_submit' => __( 'Get the Discount', 'gravityforms' ),
'email_message_footer' => __( 'I agree to the handling and storage of my data and to receive marketing communications from Gravity Forms.', 'gravityforms' ),
// Screen 02.
'set_up_title' => __( "Let's get you set up!", 'gravityforms' ),
'set_up_copy' => __( 'Configure Gravity Forms to work in the way that you want.', 'gravityforms' ),
'for_client' => __( 'Hide license information', 'gravityforms' ),
'hide_license' => __( 'If you\'re installing Gravity Forms for a client, enable this setting to hide the license information.', 'gravityforms' ),
'enable_updates' => __( 'Enable automatic updates', 'gravityforms' ),
'enable_updates_tag' => __( 'Recommended', 'gravityforms' ),
'enable_updates_locked' => __( 'Feature Disabled', 'gravityforms' ),
'updates_recommended' => __( 'We recommend you enable this feature to ensure Gravity Forms runs smoothly.', 'gravityforms' ),
'which_currency' => __( 'Select a Currency', 'gravityforms' ),
// Screen 03.
'personalize_title' => __( 'Personalize your Gravity Forms experience', 'gravityforms' ),
'personalize_copy' => __( 'Tell us about your site and how youd like to use Gravity Forms.', 'gravityforms' ),
'describe_organization' => __( 'How would you best describe your website?', 'gravityforms' ),
'form_type' => __( 'What types of forms do you want to create?', 'gravityforms' ),
'services_connect' => __( 'Do you want to integrate your forms with any of these services?', 'gravityforms' ),
'other_label' => __( 'Other', 'gravityforms' ),
'other_placeholder' => __( 'Description', 'gravityforms' ),
// Screen 04.
'help_improve_title' => __( 'Help Make Gravity Forms Better!', 'gravityforms' ),
// translators: placeholders are markup to create a link.
'help_improve_copy' => sprintf( __( 'We love improving the form building experience for everyone in our community. By enabling data collection, you can help us learn more about how our customers use Gravity Forms. %1$sLearn more...%2$s', 'gravityforms' ), '<a target="_blank" href="https://docs.gravityforms.com/about-additional-data-collection/">', '</a>' ),
'no_thanks_button' => __( 'No, Thanks.' ),
'yes_button' => __( 'Yes, Count Me In.' ),
// Screen 05.
'complete_title' => __( 'Ready to Create Your First Form?', 'gravityforms' ),
'complete_message' => __( 'Watch the video below to help you get started with Gravity Forms, or jump straight in and begin your form building journey!', 'gravityforms' ),
'create_form_button' => __( 'Create Your First Form' ),
),
),
),
);
}
}

View File

@@ -0,0 +1,318 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Setup_Wizard\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* Config items for Setup_Wizard.
*
* @since
*/
class GF_Setup_Wizard_Config extends GF_Config {
const INVALID_KEY_COOKIE = 'gf_setup_wizard_invalid_key';
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
/**
* Determine if the config should enqueue its data.
*
* @since 2.6.2
*
* @return bool
*/
public function should_enqueue() {
return \GFForms::is_gravity_page();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'setup_wizard' => array(
'data' => array(
'dashboard_url' => get_dashboard_url(),
'redirect_url' => get_dashboard_url() . 'admin.php?page=gf_edit_forms',
'video_id' => 'KiYWpQYTD8a1Hbmb19KLKC',
'defaults' => array(
'activeStep' => empty( \GFCommon::get_key() ) ? 1 : 2,
'autoUpdate' => true,
'currency' => 'USD',
'dataCollection' => false,
'email' => '',
'emailConsent' => false,
'formTypes' => $this->get_form_types_options(),
'formTypesOther' => '',
'hideLicense' => false,
'innerDialogOpen' => false,
'isOpen' => true,
'licenseKey' => '',
'organization' => '',
'organizationOther' => '',
'services' => $this->get_services_options(),
'servicesOther' => '',
),
'options' => array(
'currencies' => \RGCurrency::get_grouped_currency_options( false ),
'organization' => $this->get_organization_options(),
'invalidKeyCookieName' => self::INVALID_KEY_COOKIE,
'hasLicense' => ! empty( \GFCommon::get_key() ),
'isSettingsPage' => rgget( 'page' ) == 'gf_settings',
),
'shouldDisplay' => $this->get_should_display(),
),
),
),
);
}
private function get_should_display() {
// Don't display on the system status page.
if ( rgget( 'page' ) == 'gf_system_status' ) {
return false;
}
if ( defined( 'GF_DISPLAY_SETUP_WIZARD' ) && GF_DISPLAY_SETUP_WIZARD ) {
return true;
}
return (bool) get_option( 'gform_pending_installation' );
}
private function get_form_types_options() {
return array(
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Contact Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'contact',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Conversational Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'conversational',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Survey', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'survey',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Payment Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'payment',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Subscription Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'subscription',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Donation Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'donation',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Customer Service Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'customer-service',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Registration Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'registration',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Custom Form', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'custom',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Other', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'other',
),
);
}
private function get_organization_options() {
return array(
array(
'value' => '',
'label' => __( 'Select a Website Type', 'gravityforms' ),
'customOptionAttributes' => array(
'disabled' => true,
),
),
array(
'value' => 'blog',
'label' => __( 'Blog', 'gravityforms' ),
),
array(
'value' => 'personal-business',
'label' => __( 'Personal Business/Services', 'gravityforms' ),
),
array(
'value' => 'small-medium-business',
'label' => __( 'Small/Medium Business', 'gravityforms' ),
),
array(
'value' => 'enterprise',
'label' => __( 'Enterprise', 'gravityforms' ),
),
array(
'value' => 'ecommerce',
'label' => __( 'eCommerce', 'gravityforms' ),
),
array(
'value' => 'education',
'label' => __( 'Education', 'gravityforms' ),
),
array(
'value' => 'nonprofit',
'label' => __( 'Nonprofit', 'gravityforms' ),
),
array(
'value' => 'other',
'label' => __( 'Other', 'gravityforms' ),
),
);
}
private function get_services_options() {
return array(
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Email Marketing Platform', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'email-marketing',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'CRM', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'crm',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Payment Processor', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'payment-processor',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Anti Spam Services', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'anti-spam',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Accounting Software', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'accounting',
),
array(
'initialChecked' => false,
'labelAttributes' => array(
'label' => __( 'Other', 'gravityforms' ),
'size' => 'text-sm',
'weight' => 'regular',
),
'name' => 'form_types',
'size' => 'size-md',
'value' => 'other',
),
);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Embed_Form\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
use Gravity_Forms\Gravity_Forms\Embed_Form\Endpoints\GF_Embed_Endpoint_Create_With_Block;
use Gravity_Forms\Gravity_Forms\Embed_Form\Endpoints\GF_Embed_Endpoint_Get_Posts;
use Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints\GF_Setup_Wizard_Endpoint_Save_Prefs;
use Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints\GF_Setup_Wizard_Endpoint_Validate_License;
/**
* Config items for the Embed Forms REST Endpoints.
*
* @since 2.6
*/
class GF_Setup_Wizard_Endpoints_Config extends GF_Config {
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
protected $name = 'gform_admin_config';
protected $overwrite = false;
/**
* Determine if the config should enqueue its data.
*
* @since 2.6.2
*
* @return bool
*/
public function should_enqueue() {
return \GFForms::is_gravity_page();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'setup_wizard' => array(
'endpoints' => $this->get_endpoints(),
),
),
);
}
/**
* Get the various endpoints for the Embed UI.
*
* @since 2.6
*
* @return array
*/
private function get_endpoints() {
return array(
// Endpoint to validate a license value.
'validate_license' => array(
'action' => array(
'value' => GF_Setup_Wizard_Endpoint_Validate_License::ACTION_NAME,
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( GF_Setup_Wizard_Endpoint_Validate_License::ACTION_NAME ),
'default' => 'nonce',
),
),
// Endpoint to save a series of preferences from the Wizard.
'save_prefs' => array(
'action' => array(
'value' => GF_Setup_Wizard_Endpoint_Save_Prefs::ACTION_NAME,
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( GF_Setup_Wizard_Endpoint_Save_Prefs::ACTION_NAME ),
'default' => 'nonce',
),
),
);
}
}

View File

@@ -0,0 +1,236 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints;
/**
* AJAX Endpoint for saving preferences.
*
* @since 2.7
*
* @package Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints
*/
class GF_Setup_Wizard_Endpoint_Save_Prefs {
// Strings.
const ACTION_NAME = 'gf_setup_wizard_save_prefs';
// Parameters.
const PARAM_ACTIVE_STEP = 'activeStep';
const PARAM_AUTO_UPDATE = 'autoUpdate';
const PARAM_CURRENCY = 'currency';
const PARAM_DATA_COLLECTION = 'dataCollection';
const PARAM_HIDE_LICENSE = 'hideLicense';
const PARAM_IS_OPEN = 'isOpen';
const PARAM_ORGANIZATION = 'organization';
const PARAM_EMAIL = 'email';
const PARAM_EMAIL_CONSENT = 'emailConsent';
const PARAM_FORM_TYPES = 'formTypes';
const PARAM_FORM_TYPES_OTHER = 'formTypesOther';
const PARAM_ORGANIZATION_OTHER = 'organizationOther';
const PARAM_SERVICES = 'services';
const PARAM_SERVICES_OTHER = 'servicesOther';
/**
* @var \Gravity_Api $api
*/
private $api;
public function __construct( \Gravity_Api $api ) {
$this->api = $api;
}
/**
* List of telemetry values to save to DB.
*
* @return string[]
*/
private function telemetry_options_map() {
// Add any additional telemetry items we want to actually save here.
return array(
self::PARAM_AUTO_UPDATE,
self::PARAM_CURRENCY,
self::PARAM_DATA_COLLECTION,
self::PARAM_EMAIL,
self::PARAM_EMAIL_CONSENT,
self::PARAM_FORM_TYPES,
self::PARAM_FORM_TYPES_OTHER,
self::PARAM_HIDE_LICENSE,
self::PARAM_ORGANIZATION,
self::PARAM_ORGANIZATION_OTHER,
self::PARAM_SERVICES,
self::PARAM_SERVICES_OTHER,
);
}
/**
* Remove any setup data, including license and installation values. Currently called when
* plugin is uninstalled.
*
* @since 2.7
*/
public function remove_setup_data() {
foreach( $this->telemetry_options_map() as $key ) {
$option_name = $this->get_option_name( $key );
delete_option( $option_name );
}
}
/**
* Map new settings names to legacy settings names.
*
* @since 2.7
*
* @return string[]
*/
private function legacy_options_map() {
return array(
self::PARAM_AUTO_UPDATE => 'gform_enable_background_updates',
);
}
/**
* Handle the AJAX request.
*
* @since 2.7
*
* @return void
*/
public function handle() {
check_ajax_referer( self::ACTION_NAME );
// Loop through each actual telemetry value we want to save and store it if present.
foreach ( $this->telemetry_options_map() as $name ) {
if ( ! isset( $_POST[ $name ] ) ) {
continue;
}
$value = $this->sanitize_posted_value( rgpost( $name ) );
$option_name = $this->get_option_name( $name );
update_option( $option_name, $value );
}
// Update legacy defaults that we no longer control via the wizard.
$this->handle_legacy();
// Cleanup.
$this->cleanup();
// Save the license key (if set).
$license = rgpost( 'licenseKey' );
if ( $license ) {
\GFFormsModel::update_license_key( md5( $license ) );
}
if ( ! empty( rgpost( self::PARAM_EMAIL ) && ( ! empty( rgpost( self::PARAM_EMAIL_CONSENT ) ) && rgpost( self::PARAM_EMAIL_CONSENT ) != 'false' ) ) ) {
$sent = $this->api->send_email_to_hubspot( rgpost( self::PARAM_EMAIL ) );
if ( is_wp_error( $sent ) ) {
\GFCommon::log_debug( __METHOD__ . '(): error sending setup wizard to hubspot. ' . print_r( $sent, true ) );
}
}
wp_send_json_success( __( 'Preferences updated.', 'gravityforms' ) );
}
/**
* Gets a saved preference by name.
*
* @since 2.7
*
* @param string $param_name The parameter name.
*
* @return string|bool Returns the value of the specified preference.
*/
public function get_value( $param_name ) {
$option_name = $this->get_option_name( $param_name );
$option = get_option( $option_name );
switch ( $param_name ) {
case self::PARAM_AUTO_UPDATE:
case self::PARAM_DATA_COLLECTION:
case self::PARAM_HIDE_LICENSE:
$option = (bool) $option ? 1 : 0;
break;
case self::PARAM_SERVICES:
case self::PARAM_FORM_TYPES:
$option = \GFCommon::is_json( $option ) ? implode( ',', \GFCommon::json_decode( $option ) ) : '';
break;
}
return $option;
}
/**
* Gets the option name that stores the specified parameter.
*
* @since 2.7
*
* @param string $param_name The parameter name.
*
* @return string Returns the name of the option associated with the specified parameter name.
*/
private function get_option_name( $param_name ) {
// Use legacy names if available.
$legacy_options = $this->legacy_options_map();
return isset( $legacy_options[ $param_name ] ) ? $legacy_options[ $param_name ] : sprintf( 'rg_gforms_%s', $param_name );
}
/**
* Values can come from the browser in a variety of types, sanitize them for consistency.
*
* @since 2.7
*
* @param $value
*
* @return bool|mixed|string
*/
private function sanitize_posted_value( $value ) {
if ( $value === 'true' ) {
$value = true;
} elseif ( $value === 'false' ) {
$value = false;
}
if ( is_array( $value ) ) {
$value = json_encode( $value );
}
return $value;
}
/**
* We don't present some legacy options in the Wizard any longer, so we need to manually set the values.
*
* @since 2.7
*
* @return void
*/
private function handle_legacy() {
update_option( 'gform_enable_toolbar_menu', true );
update_option( 'rg_gforms_enable_akismet', true );
update_option( 'gform_enable_noconflict', false );
}
/**
* After the wizard is complete, clean up values.
*
* @since 2.7
*
* @return void
*/
private function cleanup() {
// Tell the system we no longer need to display the wizard.
delete_option( 'gform_pending_installation' );
delete_option( 'rg_gforms_message' );
// Save the version in the DB
update_option( 'rg_form_version', \GFForms::$version, false );
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Setup_Wizard\Endpoints;
use Gravity_Forms\Gravity_Forms\License\GF_License_API_Connector;
/**
* AJAX Endpoint for validating a license key.
*
* @since 2.7
*
* @package Gravity_Forms\Gravity_Forms\Setup_wizard\Endpoints
*/
class GF_Setup_Wizard_Endpoint_Validate_License {
// Strings
const ACTION_NAME = 'gf_setup_wizard_validate_license';
// Parameters
const PARAM_LICENSE = 'license';
/**
* @var GF_License_API_Connector
*/
private $license_api;
public function __construct( GF_License_API_Connector $license_api ) {
$this->license_api = $license_api;
}
/**
* Handle the AJAX request.
*
* @since 2.6
*
* @return void
*/
public function handle() {
check_ajax_referer( self::ACTION_NAME );
$license = rgpost( self::PARAM_LICENSE );
// Check if $license has not alphanumeric values to prevent malformed requests to the API.
if ( ! ctype_alnum( $license ) ) {
return wp_send_json_error( __( 'The license is invalid.', 'gravityforms' ) );
}
$info = $this->license_api->check_license( $license, false );
$is_valid = $info->can_be_used();
if ( ! $is_valid ) {
return wp_send_json_error( $info->get_error_message() );
}
wp_send_json_success( $license );
}
}