Beispiel #1
0
 /**
  * Get things rolling
  * 
  * @since 2.7.4
  * @return void
  */
 function __construct()
 {
     //Bail if we aren't in the admin.
     if (!is_admin()) {
         return false;
     }
     ignore_user_abort(true);
     if (!nf_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
         //set_time_limit( 0 );
     }
     add_action('wp_ajax_nf_' . $this->action, array($this, 'processing'));
 }
 public function __construct()
 {
     if (function_exists('ignore_user_abort') && !nf_is_func_disabled('ignore_user_abort')) {
         ignore_user_abort(true);
     }
     $this->register_upgrades();
     if (defined('DOING_AJAX') && DOING_AJAX) {
         add_action('wp_ajax_nf_upgrade_handler', array($this, 'ajax_response'));
         return;
     } else {
         $this->page = new NF_UpgradeHandlerPage();
     }
 }
/**
 * Upgrades for Ninja Forms v2.7 and Submission Custom Post Type.
 *
 * @since 2.7
 * @return void
 */
function nf_v27_upgrade_subs_to_cpt() {
	//Bail if we aren't in the admin.
	if ( ! is_admin() )
		return false;

	// Bail if we don't have the appropriate permissions.
	if ( is_multisite() ) {
		if ( ! is_super_admin() )
			return false;
	} else {
		if ( ! current_user_can( 'install_plugins' ) )
			return false;
	}

	ignore_user_abort( true );

	if ( ! nf_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
		//set_time_limit( 0 );
	}

	$step   = isset( $_GET['step'] )  ? absint( $_GET['step'] )  : 1;
	$total  = isset( $_GET['total'] ) ? absint( $_GET['total'] ) : false;
	$number  = isset( $_GET['custom'] ) ? absint( $_GET['custom'] ) : 1;

	if ( get_option( 'nf_convert_subs_num' ) ) {
		$number = get_option( 'nf_convert_subs_num' );
	}

	$form_id  = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;

	update_option( 'nf_convert_subs_step', $step );

	$convert_subs = new NF_Convert_Subs();
	$old_sub_count = $convert_subs->count_old_subs();

	if( empty( $total ) || $total <= 1 ) {
		$total = round( ( $old_sub_count / 100 ), 0 ) + 2;
	}

	if ( $step <= $total ) {
		if ( $step == 1 ) {
			$begin = 0;
		} else {
			$begin = ( $step - 1 ) * 100;
		}

		$subs_results = $convert_subs->get_old_subs( $begin, 100 );

		if ( is_array( $subs_results ) && ! empty( $subs_results ) ) {

			foreach ( $subs_results as $sub ) {
				if ( $form_id != $sub['form_id'] ) {
					$form_id = $sub['form_id'];
					$number = 1;
				}
				$converted = get_option( 'nf_converted_subs' );
				if ( empty( $converted ) )
					$converted = array();

				if ( ! in_array( $sub['id'], $converted ) ) {
					$convert_subs->convert( $sub, $number );

					$converted[] = $sub['id'];
					update_option( 'nf_converted_subs', $converted );
					$number++;
					update_option( 'nf_convert_subs_num', $number );
				}
			}
		}

		$step++;

		$redirect = add_query_arg( array(
			'page'        	=> 'nf-upgrades',
			'nf-upgrade' 	=> 'upgrade_subs_to_cpt',
			'step'        	=> $step,
			'custom'      	=> $number,
			'total'       	=> $total,
			'form_id'		=> $form_id
		), admin_url( 'index.php' ) );
		wp_redirect( $redirect ); exit;

	} else {
		update_option( 'nf_convert_subs_step', 'complete' );
		delete_option( 'nf_convert_subs_num' );
		wp_redirect( admin_url( 'index.php?page=nf-about' ) ); exit;
	}
}