: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public static function gated_release( $threshold = 0 ) {
$gatekeeper = $threshold >= self::get_zuul();
$gatekeeper = apply_filters( 'ninja_forms_gatekeeper', $gatekeeper );
* Checks the upgrades table to see if the form the user is viewing
* is under maintenance mode.
* @param $form_id - The ID of the form we are checking.
public static function form_in_maintenance( $form_id ) {
$db_version = get_option( 'ninja_forms_db_version' );
if( ! $db_version ) return false;
// Exit early if the column doesn't exist.
if( version_compare( '1.3', $db_version, '>' ) ) return false;
// Get our maintenance value from the DB and return it at the zero position.
$maintenance = $wpdb->get_row(
"SELECT `maintenance` FROM `{$wpdb->prefix}nf3_upgrades` WHERE `id` = {$form_id}", 'ARRAY_A'
* If maintenance isn't empty and basic on maintenance's value
* return a boolean value.
if( ! empty( $maintenance ) && 1 == $maintenance[ 'maintenance' ] ) {
* This function either put all forms in maintenance mode or remove maintenance
* mode for all forms. Depending on the input parameters
* @param $mode - Default 0 ( Take all forms out of maintenance mode )
public static function set_forms_maintenance_mode( $mode = 0 ) {
// default is 0, so if we get passed bad data, just use 0
if( ! in_array( $mode, array( 0, 1 ) ) ) {
// set maintenance flag to $mode (0 or 1)
$sql = $wpdb->prepare( "UPDATE `{$wpdb->prefix}nf3_upgrades` SET "
. "maintenance = %d", intval( $mode ) );
* We'll use to determine if we need to use the form cache or not. This will
* be used for all users not on the newest version of the database
public static function use_cache() {
$cache_mode = intval( get_option('ninja_forms_cache_mode') );
// if we've already decided to use the cache return true and exit.
if( 0 < $cache_mode ) return true;
$db_version = get_option('ninja_forms_db_version');
// If not in cache mode, get the db version and return true if we aren't at a certain threshold version-wise
if( ! $db_version || version_compare($db_version, '1.4', '<' )) {
$finished_updates = get_option( 'ninja_forms_required_updates', false );
// make sure we've run the lastest update to reconcile db with cache field values
if( $finished_updates && !isset( $finished_updates[ 'CacheFieldReconcilliation' ] ) ) {
* Sanitizes single/multiple CSS classNames
* Explodes on space, sanitize each className, implode with space to recombine
public static function sanitize_classes($value):string {
$exploded = explode(' ',$value);
foreach($exploded as $singleClass){
$sanitized[] = sanitize_html_class($singleClass);
$outgoing = implode(' ',$sanitized);
* Sanitizes string values for field settings
* WIP methods can still be implemented for this.
* @param string $key Setting name
* @param string $value of setting
* @return string sanitized value for setting
public static function sanitize_string_setting_value($key, $value):string {
if( in_array( $key, ["element_class", "container_class"] ) ) {
$value = self::sanitize_classes($value);
} else if( in_array( $key, ["label"] )){
$value = self::sanitize_text_field($value);
* Check the DISALLOW_UNFILTERED_HTML constant value and return early if true.
* If false, return opposite for 'unfiltered_html' current user capability
public static function maybe_disallow_unfiltered_html_for_sanitization():bool {
* Exit early if the config setting is TRUE to mimic WordPress capability check.
if( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) return true;
$disallow_unfiltered_html = ! current_user_can( 'unfiltered_html' );
return $disallow_unfiltered_html;
* Check the DISALLOW_UNFILTERED_HTML constant value only on the escaping side
public static function maybe_disallow_unfiltered_html_for_escaping():bool {
// Default intentinally left set to false to avoid breaking countless pre-existing forms using this feature.
$disallow_unfiltered_html = defined( 'DISALLOW_UNFILTERED_HTML' ) ? DISALLOW_UNFILTERED_HTML : false;
return $disallow_unfiltered_html;
* Sanitize output to csv to prevent formula injection.
* @param String $value The value to be escaped.
public static function maybe_escape_csv_column( $value ):string {
if (!is_string($value) && !is_numeric($value)) {
$value = implode(' ', $value);
throw new Exception('Incoming value to maybe_escape_csv_column is neither string nor array');
if( 0 < strlen($value ) ) {
$first_char = substr( $value, 0, 1 );
if( in_array( $first_char, array( '=', '@', '+', '-' ) ) ) {
} // End Class WPN_Helper