Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update file.php #532

Merged
merged 1 commit into from
Aug 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ function wpcf7_unship_uploaded_file( $file, $args = '' ) {
10, 1
);

/**
* A wpcf7_messages filter callback that adds messages for
* file-uploading fields.
*/
function wpcf7_file_messages( $messages ) {
return array_merge( $messages, array(
'upload_failed' => array(
Expand Down Expand Up @@ -140,6 +144,10 @@ function wpcf7_file_messages( $messages ) {
10, 1
);

/**
* A wpcf7_form_enctype filter callback that sets the enctype attribute
* to multipart/form-data if the form has file-uploading fields.
*/
function wpcf7_file_form_enctype_filter( $enctype ) {
$multipart = (bool) wpcf7_scan_form_tags( array(
'feature' => 'file-uploading',
Expand Down Expand Up @@ -234,6 +242,9 @@ function wpcf7_acceptable_filetypes( $types = 'default', $format = 'regex' ) {
10, 0
);

/**
* Initializes the temporary directory for uploaded files.
*/
function wpcf7_init_uploads() {
$dir = wpcf7_upload_tmp_dir();

Expand All @@ -249,6 +260,12 @@ function wpcf7_init_uploads() {
}


/**
* Creates a child directory with a randomly generated name.
*
* @param string $dir The parent directory path.
* @return string The child directory path if created, otherwise the parent.
*/
function wpcf7_maybe_add_random_dir( $dir ) {
do {
$rand_max = mt_getrandmax();
Expand Down Expand Up @@ -291,6 +308,13 @@ function wpcf7_upload_tmp_dir() {
20, 0
);

/**
* Cleans up files in the temporary directory for uploaded files.
*
* @param int $seconds Files older than this are removed. Default 60.
* @param int $max Maximum number of files to be removed in a function call.
* Default 100.
*/
function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
if ( is_admin()
or 'GET' != $_SERVER['REQUEST_METHOD']
Expand Down Expand Up @@ -345,6 +369,9 @@ function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
10, 3
);

/**
* Displays warning messages about file-uploading fields.
*/
function wpcf7_file_display_warning_message( $page, $action, $object ) {
if ( $object instanceof WPCF7_ContactForm ) {
$contact_form = $object;
Expand Down