0

I am creating a WordPress plugin to help people protect their content from being copied. There are many plugins to protect content from being copied when JavaScript is on, but no plugins which protect content even when JS is off.

How can I add the following custom CSS code in a PHP file, to protect content copy via CSS, and then install the PHP file as a WordPress plugin?

body {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
}
1

I know this sounds like it's a good idea, but anyone can simply just view the source of the page and take whatever they want from there. They can also simply just hit Ctrl+S on their keyboard and save that entire page to their hard drive. They could even screenshot the page and use OCR technology to simply pull the text out if they wanted to. There's also Photoshop.

In my opinion, this is a waste of time.

With that out of the way, you could start by looking here: https://codex.wordpress.org/Writing_a_Plugin

That will cover a lot of important aspects of creating a plugin.

Then, to understand the most simplest form of a plugin, have a look at the hello.php (Hello Dolly plugin) file in your Wordpress' wp-content/plugins/ directory. Changing that will allow you to achieve what you want.

If you simply want to add this to your own site, you can do this in the footer:

<?php
    echo '<style>body {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
}</style>';
?>
  • Hi, I have Created Plugin with your Code, and Enabled in Site - gamehostingreviews.com . Please See Homepage, it's Not showing Full content. Please check and try to solve this – Missing Tricks Mar 17 '16 at 12:07
  • Your #main CSS is hiding the overflow.... line 401. Fix like this: #main { clear: both; overflow: visible; height: 100%; } – RiaanP Mar 17 '16 at 14:06
0

You can hook that into a filter that applies on every page.

function block_copy(){
    echo '<style>body {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -o-user-select: none;
    }</style>';
}
add_action('wp_head', 'block_copy');

Drop that into your functions.php

If you're going to be using one header or footer file on each page you could also just paste the straight tag content in those.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.