Add duplicate merging option to staff and team importer
This commit is contained in:
@@ -72,7 +72,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
endif;
|
endif;
|
||||||
|
|
||||||
// Get or insert player
|
// Get or insert player
|
||||||
$player_object = get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' );
|
$player_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' ) : false;
|
||||||
if ( $player_object ):
|
if ( $player_object ):
|
||||||
if ( $player_object->post_status != 'publish' ):
|
if ( $player_object->post_status != 'publish' ):
|
||||||
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
|||||||
@@ -70,12 +70,20 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
continue;
|
continue;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
// Get or insert staff
|
||||||
|
$staff_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_staff' ) : false;
|
||||||
|
if ( $staff_object ):
|
||||||
|
if ( $staff_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $staff_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
$id = $staff_object->ID;
|
||||||
|
else:
|
||||||
|
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||||
|
$id = wp_insert_post( $args );
|
||||||
|
|
||||||
$id = wp_insert_post( $args );
|
// Flag as import
|
||||||
|
update_post_meta( $id, '_sp_import', 1 );
|
||||||
// Flag as import
|
endif;
|
||||||
update_post_meta( $id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
// Update roles
|
// Update roles
|
||||||
$roles = explode( '|', sp_array_value( $meta, 'sp_role' ) );
|
$roles = explode( '|', sp_array_value( $meta, 'sp_role' ) );
|
||||||
@@ -168,5 +176,29 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
wp_import_upload_form( 'admin.php?import=sp_staff_csv&step=1' );
|
wp_import_upload_form( 'admin.php?import=sp_staff_csv&step=1' );
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* options function.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function options() {
|
||||||
|
?>
|
||||||
|
<table class="form-table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="hidden" name="merge" value="0">
|
||||||
|
<input type="checkbox" name="merge" value="1" checked="checked">
|
||||||
|
<?php _e( 'Merge duplicates', 'sportspress' ); ?>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,12 +70,20 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
continue;
|
continue;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
// Get or insert team
|
||||||
|
$team_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_team' ) : false;
|
||||||
|
if ( $team_object ):
|
||||||
|
if ( $team_object->post_status != 'publish' ):
|
||||||
|
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
|
||||||
|
endif;
|
||||||
|
$id = $team_object->ID;
|
||||||
|
else:
|
||||||
|
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
|
||||||
|
$id = wp_insert_post( $args );
|
||||||
|
|
||||||
$id = wp_insert_post( $args );
|
// Flag as import
|
||||||
|
update_post_meta( $id, '_sp_import', 1 );
|
||||||
// Flag as import
|
endif;
|
||||||
update_post_meta( $id, '_sp_import', 1 );
|
|
||||||
|
|
||||||
// Update leagues
|
// Update leagues
|
||||||
$leagues = explode( '|', sp_array_value( $meta, 'sp_league' ) );
|
$leagues = explode( '|', sp_array_value( $meta, 'sp_league' ) );
|
||||||
@@ -127,5 +135,29 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' );
|
wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' );
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* options function.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function options() {
|
||||||
|
?>
|
||||||
|
<table class="form-table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="hidden" name="merge" value="0">
|
||||||
|
<input type="checkbox" name="merge" value="1" checked="checked">
|
||||||
|
<?php _e( 'Merge duplicates', 'sportspress' ); ?>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user