notices-save-progress.php 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * NF_Notices_SP Class
  4. *
  5. * Extends NF_Notices to check for 40 or more fields in a single form and if multi-part forms is not installed before throwing an admin notice.
  6. *
  7. * @since 2.9
  8. */
  9. class NF_Notices_SP extends NF_Notices
  10. {
  11. // Basic actions to run
  12. public function __construct(){
  13. // Runs the admin notice ignore function incase a dismiss button has been clicked
  14. add_action( 'admin_init', array( $this, 'admin_notice_ignore' ) );
  15. // Runs the visibility checks for admin notices after all needed core files are loaded
  16. add_filter( 'nf_admin_notices', array( $this, 'special_parameters' ) );
  17. }
  18. // Function to do all the special checks before running the notice
  19. public function special_parameters( $admin_notices ){
  20. // Check if on builder
  21. if ( ! $this->admin_notice_pages( array( array( 'ninja-forms', 'builder' ) ) ) ) {
  22. return $admin_notices;
  23. }
  24. // Check for 20 fields in one form
  25. $field_check = 0;
  26. $all_fields = ninja_forms_get_all_fields();
  27. if ( is_array( $all_fields ) ) {
  28. $count = array();
  29. foreach ( $all_fields as $key => $val ) {
  30. $form_id = $all_fields[ $key ][ 'form_id' ];
  31. if ( ! isset( $count[ $form_id ] ) ) {
  32. $count[ $form_id ] = 1;
  33. } else {
  34. $count[ $form_id ]++;
  35. }
  36. }
  37. foreach ( $count as $form_id => $field_count ) {
  38. if ( $field_count >=40 ) {
  39. $field_check = 1;
  40. }
  41. }
  42. }
  43. // Check for multi-part forms installed and if the above passes
  44. if ( ! is_plugin_active( 'ninja-forms-save-progress/save-progress.php' ) && $field_check == 1 ) {
  45. // Add notice
  46. $tags = '?utm_medium=plugin&utm_source=admin-notice&utm_campaign=Ninja+Forms+Upsell&utm_content=Save+Progress';
  47. $save_progress_ignore = add_query_arg( array( 'nf_admin_notice_ignore' => 'save_progress' ) );
  48. $save_progress_temp = add_query_arg( array( 'nf_admin_notice_temp_ignore' => 'save_progress', 'int' => 14) );
  49. $admin_notices['save_progress'] = array(
  50. 'title' => __( 'Increase Conversions', 'ninja-forms' ),
  51. 'msg' => __( 'Users are more likely to complete long forms when they can save and return to complete their submission later.<p>The Save Progress extension for Ninja Forms makes this quick and easy.</p>', 'ninja-forms' ),
  52. 'link' => '<li> <span class="dashicons dashicons-external"></span><a target="_blank" href="https://ninjaforms.com/extensions/save-user-progress/' . $tags . '"> ' . __( 'Learn More About Save Progress', 'ninja-forms' ) . '</a></li>
  53. <li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $save_progress_temp . '">' . __( 'Maybe Later' ,'ninja-forms' ) . '</a></li>
  54. <li><span class="dashicons dashicons-dismiss"></span><a href="' . $save_progress_ignore . '">' . __( 'Dismiss', 'ninja-forms' ) . '</a></li>',
  55. 'int' => 0
  56. );
  57. }
  58. return $admin_notices;
  59. }
  60. // Ignore function that gets ran at admin init to ensure any messages that were dismissed get marked
  61. public function admin_notice_ignore() {
  62. $slug = ( isset( $_GET[ 'nf_admin_notice_ignore' ] ) ) ? $_GET[ 'nf_admin_notice_ignore' ] : '';
  63. // If user clicks to ignore the notice, run this action
  64. if ( $slug == 'multi-part19' && current_user_can( apply_filters( 'ninja_forms_admin_parent_menu_capabilities', 'manage_options' ) ) ) {
  65. $admin_notices_extra_option = get_option( 'nf_admin_notice_extra', array() );
  66. $admin_notices_extra_option[ $_GET[ 'nf_admin_notice_ignore' ] ][ 'test19' ] = 1;
  67. update_option( 'nf_admin_notice_extra', $admin_notices_extra_option );
  68. }
  69. }
  70. }
  71. return new NF_Notices_SP();