ITSP_GF_DPR_Save_Button

The Gravity Forms - Data Persistence Reloaded - Save Button ITSP GF DPR Save Button class.

Defined (1)

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

/gravity-forms-data-persistence-add-on-reloaded-save-button.php  
  1. class ITSP_GF_DPR_Save_Button 
  2. private static $name = 'Gravity Forms - Data Persistence Reloaded - Save Button'; 
  3. private static $slug = 'itsp_gp_drp_save_button'; 
  4.  
  5. /** 
  6. * the save button template 
  7. */ 
  8. public static $save_button = "<input type='button' value='Save' class='button gform_next_button itsg_gf_save_button' onclick='itsg_gf_save_button_ajax_function();'> ";  
  9.  
  10. /** 
  11. * Construct the plugin object 
  12. */ 
  13. public function __construct() 
  14. // register actions 
  15. if ((self::is_gravityforms_installed())) { 
  16. // start the plugin 
  17. add_action('gform_enqueue_scripts', array(&$this, 'itsg_gf_save_button_button_ajax'), 90, 3); 
  18.  
  19. } // END __construct 
  20.  
  21. /** 
  22. * Place the save button before the 'Next' button 
  23. */ 
  24. function itsg_gf_next_button_markup( $next_button, $form ) { 
  25. $save_button = self::$save_button; 
  26. return $save_button.$next_button; 
  27. } // END my_next_button_markup 
  28.  
  29. /** 
  30. * Place the save button before the 'Submit' button 
  31. */ 
  32. function itsg_gf_submit_button_markup( $submit_button, $form ) { 
  33. $save_button = self::$save_button; 
  34. return $save_button.$submit_button; 
  35. } // END my_submit_button_markup 
  36.  
  37. /** 
  38. * If Ajax data persistence is enabled, user is logged in and current form is not a user registration form - enqueue javascript and buttons 
  39. */ 
  40. public function itsg_gf_save_button_button_ajax($form, $is_ajax) { 
  41.  
  42. if($form['ri_gfdp_persist'] == 'ajax' && is_user_logged_in() && !self::is_user_registration_form($form)) { 
  43.  
  44. add_action('wp_footer', array(&$this, 'itsg_gf_save_button_ajax')); 
  45. add_filter( 'gform_next_button', array(&$this, 'itsg_gf_next_button_markup'), 10, 2 ); 
  46. add_filter( 'gform_submit_button', array(&$this, 'itsg_gf_submit_button_markup'), 10, 2 ); 
  47.  
  48. } // END itsg_gf_save_button_button_ajax 
  49.  
  50. /** 
  51. * Ajax to handle button press -  
  52. * activates the 'save' command,  
  53. * sets the button value to 'Saving ...' whilst being saved,  
  54. * sets the button value to 'Saved' for three seconds to confirm to the user that the save completed,  
  55. * sets the button value back to 'Save' 
  56. */ 
  57. public static function itsg_gf_save_button_ajax() { 
  58. ?> 
  59. <script type="text/javascript" > 
  60. function itsg_gf_save_button_ajax_function() { 
  61. jQuery('.gform_body').find('.itsg_gf_save_button').prop('value', '<?php _e('Saving ...', self::$slug); ?>'); 
  62.  
  63. changed = true;  
  64. gfdp_ajax(); 
  65. jQuery(document).ajaxComplete(function(event, request, settings ) { 
  66. if ( settings.url === '<?php echo admin_url('admin-ajax.php'); ?>' && request.responseText === 'Saved' ) { 
  67. itsg_gf_save_button_ajax_reset_button_function(); 
  68. }); 
  69.  
  70. function itsg_gf_save_button_ajax_reset_button_function() { 
  71. jQuery('.gform_body').find('.itsg_gf_save_button').prop('value', '<?php _e('Saved', self::$slug); ?>'); 
  72. setTimeout(function() { 
  73. jQuery('.gform_body').find('.itsg_gf_save_button').prop('value', '<?php _e('Save', self::$slug); ?>'); 
  74. }, 3000); 
  75.  
  76. </script> <?php 
  77. } // END itsg_gf_save_button_ajax 
  78.  
  79. /** 
  80. * Warning message if Gravity Forms is not installed and enabled 
  81. */ 
  82. public static function admin_warnings() { 
  83. if ( !self::is_gravityforms_installed() ) { 
  84. $gf_message = __('Requires Gravity Forms to be installed.', self::$slug); 
  85. if ( !self::is_dpr_installed() ) { 
  86. $gfdpr_message = __('Requires Gravity - Data Persistence Reloaded to be installed.', self::$slug); 
  87.  
  88. if (!empty($gf_message)) { 
  89. ?> 
  90. <div class="error"> 
  91. <p> 
  92. <?php _e('The plugin ', self::$slug); ?><strong><?php echo self::$name; ?></strong> <?php echo $gf_message; ?><br /> 
  93. <?php _e('Please ', self::$slug); ?><a href="http://www.gravityforms.com/"><?php _e(' download the latest version', self::$slug); ?></a><?php _e(' of Gravity Forms and try again.', self::$slug) ?> 
  94. </p> 
  95. </div> 
  96. <?php 
  97.  
  98. if (!empty($gfdpr_message)) { 
  99. ?> 
  100. <div class="error"> 
  101. <p> 
  102. <?php _e('The plugin ', self::$slug); ?><strong><?php echo self::$name; ?></strong> <?php echo $gfdpr_message; ?><br /> 
  103. <?php _e('Please ', self::$slug); ?><a href="https://wordpress.org/plugins/gravity-forms-data-persistence-add-on-reloaded/"><?php _e(' download the latest version', self::$slug); ?></a><?php _e(' of Gravity Forms Data Persistence Add-On Reloaded and try again.', self::$slug) ?> 
  104. </p> 
  105. </div> 
  106. <?php 
  107. }  
  108.  
  109. } // END admin_warnings 
  110.  
  111. /** 
  112. * Check if GF is installed 
  113. */ 
  114. private static function is_gravityforms_installed() 
  115. return class_exists('GFAPI'); 
  116. } // END is_gravityforms_installed 
  117.  
  118. /** 
  119. * Check if Gravity Forms - Data Persistence Reloaded is installed 
  120. */ 
  121. private static function is_dpr_installed()  
  122. return function_exists('ri_gfdp_ajax'); 
  123. } // END is_dpr_installed 
  124.  
  125. private static function is_user_registration_form($form) 
  126. global $wpdb; 
  127.  
  128. $form_id = $form[id]; 
  129. $table_user_reg = $wpdb->prefix . "rg_userregistration"; 
  130.  
  131. $sql = "SELECT userreg.form_id 
  132. FROM $table_user_reg as userreg  
  133. WHERE userreg.form_id = $form_id"; 
  134.  
  135. $results = $wpdb->get_results($sql); 
  136.  
  137. if (!empty($results)) { 
  138. return true; 
  139. }  
  140.