Skip to content

Degree Importer

Jo Dickson edited this page May 8, 2018 · 3 revisions

This plugin includes a WP-CLI degree import script, which fetches program data from the UCF Search Service and imports it as degree posts. The importer is able to check for existing degree data on subsequent imports and update it if present; you can also exclude specific degrees from being updated or modified via the degree importer if necessary for unique degrees.

Command

$ wp degrees import

Options

  • api_base_url

    The base URL of the Search Service you want to pull from. The "Search Service Base URL" plugin option is used by default.

  • api_key

    The API key to query against the Search Service with. The "Search Service API Key" plugin option is used by default.

  • enable_search_writebacks

    If enabled, data will be written back to the Search Service when each degree is imported. Disabled by default. Accepted options: "True"/"False"

Examples

  • Explicitly import degrees from the production search service.

    $ wp degrees import --api_base_url="https://search.cm.ucf.edu/api/v1/" --api_key="xxxxxxxxxxxxxxxxx"

  • Enable Search Service writebacks during the import process.

    $ wp degrees import --enable_search_writebacks="True"

Notes

Remember to pass in the global --url option when running this command against a multisite instance to designate the specific site to run the command against.

Imported Data

The degree import script will import/update the following data. All values listed below will be overridden upon subsequent imports, and should therefore not be modified manually, unless otherwise noted:

  • Post title: the degree name
  • Post slug: custom slug value for the degree; is not modified on subsequent imports (can be modified manually)
  • College term(s): if the UCF Colleges Taxonomy plugin is activated, the degree's college(s) will be assigned.
  • Program Types: the "level" and "career" values from the UCF Search Service are assigned as program types.
  • Department(s): if the UCF Departments Taxonomy plugin is activated, the degree's department(s) will be assigned.
  • Parent post: if the degree is a subplan, the parent degree plan is assigned as the parent post.
  • Post meta:
    • degree_id: a unique identifier for the degree
    • degree_api_id: the ID of the degree in the UCF Search Service
    • degree_pdf: the URL of the degree's catalog description
    • degree_plan_code: the degree's plan code
    • degree_subplan_code: the degree's subplan code
    • degree_name_short: an abbreviated degree name; for subplans, this is the name of the degree with the parent degree's name excluded from the beginning.

Modify/Add Imported Metadata

Themes and other plugins can modify what post meta gets imported using the ucf_degree_get_post_metadata hook. Custom filters should always return an associative array of meta names and values.

Example

<?php
// Add the `my_custom_meta` meta value on all imported degrees
function my_custom_degree_meta( $meta, $program ) {
    $meta['my_custom_meta'] = '...';
    return $meta;
}
add_filter( 'ucf_degree_get_post_metadata', 'my_custom_degree_meta', 10, 2 );

Arguments

  • $meta: existing associative array of degree meta names and values
  • $program: the program object fetched from the Search Service

Modify/Add Imported Post Terms

Themes and other plugins can modify what taxonomy term data gets imported using the ucf_degree_get_post_terms hook. Custom filters should always return an associative array of taxonomy slugs and term names.

Example

<?php
// Add the "My Tag" and "Another Tag" post tags to all imported degrees
function my_custom_degree_terms( $terms, $program ) {
    $terms['post_tag'] = array( 'My Tag', 'Another Tag' );
    return $terms;
}
add_filter( 'ucf_degree_get_post_terms', 'my_custom_degree_terms', 10, 2 );

Arguments

  • $terms: existing associative array of taxonomy slugs and term names
  • $program: the program object fetched from the Search Service

Exclude Degrees from the Import Process

When the degree importer is run, any custom degree posts that don't have a valid plan code, subplan code, and parent degree plan assignment will be removed (because they don't match against any existing Search Service data). This may be undesirable when your site uses unique degrees not present in the Search Service, e.g. to define custom verticals or degree relationships.

To prevent a unique degree post from being modified or deleted by the degree importer, check the "Ignore On Import" checkbox in the "Degree Import Options" metabox for each degree you'd like to exclude.

Clone this wiki locally