class Cherry_Picker_Admin { private $plugin_name; private $version; public function __construct($plugin_name, $version) { $this->plugin_name = $plugin_name; $this->version = $version; } public function enqueue_styles() { wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/cherry-picker-admin.css', array(), $this->version, 'all'); } private static function get_adapters_base_url() { return plugin_dir_url(__FILE__) . 'js/adapters/'; } public static function get_adapters_list() { $adapters = [ 'amazon.*' => 'amazon.js', 'aliexpress.*' => 'aliexpress.js', 'iherb.com' => 'iherb.js', 'xiaomi-mi.*' => 'xiaomi.js', 'gearbest.com' => 'gearbest.js', 'next.*' => 'next.js', 'poshmark.com' => 'poshmark.js', 'laredoute.*' => 'redoute.js' // Ajout de La Redoute ]; error_log("[Cherry Picker] Adapters list: " . json_encode($adapters)); // Log des adaptateurs return apply_filters('cherry_picker_adapters', $adapters); } public function enqueue_scripts() { wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/cherry-picker-admin.js', array('jquery'), $this->version, false); } public function render_admin_page() { $this->options = get_option('cherry_picker_options'); require_once plugin_dir_path(dirname(__FILE__)) . 'admin/partials/cherry-picker-admin-display.php'; } public function admin_plugin_page() { add_menu_page(__('Cherry Picker Settings', 'cherry-picker'), __('Cherry Picker', 'cherry-picker'), 'manage_options', 'custompage', [$this, 'render_admin_page'], 'dashicons-plus-alt', '55'); } public static function generate_boormarklet() { $supported = json_encode(self::get_adapters_list()); $tpl = '(function() { console.log("[Cherry Picker] Bookmarklet executed"); // Log lors de l'exécution const supported = %3$s; console.log("[Cherry Picker] Supported adapters:", supported); const adapterBase = "%4$s"; const supportedIndex = Object.keys(supported).find(function(site) { console.log("[Cherry Picker] Checking site:", site, window.location.href); return new RegExp(site).test(window.location.href); }); console.log("[Cherry Picker] Supported index:", supportedIndex); if (supportedIndex === undefined) { console.error("[Cherry Picker] Site not supported"); alert("Site not supported"); return; } var script = document.createElement("script"); script.src = "%1$s"; console.log("[Cherry Picker] Loading bundle from:", script.src); window.cherryPickerSubmitUrl = "%2$s"; window.adapterUrl = supported[supportedIndex].startsWith("http") ? supported[supportedIndex] : adapterBase + supported[supportedIndex]; console.log("[Cherry Picker] Adapter URL:", window.adapterUrl); document.body.appendChild(script); })()'; $bundle_url = defined('CP_BUNDLE_URL') ? CP_BUNDLE_URL : plugin_dir_url(__DIR__) . 'public/js/bundle.js'; $form_action = admin_url('admin-post.php'); $bookmark = sprintf( $tpl, $bundle_url, $form_action, $supported, self::get_adapters_base_url() ); printf('%s', __('CherryPick', 'cherry-pick')); } public function register_settings_group() { register_setting( 'my_option_group', 'cherry_picker_options', [$this, 'sanitize'] ); add_settings_section( 'setting_section_id', __('General settings'), array($this, 'print_section_info'), 'custompage' ); add_settings_field( 'default_status', 'Default product status', array($this, 'status_select_callback'), 'custompage', 'setting_section_id' ); } public function sanitize($input) { $new_input = array(); if (isset($input['default_status'])) { $new_input['default_status'] = sanitize_text_field($input['default_status']); } if (isset($input['title'])) { $new_input['title'] = sanitize_text_field($input['title']); } return $new_input; } public function status_select_callback() { $options = ''; $selected = $this->options['default_status']; $statuses = [ null => __('Select'), 'publish' => __('Public', 'cherry-pick'), 'draft' => __('Draft', 'cherry-pick') ]; foreach ($statuses as $key => $status) { $options .= sprintf('', $key, $status, selected($selected, $key, false)); } printf( '
', $options ); _e('Select default status for products created via Cherry Picker
', 'cherry-picker'); } public function print_section_info() { // } }