ACF_WPML_Compatibility::upgrade_500_field_group() public ACF 5.2.3
Update the icl_translations table data when creating the field groups.
{} Это метод класса: ACF_WPML_Compatibility{}
Хуков нет.
Возвращает
null.
Использование
$ACF_WPML_Compatibility = new ACF_WPML_Compatibility(); $ACF_WPML_Compatibility->upgrade_500_field_group( $field_group, $ofg );
- $field_group(массив) (обязательный)
- The new field group array.
- $ofg(объект) (обязательный)
- The old field group WP_Post object.
Список изменений
С версии 5.2.3 | Введена. |
Код ACF_WPML_Compatibility::upgrade_500_field_group() ACF WPML Compatibility::upgrade 500 field group ACF 5.9.1
function upgrade_500_field_group($field_group, $ofg) {
// global
global $wpdb;
// get translation rows (old acf4 and new acf5)
$old_row = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d",
'post_acf', $ofg->ID
), ARRAY_A);
$new_row = $wpdb->get_row($wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d",
'post_acf-field-group', $field_group['ID']
), ARRAY_A);
// bail ealry if no rows
if( !$old_row || !$new_row ) {
return;
}
// create reference of old trid to new trid
// trid is a simple int used to find associated objects
if( empty($this->trid_ref) ) {
$this->trid_ref = array();
}
// update trid
if( isset($this->trid_ref[ $old_row['trid'] ]) ) {
// this field group is a translation of another, update it's trid to match the previously inserted group
$new_row['trid'] = $this->trid_ref[ $old_row['trid'] ];
} else {
// this field group is the first of it's translations, update the reference for future groups
$this->trid_ref[ $old_row['trid'] ] = $new_row['trid'];
}
// update icl_translations
// Row is created by WPML, and much easier to tweak it here due to the very complicated and nonsensical WPML logic
$table = "{$wpdb->prefix}icl_translations";
$data = array( 'trid' => $new_row['trid'], 'language_code' => $old_row['language_code'] );
$where = array( 'translation_id' => $new_row['translation_id'] );
$data_format = array( '%d', '%s' );
$where_format = array( '%d' );
// allow source_language_code to equal NULL
if( $old_row['source_language_code'] ) {
$data['source_language_code'] = $old_row['source_language_code'];
$data_format[] = '%s';
}
// update wpdb
$result = $wpdb->update( $table, $data, $where, $data_format, $where_format );
}