array( 'name' => 'Lasso Pro', 'slug' => 'lasso', 'icon' => 'dashicons-networking', 'color' => '#22c55e', 'description' => 'Import product cards, comparison data, prices, and links from Lasso Pro.', ), 'lasso_lite' => array( 'name' => 'Lasso Lite', 'slug' => 'lasso_lite', 'icon' => 'dashicons-admin-links', 'color' => '#16a34a', 'description' => 'Import affiliate displays, target URLs, and badges from Lasso Lite (Simple URLs).', ), 'pretty_links' => array( 'name' => 'Pretty Links', 'slug' => 'pretty_links', 'icon' => 'dashicons-admin-links', 'color' => '#3b82f6', 'description' => 'Import cloaked affiliate links and target URLs from Pretty Links.', ), 'thirstyaffiliates' => array( 'name' => 'ThirstyAffiliates', 'slug' => 'thirstyaffiliates', 'icon' => 'dashicons-coffee', 'color' => '#10b981', 'description' => 'Import affiliate links, redirection settings, and media from ThirstyAffiliates.', ), 'easy_affiliate_links' => array( 'name' => 'Easy Affiliate Links', 'slug' => 'easy_affiliate_links', 'icon' => 'dashicons-share', 'color' => '#06b6d4', 'description' => 'Import affiliate text links, buttons, and attributes from Easy Affiliate Links.', ), 'aawp' => array( 'name' => 'AAWP', 'slug' => 'aawp', 'icon' => 'dashicons-cart', 'color' => '#f59e0b', 'description' => 'Import Amazon product boxes, ASINs, pricing, and pros/cons from AAWP.', ), 'easyazon' => array( 'name' => 'EasyAzon', 'slug' => 'easyazon', 'icon' => 'dashicons-tag', 'color' => '#ea580c', 'description' => 'Import Amazon product links, ASINs, and popups from EasyAzon.', ), 'amalinkspro' => array( 'name' => 'AmaLinks Pro', 'slug' => 'amalinkspro', 'icon' => 'dashicons-superhero', 'color' => '#8b5cf6', 'description' => 'Import showcase boxes, CTA buttons, and product data from AmaLinks Pro.', ), 'earnist' => array( 'name' => 'Earnist', 'slug' => 'earnist', 'icon' => 'dashicons-chart-line', 'color' => '#6366f1', 'description' => 'Import affiliate product cards, ratings, and badges from Earnist.', ), ); /** * Detect installed plugins and existing database records across all providers. * * @return array Providers list with detection status and item count. */ public static function detect_sources() { global $wpdb; $results = array(); if ( ! function_exists( 'is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } foreach ( self::PROVIDERS as $key => $provider ) { $count = 0; $detected = false; switch ( $key ) { case 'lasso': // 1. Check custom table wp_lasso_urls. $lasso_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'lasso_urls' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $lasso_table ) ); if ( $table_exists === $lasso_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $lasso_table ) ); } // 2. Also check CPT lasso-urls. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $cpt_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('lasso-urls', 'lasso_url') AND post_status NOT IN ('trash', 'auto-draft')" ); $count = max( $count, $cpt_count ); $detected = ( $count > 0 || is_plugin_active( 'lasso/lasso.php' ) || is_plugin_active( 'lasso-pro/lasso-pro.php' ) ); break; case 'lasso_lite': // 1. Check custom table wp_lasso_lite_url_details. $lasso_lite_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'lasso_lite_url_details' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $lasso_lite_table ) ); if ( $table_exists === $lasso_lite_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $lasso_lite_table ) ); } // 2. Also check CPTs: surl (Lasso Lite / Simple URLs), affiliate_url, simple_url, lasso-lite, lasso_lite. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $cpt_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('surl', 'affiliate_url', 'simple_url', 'lasso-lite', 'lasso_lite') AND post_status NOT IN ('trash', 'auto-draft')" ); $count = max( $count, $cpt_count ); $detected = ( $count > 0 || is_plugin_active( 'lasso-lite/lasso-lite.php' ) || is_plugin_active( 'simple-urls/simple-urls.php' ) ); break; case 'pretty_links': // 1. Check table wp_prli_links. $prli_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'prli_links' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $prli_table ) ); if ( $table_exists === $prli_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $prli_table ) ); } // 2. Also check CPT pretty-link. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $cpt_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'pretty-link' AND post_status NOT IN ('trash', 'auto-draft')" ); $count = max( $count, $cpt_count ); $detected = ( $count > 0 || is_plugin_active( 'pretty-link/pretty-link.php' ) ); break; case 'thirstyaffiliates': // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('thirstylink', 'thirstylink_item') AND post_status NOT IN ('trash', 'auto-draft')" ); $detected = ( $count > 0 || is_plugin_active( 'thirstyaffiliates/thirstyaffiliates.php' ) ); break; case 'easy_affiliate_links': // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('easy_affiliate_link', 'eafl_link') AND post_status NOT IN ('trash', 'auto-draft')" ); $detected = ( $count > 0 || is_plugin_active( 'easy-affiliate-links/easy-affiliate-links.php' ) ); break; case 'aawp': // 1. Check table wp_aawp_products. $aawp_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'aawp_products' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $aawp_table ) ); if ( $table_exists === $aawp_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $aawp_table ) ); } // 2. Also check CPT aawp or aawp_list. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $cpt_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('aawp', 'aawp_list') AND post_status NOT IN ('trash', 'auto-draft')" ); $count = max( $count, $cpt_count ); $detected = ( $count > 0 || is_plugin_active( 'aawp/aawp.php' ) ); break; case 'easyazon': // Check postmeta with _easyazon_asin or CPT easyazon. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT post_id) FROM {$wpdb->postmeta} WHERE meta_key LIKE %s", '%easyazon_asin%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $cpt_count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('easyazon', 'easyazon_item') AND post_status NOT IN ('trash', 'auto-draft')" ); $count = max( $count, $cpt_count ); $detected = ( $count > 0 || is_plugin_active( 'easyazon/easyazon.php' ) || is_plugin_active( 'easyazon-pro/easyazon-pro.php' ) ); break; case 'amalinkspro': // Check CPT amalinkspro, amalinkspro_cta, or amalinkspro_table. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('amalinkspro', 'amalinkspro_cta', 'amalinkspro_table') AND post_status NOT IN ('trash', 'auto-draft')" ); $detected = ( $count > 0 || is_plugin_active( 'amalinkspro/amalinkspro.php' ) ); break; case 'earnist': // Check CPT earnist, earnist_product, or earnist_link. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ('earnist', 'earnist_product', 'earnist_link') AND post_status NOT IN ('trash', 'auto-draft')" ); $detected = ( $count > 0 || is_plugin_active( 'earnist/earnist.php' ) ); break; } $results[ $key ] = array_merge( $provider, array( 'detected' => $detected, 'count' => $count, ) ); } return $results; } /** * Retrieve a page of source items ready for preview or import. * * @param string $source Provider identifier. * @param int $limit Maximum records to fetch. * @param int $offset Query offset. * @return array Standardized array of items. */ public static function get_source_items( $source, $limit = 50, $offset = 0 ) { $limit = max( 1, min( 200, (int) $limit ) ); $offset = max( 0, (int) $offset ); switch ( $source ) { case 'lasso': return self::fetch_lasso_items( $limit, $offset ); case 'lasso_lite': return self::fetch_lasso_lite_items( $limit, $offset ); case 'pretty_links': return self::fetch_pretty_links_items( $limit, $offset ); case 'thirstyaffiliates': return self::fetch_thirstyaffiliates_items( $limit, $offset ); case 'easy_affiliate_links': return self::fetch_easy_affiliate_links_items( $limit, $offset ); case 'aawp': return self::fetch_aawp_items( $limit, $offset ); case 'easyazon': return self::fetch_easyazon_items( $limit, $offset ); case 'amalinkspro': return self::fetch_amalinkspro_items( $limit, $offset ); case 'earnist': return self::fetch_earnist_items( $limit, $offset ); default: return array(); } } /** * Fetch items from Lasso. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_lasso_items( $limit, $offset ) { global $wpdb; $items = array(); $lasso_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'lasso_urls' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $lasso_table ) ); if ( $table_exists === $lasso_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i ORDER BY id DESC LIMIT %d OFFSET %d', $lasso_table, $limit, $offset ), ARRAY_A ); if ( ! empty( $rows ) ) { foreach ( $rows as $row ) { $items[] = array( 'id' => 'lasso_tbl_' . $row['id'], 'title' => ! empty( $row['title'] ) ? $row['title'] : __( 'Lasso Product', 'affistyle' ), 'url' => ! empty( $row['target_url'] ) ? $row['target_url'] : ( ! empty( $row['primary_link'] ) ? $row['primary_link'] : '' ), 'image' => ! empty( $row['image_src'] ) ? $row['image_src'] : '', 'price' => ! empty( $row['price'] ) ? $row['price'] : '', 'rating' => ! empty( $row['rating'] ) ? (float) $row['rating'] : 0, 'badge' => ! empty( $row['badge_text'] ) ? $row['badge_text'] : '', 'button_text' => ! empty( $row['buy_btn_text'] ) ? $row['buy_btn_text'] : __( 'Buy Now', 'affistyle' ), 'description' => ! empty( $row['description'] ) ? $row['description'] : '', 'asin' => ! empty( $row['amazon_asin'] ) ? $row['amazon_asin'] : '', 'source' => 'Lasso', ); } return $items; } } // Fallback to CPT lasso-urls. $posts = get_posts( array( 'post_type' => array( 'lasso-urls', 'lasso_url', 'lasso-pro', 'lasso_urls' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { $badge = get_post_meta( $p->ID, '_lasso_url_badge', true ); if ( empty( $badge ) ) { $badge = get_post_meta( $p->ID, 'lasso_badge', true ); } if ( empty( $badge ) ) { $cats = wp_get_post_terms( $p->ID, array( 'lasso-cat', 'lasso-category', 'category' ), array( 'fields' => 'names' ) ); if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { $badge = $cats[0]; } } $asin = get_post_meta( $p->ID, '_lasso_url_amazon_asin', true ); if ( empty( $asin ) ) { $asin = get_post_meta( $p->ID, 'amazon_asin', true ); } $target_url = get_post_meta( $p->ID, '_lasso_url_target_url', true ); if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, 'target_url', true ); } if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, 'primary_url', true ); } if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, 'affiliate_link', true ); } if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, '_url', true ); } if ( empty( $asin ) && ! empty( $target_url ) && class_exists( 'AffiStyle_Scraper' ) ) { $asin = AffiStyle_Scraper::extract_asin( $target_url ); } $image_url = get_post_meta( $p->ID, '_lasso_url_image_url', true ); if ( empty( $image_url ) ) { $image_url = get_post_meta( $p->ID, 'lasso_custom_thumbnail', true ); } if ( empty( $image_url ) ) { $image_url = get_post_meta( $p->ID, '_lasso_custom_thumbnail', true ); } if ( empty( $image_url ) && has_post_thumbnail( $p->ID ) ) { $image_url = (string) get_the_post_thumbnail_url( $p->ID, 'full' ); } $price = get_post_meta( $p->ID, '_lasso_url_price', true ); if ( empty( $price ) ) { $price = get_post_meta( $p->ID, 'lasso_price', true ); } $rating = (float) get_post_meta( $p->ID, '_lasso_url_rating', true ); if ( empty( $rating ) ) { $rating = (float) get_post_meta( $p->ID, 'lasso_rating', true ); } $desc = get_post_meta( $p->ID, '_lasso_url_description', true ); if ( empty( $desc ) ) { $desc = get_post_meta( $p->ID, 'lasso_description', true ); } if ( empty( $desc ) ) { $desc = ! empty( $p->post_excerpt ) ? $p->post_excerpt : $p->post_content; } $btn_text = get_post_meta( $p->ID, 'lasso_button_text', true ); if ( empty( $btn_text ) ) { $btn_text = ! empty( $asin ) ? __( 'Buy on Amazon', 'affistyle' ) : __( 'Buy Now', 'affistyle' ); } $items[] = array( 'id' => 'lasso_cpt_' . $p->ID, 'title' => $p->post_title, 'url' => $target_url, 'image' => $image_url ? $image_url : '', 'price' => $price ? $price : '', 'rating' => $rating, 'badge' => $badge ? $badge : '', 'button_text' => $btn_text, 'description' => $desc, 'asin' => $asin ? $asin : '', 'source' => 'Lasso', ); } return $items; } /** * Fetch items from Lasso Lite (wp_lasso_lite_url_details table and CPT simple_url). * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_lasso_lite_items( $limit, $offset ) { global $wpdb; $items = array(); $lasso_lite_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'lasso_lite_url_details' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $lasso_lite_table ) ); if ( $table_exists === $lasso_lite_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i ORDER BY 1 DESC LIMIT %d OFFSET %d', $lasso_lite_table, $limit, $offset ), ARRAY_A ); if ( ! empty( $rows ) ) { foreach ( $rows as $row ) { $lasso_id = ! empty( $row['lasso_id'] ) ? (int) $row['lasso_id'] : ( ! empty( $row['id'] ) ? (int) $row['id'] : 0 ); $row_id = $lasso_id > 0 ? $lasso_id : wp_generate_uuid4(); // URL mapping: redirect_url (primary in lasso_lite_url_details), target_url, primary_link. $url = ! empty( $row['redirect_url'] ) ? $row['redirect_url'] : ( ! empty( $row['target_url'] ) ? $row['target_url'] : ( ! empty( $row['primary_link'] ) ? $row['primary_link'] : ( ! empty( $row['url'] ) ? $row['url'] : '' ) ) ); // ASIN mapping: product_id (primary in lasso_lite_url_details), amazon_asin, or asin. $asin = ! empty( $row['product_id'] ) ? $row['product_id'] : ( ! empty( $row['amazon_asin'] ) ? $row['amazon_asin'] : ( ! empty( $row['asin'] ) ? $row['asin'] : '' ) ); // Check linked post in wp_posts where ID = lasso_id. $linked_post = $lasso_id > 0 ? get_post( $lasso_id ) : null; // Title. $title = ! empty( $row['title'] ) ? $row['title'] : ( ! empty( $row['name'] ) ? $row['name'] : '' ); if ( empty( $title ) && $linked_post && ! empty( $linked_post->post_title ) ) { $title = $linked_post->post_title; } if ( empty( $title ) ) { $title = __( 'Lasso Lite Product', 'affistyle' ); } // Description. $desc = ! empty( $row['description'] ) ? $row['description'] : ''; if ( empty( $desc ) && $linked_post ) { $desc = ! empty( $linked_post->post_excerpt ) ? $linked_post->post_excerpt : $linked_post->post_content; } if ( empty( $desc ) && $lasso_id > 0 ) { $desc = (string) get_post_meta( $lasso_id, '_lasso_url_description', true ); } // Image. $img = ! empty( $row['image_src'] ) ? $row['image_src'] : ( ! empty( $row['image_url'] ) ? $row['image_url'] : ( ! empty( $row['image'] ) ? $row['image'] : '' ) ); if ( empty( $img ) && $lasso_id > 0 ) { $img = (string) get_post_meta( $lasso_id, 'lasso_custom_thumbnail', true ); if ( empty( $img ) ) { $img = (string) get_post_meta( $lasso_id, '_lasso_custom_thumbnail', true ); } if ( empty( $img ) ) { $img = (string) get_post_meta( $lasso_id, '_lasso_url_image_url', true ); } if ( empty( $img ) && has_post_thumbnail( $lasso_id ) ) { $img = (string) get_the_post_thumbnail_url( $lasso_id, 'full' ); } } // Price. $price = ! empty( $row['price'] ) ? $row['price'] : ( ! empty( $row['default_price'] ) ? $row['default_price'] : '' ); if ( empty( $price ) && $lasso_id > 0 ) { $price = (string) get_post_meta( $lasso_id, '_lasso_url_price', true ); if ( empty( $price ) ) { $price = (string) get_post_meta( $lasso_id, 'lasso_price', true ); } } // Rating. $rating = ! empty( $row['rating'] ) ? (float) $row['rating'] : 0.0; if ( empty( $rating ) && $lasso_id > 0 ) { $rating = (float) get_post_meta( $lasso_id, '_lasso_url_rating', true ); } // Badge. $badge = ! empty( $row['badge_text'] ) ? $row['badge_text'] : ( ! empty( $row['badge'] ) ? $row['badge'] : '' ); if ( empty( $badge ) && $lasso_id > 0 ) { $badge = (string) get_post_meta( $lasso_id, '_lasso_url_badge', true ); } if ( empty( $badge ) && $lasso_id > 0 ) { $cats = wp_get_post_terms( $lasso_id, array( 'lasso-lite-cat', 'category' ), array( 'fields' => 'names' ) ); if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { $badge = $cats[0]; } } // Button Text. $button = ! empty( $row['buy_btn_text'] ) ? $row['buy_btn_text'] : ( ! empty( $row['button_text'] ) ? $row['button_text'] : '' ); if ( empty( $button ) && $lasso_id > 0 ) { $button = (string) get_post_meta( $lasso_id, 'lasso_button_text', true ); } if ( empty( $button ) ) { $prod_type = ! empty( $row['product_type'] ) ? $row['product_type'] : ''; if ( 'Amazon Product' === $prod_type || ! empty( $asin ) ) { $button = __( 'Buy on Amazon', 'affistyle' ); } else { $button = __( 'Buy Now', 'affistyle' ); } } // Fallback ASIN extraction from Amazon URL. if ( empty( $asin ) && ! empty( $url ) && class_exists( 'AffiStyle_Scraper' ) ) { $asin = AffiStyle_Scraper::extract_asin( $url ); } $items[] = array( 'id' => 'lasso_lite_tbl_' . $row_id, 'title' => $title, 'url' => $url, 'image' => $img, 'price' => $price, 'rating' => $rating, 'badge' => $badge, 'button_text' => $button, 'description' => $desc, 'asin' => $asin, 'source' => 'Lasso Lite', ); } return $items; } } // Fallback to CPT surl (Lasso Lite), affiliate_url, simple_url, lasso-lite, lasso_lite. $posts = get_posts( array( 'post_type' => array( 'surl', 'affiliate_url', 'simple_url', 'lasso-lite', 'lasso_lite' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { // URL can be in _url (Simple URLs standard) or _affiliate_url, affiliate_url, _lasso_url_target_url, target_url. $target_url = get_post_meta( $p->ID, '_url', true ); if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, '_affiliate_url', true ); } if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, 'affiliate_url', true ); } if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, '_lasso_url_target_url', true ); } if ( empty( $target_url ) ) { $target_url = get_post_meta( $p->ID, 'target_url', true ); } // Image can be in lasso_custom_thumbnail, _lasso_url_image_url, or featured thumbnail. $image_url = get_post_meta( $p->ID, 'lasso_custom_thumbnail', true ); if ( empty( $image_url ) ) { $image_url = get_post_meta( $p->ID, '_lasso_custom_thumbnail', true ); } if ( empty( $image_url ) ) { $image_url = get_post_meta( $p->ID, '_lasso_url_image_url', true ); } if ( empty( $image_url ) && has_post_thumbnail( $p->ID ) ) { $image_url = (string) get_the_post_thumbnail_url( $p->ID, 'full' ); } // Price. $price = get_post_meta( $p->ID, '_lasso_url_price', true ); if ( empty( $price ) ) { $price = get_post_meta( $p->ID, 'lasso_price', true ); } // Rating. $rating = (float) get_post_meta( $p->ID, '_lasso_url_rating', true ); if ( empty( $rating ) ) { $rating = (float) get_post_meta( $p->ID, 'lasso_rating', true ); } // Badge. $badge = get_post_meta( $p->ID, '_lasso_url_badge', true ); if ( empty( $badge ) ) { $badge = get_post_meta( $p->ID, 'lasso_badge', true ); } if ( empty( $badge ) ) { $cats = wp_get_post_terms( $p->ID, array( 'lasso-lite-cat', 'category' ), array( 'fields' => 'names' ) ); if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { $badge = $cats[0]; } } // ASIN. $asin = get_post_meta( $p->ID, '_lasso_url_amazon_asin', true ); if ( empty( $asin ) ) { $asin = get_post_meta( $p->ID, 'amazon_asin', true ); } if ( empty( $asin ) && ! empty( $target_url ) && class_exists( 'AffiStyle_Scraper' ) ) { $asin = AffiStyle_Scraper::extract_asin( $target_url ); } // Button Text. $btn_text = get_post_meta( $p->ID, 'lasso_button_text', true ); if ( empty( $btn_text ) ) { $btn_text = ! empty( $asin ) ? __( 'Buy on Amazon', 'affistyle' ) : __( 'Buy Now', 'affistyle' ); } // Description. $desc = get_post_meta( $p->ID, '_lasso_url_description', true ); if ( empty( $desc ) ) { $desc = get_post_meta( $p->ID, 'lasso_description', true ); } if ( empty( $desc ) ) { $desc = ! empty( $p->post_excerpt ) ? $p->post_excerpt : $p->post_content; } $items[] = array( 'id' => 'lasso_lite_cpt_' . $p->ID, 'title' => $p->post_title, 'url' => $target_url, 'image' => $image_url, 'price' => $price, 'rating' => $rating, 'badge' => $badge, 'button_text' => $btn_text, 'description' => $desc, 'asin' => $asin, 'source' => 'Lasso Lite', ); } return $items; } /** * Fetch items from Pretty Links. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_pretty_links_items( $limit, $offset ) { global $wpdb; $items = array(); $prli_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'prli_links' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $prli_table ) ); if ( $table_exists === $prli_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i ORDER BY id DESC LIMIT %d OFFSET %d', $prli_table, $limit, $offset ), ARRAY_A ); if ( ! empty( $rows ) ) { foreach ( $rows as $row ) { $items[] = array( 'id' => 'prli_tbl_' . $row['id'], 'title' => ! empty( $row['name'] ) ? $row['name'] : ( ! empty( $row['slug'] ) ? $row['slug'] : __( 'Affiliate Link', 'affistyle' ) ), 'url' => ! empty( $row['url'] ) ? $row['url'] : '', 'image' => '', 'price' => '', 'rating' => 0, 'badge' => '', 'button_text' => __( 'Check Offer', 'affistyle' ), 'description' => '', 'slug' => ! empty( $row['slug'] ) ? $row['slug'] : '', 'source' => 'Pretty Links', ); } return $items; } } // Fallback to CPT pretty-link. $posts = get_posts( array( 'post_type' => 'pretty-link', 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => 'publish', ) ); foreach ( $posts as $p ) { $items[] = array( 'id' => 'prli_cpt_' . $p->ID, 'title' => $p->post_title, 'url' => get_post_meta( $p->ID, '_prli_target_url', true ), 'image' => '', 'price' => '', 'rating' => 0, 'badge' => '', 'button_text' => __( 'Check Offer', 'affistyle' ), 'description' => '', 'slug' => $p->post_name, 'source' => 'Pretty Links', ); } return $items; } /** * Fetch items from ThirstyAffiliates. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_thirstyaffiliates_items( $limit, $offset ) { $items = array(); $posts = get_posts( array( 'post_type' => array( 'thirstylink', 'thirstylink_item' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { $img_id = get_post_thumbnail_id( $p->ID ); $img_url = $img_id ? wp_get_attachment_url( $img_id ) : get_post_meta( $p->ID, '_ta_image_url', true ); $url = get_post_meta( $p->ID, '_ta_destination_url', true ); if ( empty( $url ) ) { $url = get_post_meta( $p->ID, '_ta_redirect_url', true ); } if ( empty( $url ) ) { $url = get_post_meta( $p->ID, '_ta_url', true ); } $items[] = array( 'id' => 'ta_' . $p->ID, 'title' => $p->post_title, 'url' => $url ? $url : '', 'image' => $img_url ? $img_url : '', 'price' => '', 'rating' => 0, 'badge' => '', 'button_text' => __( 'Visit Store', 'affistyle' ), 'description' => $p->post_excerpt, 'source' => 'ThirstyAffiliates', ); } return $items; } /** * Fetch items from Easy Affiliate Links. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_easy_affiliate_links_items( $limit, $offset ) { $items = array(); $posts = get_posts( array( 'post_type' => array( 'easy_affiliate_link', 'eafl_link' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { $img_id = get_post_thumbnail_id( $p->ID ); $img_url = $img_id ? wp_get_attachment_url( $img_id ) : ''; $url = get_post_meta( $p->ID, 'eafl_url', true ); if ( empty( $url ) ) { $url = get_post_meta( $p->ID, '_eafl_url', true ); } if ( empty( $url ) ) { $url = get_post_meta( $p->ID, 'url', true ); } $btn_txt = get_post_meta( $p->ID, 'eafl_text', true ); if ( empty( $btn_txt ) ) { $btn_txt = get_post_meta( $p->ID, '_eafl_text', true ); } $desc = ! empty( $p->post_content ) ? $p->post_content : get_post_meta( $p->ID, 'eafl_description', true ); $items[] = array( 'id' => 'eafl_' . $p->ID, 'title' => $p->post_title, 'slug' => $p->post_name, 'url' => $url, 'image' => $img_url ? $img_url : '', 'price' => '', 'rating' => 0, 'badge' => '', 'button_text' => ! empty( $btn_txt ) ? $btn_txt : __( 'Buy Now', 'affistyle' ), 'description' => $desc ? $desc : '', 'source' => 'Easy Affiliate Links', ); } return $items; } /** * Fetch items from AAWP. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_aawp_items( $limit, $offset ) { global $wpdb; $items = array(); $aawp_table = preg_replace( '/[^a-zA-Z0-9_]/', '', $wpdb->prefix . 'aawp_products' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $aawp_table ) ); if ( $table_exists === $aawp_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i ORDER BY id DESC LIMIT %d OFFSET %d', $aawp_table, $limit, $offset ), ARRAY_A ); if ( ! empty( $rows ) ) { foreach ( $rows as $row ) { $img_url = ! empty( $row['image_url'] ) ? $row['image_url'] : ''; if ( empty( $img_url ) && ! empty( $row['image_id'] ) ) { $img_url = wp_get_attachment_url( (int) $row['image_id'] ); } $features = ! empty( $row['features'] ) ? maybe_unserialize( $row['features'] ) : ''; $pros_txt = is_array( $features ) ? implode( "\n", $features ) : (string) $features; $items[] = array( 'id' => 'aawp_' . $row['id'], 'title' => ! empty( $row['title'] ) ? $row['title'] : __( 'Amazon Product', 'affistyle' ), 'url' => ! empty( $row['url'] ) ? $row['url'] : '', 'image' => $img_url ? $img_url : '', 'price' => ! empty( $row['price'] ) ? $row['price'] : '', 'rating' => ! empty( $row['rating'] ) ? (float) $row['rating'] : 0, 'badge' => '', 'button_text' => __( 'Buy on Amazon', 'affistyle' ), 'description' => $pros_txt, 'pros' => $pros_txt, 'asin' => ! empty( $row['asin'] ) ? $row['asin'] : '', 'source' => 'AAWP', ); } return $items; } } // Fallback to CPT aawp or aawp_list. $posts = get_posts( array( 'post_type' => array( 'aawp', 'aawp_list' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { $asin = get_post_meta( $p->ID, '_aawp_asin', true ); if ( empty( $asin ) ) { $asin = get_post_meta( $p->ID, 'aawp_asin', true ); } if ( empty( $asin ) ) { $asin = get_post_meta( $p->ID, 'asin', true ); } $url = get_post_meta( $p->ID, '_aawp_url', true ); if ( empty( $url ) ) { $url = get_post_meta( $p->ID, 'aawp_url', true ); } if ( empty( $url ) && ! empty( $asin ) ) { $url = 'https://www.amazon.com/dp/' . $asin; } $img_id = get_post_thumbnail_id( $p->ID ); $img_url = $img_id ? wp_get_attachment_url( $img_id ) : get_post_meta( $p->ID, '_aawp_image', true ); if ( empty( $img_url ) ) { $img_url = get_post_meta( $p->ID, 'aawp_image', true ); } $price = get_post_meta( $p->ID, '_aawp_price', true ); if ( empty( $price ) ) { $price = get_post_meta( $p->ID, 'aawp_price', true ); } $rating = (float) get_post_meta( $p->ID, '_aawp_rating', true ); if ( empty( $rating ) ) { $rating = (float) get_post_meta( $p->ID, 'aawp_rating', true ); } $items[] = array( 'id' => 'aawp_cpt_' . $p->ID, 'title' => $p->post_title, 'url' => $url ? $url : '', 'image' => $img_url ? $img_url : '', 'price' => $price ? $price : '', 'rating' => $rating, 'badge' => '', 'button_text' => __( 'Buy on Amazon', 'affistyle' ), 'description' => $p->post_content, 'pros' => '', 'asin' => $asin ? $asin : '', 'source' => 'AAWP', ); } return $items; } /** * Fetch items from EasyAzon. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_easyazon_items( $limit, $offset ) { global $wpdb; $items = array(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key LIKE %s LIMIT %d OFFSET %d", '%easyazon_asin%', $limit, $offset ) ); if ( empty( $post_ids ) ) { // Fallback: check CPT easyazon or easyazon_item. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type IN ('easyazon', 'easyazon_item') AND post_status NOT IN ('trash', 'auto-draft') LIMIT %d OFFSET %d", $limit, $offset ) ); } if ( ! empty( $post_ids ) ) { foreach ( $post_ids as $pid ) { $asin = get_post_meta( $pid, '_easyazon_asin', true ); if ( empty( $asin ) ) { $asin = get_post_meta( $pid, 'easyazon_asin', true ); } if ( empty( $asin ) ) { $asin = get_post_meta( $pid, 'asin', true ); } $title = get_the_title( $pid ); $url = get_post_meta( $pid, '_easyazon_url', true ); if ( empty( $url ) ) { $url = get_post_meta( $pid, 'easyazon_url', true ); } if ( empty( $url ) && ! empty( $asin ) ) { $url = 'https://www.amazon.com/dp/' . $asin; } $img = get_post_meta( $pid, '_easyazon_image', true ); if ( empty( $img ) ) { $img = get_post_meta( $pid, 'easyazon_image', true ); } if ( empty( $img ) && has_post_thumbnail( $pid ) ) { $img = (string) get_the_post_thumbnail_url( $pid, 'full' ); } $price = get_post_meta( $pid, '_easyazon_price', true ); if ( empty( $price ) ) { $price = get_post_meta( $pid, 'easyazon_price', true ); } $items[] = array( 'id' => 'easyazon_' . $pid, 'title' => ! empty( $title ) ? $title : ( ! empty( $asin ) ? 'Amazon Item ' . $asin : __( 'EasyAzon Product', 'affistyle' ) ), 'url' => $url, 'image' => $img ? $img : '', 'price' => $price ? $price : '', 'rating' => 0, 'badge' => '', 'button_text' => __( 'Buy on Amazon', 'affistyle' ), 'description' => '', 'asin' => $asin ? $asin : '', 'source' => 'EasyAzon', ); } } return $items; } /** * Fetch items from AmaLinks Pro. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_amalinkspro_items( $limit, $offset ) { $items = array(); $posts = get_posts( array( 'post_type' => array( 'amalinkspro', 'amalinkspro_cta', 'amalinkspro_table' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { $asin = get_post_meta( $p->ID, '_amalinkspro_asin', true ); if ( empty( $asin ) ) { $asin = get_post_meta( $p->ID, 'amalinkspro_asin', true ); } if ( empty( $asin ) ) { $asin = get_post_meta( $p->ID, 'asin', true ); } $url = get_post_meta( $p->ID, '_amalinkspro_url', true ); if ( empty( $url ) ) { $url = get_post_meta( $p->ID, 'amalinkspro_url', true ); } if ( empty( $url ) && ! empty( $asin ) ) { $url = 'https://www.amazon.com/dp/' . $asin; } $img = get_post_meta( $p->ID, '_amalinkspro_image', true ); if ( empty( $img ) ) { $img = get_post_meta( $p->ID, 'amalinkspro_image', true ); } if ( empty( $img ) && has_post_thumbnail( $p->ID ) ) { $img = (string) get_the_post_thumbnail_url( $p->ID, 'full' ); } $price = get_post_meta( $p->ID, '_amalinkspro_price', true ); if ( empty( $price ) ) { $price = get_post_meta( $p->ID, 'amalinkspro_price', true ); } $btn_txt = get_post_meta( $p->ID, '_amalinkspro_button_text', true ); if ( empty( $btn_txt ) ) { $btn_txt = get_post_meta( $p->ID, 'amalinkspro_button_text', true ); } $rating = (float) get_post_meta( $p->ID, '_amalinkspro_rating', true ); if ( empty( $rating ) ) { $rating = (float) get_post_meta( $p->ID, 'amalinkspro_rating', true ); } $items[] = array( 'id' => 'amalinkspro_' . $p->ID, 'title' => $p->post_title, 'url' => $url ? $url : '', 'image' => $img ? $img : '', 'price' => $price ? $price : '', 'rating' => $rating, 'badge' => '', 'button_text' => ! empty( $btn_txt ) ? $btn_txt : __( 'Buy on Amazon', 'affistyle' ), 'description' => $p->post_content, 'asin' => $asin ? $asin : '', 'source' => 'AmaLinks Pro', ); } return $items; } /** * Fetch items from Earnist. * * @param int $limit Query limit. * @param int $offset Query offset. * @return array */ private static function fetch_earnist_items( $limit, $offset ) { $items = array(); $posts = get_posts( array( 'post_type' => array( 'earnist', 'earnist_product', 'earnist_link' ), 'posts_per_page' => $limit, 'offset' => $offset, 'post_status' => array( 'publish', 'private' ), ) ); foreach ( $posts as $p ) { $img_id = get_post_thumbnail_id( $p->ID ); $img_url = $img_id ? wp_get_attachment_url( $img_id ) : get_post_meta( $p->ID, '_earnist_image', true ); if ( empty( $img_url ) ) { $img_url = get_post_meta( $p->ID, 'earnist_image', true ); } $btn_txt = get_post_meta( $p->ID, '_earnist_button_text', true ); if ( empty( $btn_txt ) ) { $btn_txt = get_post_meta( $p->ID, 'earnist_button_text', true ); } $url = get_post_meta( $p->ID, '_earnist_url', true ); if ( empty( $url ) ) { $url = get_post_meta( $p->ID, 'earnist_url', true ); } if ( empty( $url ) ) { $url = get_post_meta( $p->ID, '_url', true ); } if ( empty( $url ) ) { $url = get_post_meta( $p->ID, 'url', true ); } $price = get_post_meta( $p->ID, '_earnist_price', true ); if ( empty( $price ) ) { $price = get_post_meta( $p->ID, 'earnist_price', true ); } $rating = (float) get_post_meta( $p->ID, '_earnist_rating', true ); if ( empty( $rating ) ) { $rating = (float) get_post_meta( $p->ID, 'earnist_rating', true ); } $badge = get_post_meta( $p->ID, '_earnist_badge', true ); if ( empty( $badge ) ) { $badge = get_post_meta( $p->ID, 'earnist_badge', true ); } $items[] = array( 'id' => 'earnist_' . $p->ID, 'title' => $p->post_title, 'url' => $url ? $url : '', 'image' => $img_url ? $img_url : '', 'price' => $price ? $price : '', 'rating' => $rating, 'badge' => $badge ? $badge : '', 'button_text' => ! empty( $btn_txt ) ? $btn_txt : __( 'Buy Now', 'affistyle' ), 'description' => $p->post_content, 'pros' => get_post_meta( $p->ID, '_earnist_pros', true ), 'cons' => get_post_meta( $p->ID, '_earnist_cons', true ), 'source' => 'Earnist', ); } return $items; } /** * Import a single item into AffiStyle custom post type with full meta mapping. * * @param array $item Raw source item array. * @param array $options Import options (skip_duplicates, default_style, default_button_text). * @return array Result array with status, message, and box_id if created. */ public static function import_item( $item, $options = array() ) { global $wpdb; $title = ! empty( $item['title'] ) ? sanitize_text_field( $item['title'] ) : __( 'Imported Affiliate Product', 'affistyle' ); $url = ! empty( $item['url'] ) ? esc_url_raw( $item['url'] ) : ''; $asin = ! empty( $item['asin'] ) ? sanitize_text_field( $item['asin'] ) : ''; $skip_duplicates = isset( $options['skip_duplicates'] ) ? (bool) $options['skip_duplicates'] : true; $default_style = ! empty( $options['default_style'] ) ? sanitize_key( $options['default_style'] ) : 'style-1'; $source = ! empty( $item['source'] ) ? sanitize_text_field( $item['source'] ) : 'Importer'; // Ensure all elements in $item are fully sanitized for subsequent processing and action hooks. $item = array( 'title' => $title, 'url' => $url, 'asin' => $asin, 'source' => $source, 'description' => ! empty( $item['description'] ) ? sanitize_textarea_field( $item['description'] ) : '', 'image' => ! empty( $item['image'] ) ? esc_url_raw( $item['image'] ) : '', 'price' => ! empty( $item['price'] ) ? sanitize_text_field( $item['price'] ) : '', 'button_text' => ! empty( $item['button_text'] ) ? sanitize_text_field( $item['button_text'] ) : __( 'Buy Now', 'affistyle' ), 'badge' => ! empty( $item['badge'] ) ? sanitize_text_field( $item['badge'] ) : '', 'rating' => ! empty( $item['rating'] ) ? max( 0.0, min( 5.0, floatval( $item['rating'] ) ) ) : 0.0, 'pros' => ! empty( $item['pros'] ) ? sanitize_textarea_field( $item['pros'] ) : '', 'cons' => ! empty( $item['cons'] ) ? sanitize_textarea_field( $item['cons'] ) : '', 'slug' => ! empty( $item['slug'] ) ? sanitize_title( $item['slug'] ) : '', ); if ( empty( $url ) && empty( $asin ) ) { return array( 'status' => 'error', 'message' => sprintf( /* translators: %s: Item title */ __( 'Item "%s" skipped: No destination URL or ASIN found.', 'affistyle' ), $title ), ); } // Duplicate detection. if ( $skip_duplicates ) { $existing_id = 0; if ( ! empty( $url ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $existing_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_affistyle_destination' AND meta_value = %s LIMIT 1", $url ) ); } if ( ! $existing_id && ! empty( $asin ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $existing_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_affistyle_amazon_asin' AND meta_value = %s LIMIT 1", $asin ) ); } if ( $existing_id > 0 ) { return array( 'status' => 'skipped', 'box_id' => $existing_id, 'title' => $title, 'edit_url' => get_edit_post_link( $existing_id, 'raw' ), 'message' => sprintf( /* translators: 1: Item title, 2: Box ID */ __( 'Skipped "%1$s" — already exists in Box #%2$d.', 'affistyle' ), $title, $existing_id ), ); } } // Create the new AffiStyle box post. $post_id = wp_insert_post( array( 'post_title' => $title, 'post_status' => 'publish', 'post_type' => 'affistyle_box', 'post_content' => ! empty( $item['description'] ) ? sanitize_textarea_field( $item['description'] ) : '', ) ); if ( is_wp_error( $post_id ) || ! $post_id ) { return array( 'status' => 'error', 'message' => sprintf( /* translators: %s: Item title */ __( 'Failed to create Affiliate Box for "%s".', 'affistyle' ), $title ), ); } // Update core AffiStyle meta fields. update_post_meta( $post_id, '_affistyle_style', $default_style ); update_post_meta( $post_id, '_affistyle_title_1', $title ); update_post_meta( $post_id, '_affistyle_destination', $url ); update_post_meta( $post_id, '_affistyle_url_default', $url ); if ( ! empty( $item['image'] ) ) { $img = esc_url_raw( $item['image'] ); update_post_meta( $post_id, '_affistyle_image_1', $img ); update_post_meta( $post_id, '_affistyle_image_url', $img ); } if ( ! empty( $item['price'] ) ) { $price = sanitize_text_field( $item['price'] ); update_post_meta( $post_id, '_affistyle_price_1', $price ); update_post_meta( $post_id, '_affistyle_price', $price ); } $btn_text = ! empty( $item['button_text'] ) ? sanitize_text_field( $item['button_text'] ) : __( 'Buy Now', 'affistyle' ); update_post_meta( $post_id, '_affistyle_button_text', $btn_text ); if ( ! empty( $item['badge'] ) ) { update_post_meta( $post_id, '_affistyle_badge', sanitize_text_field( $item['badge'] ) ); } if ( ! empty( $item['rating'] ) ) { $score = floatval( $item['rating'] ); $score = max( 0.0, min( 5.0, $score ) ); update_post_meta( $post_id, '_affistyle_rating_score', $score ); update_post_meta( $post_id, '_affistyle_show_rating', '1' ); } if ( ! empty( $item['pros'] ) ) { update_post_meta( $post_id, '_affistyle_pros', sanitize_textarea_field( $item['pros'] ) ); } if ( ! empty( $item['cons'] ) ) { update_post_meta( $post_id, '_affistyle_cons', sanitize_textarea_field( $item['cons'] ) ); } if ( ! empty( $asin ) ) { update_post_meta( $post_id, '_affistyle_amazon_asin', $asin ); } if ( ! empty( $item['slug'] ) ) { update_post_meta( $post_id, '_affistyle_custom_slug', sanitize_title( $item['slug'] ) ); } update_post_meta( $post_id, '_affistyle_imported_from', $source ); update_post_meta( $post_id, '_affistyle_imported_at', current_time( 'mysql' ) ); /** * Action hook after an affiliate item has been imported. * * @param int $post_id Newly created affistyle_box ID. * @param array $item Raw source item array. * @param array $options Import options. */ do_action( 'affistyle_after_import_item', $post_id, $item, $options ); return array( 'status' => 'success', 'box_id' => $post_id, 'title' => $title, 'edit_url' => get_edit_post_link( $post_id, 'raw' ), 'message' => sprintf( /* translators: 1: Item title, 2: Box ID */ __( 'Successfully imported "%1$s" into Affiliate Box #%2$d.', 'affistyle' ), $title, $post_id ), ); } }