ACF_Admin_Internal_Post_Type_List::check_sync
Checks for the custom "acfsync" action.
Метод класса: ACF_Admin_Internal_Post_Type_List{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$ACF_Admin_Internal_Post_Type_List = new ACF_Admin_Internal_Post_Type_List(); $ACF_Admin_Internal_Post_Type_List->check_sync();
Список изменений
| С версии 5.9.0 | Введена. |
Код ACF_Admin_Internal_Post_Type_List::check_sync() ACF Admin Internal Post Type List::check sync ACF 6.4.2
public function check_sync() {
// Verify capability.
if ( ! acf_current_user_can_admin() ) {
return;
}
$args = acf_request_args(
array(
'acfsynccomplete' => '',
'acfsync' => '',
'post' => '',
'action2' => '',
)
);
// Display notice on success redirect.
if ( ! empty( $args['acfsynccomplete'] ) ) {
check_admin_referer( 'bulk-posts' );
$synced = array_map( 'intval', explode( ',', $args['acfsynccomplete'] ) );
$text = $this->get_action_notice_text( 'acfsynccomplete', count( $synced ) );
$links = array();
foreach ( $synced as $synced_id ) {
$links[] = sprintf(
'<a href="%1$s">%2$s</a>',
get_edit_post_link( $synced_id ),
get_the_title( $synced_id )
);
}
$text .= ' ' . implode( ', ', $links );
// Add notice.
acf_add_admin_notice( $text, 'success' );
return;
}
// Find items to sync.
$keys = array();
if ( ! empty( $args['acfsync'] ) ) {
$keys[] = sanitize_text_field( $args['acfsync'] );
} elseif ( ! empty( $args['post'] ) && 'acfsync' === $args['action2'] ) {
$keys = array_map( 'sanitize_text_field', $args['post'] );
}
if ( $keys && $this->sync ) {
check_admin_referer( 'bulk-posts' );
// Disable "Local JSON" controller to prevent the .json file from being modified during import.
acf_update_setting( 'json', false );
// Sync the items and generate array of new IDs.
$files = acf_get_local_json_files( $this->post_type );
$nonce = wp_create_nonce( 'bulk-posts' );
$synced = array();
foreach ( $this->sync as $key => $post ) {
if ( $post['key'] && in_array( $post['key'], $keys ) ) {
// Import.
} elseif ( $post['ID'] && in_array( $post['ID'], $keys ) ) {
// Import.
} else {
// Ignore.
continue;
}
$local_post = json_decode( file_get_contents( $files[ $key ] ), true );
$local_post['ID'] = $post['ID'];
$result = acf_import_internal_post_type( $local_post, $this->post_type );
$synced[] = $result['ID'];
}
// Redirect.
wp_safe_redirect( $this->get_current_admin_url( '&_wpnonce=' . $nonce . '&acfsynccomplete=' . implode( ',', $synced ) ) );
exit;
}
}