WC_Structured_Data::set_data
Sets data.
Метод класса: WC_Structured_Data{}
Хуков нет.
Возвращает
bool.
Использование
$WC_Structured_Data = new WC_Structured_Data(); $WC_Structured_Data->set_data( $data, $reset );
- $data(массив) (обязательный)
- Structured data. The
@typevalue accepts a string or an array of strings. Every type must contain 1 to 20 ASCII letters; any invalid array member rejects the node. - $reset(true|false)
- Unset data .
По умолчанию:false)
Список изменений
| С версии 3.0.0 | Введена. |
| С версии 11.2.0 | Added support for multiple schema types in @type. |
Код WC_Structured_Data::set_data() WC Structured Data::set data WC 11.3.0
public function set_data( $data, $reset = false ) {
if ( isset( $data['@type'] ) && is_array( $data['@type'] ) ) {
if ( empty( $data['@type'] ) ) {
return false;
}
foreach ( $data['@type'] as $type ) {
if ( ! is_string( $type ) || ! preg_match( '|^[a-zA-Z]{1,20}$|', $type ) ) {
return false;
}
}
$data['@type'] = array_values( $data['@type'] );
} elseif ( ! isset( $data['@type'] ) || ! preg_match( '|^[a-zA-Z]{1,20}$|', $data['@type'] ) ) {
return false;
}
if ( $reset && isset( $this->_data ) ) {
unset( $this->_data );
}
$this->_data[] = $data;
return true;
}