-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2aab1f3
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
global $wpdb; | ||
// Get text from database to add when article/writing is copied by the user | ||
$added_text = $wpdb->get_var("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name = 'referensi_copy'"); | ||
function ILRICT_check_data() | ||
{ | ||
global $added_text; | ||
// Check if the admin has set the plugin | ||
if (!$added_text) { | ||
// If not, display this text when the article/writing is copied by the user | ||
echo "Read more at:"; | ||
} else { | ||
// If yes, display the text set by the admin | ||
echo esc_html($added_text); | ||
} | ||
} | ||
|
||
function ILRICT_reference_link() | ||
{ | ||
?> | ||
|
||
<script> | ||
function ILRICT_add_link() { | ||
var body_element = document.getElementsByTagName('body')[0]; | ||
var selection; | ||
selection = window.getSelection(); | ||
var oldselection = selection | ||
var page_link = "<br><br><?php ILRICT_check_data() ?> <a href='<?php echo get_permalink(get_the_ID()); ?>'><?php echo get_permalink(get_the_ID()); ?></a>"; // Text that appears when the article/writing is copied by the user | ||
var copy_text = selection + page_link; | ||
var new_div = document.createElement('div'); | ||
new_div.style.left = '-99999px'; | ||
new_div.style.position = 'absolute'; | ||
|
||
body_element.appendChild(new_div); | ||
new_div.innerHTML = copy_text; | ||
selection.selectAllChildren(new_div); | ||
window.setTimeout(function() { | ||
body_element.removeChild(new_div); | ||
}, 0); | ||
} | ||
|
||
document.oncopy = ILRICT_add_link; | ||
</script> | ||
|
||
<?php | ||
} | ||
add_action('wp_head', 'ILRICT_reference_link'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>Source Code</title> | ||
</head> | ||
|
||
<body> | ||
<h1><a href="https://github.com/mushlih-almubarak/Insert-Link-Reference-In-Copied-Text">Source Code For This | ||
Plugin</a></h1> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/* | ||
Plugin Name: Insert Link Reference In Copied Text | ||
Description: This plugin will add a reference from which site someone copied a text. | ||
Author: Mushlih Almubarak | ||
Author URI: https://github.com/mushlih-almubarak | ||
Version: 1 | ||
*/ | ||
|
||
// Include functions.php, use require_once to stop the script if the functions.php file is not found | ||
require_once plugin_dir_path(__FILE__) . 'functions.php'; | ||
// Connect action hook 'admin_menu', run 'ILRICT_add_setting_menu' function | ||
add_action('admin_menu', 'ILRICT_add_setting_menu'); | ||
|
||
// Add menu link in WordPress dashboard | ||
function ILRICT_add_setting_menu() | ||
{ | ||
add_menu_page( | ||
'Insert Link Reference In Copied Text', // Page title | ||
'Insert Reference', // The text displayed on the menu | ||
'manage_options', // Requirements to be able to view the link | ||
'insert-link-reference-in-copied-text', // Permalink. | ||
'ILRICT_setting' // Call the "ILRICT_setting" function | ||
); | ||
|
||
function ILRICT_setting() | ||
{ | ||
require_once 'Setting.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
global $wpdb; | ||
// if the admin clicks "save" in the setting page | ||
if (isset($_POST["save"])) { | ||
// Check if there are settings that have been previously saved by the admin | ||
$check_data = $wpdb->get_var("SELECT * FROM {$wpdb->prefix}options WHERE option_name = 'referensi_copy'"); | ||
|
||
// Enter the admin input into the "text" variable | ||
$text = sanitize_text_field($_POST["reference"]); | ||
// Function to write error message (if any) in console | ||
function ILRICT_log_to_console($error) | ||
{ | ||
printf('<script>console.log(%s);</script>', json_encode($error)); | ||
}; | ||
|
||
// If the admin has never set up the plugin before: | ||
if (!$check_data) { | ||
// Insert data | ||
$wpdb->insert($wpdb->options, array("option_id" => null, "option_name" => "referensi_copy", "option_value" => "$text", "autoload" => "yes")); | ||
|
||
// Check if the data was inserted successfully | ||
if (!$wpdb->last_error) { | ||
echo "<script>alert('Setting Saved')</script>"; | ||
} else { | ||
echo "<script>alert('Failed To Save Settings')</script>"; | ||
// Log error to console | ||
$error_when_insert_data = $wpdb->last_error; | ||
ILRICT_log_to_console($error_when_insert_data); | ||
} | ||
} | ||
// If the admin has set up the plugin before: | ||
else { | ||
// Update data | ||
$wpdb->update($wpdb->options, array("option_value" => "$text"), array("option_name" => "referensi_copy")); | ||
|
||
// Check if the data was updated successfully | ||
if (!$wpdb->last_error) { | ||
echo "<script>alert('Setting Updated')</script>"; | ||
} else { | ||
echo "<script>alert('Failed To Update Settings')</script>"; | ||
// Log error to console | ||
$error_when_update_data = $wpdb->last_error; | ||
ILRICT_log_to_console($error_when_update_data); | ||
} | ||
} | ||
} | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Insert Link Reference In Copied Text Setting Plugin</title> | ||
</head> | ||
|
||
<body> | ||
<form method="POST"> | ||
<h1>The Text That Appears When A Text Copied</h1> | ||
<input type="text" name="reference"> | ||
<button type="submit" name="save" autofocus>Save</button> | ||
</form> | ||
<p>Created by <a href="https://github.com/mushlih-almubarak" target="_blank">Mushlih</a>, from Indonesia</p> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
=== Insert Link Reference In Copied Text === | ||
Contributors: mushlih | ||
Tags: copy, insert, paste | ||
Requires at least: 4.7 | ||
Tested up to: 5.9 | ||
Requires PHP: 7.3.5 | ||
Stable tag: 1 | ||
License: GPLv2 | ||
License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
|
||
This plugin will add a reference from which site someone copied a text. | ||
|
||
== Description == | ||
If someone copies an article on your site, then when that person pastes it, there will be additional text in the pasted text, and you can set with this plugin what text will appear if someone copies the article from your site. | ||
|
||
This plugin is created and designed as simple as possible, so as not to burden your site, even the size of this plugin is not up to 1 MB! | ||
|
||
== Installation == | ||
= Download Insert Link Reference In Copied Text Plugin From WordPress Dashboard = | ||
1. Visit the plugins page in your WordPress dashboard and click "Add New". | ||
2. Search for "Insert Link Reference In Copied Text". | ||
3. Click "Install Now", then "Active". | ||
|
||
= Download Insert Link Reference In Copied Text Plugin Manually = | ||
1. Upload the plugin folder to the /wp-content/plugins/ directory. | ||
2. Activate the plugin through the ‘Plugins’ menu in the WordPress dashboard. | ||
|
||
== Frequently Asked Questions == | ||
= How to use this plugin? = | ||
Go to the WordPress dashboard, then click the "Insert Reference" menu, add the words you want to add when someone copies text from your site, then click "Save". | ||
|
||
== Screenshots == | ||
1. [https://imgur.com/R9IbelK Setting Page] | ||
2. [https://imgur.com/ioyguoa Text that appears after copying] | ||
|
||
== Changelog == | ||
= Version: 1 = | ||
* Release Date: January, 2022. | ||
* First Release. |