= $closes ) {
return self::message(
$rules['closedMessage'] ?? '',
__( 'This form is closed and no longer accepts entries.', 'subtleforms' )
);
}
// Total entry limit.
$limit = isset( $rules['entryLimit'] ) ? (int) $rules['entryLimit'] : 0;
if ( $limit > 0 && self::countEntries( $formId ) >= $limit ) {
return self::message(
$rules['limitMessage'] ?? '',
__( 'This form has reached its maximum number of entries.', 'subtleforms' )
);
}
return null;
}
/**
* Markup shown in place of a blocked form.
*
* @param string $message Plain-text message.
*/
public static function render( string $message ): string {
return sprintf(
'
',
esc_html( $message )
);
}
/**
* Load the active schema for a form through the container.
*
* @param int $formId Form ID.
* @return array|null
*/
public static function activeSchema( int $formId ): ?array {
try {
$repo = \SubtleForms\Plugin::instance()->container()->get( \SubtleForms\Repositories\FormsRepository::class );
$row = $repo->loadSchemaVersion( $formId );
} catch ( \Throwable $e ) {
return null;
}
if ( ! is_array( $row ) ) {
return null;
}
return is_array( $row['schema'] ?? null ) ? $row['schema'] : $row;
}
private static function message( $custom, string $fallback ): string {
$custom = is_string( $custom ) ? trim( $custom ) : '';
return $custom !== '' ? $custom : $fallback;
}
private static function toTimestamp( $value ): int {
if ( ! is_string( $value ) || $value === '' ) {
return 0;
}
$ts = strtotime( $value );
return $ts ? (int) $ts : 0;
}
private static function countEntries( int $formId ): int {
global $wpdb;
$table = $wpdb->prefix . 'subtleforms_submissions';
// phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name is from $wpdb->prefix; the count must be live.
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE form_id = %d AND status != 'spam' AND status != 'trash' AND status != 'preview'", $formId ) );
}
}