ID, $excluded_ids, true)) { return true; } } if (!empty($options['protected_post_types']) && is_array($options['protected_post_types'])) { if (!in_array($post->post_type, $options['protected_post_types'], true)) { return true; } } return false; } /** * Check if the current page is excluded from Watermarking. * Checks watermark_excluded_page_ids. */ function accelvia_is_page_excluded_from_wm($options) { $post = get_post(); if (!$post) { return false; } if (!empty($options['watermark_excluded_page_ids'])) { $excluded_ids = array_map('absint', explode(',', $options['watermark_excluded_page_ids'])); if (in_array((int) $post->ID, $excluded_ids, true)) { return true; } } return false; } /** * Enqueue the frontend protection script when appropriate. */ function accelvia_enqueue_frontend_protection() { // Never run in admin. if (is_admin()) { return; } $options = get_option(ACCELVIA_OPTION_KEY, array()); // Bail if protection is globally disabled. if (empty($options['enable_protection']) || '1' !== $options['enable_protection']) { return; } // Skip for logged-in administrators if that option is enabled. if (!empty($options['skip_admins']) && '1' === $options['skip_admins'] && current_user_can('manage_options')) { return; } $is_cp_excluded = accelvia_is_page_excluded_from_cp($options); $is_wm_excluded = accelvia_is_page_excluded_from_wm($options); if ($is_cp_excluded && $is_wm_excluded) { return; // Nothing to do here. } // --- Content Protection Scripts --- if (!$is_cp_excluded) { // Enqueue the protection script. wp_enqueue_script( 'accelvia-protection', ACCELVIA_PLUGIN_URL . 'assets/js/protection.js', array(), // No dependencies – pure Vanilla JS. ACCELVIA_VERSION, true // Load in footer. ); // Pass configuration to JS. $config = array( 'disableRightClick' => !empty($options['disable_right_click']) && '1' === $options['disable_right_click'], 'disableShortcuts' => !empty($options['disable_shortcuts']) && '1' === $options['disable_shortcuts'], 'disableTextSelection' => !empty($options['disable_text_selection']) && '1' === $options['disable_text_selection'], 'disableImageDrag' => !empty($options['disable_image_drag']) && '1' === $options['disable_image_drag'], 'disableCopy' => !empty($options['disable_copy']) && '1' === $options['disable_copy'], 'disableDevTools' => !empty($options['disable_devtools']) && '1' === $options['disable_devtools'], 'disableScreenshot' => !empty($options['disable_screenshot']) && '1' === $options['disable_screenshot'], 'encryptContent' => !empty($options['encrypt_content']) && '1' === $options['encrypt_content'], 'notificationType' => isset($options['notification_type']) ? $options['notification_type'] : 'toast', 'notificationMessage' => isset($options['notification_message']) ? $options['notification_message'] : __('This content is protected by Accelvia.', 'accelvia-content-protection'), ); wp_localize_script('accelvia-protection', 'accelvia_config', $config); } // End CP check // --- Watermark Module --- if (!$is_wm_excluded && !empty($options['watermark_enabled']) && '1' === $options['watermark_enabled']) { wp_enqueue_script( 'accelvia-watermark', ACCELVIA_PLUGIN_URL . 'assets/js/watermark.js', array(), // No dependencies – pure Vanilla JS. ACCELVIA_VERSION, true // Load in footer. ); $wm_config = array( 'type' => isset($options['watermark_type']) ? $options['watermark_type'] : 'text', 'imageUrl' => isset($options['watermark_image_url']) ? $options['watermark_image_url'] : '', 'text' => isset($options['watermark_text']) ? $options['watermark_text'] : __('© Protected by Accelvia', 'accelvia-content-protection'), 'fontSize' => isset($options['watermark_font_size']) ? absint($options['watermark_font_size']) : 16, 'fontColor' => isset($options['watermark_font_color']) ? $options['watermark_font_color'] : '#ffffff', 'position' => isset($options['watermark_position']) ? $options['watermark_position'] : 'bottom-right', 'opacity' => isset($options['watermark_opacity']) ? absint($options['watermark_opacity']) : 50, 'size' => isset($options['watermark_size']) ? absint($options['watermark_size']) : 30, 'tileSpacing' => isset($options['watermark_tile_spacing']) ? absint($options['watermark_tile_spacing']) : 80, 'scope' => isset($options['watermark_scope']) ? $options['watermark_scope'] : 'all', 'selector' => isset($options['watermark_selector']) ? $options['watermark_selector'] : '', 'excludeSelector' => isset($options['watermark_exclude_selector']) ? $options['watermark_exclude_selector'] : '', 'device' => isset($options['watermark_device']) ? $options['watermark_device'] : 'both', ); wp_localize_script('accelvia-watermark', 'accelvia_watermark', $wm_config); } } add_action('wp_enqueue_scripts', 'accelvia_enqueue_frontend_protection'); /** * Inject an inline micro-script in that blocks right-click IMMEDIATELY. * * This eliminates the race condition where protection.js hasn't loaded yet * during hot-reload or slow page loads, leaving right-click unprotected. * * Also injects a