/deprecated/includes/display/form/sub-limit.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. /** 
  4. * Function that checks the current sub count and updates the loading class if neccesary. 
  5. * @param $string $form_id 
  6. * @since 2.5 
  7. * @return void 
  8. */ 
  9. function nf_check_sub_limit( $form_id ) { 
  10. global $ninja_forms_loading; 
  11.  
  12. if ( ! isset( $ninja_forms_loading ) ) 
  13. return false; 
  14.  
  15. $sub_limit = $ninja_forms_loading->get_form_setting( 'sub_limit_number' ); 
  16.  
  17. if ( !$sub_limit or empty ( $sub_limit ) ) 
  18. return false; 
  19.  
  20. $args = array( 
  21. 'form_id' => $form_id,  
  22. 'action' => 'submit',  
  23. ); 
  24. $sub_count = ninja_forms_get_sub_count( $args ); 
  25.  
  26. if ( $sub_count >= $sub_limit ) { 
  27. $ninja_forms_loading->update_form_setting( 'sub_limit_reached', true ); 
  28.  
  29. add_action( 'ninja_forms_display_init', 'nf_check_sub_limit' ); 
  30.  
  31. /** 
  32. * Function that filters the display variable and returns false if sub limit has been reached. 
  33. * @param bool $display 
  34. * @param string $form_id 
  35. * @since 2.5 
  36. * @return string $display 
  37. */ 
  38. function nf_sub_limit_display_filter( $display, $form_id ) { 
  39. global $ninja_forms_loading; 
  40.  
  41. if ( ! isset( $ninja_forms_loading ) ) 
  42. return $display; 
  43.  
  44. if ( $ninja_forms_loading->get_form_setting( 'sub_limit_reached' ) ) { 
  45. $display = 0; 
  46. return $display; 
  47. add_filter( 'ninja_forms_display_show_form', 'nf_sub_limit_display_filter', 10, 2 ); 
  48.  
  49. /** 
  50. * Function that echoes the sub limit reached message if necessary. 
  51. * @param string $form_id 
  52. * @since 2.5 
  53. * @return void 
  54. */ 
  55. function nf_sub_limit_display_msg( $form_id ) { 
  56. global $ninja_forms_loading; 
  57.  
  58. if ( ! isset( $ninja_forms_loading ) ) 
  59. return false; 
  60.  
  61. if ( $ninja_forms_loading->get_form_setting( 'sub_limit_reached' ) ) { 
  62. $msg = $ninja_forms_loading->get_form_setting( 'sub_limit_msg' ); 
  63. $msg = wpautop( $msg ); 
  64. $msg = do_shortcode( $msg ); 
  65. $msg = '<div class="sub-limit-reached-msg">' . $msg . '</div>'; 
  66. $msg = apply_filters( 'nf_sub_limit_reached_msg', $msg, $form_id ); 
  67. echo $msg; 
  68.  
  69. add_action( 'ninja_forms_display_user_not_logged_in', 'nf_sub_limit_display_msg' ); 
.