admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'pdfib_ajax' ), ) ); \wp_localize_script( 'jquery', 'pdfBuilderAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'pdfib_ajax' ), 'debug' => array( 'enabled' => true, 'level' => 'info', 'console' => true, 'server' => false, ), 'strings' => array( 'loading' => __( 'Chargement...', 'advanced-pdf-invoice-builder' ), 'error' => __( 'Erreur', 'advanced-pdf-invoice-builder' ), 'success' => __( 'Succès', 'advanced-pdf-invoice-builder' ), 'saving' => __( 'Sauvegarde en cours...', 'advanced-pdf-invoice-builder' ), ), ) ); } /** * Enregistre les scripts pour l'éditeur React (pdf-builder-react-editor). */ function pdfib_register_react_editor_scripts(): void { add_action( 'admin_enqueue_scripts', function ( $hook ) { $on_react_editor = 'pdf-builder_page_pdf-builder-react-editor' === $hook || ( isset( $GLOBALS['_GET']['page'] ) && 'pdf-builder-react-editor' === $GLOBALS['_GET']['page'] ); if ( ! $on_react_editor ) { return; } $bundle_url = PDFIB_PLUGIN_URL . 'assets/js/pdf-builder-react-wrapper.min.js'; \wp_enqueue_script( 'pdf-builder-react-bundle', $bundle_url, array( 'wp-element', 'jquery' ), PDFIB_VERSION . '-' . time(), true ); $template_id = isset( $GLOBALS['_GET']['template_id'] ) ? intval( wp_unslash( $GLOBALS['_GET']['template_id'] ) ) : 0; $editor_action = isset( $GLOBALS['_GET']['editor_action'] ) ? sanitize_key( wp_unslash( $GLOBALS['_GET']['editor_action'] ) ) : ''; $is_creating = 'new' === $editor_action || 0 === $template_id; // Récupérer les informations sur les templates et la limite $user_id = get_current_user_id(); $templates_count = 0; $template_limit = 1; $is_premium = false; if ( class_exists( '\PDFIB\Admin\PdfBuilderAdmin' ) ) { $templates_count = \PDFIB\Admin\PdfBuilderAdmin::count_user_custom_templates( $user_id ); $pdfib_license_manager = apply_filters( 'pdfib_license_manager_instance', null ); $is_premium = is_object( $pdfib_license_manager ) && method_exists( $pdfib_license_manager, 'is_premium' ) && $pdfib_license_manager->is_premium(); if ( $is_premium ) { $template_limit = 999; // Limite pratiquement illimitée pour premium } } $can_create_template = $is_premium || $templates_count < $template_limit; $limit_reached = ! $can_create_template && $is_creating; $localize_data = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'pdfib_ajax' ), 'version' => PDFIB_VERSION, 'templateId' => $template_id, 'isEdit' => $template_id > 0, 'timestamp' => time(), 'debug' => WP_DEBUG, 'isPremium' => $is_premium, 'templatesCount' => $templates_count, 'templateLimit' => $template_limit, 'canCreateTemplate' => $can_create_template, 'limitReached' => $limit_reached, 'isCreating' => $is_creating, 'strings' => array( 'loading' => __( 'Chargement...', 'advanced-pdf-invoice-builder' ), 'error' => __( 'Erreur', 'advanced-pdf-invoice-builder' ), 'success' => __( 'Succès', 'advanced-pdf-invoice-builder' ), 'limitReachedWarning' => sprintf( __( 'Attention : Vous avez atteint la limite de %d template gratuit. Vous pouvez modifier ce template ou mettre à niveau vers Premium pour une limite illimitée.', 'advanced-pdf-invoice-builder' ), $template_limit ), 'currentTemplateCount' => sprintf( __( 'Vous avez actuellement %d template.', 'advanced-pdf-invoice-builder' ), $templates_count ), 'upgradePrompt' => __( 'Passer à Premium pour une limite illimitée.', 'advanced-pdf-invoice-builder' ), ), ); \wp_localize_script( 'pdf-builder-react-bundle', 'pdfBuilderAjax', $localize_data ); } ); }