Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Last active August 18, 2016 20:21
Show Gist options
  • Save stephanieleary/5ff713797644043a9546c850011ecc77 to your computer and use it in GitHub Desktop.
Save stephanieleary/5ff713797644043a9546c850011ecc77 to your computer and use it in GitHub Desktop.
Example filters to add or edit custom fields for the Citation Importer plugin.
<?php
/*
Plugin Name: Citation Importer Filters
Plugin URI: http://stephanieleary.com/
Description: Add or edit fields for the Citation Importer.
Author: sillybean
Author URI: http://stephanieleary.com/
Version: 0.1
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
add_filter( 'citation_importer_fielddata', 'filter_citation_importer_source_fields', 10, 3 );
function filter_citation_importer_source_fields( $fields, $post, $item ) {
$fields['source'] = sanitize_text_field( $item['container-title'][0] );
if ( isset( $item['volume'] ) && !empty( $item['volume'] ) )
$fields['volume'] = sanitize_text_field( $item['volume'] );
if ( isset( $item['issue'] ) &&!empty( $item['issue'] ) )
$fields['issue'] = sanitize_text_field( $item['issue'] );
if ( isset( $item['page'] ) &&!empty( $item['page'] ) )
$fields['page'] = sanitize_text_field( $item['page'] );
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment