Skip to content

Commit f4aec30

Browse files
committed
WPP importer
Fixes #161
1 parent 1d52d6e commit f4aec30

File tree

4 files changed

+1304
-25
lines changed

4 files changed

+1304
-25
lines changed

includes/admin/class-import-export.php

+32-25
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function __construct() {
4646
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
4747
add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ), 11 );
4848
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
49+
50+
new WPP_Importer();
4951
}
5052

5153
/**
@@ -59,6 +61,7 @@ public function admin_enqueue_scripts( $hook ) {
5961
if ( $hook === $this->parent_id ) {
6062
wp_enqueue_script( 'top-ten-admin-js' );
6163
wp_enqueue_style( 'top-ten-admin-css' );
64+
6265
}
6366
}
6467

@@ -164,7 +167,7 @@ public function render_page() {
164167

165168
<hr />
166169

167-
<form method="post">
170+
<form method="post">
168171

169172
<h2 style="padding-left:0px"><?php esc_html_e( 'Export tables', 'top-10' ); ?></h2>
170173
<p class="description">
@@ -194,42 +197,43 @@ public function render_page() {
194197
<br />
195198
<?php esc_html_e( 'Be careful when opening the file in Excel as it tends to change the date format. Recommended date-time format is YYYY-MM-DD H.', 'top-10' ); ?>
196199
</p>
197-
<p class="description">
200+
<p class="notice notice-warning">
198201
<strong><?php esc_html_e( 'Backup your database before proceeding so you will be able to restore it in case anything goes wrong.', 'top-10' ); ?></strong>
199202
</p>
200203
<p>
201204
<label><input type="checkbox" name="import_urls" id="import_urls" value="1" /> <?php esc_html_e( 'Use URLs instead of Post IDs in import', 'top-10' ); ?></label>
205+
<input type="hidden" name="tptn_action" value="import_tables" />
206+
<input type="hidden" name="network_wide" value="<?php echo ( is_network_admin() ? 1 : 0 ); ?>" />
202207
</p>
203-
<p>
204-
<label><input type="checkbox" name="reset_tables" id="reset_tables" value="1" checked="checked" /> <?php esc_html_e( 'Truncate tables on import. Unchecking this will keep existing counts and overwrite any counts which have the same post ID.', 'top-10' ); ?></label>
205-
</p>
206-
207-
<hr />
208-
209-
<h4 style="padding-left:0px"><?php esc_html_e( 'Import Overall Table', 'top-10' ); ?></h4>
210-
<p>
211-
<input type="file" name="import_file" />
212-
</p>
213-
<p>
214-
<?php submit_button( esc_html__( 'Import Overall CSV', 'top-10' ), 'primary', 'tptn_import_total', false ); ?>
215-
</p>
216-
217-
<hr />
218208

219-
<h4 style="padding-left:0px"><?php esc_html_e( 'Import Daily Table', 'top-10' ); ?></h4>
220-
<p>
221-
<input type="file" name="import_file_daily" />
222-
</p>
209+
<table class="form-table">
210+
<tr>
211+
<th scope="row"><?php esc_html_e( 'Import overall tables', 'top-10' ); ?></th>
212+
<td><input type="file" name="overall_table_file" /><br />
213+
<span class="description"><?php esc_html_e( 'CSV file', 'top-10' ); ?></span></td>
214+
</tr>
215+
<tr>
216+
<th scope="row"><?php esc_html_e( 'Import daily tables', 'top-10' ); ?></th>
217+
<td><input type="file" name="daily_table_file" /><br />
218+
<span class="description"><?php esc_html_e( 'CSV file', 'top-10' ); ?></span></td>
219+
</tr>
220+
</table>
223221
<p>
224-
<?php submit_button( esc_html__( 'Import Daily CSV', 'top-10' ), 'primary', 'tptn_import_daily', false ); ?>
222+
<?php submit_button( esc_html__( 'Import Tables', 'top-10' ), 'primary', 'tptn_import', false ); ?>
225223
</p>
226224

227-
<input type="hidden" name="tptn_action" value="import_tables" />
228-
<input type="hidden" name="network_wide" value="<?php echo ( is_network_admin() ? 1 : 0 ); ?>" />
229-
230225
<?php wp_nonce_field( 'tptn_import_nonce', 'tptn_import_nonce' ); ?>
231226
</form>
232227

228+
<?php
229+
/**
230+
* Action hook to add additional import/export options.
231+
*
232+
* @since 3.3.0
233+
*/
234+
do_action( 'tptn_admin_import_export_tab_content' );
235+
?>
236+
233237
</div><!-- /#post-body-content -->
234238

235239
<div id="postbox-container-1" class="postbox-container">
@@ -407,17 +411,20 @@ public static function import_tables() {
407411
} else {
408412
return;
409413
}
414+
410415
if ( isset( $_POST['network_wide'] ) ) {
411416
$network_wide = intval( $_POST['network_wide'] );
412417
} else {
413418
return;
414419
}
420+
415421
if ( isset( $_POST['import_urls'] ) ) {
416422
$import_urls = intval( $_POST['import_urls'] );
417423
++$column_count;
418424
} else {
419425
$import_urls = 0;
420426
}
427+
421428
if ( isset( $_POST['reset_tables'] ) ) {
422429
$reset_tables = intval( $_POST['reset_tables'] );
423430
} else {

0 commit comments

Comments
 (0)