Skip to content

Commit

Permalink
Merge pull request #176 from PRX/fix_cat_desc_import
Browse files Browse the repository at this point in the history
Improve the import term description to include Drupal images
  • Loading branch information
brandonhundt authored Mar 22, 2024
2 parents 7addfd1 + ca5cd40 commit 28ca0a7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,9 @@ public function get_taxonomies_terms( $taxonomy, $limit = 1000, $taxonomy_name =
* @return int Number of inserted terms
*/
public function insert_taxonomies_terms( $terms, $taxonomy ) {

global $fgd2wpp;

$terms_count = 0;
$processed_terms_count = count( $terms );
$term_metakey = '_fgd2wp_old_taxonomy_id';
Expand Down Expand Up @@ -1665,7 +1668,14 @@ public function insert_taxonomies_terms( $terms, $taxonomy ) {

// Description
if ( isset( $term['description'] ) ) {
$args['description'] = $term['description'];
// $args['description'] = $term['description'];

// DINKUM: Add media support to taxonomy description.
$term_body = $fgd2wpp->replace_media_shortcodes( $term['description'] );
$term_media = $this->import_media_from_content( $term_body );
$term_description = $this->process_content( $term_body, $term_media['media'] );

$args['description'] = $term_description;
}

// Parent term
Expand All @@ -1681,8 +1691,14 @@ public function insert_taxonomies_terms( $terms, $taxonomy ) {
// Hook before inserting the term
$args = apply_filters( 'fgd2wp_pre_insert_taxonomy_term', $args, $term, $wp_taxonomy );

// Allow html in description
pri_allow_html_term_description( true );

$new_term = wp_insert_term( $term['name'], $wp_taxonomy, $args );

// Disallow html in description
pri_allow_html_term_description( false );

// Store the last ID to resume the import where it left off
$term_id_without_prefix = preg_replace( '/^(\D*)/', '', $term_id );
update_option( $last_taxonomy_metakey, $term_id_without_prefix );
Expand Down
22 changes: 22 additions & 0 deletions wp-content/plugins/pri-migration-helper/migration/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,25 @@ function pri_migration_tw_how_many_nodes_to_import( $how_many_nodes_to_import, $
return $how_many_nodes_to_import;
}
add_filter( 'tw_how_many_nodes_to_import', 'pri_migration_tw_how_many_nodes_to_import', 10, 2 );

/**
* Allow and disallow HTML tags.
*
* @param bool $allow Allow HTML tags.
*
* @return void
*/
function pri_allow_html_term_description( bool $allow ) {

if ( $allow ) {
remove_filter( 'term_description', 'wp_kses_data' );
remove_filter( 'pre_term_description', 'wp_filter_kses' );
add_filter( 'term_description', 'wp_kses_post' );
add_filter( 'pre_term_description', 'wp_filter_post_kses' );
} else {
add_filter( 'term_description', 'wp_kses_data' );
add_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_post' );
remove_filter( 'pre_term_description', 'wp_filter_post_kses' );
}
}

0 comments on commit 28ca0a7

Please sign in to comment.