plugin install
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class GF_Installation_Wizard {
|
||||
private $_step_class_names = array();
|
||||
|
||||
function __construct(){
|
||||
$path = GFCommon::get_base_path() . '/includes/wizard/steps/';
|
||||
require_once( $path . 'class-gf-installation-wizard-step.php' );
|
||||
$classes = array();
|
||||
$files = GFCommon::glob_require_once( 'class-gf-installation-wizard-step-*.php', $path );
|
||||
|
||||
foreach ( $files as $filename ) {
|
||||
$regex = '/class-gf-installation-wizard-step-(.*?).php/';
|
||||
preg_match( $regex, $filename, $matches );
|
||||
$class_name = 'GF_Installation_Wizard_Step_' . str_replace( '-', '_', $matches[1] );
|
||||
$step = new $class_name;
|
||||
$step_name = $step->get_name();
|
||||
$classes[ $step_name ] = $class_name;
|
||||
}
|
||||
$sorted = array();
|
||||
foreach ( $this->get_sorted_step_names() as $sorted_step_name ){
|
||||
$sorted[ $sorted_step_name ] = $classes[ $sorted_step_name ];
|
||||
}
|
||||
$this->_step_class_names = $sorted;
|
||||
}
|
||||
|
||||
public function get_sorted_step_names(){
|
||||
return array(
|
||||
'license_key',
|
||||
'background_updates',
|
||||
'settings',
|
||||
'complete',
|
||||
);
|
||||
}
|
||||
|
||||
public function display(){
|
||||
|
||||
update_option( 'gform_pending_installation', true );
|
||||
|
||||
$name = rgpost( '_step_name' );
|
||||
|
||||
$current_step = $this->get_step( $name );
|
||||
|
||||
$nonce_key = '_gform_installation_wizard_step_' . $current_step->get_name();
|
||||
|
||||
if ( isset( $_POST[ $nonce_key ] ) && check_admin_referer( $nonce_key, $nonce_key ) ) {
|
||||
|
||||
if ( rgpost( '_previous' ) ) {
|
||||
$posted_values = $current_step->get_posted_values();
|
||||
$current_step->update( $posted_values );
|
||||
$previous_step = $this->get_previous_step( $current_step );
|
||||
if ( $previous_step ) {
|
||||
$current_step = $previous_step;
|
||||
}
|
||||
} elseif ( rgpost( '_next' ) ) {
|
||||
$posted_values = $current_step->get_posted_values();
|
||||
$current_step->update( $posted_values );
|
||||
$validation_result = $current_step->validate();
|
||||
$current_step->update();
|
||||
if ( $validation_result === true ) {
|
||||
$next_step = $this->get_next_step( $current_step );
|
||||
if ( $next_step ) {
|
||||
$current_step = $next_step;
|
||||
}
|
||||
}
|
||||
} elseif ( rgpost( '_install' ) ) {
|
||||
$posted_values = $current_step->get_posted_values();
|
||||
$current_step->update( $posted_values );
|
||||
$validation_result = $current_step->validate();
|
||||
$current_step->update();
|
||||
if ( $validation_result === true ) {
|
||||
$this->complete_installation();
|
||||
$next_step = $this->get_next_step( $current_step );
|
||||
if ( $next_step ) {
|
||||
$current_step = $next_step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nonce_key = '_gform_installation_wizard_step_' . $current_step->get_name();
|
||||
|
||||
}
|
||||
|
||||
// Print admin styles
|
||||
wp_print_styles( array( 'jquery-ui-styles', 'gform_admin', 'gform_settings' ) );
|
||||
|
||||
?>
|
||||
|
||||
<?php GFCommon::gf_header(); ?>
|
||||
|
||||
<div class="wrap about-wrap gform_installation_progress_step_wrap">
|
||||
|
||||
<h1><?php esc_html_e( 'Welcome to Gravity Forms', 'gravityforms' ) ?></h1>
|
||||
|
||||
<div id="gform_installation_progress">
|
||||
<?php $this->progress( $current_step ); ?>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
||||
<br />
|
||||
<h2>
|
||||
<?php echo $current_step->get_title(); ?>
|
||||
</h2>
|
||||
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="_step_name" value="<?php echo esc_attr( $current_step->get_name() ); ?>"/>
|
||||
<?php
|
||||
wp_nonce_field( $nonce_key, $nonce_key );
|
||||
|
||||
$validation_summary = $current_step->get_validation_summary();
|
||||
if ( $validation_summary ) {
|
||||
printf( '<div class="delete-alert alert_red">%s</div>', $validation_summary );
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="about-text">
|
||||
<?php
|
||||
|
||||
$current_step->display( $current_step );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if ( $current_step->is( 'settings' ) ) {
|
||||
$next_button = sprintf( '<input class="button button-primary" type="submit" value="%s" name="_install"/>', esc_attr( $current_step->get_next_button_text() ) );
|
||||
} elseif ( $current_step->is( 'complete' ) ) {
|
||||
|
||||
$next_button = sprintf( '<a class="button button-primary" href="%s">%s</a>', esc_url( admin_url('admin.php?page=gf_new_form') ), esc_attr( $current_step->get_next_button_text() ) );
|
||||
} else {
|
||||
$next_button = sprintf( '<input class="button button-primary" type="submit" value="%s" name="_next"/>', esc_attr( $current_step->get_next_button_text() ) );
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<?php
|
||||
$previous_button_text = $current_step->get_previous_button_text();
|
||||
if ( $previous_button_text ) {
|
||||
$previous_button = $this->get_step_index( $current_step ) > 0 ? '<input name="_previous" class="button button-primary" type="submit" value="' . esc_attr( $previous_button_text ) . '" style="margin-right:30px;" />' : '';
|
||||
echo $previous_button;
|
||||
}
|
||||
echo $next_button;
|
||||
?>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $name
|
||||
*
|
||||
* @return GF_Installation_Wizard_Step
|
||||
*/
|
||||
public function get_step( $name = false ){
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
$class_names = array_keys( $this->_step_class_names );
|
||||
$name = $class_names[0];
|
||||
}
|
||||
|
||||
$current_step_values = get_option( 'gform_installation_wizard_' . $name );
|
||||
|
||||
$step = new $this->_step_class_names[ $name ]( $current_step_values );
|
||||
|
||||
return $step;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $current_step
|
||||
*
|
||||
* @return bool|GF_Installation_Wizard_Step
|
||||
*/
|
||||
public function get_previous_step( $current_step ){
|
||||
$current_step_name = $current_step->get_name();
|
||||
|
||||
$step_names = array_keys( $this->_step_class_names );
|
||||
$i = array_search( $current_step_name, $step_names );
|
||||
|
||||
if ( $i == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$previous_step_name = $step_names[ $i - 1 ];
|
||||
|
||||
return $this->get_step( $previous_step_name );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GF_Installation_Wizard_Step $current_step
|
||||
*
|
||||
* @return bool|GF_Installation_Wizard_Step
|
||||
*/
|
||||
public function get_next_step( $current_step ){
|
||||
$current_step_name = $current_step->get_name();
|
||||
|
||||
$step_names = array_keys( $this->_step_class_names );
|
||||
$i = array_search( $current_step_name, $step_names );
|
||||
|
||||
if ( $i == count( $step_names ) - 1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$next_step_name = $step_names[ $i + 1 ];
|
||||
|
||||
return $this->get_step( $next_step_name );
|
||||
}
|
||||
|
||||
public function complete_installation() {
|
||||
foreach ( array_keys( $this->_step_class_names ) as $step_name ) {
|
||||
$step = $this->get_step( $step_name );
|
||||
$step->install();
|
||||
$step->flush_values();
|
||||
}
|
||||
update_option( 'gform_pending_installation', false );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param GF_Installation_Wizard_Step $current_step
|
||||
* @param bool $echo
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function progress( $current_step, $echo = true ){
|
||||
$html = '<ul id="gform_installation_progress">';
|
||||
$done = true;
|
||||
$current_step_name = $current_step->get_name();
|
||||
foreach ( array_keys( $this->_step_class_names ) as $step_name ) {
|
||||
$class = '';
|
||||
$step = $this->get_step( $step_name );
|
||||
if ( $current_step_name == $step_name ) {
|
||||
$class .= 'gform_installation_progress_current_step ';
|
||||
$done = $step->is('complete') ? true : false;
|
||||
} else {
|
||||
$class .= $done ? 'gform_installation_progress_step_complete' : 'gform_installation_progress_step_pending';
|
||||
}
|
||||
$check = $done ? '<i class="fa fa-check" style="color:green"></i>' : '<i class="fa fa-check" style="visibility:hidden"></i>';
|
||||
|
||||
$html .= sprintf( '<li id="gform_installation_progress_%s" class="%s">%s %s</li>', esc_attr( $step->get_name() ), esc_attr( $class ), esc_html( $step->get_title() ), $check );
|
||||
}
|
||||
$html .= '</ul>';
|
||||
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function get_step_index( $step ){
|
||||
$i = array_search( $step->get_name(), array_keys( $this->_step_class_names ) );
|
||||
return $i;
|
||||
}
|
||||
|
||||
public function summary(){
|
||||
?>
|
||||
|
||||
<h3>Summary</h3>
|
||||
<?php
|
||||
echo '<table class="form-table"><tbody>';
|
||||
$steps = $this->get_steps();
|
||||
foreach ( $steps as $step ) {
|
||||
$step_summary = $step->summary( false );
|
||||
if ( $step_summary ) {
|
||||
printf( '<tr valign="top"><th scope="row"><label>%s</label></th><td>%s</td></tr>', esc_html( $step->get_title() ), $step_summary );
|
||||
}
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GF_Installation_Wizard_Step[]
|
||||
*/
|
||||
public function get_steps() {
|
||||
$steps = array();
|
||||
foreach ( array_keys( $this->_step_class_names ) as $step_name ) {
|
||||
$steps[] = $this->get_step( $step_name );
|
||||
}
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class GF_Upgrade_Wizard {
|
||||
private $_step_class_names = array();
|
||||
|
||||
function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function display(){
|
||||
//not implemented
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
public function display(){
|
||||
|
||||
// register admin styles
|
||||
wp_print_styles( array( 'jquery-ui-styles', 'gform_admin' ) );
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap about-wrap gform_installation_progress_step_wrap">
|
||||
|
||||
<h1><?php esc_html_e( 'Gravity Forms Upgrade', 'gravityforms' ) ?></h1>
|
||||
|
||||
<hr/>
|
||||
|
||||
<h2><?php esc_html_e( 'Database Update Required', 'gravityforms' ); ?></h2>
|
||||
|
||||
<p><?php esc_html_e( 'Gravity Forms has been updated! Before we send you on your way, we have to update your database to the newest version.', 'gravityforms' ); ?></p>
|
||||
<p><?php esc_html_e( 'The database update process may take a little while, so please be patient.', 'gravityforms' ); ?></p>
|
||||
|
||||
<input class="button button-primary" type="submit" value="<?php esc_attr_e( 'Upgrade', 'gravityforms' ) ?>" name="_upgrade"/>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function gform_start_upgrade(){
|
||||
|
||||
gform_message( 'Progress: 0%' );
|
||||
|
||||
//TODO: implement AJAX callbacks for manual upgrade
|
||||
|
||||
jQuery.post(ajaxurl, {
|
||||
action : "gf_upgrade",
|
||||
gf_upgrade : '<?php echo wp_create_nonce( 'gf_upgrade' ); ?>',
|
||||
})
|
||||
.done(function( data ) {
|
||||
gform_success_message();
|
||||
})
|
||||
|
||||
setTimeout( 'gform_check_upgrade_status', 1000 );
|
||||
|
||||
}
|
||||
|
||||
function gform_check_upgrade_status(){
|
||||
|
||||
jQuery.post(ajaxurl, {
|
||||
action : "gf_check_upgrade_status",
|
||||
gf_upgrade_status : '<?php echo wp_create_nonce( 'gf_upgrade_status' ); ?>',
|
||||
})
|
||||
.done(function( data ) {
|
||||
if( data == '100' ){
|
||||
gform_success_message();
|
||||
}
|
||||
else{
|
||||
gform_message( 'Progress: ' + parseInt( data ) + '%' );
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function gform_message( message ){
|
||||
jQuery( '#gform_upgrade_message' ).html( message );
|
||||
}
|
||||
|
||||
function gform_success_message(){
|
||||
gform_message( 'Database upgrade complete' );
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
class GF_Installation_Wizard_Step_Background_Updates extends GF_Installation_Wizard_Step {
|
||||
|
||||
protected $_name = 'background_updates';
|
||||
|
||||
// Defaults
|
||||
public $defaults = array(
|
||||
'background_updates' => 'enabled',
|
||||
'accept_terms' => false,
|
||||
);
|
||||
|
||||
function display() {
|
||||
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e( 'Gravity Forms will download important bug fixes, security enhancements and plugin updates automatically. Updates are extremely important to the security of your WordPress site.', 'gravityforms' );
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<strong>
|
||||
<?php
|
||||
esc_html_e( 'This feature is activated by default unless you opt to disable it below. We only recommend disabling background updates if you intend on managing updates manually.', 'gravityforms' );
|
||||
?>
|
||||
</strong>
|
||||
</p>
|
||||
<?php
|
||||
$license_key_step_settings = get_option( 'gform_installation_wizard_license_key' );
|
||||
$is_valid_license_key = $license_key_step_settings['is_valid_key'];
|
||||
if ( ! $is_valid_license_key ) :
|
||||
?>
|
||||
<p>
|
||||
<strong>
|
||||
<?php esc_html_e( 'Updates will only be available if you have entered a valid License Key', 'gravityforms' ); ?>
|
||||
</strong>
|
||||
</p>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
|
||||
|
||||
<div>
|
||||
<label>
|
||||
<input type="radio" id="background_updates_enabled" value="enabled" <?php checked( 'enabled', $this->background_updates ); ?> name="background_updates"/>
|
||||
<?php esc_html_e( 'Keep background updates enabled', 'gravityforms' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
<input type="radio" id="background_updates_disabled" value="disabled" <?php checked( 'disabled', $this->background_updates ); ?> name="background_updates"/>
|
||||
<?php esc_html_e( 'Turn off background updates', 'gravityforms' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div id="accept_terms_container" style="display:none;">
|
||||
<div id="are_you_sure" style="background: #fff none repeat scroll 0 0;box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);padding: 1px 12px;border-left: 4px solid #dd3d36;margin: 5px 0 15px;display: inline-block;">
|
||||
|
||||
<h3 style="margin-top:0.6em;"><i class="fa fa-exclamation-triangle gf_invalid"></i> <?php _e( 'Are you sure?', 'gravityforms' ); ?>
|
||||
</h3>
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'By disabling background updates your site may not get critical bug fixes and security enhancements. We only recommend doing this if you are experienced at managing a WordPress site and accept the risks involved in manually keeping your WordPress site updated.', 'gravityforms' ); ?></strong>
|
||||
</p>
|
||||
</div>
|
||||
<label>
|
||||
<input type="checkbox" id="accept_terms" value="1" <?php checked( 1, $this->accept_terms ); ?> name="accept_terms"/>
|
||||
<?php esc_html_e( 'I understand and accept the risk of not enabling background updates.', 'gravityforms' ); ?> <span class="gfield_required">*</span>
|
||||
</label>
|
||||
|
||||
<?php $this->validation_message( 'accept_terms' ); ?>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
var backgroundUpdatesDisabled = $('#background_updates_disabled').is(':checked');
|
||||
|
||||
$('#accept_terms_container').toggle(backgroundUpdatesDisabled);
|
||||
|
||||
$('#background_updates_disabled').click(function(){
|
||||
$("#accept_terms_container").slideDown();
|
||||
});
|
||||
$('#background_updates_enabled').click(function(){
|
||||
$('#accept_terms').prop('checked', false);
|
||||
$("#accept_terms_container").slideUp();
|
||||
});
|
||||
})
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
function get_title(){
|
||||
return esc_html__( 'Background Updates', 'gravityforms' );
|
||||
}
|
||||
|
||||
function validate() {
|
||||
$valid = true;
|
||||
if ( $this->background_updates == 'enabled' ) {
|
||||
$this->accept_terms = false;
|
||||
} elseif ( empty( $this->accept_terms ) ) {
|
||||
$this->set_field_validation_result( 'accept_terms', esc_html__( 'Please accept the terms.', 'gravityforms' ) );
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
function summary( $echo = true ){
|
||||
$html = $this->background_updates !== 'disabled' ? esc_html__( 'Enabled', 'gravityforms' ) . ' <i class="fa fa-check gf_valid"></i>' : esc_html__( 'Disabled', 'gravityforms' ) . ' <i class="fa fa-times gf_invalid"></i>' ;
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function install(){
|
||||
|
||||
update_option( 'gform_enable_background_updates', $this->background_updates != 'disabled' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class GF_Installation_Wizard_Step_Complete extends GF_Installation_Wizard_Step {
|
||||
|
||||
protected $_name = 'complete';
|
||||
|
||||
function display() {
|
||||
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e( "Congratulations! Click the 'Create A Form' button to get started.", 'gravityforms' );
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
function get_title(){
|
||||
return esc_html__( 'Installation Complete', 'gravityforms' );
|
||||
}
|
||||
|
||||
function get_next_button_text(){
|
||||
return esc_html__( 'Create A Form', 'gravityforms' );
|
||||
}
|
||||
|
||||
function get_previous_button_text(){
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class GF_Installation_Wizard_Step_License_Key extends GF_Installation_Wizard_Step {
|
||||
public $required = true;
|
||||
|
||||
protected $_name = 'license_key';
|
||||
|
||||
public $defaults = array(
|
||||
'license_key' => '',
|
||||
'accept_terms' => false,
|
||||
);
|
||||
|
||||
function display() {
|
||||
|
||||
if ( ! $this->license_key && defined( 'GF_LICENSE_KEY' ) ) {
|
||||
$this->license_key = GF_LICENSE_KEY;
|
||||
}
|
||||
|
||||
?>
|
||||
<p>
|
||||
<?php echo sprintf( esc_html__( 'Enter your Gravity Forms License Key below. Your key unlocks access to automatic updates, the add-on installer, and support. You can find your key on the My Account page on the %sGravity Forms%s site.', 'gravityforms' ), '<a href="https://www.gravityforms.com">', '</a>' ); ?>
|
||||
|
||||
</p>
|
||||
<div>
|
||||
<input type="text" class="regular-text" id="license_key" value="<?php echo esc_attr( $this->license_key ); ?>" name="license_key" placeholder="<?php esc_attr_e('Enter Your License Key', 'gravityforms'); ?>" />
|
||||
<?php
|
||||
$key_error = $this->validation_message( 'license_key', false );
|
||||
if ( $key_error ) {
|
||||
echo $key_error;
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$message = $this->validation_message( 'accept_terms', false );
|
||||
if ( $message || $key_error || $this->accept_terms ) {
|
||||
?>
|
||||
<p>
|
||||
<?php esc_html_e( "If you don't enter a valid license key, you will not be able to update Gravity Forms when important bug fixes and security enhancements are released. This can be a serious security risk for your site.", 'gravityforms' ); ?>
|
||||
</p>
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" id="accept_terms" value="1" <?php checked( 1, $this->accept_terms ); ?> name="accept_terms" />
|
||||
<?php esc_html_e( 'I understand the risks of not providing a valid license key.', 'gravityforms' ); ?> <span class="gfield_required">*</span>
|
||||
</label>
|
||||
<?php echo $message ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
function get_title() {
|
||||
return esc_html__( 'License Key', 'gravityforms' );
|
||||
}
|
||||
|
||||
function validate() {
|
||||
|
||||
$this->is_valid_key = true;
|
||||
$license_key = $this->license_key;
|
||||
|
||||
if ( empty ( $license_key ) ) {
|
||||
$message = esc_html__( 'Please enter a valid license key.', 'gravityforms' ) . '</span>';
|
||||
$this->set_field_validation_result( 'license_key', $message );
|
||||
$this->is_valid_key = false;
|
||||
} else {
|
||||
$key_info = GFCommon::get_key_info( $license_key );
|
||||
if ( empty( $key_info ) || ( ! $key_info['is_active'] ) ){
|
||||
$message = " <i class='fa fa-times gf_keystatus_invalid'></i> <span class='gf_keystatus_invalid_text'>" . __( 'Invalid or Expired Key : Please make sure you have entered the correct value and that your key is not expired.', 'gravityforms' ) . '</span>';
|
||||
$this->set_field_validation_result( 'license_key', $message );
|
||||
$this->is_valid_key = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->is_valid_key && ! $this->accept_terms ) {
|
||||
$this->set_field_validation_result( 'accept_terms', __( 'Please accept the terms', 'gravityforms' ) );
|
||||
}
|
||||
|
||||
$valid = $this->is_valid_key || ( ! $this->is_valid_key && $this->accept_terms );
|
||||
return $valid;
|
||||
}
|
||||
|
||||
function install() {
|
||||
if ( $this->license_key ) {
|
||||
|
||||
GFFormsModel::save_key( $this->license_key );
|
||||
|
||||
$version_info = GFCommon::get_version_info( false );
|
||||
}
|
||||
}
|
||||
|
||||
function get_previous_button_text() {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
class GF_Installation_Wizard_Step_Settings extends GF_Installation_Wizard_Step {
|
||||
|
||||
protected $_name = 'settings';
|
||||
|
||||
public $defaults = array(
|
||||
'currency' => '',
|
||||
'enable_noconflict' => false,
|
||||
'enable_toolbar_menu' => true,
|
||||
'enable_akismet' => true,
|
||||
);
|
||||
|
||||
function display() {
|
||||
$disabled = apply_filters( 'gform_currency_disabled', false ) ? "disabled='disabled'" : ''
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<label for="gforms_currency"><?php esc_html_e( 'Currency', 'gravityforms' ); ?></label> <?php gform_tooltip( 'settings_currency' ) ?>
|
||||
</th>
|
||||
<td>
|
||||
<?php
|
||||
$disabled = apply_filters( 'gform_currency_disabled', false ) ? "disabled='disabled'" : ''
|
||||
?>
|
||||
|
||||
<select id="gforms_currency" name="currency" <?php echo $disabled ?>>
|
||||
<option value=""><?php esc_html_e( 'Select a Currency', 'gravityforms' ) ?></option>
|
||||
<?php
|
||||
$current_currency = $this->currency;
|
||||
|
||||
foreach ( RGCurrency::get_currencies() as $code => $currency ) {
|
||||
?>
|
||||
<option value="<?php echo esc_attr( $code ) ?>" <?php echo $current_currency == $code ? "selected='selected'" : '' ?>><?php echo esc_html( $currency['name'] ) ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php do_action( 'gform_currency_setting_message', '' ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<label for="gform_enable_noconflict"><?php esc_html_e( 'No-Conflict Mode', 'gravityforms' ); ?></label> <?php gform_tooltip( 'settings_noconflict' ) ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="radio" name="enable_noconflict" value="1" <?php echo $this->enable_noconflict == 1 ? "checked='checked'" : '' ?> id="gform_enable_noconflict" /> <?php esc_html_e( 'On', 'gravityforms' ); ?>
|
||||
<input type="radio" name="enable_noconflict" value="0" <?php echo $this->enable_noconflict == 1 ? '' : "checked='checked'" ?> id="gform_disable_noconflict" /> <?php esc_html_e( 'Off', 'gravityforms' ); ?>
|
||||
<br />
|
||||
<span class="gf_settings_description"><?php esc_html_e( 'Set this to ON to prevent extraneous scripts and styles from being printed on Gravity Forms admin pages, reducing conflicts with other plugins and themes.', 'gravityforms' ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<label for="gform_enable_toolbar_menu"><?php esc_html_e( 'Toolbar Menu', 'gravityforms' ); ?></label> <?php gform_tooltip( 'settings_toolbar_menu' ) ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="radio" name="enable_toolbar_menu" value="1" <?php checked( $this->enable_toolbar_menu, true ); ?> id="gform_enable_toolbar_menu" /> <?php esc_html_e( 'On', 'gravityforms' ); ?>
|
||||
<input type="radio" name="enable_toolbar_menu" value="0" <?php checked( $this->enable_toolbar_menu, false );?> id="gform_disable_toolbar_menu" /> <?php esc_html_e( 'Off', 'gravityforms' ); ?>
|
||||
<br />
|
||||
<span class="gf_settings_description"><?php esc_html_e( 'Set this to ON to display the Forms menu in the WordPress top toolbar. The Forms menu will display the latest ten forms recently opened in the form editor.', 'gravityforms' ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php if ( GFCommon::has_akismet() ) { ?>
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<label for="gforms_enable_akismet"><?php esc_html_e( 'Akismet Integration', 'gravityforms' ); ?></label> <?php gform_tooltip( 'settings_akismet' ) ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="radio" name="enable_akismet" value="1" <?php checked( $this->enable_akismet, true ) ?> id="gforms_enable_akismet" /> <?php esc_html_e( 'Yes', 'gravityforms' ); ?>
|
||||
<input type="radio" name="enable_akismet" value="0" <?php checked( $this->enable_akismet, false ) ?> /> <?php esc_html_e( 'No', 'gravityforms' ); ?>
|
||||
<br />
|
||||
<span class="gf_settings_description"><?php esc_html_e( 'Protect your form entries from spam using Akismet.', 'gravityforms' ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
function get_title() {
|
||||
return esc_html__( 'Global Settings', 'gravityforms' );
|
||||
}
|
||||
|
||||
function install() {
|
||||
update_option( 'gform_enable_noconflict', (bool) $this->enable_noconflict );
|
||||
update_option( 'rg_gforms_enable_akismet', (bool) $this->enable_akismet );
|
||||
update_option( 'rg_gforms_currency', $this->currency );
|
||||
update_option( 'gform_enable_toolbar_menu', (bool) $this->enable_toolbar_menu );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
abstract class GF_Installation_Wizard_Step extends stdClass {
|
||||
|
||||
protected $_name = '';
|
||||
|
||||
protected $_field_validation_results = array();
|
||||
protected $_validation_summary = '';
|
||||
|
||||
public $defaults = array();
|
||||
private $_step_values;
|
||||
|
||||
function __construct( $values = array() ){
|
||||
if ( empty ( $this->_name ) ) {
|
||||
throw new Exception( 'Name not set' );
|
||||
}
|
||||
$this->_step_values = empty ( $values ) ? $this->defaults : $values;
|
||||
}
|
||||
|
||||
function get_name(){
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
function is( $key ) {
|
||||
return $key == $this->get_name();
|
||||
}
|
||||
|
||||
function get_title(){
|
||||
return '';
|
||||
}
|
||||
|
||||
public function __set( $key, $value ) {
|
||||
$this->_step_values[ $key ] = $value;
|
||||
}
|
||||
|
||||
public function __isset( $key ) {
|
||||
return isset( $this->_step_values[ $key ] );
|
||||
}
|
||||
|
||||
public function __unset( $key ) {
|
||||
unset( $this->_step_values[ $key ] );
|
||||
}
|
||||
|
||||
function &__get( $key ){
|
||||
if ( ! isset( $this->_step_values[ $key ] ) ) {
|
||||
$this->_step_values[ $key ] = '';
|
||||
}
|
||||
return $this->_step_values[ $key ];
|
||||
}
|
||||
|
||||
function get_values(){
|
||||
$set_values = $this->_step_values ? $this->_step_values : array();
|
||||
$values = array_merge( $this->defaults, $set_values);
|
||||
return $values;
|
||||
}
|
||||
|
||||
function display(){
|
||||
}
|
||||
|
||||
function validate(){
|
||||
// Assign $this->_validation_result;
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_field_validation_result( $key ){
|
||||
if ( ! isset( $this->_field_validation_results[ $key ] ) ) {
|
||||
$this->_field_validation_results[ $key ] = '';
|
||||
}
|
||||
return $this->_field_validation_results[ $key ];
|
||||
}
|
||||
|
||||
function set_field_validation_result( $key, $text ){
|
||||
$this->_field_validation_results[ $key ] = $text;
|
||||
}
|
||||
|
||||
function set_validation_summary( $text ) {
|
||||
$this->_validation_summary = $text;
|
||||
}
|
||||
|
||||
function get_validation_summary(){
|
||||
return $this->_validation_summary;
|
||||
}
|
||||
|
||||
function validation_message( $key, $echo = true ){
|
||||
$message = '';
|
||||
$validation_result = $this->get_field_validation_result( $key );
|
||||
if ( ! empty ( $validation_result ) ) {
|
||||
|
||||
$message = sprintf( '<div class="validation_message">%s</div>', $validation_result );
|
||||
}
|
||||
|
||||
if ( $echo ) {
|
||||
echo $message;
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
function is_complete(){
|
||||
}
|
||||
|
||||
function get_next_button_text(){
|
||||
return __( 'Next', 'gravityforms' );
|
||||
}
|
||||
|
||||
function get_previous_button_text(){
|
||||
return __( 'Back', 'gravityforms' );
|
||||
}
|
||||
|
||||
function update( $posted_values = array() ){
|
||||
$step_values = $this->get_values();
|
||||
if ( empty ( $step_values ) ) {
|
||||
$step_values = array();
|
||||
}
|
||||
$new_values = array_merge( $step_values, $posted_values );
|
||||
update_option( 'gform_installation_wizard_' . $this->get_name(), $new_values );
|
||||
$this->_step_values = $new_values;
|
||||
}
|
||||
|
||||
function summary( $echo = true ){
|
||||
return '';
|
||||
}
|
||||
|
||||
function install(){
|
||||
// do something
|
||||
}
|
||||
|
||||
function flush_values(){
|
||||
delete_option( 'gform_installation_wizard_' . $this->get_name() );
|
||||
}
|
||||
|
||||
function get_posted_values() {
|
||||
|
||||
$posted_values = stripslashes_deep( $_POST );
|
||||
$values = array();
|
||||
foreach ( $posted_values as $key => $value ) {
|
||||
if ( strpos( $key, '_', 0 ) !== 0 ) {
|
||||
$values[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
$values = array_merge( $this->defaults, $values);
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user