'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 '
PrintLoom '.esc_html($pro_label).' ';
foreach ($tabs as $slug=>$t) {
$ic = $meta[$slug][0] ?? 'admin-page';
echo ''.esc_html($t[0]).' ';
}
if (defined('AIPH_ENVATO')) echo ' ';
else echo '';
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 ''.esc_html($st[1]).' ';
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').' ';
foreach ($links as $l) { if (!$l[2]) continue; $ext = strpos($l[2], admin_url()) !== 0 && strpos($l[2], home_url()) !== 0;
echo '
'.esc_html($l[1]).''; }
echo '
';
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 '#'.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 '
';
}
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 ''; }
/* 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 '
'.esc_html__('Pick a product that has a mockup photo as its featured image.', 'printloom').' '.esc_html__('Choose what it is — we place the print area and set a typical print size.', 'printloom').' '.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 '
';
} 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 '
';
foreach ($enabled as $p) echo ''.esc_html($p->get_name()).' ';
echo ' '.esc_html__('Include side mockup images', 'printloom').''.esc_html__('Copy to ticked products', 'printloom').'
';
}
echo '
';
echo ''.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).' ' : 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 '';
}