Plugin Directory

Changeset 3465576


Ignore:
Timestamp:
02/20/2026 08:37:05 AM (6 weeks ago)
Author:
mantrabrain
Message:

Update to version 2.0.3 from GitHub

Location:
ultimate-watermark
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ultimate-watermark/tags/2.0.3/readme.txt

    r3465508 r3465576  
    55Requires at least: 5.0
    66Tested up to: 6.9
    7 Stable tag: 2.0.2
     7Stable tag: 2.0.3
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    3030* **[Get Support](https://wordpress.org/support/plugin/ultimate-watermark/)** - Free community support forum
    3131* **[Feature Requests](https://mantrabrain.com/contact)** - Suggest new features and improvements
     32
     33= 📺 Video Walkthrough =
     34
     35Watch this quick video tutorial to see Ultimate Watermark in action and learn how to protect your images in minutes:
     36
     37https://www.youtube.com/watch?v=6QcDWgtaJRU
    3238
    3339= ⭐ Key Features (Free Version) =
     
    362368== Changelog ==
    363369
    364 = 2.0.2- 2026/02/20  =
     370= 2.0.3- 2026/02/20  =
    365371* **Fixed** - Duplication issue fixed
    366372* **Fixed** - GD library issue fixed
     373* **Fixed** - Minor other issues
    367374
    368375= 2.0 - 2026/02/19 =
  • ultimate-watermark/tags/2.0.3/src/Admin/MediaLibraryIntegration.php

    r3465062 r3465576  
    293293        $image_sizes = get_intermediate_image_sizes();
    294294        $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);
    295299       
    296300        // Extract watermark_rules for per-size evaluation
     
    306310        }
    307311       
    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        
    315312        $success_count = 0;
     313        $rules_skipped_sizes = []; // Track sizes skipped due to rule conditions
    316314       
    317315        // Apply watermarks to each size, evaluating rules per-size
     
    321319            if (!$has_rule_conditions) {
    322320                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                     }
    326321                    continue;
    327322                }
     
    333328                $eval_context = RulesEvaluator::buildContext($attachment_id, $size, 0);
    334329                $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                 }
    338330                if (!$rule_result) {
     331                    // Track that this size was skipped due to rule conditions
     332                    $rules_skipped_sizes[] = $size;
    339333                    continue; // Rules don't match for this size
    340334                }
     
    343337            // All rules passed, apply watermark
    344338            $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             }
    348339            if (!$image_path || !file_exists($image_path)) {
    349340                $result['skipped_sizes'][] = [
     
    380371                    ];
    381372                }
    382                 if (defined('WP_DEBUG') && WP_DEBUG) {
    383                     error_log('Ultimate Watermark [Manual]: Size "' . $size . '" watermark apply=' . ($apply_success ? 'SUCCESS' : 'FAILED'));
    384                 }
    385373            } catch (\Exception $e) {
    386374                \MantraBrain\UltimateWatermark\Watermark\WatermarkService::setAttachmentContext([]);
     
    394382                    ),
    395383                ];
    396                 if (defined('WP_DEBUG') && WP_DEBUG) {
    397                     error_log('Ultimate Watermark [Manual]: Size "' . $size . '" EXCEPTION: ' . $e->getMessage());
    398                 }
    399384            }
    400385        }
     
    411396            );
    412397        } 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            }
    414408        }
    415409       
     
    1000994                        }
    1001995                        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                        }
    10021006                    });
    10031007                   
     
    11061110                                if (toggleState === '1') {
    11071111                                    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                                            }
    11151119                                        }
     1120                                    } catch (e) {
     1121                                        // Silent fail
    11161122                                    }
    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'];
    11191127                                }
    11201128                            }
     
    11341142                                if (toggleState === '1') {
    11351143                                    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                                            }
    11431151                                        }
     1152                                    } catch (e) {
     1153                                        // Silent fail
    11441154                                    }
    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'];
    11471159                                }
    11481160                            }
     
    12101222                }
    12111223               
    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) {
    12161230                    // Ensure multipart_params exists
    12171231                    if (!up.settings.multipart_params) {
     
    14041418        $ids_string = isset($_POST['ids']) ? sanitize_text_field($_POST['ids']) : '';
    14051419       
    1406         // Always log for debugging
    1407         error_log('Ultimate Watermark: handleSetTempSelectedIds - Received IDs: [' . $ids_string . ']');
    1408        
    14091420        update_option('ultimate_watermark_temp_selected_ids', $ids_string, false);
    14101421       
    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]);
    14161423    }
    14171424
  • ultimate-watermark/tags/2.0.3/src/Integration/RestApiIntegration.php

    r3465508 r3465576  
    9191        $auto_apply_enabled = false;
    9292       
    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)
    109113            $option_value = get_option('ultimate_watermark_auto_apply_toggle', '0');
    110114            if ($option_value === '1') {
     
    150154            if (isset($_POST['ultimate_watermark_ids'])) {
    151155                $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                 }
    155156            }
    156157            // 2. Check $_REQUEST (broader scope)
    157158            elseif (isset($_REQUEST['ultimate_watermark_ids'])) {
    158159                $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                 }
    162160            }
    163161            // 3. Check WordPress option (set by AJAX before upload)
    164162            elseif (get_option('ultimate_watermark_temp_selected_ids', '') !== '') {
    165163                $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                 }
    169164                // Clear after reading (one-time use)
    170165                delete_option('ultimate_watermark_temp_selected_ids');
    171166            }
    172             // 4. Check raw input stream (for multipart/form-data)
     167            // 4. Check raw input as last resort
    173168            else {
    174169                $raw_input = file_get_contents('php://input');
    175170                if (preg_match('/name="ultimate_watermark_ids"[^>]*>([^<]+)</i', $raw_input, $matches)) {
    176171                    $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                     }
    180172                }
    181173                // 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)) {
    183175                    $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));
    193176                }
    194177            }
     
    197180            if (!empty($ids_string) && trim($ids_string) !== '') {
    198181                $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                 }
    202182            } else {
    203183                // If empty string, keep as empty array (user explicitly unchecked all)
    204184                $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 input
    211             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                 }
    218185            }
    219186           
    220187            // Store selected watermark IDs in attachment meta (even if empty, to track user intent)
    221188            // 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             }
    225189            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             }
    233190           
    234191            // Mark this attachment for watermarking
    235192            update_post_meta($attachment_id, '_ulwm_watermarked', true);
    236            
    237             // Debug logging
    238             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             }
    249193           
    250194            // DO NOT reset the toggle here - it will be reset after watermark is applied
     
    335279                        }
    336280                    }
    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)
    370287            }
    371288        }
     
    399316               
    400317            } catch (\Exception $e) {
    401                 // Log error for debugging in production
    402                 if (defined('WP_DEBUG') && WP_DEBUG) {
    403                     error_log('Ultimate Watermark Error: ' . $e->getMessage());
    404                 }
    405318                // Restore original memory limit
    406319                ini_set('memory_limit', $original_memory_limit);
     
    508421        });
    509422       
    510         // Debug logging
    511         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         }
    523423       
    524424        // Get parent post ID for rule checking (for REST API uploads from page/post editor)
     
    559459                $selected_ids_int = array_map('intval', $selected_watermark_ids);
    560460               
    561                 // Debug logging
    562                 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                 }
    567461               
    568462                $automatic_watermarks = array_filter($automatic_watermarks, function($watermark) use ($selected_ids_int) {
     
    570464                    $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0);
    571465                   
    572                     // Log all watermark data for debugging
    573                     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                    
    577466                    // 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);
    585468                });
    586469               
    587                 if (defined('WP_DEBUG') && WP_DEBUG) {
    588                     error_log('Ultimate Watermark: Watermarks after ID filter: ' . count($automatic_watermarks));
    589                 }
    590470               
    591471                // Filter by legacy size rules ONLY if no unified rules exist
     
    611491                    }
    612492                   
    613                     // CRITICAL: Use 'id' (lowercase) - that's what WatermarkHelper returns
    614                     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                     }
    618493                    return $passes_size;
    619494                });
    620495               
    621                 if (defined('WP_DEBUG') && WP_DEBUG) {
    622                     error_log('Ultimate Watermark: Watermarks after size filter: ' . count($size_filtered));
    623                 }
    624496                $automatic_watermarks = $size_filtered;
    625497            } else {
     
    737609           
    738610            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                 }
    742611                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 first
    749                     $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                 }
    752612            }
    753613           
     
    767627        $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0);
    768628       
    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        
    772629        if (!$watermark_id) {
    773             error_log('Ultimate Watermark: ERROR - No watermark ID found! Watermark data: ' . print_r($watermark, true));
    774630            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);
    779631        }
    780632       
    781633        // Get the image path for the specific size
    782634        $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         }
    788635       
    789636        if (!$image_path || !file_exists($image_path)) {
     
    815662        // Apply watermark using WatermarkService
    816663        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'));
    821664           
    822665            // Set attachment context for Pro plugin placeholder resolution
     
    852695                // Track watermark usage for this specific size (count once)
    853696                \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                 }
    858697            }
    859698        } 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
    865700        }
    866701    }
  • ultimate-watermark/tags/2.0.3/ultimate-watermark.php

    r3465508 r3465576  
    44 * Plugin URI: https://mantrabrain.com/ultimate-watermark
    55 * Description: Advanced WordPress Image Watermarking Plugin
    6  * Version: 2.0.2
     6 * Version: 2.0.3
    77 * Author: MantraBrain
    88 * Author URI: https://mantrabrain.com
     
    1818 * @package UltimateWatermark
    1919 * @author MantraBrain
    20  * @version 2.0.2
     20 * @version 2.0.3
    2121 */
    2222
     
    3636
    3737// Define plugin constants
    38 define('ULTIMATE_WATERMARK_VERSION', '2.0.2');
     38define('ULTIMATE_WATERMARK_VERSION', '2.0.3');
    3939define('ULTIMATE_WATERMARK_FILE', __FILE__);
    4040define('ULTIMATE_WATERMARK_DIR', plugin_dir_path(__FILE__));
  • ultimate-watermark/trunk/readme.txt

    r3465508 r3465576  
    55Requires at least: 5.0
    66Tested up to: 6.9
    7 Stable tag: 2.0.2
     7Stable tag: 2.0.3
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    3030* **[Get Support](https://wordpress.org/support/plugin/ultimate-watermark/)** - Free community support forum
    3131* **[Feature Requests](https://mantrabrain.com/contact)** - Suggest new features and improvements
     32
     33= 📺 Video Walkthrough =
     34
     35Watch this quick video tutorial to see Ultimate Watermark in action and learn how to protect your images in minutes:
     36
     37https://www.youtube.com/watch?v=6QcDWgtaJRU
    3238
    3339= ⭐ Key Features (Free Version) =
     
    362368== Changelog ==
    363369
    364 = 2.0.2- 2026/02/20  =
     370= 2.0.3- 2026/02/20  =
    365371* **Fixed** - Duplication issue fixed
    366372* **Fixed** - GD library issue fixed
     373* **Fixed** - Minor other issues
    367374
    368375= 2.0 - 2026/02/19 =
  • ultimate-watermark/trunk/src/Admin/MediaLibraryIntegration.php

    r3465062 r3465576  
    293293        $image_sizes = get_intermediate_image_sizes();
    294294        $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);
    295299       
    296300        // Extract watermark_rules for per-size evaluation
     
    306310        }
    307311       
    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        
    315312        $success_count = 0;
     313        $rules_skipped_sizes = []; // Track sizes skipped due to rule conditions
    316314       
    317315        // Apply watermarks to each size, evaluating rules per-size
     
    321319            if (!$has_rule_conditions) {
    322320                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                     }
    326321                    continue;
    327322                }
     
    333328                $eval_context = RulesEvaluator::buildContext($attachment_id, $size, 0);
    334329                $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                 }
    338330                if (!$rule_result) {
     331                    // Track that this size was skipped due to rule conditions
     332                    $rules_skipped_sizes[] = $size;
    339333                    continue; // Rules don't match for this size
    340334                }
     
    343337            // All rules passed, apply watermark
    344338            $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             }
    348339            if (!$image_path || !file_exists($image_path)) {
    349340                $result['skipped_sizes'][] = [
     
    380371                    ];
    381372                }
    382                 if (defined('WP_DEBUG') && WP_DEBUG) {
    383                     error_log('Ultimate Watermark [Manual]: Size "' . $size . '" watermark apply=' . ($apply_success ? 'SUCCESS' : 'FAILED'));
    384                 }
    385373            } catch (\Exception $e) {
    386374                \MantraBrain\UltimateWatermark\Watermark\WatermarkService::setAttachmentContext([]);
     
    394382                    ),
    395383                ];
    396                 if (defined('WP_DEBUG') && WP_DEBUG) {
    397                     error_log('Ultimate Watermark [Manual]: Size "' . $size . '" EXCEPTION: ' . $e->getMessage());
    398                 }
    399384            }
    400385        }
     
    411396            );
    412397        } 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            }
    414408        }
    415409       
     
    1000994                        }
    1001995                        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                        }
    10021006                    });
    10031007                   
     
    11061110                                if (toggleState === '1') {
    11071111                                    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                                            }
    11151119                                        }
     1120                                    } catch (e) {
     1121                                        // Silent fail
    11161122                                    }
    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'];
    11191127                                }
    11201128                            }
     
    11341142                                if (toggleState === '1') {
    11351143                                    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                                            }
    11431151                                        }
     1152                                    } catch (e) {
     1153                                        // Silent fail
    11441154                                    }
    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'];
    11471159                                }
    11481160                            }
     
    12101222                }
    12111223               
    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) {
    12161230                    // Ensure multipart_params exists
    12171231                    if (!up.settings.multipart_params) {
     
    14041418        $ids_string = isset($_POST['ids']) ? sanitize_text_field($_POST['ids']) : '';
    14051419       
    1406         // Always log for debugging
    1407         error_log('Ultimate Watermark: handleSetTempSelectedIds - Received IDs: [' . $ids_string . ']');
    1408        
    14091420        update_option('ultimate_watermark_temp_selected_ids', $ids_string, false);
    14101421       
    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]);
    14161423    }
    14171424
  • ultimate-watermark/trunk/src/Integration/RestApiIntegration.php

    r3465508 r3465576  
    9191        $auto_apply_enabled = false;
    9292       
    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)
    109113            $option_value = get_option('ultimate_watermark_auto_apply_toggle', '0');
    110114            if ($option_value === '1') {
     
    150154            if (isset($_POST['ultimate_watermark_ids'])) {
    151155                $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                 }
    155156            }
    156157            // 2. Check $_REQUEST (broader scope)
    157158            elseif (isset($_REQUEST['ultimate_watermark_ids'])) {
    158159                $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                 }
    162160            }
    163161            // 3. Check WordPress option (set by AJAX before upload)
    164162            elseif (get_option('ultimate_watermark_temp_selected_ids', '') !== '') {
    165163                $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                 }
    169164                // Clear after reading (one-time use)
    170165                delete_option('ultimate_watermark_temp_selected_ids');
    171166            }
    172             // 4. Check raw input stream (for multipart/form-data)
     167            // 4. Check raw input as last resort
    173168            else {
    174169                $raw_input = file_get_contents('php://input');
    175170                if (preg_match('/name="ultimate_watermark_ids"[^>]*>([^<]+)</i', $raw_input, $matches)) {
    176171                    $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                     }
    180172                }
    181173                // 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)) {
    183175                    $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));
    193176                }
    194177            }
     
    197180            if (!empty($ids_string) && trim($ids_string) !== '') {
    198181                $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                 }
    202182            } else {
    203183                // If empty string, keep as empty array (user explicitly unchecked all)
    204184                $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 input
    211             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                 }
    218185            }
    219186           
    220187            // Store selected watermark IDs in attachment meta (even if empty, to track user intent)
    221188            // 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             }
    225189            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             }
    233190           
    234191            // Mark this attachment for watermarking
    235192            update_post_meta($attachment_id, '_ulwm_watermarked', true);
    236            
    237             // Debug logging
    238             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             }
    249193           
    250194            // DO NOT reset the toggle here - it will be reset after watermark is applied
     
    335279                        }
    336280                    }
    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)
    370287            }
    371288        }
     
    399316               
    400317            } catch (\Exception $e) {
    401                 // Log error for debugging in production
    402                 if (defined('WP_DEBUG') && WP_DEBUG) {
    403                     error_log('Ultimate Watermark Error: ' . $e->getMessage());
    404                 }
    405318                // Restore original memory limit
    406319                ini_set('memory_limit', $original_memory_limit);
     
    508421        });
    509422       
    510         // Debug logging
    511         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         }
    523423       
    524424        // Get parent post ID for rule checking (for REST API uploads from page/post editor)
     
    559459                $selected_ids_int = array_map('intval', $selected_watermark_ids);
    560460               
    561                 // Debug logging
    562                 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                 }
    567461               
    568462                $automatic_watermarks = array_filter($automatic_watermarks, function($watermark) use ($selected_ids_int) {
     
    570464                    $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0);
    571465                   
    572                     // Log all watermark data for debugging
    573                     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                    
    577466                    // 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);
    585468                });
    586469               
    587                 if (defined('WP_DEBUG') && WP_DEBUG) {
    588                     error_log('Ultimate Watermark: Watermarks after ID filter: ' . count($automatic_watermarks));
    589                 }
    590470               
    591471                // Filter by legacy size rules ONLY if no unified rules exist
     
    611491                    }
    612492                   
    613                     // CRITICAL: Use 'id' (lowercase) - that's what WatermarkHelper returns
    614                     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                     }
    618493                    return $passes_size;
    619494                });
    620495               
    621                 if (defined('WP_DEBUG') && WP_DEBUG) {
    622                     error_log('Ultimate Watermark: Watermarks after size filter: ' . count($size_filtered));
    623                 }
    624496                $automatic_watermarks = $size_filtered;
    625497            } else {
     
    737609           
    738610            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                 }
    742611                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 first
    749                     $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                 }
    752612            }
    753613           
     
    767627        $watermark_id = isset($watermark['id']) ? (int)$watermark['id'] : (isset($watermark['ID']) ? (int)$watermark['ID'] : 0);
    768628       
    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        
    772629        if (!$watermark_id) {
    773             error_log('Ultimate Watermark: ERROR - No watermark ID found! Watermark data: ' . print_r($watermark, true));
    774630            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);
    779631        }
    780632       
    781633        // Get the image path for the specific size
    782634        $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         }
    788635       
    789636        if (!$image_path || !file_exists($image_path)) {
     
    815662        // Apply watermark using WatermarkService
    816663        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'));
    821664           
    822665            // Set attachment context for Pro plugin placeholder resolution
     
    852695                // Track watermark usage for this specific size (count once)
    853696                \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                 }
    858697            }
    859698        } 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
    865700        }
    866701    }
  • ultimate-watermark/trunk/ultimate-watermark.php

    r3465508 r3465576  
    44 * Plugin URI: https://mantrabrain.com/ultimate-watermark
    55 * Description: Advanced WordPress Image Watermarking Plugin
    6  * Version: 2.0.2
     6 * Version: 2.0.3
    77 * Author: MantraBrain
    88 * Author URI: https://mantrabrain.com
     
    1818 * @package UltimateWatermark
    1919 * @author MantraBrain
    20  * @version 2.0.2
     20 * @version 2.0.3
    2121 */
    2222
     
    3636
    3737// Define plugin constants
    38 define('ULTIMATE_WATERMARK_VERSION', '2.0.2');
     38define('ULTIMATE_WATERMARK_VERSION', '2.0.3');
    3939define('ULTIMATE_WATERMARK_FILE', __FILE__);
    4040define('ULTIMATE_WATERMARK_DIR', plugin_dir_path(__FILE__));
Note: See TracChangeset for help on using the changeset viewer.