的想法birgire 很有趣,但这已经可以通过每个用户一篇帖子来完成。
创建角色为“Contributor”的用户,然后每个用户创建一篇包含此内容的帖子
按钮1文本
一句话,quis nostrud execution ullamco laboris nisi ut aliquip ex ea commodo consequeat。两人或两人在一起的时候,在一起的时候,你可以在一起,在一起的时候,你可以在一起。
按钮2文本一个大句子。。。。。。。。。
然后使用此插件生成带有按钮的页面:
<?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 () {