Skip to content

Commit

Permalink
Merge pull request #1446 from sapayth/fix/file_upload_on_page_builders
Browse files Browse the repository at this point in the history
fix: file upload problem using page builders
  • Loading branch information
sapayth authored Mar 22, 2024
2 parents 7b1718e + 739aff4 commit a5ce4fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
46 changes: 46 additions & 0 deletions includes/Fields/Field_Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,50 @@ public function check_content_restriction_func( $content_limit, $rich_text, $fie
</script>
<?php
}

/**
* Enqueue file upload scripts
*
* @since WPUF_SINCE
*
* @return void
*/
public function enqueue_file_upload_scripts() {
wp_enqueue_style( 'wpuf-sweetalert2' );

wp_enqueue_script( 'wpuf-sweetalert2' );
wp_enqueue_script( 'wpuf-upload' );

wp_localize_script(
'wpuf-upload', 'wpuf_upload', [
'confirmMsg' => __( 'Are you sure?', 'wp-user-frontend' ),
'delete_it' => __( 'Yes, delete it', 'wp-user-frontend' ),
'cancel_it' => __( 'No, cancel it', 'wp-user-frontend' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wpuf_nonce' ),
'plupload' => [
'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce(
'wpuf-upload-nonce'
),
'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
'filters' => [
[
'title' => __( 'Allowed Files', 'wp-user-frontend' ),
'extensions' => '*',
],
],
'multipart' => true,
'urlstream_upload' => true,
'warning' => __( 'Maximum number of files reached!', 'wp-user-frontend' ),
'size_error' => __(
'The file you have uploaded exceeds the file size limit. Please try again.',
'wp-user-frontend'
),
'type_error' => __(
'You have uploaded an incorrect file type. Please try again.', 'wp-user-frontend'
),
],
]
);
}
}
2 changes: 2 additions & 0 deletions includes/Fields/Form_Field_Featured_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct() {
* @return void
*/
public function render( $field_settings, $form_id, $type = 'post', $post_id = null ) {
$this->enqueue_file_upload_scripts();

$has_featured_image = false;

$unique_id = sprintf( '%s-%d', $field_settings['name'], $form_id );
Expand Down
2 changes: 2 additions & 0 deletions includes/Fields/Form_Field_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct() {
* @return void
*/
public function render( $field_settings, $form_id, $type = 'post', $post_id = null ) {
$this->enqueue_file_upload_scripts();

$has_images = false;

if ( isset( $post_id ) && $post_id !== 0 ) {
Expand Down

0 comments on commit a5ce4fb

Please sign in to comment.