|null */ private $settings_cache = null; /** * @param Siti_Stock_Settings $settings Settings repository. * @param Siti_Stock_Sync_Controller $sync_controller Sync controller. * @param Siti_Stock_Admin_Notices $notices Notice handler. * @param Siti_Stock_Supplier_Exports $supplier_exports Supplier exports handler. */ public function __construct( Siti_Stock_Settings $settings, Siti_Stock_Sync_Controller $sync_controller, Siti_Stock_Admin_Notices $notices, Siti_Stock_Supplier_Exports $supplier_exports ) { $this->settings = $settings; $this->sync_controller = $sync_controller; $this->notices = $notices; $this->supplier_exports = $supplier_exports; } /** * Register all admin-related hooks. */ public function register_hooks() { add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_menu', array( $this, 'register_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); add_action( 'admin_notices', array( $this, 'maybe_show_missing_dependencies' ) ); $this->notices->register_hooks(); } /** * Register settings sections/fields. */ public function register_settings() { $this->settings->register(); add_settings_section( 'siti_stock_api', __( 'API-instellingen', 'siti-stock-plugin' ), function () { echo '

' . esc_html__( 'Configureer het endpoint dat de actuele voorraad teruggeeft.', 'siti-stock-plugin' ) . '

'; }, 'siti-stock-plugin' ); add_settings_field( 'api_endpoint', __( 'API-endpoint', 'siti-stock-plugin' ), array( $this, 'render_text_field' ), 'siti-stock-plugin', 'siti_stock_api', array( 'key' => 'api_endpoint', 'placeholder' => 'https://example.com/api/stock', ) ); add_settings_field( 'api_key', __( 'API-sleutel', 'siti-stock-plugin' ), array( $this, 'render_text_field' ), 'siti-stock-plugin', 'siti_stock_api', array( 'key' => 'api_key', 'type' => 'password', 'description' => __( 'Wordt als Bearer-token meegestuurd.', 'siti-stock-plugin' ), ) ); add_settings_section( 'siti_stock_sync', __( 'Synchronisatie', 'siti-stock-plugin' ), function () { echo '

' . esc_html__( 'Stel in hoe en wanneer de voorraad automatisch bijgewerkt moet worden.', 'siti-stock-plugin' ) . '

'; }, 'siti-stock-plugin' ); add_settings_field( 'default_status', __( 'Standaardstatus', 'siti-stock-plugin' ), array( $this, 'render_select_field' ), 'siti-stock-plugin', 'siti_stock_sync', array( 'key' => 'default_status', 'options' => array( 'instock' => __( 'Op voorraad', 'siti-stock-plugin' ), 'outofstock' => __( 'Niet op voorraad', 'siti-stock-plugin' ), 'onbackorder'=> __( 'In nabestelling', 'siti-stock-plugin' ), ), ) ); add_settings_field( 'enable_auto_sync', __( 'Automatisch synchroniseren', 'siti-stock-plugin' ), array( $this, 'render_checkbox_field' ), 'siti-stock-plugin', 'siti_stock_sync', array( 'key' => 'enable_auto_sync', 'description' => __( 'Voer de synchronisatie periodiek uit via WP-Cron.', 'siti-stock-plugin' ), ) ); add_settings_field( 'sync_interval', __( 'Interval', 'siti-stock-plugin' ), array( $this, 'render_select_field' ), 'siti-stock-plugin', 'siti_stock_sync', array( 'key' => 'sync_interval', 'options' => array( 'siti_stock_quarter_hour' => __( 'Elke 15 minuten', 'siti-stock-plugin' ), 'hourly' => __( 'Elk uur', 'siti-stock-plugin' ), 'twicedaily' => __( 'Twee keer per dag', 'siti-stock-plugin' ), 'daily' => __( 'Dagelijks', 'siti-stock-plugin' ), ), ) ); } /** * Register admin menu page. */ public function register_menu() { add_menu_page( __( 'Siti Stock', 'siti-stock-plugin' ), __( 'Siti Stock', 'siti-stock-plugin' ), 'manage_options', 'siti-stock-plugin', array( $this, 'render_settings_page' ), 'dashicons-products' ); add_submenu_page( 'siti-stock-plugin', __( 'Stock updates', 'siti-stock-plugin' ), __( 'Stock updates', 'siti-stock-plugin' ), 'manage_options', 'siti-stock-plugin-stock-updates', array( $this, 'render_stock_updates_page' ) ); } /** * Enqueue admin assets only on our page. * * @param string $hook Hook suffix. */ public function enqueue_admin_assets( $hook ) { $pages = array( 'toplevel_page_siti-stock-plugin', 'siti-stock-plugin_page_siti-stock-plugin-stock-updates', ); if ( ! in_array( $hook, $pages, true ) ) { return; } wp_enqueue_style( 'siti-stock-admin', plugins_url( 'assets/css/admin.css', SITI_STOCK_PLUGIN_FILE ), array(), SITI_STOCK_PLUGIN_VERSION ); wp_enqueue_script( 'siti-stock-admin', plugins_url( 'assets/js/admin.js', SITI_STOCK_PLUGIN_FILE ), array( 'jquery' ), SITI_STOCK_PLUGIN_VERSION, true ); } /** * Display main admin page. */ public function render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = $this->get_settings_snapshot(); $next_run = $this->sync_controller->get_next_scheduled_run(); ?>

settings->get_settings_group() ); do_settings_sections( 'siti-stock-plugin' ); submit_button(); ?>

supplier_exports->get_supplier_configs(); $admin_email = get_option( 'admin_email' ); ?>

$config ) : ?>

$config ) : ?>
$args Field args. */ public function render_text_field( $args ) { $key = $args['key']; $type = isset( $args['type'] ) ? $args['type'] : 'text'; $placeholder = isset( $args['placeholder'] ) ? $args['placeholder'] : ''; $value = $this->get_settings_value( $key ); ?>

$args Field args. */ public function render_select_field( $args ) { $key = $args['key']; $value = $this->get_settings_value( $key ); $options = isset( $args['options'] ) ? $args['options'] : array(); ?> $args Arguments. */ public function render_checkbox_field( $args ) { $key = $args['key']; $value = (bool) $this->get_settings_value( $key ); ?>

' . esc_html__( 'WooCommerce is vereist voor de Siti Stock Plugin.', 'siti-stock-plugin' ) . '

'; } /** * Get cached settings snapshot for admin rendering. * * @return array */ private function get_settings_snapshot() { if ( null === $this->settings_cache ) { $this->settings_cache = $this->settings->get_all(); } return $this->settings_cache; } /** * Helper for retrieving a specific setting. * * @param string $key Array key. * @return mixed */ private function get_settings_value( $key ) { $settings = $this->get_settings_snapshot(); return isset( $settings[ $key ] ) ? $settings[ $key ] : ''; } }