Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nicholasohrn/9301743 to your computer and use it in GitHub Desktop.
Save nicholasohrn/9301743 to your computer and use it in GitHub Desktop.
Ridiculously Naive Image Protection Plugin
<?php
/*
Plugin Name: Ridiculously Naive Image Protection
Description: Enables ridiculously naive image protection. Disables contextmenu and dragstart on images using jQuery's event handling. That's it!
Version: 1.0.0.B.1
Author: Nick Ohrn
Author URI: http://nickohrn.com/
*/
function image_protector_wp_enqueue_scripts() {
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'image_protector_wp_enqueue_scripts');
function image_protector_output_javascript() {
echo '<script type="text/javascript">jQuery(document).ready(function($) { $(document).on("contextmenu dragstart", "img", function(event) { event.preventDefault(); }) });</script>';
}
add_action('wp_footer', 'image_protector_output_javascript');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment