Admin pages preview
For reference only.
The 'Preview page' button is $_POST['submit2'] which actions at the top of index.php in admin. Amongst other things, the action must:
- before showing the preview page, check whether a page title was entered,
- before showing the preview page, check whether any content was entered, and
- make sure the preview doesn't lose the content of index.php when the preview page 'edit' link is clicked to go back to it.
How 'preview' works
(assuming a page title and content were entered)
- The 'Preview page' button is pressed.
- If a file preview.txt exists, it is deleted.
- A temporary new text file preview.txt is created.
- The content is written to it.
- A 'header' location 'https://example.com/preview?page=page-title' is set, replacing index.php.
- inc/edit.php in the page being previewed GETs the value of '?page' from the URL parameter
- ... with the return 'edit' link as 'https:example.com/index.php?page=page-title&mode=preview'
The return 'edit' link re-opens index.php with the page title and content unchanged. index.php does this by:
- $mode = $_GET['mode'] which = 'preview'
- Populating the content box with the contents of 'preview.txt'
- then deleting 'preview.txt' ready for the next preview.
See information