Skip to content

Commit

Permalink
Add form option to replace by post title
Browse files Browse the repository at this point in the history
  • Loading branch information
hissy committed Jul 10, 2016
1 parent 5ee68d8 commit 0f8ccff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions auto.js
@@ -0,0 +1,6 @@
(function($){
var form = $('#really-simple-csv-importer-form-options');
if ( form.length ) {
form.prependTo('#import-upload-form').show();
}
})(jQuery);
23 changes: 22 additions & 1 deletion rs-csv-importer.php
Expand Up @@ -67,6 +67,18 @@ function greet() {
echo ' <a href="'.plugin_dir_url( __FILE__ ).'sample/sample.ods">'.__( 'ods', 'really-simple-csv-importer' ).'</a>';
echo ' '.__('(OpenDocument Spreadsheet file format for LibreOffice. Please export as csv before import)', 'really-simple-csv-importer' );
echo '</p>';
?>
<div id="really-simple-csv-importer-form-options" style="display: none;">
<h2><?php _e( 'Import Options', 'really-simple-csv-importer' ); ?></h2>
<p><?php _e( 'Replace by post title', 'really-simple-csv-importer' ); ?></p>
<label>
<input type="radio" name="replace-by-title" value="0" checked="checked" /><?php _e( 'Disable', 'really-simple-csv-importer' ); ?>
</label>
<label>
<input type="radio" name="replace-by-title" value="1" /><?php _e( 'Enable', 'really-simple-csv-importer' ); ?>
</label>
</div>
<?php
wp_import_upload_form( add_query_arg('step', 1) );
}

Expand Down Expand Up @@ -205,7 +217,7 @@ function process_posts() {
$post_title = $h->get_data($this,$data,'post_title');
if ($post_title) {

if ( ! $is_update ) {
if ( ! $is_update && $_POST['replace-by-title'] == 1 ) {
//try to update a post with the same title
if ( ! $post_type ) {
$post_type = 'post';
Expand Down Expand Up @@ -481,4 +493,13 @@ function really_simple_csv_importer() {
}
add_action( 'plugins_loaded', 'really_simple_csv_importer' );

function really_simple_csv_importer_enqueue($hook) {
if ( 'admin.php' != $hook ) {
return;
}

wp_enqueue_script( 'really_simple_csv_importer_admin_script', plugin_dir_url( __FILE__ ) . 'auto.js', array(), false, true );
}
add_action( 'admin_enqueue_scripts', 'really_simple_csv_importer_enqueue' );

} // class_exists( 'WP_Importer' )

0 comments on commit 0f8ccff

Please sign in to comment.