Allow categories to be added when registering player positions from preset

This commit is contained in:
Brian Miyaji
2016-04-23 20:42:23 +10:00
parent 4dafde26cc
commit 22f46b3c53

View File

@@ -100,28 +100,21 @@ class SP_Admin_Sports {
// Positions // Positions
$positions = sp_array_value( $preset, 'positions', array() ); $positions = sp_array_value( $preset, 'positions', array() );
$i = 0; $i = 0;
foreach ( $positions as $parent => $position ) { foreach ( $positions as $position ) {
if ( is_array( $position ) ) { if ( is_string( $position ) ) {
$name = $position;
if ( ! term_exists( $parent, 'sp_position' ) ) { $sections = array( 0, 1 );
// Insert parent position
$slug = $i . '-' . sanitize_title( $parent );
wp_insert_term( $parent, 'sp_position', array( 'slug' => $slug ) );
}
// Insert positions with parent
foreach ( $position as $index => $child ) {
$parent_term = term_exists( $parent, 'sp_position' );
$parent_id = $parent_term['term_id'];
$slug = $index . '-' . sanitize_title( $child );
wp_insert_term( $child, 'sp_position', array( 'slug' => $slug, 'parent' => $parent_id ) );
}
} else { } else {
$name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) );
// Insert single position $sections = sp_array_value( $position, 'sections', array( 0, 1 ) );
$slug = $i . '-' . sanitize_title( $position );
wp_insert_term( $position, 'sp_position', array( 'slug' => $slug ) );
} }
$slug = $i . '-' . sanitize_title( $name );
$term = wp_insert_term( $name, 'sp_position', array( 'slug' => $slug ) );
if ( is_wp_error( $term ) ) continue;
$t_id = $term['term_id'];
$term_meta = get_option( "taxonomy_$t_id" );
$term_meta['sp_sections'] = $sections;
update_option( "taxonomy_$t_id", $term_meta );
$i++; $i++;
} }