Commit 9ecfa951 authored by KR Moorhouse's avatar KR Moorhouse

Merge branch 'issue#3719' into 'feat-stage-two'

Issue#3719

See merge request ninja-forms/ninja-forms!3699
parents 63ec9cf7 5ad7a238
Pipeline #449 passed with stage
in 1 minute and 34 seconds
......@@ -377,4 +377,43 @@ final class WPN_Helper
}
}
/**
* This funtion gets/creates the Ninja Forms gate keeper( a random integer
* between 1 and 100 ). We will use this number when deciding whether a
* particular install is eligible for an upgrade or whatever else we decide
* to use it for
*
* @return int $zuul
*
* @since UPDATE_VERSION_ON_MERGE
*/
public static function get_zuul() {
$zuul = get_option( 'ninja_forms_zuul', -1 );
if( -1 === $zuul ) {
$zuul = rand( 1, 100 );
update_option( 'ninja_forms_zuul', $zuul, false );
}
return $zuul;
}
/**
* This function will return true/false based on an option( ninja_forms_zuul )
* and a threshold that we set. We can use this to limit updates
*
* @param $threshold
*
* @return bool
*
* @since UPDATE_VERSION_ON_MERGE
*/
public static function gated_release( $threshold = 0 ) {
$gatekeeper = $threshold >= self::get_zuul();
$gatekeeper = apply_filters( 'ninja_forms_gatekeeper', $gatekeeper );
return $gatekeeper;
}
} // End Class WPN_Helper
......@@ -457,9 +457,12 @@ if( get_option( 'ninja_forms_load_deprecated', FALSE ) && ! ( isset( $_POST[ 'nf
// Get our list of required updates.
$required_updates = Ninja_Forms()->config( 'RequiredUpdates' );
// If we got back a list of updates...
if ( ! empty( $required_updates ) ) {
$required_updates = Ninja_Forms()->config( 'RequiredUpdates' );
$threshold = 5; // Threshold percentage for any updates/releases
// If we got back a list of updates and the gate is open...
if ( ! empty( $required_updates )
&& WPN_Helper::gated_release( $threshold ) ) {
// Record that we have updates to run.
update_option( 'ninja_forms_needs_updates', 1 );
} // Otherwise... (Sanity check)
......@@ -868,6 +871,9 @@ if( get_option( 'ninja_forms_load_deprecated', FALSE ) && ! ( isset( $_POST[ 'nf
if( Ninja_Forms()->form()->get_forms() ) return;
// Go ahead and create our randomn number for gated releases in the future
$zuul = WPN_Helper::get_zuul();
// Assume we're on a clean installation.
update_option( 'ninja_forms_data_is_clean', 'true' );
$form = Ninja_Forms::template( 'formtemplate-contactform.nff', array(), TRUE );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment