57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
class WPI_Admin_Page
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
add_action('admin_menu', [$this, 'menu']);
|
|
add_action('wp_ajax_wpi_import_api', [$this, 'import_api']);
|
|
add_action('wp_ajax_wpi_import_csv', [$this, 'import_csv']);
|
|
}
|
|
|
|
public function menu()
|
|
{
|
|
add_menu_page(
|
|
'Product Importer',
|
|
'Product Importer',
|
|
'manage_woocommerce',
|
|
'wpi-importer',
|
|
[$this, 'render']
|
|
);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
?>
|
|
<h1>Woo Product Importer</h1>
|
|
|
|
<h2>Import from API</h2>
|
|
<input type="text" id="api_url" placeholder="API URL">
|
|
<button id="import_api">Import API</button>
|
|
|
|
<h2>Import from CSV</h2>
|
|
<input type="file" id="csv_file">
|
|
<button id="import_csv">Import CSV</button>
|
|
<?php
|
|
}
|
|
|
|
public function import_api()
|
|
{
|
|
$url = sanitize_text_field($_POST['url']);
|
|
$importer = new WPI_API_Importer();
|
|
$result = $importer->import($url);
|
|
wp_send_json_success($result);
|
|
}
|
|
|
|
public function import_csv()
|
|
{
|
|
if (empty($_FILES['file'])) {
|
|
wp_send_json_error('No file');
|
|
}
|
|
$importer = new WPI_CSV_Importer();
|
|
$result = $importer->import($_FILES['file']['tmp_name']);
|
|
wp_send_json_success($result);
|
|
}
|
|
}
|