GF_Installation_Wizard

The Gravity Forms GF Installation Wizard class.

Defined (1)

The class is defined in the following location(s).

/includes/wizard/class-gf-installation-wizard.php  
  1. class GF_Installation_Wizard { 
  2. private $_step_class_names = array(); 
  3.  
  4. function __construct() { 
  5. $path = GFCOmmon::get_base_path() . '/includes/wizard/steps/'; 
  6. require_once( $path . 'class-gf-installation-wizard-step.php' ); 
  7. $classes = array(); 
  8. foreach ( glob( $path . 'class-gf-installation-wizard-step-*.php' ) as $filename ) { 
  9. require_once( $filename ); 
  10. $regex = '/class-gf-installation-wizard-step-(.*?).php/'; 
  11. preg_match( $regex, $filename, $matches ); 
  12. $class_name = 'GF_Installation_Wizard_Step_' . str_replace( '-', '_', $matches[1] ); 
  13. $step = new $class_name; 
  14. $step_name = $step->get_name(); 
  15. $classes[ $step_name ] = $class_name; 
  16. $sorted = array(); 
  17. foreach ( $this->get_sorted_step_names() as $sorted_step_name ) { 
  18. $sorted[ $sorted_step_name ] = $classes[ $sorted_step_name ]; 
  19. $this->_step_class_names = $sorted; 
  20.  
  21. public function get_sorted_step_names() { 
  22. return array( 
  23. 'license_key',  
  24. 'background_updates',  
  25. 'settings',  
  26. 'complete',  
  27. ); 
  28.  
  29. public function display() { 
  30.  
  31. $name = rgpost( '_step_name' ); 
  32.  
  33. $current_step = $this->get_step( $name ); 
  34.  
  35. $nonce_key = '_gform_installation_wizard_step_' . $current_step->get_name(); 
  36.  
  37. if ( isset( $_POST[ $nonce_key ] ) && check_admin_referer( $nonce_key, $nonce_key ) ) { 
  38.  
  39. if ( rgpost( '_previous' ) ) { 
  40. $posted_values = $current_step->get_posted_values(); 
  41. $current_step->update( $posted_values ); 
  42. $previous_step = $this->get_previous_step( $current_step ); 
  43. if ( $previous_step ) { 
  44. $current_step = $previous_step; 
  45. } elseif ( rgpost( '_next' ) ) { 
  46. $posted_values = $current_step->get_posted_values(); 
  47. $current_step->update( $posted_values ); 
  48. $validation_result = $current_step->validate(); 
  49. $current_step->update(); 
  50. if ( $validation_result === true ) { 
  51. $next_step = $this->get_next_step( $current_step ); 
  52. if ( $next_step ) { 
  53. $current_step = $next_step; 
  54. } elseif ( rgpost( '_install' ) ) { 
  55. $posted_values = $current_step->get_posted_values(); 
  56. $current_step->update( $posted_values ); 
  57. $validation_result = $current_step->validate(); 
  58. $current_step->update(); 
  59. if ( $validation_result === true ) { 
  60. $this->complete_installation(); 
  61. $next_step = $this->get_next_step( $current_step ); 
  62. if ( $next_step ) { 
  63. $current_step = $next_step; 
  64.  
  65. $nonce_key = '_gform_installation_wizard_step_' . $current_step->get_name(); 
  66.  
  67.  
  68. $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min'; 
  69.  
  70. // register admin styles 
  71. wp_register_style( 'gform_admin', GFCommon::get_base_url() . "/css/admin{$min}.css" ); 
  72. wp_print_styles( array( 'jquery-ui-styles', 'gform_admin' ) ); 
  73.  
  74.  
  75.  
  76. ?> 
  77.  
  78. <div class="wrap about-wrap gform_installation_progress_step_wrap"> 
  79.  
  80. <h1><?php esc_html_e( 'Welcome to Gravity Forms', 'gravityforms' ) ?></h1> 
  81.  
  82. <div id="gform_installation_progress"> 
  83. <?php $this->progress( $current_step ); ?> 
  84. </div> 
  85.  
  86. <hr/> 
  87.  
  88. <br /> 
  89. <h2> 
  90. <?php echo $current_step->get_title(); ?> 
  91. </h2> 
  92.  
  93. <form action="" method="POST"> 
  94. <input type="hidden" name="_step_name" value="<?php echo esc_attr( $current_step->get_name() ); ?>"/> 
  95. <?php 
  96. wp_nonce_field( $nonce_key, $nonce_key ); 
  97.  
  98. $validation_summary = $current_step->get_validation_summary(); 
  99. if ( $validation_summary ) { 
  100. printf( '<div class="delete-alert alert_red">%s</div>', $validation_summary ); 
  101.  
  102. ?> 
  103. <div class="about-text"> 
  104. <?php 
  105.  
  106. $current_step->display( $current_step ); 
  107. ?> 
  108. </div> 
  109. <?php 
  110. if ( $current_step->is( 'settings' ) ) { 
  111. $next_button = sprintf( '<input class="button button-primary" type="submit" value="%s" name="_install"/>', esc_attr( $current_step->get_next_button_text() ) ); 
  112. } elseif ( $current_step->is( 'complete' ) ) { 
  113.  
  114. $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() ) ); 
  115. } else { 
  116. $next_button = sprintf( '<input class="button button-primary" type="submit" value="%s" name="_next"/>', esc_attr( $current_step->get_next_button_text() ) ); 
  117. ?> 
  118. <div> 
  119. <?php 
  120. $previous_button_text = $current_step->get_previous_button_text(); 
  121. if ( $previous_button_text ) { 
  122. $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;" />' : ''; 
  123. echo $previous_button; 
  124. echo $next_button; 
  125. ?> 
  126. </div> 
  127. </form> 
  128. </div> 
  129.  
  130. <?php 
  131.  
  132. return true; 
  133.  
  134. /** 
  135. * @param bool $name 
  136. * @return GF_Installation_Wizard_Step 
  137. */ 
  138. public function get_step( $name = false ) { 
  139.  
  140. if ( empty( $name ) ) { 
  141. $class_names = array_keys( $this->_step_class_names ); 
  142. $name = $class_names[0]; 
  143.  
  144. $current_step_values = get_option( 'gform_installation_wizard_' . $name ); 
  145.  
  146. $step = new $this->_step_class_names[ $name ]( $current_step_values ); 
  147.  
  148. return $step; 
  149.  
  150. /** 
  151. * @param $current_step 
  152. * @return bool|GF_Installation_Wizard_Step 
  153. */ 
  154. public function get_previous_step( $current_step ) { 
  155. $current_step_name = $current_step->get_name(); 
  156.  
  157. $step_names = array_keys( $this->_step_class_names ); 
  158. $i = array_search( $current_step_name, $step_names ); 
  159.  
  160. if ( $i == 0 ) { 
  161. return false; 
  162.  
  163. $previous_step_name = $step_names[ $i - 1 ]; 
  164.  
  165. return $this->get_step( $previous_step_name ); 
  166.  
  167. /** 
  168. * @param GF_Installation_Wizard_Step $current_step 
  169. * @return bool|GF_Installation_Wizard_Step 
  170. */ 
  171. public function get_next_step( $current_step ) { 
  172. $current_step_name = $current_step->get_name(); 
  173.  
  174. $step_names = array_keys( $this->_step_class_names ); 
  175. $i = array_search( $current_step_name, $step_names ); 
  176.  
  177. if ( $i == count( $step_names ) - 1 ) { 
  178. return false; 
  179.  
  180. $next_step_name = $step_names[ $i + 1 ]; 
  181.  
  182. return $this->get_step( $next_step_name ); 
  183.  
  184. public function complete_installation() { 
  185. foreach ( array_keys( $this->_step_class_names ) as $step_name ) { 
  186. $step = $this->get_step( $step_name ); 
  187. $step->install(); 
  188. $step->flush_values(); 
  189. delete_option( 'gform_pending_installation' ); 
  190.  
  191.  
  192.  
  193. /** 
  194. * @param GF_Installation_Wizard_Step $current_step 
  195. * @param bool $echo 
  196. * @return string 
  197. */ 
  198. public function progress( $current_step, $echo = true ) { 
  199. $html = '<ul id="gform_installation_progress">'; 
  200. $done = true; 
  201. $current_step_name = $current_step->get_name(); 
  202. foreach ( array_keys( $this->_step_class_names ) as $step_name ) { 
  203. $class = ''; 
  204. $step = $this->get_step( $step_name ); 
  205. if ( $current_step_name == $step_name ) { 
  206. $class .= 'gform_installation_progress_current_step '; 
  207. $done = $step->is('complete') ? true : false; 
  208. } else { 
  209. $class .= $done ? 'gform_installation_progress_step_complete' : 'gform_installation_progress_step_pending'; 
  210. $check = $done ? '<i class="fa fa-check" style="color:green"></i>' : '<i class="fa fa-check" style="visibility:hidden"></i>'; 
  211.  
  212. $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 ); 
  213. $html .= '</ul>'; 
  214.  
  215. if ( $echo ) { 
  216. echo $html; 
  217. return $html; 
  218.  
  219. public function get_step_index( $step ) { 
  220. $i = array_search( $step->get_name(), array_keys( $this->_step_class_names ) ); 
  221. return $i; 
  222.  
  223. public function summary() { 
  224. ?> 
  225.  
  226. <h3>Summary</h3> 
  227. <?php 
  228. echo '<table class="form-table"><tbody>'; 
  229. $steps = $this->get_steps(); 
  230. foreach ( $steps as $step ) { 
  231. $step_summary = $step->summary( false ); 
  232. if ( $step_summary ) { 
  233. printf( '<tr valign="top"><th scope="row"><label>%s</label></th><td>%s</td></tr>', esc_html( $step->get_title() ), $step_summary ); 
  234. echo '</tbody></table>'; 
  235.  
  236.  
  237. /** 
  238. * @return GF_Installation_Wizard_Step[] 
  239. */ 
  240. public function get_steps() { 
  241. $steps = array(); 
  242. foreach ( array_keys( $this->_step_class_names ) as $step_name ) { 
  243. $steps[] = $this->get_step( $step_name ); 
  244.  
  245. return $steps; 
  246.