Automattic\WooCommerce\Internal\Admin\ProductForm
FormFactory::create_item
Creates a new item.
Метод класса: FormFactory{}
Хуков нет.
Возвращает
Field|Card|Section|Tab|WP_Error. New product form item or WP_Error.
Использование
$result = FormFactory::create_item( $type, $class_name, $id, $plugin_id, $args );
- $type(строка) (обязательный)
- Form component type.
- $class_name(class-string) (обязательный)
- Class of component type.
- $id(строка) (обязательный)
- Item id.
- $plugin_id(строка) (обязательный)
- Plugin id.
- $args(массив) (обязательный)
- additional arguments for item.
Код FormFactory::create_item() FormFactory::create item WC 10.3.5
private static function create_item( $type, $class_name, $id, $plugin_id, $args ) {
$item_list = self::get_item_list( $type );
$class = 'Automattic\\WooCommerce\\Internal\\Admin\\ProductForm\\' . $class_name;
if ( ! class_exists( $class ) ) {
return new WP_Error(
'wc_product_form_' . $type . '_missing_form_class',
sprintf(
/* translators: 1: missing class name. */
esc_html__( '%1$s class does not exist.', 'woocommerce' ),
$class
)
);
}
if ( isset( $item_list[ $id ] ) ) {
return new WP_Error(
'wc_product_form_' . $type . '_duplicate_field_id',
sprintf(
/* translators: 1: Item type 2: Duplicate registered item id. */
esc_html__( 'You have attempted to register a duplicate form %1$s with WooCommerce Form: %2$s', 'woocommerce' ),
$type,
'`' . $id . '`'
)
);
}
$defaults = array(
'order' => 20,
);
$item_arguments = wp_parse_args( $args, $defaults );
try {
return new $class( $id, $plugin_id, $item_arguments );
} catch ( \Exception $e ) {
return new WP_Error(
'wc_product_form_' . $type . '_class_creation',
$e->getMessage()
);
}
}