The idea of birgire is interesting but this can already be done with a single post per user.
Create users with the role “Contributor” and then each user create a post with this content
button 1 text
a sentence, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.button 2 text
a big sentence ………
and then the page with the button is generated with this plugin :
<?php
/*
Plugin Name: One Sentence to bring them all and in the darkness bind them
Version: 1
*/
if (!function_exists("add_action")) {
echo "plugin";
exit();
}
add_action("admin_menu", function () {
$current_user = wp_get_current_user();
if (!in_array("contributor", $current_user->roles)) {
return;
}
add_menu_page(
"Sentences"
, "Sentences"
, "read" //, "manage_options"
, "Sentences"
, function () {
do_action("OneSentence/Sentences");
}
, NULL
, 0
);
});
add_action("OneSentence/Sentences", function () {
$current_user = wp_get_current_user();
$posts = get_posts([
"author" => $current_user->ID,
"post_status" => "pending",
"orderby" => "ID",
"order" => "ASC",
"posts_per_page" => 1,
]);
if (!isset($posts[0])) {
return;
}
?>
<div>
When the button have a green background, the sentence is in the clipboard and can be past everywhere.
</div>
<?php
$text = $posts[0]->post_content;
$tab1 = explode(" ", $text);
foreach ($tab1 as $e) {
$e = trim($e);
if (empty($e)) {
continue;
}
$tab2 = explode("\n", $e);
$bouton_text = trim($tab2[0]);
$content = trim($tab2[2]);
?>
<button
class="button_sentence"
data-content="<?php echo htmlspecialchars($content);?>"
>
<?php echo htmlspecialchars($bouton_text);?></button>
<?php
} // END foreach ($tab1 as $e) {
?>
<script>
$ = jQuery;
$(function () {
//console.clear();
$(".button_sentence").click(function () {
$(".button_sentence").css("background", "initial");
let element = $(this);
let textarea = document.createElement("textarea");
textarea.textContent = element.data("content");
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand("copy");
element.css("background", "green");
} catch (ex) {
console.warn("Copy to clipboard failed.", ex);
return false;
} finally {
document.body.removeChild(textarea);
}
});
});
</script>
<?php
}); // END add_action("OneSentence/Sentences", function () {