nf_v27_upgrade_subs_to_cpt

Upgrades for Ninja Forms v2.7 and Submission Custom Post Type.

Description

nf_v27_upgrade_subs_to_cpt(); 

Usage

  1. if ( !function_exists( 'nf_v27_upgrade_subs_to_cpt' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/admin/upgrades/upgrade-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = nf_v27_upgrade_subs_to_cpt(); 
  7.  

Defined (1)

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

/deprecated/includes/admin/upgrades/upgrade-functions.php  
  1. function nf_v27_upgrade_subs_to_cpt() { 
  2. //Bail if we aren't in the admin. 
  3. if ( ! is_admin() ) 
  4. return false; 
  5.  
  6. // Bail if we don't have the appropriate permissions. 
  7. if ( is_multisite() ) { 
  8. if ( ! is_super_admin() ) 
  9. return false; 
  10. } else { 
  11. if ( ! current_user_can( 'install_plugins' ) ) 
  12. return false; 
  13.  
  14. if ( function_exists( 'ignore_user_abort' ) && ! nf_is_func_disabled( 'ignore_user_abort' ) ) { 
  15. ignore_user_abort( true ); 
  16.  
  17. if ( ! nf_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { 
  18. //set_time_limit( 0 ); 
  19.  
  20. $step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1; 
  21. $total = isset( $_GET['total'] ) ? absint( $_GET['total'] ) : false; 
  22. $number = isset( $_GET['custom'] ) ? absint( $_GET['custom'] ) : 1; 
  23.  
  24. if ( get_option( 'nf_convert_subs_num' ) ) { 
  25. $number = get_option( 'nf_convert_subs_num' ); 
  26.  
  27. $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; 
  28.  
  29. update_option( 'nf_convert_subs_step', $step ); 
  30.  
  31. $convert_subs = new NF_Convert_Subs(); 
  32. $old_sub_count = $convert_subs->count_old_subs(); 
  33.  
  34. if( empty( $total ) || $total <= 1 ) { 
  35. $total = round( ( $old_sub_count / 100 ), 0 ) + 2; 
  36.  
  37. if ( $step <= $total ) { 
  38. if ( $step == 1 ) { 
  39. $begin = 0; 
  40. } else { 
  41. $begin = ( $step - 1 ) * 100; 
  42.  
  43. $subs_results = $convert_subs->get_old_subs( $begin, 100 ); 
  44.  
  45. if ( is_array( $subs_results ) && ! empty( $subs_results ) ) { 
  46.  
  47. foreach ( $subs_results as $sub ) { 
  48. if ( $form_id != $sub['form_id'] ) { 
  49. $form_id = $sub['form_id']; 
  50. $number = 1; 
  51. $converted = get_option( 'nf_converted_subs' ); 
  52. if ( empty( $converted ) ) 
  53. $converted = array(); 
  54.  
  55. if ( ! in_array( $sub['id'], $converted ) ) { 
  56. $convert_subs->convert( $sub, $number ); 
  57.  
  58. $converted[] = $sub['id']; 
  59. update_option( 'nf_converted_subs', $converted ); 
  60. $number++; 
  61. update_option( 'nf_convert_subs_num', $number ); 
  62.  
  63. $step++; 
  64.  
  65. $redirect = add_query_arg( array( 
  66. 'page' => 'nf-upgrades',  
  67. 'nf-upgrade' => 'upgrade_subs_to_cpt',  
  68. 'step' => $step,  
  69. 'custom' => $number,  
  70. 'total' => $total,  
  71. 'form_id' => $form_id 
  72. ), admin_url( 'index.php' ) ); 
  73. wp_redirect( $redirect ); exit; 
  74.  
  75. } else { 
  76. update_option( 'nf_convert_subs_step', 'complete' ); 
  77. delete_option( 'nf_convert_subs_num' ); 
  78. wp_redirect( admin_url( 'index.php?page=nf-about' ) ); exit;