Add gravity flow demo
This commit is contained in:
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Installation_Wizard
|
||||
*/
|
||||
class Gravity_Flow_Installation_Wizard {
|
||||
|
||||
/**
|
||||
* The installation wizard step class names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_step_class_names = array();
|
||||
|
||||
/**
|
||||
* Gravity_Flow_Installation_Wizard constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$path = gravity_flow()->get_base_path() . '/includes/wizard/steps/';
|
||||
require_once( $path . 'class-iw-step.php' );
|
||||
$classes = array();
|
||||
foreach ( glob( $path . 'class-iw-step-*.php' ) as $filename ) {
|
||||
require_once( $filename );
|
||||
$regex = '/class-iw-step-(.*?).php/';
|
||||
preg_match( $regex, $filename, $matches );
|
||||
$class_name = 'Gravity_Flow_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the step names in the order the steps will appear.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sorted_step_names() {
|
||||
return array(
|
||||
'welcome',
|
||||
'license_key',
|
||||
'updates',
|
||||
'pages',
|
||||
'complete',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the HTML for the current step.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function display() {
|
||||
|
||||
/**
|
||||
* @var Gravity_Flow_Installation_Wizard_Step $current_step The step being displayed.
|
||||
* @var string $nonce_key The nonce key for the current step.
|
||||
*/
|
||||
list( $current_step, $nonce_key ) = $this->get_current_step();
|
||||
$this->include_styles();
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap about-wrap gform_installation_progress_step_wrap">
|
||||
|
||||
<img style="border:0" src="<?php echo gravity_flow()->get_base_url() ?>/images/gravityflow-logo-blue-450.png"/>
|
||||
|
||||
<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(); ?>
|
||||
</div>
|
||||
<?php
|
||||
$next_button = '';
|
||||
if ( $current_step->is( 'pages' ) ) {
|
||||
$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( '<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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the step to be displayed and it's nonce key.
|
||||
*
|
||||
* @return [Gravity_Flow_Installation_Wizard_Step,string]
|
||||
*/
|
||||
public function get_current_step() {
|
||||
$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 = $this->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 = $this->get_posted_values();
|
||||
$current_step->update( $posted_values );
|
||||
$validation_result = $current_step->validate( $posted_values );
|
||||
if ( $validation_result === true ) {
|
||||
$next_step = $this->get_next_step( $current_step );
|
||||
if ( $next_step ) {
|
||||
$current_step = $next_step;
|
||||
}
|
||||
}
|
||||
} elseif ( rgpost( '_install' ) ) {
|
||||
$posted_values = $this->get_posted_values();
|
||||
$current_step->update( $posted_values );
|
||||
$validation_result = $current_step->validate( $posted_values );
|
||||
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();
|
||||
}
|
||||
|
||||
return array( $current_step, $nonce_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the admin styles and includes the inline style block.
|
||||
*/
|
||||
public function include_styles() {
|
||||
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min';
|
||||
|
||||
// Register admin styles.
|
||||
wp_register_style( 'gform_admin', GFCommon::get_base_url() . "/css/admin{$min}.css" );
|
||||
wp_print_styles( array( 'jquery-ui-styles', 'gform_admin' ) );
|
||||
?>
|
||||
<style>
|
||||
#gform_installation_progress li {
|
||||
display: inline-block;
|
||||
padding: 10px 20px 10px 0;
|
||||
}
|
||||
|
||||
.gform_installation_progress_current_step {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.gform_installation_progress_step_pending {
|
||||
color: silver;
|
||||
}
|
||||
|
||||
.gform_installation_progress_step_complete {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.gform_installation_progress_step_wrap p {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.about-text input.regular-text {
|
||||
font-size: 19px;
|
||||
padding: 8px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified step.
|
||||
*
|
||||
* @param bool|string $name The step name.
|
||||
*
|
||||
* @return Gravity_Flow_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( 'gravityflow_installation_wizard_' . $name );
|
||||
|
||||
$step = new $this->_step_class_names[$name]( $current_step_values );
|
||||
|
||||
return $step;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous step.
|
||||
*
|
||||
* @param Gravity_Flow_Installation_Wizard_Step $current_step The current step.
|
||||
*
|
||||
* @return bool|Gravity_Flow_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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next step.
|
||||
*
|
||||
* @param Gravity_Flow_Installation_Wizard_Step $current_step The current step.
|
||||
*
|
||||
* @return bool|Gravity_Flow_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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actions to complete the installation such as saving options to the database.
|
||||
*/
|
||||
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( 'gravityflow_pending_installation', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the posted options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML markup for the installation progress.
|
||||
*
|
||||
* @param Gravity_Flow_Installation_Wizard_Step $current_step The current step.
|
||||
* @param bool $echo Indicates if the HTML should be echoed.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index for the current step in the _step_class_names array.
|
||||
*
|
||||
* @param Gravity_Flow_Installation_Wizard_Step $step The current step.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_step_index( $step ) {
|
||||
$i = array_search( $step->get_name(), array_keys( $this->_step_class_names ) );
|
||||
|
||||
return $i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the summary.
|
||||
*/
|
||||
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>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array containing all the steps.
|
||||
*
|
||||
* @return Gravity_Flow_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the values for all steps.
|
||||
*/
|
||||
public function flush_values() {
|
||||
$steps = $this->get_steps();
|
||||
foreach ( $steps as $step ) {
|
||||
$step->flush_values();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard: Completion Step
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Installation_Wizard_Step_Complete
|
||||
*/
|
||||
class Gravity_Flow_Installation_Wizard_Step_Complete extends Gravity_Flow_Installation_Wizard_Step {
|
||||
|
||||
/**
|
||||
* The step name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = 'complete';
|
||||
|
||||
/**
|
||||
* Displays the content for this step.
|
||||
*/
|
||||
public function display() {
|
||||
|
||||
$url = admin_url( 'admin.php?page=gf_edit_forms&view=settings&subview=gravityflow&id=' );
|
||||
|
||||
$forms = GFFormsModel::get_forms();
|
||||
?>
|
||||
<script>
|
||||
(function($) {
|
||||
$(document).ready(function () {
|
||||
$('#add_workflow_step').click(function(){
|
||||
window.location.href = <?php echo json_encode( $url ); ?> + $('#form_id').val();
|
||||
return false;
|
||||
})
|
||||
});
|
||||
})( jQuery );
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.circle{
|
||||
background: #808080;
|
||||
border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
-webkit-border-radius: 50%;
|
||||
color: #ffffff;
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
line-height: 1.6em;
|
||||
margin-right: 5px;
|
||||
text-align: center;
|
||||
width: 1.6em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e( 'Congratulations! Now you can set up your first workflow.', 'gravityflow' );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
if ( ! empty( $forms ) ) : ?>
|
||||
<h4>
|
||||
<span class="circle">1</span>
|
||||
<?php
|
||||
esc_html_e( 'Select a Form to use for your Workflow', 'gravityflow' );
|
||||
?>
|
||||
</h4>
|
||||
<p>
|
||||
<select id="form_id">
|
||||
<?php
|
||||
|
||||
foreach ( $forms as $form ) {
|
||||
printf( '<option value="%d">%s</option>', $form->id, $form->title );
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<h4>
|
||||
<span class="circle">2</span>
|
||||
<?php
|
||||
esc_html_e( 'Add Workflow Steps in the Form Settings', 'gravityflow' );
|
||||
?>
|
||||
</h4>
|
||||
<p>
|
||||
<a id="add_workflow_step" class="button button-primary" href="#" ><?php esc_html_e( 'Add Workflow Steps', 'gravityflow' )?></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<?php
|
||||
$url = admin_url( 'admin.php?page=gf_new_form' );
|
||||
$open_a_tag = sprintf( '<a href="%s">', $url );
|
||||
printf( esc_html__( "Don't have a form you want to use for the workflow? %sCreate a Form%s and add your steps in the Form Settings later.", 'gravityflow' ), $open_a_tag, '</a>' );
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
else :
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
$url = admin_url( 'admin.php?page=gf_new_form' );
|
||||
$open_a_tag = sprintf( '<a href="%s">', $url );
|
||||
printf( esc_html__( '%sCreate a Form%s and then add your Workflow steps in the Form Settings.', 'gravityflow' ), $open_a_tag, '</a>' );
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title for this step.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return esc_html__( 'Installation Complete', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next button label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_next_button_text() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous button label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_previous_button_text() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard: License Key Step
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Installation_Wizard_Step_License_Key
|
||||
*/
|
||||
class Gravity_Flow_Installation_Wizard_Step_License_Key extends Gravity_Flow_Installation_Wizard_Step {
|
||||
|
||||
/**
|
||||
* Is this step required?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $required = true;
|
||||
|
||||
/**
|
||||
* The step name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = 'license_key';
|
||||
|
||||
/**
|
||||
* Displays the content for this step.
|
||||
*/
|
||||
public function display() {
|
||||
|
||||
if ( ! $this->license_key && defined( 'GRAVITY_FLOW_LICENSE_KEY' ) ) {
|
||||
$this->license_key = GRAVITY_FLOW_LICENSE_KEY;
|
||||
}
|
||||
|
||||
?>
|
||||
<p>
|
||||
<?php echo sprintf( esc_html__( 'Enter your Gravity Flow License Key below. Your key unlocks access to automatic updates and support. You can find your key in your purchase receipt or by logging into the %sGravity Flow%s site.', 'gravityflow' ), '<a href="http://www.gravityflow.io">', '</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', 'gravityflow' ); ?>" />
|
||||
<?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 Flow when important bug fixes and security enhancements are released. This can be a serious security risk for your site.", 'gravityflow' ); ?>
|
||||
</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', 'gravityflow' ); ?> <span class="gfield_required">*</span>
|
||||
</label>
|
||||
<?php echo $message ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title for this step.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return esc_html__( 'License Key', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the posted values for this step.
|
||||
*
|
||||
* @param array $posted_values The posted values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate( $posted_values ) {
|
||||
|
||||
$valid_key = true;
|
||||
$terms_accepted = true;
|
||||
$license_key = rgar( $posted_values, 'license_key' );
|
||||
|
||||
if ( empty( $license_key ) ) {
|
||||
$message = esc_html__( 'Please enter a valid license key.', 'gravityflow' ) . '</span>';
|
||||
$this->set_field_validation_result( 'license_key', $message );
|
||||
$valid_key = false;
|
||||
} else {
|
||||
$license_info = gravity_flow()->activate_license( $license_key );
|
||||
if ( empty( $license_info ) || $license_info->license !== 'valid' ) {
|
||||
$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.', 'gravityflow' ) . '</span>';
|
||||
$this->set_field_validation_result( 'license_key', $message );
|
||||
$valid_key = false;
|
||||
}
|
||||
}
|
||||
|
||||
$accept_terms = rgar( $posted_values, 'accept_terms' );
|
||||
if ( ! $valid_key && ! $accept_terms ) {
|
||||
$this->set_field_validation_result( 'accept_terms', __( 'Please accept the terms.', 'gravityflow' ) );
|
||||
$terms_accepted = false;
|
||||
}
|
||||
|
||||
$valid = $valid_key || ( ! $valid_key && $terms_accepted );
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs the license key, if supplied.
|
||||
*/
|
||||
public function install() {
|
||||
if ( $this->license_key ) {
|
||||
$gravityflow = gravity_flow();
|
||||
|
||||
$settings = $gravityflow->get_app_settings();
|
||||
$settings['license_key'] = $this->license_key;
|
||||
gravity_flow()->update_app_settings( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous button label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_previous_button_text() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard: Workflow Pages Step
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Installation_Wizard_Step_Pages
|
||||
*/
|
||||
class Gravity_Flow_Installation_Wizard_Step_Pages extends Gravity_Flow_Installation_Wizard_Step {
|
||||
|
||||
/**
|
||||
* The step name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = 'pages';
|
||||
|
||||
/**
|
||||
* Displays the content for this step.
|
||||
*/
|
||||
public function display() {
|
||||
if ( $this->workflow_pages == '' ) {
|
||||
// First run.
|
||||
$this->workflow_pages = 'admin';
|
||||
};
|
||||
echo '<p>' . esc_html__( "Gravity Flow can be accessed from both the front end of your site and from the built-in WordPress admin pages (Workflow menu). If you want to use your site styles, or if you want to use the one-click approval links, then you'll need to add some pages to your site.", 'gravityflow' ) . '</p>';
|
||||
echo '<p>' . sprintf( esc_html__( 'Would you like to create custom inbox, status, and submit pages now? The pages will contain the %s[gravityflow] shortcode%s enabling assignees to interact with the workflow from the front end of the site.', 'gravityflow' ), '<a href="http://docs.gravityflow.io/article/36-the-shortcode" target="_blank">', '</a>' ) . '</p>';
|
||||
|
||||
?>
|
||||
|
||||
<div>
|
||||
<label>
|
||||
<input type="radio" value="admin" <?php checked( 'admin', $this->workflow_pages ); ?> name="workflow_pages"/>
|
||||
<?php esc_html_e( 'No, use the WordPress Admin (Workflow menu).', 'gravityflow' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
<input type="radio" value="custom" <?php checked( 'custom', $this->workflow_pages ); ?> name="workflow_pages"/>
|
||||
<?php esc_html_e( 'Yes, create inbox, status, and submit pages now.', 'gravityflow' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title for this step.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return esc_html__( 'Workflow Pages', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the plugin settings with the custom page IDs.
|
||||
*/
|
||||
public function install() {
|
||||
if ( $this->workflow_pages == 'custom' ) {
|
||||
$settings = gravity_flow()->get_app_settings();
|
||||
$settings['inbox_page'] = $this->create_page( 'inbox' );
|
||||
$settings['status_page'] = $this->create_page( 'status' );
|
||||
$settings['submit_page'] = $this->create_page( 'submit' );
|
||||
gravity_flow()->update_app_settings( $settings );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new page containing the gravityflow shortcode for the specified page type.
|
||||
*
|
||||
* @param string $page The page type: inbox, status, or submit.
|
||||
*
|
||||
* @return int|string|WP_Error
|
||||
*/
|
||||
public function create_page( $page ) {
|
||||
$post = array(
|
||||
'post_title' => $this->get_page_title( $page ),
|
||||
'post_content' => sprintf( '[gravityflow page="%s"]', $page ),
|
||||
'post_excerpt' => $this->get_page_title( $page ),
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'page',
|
||||
);
|
||||
|
||||
$post_id = wp_insert_post( $post );
|
||||
|
||||
return $post_id ? $post_id : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return page title for the specified page type.
|
||||
*
|
||||
* @param string $page The page type: inbox, status, or submit.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_page_title( $page ) {
|
||||
$titles = array(
|
||||
'inbox' => esc_html__( 'Workflow Inbox', 'gravityflow' ),
|
||||
'status' => esc_html__( 'Workflow Status', 'gravityflow' ),
|
||||
'submit' => esc_html__( 'Submit a Workflow Form', 'gravityflow' ),
|
||||
);
|
||||
|
||||
return $titles[ $page ];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard: Updates Step
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Installation_Wizard_Step_Updates
|
||||
*/
|
||||
class Gravity_Flow_Installation_Wizard_Step_Updates extends Gravity_Flow_Installation_Wizard_Step {
|
||||
|
||||
/**
|
||||
* The step name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = 'updates';
|
||||
|
||||
/**
|
||||
* Displays the content for this step.
|
||||
*/
|
||||
function display() {
|
||||
if ( $this->background_updates == '' ) {
|
||||
// First run.
|
||||
$this->background_updates = 'enabled';
|
||||
};
|
||||
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e( 'Gravity Flow will download important bug fixes, security enhancements and plugin updates automatically. Updates are extremely important to the security of your WordPress site.', 'gravityflow' );
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
|
||||
<?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. A valid license is required for background updates.', 'gravityflow' );
|
||||
?>
|
||||
|
||||
</p>
|
||||
<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', 'gravityflow' ); ?>
|
||||
</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', 'gravityflow' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div id="accept_terms_container" style="display:none;">
|
||||
<div 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><i class="fa fa-exclamation-triangle gf_invalid"></i> <?php _e( 'Are you sure?', 'gravityflow' ); ?>
|
||||
</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.', 'gravityflow' ); ?></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', 'gravityflow' ); ?> <span class="gfield_required">*</span>
|
||||
</label>
|
||||
<?php $this->validation_message( 'accept_terms' ); ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function($) {
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#accept_terms_container').toggle($('#background_updates_disabled').is(':checked'));
|
||||
|
||||
$('#background_updates_disabled').click(function(){
|
||||
$("#accept_terms_container").slideDown();
|
||||
});
|
||||
$('#background_updates_enabled').click(function(){
|
||||
$("#accept_terms_container").slideUp();
|
||||
});
|
||||
})
|
||||
})(jQuery);
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title for this step.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_title() {
|
||||
return esc_html__( 'Background Updates', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the posted values for this step.
|
||||
*
|
||||
* @param array $posted_values The posted values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function validate( $posted_values ) {
|
||||
$valid = true;
|
||||
if ( $this->background_updates == 'disabled' && empty( $this->accept_terms ) ) {
|
||||
$this->set_field_validation_result( 'accept_terms', esc_html__( 'Please accept the terms.', 'gravityflow' ) );
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary content.
|
||||
*
|
||||
* @param bool $echo Indicates if the summary should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function summary( $echo = true ) {
|
||||
$html = $this->background_updates !== 'disabled' ? esc_html__( 'Enabled', 'gravityflow' ) . ' <i class="fa fa-check gf_valid"></i>' : esc_html__( 'Disabled', 'gravityflow' ) . ' <i class="fa fa-times gf_invalid"></i>' ;
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the plugin settings with the value of the background_updates setting.
|
||||
*/
|
||||
function install() {
|
||||
$gravityflow = gravity_flow();
|
||||
|
||||
$settings = $gravityflow->get_app_settings();
|
||||
$settings['background_updates'] = $this->background_updates !== 'disabled';
|
||||
gravity_flow()->update_app_settings( $settings );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard: Welcome Step
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Installation_Wizard_Step_Welcome
|
||||
*/
|
||||
class Gravity_Flow_Installation_Wizard_Step_Welcome extends Gravity_Flow_Installation_Wizard_Step {
|
||||
|
||||
/**
|
||||
* The step name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = 'welcome';
|
||||
|
||||
/**
|
||||
* Displays the content for this step.
|
||||
*/
|
||||
function display() {
|
||||
|
||||
esc_html_e( "Click the 'Get Started' button to complete your installation.", 'gravityflow' );
|
||||
?>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next button label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_next_button_text() {
|
||||
return esc_html__( 'Get Started', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title for this step.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_title() {
|
||||
return esc_html__( 'Welcome', 'gravityflow' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Installation Wizard
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Installation_Wizard
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract class used as the base for all installation wizard steps.
|
||||
*
|
||||
* Class Gravity_Flow_Installation_Wizard_Step
|
||||
*/
|
||||
abstract class Gravity_Flow_Installation_Wizard_Step extends stdClass {
|
||||
|
||||
/**
|
||||
* The step name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = '';
|
||||
|
||||
/**
|
||||
* The field validation results.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_field_validation_results = array();
|
||||
|
||||
/**
|
||||
* The validation summary.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_validation_summary = '';
|
||||
|
||||
/**
|
||||
* The step values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_step_values;
|
||||
|
||||
/**
|
||||
* Gravity_Flow_Installation_Wizard_Step constructor.
|
||||
*
|
||||
* @param array $values The step values.
|
||||
*
|
||||
* @throws Exception When the step name has not been set.
|
||||
*/
|
||||
public function __construct( $values = array() ) {
|
||||
if ( empty( $this->_name ) ) {
|
||||
throw new Exception( 'Name not set' );
|
||||
}
|
||||
$this->_step_values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the step name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the supplied key against the current step name.
|
||||
*
|
||||
* @param string $key The step name.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is( $key ) {
|
||||
return $key == $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the step title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for the specified property.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
* @param mixed $value The property value.
|
||||
*/
|
||||
public function __set( $key, $value ) {
|
||||
$this->_step_values[ $key ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the specified property has been defined.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset( $key ) {
|
||||
return isset( $this->_step_values[ $key ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the specified property.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
*/
|
||||
public function __unset( $key ) {
|
||||
unset( $this->_step_values[ $key ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified property or an empty string for an undefined property.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function &__get( $key ) {
|
||||
if ( ! isset( $this->_step_values[ $key ] ) ) {
|
||||
$this->_step_values[ $key ] = '';
|
||||
}
|
||||
return $this->_step_values[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the values for the current step.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_values() {
|
||||
return $this->_step_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to display content for this step.
|
||||
*/
|
||||
public function display() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to validate the posted values for this step.
|
||||
*
|
||||
* @param array $posted_values The posted values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate( $posted_values ) {
|
||||
// Assign $this->_validation_result;.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validation result for the specified property or an empty string for an undefined property.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_field_validation_result( $key ) {
|
||||
if ( ! isset( $this->_field_validation_results[ $key ] ) ) {
|
||||
$this->_field_validation_results[ $key ] = '';
|
||||
}
|
||||
return $this->_field_validation_results[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the field validation result for the specified property.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
* @param string $text The validation result.
|
||||
*/
|
||||
public function set_field_validation_result( $key, $text ) {
|
||||
$this->_field_validation_results[ $key ] = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the validation summary property.
|
||||
*
|
||||
* @param string $text The validation summary.
|
||||
*/
|
||||
public function set_validation_summary( $text ) {
|
||||
$this->_validation_summary = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validation summary property.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_validation_summary() {
|
||||
return $this->_validation_summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the markup for the validation message.
|
||||
*
|
||||
* @param string $key The property key.
|
||||
* @param bool $echo Indicates if the message should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to determine if the current step has been completed.
|
||||
*/
|
||||
public function is_complete() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next button label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_next_button_text() {
|
||||
return __( 'Next', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous button label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_previous_button_text() {
|
||||
return __( 'Back', 'gravityflow' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the step options in the database and class property.
|
||||
*
|
||||
* @param array $values The step values.
|
||||
*/
|
||||
public function update( $values ) {
|
||||
update_option( 'gravityflow_installation_wizard_' . $this->get_name(), $values );
|
||||
$this->_step_values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to return summary content.
|
||||
*
|
||||
* @param bool $echo Indicates if the summary should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function summary( $echo = true ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to perform actions when the installation wizard is completing.
|
||||
*/
|
||||
public function install() {
|
||||
// Do something.
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this steps values from the database.
|
||||
*/
|
||||
public function flush_values() {
|
||||
delete_option( 'gravityflow_installation_wizard_' . $this->get_name() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
Reference in New Issue
Block a user