0

My company that I work with would like me to investigate how I might go about creating a system in the back end of our website that our employees can you use to help speed up their workload. I am by no means a programmer, I can make some basic CMS websites but that is not my daily function.

Essentially it would need to do this: allow each employee to create a phrase ( text ) that could be saved as a button or link or line of text that could be double clicked and automatically be entered into a blank text field.

So having a bunch of these pre saved text options will allow them to speed up their on-site work. Once inside a text box they could copy and paste it into other proprietary software. Naturally we would want each user's text buttons to be saved and unique to their own profile. Initially I was under the impression that perhaps a CMS module would do the trick but I have not found anything (or combination) that would do just that.

I am open to having someone do this for us but I need a little push in the right direction. Would this be more appropriate as a CMS back end situation or web app, or something else?

  • if the user need to copy-paste, can it be enough if all sentences of the user are on a page and they just select the choosen sentence ? then a single text file can be enough fo each user. – Kaperto Nov 8 '19 at 1:31
  • There are a significant number of text sentences. More than a hundred for each user so ideally it would be something that can be made smaller and yet all the buttons fit on one visible area. – user12340396 Nov 8 '19 at 2:30
  • Sounds like the text phrases could be normal WP posts and one can create a custom copy button for each post on the frontend or e.g. in the post list table in backend (no need for a visible text box). That way each user can log into their WP account to add/edit/delete their own text phrases. – birgire Nov 8 '19 at 9:05
  • I should mention that a combination of these phrases are used all together for a description of the on site work. So it could be phrase x,y,z one hour and a,b,c the next. That is reason for the multitude of buttons or available options visible. After putting them together in a blank text field, modifications could be made to the paragraph prior to copy and paste into the proprietary software. – user12340396 Nov 9 '19 at 4:45
1

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("&nbsp;", $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 () {
  • Would this accommodate each user adding, editing or deleting one phrase at a time? Or would this have to be all one post? – user12340396 Nov 9 '19 at 1:06

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.