WordPress.org

Ready to get started?Download WordPress

Forums

How to, ultra simple plain text edit for single page, single user. (9 posts)

  1. albertodg
    Member
    Posted 1 year ago #

    I need to allow a single user to edit the plain text of the content of a single page, with just a simple form textarea.

    I want to avoid all the complexity of the admin environment, just get the actual content into a textarea and the option to modify it and save the new text with a button. The edit script will be hardwired to the specific page.

    I administrate the server, so I can modify everything.

    Any indication on how to do this?

    Thanks!

  2. bjohnson2
    Member
    Posted 1 year ago #

    maybe this plugin will help?
    http://wordpress.org/extend/plugins/live-edit/

  3. albertodg
    Member
    Posted 1 year ago #

    Thanks bjohnson2,

    I'm trying to find or make something even simpler. I want to force the use of just plain text, without any formatting. Also, what I need is a single page, single user approach. It is for CMS like use of WP.

    I'm thinking in the possibility of going directly to the database using php-sql scripts completely outside of WP. Some code would be helpful. I'm not a professional programmer.

    Thnks again.

  4. bcworkz
    Member
    Posted 1 year ago #

    The simplest I can imagine is creating a WP page template that serves as a basic admin-like edit form, except it is on the front end. It can be nothing more than title and content textareas and a submit button. Add a WP page based on this template. All edit links will call this page with the post id as an url parameter.

    When the template loads, it first checks user capabilities. It then grabs the url parameter and fetches the associated content from the DB and populates the textarea. When the submit button is clicked, the textarea value is used to update the post content in the DB.

    This is not pro level stuff. If you can program at all, you can figure this out.

  5. albertodg
    Member
    Posted 1 year ago #

    Thanks bcworkz,

    This is what I had in mind. I tryed to follow the code to undertand how the admin page edit page works, with the idea of replicating it in a minimalistic form, as you decribed, but I get lost in the complexity of wp.

    I couldn't find the function that retreives the page contents to the edit form, nor the funtion to save the changes.

    Other problem is how to call the same page with two different page templates, one for general use and the other for editing. There are some plugins for switching templates or themes for especial users, but this is another level of complexity.

    A brute force approach could be to use a second wp installation working on the same database, but I don't like the idea very much.

    At this time, I can get the page contents, as it is stored in the database, without any wp filtering, inside a textare. Now I need to save the changes, but I don't know how to doti, and better, how to bypass the user identification of wp. I need this operation extremely simple. A link sent to the user should make it all, without login, usernames or passwords.

    Thanks again.

  6. bcworkz
    Member
    Posted 1 year ago #

    Sorry, I was referring to the admin edit page conceptually, I did not intend you try to figure out how it actually works, that task is best left to the experts. You use the function wp_update_post() to save the contents from the text area.

    Do not use a second installation! That is not called for, there will be a simpler solution somehow.

    I was thinking this edit page would be called from an edit button adjacent to the post content, much as is done with the default theme when you are logged in. The button would just be a link similar to hxxp://example.com/simple-edit/?id=123&nonce=12a34c56e2 (the http intentionally munged to prevent annoying auto-linkifying)

    The page simple-edit is a WP page created from the Pages>Add New backend menu pick. The page is based on a custom template you create. This is an easy way to get all the theme styling applied and gives your template direct access to all WP functions without needing to include wp-load or blog-headers. It is also found automatically with a permalink. The template does all the work, you just add a title so you can access the page by it's slug, and specify your template as a page attribute.

    Since this is an open form with direct access to your DB, you need to implement some behind the scene security to prevent SQL injection hacks. Try to use a nonce if you can, if it is included in a link you send to someone, it will work for 24 hours and then the form should fail to load. Also be sure to validate and sanitize the content before inserting it into the DB. Ensure the form is only for editing content, not creating new posts, or the SEO spammers will have a field day. The nonce will help deter them from adding their links to existing posts.

  7. albertodg
    Member
    Posted 1 year ago #

    Thanks again, bcworkz!

    A very detailed advice! I was exploring wp_update_post() in the codex, but your indications are very helpful and do exactly what I had in mind. I'll try to put all of this to work!

  8. albertodg
    Member
    Posted 1 year ago #

    I donĀ“t understand why wp_update_post() in this code creates a new instance of a page, instead of updating the page indicated.

    The code is a page template (bare bones to test the behavior or of the function).

    Find the page id and change it in the template.

    Set the test page to use this template and open the page. Then go back to the admin pages in and you will find a new instance of the test page, not this one updated.

    What is wrong?

    <?php
    /*
    Template Name: test_wp_update_post
    */
    $pgid = 14; // substitute with a real page id
    // Update post $edpagid
      $my_post = array();
      $my_post['ID'] = $pagid;
      $my_post['post_content'] = "any other text";
    // Update the post into the database
      wp_update_post( $my_post );
    ?>
  9. albertodg
    Member
    Posted 1 year ago #

    Please, forget it! A couple of typos in the $pgid, $pagid var.

    Everything works!

Topic Closed

This topic has been closed to new replies.

About this Topic