Skip to content

#419 Image field#441

Open
reygcalantaol wants to merge 3 commits into
developfrom
#419-Image-Field
Open

#419 Image field#441
reygcalantaol wants to merge 3 commits into
developfrom
#419-Image-Field

Conversation

@reygcalantaol
Copy link
Copy Markdown
Collaborator

@reygcalantaol reygcalantaol commented Mar 23, 2026

Resolves #419

What Changed

Adds a new Image field type to WP User Manager custom fields, powered by the FilePond uploader.

How It Works

This PR adds a new Image field type to WPUM using FilePond to replace the default file input with a much better upload experience.

Files Changes
includes/assets.php - Enqueues all the FilePond scripts and styles so the uploader works properly.
includes/fields/class-wpum-fields.php - Registers the new image field type so it shows up in WPUM custom fields.
Gruntfile.js - Updated to bundle FilePond and its plugins into one build.

Files Added
includes/fields/types/class-wpum-field-image.php - Main logic for the image field.
templates/form-fields/image-field.php - Outputs the field markup and passes data needed for FilePond.

JS
assets/js/src/wpum-filepond.js - Initializes FilePond, handles default images, and keeps things in sync when users add/remove images.

FilePond assets (local copies)
CSS:
assets/css/vendor/filepond.css
assets/css/vendor/filepond/filepond-plugin-image-preview.min.css
assets/css/vendor/filepond/filepond.min.css

JS:
assets/js/vendor/filepond/filepond.min.js
assets/js/vendor/filepond/filepond.jquery.js
assets/js/vendor/filepond/filepond-plugin-file-validate-type.min.js
assets/js/vendor/filepond/filepond-plugin-image-preview.min.js
assets/js/vendor/filepond/filepond-plugin-image-validate-size.min.js

Testing Instructions

Steps for a reviewer to verify this works:

  1. In the WP admin, go to Users -> Custom Fields
  2. Edit on the Primary Fields
  3. Click Add new custom field
  4. In the Advanced Fields tab, enter field and click, Image
  5. Click Save Changes
  6. Go to Users -> Registration Forms, edit Default Registration Form
  7. Drag the Image field to form fields.
  8. Go to Register page (http://domain.com/register) and register new user.

Note:
When testing on the #419-Image-Field branch, you may notice that in step 4 the image does not have a name. This is expected and is caused by the updated field naming implementation introduced in #405 to fix the translation issue.

	public function set_name() {
		$this->name = esc_html__( 'Image', 'wp-user-manager' );
	}

Test Coverage

  • Unit tests added/updated in tests/wpunit/
  • E2E test reproduces the bug (for bug fixes) — test fails before fix, passes after
  • Happy path covered
  • Edge cases covered
  • All existing tests still pass (vendor/bin/codecept run wpunit or vendor/bin/phpunit)

Tests Performed

  1. Upload image in registration form.
  2. Upload image in user account page in the frontend.
  3. Upload image in the user profile edit in the backend.

Screenshots

If this changes any UI, add before/after screenshots.

Pre-merge Checklist

  • Acceptance criteria from the linked issue are met
  • Code follows WordPress coding standards (tabs, Yoda conditions, escaping/sanitization)
  • Self-reviewed the diff
  • No new PHP warnings, notices, or deprecations
  • Tested on PHP 7.4 and 8.x (if touching compatibility-sensitive code)
  • Review requested from @polevaultweb

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Image custom field type to WP User Manager forms, using FilePond to provide an enhanced upload UI and preview behavior.

Changes:

  • Registers a new image field type and template for WPUM custom fields.
  • Enqueues FilePond assets and initializes FilePond on image inputs.
  • Updates Grunt build steps to bundle FilePond scripts/styles.

Reviewed changes

Copilot reviewed 7 out of 18 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
templates/form-fields/image-field.php New image field template that outputs the <input type="file"> and passes FilePond config via data attributes.
includes/fields/types/class-wpum-field-image.php New field type class extending the existing file field behavior for image-specific handling/output.
includes/fields/class-wpum-fields.php Registers image in the field loader list so the type becomes available.
includes/assets.php Enqueues FilePond bundle + CSS and the WPUM FilePond initializer script on relevant frontend pages.
assets/js/src/wpum-filepond.js FilePond initializer for WPUM image fields (source).
assets/js/wpum-filepond.js / assets/js/wpum-filepond.min.js Built artifacts for the initializer script.
assets/js/vendor/filepond/* Local vendor copies of FilePond core + plugins (inputs to bundling).
assets/css/vendor/filepond/* and assets/css/vendor/filepond.css Local vendor CSS and bundled CSS.
Gruntfile.js Adds concat/uglify targets for FilePond bundles and the new initializer script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +31
function parseFileTypes(types) {
if (!types) {
return ['image/*'];
}

var result = [];

types.split('|').forEach(function (type) {
type = type.trim().toLowerCase();

if (!type) {
return;
}

if (type.indexOf('/') !== -1) {
result.push(type);
} else {
result.push('image/' + type);
}
});

return result;
Comment on lines +48 to +83
// Register only the plugins that are available.
var plugins = [
window.FilePondPluginImagePreview,
window.FilePondPluginFileValidateType,
window.FilePondPluginFileValidateSize
].filter(function (plugin) {
return !!plugin;
});

if (plugins.length) {
FilePond.registerPlugin.apply(FilePond, plugins);
}

$(imageFields).each(function () {
const $input = $(this);

// Prevent double initialization.
if ($input.hasClass('filepond--root')) {
return;
}

const fileTypes = parseFileTypes($input.data('file_types'));
const wrapper = $input.closest('fieldset');
const fileUrl = $(wrapper).find('input[name="' + 'current_' + $input.attr('name') + '"]').val();

$input.filepond({
acceptedFileTypes: fileTypes,
allowFileSizeValidation: true,
allowFileTypeValidation: true,
allowImagePreview: true,
allowMultiple: false,
credits: false,
maxFileSize: $input.data('file_size'),
required: $input.prop('required'),
storeAsFile: true,

Comment thread includes/assets.php
Comment on lines +68 to +73
wp_enqueue_style( 'filepond-style', WPUM_PLUGIN_URL . 'assets/css/vendor/filepond.css', false, WPUM_VERSION );
wp_enqueue_script( 'filepond-js', WPUM_PLUGIN_URL . 'assets/js/vendor/filepond-bundle.min.js', array( 'jquery' ), WPUM_VERSION, true );

$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'wpum-frontend-js', WPUM_PLUGIN_URL . 'assets/js/wp-user-manager' . $suffix . '.js', array( 'jquery' ), WPUM_VERSION, true );
wp_enqueue_script( 'wpum-filepond-js', WPUM_PLUGIN_URL . 'assets/js/wpum-filepond' . $suffix . '.js', array( 'jquery', 'filepond-js' ), WPUM_VERSION, true );
$current_image = '';

if ( is_numeric( $data->value ) ) {
$current_image = wp_get_attachment_image_src( absint( $data->value ) )[0] ?? '';
Comment on lines +3 to +5
* The template for displaying the file field.
*
* This template can be overridden by copying it to yourtheme/wpum/form-fields/file-field.php

$extension = substr( strrchr( $image_src, '.' ), 1 );
$file_type = wp_ext2type( $extension );
$value = '<span class="wpum-uploaded-image-name"><img src="' . $image_src . '"></span>';
Comment on lines +99 to +103
$extension = substr( strrchr( $image_src, '.' ), 1 );
$file_type = wp_ext2type( $extension );
$value = '<span class="wpum-uploaded-image-name"><img src="' . $image_src . '"></span>';

return $value;
Comment thread Gruntfile.js
'assets/js/vendor/filepond/filepond.min.js',
'assets/js/vendor/filepond/filepond.jquery.js',
'assets/js/vendor/filepond/filepond-plugin-file-validate-type.min.js',
'assets/js/vendor/filepond/filepond-plugin-file-validate-size.min.js',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Field

2 participants