__( 'Artwork', 'proofkit' ), 'target' => 'proofkit_artwork_data', 'class' => [], 'priority' => 65, ]; return $tabs; } /** * Render the Artwork panel. */ public static function render_panel(): void { global $post; $product_id = $post instanceof \WP_Post ? (int) $post->ID : 0; $enabled = 'yes' === get_post_meta( $product_id, '_proofkit_enabled', true ); $required = 'yes' === get_post_meta( $product_id, '_proofkit_required', true ); $instructions = (string) get_post_meta( $product_id, '_proofkit_instructions', true ); $max_mb = (int) get_post_meta( $product_id, '_proofkit_max_mb', true ); $exts = (string) get_post_meta( $product_id, '_proofkit_exts', true ); $default_mb = (int) round( Settings::max_bytes() / 1048576 ); ?> 0 ) { update_post_meta( $post_id, '_proofkit_max_mb', $max_mb ); } else { delete_post_meta( $post_id, '_proofkit_max_mb' ); } $raw_exts = isset( $_POST['_proofkit_exts'] ) && is_string( $_POST['_proofkit_exts'] ) ? sanitize_text_field( wp_unslash( $_POST['_proofkit_exts'] ) ) : ''; $exts = self::normalize_extensions( $raw_exts ); if ( $exts ) { update_post_meta( $post_id, '_proofkit_exts', implode( ',', $exts ) ); } else { delete_post_meta( $post_id, '_proofkit_exts' ); } } /** * Whether artwork upload is enabled for a product. */ public static function is_enabled( int $product_id ): bool { return 'yes' === get_post_meta( $product_id, '_proofkit_enabled', true ); } /** * Whether artwork is required for a product. */ public static function is_required( int $product_id ): bool { return 'yes' === get_post_meta( $product_id, '_proofkit_required', true ); } /** * Customer-facing instructions for a product. */ public static function instructions( int $product_id ): string { return wp_kses_post( (string) get_post_meta( $product_id, '_proofkit_instructions', true ) ); } /** * Effective upload size limit for a product. */ public static function max_bytes( int $product_id ): int { $max_mb = min( 100, (int) get_post_meta( $product_id, '_proofkit_max_mb', true ) ); $global = Settings::max_bytes(); return $max_mb > 0 ? min( $max_mb * MB_IN_BYTES, $global ) : $global; } /** * Effective extension allow-list for a product. * * @return string[] */ public static function allowed_extensions( int $product_id ): array { $global = Settings::allowed_extensions(); $exts = self::normalize_extensions( (string) get_post_meta( $product_id, '_proofkit_exts', true ) ); if ( ! $exts ) { return $global; } // A product may narrow the site-wide allow-list, never widen it. $exts = array_values( array_intersect( $exts, $global ) ); return $exts ? $exts : $global; } /** * Clean a comma-separated extension list. * * @return string[] */ private static function normalize_extensions( string $raw ): array { $parts = preg_split( '/[\s,]+/', strtolower( $raw ), -1, PREG_SPLIT_NO_EMPTY ); if ( ! is_array( $parts ) ) { return []; } $exts = []; foreach ( $parts as $part ) { $ext = preg_replace( '/[^a-z0-9]/', '', $part ); if ( is_string( $ext ) && '' !== $ext ) { $exts[] = $ext; } } return array_values( array_unique( $exts ) ); } }