@ Age
Yes, it is possible. But, I have not worked out the code to do so. I think it would be pretty straightforward…
You would use the cncsv_map_import_fields filter to add the Certifications field mapping choice to the drop down.
You would also use the cncsv_import_fields to register the callback to import the Certifications. Much like importing the meta code.
The code within the function would be nearly identical to the code in the file class.cncsv-entry.php file in the processTerms() method around line 518. This file is part of the Connections CSV Import extension.
Off the top, the only changes would be changing the taxonomy from category to certification and the elseif to add the default could be removed since it is not required.
Something like this (untested):
add_filter( 'cncsv_map_import_fields', 'cncsv_import_certifications_field_option' );
function cncsv_import_certifications_field_option( $fields ) {
$fields['certifications'] = 'Certifications';
return $fields;
}
add_action( 'cncsv_import_fields', 'cncsv_import_certification_field_import', 10, 3 );
function cncsv_import_certification_field_import( $id, $row, $entry ) {
$termIDs = array();
$parsed = $entry->arrayPull( $row, 'certification', $termIDs );
if ( ! empty( $parsed ) ) {
/*
* Convert the supplied certifications to an array and sanitize.
* Apply the same filters added to the core WP default filters for `pre_term_name` so the certification name
* will return a match if it exists.
*/
$certifications = explode( ',', $parsed );
$certifications = array_map( 'sanitize_text_field', $certifications );
$certifications = array_map( 'wp_filter_kses', $certifications );
$certifications = array_map( '_wp_specialchars', $certifications );
foreach ( $certifications as $certification ) {
// Query the db for the term to be added.
$term = cnTerm::getBy( 'name', $certification, 'certification' );
if ( $term instanceof cnTerm_Object ) {
$termIDs[] = $term->term_id;
} else {
// Add the new certification.
$insert_result = cnTerm::insert( $certification, 'certification', array( 'slug' => '', 'parent' => '0', 'description' => '' ) );
if ( ! is_wp_error( $insert_result ) ) {
$termIDs[] = $insert_result['term_id'];
}
}
}
}
// Do not set certification relationships if $termIDs is empty because if updating, it will delete existing relationships.
if ( ! empty( $termIDs ) ) Connections_Directory()->term->setTermRelationships( $id, $termIDs, 'certification' );
}
-
This reply was modified 8 years, 1 month ago by
Steven Zahm. Reason: Code corrections
