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' ) );
?>
_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 = '';
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(){
?>
Summary
';
$steps = $this->get_steps();
foreach ( $steps as $step ) {
$step_summary = $step->summary( false );
if ( $step_summary ) {
printf( ' | %s |
', esc_html( $step->get_title() ), $step_summary );
}
}
echo '';
}
/**
* @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;
}
}