ACF_Admin_Tool_Import::import_cpt_uipublicACF 6.1

Handles the import of CPTUI post types and taxonomies.

Метод класса: ACF_Admin_Tool_Import{}

Хуков нет.

Возвращает

ACF_Admin_Notice.

Использование

$ACF_Admin_Tool_Import = new ACF_Admin_Tool_Import();
$ACF_Admin_Tool_Import->import_cpt_ui( $import_args );
$import_args(массив) (обязательный)
What to import.

Список изменений

С версии 6.1 Введена.

Код ACF_Admin_Tool_Import::import_cpt_ui() ACF 6.4.2

public function import_cpt_ui( $import_args ) {
	if ( ! is_array( $import_args ) ) {
		return acf_add_admin_notice( __( 'Nothing from Custom Post Type UI plugin selected for import.', 'acf' ), 'warning' );
	}

	$imported = array();

	// Import any post types.
	if ( in_array( 'post_types', $import_args, true ) ) {
		$cptui_post_types = get_option( 'cptui_post_types' );
		$instance         = acf_get_internal_post_type_instance( 'acf-post-type' );

		if ( ! is_array( $cptui_post_types ) || ! $instance ) {
			return acf_add_admin_notice( __( 'Failed to import post types.', 'acf' ), 'warning' );
		}

		foreach ( $cptui_post_types as $post_type ) {
			$result = $instance->import_cptui_post_type( $post_type );

			if ( is_array( $result ) && isset( $result['ID'] ) ) {
				$imported[] = (int) $result['ID'];
			}
		}
	}

	// Import any taxonomies.
	if ( in_array( 'taxonomies', $import_args, true ) ) {
		$cptui_taxonomies = get_option( 'cptui_taxonomies' );
		$instance         = acf_get_internal_post_type_instance( 'acf-taxonomy' );

		if ( ! is_array( $cptui_taxonomies ) || ! $instance ) {
			return acf_add_admin_notice( __( 'Failed to import taxonomies.', 'acf' ), 'warning' );
		}

		foreach ( $cptui_taxonomies as $taxonomy ) {
			$result = $instance->import_cptui_taxonomy( $taxonomy );

			if ( is_array( $result ) && isset( $result['ID'] ) ) {
				$imported[] = (int) $result['ID'];
			}
		}
	}

	if ( ! empty( $imported ) ) {
		// Generate text.
		$total = count( $imported );
		/* translators: %d - number of items imported from CPTUI */
		$text = sprintf( _n( 'Imported %d item from Custom Post Type UI -', 'Imported %d items from Custom Post Type UI -', $total, 'acf' ), $total );

		// Add links to text.
		$links = array();
		foreach ( $imported as $id ) {
			$links[] = '<a href="' . get_edit_post_link( $id ) . '">' . get_the_title( $id ) . '</a>';
		}

		$text .= ' ' . implode( ', ', $links );
		$text .= __( '. The Custom Post Type UI plugin can be deactivated.', 'acf' );

		return acf_add_admin_notice( $text, 'success' );
	}

	return acf_add_admin_notice( __( 'Nothing to import', 'acf' ), 'warning' );
}