Merge pull request #31238 from LuigiPulcini/add/generate-field-html

Add action hook to generate a custom field type.
This commit is contained in:
Barry Hughes 2022-03-21 10:54:40 -07:00 committed by GitHub
commit 3dc4f7cea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -329,6 +329,22 @@ abstract class WC_Settings_API {
if ( method_exists( $this, 'generate_' . $type . '_html' ) ) {
$html .= $this->{'generate_' . $type . '_html'}( $k, $v );
} elseif ( has_filter( 'woocommerce_generate_' . $type . '_html' ) ) {
/**
* Allow the generation of custom field types on the settings screen.
*
* The dynamic portion of the hook name refers to the slug of the custom field type.
* For instance, to introduce a new field type `fancy_lazy_dropdown` you would use
* the hook `woocommerce_generate_fancy_lazy_dropdown_html`.
*
* @since 6.5.0
*
* @param string $field_html The markup of the field being generated (initiated as an empty string).
* @param string $key The key of the field.
* @param array $data The attributes of the field as an associative array.
* @param object $wc_settings The current WC_Settings_API object.
*/
$html .= apply_filters( 'woocommerce_generate_' . $type . '_html', '', $k, $v, $this );
} else {
$html .= $this->generate_text_html( $k, $v );
}