Opened 10 months ago
Closed 8 days ago
#62086 closed enhancement (fixed)
Add Filter for Custom Form Attributes in New Site Creation (/wp-admin/network/site-new.php)
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.9 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Networks and Sites | Keywords: | has-patch has-test-info |
Focuses: | administration, multisite | Cc: |
Description
When adding a new site in a WordPress Multisite Network (via /wp-admin/network/site-new.php
), the form does not provide a filter to allow the addition of custom attributes, such as enctype="multipart/form-data"
, which is necessary for handling file uploads during new site creation.
This issue arises when developers need to extend the new site creation form to allow file uploads (e.g., custom site logos or configuration files). However, since there is no hook or filter to modify the form attributes, it is currently impossible to add the enctype="multipart/form-data"
attribute to the form without overriding core files.
Change History (14)
This ticket was mentioned in PR #7402 on WordPress/wordpress-develop by @sakibmoon.
10 months ago
#1
This ticket was mentioned in PR #7403 on WordPress/wordpress-develop by @sakibmoon.
10 months ago
#2
This change introduces the network_site_new_form_attributes
filter to the site creation form (/wp-admin/network/site-new.php
) in WordPress Multisite.
The filter allows developers to modify form attributes such as enctype="multipart/form-data"
, enabling file uploads or other custom behaviors when creating a new site.
This enhancement provides more flexibility for developers extending the multisite functionality without requiring modifications to core files.
Trac ticket: https://core.trac.wordpress.org/ticket/62086
4 months ago
#4
@sakibmoon There might be some room to improve this PR.
- If the filter returns something like
autocomplete="off"
, it will be appended directly after theclass
attribute, resulting in:
<form method="post" action="site-new.php" class="wp-validate"autocomplete="off">
Which is invalid HTML due to the missing space. You could add a check to prepend a space if needed.
- It might also be worth considering some sanitization or validation of the filtered output — perhaps passing it through something like wp_kses_attr_check() or at least documenting that the output should be properly escaped HTML attributes.
Thanks for your work on this!
This ticket was mentioned in Slack in #core-multisite by realloc. View the logs.
3 months ago
#7
follow-up:
↓ 8
@
3 months ago
What if we just add enctype="multipart/form-data"
to the form? 🧐
What I don't like about putting a filter in there is that it would be unique. No other form attributes have filters like that, and introducing a new pattern (that could be used on many forms in WordPress Admin) would require a bunch of scrutiny.
What I like about adding it directly, is it:
- doesn't change any behavior if there are no attachments
- allows for plugins to do what is being proposed
- adds a commonly used attribute that nav-menus already appears to have without handling attachments
What I don't like about adding it directly, is:
- it's potentially confusing that the core form doesn't actually need it (maybe we add an inline doc?)
#8
in reply to:
↑ 7
@
2 months ago
Replying to johnjamesjacoby:
What if we just add
enctype="multipart/form-data"
to the form? 🧐
IMHO, that would be a much better solution than relying on the filter.
This ticket was mentioned in PR #9084 on WordPress/wordpress-develop by @realloc.
12 days ago
#10
This PR adds the enctype="multipart/form-data" attribute to the site creation form on /wp-admin/network/site-new.php.
Related ticket: https://core.trac.wordpress.org/ticket/62086
#11
@
12 days ago
- Keywords needs-testing added; changes-requested removed
- Owner set to realloc
- Status changed from new to assigned
#12
@
12 days ago
- Keywords has-test-info added; needs-testing removed
Test Report
Description
✅ This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/9084.diff
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 137.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-One 2.5
- MU Plugins: None activated
- Plugins:
- Network Site Logo 1.0.0
- Test Reports 1.2.0
Patch Testing Instructions
- Create a Multisite
- Add the code provided in supplemental artifacts for testing. Basically, I'm adding as OP suggested, a field to add a logo. You can modify the code and add whatever field you like for the test
- Go to
/wp-admin/network/site-new.php
- Add the file or whatever content you have added in the form
- Check in the DB, in the new options table for the newly created multisite, example
wp_2_options
thesite_logo_url
field has been introduced with the URL of the logo.
Actual Results
- ✅ Issue resolved with patch.
Supplemental Artifacts
Testing Code:
function add_ms_logo_field() { ?> <tr class="form-field"> <th scope="row"><label for="site-logo"><?php echo 'Site Logo'; ?></label></th> <td><input name="site_logo" type="file" id="site-logo" /></td> </tr> <?php } add_action( 'network_site_new_form', 'add_ms_logo_field' ); function save_ms_logo( $new_site ) { require_once ABSPATH . 'wp-admin/includes/file.php'; switch_to_blog( $new_site->blog_id ); $upload_overrides = array( 'test_form' => false ); $logofile = wp_handle_upload( $_FILES['site_logo'], $upload_overrides ); update_option( 'site_logo_url', $logofile['url'] ); restore_current_blog(); } add_action( 'wp_initialize_site', 'save_ms_logo', 10, 1 );
This change introduces the
network_site_new_form_attributes
filter to the site creation form (/wp-admin/network/site-new.php
) in WordPress Multisite.The filter allows developers to modify form attributes such as
enctype="multipart/form-data"
, enabling file uploads or other custom behaviors when creating a new site.This enhancement provides more flexibility for developers extending the multisite functionality without requiring modifications to core files.
Trac ticket: https://core.trac.wordpress.org/ticket/62086