__('Free Photo', 'studiou-wc-free-photo-product'), 'target' => 'studiou_fpp_product_data', 'class' => array('show_if_variable'), 'priority' => 80, ); return $tabs; } public function add_product_data_panel() { global $post; $product_id = $post->ID; $enabled = get_post_meta($product_id, '_studiou_fpp_enabled', true); $media_category = get_post_meta($product_id, '_studiou_fpp_media_category', true); $max_file_size = get_post_meta($product_id, '_studiou_fpp_max_file_size', true); $max_uploads = get_post_meta($product_id, '_studiou_fpp_max_uploads', true); $upload_info_text = get_post_meta($product_id, '_studiou_fpp_upload_info_text', true); $min_width = get_post_meta($product_id, '_studiou_fpp_min_width', true); $min_height = get_post_meta($product_id, '_studiou_fpp_min_height', true); $max_width = get_post_meta($product_id, '_studiou_fpp_max_width', true); $max_height = get_post_meta($product_id, '_studiou_fpp_max_height', true); if (empty($max_file_size)) { $max_file_size = 50; } $categories = get_terms(array( 'taxonomy' => 'studiou_media_category', 'hide_empty' => false, )); if (is_wp_error($categories)) { $categories = array(); } ?>
500) $max_size = 500; update_post_meta($product_id, '_studiou_fpp_max_file_size', $max_size); } $max_uploads = isset($_POST['_studiou_fpp_max_uploads']) ? absint($_POST['_studiou_fpp_max_uploads']) : 0; update_post_meta($product_id, '_studiou_fpp_max_uploads', $max_uploads); if (isset($_POST['_studiou_fpp_upload_info_text'])) { update_post_meta($product_id, '_studiou_fpp_upload_info_text', sanitize_textarea_field($_POST['_studiou_fpp_upload_info_text'])); } // Resolution limits (0 or empty = no limit) $res_fields = array('_studiou_fpp_min_width', '_studiou_fpp_min_height', '_studiou_fpp_max_width', '_studiou_fpp_max_height'); foreach ($res_fields as $field) { $val = isset($_POST[$field]) ? absint($_POST[$field]) : 0; update_post_meta($product_id, $field, $val ?: ''); } } public function ajax_add_media_category() { check_ajax_referer('studiou-wcfpp-nonce', 'nonce'); if (!current_user_can('manage_woocommerce')) { wp_send_json_error(array('message' => __('Insufficient permissions.', 'studiou-wc-free-photo-product'))); return; } $name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : ''; if (empty($name)) { wp_send_json_error(array('message' => __('Category name is required.', 'studiou-wc-free-photo-product'))); return; } $term = wp_insert_term($name, 'studiou_media_category'); if (is_wp_error($term)) { wp_send_json_error(array('message' => $term->get_error_message())); return; } wp_send_json_success(array( 'term_id' => $term['term_id'], 'name' => $name, )); } public static function is_fpp_product($product_id) { return get_post_meta($product_id, '_studiou_fpp_enabled', true) === 'yes'; } public static function get_product_max_file_size($product_id) { $size = get_post_meta($product_id, '_studiou_fpp_max_file_size', true); return !empty($size) ? (int) $size : 50; } /** * Max simultaneous uploads per batch for this product. 0 = unlimited. */ public static function get_product_max_uploads($product_id) { $val = get_post_meta($product_id, '_studiou_fpp_max_uploads', true); return (int) $val; } public static function get_product_upload_info_text($product_id) { return get_post_meta($product_id, '_studiou_fpp_upload_info_text', true); } public static function get_product_media_category($product_id) { return (int) get_post_meta($product_id, '_studiou_fpp_media_category', true); } /** * Get resolution limits for a product. * Returns array with min_width, min_height, max_width, max_height (0 = no limit). */ public static function get_product_resolution_limits($product_id) { return array( 'min_width' => (int) get_post_meta($product_id, '_studiou_fpp_min_width', true), 'min_height' => (int) get_post_meta($product_id, '_studiou_fpp_min_height', true), 'max_width' => (int) get_post_meta($product_id, '_studiou_fpp_max_width', true), 'max_height' => (int) get_post_meta($product_id, '_studiou_fpp_max_height', true), ); } }