'Customize this product →', 'auto_button' => 1, // show the button above Add to cart on product pages 'unit' => 'in', // print size unit: in | cm 'dpi' => 300, // print file resolution when a product has a real print size 'accent' => '#4338ca', // studio buttons, active tabs and highlights 'realism' => 'subtle', // product folds and shadows over the design on screen: off | subtle | strong 'stock' => 0, // free photo search (Wikimedia Commons), off until the shop turns it on )); } function aiph_opt($key) { static $o = null; if ($o === null) { $saved = get_option('aiph_options', array()); $o = array_merge(aiph_option_defaults(), is_array($saved) ? $saved : array()); } return $o[$key] ?? null; } add_action('admin_post_aiph_save_settings', function () { if (!current_user_can('manage_woocommerce')) wp_die(esc_html__('Access denied', 'printloom'), '', array('response'=>403)); check_admin_referer('aiph_settings'); // Every value is sanitized here, before the fields below and the add-ons validate their own options. $in = isset($_POST['aiph']) && is_array($_POST['aiph']) ? map_deep(wp_unslash($_POST['aiph']), 'sanitize_textarea_field') : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized by map_deep() $d = aiph_option_defaults(); $saved = (array) get_option('aiph_options', array()); $o = array_merge($saved, array( 'button_label' => sanitize_text_field($in['button_label'] ?? '') ?: $d['button_label'], 'auto_button' => empty($in['auto_button']) ? 0 : 1, 'unit' => ($in['unit'] ?? '') === 'cm' ? 'cm' : 'in', 'dpi' => max(72, min(600, absint($in['dpi'] ?? 300))), 'accent' => sanitize_hex_color((string) ($in['accent'] ?? '')) ?: $d['accent'], 'realism' => in_array($in['realism'] ?? '', array('off', 'subtle', 'strong'), true) ? $in['realism'] : 'subtle', 'stock' => empty($in['stock']) ? 0 : 1, )); // Add-ons sanitize and add their own fields. update_option('aiph_options', apply_filters('aiph_save_settings', $o, $in)); wp_safe_redirect(add_query_arg(array('page'=>'aiph-studio','tab'=>'settings','updated'=>1), admin_url('admin.php'))); exit; }); add_action('admin_post_aiph_toggle', function () { $id = absint($_GET['product'] ?? 0); if (!current_user_can('edit_product', $id)) wp_die(esc_html__('Access denied', 'printloom'), '', array('response'=>403)); check_admin_referer('aiph_toggle_'.$id); $p = wc_get_product($id); if ($p && aiph_supported($p)) { $p->update_meta_data('_aiph_enabled', aiph_enabled($id) ? 'no' : 'yes'); $p->save(); } wp_safe_redirect(add_query_arg(array('page'=>'aiph-studio','tab'=>'products'), admin_url('admin.php'))); exit; }); /** Tabs of the Design Studio screen: slug => array(label, callback). */ function aiph_admin_tabs() { return apply_filters('aiph_admin_tabs', array( 'dashboard' => array(__('Dashboard', 'printloom'), 'aiph_dashboard_tab'), 'products' => array(__('Products', 'printloom'), 'aiph_products_tab'), 'settings' => array(__('Settings', 'printloom'), 'aiph_settings_tab'), )); } /** Menu icon (dashicons name) and one-line description of each tab; add-ons can add theirs. */ function aiph_admin_tab_meta() { return (array) apply_filters('aiph_admin_tab_meta', array( 'dashboard' => array('dashboard', __('Your designer at a glance: products, designs and orders.', 'printloom')), 'products' => array('products', __('Turn the designer on for products and copy settings between them.', 'printloom')), 'settings' => array('admin-generic', __('Storefront button, studio look and print files.', 'printloom')), 'print-pricing' => array('money-alt', __('Shared price tables for screen and digital printing.', 'printloom')), 'templates' => array('layout', __('Ready-made designs customers start from.', 'printloom')), 'library' => array('images-alt2', __('Fonts, graphics and categories in the studio.', 'printloom')), 'license' => array('admin-network', __('Your Pro license and updates.', 'printloom')), )); } /** Help link: the bundled documentation in the CodeCanyon edition, otherwise the online guides. */ function aiph_help_url() { return defined('AIPH_DOCS_URL') ? AIPH_DOCS_URL : 'https://aipluginhub.io/product-designer/'; } function aiph_admin_url($tab = 'dashboard', $args = array()) { return add_query_arg(array_merge(array('page'=>'aiph-studio', 'tab'=>$tab), $args), admin_url('admin.php')); } function aiph_admin_page() { $tabs = aiph_admin_tabs(); $meta = aiph_admin_tab_meta(); $tab = sanitize_key(wp_unslash($_GET['tab'] ?? 'dashboard')); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- tab switch only if (!isset($tabs[$tab])) $tab = 'dashboard'; $pro = defined('AIPH_PRO_VERSION'); echo '

'.esc_html__('PrintLoom · Design Studio', 'printloom').'

'; // Side menu (Lumise-style app layout); a scrolling bar on small screens. $pro_label = defined('AIPH_ENVATO') ? 'v'.AIPH_ENVATO : ($pro ? 'Pro '.AIPH_PRO_VERSION : 'v'.AIPH_VERSION); echo ''; else echo '
'.esc_html__('Live demo', 'printloom').''.esc_html__('Help', 'printloom').'
'; echo '

'.esc_html($tabs[$tab][0]).'

'.(!empty($meta[$tab][1]) ? '

'.esc_html($meta[$tab][1]).'

' : '').'
'; if ($tab !== 'products') echo ''.esc_html__('Set up a product', 'printloom').''; echo '
'; do_action('aiph_admin_notices', $tab); // Sites that used the all-in-one 0.8 version with a Pro license: Pro now lives in a separate add-on. $old = get_option('aiph_license'); if (!defined('AIPH_PRO_VERSION') && is_array($old) && !empty($old['key'])) { echo '

'.wp_kses(sprintf(/* translators: %s: account URL */ __('This site has a Pro license. Pro features now come from the separate PrintLoom Pro add-on: download it from your aipluginhub.io account and activate it to keep them.', 'printloom'), esc_url('https://aipluginhub.io/my-account/')), array('a'=>array('href'=>true,'target'=>true,'rel'=>true))).'

'; } if (is_callable($tabs[$tab][1])) call_user_func($tabs[$tab][1]); echo '
'; } /** Dashboard: numbers, a setup checklist, shortcuts and the latest orders with designs. */ function aiph_dashboard_tab() { global $wpdb; $enabled = get_posts(array('post_type'=>'product', 'post_status'=>'publish', 'numberposts'=>-1, 'fields'=>'ids', 'meta_key'=>'_aiph_enabled', 'meta_value'=>'yes')); // phpcs:ignore WordPress.DB.SlowDBQuery -- admin screen $designs = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE 'aiph\\_design\\_%'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- a count of the design records $saved = (int) (wp_count_posts('aiph_saved')->private ?? 0); $recent = array(); $count30 = 0; if (function_exists('wc_get_orders')) { $orders = wc_get_orders(array('limit'=>60, 'orderby'=>'date', 'order'=>'DESC', 'date_created'=>'>'.(time() - 30 * DAY_IN_SECONDS), 'status'=>array_keys(wc_get_order_statuses()))); foreach ($orders as $o) { $key = ''; foreach ($o->get_items() as $it) { $k = (string) $it->get_meta('_aiph_design'); if ($k) { $key = $k; break; } } if (!$key) continue; $count30++; if (count($recent) < 6) $recent[] = array($o, $key); } } $stats = apply_filters('aiph_dashboard_stats', array( array('products', __('Products with the designer', 'printloom'), count($enabled), aiph_admin_url('products')), array('art', __('Designs created', 'printloom'), $designs, ''), array('cart', __('Orders with designs (30 days)', 'printloom'), $count30, admin_url('admin.php?page=wc-orders')), array('heart', __('Saved in My designs', 'printloom'), $saved, ''), )); echo '
'; foreach ($stats as $st) { $inner = ''.esc_html(number_format_i18n((int) $st[2])).''.esc_html($st[1]).''; echo $st[3] ? ''.$inner.'' : '
'.$inner.'
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above } echo '
'; // Setup checklist $o = (array) get_option('aiph_options', array()); $sized = false; foreach ($enabled as $pid) { $s = aiph_settings($pid); if ((float) $s['pw'] > 0) { $sized = true; break; } } $first = $enabled ? $enabled[0] : 0; $steps = apply_filters('aiph_dashboard_checklist', array( array(!empty($enabled), __('Turn the designer on for a product', 'printloom'), aiph_admin_url('products')), array($sized, __('Set the real print size on a product', 'printloom'), $first ? get_edit_post_link($first, 'url') : aiph_admin_url('products')), array(!empty($o), __('Check the settings: button text, studio color, print files', 'printloom'), aiph_admin_url('settings')), array($first && $designs > 0, __('Try the studio as a customer', 'printloom'), $first ? aiph_studio_url($first) : aiph_admin_url('products')), )); $done = count(array_filter(array_column($steps, 0))); echo '

'.esc_html__('Get started', 'printloom').'

'.esc_html(sprintf(/* translators: 1: done steps, 2: all steps */ __('%1$d of %2$d done', 'printloom'), $done, count($steps))).'
    '; foreach ($steps as $st) echo '
  1. '.esc_html($st[1]).'
  2. '; echo '
'; // Shortcuts $links = apply_filters('aiph_dashboard_links', array( array('plus-alt2', __('Set up a product', 'printloom'), aiph_admin_url('products')), array('admin-appearance', __('Studio look & files', 'printloom'), aiph_admin_url('settings')), array('external', __('Open the studio', 'printloom'), $first ? aiph_studio_url($first) : ''), array('book', __('Guides & help', 'printloom'), aiph_help_url()), )); echo '

'.esc_html__('Shortcuts', 'printloom').'

'; if (!defined('AIPH_PRO_VERSION')) echo '
'.esc_html__('PrintLoom Pro', 'printloom').'

'.esc_html__('3D preview, product colors from one photo, realistic fabric and caps, embroidery look, design proofs, AI designs, team names and print-ready PDFs.', 'printloom').'

'.esc_html__('See Pro', 'printloom').'
'; echo '
'; // Latest orders with designs echo '

'.esc_html__('Latest orders with designs', 'printloom').'

'; if (!$recent) echo '

'.esc_html__('No orders with customer designs in the last 30 days yet.', 'printloom').'

'; else { echo ''; foreach ($recent as [$ord, $key]) { $badge = (string) apply_filters('aiph_dashboard_order_badge', '', $ord); echo ''; } echo '
#'.esc_html($ord->get_order_number()).' '.esc_html(trim($ord->get_billing_first_name().' '.$ord->get_billing_last_name())).'
'.esc_html(wc_format_datetime($ord->get_date_created())).'
'.esc_html(wc_get_order_status_name($ord->get_status())).''.wp_kses_post($badge).''.esc_html__('View', 'printloom').'
'; } echo '
'; } /** Starting points for common products: print area (% of the mockup photo) and print size in inches. */ function aiph_presets() { return apply_filters('aiph_presets', array( 'tshirt' => array('label'=>__('T-shirt (front)', 'printloom'), 'x'=>32, 'y'=>26, 'w'=>36, 'h'=>46, 'pw'=>12, 'ph'=>16), 'hoodie' => array('label'=>__('Hoodie (front)', 'printloom'), 'x'=>33, 'y'=>30, 'w'=>34, 'h'=>30, 'pw'=>12, 'ph'=>10), 'tote' => array('label'=>__('Tote bag', 'printloom'), 'x'=>27, 'y'=>40, 'w'=>46, 'h'=>42, 'pw'=>12, 'ph'=>12), 'mug' => array('label'=>__('Mug (wrap)', 'printloom'), 'x'=>20, 'y'=>28, 'w'=>52, 'h'=>40, 'pw'=>8.5, 'ph'=>3.5), 'cap' => array('label'=>__('Cap (front)', 'printloom'), 'x'=>33, 'y'=>30, 'w'=>34, 'h'=>18, 'pw'=>4, 'ph'=>2), 'square' => array('label'=>__('Poster, pillow or sticker (full image)', 'printloom'), 'x'=>10, 'y'=>10, 'w'=>80, 'h'=>80, 'pw'=>0, 'ph'=>0), )); } add_action('admin_post_aiph_quick_setup', function () { if (!current_user_can('manage_woocommerce')) wp_die(esc_html__('Access denied', 'printloom'), '', array('response'=>403)); check_admin_referer('aiph_quick_setup'); $id = absint($_POST['product'] ?? 0); $p = wc_get_product($id); $presets = aiph_presets(); $key = sanitize_key(wp_unslash($_POST['preset'] ?? '')); if (!aiph_supported($p) || !current_user_can('edit_product', $id) || !isset($presets[$key])) { wp_safe_redirect(add_query_arg(array('page'=>'aiph-studio','tab'=>'products','aiph_msg'=>'error'), admin_url('admin.php'))); exit; } $pr = $presets[$key]; $s = aiph_settings($id); $cm = aiph_print_unit() === 'cm'; foreach (array('x','y','w','h') as $k) $s[$k] = (float) $pr[$k]; foreach (array('pw','ph') as $k) $s[$k] = $pr[$k] > 0 ? ($cm ? round($pr[$k]*2.54*2)/2 : (float) $pr[$k]) : 0; $p->update_meta_data('_aiph_area', $s); $p->update_meta_data('_aiph_enabled', 'yes'); $p->save(); wp_safe_redirect(add_query_arg(array('page'=>'aiph-studio','tab'=>'products','aiph_msg'=>'setup','product'=>$id), admin_url('admin.php'))); exit; }); /** Designer meta keys copied between products. Mockup images are optional (they usually differ per product). */ function aiph_copy_meta_keys($from, $with_images) { $keys = array(); foreach (array_keys((array) get_post_meta($from)) as $k) { if (!str_starts_with($k, '_aiph_') || in_array($k, array('_aiph_design'), true)) continue; if (!$with_images && str_ends_with($k, '_image')) continue; $keys[] = $k; } return (array) apply_filters('aiph_copy_meta_keys', $keys, $from, $with_images); } add_action('admin_post_aiph_copy_settings', function () { if (!current_user_can('manage_woocommerce')) wp_die(esc_html__('Access denied', 'printloom'), '', array('response'=>403)); check_admin_referer('aiph_copy_settings'); $from = absint($_POST['from'] ?? 0); $targets = array_filter(array_map('absint', (array) wp_unslash($_POST['to'] ?? array()))); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- absint() on every value $n = 0; if ($from && aiph_enabled($from) && $targets) { $keys = aiph_copy_meta_keys($from, !empty($_POST['images'])); foreach (array_slice($targets, 0, 200) as $to) { if ($to === $from || !current_user_can('edit_product', $to) || !aiph_supported(wc_get_product($to))) continue; foreach ($keys as $k) update_post_meta($to, $k, get_post_meta($from, $k, true)); update_post_meta($to, '_aiph_enabled', 'yes'); $n++; } } wp_safe_redirect(add_query_arg(array('page'=>'aiph-studio','tab'=>'products','aiph_msg'=>$n ? 'copied' : 'nocopy','count'=>$n), admin_url('admin.php'))); exit; }); function aiph_products_tab() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- display-only notices after redirects $msg = sanitize_key(wp_unslash($_GET['aiph_msg'] ?? '')); if ($msg === 'setup') { $pid = absint($_GET['product'] ?? 0); echo '

'.esc_html__('The designer is on. Check the print area on the product photo, then try it in the studio.', 'printloom').' '.esc_html__('Adjust print area', 'printloom').' '.esc_html__('Open studio', 'printloom').'

'; } /* translators: %d: number of products */ if ($msg === 'copied') echo '

'.esc_html(sprintf(_n('Settings copied to %d product.', 'Settings copied to %d products.', absint($_GET['count'] ?? 0), 'printloom'), absint($_GET['count'] ?? 0))).'

'; if ($msg === 'nocopy') echo '

'.esc_html__('Nothing was copied. Choose a product to copy from and tick at least one product in the list.', 'printloom').'

'; if ($msg === 'error') echo '

'.esc_html__('Please choose a product and a product type.', 'printloom').'

'; // phpcs:enable $products = wc_get_products(array('limit'=>200,'status'=>'publish','type'=>array('simple','variable'),'orderby'=>'title','order'=>'ASC')); $enabled = array_filter($products, fn($p) => aiph_enabled($p->get_id())); $off = array_filter($products, fn($p) => !aiph_enabled($p->get_id())); echo '
'; // Quick setup echo '

'.esc_html($enabled ? __('Quick setup', 'printloom') : __('Set up your first product in 2 minutes', 'printloom')).'

'; if (!$enabled) echo '
  1. '.esc_html__('Pick a product that has a mockup photo as its featured image.', 'printloom').'
  2. '.esc_html__('Choose what it is — we place the print area and set a typical print size.', 'printloom').'
  3. '.esc_html__('Open the studio and try it. Fine-tune the print area any time on the product screen.', 'printloom').'
'; else echo '

'.esc_html__('Turn on the designer for another product with a ready-made print area.', 'printloom').'

'; if ($off) { echo '
'; wp_nonce_field('aiph_quick_setup'); echo '
'; } else echo '

'.esc_html__('All your products already have the designer turned on.', 'printloom').'

'; echo '
'; // Copy settings if ($enabled && count($products) > 1) { echo '

'.esc_html__('Copy settings to other products', 'printloom').'

'.esc_html__('Use one product as the model: print areas, print sizes and extras are copied to the products you tick in the list below.', 'printloom').'

'; echo '
'; } echo '
'; echo '
'; wp_nonce_field('aiph_copy_settings'); echo ''; if (!$products) echo ''; foreach ($products as $p) { $id = $p->get_id(); $on = aiph_enabled($id); $toggle = wp_nonce_url(admin_url('admin-post.php?action=aiph_toggle&product='.$id), 'aiph_toggle_'.$id); echo ''; echo ''; echo ''; echo ''; } echo '
'.esc_html__('Product', 'printloom').''.esc_html__('Type', 'printloom').''.esc_html__('Designer', 'printloom').''.esc_html__('Mockup', 'printloom').'
'.esc_html__('No published simple or variable products yet.', 'printloom').'
'.($p->get_image_id() ? wp_get_attachment_image($p->get_image_id(), array(40, 40), false, array('class'=>'aiph-prod-img', 'alt'=>'')) : '').''.esc_html($p->get_name()).''.esc_html(ucfirst($p->get_type())).''.($on ? ''.esc_html__('● Enabled', 'printloom').'' : ''.esc_html__('○ Off', 'printloom').'').'   '.($on?esc_html__('Turn off', 'printloom'):esc_html__('Turn on', 'printloom')).''.($p->get_image_id() ? '✓ '.esc_html__('Featured image', 'printloom') : ''.esc_html__('Add a featured image', 'printloom').'').''.($on ? ''.esc_html__('Open studio →', 'printloom').'' : '').'

'.esc_html__('Artwork is private. Abandoned designs are removed after seven days; ordered designs are kept with the order.', 'printloom').'

'; if (!defined('AIPH_PRO_VERSION')) { // A plain link on the plugin's own screen; nothing is locked or hidden in this plugin. echo '

'.esc_html__('Want more?', 'printloom').'

'.esc_html__('The separate Pro add-on adds design templates, AI designs, text styles, a graphics library, back and sleeve printing, team names & numbers, quantity discounts, print PDFs and production sheets.', 'printloom').' '.esc_html__('Learn more', 'printloom').'

'; } } /** One settings row: label with an optional tooltip, then the control and a short description. */ function aiph_settings_row($label, $control, $tip = '', $desc = '', $for = '', $attrs = '') { echo ''.($for !== '' ? '' : esc_html($label)).aiph_tip($tip).''.$control.($desc !== '' ? '

'.wp_kses_post($desc).'

' : '').''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $control and $attrs are built escaped by the caller; wc_help_tip() escapes } function aiph_settings_tab() { if (!empty($_GET['updated'])) echo // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only notice '

'.esc_html__('Settings saved.', 'printloom').'

'; $o = array_merge(aiph_option_defaults(), (array) get_option('aiph_options', array())); echo '
'; wp_nonce_field('aiph_settings'); echo ''; echo '

'.esc_html__('Storefront', 'printloom').'

'; aiph_settings_row(__('Button text', 'printloom'), '', __('The text on the button that opens the design studio on product pages.', 'printloom'), '', 'aiph-label'); aiph_settings_row(__('Show the button', 'printloom'), '', __('Turn this off if you place the button yourself, for example in a page builder layout.', 'printloom'), esc_html__('Or place it yourself with the shortcode', 'printloom').' [aiph_designer], '.esc_html__('the “Product Designer Button” block or the Elementor “Custom Product Designer” widget.', 'printloom')); aiph_settings_row(__('Studio accent color', 'printloom'), ''.esc_html(sanitize_hex_color((string) $o['accent']) ?: aiph_option_defaults()['accent']).'', __('Color of the main buttons, the active tab and highlights in the design studio. Pick your brand color; dark colors work best because button text is white.', 'printloom'), '', 'aiph-accent'); $real = ''; foreach (array('off'=>__('Off', 'printloom'), 'subtle'=>__('Subtle', 'printloom'), 'strong'=>__('Strong', 'printloom')) as $k=>$lbl) $real .= ''; $real .= ''; aiph_settings_row(__('Realistic look', 'printloom'), $real, __('Shows the folds and shadows of your product photo through the customer’s design, so it looks printed on the fabric. Only for the preview: print files stay clean.', 'printloom'), esc_html__('Works best with real product photos. Use Off for flat illustrations.', 'printloom')); aiph_settings_row(__('Free photo search', 'printloom'), '', __('Adds a search box under Upload. Results are public domain or CC0 images from Wikimedia Commons, so no credit is needed on the product.', 'printloom'), esc_html__('When this is on, the customer’s browser connects to Wikimedia Commons (commons.wikimedia.org) to search and load images. Check photos of people, logos or brands before you print them.', 'printloom')); echo ''; echo '

'.esc_html__('Print files', 'printloom').'

'; $unit = ''; foreach (array('in'=>__('Inches (in)', 'printloom'), 'cm'=>__('Centimeters (cm)', 'printloom')) as $k=>$lbl) $unit .= ''; $unit .= ''; aiph_settings_row(__('Print size unit', 'printloom'), $unit, __('Used for the print size of every product (PrintLoom tab on the product screen).', 'printloom'), esc_html__('Changing the unit does not convert sizes you already entered.', 'printloom')); aiph_settings_row(__('Print resolution', 'printloom'), 'DPI', __('Artwork files for products with a print size are made at this resolution. 300 DPI is standard for DTG, DTF and screen printing. Very large prints are capped at 6000 px per side.', 'printloom'), '', 'aiph-dpi'); echo ''; // Add-ons (AI, background removal…) add their sections after the core ones. do_action('aiph_settings_sections', $o); echo '
'; submit_button(__('Save settings', 'printloom'), 'primary', 'submit', false); echo '
'; }