pluginbase = $pluginbase; // Meta boxes for posts add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_metabox_assets' ) ); // Editor buttons - NO MODAL ANYMORE, only on dedicated shortcode generator page add_action( 'media_buttons', array( $this, 'add_media_button' ) ); // Removed: add_action( 'admin_footer', array( $this, 'render_popup' ) ); // TinyMCE button add_action( 'admin_head', array( $this, 'add_tinymce_button' ) ); // Gutenberg block support add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_gutenberg_assets' ) ); add_action( 'init', array( $this, 'register_gutenberg_blocks' ), 20 ); // Higher priority to ensure registration add_filter( 'block_categories_all', array( $this, 'register_block_category' ), 10, 2 ); // AJAX handlers for Gutenberg blocks add_action( 'wp_ajax_atkp_block_search_products', array( $this, 'ajax_search_products' ) ); add_action( 'wp_ajax_atkp_block_search_external', array( $this, 'ajax_search_external_products' ) ); // Note: atkp_import_product and atkp_create_list are handled by atkp_endpoints.php add_action( 'wp_ajax_atkp_search_posts', array( $this, 'ajax_search_posts' ) ); } /** * Add meta boxes to posts and pages */ public function add_meta_boxes() { $post_types = array( 'post', 'page' ); $custom_types = get_option( ATKP_PLUGIN_PREFIX . '_custom_posttypes', array() ); if ( is_array( $custom_types ) ) { $post_types = array_merge( $post_types, $custom_types ); } $post_types = apply_filters( 'atkp_mainproduct_posttypes', $post_types ); foreach ( $post_types as $type ) { add_meta_box( ATKP_PLUGIN_PREFIX . '_product_box', esc_html__( 'affiliate-toolkit', 'affiliate-toolkit-starter' ), array( $this, 'render_meta_box' ), $type, 'normal', 'default' ); } } /** * Render meta box content */ public function render_meta_box( $post ) { wp_nonce_field( plugin_basename( __FILE__ ), 'atkp_meta_box_nonce' ); $product_id = ATKPTools::get_post_setting( $post->ID, ATKP_PLUGIN_PREFIX . '_product' ); $list_id = ATKPTools::get_post_setting( $post->ID, ATKP_PLUGIN_PREFIX . '_list' ); ?>
get_disableselect2_backend() ) { return; } // Enqueue Select2 - use registered scripts wp_enqueue_style( 'atkp-select2-styles' ); wp_enqueue_script( 'atkp-select2-scripts' ); // Enqueue custom metabox script wp_enqueue_script( 'atkp-metabox-select2', plugins_url( 'js/metabox-select2.js', ATKP_PLUGIN_FILE ), array( 'jquery', 'atkp-select2-scripts' ), ATKP_UPDATE_VERSION, true ); // Localize script with data wp_localize_script( 'atkp-metabox-select2', 'atkpMetabox', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'atkp-search-nonce' ), 'searchPlaceholder' => __( 'Type to search...', 'affiliate-toolkit-starter' ) ) ); // Add custom CSS for Select2 in metaboxes wp_add_inline_style( 'atkp-select2-styles', " .atkp-modern-metabox .select2-container { width: 100% !important; display: block; } .atkp-modern-metabox .select2-container .select2-selection--single { height: auto; min-height: 32px; padding: 4px 8px; border: 1px solid #8c8f94; border-radius: 4px; background: #fff; } .atkp-modern-metabox .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 24px; padding-left: 0; padding-right: 20px; } .atkp-modern-metabox .select2-container--default .select2-selection--single .select2-selection__arrow { height: 30px; right: 4px; } .atkp-modern-metabox .select2-container--default .select2-selection--single .select2-selection__placeholder { color: #646970; } .atkp-modern-metabox .select2-container--default.select2-container--focus .select2-selection--single { border-color: #2271b1; box-shadow: 0 0 0 1px #2271b1; } /* Hide duplicate search containers */ .atkp-modern-metabox .select2-container + .select2-container { display: none !important; } .select2-container--default .select2-results__option--highlighted[aria-selected] { background-color: #2271b1; } .select2-dropdown { border: 1px solid #8c8f94; border-radius: 4px; } .select2-search--dropdown { padding: 8px; } .select2-search--dropdown .select2-search__field { border: 1px solid #8c8f94; border-radius: 4px; padding: 6px 8px; width: 100%; } .select2-search--dropdown .select2-search__field:focus { border-color: #2271b1; outline: none; box-shadow: 0 0 0 1px #2271b1; } " ); } /** * Save meta box data */ public function save_meta_boxes( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } $nonce = ATKPTools::get_post_parameter( 'atkp_meta_box_nonce', 'string' ); if ( ! wp_verify_nonce( $nonce, plugin_basename( __FILE__ ) ) ) { return; } $post_types = array( 'post', 'page' ); $custom_types = get_option( ATKP_PLUGIN_PREFIX . '_custom_posttypes', array() ); if ( is_array( $custom_types ) ) { $post_types = array_merge( $post_types, $custom_types ); } $post_types = apply_filters( 'atkp_mainproduct_posttypes', $post_types ); // Save product $this->save_main_reference( $post_id, '_product', ATKP_PRODUCT_POSTTYPE, $post_types ); // Save list $this->save_main_reference( $post_id, '_list', ATKP_LIST_POSTTYPE, $post_types ); } /** * Save main product/list reference */ private function save_main_reference( $post_id, $field, $posttype, $posttypes ) { $new_id = ATKPTools::get_post_parameter( ATKP_PLUGIN_PREFIX . $field, 'int' ); $old_id = ATKPTools::get_post_setting( $post_id, ATKP_PLUGIN_PREFIX . $field ); $item = get_post( $new_id ); if ( ! $item ) { ATKPTools::set_post_setting( $post_id, ATKP_PLUGIN_PREFIX . $field, null ); } else { ATKPTools::set_post_setting( $post_id, ATKP_PLUGIN_PREFIX . $field, $new_id ); } // Update references if ( $old_id != $new_id ) { $changed_ids = array(); if ( $old_id ) { $changed_ids[] = $old_id; } if ( $new_id ) { $changed_ids[] = $new_id; } foreach ( $changed_ids as $item_id ) { $this->update_post_references( $item_id, $field, $posttype, $posttypes ); } } } /** * Update post references for a product/list */ private function update_post_references( $item_id, $field, $posttype, $posttypes ) { $post_ids = array(); $query = new WP_Query( array( 'post_type' => $posttypes, 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => -1, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to find posts referencing this product/list. 'meta_query' => array( array( 'key' => ATKP_PLUGIN_PREFIX . $field, 'value' => $item_id, 'compare' => '=', ), ), ) ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $post_ids[] = get_the_ID(); } wp_reset_postdata(); } ATKPTools::set_post_setting( $item_id, $posttype . '_postid', $post_ids ); } /** * Add TinyMCE button */ public function add_tinymce_button() { global $typenow; $page = ATKPTools::get_get_parameter( 'page', 'string' ); $allowed_pages = array( 'ATKP_affiliate_toolkit-plugin' ); $post_types = array( 'post', 'page' ); $custom_types = get_option( ATKP_PLUGIN_PREFIX . '_custom_posttypes', array() ); if ( is_array( $custom_types ) ) { $post_types = array_merge( $post_types, $custom_types ); } $post_types[] = ATKP_PRODUCT_POSTTYPE; if ( ! in_array( $typenow, $post_types ) && ! in_array( $page, $allowed_pages ) ) { return; } add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugin' ) ); add_filter( 'mce_buttons', array( $this, 'register_tinymce_button' ) ); } public function add_tinymce_plugin( $plugin_array ) { $plugin_array['atkp_button'] = plugins_url( '/js/editor-button-modern.js', ATKP_PLUGIN_FILE ); return $plugin_array; } public function register_tinymce_button( $buttons ) { array_push( $buttons, 'separator', 'atkp_button' ); return $buttons; } /** * Add media button to post editor * Button opens the dedicated shortcode generator page in a Thickbox modal */ public function add_media_button( $args = array() ) { global $typenow; // Check if we should show the button on post/page edit screens if ( ! current_user_can( 'edit_posts' ) ) { return; } $post_types = array( 'post', 'page' ); $custom_types = get_option( ATKP_PLUGIN_PREFIX . '_custom_posttypes', array() ); if ( is_array( $custom_types ) ) { $post_types = array_merge( $post_types, $custom_types ); } $post_types = apply_filters( 'atkp_mainproduct_posttypes', $post_types ); $is_editor_screen = in_array( $typenow, $post_types ); if ( ! $is_editor_screen ) { return; } // Enqueue Thickbox add_thickbox(); // Add the button that opens in Thickbox modal // Note: atkp_iframe parameter BEFORE TB_iframe (Thickbox cuts off params after TB_iframe) $generator_url = admin_url( 'admin.php?page=ATKP_affiliate_toolkit-shortcodegenerator&atkp_iframe=1&width=1400&height=700&TB_iframe=true' ); $icon_url = plugins_url( '/images/affiliate_toolkit_menu.png', ATKP_PLUGIN_FILE ); $button_text = __( 'AT Shortcode', 'affiliate-toolkit-starter' ); echo ''; echo ''; echo esc_html( $button_text ); echo ''; } /** * Render popup modal * REMOVED: Modal is now only shown on dedicated shortcode generator page * This function is kept for backward compatibility but does nothing */ public function render_popup() { // Intentionally empty - modal removed from post/page edit screens // Modal is now only available on the dedicated shortcode generator page } /** * Register block category for Gutenberg */ public function register_block_category( $categories, $editor_context ) { return array_merge( $categories, array( array( 'slug' => 'affiliate-toolkit', 'title' => __( 'affiliate-toolkit', 'affiliate-toolkit-starter' ), 'icon' => null, ), ) ); } /** * Register Gutenberg blocks */ public function register_gutenberg_blocks() { if ( ! function_exists( 'register_block_type' ) ) { ATKPLog::LogError( 'ATKP: register_block_type function not available!' ); return; } // Register block scripts (they will be enqueued automatically by WordPress) // Force cache bust with new version $version = ATKP_UPDATE_VERSION . '.blocks.v2'; wp_register_script( 'atkp-block-product', plugins_url( 'js/blocks/product-block.js', ATKP_PLUGIN_FILE ), array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'jquery' ), $version, false ); wp_register_script( 'atkp-block-list', plugins_url( 'js/blocks/list-block.js', ATKP_PLUGIN_FILE ), array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'jquery' ), $version, false ); // Prepare localized data for blocks $templates = atkp_template::get_list( true, false ); $template_options = array(); $template_options[] = array( 'label' => __( 'Default', 'affiliate-toolkit-starter' ), 'value' => '' ); foreach ( $templates as $template_id => $template_name ) { $template_options[] = array( 'label' => $template_name, 'value' => (string) $template_id ); } $shops = atkp_shop::get_list(); $shop_options = array(); if ( $shops ) { foreach ( $shops as $shop ) { $shop_options[] = array( 'label' => $shop->title, 'value' => (string) $shop->id, ); // Add children shops with indentation if ( isset( $shop->children ) && is_array( $shop->children ) && count( $shop->children ) > 0 ) { foreach ( $shop->children as $child ) { $shop_options[] = array( 'label' => ' ↳ ' . $child->title, 'value' => (string) $child->id, ); } } } } $localize_data = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'atkp-import-nonce' ), // For atkp_endpoints.php functions 'restUrl' => rest_url(), 'restNonce' => wp_create_nonce( 'wp_rest' ), 'templates' => $template_options, 'shops' => $shop_options, 'pluginUrl' => plugins_url( '', ATKP_PLUGIN_FILE ), // Translations - all strings used in JavaScript 'i18n' => array( // Block Titles 'affiliateToolkitProduct' => __( 'affiliate-toolkit Product', 'affiliate-toolkit-starter' ), 'affiliateToolkitProductList' => __( 'affiliate-toolkit Product List', 'affiliate-toolkit-starter' ), // Product Block 'productSelection' => __( 'Product Selection', 'affiliate-toolkit-starter' ), 'selectedProduct' => __( 'Selected Product:', 'affiliate-toolkit-starter' ), 'changeProduct' => __( 'Change Product', 'affiliate-toolkit-starter' ), 'select' => __( 'Select', 'affiliate-toolkit-starter' ), 'import' => __( 'Import', 'affiliate-toolkit-starter' ), 'searchExistingProducts' => __( 'Search existing products:', 'affiliate-toolkit-starter' ), 'enterProductTitleOrId' => __( 'Enter product title or ID...', 'affiliate-toolkit-starter' ), 'search' => __( 'Search', 'affiliate-toolkit-starter' ), 'showing5NewestProducts' => __( 'Showing 5 newest products', 'affiliate-toolkit-starter' ), 'importProductsFromShop' => __( 'Import products from shop:', 'affiliate-toolkit-starter' ), 'selectShop' => __( 'Select Shop', 'affiliate-toolkit-starter' ), 'selectShopPlaceholder' => __( '-- Select Shop --', 'affiliate-toolkit-starter' ), 'searchKeyword' => __( 'Search Keyword', 'affiliate-toolkit-starter' ), 'exampleIphone' => __( 'e.g., "iPhone 15"', 'affiliate-toolkit-starter' ), 'keywordToSearch' => __( 'Keyword to search for products', 'affiliate-toolkit-starter' ), 'loadingPreview' => __( 'Loading Preview...', 'affiliate-toolkit-starter' ), 'previewResults' => __( 'Preview Results', 'affiliate-toolkit-starter' ), 'importAndSelect' => __( 'Import & Select', 'affiliate-toolkit-starter' ), 'noProductsFound' => __( 'No products found. Try a different search term.', 'affiliate-toolkit-starter' ), 'orEnterProductId' => __( 'Or enter Product ID directly below:', 'affiliate-toolkit-starter' ), 'productIdManual' => __( 'Product ID (Manual)', 'affiliate-toolkit-starter' ), 'enterProductIdIfKnown' => __( 'Enter product ID if you know it', 'affiliate-toolkit-starter' ), 'displaySettings' => __( 'Display Settings', 'affiliate-toolkit-starter' ), 'template' => __( 'Template', 'affiliate-toolkit-starter' ), 'buttonType' => __( 'Button Type', 'affiliate-toolkit-starter' ), 'default' => __( 'Default', 'affiliate-toolkit-starter' ), 'addToCart' => __( 'Add to Cart', 'affiliate-toolkit-starter' ), 'link' => __( 'Link', 'affiliate-toolkit-starter' ), 'productPage' => __( 'Product Page', 'affiliate-toolkit-starter' ), 'hideDisclaimer' => __( 'Hide Disclaimer', 'affiliate-toolkit-starter' ), 'hideDisclaimerText' => __( 'Hide the affiliate disclaimer text', 'affiliate-toolkit-starter' ), 'advancedSettings' => __( 'Advanced Settings', 'affiliate-toolkit-starter' ), 'containerCssClass' => __( 'Container CSS Class', 'affiliate-toolkit-starter' ), 'customCssContainer' => __( 'Custom CSS classes for the container', 'affiliate-toolkit-starter' ), 'elementCssClass' => __( 'Element CSS Class', 'affiliate-toolkit-starter' ), 'customCssElements' => __( 'Custom CSS classes for elements', 'affiliate-toolkit-starter' ), 'overrideAffiliateId' => __( 'Override Affiliate ID', 'affiliate-toolkit-starter' ), 'amazonEbayTrackingId' => __( 'Amazon or eBay tracking ID', 'affiliate-toolkit-starter' ), 'productId' => __( 'Product ID:', 'affiliate-toolkit-starter' ), 'templateLabel' => __( 'Template:', 'affiliate-toolkit-starter' ), 'pleaseSelectProduct' => __( 'Please select a product using the sidebar →', 'affiliate-toolkit-starter' ), 'pleaseSelectShopFirst' => __( 'Please select a shop first', 'affiliate-toolkit-starter' ), 'productAlreadyExists' => __( 'Product already exists and has been selected', 'affiliate-toolkit-starter' ), 'productImportedSuccessfully' => __( 'Product imported successfully!', 'affiliate-toolkit-starter' ), 'failedToImportProduct' => __( 'Failed to import product: ', 'affiliate-toolkit-starter' ), 'failedToImportInvalidResponse' => __( 'Failed to import product: Invalid response', 'affiliate-toolkit-starter' ), 'failedToImportInvalidFormat' => __( 'Failed to import product: Invalid response format', 'affiliate-toolkit-starter' ), 'errorImportingProduct' => __( 'Error importing product', 'affiliate-toolkit-starter' ), 'searchFailed' => __( 'Search failed: ', 'affiliate-toolkit-starter' ), 'searchFailedGeneric' => __( 'Search failed', 'affiliate-toolkit-starter' ), 'serverError500' => __( 'Server error (500). Please check error log.', 'affiliate-toolkit-starter' ), 'enterProductNameAsinEan' => __( 'Enter product name, ASIN, or EAN...', 'affiliate-toolkit-starter' ), 'searching' => __( 'Searching...', 'affiliate-toolkit-starter' ), 'importing' => __( 'Importing...', 'affiliate-toolkit-starter' ), 'importProductFromShop' => __( 'Import product from shop:', 'affiliate-toolkit-starter' ), 'alignment' => __( 'Alignment', 'affiliate-toolkit-starter' ), 'noAlignment' => __( 'No alignment', 'affiliate-toolkit-starter' ), 'alignLeft' => __( 'Left', 'affiliate-toolkit-starter' ), 'alignCenter' => __( 'Center', 'affiliate-toolkit-starter' ), 'alignRight' => __( 'Right', 'affiliate-toolkit-starter' ), 'customContent' => __( 'Custom Content', 'affiliate-toolkit-starter' ), 'customContentHelp' => __( 'Optional custom content or link text', 'affiliate-toolkit-starter' ), 'outputRenderedOnFrontend' => __( 'Output will be rendered on frontend', 'affiliate-toolkit-starter' ), // List Block 'listSelection' => __( 'List Selection', 'affiliate-toolkit-starter' ), 'selectedList' => __( 'Selected List:', 'affiliate-toolkit-starter' ), 'changeList' => __( 'Change List', 'affiliate-toolkit-starter' ), 'create' => __( 'Create', 'affiliate-toolkit-starter' ), 'searchExistingLists' => __( 'Search existing lists:', 'affiliate-toolkit-starter' ), 'enterListNameOrId' => __( 'Enter list name or ID...', 'affiliate-toolkit-starter' ), 'showing5NewestLists' => __( 'Showing 5 newest lists', 'affiliate-toolkit-starter' ), 'createNewProductList' => __( 'Create new product list:', 'affiliate-toolkit-starter' ), 'listName' => __( 'List Name', 'affiliate-toolkit-starter' ), 'enterListName' => __( 'Enter list name...', 'affiliate-toolkit-starter' ), 'giveListDescriptiveName' => __( 'Give your list a descriptive name', 'affiliate-toolkit-starter' ), 'listType' => __( 'List Type', 'affiliate-toolkit-starter' ), 'topSeller' => __( 'Top Seller', 'affiliate-toolkit-starter' ), 'newReleases' => __( 'New Releases', 'affiliate-toolkit-starter' ), 'searchResults' => __( 'Search Results', 'affiliate-toolkit-starter' ), 'productsMatchingKeyword' => __( 'Products matching search keyword', 'affiliate-toolkit-starter' ), 'categoryBasedList' => __( 'Category-based list (requires node/category ID)', 'affiliate-toolkit-starter' ), 'categoryNodeId' => __( 'Category/Node ID', 'affiliate-toolkit-starter' ), 'example123456' => __( 'e.g., "123456"', 'affiliate-toolkit-starter' ), 'browseNodeOrCategoryId' => __( 'Browse node or category ID from shop', 'affiliate-toolkit-starter' ), 'previewFirst5' => __( 'Preview (first 5 results):', 'affiliate-toolkit-starter' ), 'creating' => __( 'Creating...', 'affiliate-toolkit-starter' ), 'createList' => __( 'Create List', 'affiliate-toolkit-starter' ), 'listWillBeCreated' => __( '💡 The list will be created and automatically selected for this block.', 'affiliate-toolkit-starter' ), 'orEnterListId' => __( 'Or enter List ID directly below:', 'affiliate-toolkit-starter' ), 'listIdManual' => __( 'List ID (Manual)', 'affiliate-toolkit-starter' ), 'enterListIdIfKnown' => __( 'Enter list ID if you know it', 'affiliate-toolkit-starter' ), 'limit' => __( 'Limit', 'affiliate-toolkit-starter' ), 'numberOfProducts' => __( 'Number of products to display (0 = all)', 'affiliate-toolkit-starter' ), 'randomSort' => __( 'Random Sort', 'affiliate-toolkit-starter' ), 'randomizeProductOrder' => __( 'Randomize product order on each page load', 'affiliate-toolkit-starter' ), 'listId' => __( 'List ID:', 'affiliate-toolkit-starter' ), 'limitLabel' => __( 'Limit:', 'affiliate-toolkit-starter' ), 'products' => __( 'products', 'affiliate-toolkit-starter' ), 'randomSortEnabled' => __( 'Random sort enabled', 'affiliate-toolkit-starter' ), 'pleaseSelectList' => __( 'Please select a list using the sidebar →', 'affiliate-toolkit-starter' ), 'pleaseEnterListName' => __( 'Please enter a list name', 'affiliate-toolkit-starter' ), 'pleaseSelectShop' => __( 'Please select a shop', 'affiliate-toolkit-starter' ), 'pleaseEnterSearchKeyword' => __( 'Please enter a search keyword', 'affiliate-toolkit-starter' ), 'pleaseEnterCategoryNodeId' => __( 'Please enter a category/node ID', 'affiliate-toolkit-starter' ), 'listCreatedSuccessfully' => __( 'List created successfully!', 'affiliate-toolkit-starter' ), 'failedToCreateList' => __( 'Failed to create list: ', 'affiliate-toolkit-starter' ), 'failedToCreateListInvalidResponse' => __( 'Failed to create list: Invalid response', 'affiliate-toolkit-starter' ), 'failedToCreateListInvalidFormat' => __( 'Failed to create list: Invalid response format', 'affiliate-toolkit-starter' ), 'errorCreatingList' => __( 'Error creating list', 'affiliate-toolkit-starter' ), 'exampleLaptopGaming' => __( 'e.g., "laptop gaming"', 'affiliate-toolkit-starter' ), ) ); // Localize both block scripts wp_localize_script( 'atkp-block-product', 'atkpBlocks', $localize_data ); wp_localize_script( 'atkp-block-list', 'atkpBlocks', $localize_data ); // Translations are provided via wp_localize_script above. // wp_set_script_translations is not used because there are no Jed-format // JSON translation files; the call would generate a broken inline script. // Register product block with static callback $product_block = register_block_type( 'atkp/product', array( 'api_version' => 2, 'editor_script' => 'atkp-block-product', 'editor_style' => 'atkp-block-editor', 'render_callback' => array( __CLASS__, 'static_render_product_block' ), 'supports' => array( 'html' => false, 'multiple' => true, 'reusable' => true, 'customClassName' => false, 'className' => false, 'anchor' => false, ), 'attributes' => array( 'productId' => array( 'type' => 'string', 'default' => '' ), 'productTitle' => array( 'type' => 'string', 'default' => '' ), 'template' => array( 'type' => 'string', 'default' => '' ), 'buttonType' => array( 'type' => 'string', 'default' => '' ), 'align' => array( 'type' => 'string', 'default' => '' ), 'elementCss' => array( 'type' => 'string', 'default' => '' ), 'containerCss' => array( 'type' => 'string', 'default' => '' ), 'content' => array( 'type' => 'string', 'default' => '' ), 'field' => array( 'type' => 'string', 'default' => '' ), 'link' => array( 'type' => 'boolean', 'default' => false ), 'hideDisclaimer' => array( 'type' => 'boolean', 'default' => false ), 'trackingId' => array( 'type' => 'string', 'default' => '' ), ), ) ); if ( ! $product_block ) { ATKPLog::LogError( 'ATKP: ERROR - Product block registration failed!' ); } // Register list block with static callback $list_block = register_block_type( 'atkp/list', array( 'api_version' => 2, 'editor_script' => 'atkp-block-list', 'editor_style' => 'atkp-block-editor', 'render_callback' => array( __CLASS__, 'static_render_list_block' ), 'supports' => array( 'html' => false, 'multiple' => true, 'reusable' => true, 'customClassName' => false, 'className' => false, 'anchor' => false, ), 'attributes' => array( 'listId' => array( 'type' => 'string', 'default' => '' ), 'listTitle' => array( 'type' => 'string', 'default' => '' ), 'template' => array( 'type' => 'string', 'default' => '' ), 'limit' => array( 'type' => 'number', 'default' => 0 ), 'randomSort' => array( 'type' => 'boolean', 'default' => false ), 'buttonType' => array( 'type' => 'string', 'default' => '' ), 'elementCss' => array( 'type' => 'string', 'default' => '' ), 'containerCss' => array( 'type' => 'string', 'default' => '' ), 'hideDisclaimer' => array( 'type' => 'boolean', 'default' => false ), 'trackingId' => array( 'type' => 'string', 'default' => '' ), ), ) ); if ( ! $list_block ) { ATKPLog::LogError( 'ATKP: ERROR - List block registration failed!' ); } } /** * Enqueue Gutenberg assets * Note: Block scripts are registered in register_gutenberg_blocks() and automatically * enqueued by WordPress via the editor_script parameter in register_block_type() */ public function enqueue_gutenberg_assets() { // Only enqueue editor styles here // Scripts are handled automatically by WordPress from register_block_type() wp_enqueue_style( 'atkp-block-editor', plugins_url( 'css/blocks-editor.css', ATKP_PLUGIN_FILE ), array( 'wp-edit-blocks' ), ATKP_UPDATE_VERSION ); } /** * Render product block */ public function render_product_block( $attributes ) { // Don't render in editor context - let JavaScript handle it // This is CRUCIAL for block editability after save if ( is_admin() && function_exists( 'get_current_screen' ) ) { $screen = get_current_screen(); if ( $screen && $screen->is_block_editor() ) { return ''; } } // Check if we have a product ID if ( empty( $attributes['productId'] ) ) { return '