plugin = $plugin; add_action( 'add_meta_boxes', [ $this, 'register_meta_box' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); add_action( 'admin_footer', [ $this, 'render_modal_markup' ] ); } public function register_meta_box() { add_meta_box( 'groq-ai-generator-box', __( 'Gebruik AI', GROQ_AI_PRODUCT_TEXT_DOMAIN ), [ $this, 'render_meta_box' ], 'product', 'side', 'high' ); } public function render_meta_box() { if ( ! current_user_can( 'edit_products' ) ) { echo '

' . esc_html__( 'Je hebt geen toestemming om deze actie uit te voeren.', GROQ_AI_PRODUCT_TEXT_DOMAIN ) . '

'; return; } ?>

post_type && in_array( $screen->base, [ 'post', 'post-new' ], true ) ) { wp_enqueue_style( 'groq-ai-admin', plugins_url( 'assets/css/admin.css', GROQ_AI_PRODUCT_TEXT_FILE ), [], GROQ_AI_PRODUCT_TEXT_VERSION ); wp_enqueue_script( 'groq-ai-admin', plugins_url( 'assets/js/admin.js', GROQ_AI_PRODUCT_TEXT_FILE ), [ 'jquery' ], GROQ_AI_PRODUCT_TEXT_VERSION, true ); global $post; $post_id = ( $post && isset( $post->ID ) ) ? (int) $post->ID : 0; $settings = $this->plugin->get_settings(); $attribute_defaults = isset( $settings['product_attribute_includes'] ) && is_array( $settings['product_attribute_includes'] ) ? array_values( array_unique( array_map( 'sanitize_key', $settings['product_attribute_includes'] ) ) ) : []; wp_localize_script( 'groq-ai-admin', 'GroqAIGenerator', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'groq_ai_generate' ), 'defaultPrompt' => $settings['default_prompt'], 'postId' => $post_id, 'contextDefaults' => isset( $settings['context_fields'] ) ? $settings['context_fields'] : $this->plugin->get_default_context_fields(), 'attributeIncludesDefaults' => $attribute_defaults, ] ); } } public function render_modal_markup() { $screen = get_current_screen(); if ( ! $screen || 'product' !== $screen->post_type ) { return; } $settings = $this->plugin->get_settings(); $rankmath_enabled = $this->plugin->is_rankmath_active() && $this->plugin->is_module_enabled( 'rankmath', $settings ); $attribute_options = $this->get_product_attribute_include_options(); ?> __( 'Custom attributen (niet-taxonomie)', GROQ_AI_PRODUCT_TEXT_DOMAIN ), ]; if ( function_exists( 'wc_get_attribute_taxonomies' ) ) { $taxonomies = wc_get_attribute_taxonomies(); if ( is_array( $taxonomies ) ) { foreach ( $taxonomies as $attr ) { $name = isset( $attr->attribute_name ) ? sanitize_key( (string) $attr->attribute_name ) : ''; $label = isset( $attr->attribute_label ) ? sanitize_text_field( (string) $attr->attribute_label ) : ''; if ( '' === $name ) { continue; } $taxonomy = 'pa_' . $name; if ( '' === $label ) { $label = function_exists( 'wc_attribute_label' ) ? wc_attribute_label( $taxonomy ) : $taxonomy; } $options[ $taxonomy ] = $label; } } } if ( count( $options ) > 1 ) { $fixed = [ '__custom__' => $options['__custom__'], ]; unset( $options['__custom__'] ); asort( $options, SORT_NATURAL | SORT_FLAG_CASE ); $options = $fixed + $options; } return $options; } }