WC_Data::is_internal_meta_key()protectedWC 3.2.0

Check if the key is an internal one.

Method of the class: WC_Data{}

No Hooks.

Return

true|false. true if it's an internal key, false otherwise

Usage

// protected - for code of main (parent) or child class
$result = $this->is_internal_meta_key( $key );
$key(string) (required)
Key to check.

Changelog

Since 3.2.0 Introduced.

WC_Data::is_internal_meta_key() code WC 8.6.1

protected function is_internal_meta_key( $key ) {
	$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );

	if ( ! $internal_meta_key ) {
		return false;
	}

	$has_setter_or_getter = is_callable( array( $this, 'set_' . ltrim( $key, '_' ) ) ) || is_callable( array( $this, 'get_' . ltrim( $key, '_' ) ) );

	if ( ! $has_setter_or_getter ) {
		return false;
	}

	if ( in_array( $key, $this->legacy_datastore_props, true ) ) {
		return true; // return without warning because we don't want to break legacy code which was calling add/get/update/delete meta.
	}

	/* translators: %s: $key Key to check */
	wc_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'woocommerce' ), $key ), '3.2.0' );

	return true;
}