is_premium_active()) { return; } // Enqueue base JS for media library display add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_assets']); // Add display to media library add_filter('attachment_fields_to_edit', [$this, 'add_optimization_fields'], 10, 2); } /** * Enqueue admin assets for free version */ public function enqueue_admin_assets($hook) { // Only load on media pages $media_pages = ['upload.php', 'post.php', 'post-new.php', 'media-upload.php']; if (!in_array($hook, $media_pages) && strpos($hook, 'media') === false) { return; } // Use Assets_Manager for enqueue (single source of truth) \MasterAddons\Inc\Classes\Assets_Manager::enqueue('image-optimizer-base'); // Localize script with settings $pricing_url = 'https://master-addons.com/pricing/'; wp_localize_script('jltma-image-optimizer-base', 'jltmaImageOptimizerBase', [ 'isPremium' => false, 'pricingUrl' => $pricing_url, 'settings' => [], 'i18n' => [ /* translators: %d is the percentage of savings. */ 'savePercent' => __('Save ~%d%%', 'master-addons'), 'autoOptimize' => __('Auto-optimize images on upload', 'master-addons'), 'upgradeToPro' => __('Upgrade to Pro', 'master-addons'), ], ]); } /** * Check if premium is active */ protected function is_premium_active() { return function_exists('ma_el_fs') && ma_el_fs()->can_use_premium_code__premium_only(); } /** * Add optimization fields to attachment edit screen */ public function add_optimization_fields($form_fields, $post) { if (!wp_attachment_is_image($post->ID)) { return $form_fields; } // Skip on attachment edit page global $pagenow; if ($pagenow === 'post.php' && isset($_GET['action']) && $_GET['action'] === 'edit' && !wp_doing_ajax()) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only admin context detection, no data processed return $form_fields; } // Get file info for potential savings estimate $file_path = get_attached_file($post->ID); $file_size = $file_path && file_exists($file_path) ? filesize($file_path) : 0; // Estimate potential savings (~60-80% for WebP conversion) $savings_percent = wp_rand(65, 85); $potential_savings = $file_size > 0 ? round($file_size * ($savings_percent / 100)) : 0; $potential_size = $file_size - $potential_savings; // Build upsell card $html = '