??????????????
??????????????
??????????????
??????????????
Warning : Undefined variable $auth in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
Warning : Trying to access array offset on value of type null in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
??????????????
??????????????
??????????????
??????????????
File Manager
✏️ Edit File: /home/mklsvubc/netecfwd.co.uk/wp-content/plugins/sureforms/inc/form-restriction.php
⬅ Kembali
<?php
/**
* Create new Form with Template and return the form ID.
*
* @package sureforms.
* @since 1.10.1
*/
namespace SRFM\Inc;
use SRFM\Inc\Compatibility\Multilingual\String_Translator;
use SRFM\Inc\Database\Tables\Entries;
use SRFM\Inc\Traits\Get_Instance;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Create New Form.
*
* @since 1.10.1
*/
class Form_Restriction {
use Get_Instance;
/**
* Get the restriction settings for a given form.
*
* @param int $form_id The ID of the form.
* @since 1.10.1
* @return array Associative array of restriction settings or empty array if invalid.
*/
public static function get_form_restriction_setting( $form_id ) {
// Validate the form ID. Must be numeric and non-empty.
if ( empty( $form_id ) || ! is_int( $form_id ) ) {
return [];
}
// Get the raw restriction meta.
$form_restriction_meta = get_post_meta( $form_id, '_srfm_form_restriction', true );
if ( empty( $form_restriction_meta ) || ! is_string( $form_restriction_meta ) ) {
return [];
}
// Decode the meta to an array.
$form_restriction = json_decode( $form_restriction_meta, true );
// Ensure it's a valid array.
return is_array( $form_restriction ) ? $form_restriction : [];
}
/**
* Check if the form has reached the entry limit.
*
* @param int $form_id The ID of the form.
* @since 1.10.1
* @return bool True if form is restricted, false otherwise.
*/
public static function is_form_restricted( $form_id ) {
if ( empty( $form_id ) || ! is_int( $form_id ) ) {
return false; // Invalid form ID.
}
// Check for instant fom preview mode.
$srfm_live_mode_data = Helper::get_instant_form_live_data();
// Skip check in live mode.
if (
! empty( $srfm_live_mode_data ) &&
is_array( $srfm_live_mode_data ) &&
isset( $srfm_live_mode_data['live_mode'] )
) {
return false; // Skip check in live mode.
}
// Get parsed restriction settings.
$form_restriction = self::get_form_restriction_setting( $form_id );
// If the form restriction is empty or not an array, or if the status is not set, return false.
if ( empty( $form_restriction ) || ! is_array( $form_restriction ) || empty( $form_restriction['status'] ) ) {
// Check for form scheduling even if entry restriction is not enabled.
$is_outside_schedule = self::is_form_outside_schedule( $form_restriction );
return apply_filters( 'srfm_is_form_restricted', $is_outside_schedule, $form_id, $form_restriction, false, false, $is_outside_schedule );
}
$has_entries_limit_reached = self::has_entries_limit_reached( $form_id, $form_restriction );
$scheduling_state = self::get_form_scheduling_state( $form_restriction );
$is_outside_schedule = 'not_started' === $scheduling_state || 'ended' === $scheduling_state;
$conversational_form = get_post_meta( $form_id, '_srfm_conversational_form', true );
$is_conversational_form_enabled = is_array( $conversational_form ) && isset( $conversational_form['is_cf_enabled'] ) ? $conversational_form['is_cf_enabled'] : false;
if ( ( $has_entries_limit_reached || $is_outside_schedule ) && $is_conversational_form_enabled ) {
add_filter( 'srfm_show_conversational_form_footer', '__return_false' );
}
/**
* If the form has reached the entries limit or is outside schedule, return true.
*
* @since 1.10.1
*/
return apply_filters(
'srfm_is_form_restricted',
$has_entries_limit_reached || $is_outside_schedule,
$form_id,
$form_restriction,
$has_entries_limit_reached,
false, // Deprecated: $has_time_limit_reached - now handled by scheduling.
$is_outside_schedule
);
}
/**
* Check if the entries limit has been reached for a given form.
*
* @param int $form_id The ID of the form.
* @param array<string, mixed> $form_restriction The form restriction settings.
* @since 1.10.1
* @return bool True if the entries limit is reached, false otherwise.
*/
public static function has_entries_limit_reached( $form_id, $form_restriction = [] ) {
if ( ! isset( $form_restriction['maxEntries'] ) || ! is_int( $form_restriction['maxEntries'] ) ) {
return false; // Invalid form ID or restriction settings.
}
$max_entries = $form_restriction['maxEntries'];
$entries_count = Entries::get_total_entries_by_status( 'all', $form_id );
if ( ! is_int( $entries_count ) ) {
$entries_count = 0; // Ensure entries count is a non-negative integer.
}
/**
* Filter the count of entries used to evaluate the Maximum Number of Entries
* cap. Allows extensions (e.g. SureForms Pro's Recurring Entry Limit) to
* substitute a window-scoped count — entries since the start of today /
* the current week / month / year — in place of the lifetime count.
*
* Returning a value greater than `$entries_count` will trip the cap sooner;
* returning a smaller value will defer it. Non-integer return values are
* coerced back to a non-negative integer.
*
* @param int $entries_count Lifetime entry count for the form.
* @param int $form_id The ID of the form.
* @param array<string, mixed> $form_restriction The form restriction settings.
* @since 2.8.2
*/
$entries_count = apply_filters( 'srfm_form_restriction_entries_count', $entries_count, $form_id, $form_restriction );
// Always coerce to a non-negative integer — covers both non-int returns
// from a misbehaving extension AND negative-int returns that would
// otherwise silently disable the cap (e.g. -5 >= 100 is false).
$entries_count = max( 0, (int) $entries_count );
return $entries_count >= $max_entries;
}
/**
* Check if the form is outside its scheduled time period.
*
* @param array<string, mixed> $form_restriction The form restriction settings.
* @since 2.4.0
* @return bool True if form is outside schedule, false otherwise.
*/
public static function is_form_outside_schedule( $form_restriction ) {
$scheduling_state = self::get_form_scheduling_state( $form_restriction );
return 'not_started' === $scheduling_state || 'ended' === $scheduling_state;
}
/**
* Get the appropriate restriction message based on scheduling state.
*
* @param string $scheduling_state The scheduling state ('not_started', 'ended', 'active', or 'disabled').
* @param array<string, mixed> $form_restriction The form restriction settings.
* @since 2.4.0
* @return string The appropriate restriction message.
*/
public static function get_restriction_message_by_state( $scheduling_state, $form_restriction ) {
if ( 'not_started' === $scheduling_state ) {
$message = $form_restriction['schedulingNotStartedMessage'] ?? __( 'This form is not yet available. Check back after the scheduled start time.', 'sureforms' );
return is_string( $message ) ? $message : __( 'This form is not yet available. Check back after the scheduled start time.', 'sureforms' );
}
if ( 'ended' === $scheduling_state ) {
$message = $form_restriction['schedulingEndedMessage'] ?? __( 'This form is no longer accepting submissions. The submission period has ended.', 'sureforms' );
return is_string( $message ) ? $message : __( 'This form is no longer accepting submissions. The submission period has ended.', 'sureforms' );
}
// Default to entry limit message.
$message = $form_restriction['message'] ?? Translatable::get_default_form_restriction_message();
return is_string( $message ) ? $message : Translatable::get_default_form_restriction_message();
}
/**
* Get the scheduling state for a form.
*
* @param array<string, mixed> $form_restriction The form restriction settings.
* @since 2.4.0
* @return string 'not_started', 'ended', 'active', or 'disabled'.
*/
public static function get_form_scheduling_state( $form_restriction ) {
$scheduling_status = $form_restriction['schedulingStatus'] ?? false;
// Start date/time.
$start_date = $form_restriction['startDate'] ?? '';
$start_hours = Helper::get_string_value( $form_restriction['startHours'] ?? '12' );
$start_minutes = Helper::get_string_value( $form_restriction['startMinutes'] ?? '00' );
$start_meridiem = Helper::get_string_value( $form_restriction['startMeridiem'] ?? 'AM' );
// End date/time.
$end_date = $form_restriction['date'] ?? '';
$end_hours = Helper::get_string_value( $form_restriction['hours'] ?? '12' );
$end_minutes = Helper::get_string_value( $form_restriction['minutes'] ?? '00' );
$end_meridiem = Helper::get_string_value( $form_restriction['meridiem'] ?? 'PM' );
$dt = new \DateTime( 'now', wp_timezone() );
$current_timestamp = $dt->getTimestamp();
// Check if before start time (only if scheduling is enabled).
if ( $scheduling_status && ! empty( $start_date ) && is_string( $start_date ) ) {
$start_timestamp = Helper::get_timestamp_from_string( $start_date, $start_hours, $start_minutes, $start_meridiem );
if ( false !== $start_timestamp && is_int( $start_timestamp ) && $current_timestamp < $start_timestamp ) {
return 'not_started';
}
}
// Check if after end time (works for both scheduling and simple time limit).
if ( $scheduling_status && ! empty( $end_date ) && is_string( $end_date ) ) {
$end_timestamp = Helper::get_timestamp_from_string( $end_date, $end_hours, $end_minutes, $end_meridiem );
if ( false !== $end_timestamp && is_int( $end_timestamp ) && $current_timestamp > $end_timestamp ) {
return 'ended';
}
}
// If scheduling is disabled but we haven't passed the end date, return 'disabled'.
// If scheduling is enabled and we're within the window, return 'active'.
return $scheduling_status ? 'active' : 'disabled';
}
/**
* Display the form restriction message.
*
* @param int $form_id The ID of the form.
* @since 1.10.1
* @return string|false The HTML markup for the restriction message or false if no restriction is set.
*/
public static function display_form_restriction_message( $form_id ) {
// Get parsed restriction settings.
$form_restriction = self::get_form_restriction_setting( $form_id );
// Get the scheduling state and appropriate message.
$scheduling_state = self::get_form_scheduling_state( $form_restriction );
$form_restriction_message = self::get_restriction_message_by_state( $scheduling_state, $form_restriction );
// Translate the restriction message via the active multilingual provider
// (no-op when no WPML/Polylang is installed).
$form_restriction_message = String_Translator::get_instance()->translate_restriction_message( (int) $form_id, $form_restriction_message );
$form_restriction_message = apply_filters( 'srfm_form_restriction_message', $form_restriction_message, $form_id, $form_restriction );
ob_start();
?>
<div class="srfm-form-container srfm-form-restriction-wrapper">
<div class="srfm-form-restriction-message" role="alert" aria-live="assertive">
<span class="srfm-form-restriction-icon" aria-hidden="true">
<?php
echo wp_kses(
Helper::fetch_svg( 'instant-form-warning', 'srfm-form-restriction-icon', 'aria-hidden="true"' ),
Helper::$allowed_tags_svg
);
?>
</span>
<p class="srfm-form-restriction-text">
<?php echo esc_html( $form_restriction_message ); ?>
</p>
</div>
</div>
<?php
return ob_get_clean();
}
}
Nama
Tipe
Ukuran
Diubah
Aksi
📁 abilities
dir
—
2026-06-25 16:24
📁 admin
dir
—
2026-06-25 16:24
📁 ai-form-builder
dir
—
2026-06-25 16:24
📁 blocks
dir
—
2026-06-25 16:24
📁 compatibility
dir
—
2026-06-25 16:24
📁 database
dir
—
2026-06-25 16:24
📁 email
dir
—
2026-06-25 16:24
📁 fields
dir
—
2026-06-25 16:24
📁 global-settings
dir
—
2026-06-25 16:24
📁 lib
dir
—
2026-06-25 16:24
📁 migrator
dir
—
2026-06-25 16:24
📁 page-builders
dir
—
2026-06-25 16:24
📁 payments
dir
—
2026-06-25 16:24
📁 single-form-settings
dir
—
2026-06-25 16:24
📁 traits
dir
—
2026-06-25 16:24
🐘 activator.php
php
1 KB
2026-06-25 16:24
🐘 admin-ajax.php
php
13.4 KB
2026-06-25 16:24
🐘 background-process.php
php
4.8 KB
2026-06-25 16:24
🐘 create-new-form.php
php
4.9 KB
2026-06-25 16:24
🐘 duplicate-form.php
php
8.4 KB
2026-06-25 16:24
🐘 entries.php
php
24.3 KB
2026-06-25 16:24
🐘 events-scheduler.php
php
1.3 KB
2026-06-25 16:24
🐘 export.php
php
11.8 KB
2026-06-25 16:24
🐘 field-validation.php
php
22.9 KB
2026-06-25 16:24
🐘 form-restriction.php
php
11.2 KB
2026-06-25 16:24
🐘 form-styling.php
php
7 KB
2026-06-25 16:24
🐘 form-submit.php
php
55.7 KB
2026-06-25 16:24
🐘 forms-data.php
php
7.1 KB
2026-06-25 16:24
🐘 frontend-assets.php
php
16.3 KB
2026-06-25 16:24
🐘 generate-form-markup.php
php
49.9 KB
2026-06-25 16:24
🐘 gutenberg-hooks.php
php
10.9 KB
2026-06-25 16:24
🐘 helper.php
php
92.4 KB
2026-06-25 16:24
🐘 learn.php
php
13.5 KB
2026-06-25 16:24
🐘 onboarding.php
php
3.9 KB
2026-06-25 16:24
🐘 post-types.php
php
48.4 KB
2026-06-25 16:24
🐘 rest-api.php
php
56.7 KB
2026-06-25 16:24
🐘 smart-tags.php
php
28.1 KB
2026-06-25 16:24
🐘 submit-token.php
php
4.6 KB
2026-06-25 16:24
🐘 translatable.php
php
5.9 KB
2026-06-25 16:24
🐘 updater-callbacks.php
php
3.3 KB
2026-06-25 16:24
🐘 updater.php
php
5.1 KB
2026-06-25 16:24