Changeset 3465576
- Timestamp:
- 02/20/2026 08:37:05 AM (6 weeks ago)
- Location:
- ultimate-watermark
- Files:
-
- 10 edited
- 1 copied
-
assets/banner-772x250.png (modified) (previous)
-
assets/icon-128x128.png (modified) (previous)
-
tags/2.0.3 (copied) (copied from ultimate-watermark/trunk)
-
tags/2.0.3/readme.txt (modified) (3 diffs)
-
tags/2.0.3/src/Admin/MediaLibraryIntegration.php (modified) (13 diffs)
-
tags/2.0.3/src/Integration/RestApiIntegration.php (modified) (13 diffs)
-
tags/2.0.3/ultimate-watermark.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/src/Admin/MediaLibraryIntegration.php (modified) (13 diffs)
-
trunk/src/Integration/RestApiIntegration.php (modified) (13 diffs)
-
trunk/ultimate-watermark.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ultimate-watermark/tags/2.0.3/readme.txt
r3465508 r3465576 5 5 Requires at least: 5.0 6 6 Tested up to: 6.9 7 Stable tag: 2.0. 27 Stable tag: 2.0.3 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 30 30 * **[Get Support](https://wordpress.org/support/plugin/ultimate-watermark/)** - Free community support forum 31 31 * **[Feature Requests](https://mantrabrain.com/contact)** - Suggest new features and improvements 32 33 = 📺 Video Walkthrough = 34 35 Watch this quick video tutorial to see Ultimate Watermark in action and learn how to protect your images in minutes: 36 37 https://www.youtube.com/watch?v=6QcDWgtaJRU 32 38 33 39 = ⭐ Key Features (Free Version) = … … 362 368 == Changelog == 363 369 364 = 2.0. 2- 2026/02/20 =370 = 2.0.3- 2026/02/20 = 365 371 * **Fixed** - Duplication issue fixed 366 372 * **Fixed** - GD library issue fixed 373 * **Fixed** - Minor other issues 367 374 368 375 = 2.0 - 2026/02/19 = -
ultimate-watermark/tags/2.0.3/src/Admin/MediaLibraryIntegration.php
r3465062 r3465576 293 293 $image_sizes = get_intermediate_image_sizes(); 294 294 $image_sizes[] = 'full'; 295 296 // CRITICAL: Check if attachment has metadata with sizes 297 $attachment_metadata = wp_get_attachment_metadata($attachment_id); 298 $mime_type = get_post_mime_type($attachment_id); 295 299 296 300 // Extract watermark_rules for per-size evaluation … … 306 310 } 307 311 308 if (defined('WP_DEBUG') && WP_DEBUG) {309 error_log('Ultimate Watermark [Manual]: Attachment ' . $attachment_id . ', Watermark ' . $watermark_id);310 error_log('Ultimate Watermark [Manual]: has_rule_conditions=' . ($has_rule_conditions ? 'YES' : 'NO'));311 error_log('Ultimate Watermark [Manual]: Rules data: ' . print_r($rules, true));312 error_log('Ultimate Watermark [Manual]: Image sizes to process: ' . implode(', ', $image_sizes));313 }314 315 312 $success_count = 0; 313 $rules_skipped_sizes = []; // Track sizes skipped due to rule conditions 316 314 317 315 // Apply watermarks to each size, evaluating rules per-size … … 321 319 if (!$has_rule_conditions) { 322 320 if (!WatermarkHelper::shouldApplyWatermarkByImageSize($watermark_data, $size)) { 323 if (defined('WP_DEBUG') && WP_DEBUG) {324 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" SKIPPED by legacy shouldApplyWatermarkByImageSize');325 }326 321 continue; 327 322 } … … 333 328 $eval_context = RulesEvaluator::buildContext($attachment_id, $size, 0); 334 329 $rule_result = RulesEvaluator::evaluate($rules, $eval_context); 335 if (defined('WP_DEBUG') && WP_DEBUG) {336 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" rules evaluate=' . ($rule_result ? 'PASS' : 'FAIL') . ', context image_size=' . ($eval_context['image_size'] ?? 'N/A'));337 }338 330 if (!$rule_result) { 331 // Track that this size was skipped due to rule conditions 332 $rules_skipped_sizes[] = $size; 339 333 continue; // Rules don't match for this size 340 334 } … … 343 337 // All rules passed, apply watermark 344 338 $image_path = $this->getImagePathForSize($attachment_id, $size); 345 if (defined('WP_DEBUG') && WP_DEBUG) {346 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" path=' . ($image_path ?: 'NULL') . ', exists=' . ($image_path && file_exists($image_path) ? 'YES' : 'NO'));347 }348 339 if (!$image_path || !file_exists($image_path)) { 349 340 $result['skipped_sizes'][] = [ … … 380 371 ]; 381 372 } 382 if (defined('WP_DEBUG') && WP_DEBUG) {383 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" watermark apply=' . ($apply_success ? 'SUCCESS' : 'FAILED'));384 }385 373 } catch (\Exception $e) { 386 374 \MantraBrain\UltimateWatermark\Watermark\WatermarkService::setAttachmentContext([]); … … 394 382 ), 395 383 ]; 396 if (defined('WP_DEBUG') && WP_DEBUG) {397 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" EXCEPTION: ' . $e->getMessage());398 }399 384 } 400 385 } … … 411 396 ); 412 397 } else { 413 $result['message'] = __('Watermark was not applied to any size.', 'ultimate-watermark'); 398 // Provide specific reason why watermark wasn't applied 399 if (!empty($rules_skipped_sizes)) { 400 $result['message'] = sprintf( 401 /* translators: %s: comma-separated list of size names */ 402 __('Watermark was not applied to any size. The watermark rules did not match any of the available image sizes (%s). Please check your watermark rule conditions.', 'ultimate-watermark'), 403 implode(', ', $rules_skipped_sizes) 404 ); 405 } else { 406 $result['message'] = __('Watermark was not applied to any size.', 'ultimate-watermark'); 407 } 414 408 } 415 409 … … 1000 994 } 1001 995 window.ultimateWatermarkUpdateToggleState(); 996 997 // CRITICAL: Immediately update all plupload instances with new toggle state 998 // This ensures uploads that happen right after toggling use the correct state 999 if (window.ultimateWatermarkUploaders && window.ultimateWatermarkUploaders.length > 0) { 1000 window.ultimateWatermarkUploaders.forEach(function(up) { 1001 if (up && up.settings && typeof updateMultipartParamsForUploader === 'function') { 1002 updateMultipartParamsForUploader(up); 1003 } 1004 }); 1005 } 1002 1006 }); 1003 1007 … … 1106 1110 if (toggleState === '1') { 1107 1111 result['ultimate_watermark_auto_apply'] = '1'; 1108 }1109 try {1110 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids');1111 if (savedIds) {1112 const parsed = JSON.parse(savedIds);1113 if (Array.isArray(parsed) && parsed.length > 0) {1114 result['ultimate_watermark_ids'] = parsed.join(',');1112 try { 1113 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids'); 1114 if (savedIds) { 1115 const parsed = JSON.parse(savedIds); 1116 if (Array.isArray(parsed) && parsed.length > 0) { 1117 result['ultimate_watermark_ids'] = parsed.join(','); 1118 } 1115 1119 } 1120 } catch (e) { 1121 // Silent fail 1116 1122 } 1117 } catch (e) { 1118 // Silent fail 1123 } else { 1124 // CRITICAL: Delete the parameter when toggle is OFF 1125 delete result['ultimate_watermark_auto_apply']; 1126 delete result['ultimate_watermark_ids']; 1119 1127 } 1120 1128 } … … 1134 1142 if (toggleState === '1') { 1135 1143 obj['ultimate_watermark_auto_apply'] = '1'; 1136 }1137 try {1138 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids');1139 if (savedIds) {1140 const parsed = JSON.parse(savedIds);1141 if (Array.isArray(parsed) && parsed.length > 0) {1142 obj['ultimate_watermark_ids'] = parsed.join(',');1144 try { 1145 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids'); 1146 if (savedIds) { 1147 const parsed = JSON.parse(savedIds); 1148 if (Array.isArray(parsed) && parsed.length > 0) { 1149 obj['ultimate_watermark_ids'] = parsed.join(','); 1150 } 1143 1151 } 1152 } catch (e) { 1153 // Silent fail 1144 1154 } 1145 } catch (e) { 1146 // Silent fail 1155 } else { 1156 // CRITICAL: Delete the parameter when toggle is OFF 1157 delete obj['ultimate_watermark_auto_apply']; 1158 delete obj['ultimate_watermark_ids']; 1147 1159 } 1148 1160 } … … 1210 1222 } 1211 1223 1212 // Check if toggle is ON 1213 const $toggle = $('#ultimate-watermark-auto-apply:checked, #ultimate-watermark-auto-apply-popup:checked'); 1214 1215 if ($toggle.length) { 1224 // CRITICAL: Read toggle state from localStorage, NOT from checkbox DOM 1225 // This ensures we use the latest saved state even if checkbox was just changed 1226 const toggleState = localStorage.getItem('ultimate_watermark_toggle_state'); 1227 const isToggleEnabled = (toggleState === '1'); 1228 1229 if (isToggleEnabled) { 1216 1230 // Ensure multipart_params exists 1217 1231 if (!up.settings.multipart_params) { … … 1404 1418 $ids_string = isset($_POST['ids']) ? sanitize_text_field($_POST['ids']) : ''; 1405 1419 1406 // Always log for debugging1407 error_log('Ultimate Watermark: handleSetTempSelectedIds - Received IDs: [' . $ids_string . ']');1408 1409 1420 update_option('ultimate_watermark_temp_selected_ids', $ids_string, false); 1410 1421 1411 // Verify it was stored 1412 $stored = get_option('ultimate_watermark_temp_selected_ids', ''); 1413 error_log('Ultimate Watermark: handleSetTempSelectedIds - Stored and verified: [' . $stored . ']'); 1414 1415 wp_send_json_success(['message' => 'IDs stored temporarily', 'ids' => $ids_string, 'stored' => $stored]); 1422 wp_send_json_success(['message' => 'IDs stored temporarily', 'ids' => $ids_string]); 1416 1423 } 1417 1424 -
ultimate-watermark/tags/2.0.3/src/Integration/RestApiIntegration.php
r3465508 r3465576 91 91 $auto_apply_enabled = false; 92 92 93 // Check POST data first (this should be set by the upload form when toggle is ON) 94 if (isset($_POST['ultimate_watermark_auto_apply']) && $_POST['ultimate_watermark_auto_apply'] === '1') { 95 $auto_apply_enabled = true; 96 if (defined('WP_DEBUG') && WP_DEBUG) { 97 error_log('Ultimate Watermark: markForWatermarking - Found toggle in $_POST'); 98 } 99 } 100 // Check REQUEST for plupload multipart_params 101 elseif (isset($_REQUEST['ultimate_watermark_auto_apply']) && $_REQUEST['ultimate_watermark_auto_apply'] === '1') { 102 $auto_apply_enabled = true; 103 if (defined('WP_DEBUG') && WP_DEBUG) { 104 error_log('Ultimate Watermark: markForWatermarking - Found toggle in $_REQUEST'); 105 } 106 } 107 // Check WordPress option as fallback (set by JavaScript) 108 else { 93 // CRITICAL: Check if the parameter was sent in the request (even if '0') 94 // If parameter exists in POST/REQUEST, use that value (it's from plupload multipart_params) 95 // Only use WordPress option fallback if parameter is completely absent 96 $toggle_param_sent = isset($_POST['ultimate_watermark_auto_apply']) || isset($_REQUEST['ultimate_watermark_auto_apply']); 97 98 if ($toggle_param_sent) { 99 // Parameter was sent - use its value (could be '1' or '0' or anything else) 100 $toggle_value = isset($_POST['ultimate_watermark_auto_apply']) 101 ? $_POST['ultimate_watermark_auto_apply'] 102 : $_REQUEST['ultimate_watermark_auto_apply']; 103 104 if ($toggle_value === '1') { 105 $auto_apply_enabled = true; 106 } else { 107 // Parameter sent but not '1' - explicitly disabled 108 $auto_apply_enabled = false; 109 } 110 } else { 111 // Parameter not sent at all - use WordPress option fallback 112 // This handles uploads from other sources (not via media library toggle) 109 113 $option_value = get_option('ultimate_watermark_auto_apply_toggle', '0'); 110 114 if ($option_value === '1') { … … 150 154 if (isset($_POST['ultimate_watermark_ids'])) { 151 155 $ids_string = sanitize_text_field($_POST['ultimate_watermark_ids']); 152 if (defined('WP_DEBUG') && WP_DEBUG) {153 error_log('Ultimate Watermark: Found in $_POST[ultimate_watermark_ids]: ' . $ids_string);154 }155 156 } 156 157 // 2. Check $_REQUEST (broader scope) 157 158 elseif (isset($_REQUEST['ultimate_watermark_ids'])) { 158 159 $ids_string = sanitize_text_field($_REQUEST['ultimate_watermark_ids']); 159 if (defined('WP_DEBUG') && WP_DEBUG) {160 error_log('Ultimate Watermark: Found in $_REQUEST[ultimate_watermark_ids]: ' . $ids_string);161 }162 160 } 163 161 // 3. Check WordPress option (set by AJAX before upload) 164 162 elseif (get_option('ultimate_watermark_temp_selected_ids', '') !== '') { 165 163 $ids_string = sanitize_text_field(get_option('ultimate_watermark_temp_selected_ids', '')); 166 if (defined('WP_DEBUG') && WP_DEBUG) {167 error_log('Ultimate Watermark: Found in WordPress option: ' . $ids_string);168 }169 164 // Clear after reading (one-time use) 170 165 delete_option('ultimate_watermark_temp_selected_ids'); 171 166 } 172 // 4. Check raw input stream (for multipart/form-data)167 // 4. Check raw input as last resort 173 168 else { 174 169 $raw_input = file_get_contents('php://input'); 175 170 if (preg_match('/name="ultimate_watermark_ids"[^>]*>([^<]+)</i', $raw_input, $matches)) { 176 171 $ids_string = sanitize_text_field($matches[1]); 177 if (defined('WP_DEBUG') && WP_DEBUG) {178 error_log('Ultimate Watermark: Found in raw input via regex: ' . $ids_string);179 }180 172 } 181 173 // Also try parsing the entire raw input 182 elseif (preg_match('/ultimate_watermark_ids[\'" ]?\s*[:=]\s*[\'"]?([^\'"&,]+)/i', $raw_input, $matches)) {174 elseif (preg_match('/ultimate_watermark_ids[\'"\']?\s*[:=]\s*[\'"\']?([^\'"&,]+)/i', $raw_input, $matches)) { 183 175 $ids_string = sanitize_text_field($matches[1]); 184 if (defined('WP_DEBUG') && WP_DEBUG) {185 error_log('Ultimate Watermark: Found in raw input via pattern match: ' . $ids_string);186 }187 }188 else if (defined('WP_DEBUG') && WP_DEBUG) {189 error_log('Ultimate Watermark: ultimate_watermark_ids NOT FOUND in $_POST, $_REQUEST, option, or raw input');190 error_log('Ultimate Watermark: $_POST keys: ' . implode(', ', array_keys($_POST)));191 error_log('Ultimate Watermark: $_REQUEST keys: ' . implode(', ', array_keys($_REQUEST)));192 error_log('Ultimate Watermark: Raw input (first 1000 chars): ' . substr($raw_input, 0, 1000));193 176 } 194 177 } … … 197 180 if (!empty($ids_string) && trim($ids_string) !== '') { 198 181 $selected_watermark_ids = array_filter(array_map('absint', explode(',', trim($ids_string)))); 199 if (defined('WP_DEBUG') && WP_DEBUG) {200 error_log('Ultimate Watermark: Processed IDs from string: ' . print_r($selected_watermark_ids, true));201 }202 182 } else { 203 183 // If empty string, keep as empty array (user explicitly unchecked all) 204 184 $selected_watermark_ids = []; 205 if (defined('WP_DEBUG') && WP_DEBUG) {206 error_log('Ultimate Watermark: IDs string was empty or not set, using empty array');207 }208 }209 210 // Additional debug: check raw input211 if (defined('WP_DEBUG') && WP_DEBUG) {212 $raw_input = file_get_contents('php://input');213 if (strpos($raw_input, 'ultimate_watermark_ids') !== false) {214 error_log('Ultimate Watermark: Found ultimate_watermark_ids in raw input (partial): ' . substr($raw_input, 0, 500));215 } else {216 error_log('Ultimate Watermark: ultimate_watermark_ids NOT found in raw php://input');217 }218 185 } 219 186 220 187 // Store selected watermark IDs in attachment meta (even if empty, to track user intent) 221 188 // CRITICAL: Always store as array, never as string 222 if (defined('WP_DEBUG') && WP_DEBUG) {223 error_log('Ultimate Watermark: Storing to meta - IDs: ' . print_r($selected_watermark_ids, true));224 }225 189 update_post_meta($attachment_id, '_ulwm_selected_watermark_ids', $selected_watermark_ids); 226 227 // Verify it was stored correctly (debug only)228 if (defined('WP_DEBUG') && WP_DEBUG) {229 $stored = get_post_meta($attachment_id, '_ulwm_selected_watermark_ids', true);230 error_log('Ultimate Watermark: Verified stored meta value: ' . print_r($stored, true));231 error_log('Ultimate Watermark: Stored type: ' . gettype($stored));232 }233 190 234 191 // Mark this attachment for watermarking 235 192 update_post_meta($attachment_id, '_ulwm_watermarked', true); 236 237 // Debug logging238 if (defined('WP_DEBUG') && WP_DEBUG) {239 error_log('Ultimate Watermark: ========================================');240 error_log('Ultimate Watermark: markForWatermarking - Toggle enabled');241 error_log('Ultimate Watermark: Attachment ID: ' . $attachment_id);242 error_log('Ultimate Watermark: Selected watermark IDs: ' . print_r($selected_watermark_ids, true));243 error_log('Ultimate Watermark: POST[ultimate_watermark_auto_apply]: ' . ($_POST['ultimate_watermark_auto_apply'] ?? 'NOT SET'));244 error_log('Ultimate Watermark: POST[ultimate_watermark_ids]: ' . ($_POST['ultimate_watermark_ids'] ?? 'NOT SET'));245 error_log('Ultimate Watermark: REQUEST[ultimate_watermark_auto_apply]: ' . ($_REQUEST['ultimate_watermark_auto_apply'] ?? 'NOT SET'));246 error_log('Ultimate Watermark: REQUEST[ultimate_watermark_ids]: ' . ($_REQUEST['ultimate_watermark_ids'] ?? 'NOT SET'));247 error_log('Ultimate Watermark: ========================================');248 }249 193 250 194 // DO NOT reset the toggle here - it will be reset after watermark is applied … … 335 279 } 336 280 } 337 } else { 338 // No parent post (direct media library upload without toggle) 339 // Automatic watermarks with no restrictive rules should still apply 340 // Check if any automatic watermarks have watermark_on='everywhere' (or empty) 341 // and either no watermark_rules or rules that don't require a parent post context 342 $unrestricted_watermarks = array_filter($automatic_watermarks, function($watermark) { 343 $watermark_on = $watermark['watermark_on'] ?? 'everywhere'; 344 if ($watermark_on !== 'everywhere' && $watermark_on !== '') { 345 return false; // Has post type restrictions via legacy field 346 } 347 348 // Check if watermark_rules have any post_type conditions 349 // If they do, this watermark needs a parent post context and shouldn't apply here 350 $rules = $watermark['watermark_rules'] ?? []; 351 if (!empty($rules) && is_array($rules)) { 352 foreach ($rules as $rule) { 353 if (!empty($rule['conditions']) && is_array($rule['conditions'])) { 354 foreach ($rule['conditions'] as $condition) { 355 if (isset($condition['type']) && $condition['type'] === 'post_type') { 356 return false; // Has post_type condition, needs parent post 357 } 358 } 359 } 360 } 361 } 362 363 return true; // No post type restrictions, apply to all uploads 364 }); 365 366 if (!empty($unrestricted_watermarks)) { 367 $should_watermark_by_rules = true; 368 } 369 } 281 } 282 // REMOVED: No longer apply watermarks to direct media library uploads without toggle 283 // If user uploads to media library with toggle OFF, watermarks should NOT be applied 284 // Watermarks only apply when: 285 // 1. Toggle is ON (handled by $was_toggle_enabled) 286 // 2. Image uploaded via REST API to a page/post with matching rules (handled above) 370 287 } 371 288 } … … 399 316 400 317 } catch (\Exception $e) { 401 // Log error for debugging in production402 if (defined('WP_DEBUG') && WP_DEBUG) {403 error_log('Ultimate Watermark Error: ' . $e->getMessage());404 }405 318 // Restore original memory limit 406 319 ini_set('memory_limit', $original_memory_limit); … … 508 421 }); 509 422 510 // Debug logging511 if (defined('WP_DEBUG') && WP_DEBUG) {512 error_log('Ultimate Watermark: ========================================');513 error_log('Ultimate Watermark: applyWatermarksToGeneratedImages called');514 error_log('Ultimate Watermark: Attachment ID: ' . $attachment_id);515 error_log('Ultimate Watermark: use_toggle_rules = ' . ($use_toggle_rules ? 'true' : 'false'));516 error_log('Ultimate Watermark: Raw meta value: ' . print_r(get_post_meta($attachment_id, '_ulwm_selected_watermark_ids', true), true));517 error_log('Ultimate Watermark: Processed selected watermark IDs: ' . print_r($selected_watermark_ids, true));518 error_log('Ultimate Watermark: Is array: ' . (is_array($selected_watermark_ids) ? 'YES' : 'NO'));519 error_log('Ultimate Watermark: Count: ' . (is_array($selected_watermark_ids) ? count($selected_watermark_ids) : 'N/A'));520 error_log('Ultimate Watermark: Empty check: ' . (empty($selected_watermark_ids) ? 'YES (EMPTY!)' : 'NO'));521 error_log('Ultimate Watermark: ========================================');522 }523 423 524 424 // Get parent post ID for rule checking (for REST API uploads from page/post editor) … … 559 459 $selected_ids_int = array_map('intval', $selected_watermark_ids); 560 460 561 // Debug logging562 if (defined('WP_DEBUG') && WP_DEBUG) {563 error_log('Ultimate Watermark: Filtering watermarks for size ' . $size);564 error_log('Ultimate Watermark: Selected IDs (int): ' . print_r($selected_ids_int, true));565 error_log('Ultimate Watermark: Total automatic watermarks before filter: ' . count($automatic_watermarks));566 }567 461 568 462 $automatic_watermarks = array_filter($automatic_watermarks, function($watermark) use ($selected_ids_int) { … … 570 464 $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0); 571 465 572 // Log all watermark data for debugging573 if (defined('WP_DEBUG') && WP_DEBUG) {574 error_log('Ultimate Watermark: Watermark data - ID field: ' . print_r(['id' => $watermark['id'] ?? 'NOT SET', 'ID' => $watermark['ID'] ?? 'NOT SET', 'name' => $watermark['name'] ?? 'UNKNOWN'], true));575 }576 577 466 // Only apply if this watermark ID is in the selected list 578 $matches = in_array($watermark_id, $selected_ids_int, true); 579 580 if (defined('WP_DEBUG') && WP_DEBUG) { 581 error_log('Ultimate Watermark: Checking watermark ID ' . $watermark_id . ' against selected [' . implode(',', $selected_ids_int) . '] - Matches: ' . ($matches ? 'YES' : 'NO')); 582 } 583 584 return $matches; 467 return in_array($watermark_id, $selected_ids_int, true); 585 468 }); 586 469 587 if (defined('WP_DEBUG') && WP_DEBUG) {588 error_log('Ultimate Watermark: Watermarks after ID filter: ' . count($automatic_watermarks));589 }590 470 591 471 // Filter by legacy size rules ONLY if no unified rules exist … … 611 491 } 612 492 613 // CRITICAL: Use 'id' (lowercase) - that's what WatermarkHelper returns614 if (defined('WP_DEBUG') && WP_DEBUG) {615 $wm_id = isset($watermark['id']) ? $watermark['id'] : (isset($watermark['ID']) ? $watermark['ID'] : 'unknown');616 error_log('Ultimate Watermark: Watermark ID ' . $wm_id . ' for size ' . $size . ' - Passes size rule: ' . ($passes_size ? 'YES' : 'NO') . ($has_unified_conditions ? ' (unified rules)' : ' (legacy)'));617 }618 493 return $passes_size; 619 494 }); 620 495 621 if (defined('WP_DEBUG') && WP_DEBUG) {622 error_log('Ultimate Watermark: Watermarks after size filter: ' . count($size_filtered));623 }624 496 $automatic_watermarks = $size_filtered; 625 497 } else { … … 737 609 738 610 if (empty($automatic_watermarks)) { 739 if (defined('WP_DEBUG') && WP_DEBUG) {740 error_log('Ultimate Watermark: No watermarks to apply for size ' . $size . ' (skipping)');741 }742 611 continue; // No watermarks for this size, skip 743 }744 745 if (defined('WP_DEBUG') && WP_DEBUG) {746 error_log('Ultimate Watermark: Applying ' . count($automatic_watermarks) . ' watermark(s) to size ' . $size);747 foreach ($automatic_watermarks as $watermark) {748 // CRITICAL: WatermarkHelper returns 'id' (lowercase), check that first749 $wm_id = isset($watermark['id']) ? $watermark['id'] : (isset($watermark['ID']) ? $watermark['ID'] : 'unknown');750 error_log('Ultimate Watermark: - About to apply watermark ID: ' . $wm_id . ' (Name: ' . ($watermark['name'] ?? 'unknown') . ')');751 }752 612 } 753 613 … … 767 627 $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0); 768 628 769 error_log('Ultimate Watermark: applyWatermarkToAttachmentSize called - Watermark data keys: ' . implode(', ', array_keys($watermark)));770 error_log('Ultimate Watermark: Extracted watermark ID: ' . $watermark_id);771 772 629 if (!$watermark_id) { 773 error_log('Ultimate Watermark: ERROR - No watermark ID found! Watermark data: ' . print_r($watermark, true));774 630 return; 775 }776 777 if (defined('WP_DEBUG') && WP_DEBUG) {778 error_log('Ultimate Watermark: About to get image path for attachment ' . $attachment_id . ', size: ' . $size);779 631 } 780 632 781 633 // Get the image path for the specific size 782 634 $image_path = $this->getImagePathForSize($attachment_id, $size); 783 784 if (defined('WP_DEBUG') && WP_DEBUG) {785 error_log('Ultimate Watermark: getImagePathForSize returned: ' . ($image_path ?: 'NULL'));786 error_log('Ultimate Watermark: File exists check: ' . ($image_path && file_exists($image_path) ? 'YES' : 'NO'));787 }788 635 789 636 if (!$image_path || !file_exists($image_path)) { … … 815 662 // Apply watermark using WatermarkService 816 663 try { 817 error_log('Ultimate Watermark: applyWatermarkToAttachmentSize - Attachment: ' . $attachment_id . ', Watermark ID: ' . $watermark_id . ', Size: ' . $size);818 error_log('Ultimate Watermark: Image path: ' . $image_path);819 error_log('Ultimate Watermark: File exists: ' . (file_exists($image_path) ? 'YES' : 'NO'));820 error_log('Ultimate Watermark: File writable: ' . (file_exists($image_path) && is_writable($image_path) ? 'YES' : 'NO'));821 664 822 665 // Set attachment context for Pro plugin placeholder resolution … … 852 695 // Track watermark usage for this specific size (count once) 853 696 \MantraBrain\UltimateWatermark\Utils\WatermarkUsageTracker::incrementUsage($watermark_id, $attachment_id, $size); 854 } else {855 if (defined('WP_DEBUG') && WP_DEBUG) {856 error_log('Ultimate Watermark: applyWatermarkById returned FALSE for watermark ID ' . $watermark_id);857 }858 697 } 859 698 } catch (\Exception $e) { 860 // Log error for debugging 861 if (defined('WP_DEBUG') && WP_DEBUG) { 862 error_log('Ultimate Watermark: Exception in applyWatermarkToAttachmentSize - ' . $e->getMessage()); 863 error_log('Ultimate Watermark: Stack trace: ' . $e->getTraceAsString()); 864 } 699 // Silently handle exceptions 865 700 } 866 701 } -
ultimate-watermark/tags/2.0.3/ultimate-watermark.php
r3465508 r3465576 4 4 * Plugin URI: https://mantrabrain.com/ultimate-watermark 5 5 * Description: Advanced WordPress Image Watermarking Plugin 6 * Version: 2.0. 26 * Version: 2.0.3 7 7 * Author: MantraBrain 8 8 * Author URI: https://mantrabrain.com … … 18 18 * @package UltimateWatermark 19 19 * @author MantraBrain 20 * @version 2.0. 220 * @version 2.0.3 21 21 */ 22 22 … … 36 36 37 37 // Define plugin constants 38 define('ULTIMATE_WATERMARK_VERSION', '2.0. 2');38 define('ULTIMATE_WATERMARK_VERSION', '2.0.3'); 39 39 define('ULTIMATE_WATERMARK_FILE', __FILE__); 40 40 define('ULTIMATE_WATERMARK_DIR', plugin_dir_path(__FILE__)); -
ultimate-watermark/trunk/readme.txt
r3465508 r3465576 5 5 Requires at least: 5.0 6 6 Tested up to: 6.9 7 Stable tag: 2.0. 27 Stable tag: 2.0.3 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 30 30 * **[Get Support](https://wordpress.org/support/plugin/ultimate-watermark/)** - Free community support forum 31 31 * **[Feature Requests](https://mantrabrain.com/contact)** - Suggest new features and improvements 32 33 = 📺 Video Walkthrough = 34 35 Watch this quick video tutorial to see Ultimate Watermark in action and learn how to protect your images in minutes: 36 37 https://www.youtube.com/watch?v=6QcDWgtaJRU 32 38 33 39 = ⭐ Key Features (Free Version) = … … 362 368 == Changelog == 363 369 364 = 2.0. 2- 2026/02/20 =370 = 2.0.3- 2026/02/20 = 365 371 * **Fixed** - Duplication issue fixed 366 372 * **Fixed** - GD library issue fixed 373 * **Fixed** - Minor other issues 367 374 368 375 = 2.0 - 2026/02/19 = -
ultimate-watermark/trunk/src/Admin/MediaLibraryIntegration.php
r3465062 r3465576 293 293 $image_sizes = get_intermediate_image_sizes(); 294 294 $image_sizes[] = 'full'; 295 296 // CRITICAL: Check if attachment has metadata with sizes 297 $attachment_metadata = wp_get_attachment_metadata($attachment_id); 298 $mime_type = get_post_mime_type($attachment_id); 295 299 296 300 // Extract watermark_rules for per-size evaluation … … 306 310 } 307 311 308 if (defined('WP_DEBUG') && WP_DEBUG) {309 error_log('Ultimate Watermark [Manual]: Attachment ' . $attachment_id . ', Watermark ' . $watermark_id);310 error_log('Ultimate Watermark [Manual]: has_rule_conditions=' . ($has_rule_conditions ? 'YES' : 'NO'));311 error_log('Ultimate Watermark [Manual]: Rules data: ' . print_r($rules, true));312 error_log('Ultimate Watermark [Manual]: Image sizes to process: ' . implode(', ', $image_sizes));313 }314 315 312 $success_count = 0; 313 $rules_skipped_sizes = []; // Track sizes skipped due to rule conditions 316 314 317 315 // Apply watermarks to each size, evaluating rules per-size … … 321 319 if (!$has_rule_conditions) { 322 320 if (!WatermarkHelper::shouldApplyWatermarkByImageSize($watermark_data, $size)) { 323 if (defined('WP_DEBUG') && WP_DEBUG) {324 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" SKIPPED by legacy shouldApplyWatermarkByImageSize');325 }326 321 continue; 327 322 } … … 333 328 $eval_context = RulesEvaluator::buildContext($attachment_id, $size, 0); 334 329 $rule_result = RulesEvaluator::evaluate($rules, $eval_context); 335 if (defined('WP_DEBUG') && WP_DEBUG) {336 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" rules evaluate=' . ($rule_result ? 'PASS' : 'FAIL') . ', context image_size=' . ($eval_context['image_size'] ?? 'N/A'));337 }338 330 if (!$rule_result) { 331 // Track that this size was skipped due to rule conditions 332 $rules_skipped_sizes[] = $size; 339 333 continue; // Rules don't match for this size 340 334 } … … 343 337 // All rules passed, apply watermark 344 338 $image_path = $this->getImagePathForSize($attachment_id, $size); 345 if (defined('WP_DEBUG') && WP_DEBUG) {346 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" path=' . ($image_path ?: 'NULL') . ', exists=' . ($image_path && file_exists($image_path) ? 'YES' : 'NO'));347 }348 339 if (!$image_path || !file_exists($image_path)) { 349 340 $result['skipped_sizes'][] = [ … … 380 371 ]; 381 372 } 382 if (defined('WP_DEBUG') && WP_DEBUG) {383 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" watermark apply=' . ($apply_success ? 'SUCCESS' : 'FAILED'));384 }385 373 } catch (\Exception $e) { 386 374 \MantraBrain\UltimateWatermark\Watermark\WatermarkService::setAttachmentContext([]); … … 394 382 ), 395 383 ]; 396 if (defined('WP_DEBUG') && WP_DEBUG) {397 error_log('Ultimate Watermark [Manual]: Size "' . $size . '" EXCEPTION: ' . $e->getMessage());398 }399 384 } 400 385 } … … 411 396 ); 412 397 } else { 413 $result['message'] = __('Watermark was not applied to any size.', 'ultimate-watermark'); 398 // Provide specific reason why watermark wasn't applied 399 if (!empty($rules_skipped_sizes)) { 400 $result['message'] = sprintf( 401 /* translators: %s: comma-separated list of size names */ 402 __('Watermark was not applied to any size. The watermark rules did not match any of the available image sizes (%s). Please check your watermark rule conditions.', 'ultimate-watermark'), 403 implode(', ', $rules_skipped_sizes) 404 ); 405 } else { 406 $result['message'] = __('Watermark was not applied to any size.', 'ultimate-watermark'); 407 } 414 408 } 415 409 … … 1000 994 } 1001 995 window.ultimateWatermarkUpdateToggleState(); 996 997 // CRITICAL: Immediately update all plupload instances with new toggle state 998 // This ensures uploads that happen right after toggling use the correct state 999 if (window.ultimateWatermarkUploaders && window.ultimateWatermarkUploaders.length > 0) { 1000 window.ultimateWatermarkUploaders.forEach(function(up) { 1001 if (up && up.settings && typeof updateMultipartParamsForUploader === 'function') { 1002 updateMultipartParamsForUploader(up); 1003 } 1004 }); 1005 } 1002 1006 }); 1003 1007 … … 1106 1110 if (toggleState === '1') { 1107 1111 result['ultimate_watermark_auto_apply'] = '1'; 1108 }1109 try {1110 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids');1111 if (savedIds) {1112 const parsed = JSON.parse(savedIds);1113 if (Array.isArray(parsed) && parsed.length > 0) {1114 result['ultimate_watermark_ids'] = parsed.join(',');1112 try { 1113 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids'); 1114 if (savedIds) { 1115 const parsed = JSON.parse(savedIds); 1116 if (Array.isArray(parsed) && parsed.length > 0) { 1117 result['ultimate_watermark_ids'] = parsed.join(','); 1118 } 1115 1119 } 1120 } catch (e) { 1121 // Silent fail 1116 1122 } 1117 } catch (e) { 1118 // Silent fail 1123 } else { 1124 // CRITICAL: Delete the parameter when toggle is OFF 1125 delete result['ultimate_watermark_auto_apply']; 1126 delete result['ultimate_watermark_ids']; 1119 1127 } 1120 1128 } … … 1134 1142 if (toggleState === '1') { 1135 1143 obj['ultimate_watermark_auto_apply'] = '1'; 1136 }1137 try {1138 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids');1139 if (savedIds) {1140 const parsed = JSON.parse(savedIds);1141 if (Array.isArray(parsed) && parsed.length > 0) {1142 obj['ultimate_watermark_ids'] = parsed.join(',');1144 try { 1145 const savedIds = localStorage.getItem('ultimate_watermark_selected_ids'); 1146 if (savedIds) { 1147 const parsed = JSON.parse(savedIds); 1148 if (Array.isArray(parsed) && parsed.length > 0) { 1149 obj['ultimate_watermark_ids'] = parsed.join(','); 1150 } 1143 1151 } 1152 } catch (e) { 1153 // Silent fail 1144 1154 } 1145 } catch (e) { 1146 // Silent fail 1155 } else { 1156 // CRITICAL: Delete the parameter when toggle is OFF 1157 delete obj['ultimate_watermark_auto_apply']; 1158 delete obj['ultimate_watermark_ids']; 1147 1159 } 1148 1160 } … … 1210 1222 } 1211 1223 1212 // Check if toggle is ON 1213 const $toggle = $('#ultimate-watermark-auto-apply:checked, #ultimate-watermark-auto-apply-popup:checked'); 1214 1215 if ($toggle.length) { 1224 // CRITICAL: Read toggle state from localStorage, NOT from checkbox DOM 1225 // This ensures we use the latest saved state even if checkbox was just changed 1226 const toggleState = localStorage.getItem('ultimate_watermark_toggle_state'); 1227 const isToggleEnabled = (toggleState === '1'); 1228 1229 if (isToggleEnabled) { 1216 1230 // Ensure multipart_params exists 1217 1231 if (!up.settings.multipart_params) { … … 1404 1418 $ids_string = isset($_POST['ids']) ? sanitize_text_field($_POST['ids']) : ''; 1405 1419 1406 // Always log for debugging1407 error_log('Ultimate Watermark: handleSetTempSelectedIds - Received IDs: [' . $ids_string . ']');1408 1409 1420 update_option('ultimate_watermark_temp_selected_ids', $ids_string, false); 1410 1421 1411 // Verify it was stored 1412 $stored = get_option('ultimate_watermark_temp_selected_ids', ''); 1413 error_log('Ultimate Watermark: handleSetTempSelectedIds - Stored and verified: [' . $stored . ']'); 1414 1415 wp_send_json_success(['message' => 'IDs stored temporarily', 'ids' => $ids_string, 'stored' => $stored]); 1422 wp_send_json_success(['message' => 'IDs stored temporarily', 'ids' => $ids_string]); 1416 1423 } 1417 1424 -
ultimate-watermark/trunk/src/Integration/RestApiIntegration.php
r3465508 r3465576 91 91 $auto_apply_enabled = false; 92 92 93 // Check POST data first (this should be set by the upload form when toggle is ON) 94 if (isset($_POST['ultimate_watermark_auto_apply']) && $_POST['ultimate_watermark_auto_apply'] === '1') { 95 $auto_apply_enabled = true; 96 if (defined('WP_DEBUG') && WP_DEBUG) { 97 error_log('Ultimate Watermark: markForWatermarking - Found toggle in $_POST'); 98 } 99 } 100 // Check REQUEST for plupload multipart_params 101 elseif (isset($_REQUEST['ultimate_watermark_auto_apply']) && $_REQUEST['ultimate_watermark_auto_apply'] === '1') { 102 $auto_apply_enabled = true; 103 if (defined('WP_DEBUG') && WP_DEBUG) { 104 error_log('Ultimate Watermark: markForWatermarking - Found toggle in $_REQUEST'); 105 } 106 } 107 // Check WordPress option as fallback (set by JavaScript) 108 else { 93 // CRITICAL: Check if the parameter was sent in the request (even if '0') 94 // If parameter exists in POST/REQUEST, use that value (it's from plupload multipart_params) 95 // Only use WordPress option fallback if parameter is completely absent 96 $toggle_param_sent = isset($_POST['ultimate_watermark_auto_apply']) || isset($_REQUEST['ultimate_watermark_auto_apply']); 97 98 if ($toggle_param_sent) { 99 // Parameter was sent - use its value (could be '1' or '0' or anything else) 100 $toggle_value = isset($_POST['ultimate_watermark_auto_apply']) 101 ? $_POST['ultimate_watermark_auto_apply'] 102 : $_REQUEST['ultimate_watermark_auto_apply']; 103 104 if ($toggle_value === '1') { 105 $auto_apply_enabled = true; 106 } else { 107 // Parameter sent but not '1' - explicitly disabled 108 $auto_apply_enabled = false; 109 } 110 } else { 111 // Parameter not sent at all - use WordPress option fallback 112 // This handles uploads from other sources (not via media library toggle) 109 113 $option_value = get_option('ultimate_watermark_auto_apply_toggle', '0'); 110 114 if ($option_value === '1') { … … 150 154 if (isset($_POST['ultimate_watermark_ids'])) { 151 155 $ids_string = sanitize_text_field($_POST['ultimate_watermark_ids']); 152 if (defined('WP_DEBUG') && WP_DEBUG) {153 error_log('Ultimate Watermark: Found in $_POST[ultimate_watermark_ids]: ' . $ids_string);154 }155 156 } 156 157 // 2. Check $_REQUEST (broader scope) 157 158 elseif (isset($_REQUEST['ultimate_watermark_ids'])) { 158 159 $ids_string = sanitize_text_field($_REQUEST['ultimate_watermark_ids']); 159 if (defined('WP_DEBUG') && WP_DEBUG) {160 error_log('Ultimate Watermark: Found in $_REQUEST[ultimate_watermark_ids]: ' . $ids_string);161 }162 160 } 163 161 // 3. Check WordPress option (set by AJAX before upload) 164 162 elseif (get_option('ultimate_watermark_temp_selected_ids', '') !== '') { 165 163 $ids_string = sanitize_text_field(get_option('ultimate_watermark_temp_selected_ids', '')); 166 if (defined('WP_DEBUG') && WP_DEBUG) {167 error_log('Ultimate Watermark: Found in WordPress option: ' . $ids_string);168 }169 164 // Clear after reading (one-time use) 170 165 delete_option('ultimate_watermark_temp_selected_ids'); 171 166 } 172 // 4. Check raw input stream (for multipart/form-data)167 // 4. Check raw input as last resort 173 168 else { 174 169 $raw_input = file_get_contents('php://input'); 175 170 if (preg_match('/name="ultimate_watermark_ids"[^>]*>([^<]+)</i', $raw_input, $matches)) { 176 171 $ids_string = sanitize_text_field($matches[1]); 177 if (defined('WP_DEBUG') && WP_DEBUG) {178 error_log('Ultimate Watermark: Found in raw input via regex: ' . $ids_string);179 }180 172 } 181 173 // Also try parsing the entire raw input 182 elseif (preg_match('/ultimate_watermark_ids[\'" ]?\s*[:=]\s*[\'"]?([^\'"&,]+)/i', $raw_input, $matches)) {174 elseif (preg_match('/ultimate_watermark_ids[\'"\']?\s*[:=]\s*[\'"\']?([^\'"&,]+)/i', $raw_input, $matches)) { 183 175 $ids_string = sanitize_text_field($matches[1]); 184 if (defined('WP_DEBUG') && WP_DEBUG) {185 error_log('Ultimate Watermark: Found in raw input via pattern match: ' . $ids_string);186 }187 }188 else if (defined('WP_DEBUG') && WP_DEBUG) {189 error_log('Ultimate Watermark: ultimate_watermark_ids NOT FOUND in $_POST, $_REQUEST, option, or raw input');190 error_log('Ultimate Watermark: $_POST keys: ' . implode(', ', array_keys($_POST)));191 error_log('Ultimate Watermark: $_REQUEST keys: ' . implode(', ', array_keys($_REQUEST)));192 error_log('Ultimate Watermark: Raw input (first 1000 chars): ' . substr($raw_input, 0, 1000));193 176 } 194 177 } … … 197 180 if (!empty($ids_string) && trim($ids_string) !== '') { 198 181 $selected_watermark_ids = array_filter(array_map('absint', explode(',', trim($ids_string)))); 199 if (defined('WP_DEBUG') && WP_DEBUG) {200 error_log('Ultimate Watermark: Processed IDs from string: ' . print_r($selected_watermark_ids, true));201 }202 182 } else { 203 183 // If empty string, keep as empty array (user explicitly unchecked all) 204 184 $selected_watermark_ids = []; 205 if (defined('WP_DEBUG') && WP_DEBUG) {206 error_log('Ultimate Watermark: IDs string was empty or not set, using empty array');207 }208 }209 210 // Additional debug: check raw input211 if (defined('WP_DEBUG') && WP_DEBUG) {212 $raw_input = file_get_contents('php://input');213 if (strpos($raw_input, 'ultimate_watermark_ids') !== false) {214 error_log('Ultimate Watermark: Found ultimate_watermark_ids in raw input (partial): ' . substr($raw_input, 0, 500));215 } else {216 error_log('Ultimate Watermark: ultimate_watermark_ids NOT found in raw php://input');217 }218 185 } 219 186 220 187 // Store selected watermark IDs in attachment meta (even if empty, to track user intent) 221 188 // CRITICAL: Always store as array, never as string 222 if (defined('WP_DEBUG') && WP_DEBUG) {223 error_log('Ultimate Watermark: Storing to meta - IDs: ' . print_r($selected_watermark_ids, true));224 }225 189 update_post_meta($attachment_id, '_ulwm_selected_watermark_ids', $selected_watermark_ids); 226 227 // Verify it was stored correctly (debug only)228 if (defined('WP_DEBUG') && WP_DEBUG) {229 $stored = get_post_meta($attachment_id, '_ulwm_selected_watermark_ids', true);230 error_log('Ultimate Watermark: Verified stored meta value: ' . print_r($stored, true));231 error_log('Ultimate Watermark: Stored type: ' . gettype($stored));232 }233 190 234 191 // Mark this attachment for watermarking 235 192 update_post_meta($attachment_id, '_ulwm_watermarked', true); 236 237 // Debug logging238 if (defined('WP_DEBUG') && WP_DEBUG) {239 error_log('Ultimate Watermark: ========================================');240 error_log('Ultimate Watermark: markForWatermarking - Toggle enabled');241 error_log('Ultimate Watermark: Attachment ID: ' . $attachment_id);242 error_log('Ultimate Watermark: Selected watermark IDs: ' . print_r($selected_watermark_ids, true));243 error_log('Ultimate Watermark: POST[ultimate_watermark_auto_apply]: ' . ($_POST['ultimate_watermark_auto_apply'] ?? 'NOT SET'));244 error_log('Ultimate Watermark: POST[ultimate_watermark_ids]: ' . ($_POST['ultimate_watermark_ids'] ?? 'NOT SET'));245 error_log('Ultimate Watermark: REQUEST[ultimate_watermark_auto_apply]: ' . ($_REQUEST['ultimate_watermark_auto_apply'] ?? 'NOT SET'));246 error_log('Ultimate Watermark: REQUEST[ultimate_watermark_ids]: ' . ($_REQUEST['ultimate_watermark_ids'] ?? 'NOT SET'));247 error_log('Ultimate Watermark: ========================================');248 }249 193 250 194 // DO NOT reset the toggle here - it will be reset after watermark is applied … … 335 279 } 336 280 } 337 } else { 338 // No parent post (direct media library upload without toggle) 339 // Automatic watermarks with no restrictive rules should still apply 340 // Check if any automatic watermarks have watermark_on='everywhere' (or empty) 341 // and either no watermark_rules or rules that don't require a parent post context 342 $unrestricted_watermarks = array_filter($automatic_watermarks, function($watermark) { 343 $watermark_on = $watermark['watermark_on'] ?? 'everywhere'; 344 if ($watermark_on !== 'everywhere' && $watermark_on !== '') { 345 return false; // Has post type restrictions via legacy field 346 } 347 348 // Check if watermark_rules have any post_type conditions 349 // If they do, this watermark needs a parent post context and shouldn't apply here 350 $rules = $watermark['watermark_rules'] ?? []; 351 if (!empty($rules) && is_array($rules)) { 352 foreach ($rules as $rule) { 353 if (!empty($rule['conditions']) && is_array($rule['conditions'])) { 354 foreach ($rule['conditions'] as $condition) { 355 if (isset($condition['type']) && $condition['type'] === 'post_type') { 356 return false; // Has post_type condition, needs parent post 357 } 358 } 359 } 360 } 361 } 362 363 return true; // No post type restrictions, apply to all uploads 364 }); 365 366 if (!empty($unrestricted_watermarks)) { 367 $should_watermark_by_rules = true; 368 } 369 } 281 } 282 // REMOVED: No longer apply watermarks to direct media library uploads without toggle 283 // If user uploads to media library with toggle OFF, watermarks should NOT be applied 284 // Watermarks only apply when: 285 // 1. Toggle is ON (handled by $was_toggle_enabled) 286 // 2. Image uploaded via REST API to a page/post with matching rules (handled above) 370 287 } 371 288 } … … 399 316 400 317 } catch (\Exception $e) { 401 // Log error for debugging in production402 if (defined('WP_DEBUG') && WP_DEBUG) {403 error_log('Ultimate Watermark Error: ' . $e->getMessage());404 }405 318 // Restore original memory limit 406 319 ini_set('memory_limit', $original_memory_limit); … … 508 421 }); 509 422 510 // Debug logging511 if (defined('WP_DEBUG') && WP_DEBUG) {512 error_log('Ultimate Watermark: ========================================');513 error_log('Ultimate Watermark: applyWatermarksToGeneratedImages called');514 error_log('Ultimate Watermark: Attachment ID: ' . $attachment_id);515 error_log('Ultimate Watermark: use_toggle_rules = ' . ($use_toggle_rules ? 'true' : 'false'));516 error_log('Ultimate Watermark: Raw meta value: ' . print_r(get_post_meta($attachment_id, '_ulwm_selected_watermark_ids', true), true));517 error_log('Ultimate Watermark: Processed selected watermark IDs: ' . print_r($selected_watermark_ids, true));518 error_log('Ultimate Watermark: Is array: ' . (is_array($selected_watermark_ids) ? 'YES' : 'NO'));519 error_log('Ultimate Watermark: Count: ' . (is_array($selected_watermark_ids) ? count($selected_watermark_ids) : 'N/A'));520 error_log('Ultimate Watermark: Empty check: ' . (empty($selected_watermark_ids) ? 'YES (EMPTY!)' : 'NO'));521 error_log('Ultimate Watermark: ========================================');522 }523 423 524 424 // Get parent post ID for rule checking (for REST API uploads from page/post editor) … … 559 459 $selected_ids_int = array_map('intval', $selected_watermark_ids); 560 460 561 // Debug logging562 if (defined('WP_DEBUG') && WP_DEBUG) {563 error_log('Ultimate Watermark: Filtering watermarks for size ' . $size);564 error_log('Ultimate Watermark: Selected IDs (int): ' . print_r($selected_ids_int, true));565 error_log('Ultimate Watermark: Total automatic watermarks before filter: ' . count($automatic_watermarks));566 }567 461 568 462 $automatic_watermarks = array_filter($automatic_watermarks, function($watermark) use ($selected_ids_int) { … … 570 464 $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0); 571 465 572 // Log all watermark data for debugging573 if (defined('WP_DEBUG') && WP_DEBUG) {574 error_log('Ultimate Watermark: Watermark data - ID field: ' . print_r(['id' => $watermark['id'] ?? 'NOT SET', 'ID' => $watermark['ID'] ?? 'NOT SET', 'name' => $watermark['name'] ?? 'UNKNOWN'], true));575 }576 577 466 // Only apply if this watermark ID is in the selected list 578 $matches = in_array($watermark_id, $selected_ids_int, true); 579 580 if (defined('WP_DEBUG') && WP_DEBUG) { 581 error_log('Ultimate Watermark: Checking watermark ID ' . $watermark_id . ' against selected [' . implode(',', $selected_ids_int) . '] - Matches: ' . ($matches ? 'YES' : 'NO')); 582 } 583 584 return $matches; 467 return in_array($watermark_id, $selected_ids_int, true); 585 468 }); 586 469 587 if (defined('WP_DEBUG') && WP_DEBUG) {588 error_log('Ultimate Watermark: Watermarks after ID filter: ' . count($automatic_watermarks));589 }590 470 591 471 // Filter by legacy size rules ONLY if no unified rules exist … … 611 491 } 612 492 613 // CRITICAL: Use 'id' (lowercase) - that's what WatermarkHelper returns614 if (defined('WP_DEBUG') && WP_DEBUG) {615 $wm_id = isset($watermark['id']) ? $watermark['id'] : (isset($watermark['ID']) ? $watermark['ID'] : 'unknown');616 error_log('Ultimate Watermark: Watermark ID ' . $wm_id . ' for size ' . $size . ' - Passes size rule: ' . ($passes_size ? 'YES' : 'NO') . ($has_unified_conditions ? ' (unified rules)' : ' (legacy)'));617 }618 493 return $passes_size; 619 494 }); 620 495 621 if (defined('WP_DEBUG') && WP_DEBUG) {622 error_log('Ultimate Watermark: Watermarks after size filter: ' . count($size_filtered));623 }624 496 $automatic_watermarks = $size_filtered; 625 497 } else { … … 737 609 738 610 if (empty($automatic_watermarks)) { 739 if (defined('WP_DEBUG') && WP_DEBUG) {740 error_log('Ultimate Watermark: No watermarks to apply for size ' . $size . ' (skipping)');741 }742 611 continue; // No watermarks for this size, skip 743 }744 745 if (defined('WP_DEBUG') && WP_DEBUG) {746 error_log('Ultimate Watermark: Applying ' . count($automatic_watermarks) . ' watermark(s) to size ' . $size);747 foreach ($automatic_watermarks as $watermark) {748 // CRITICAL: WatermarkHelper returns 'id' (lowercase), check that first749 $wm_id = isset($watermark['id']) ? $watermark['id'] : (isset($watermark['ID']) ? $watermark['ID'] : 'unknown');750 error_log('Ultimate Watermark: - About to apply watermark ID: ' . $wm_id . ' (Name: ' . ($watermark['name'] ?? 'unknown') . ')');751 }752 612 } 753 613 … … 767 627 $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0); 768 628 769 error_log('Ultimate Watermark: applyWatermarkToAttachmentSize called - Watermark data keys: ' . implode(', ', array_keys($watermark)));770 error_log('Ultimate Watermark: Extracted watermark ID: ' . $watermark_id);771 772 629 if (!$watermark_id) { 773 error_log('Ultimate Watermark: ERROR - No watermark ID found! Watermark data: ' . print_r($watermark, true));774 630 return; 775 }776 777 if (defined('WP_DEBUG') && WP_DEBUG) {778 error_log('Ultimate Watermark: About to get image path for attachment ' . $attachment_id . ', size: ' . $size);779 631 } 780 632 781 633 // Get the image path for the specific size 782 634 $image_path = $this->getImagePathForSize($attachment_id, $size); 783 784 if (defined('WP_DEBUG') && WP_DEBUG) {785 error_log('Ultimate Watermark: getImagePathForSize returned: ' . ($image_path ?: 'NULL'));786 error_log('Ultimate Watermark: File exists check: ' . ($image_path && file_exists($image_path) ? 'YES' : 'NO'));787 }788 635 789 636 if (!$image_path || !file_exists($image_path)) { … … 815 662 // Apply watermark using WatermarkService 816 663 try { 817 error_log('Ultimate Watermark: applyWatermarkToAttachmentSize - Attachment: ' . $attachment_id . ', Watermark ID: ' . $watermark_id . ', Size: ' . $size);818 error_log('Ultimate Watermark: Image path: ' . $image_path);819 error_log('Ultimate Watermark: File exists: ' . (file_exists($image_path) ? 'YES' : 'NO'));820 error_log('Ultimate Watermark: File writable: ' . (file_exists($image_path) && is_writable($image_path) ? 'YES' : 'NO'));821 664 822 665 // Set attachment context for Pro plugin placeholder resolution … … 852 695 // Track watermark usage for this specific size (count once) 853 696 \MantraBrain\UltimateWatermark\Utils\WatermarkUsageTracker::incrementUsage($watermark_id, $attachment_id, $size); 854 } else {855 if (defined('WP_DEBUG') && WP_DEBUG) {856 error_log('Ultimate Watermark: applyWatermarkById returned FALSE for watermark ID ' . $watermark_id);857 }858 697 } 859 698 } catch (\Exception $e) { 860 // Log error for debugging 861 if (defined('WP_DEBUG') && WP_DEBUG) { 862 error_log('Ultimate Watermark: Exception in applyWatermarkToAttachmentSize - ' . $e->getMessage()); 863 error_log('Ultimate Watermark: Stack trace: ' . $e->getTraceAsString()); 864 } 699 // Silently handle exceptions 865 700 } 866 701 } -
ultimate-watermark/trunk/ultimate-watermark.php
r3465508 r3465576 4 4 * Plugin URI: https://mantrabrain.com/ultimate-watermark 5 5 * Description: Advanced WordPress Image Watermarking Plugin 6 * Version: 2.0. 26 * Version: 2.0.3 7 7 * Author: MantraBrain 8 8 * Author URI: https://mantrabrain.com … … 18 18 * @package UltimateWatermark 19 19 * @author MantraBrain 20 * @version 2.0. 220 * @version 2.0.3 21 21 */ 22 22 … … 36 36 37 37 // Define plugin constants 38 define('ULTIMATE_WATERMARK_VERSION', '2.0. 2');38 define('ULTIMATE_WATERMARK_VERSION', '2.0.3'); 39 39 define('ULTIMATE_WATERMARK_FILE', __FILE__); 40 40 define('ULTIMATE_WATERMARK_DIR', plugin_dir_path(__FILE__));
Note: See TracChangeset
for help on using the changeset viewer.