Automattic\WooCommerce\Admin\Features\ProductBlockEditor

Init::register_user_metas()publicWC 1.0

Register user metas.

Method of the class: Init{}

No Hooks.

Return

null. Nothing (null).

Usage

$Init = new Init();
$Init->register_user_metas();

Init::register_user_metas() code WC 9.0.1

public function register_user_metas() {
	register_rest_field(
		'user',
		'metaboxhidden_product',
		array(
			'get_callback'    => function ( $object, $attr ) {
				$hidden = get_user_meta( $object['id'], $attr, true );

				if ( is_array( $hidden ) ) {
					// Ensures to always return a string array.
					return array_values( $hidden );
				}

				return array( 'postcustom' );
			},
			'update_callback' => function ( $value, $object, $attr ) {
				// Update the field/meta value.
				update_user_meta( $object->ID, $attr, $value );
			},
			'schema'          => array(
				'type'        => 'array',
				'description' => __( 'The metaboxhidden_product meta from the user metas.', 'woocommerce' ),
				'items'       => array(
					'type' => 'string',
				),
				'arg_options' => array(
					'sanitize_callback' => 'wp_parse_list',
					'validate_callback' => 'rest_validate_request_arg',
				),
			),
		)
	);
}