Public Post Preview - Version 1.0

Version Description

(2009-02-20): = * Initial Public Release

Download this release

Release Info

Developer sivel
Plugin Icon 128x128 Public Post Preview
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (3) hide show
  1. public-post-preview.php +113 -0
  2. readme.txt +44 -0
  3. screenshot-1.png +0 -0
public-post-preview.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Public Post Preview
4
+ Plugin URI: http://sivel.net/wordpress/
5
+ Description: Enables you to give a link to anonymous users for public preview of a post before it is published.
6
+ Author: Matt Martz
7
+ Version: 1.0
8
+ Author URI: http://sivel.net/
9
+ */
10
+
11
+ class Public_Post_Preview {
12
+
13
+ // Variable place holder for post ID for easy passing between functions
14
+ var $id;
15
+
16
+ // Plugin startup
17
+ function Public_Post_Preview() {
18
+ if (!is_admin()) {
19
+ add_action('init', array(&$this, 'show_preview'));
20
+ } else {
21
+ register_activation_hook(__FILE__, array(&$this, 'init'));
22
+ add_action('admin_menu', array(&$this, 'meta_box'));
23
+ add_action('save_post', array(&$this, 'save_post'));
24
+ }
25
+ }
26
+
27
+ // Initialize plugin
28
+ function init() {
29
+ if ( !get_option('public_post_preview') )
30
+ add_option('public_post_preview', array());
31
+ }
32
+
33
+ // verify a nonce
34
+ function verify_nonce($nonce, $action = -1) {
35
+ $i = wp_nonce_tick();
36
+ if ( substr(wp_hash($i . $action, 'nonce'), -12, 10) == $nonce )
37
+ return 12;
38
+ if ( substr(wp_hash(($i - 1) . $action, 'nonce'), -12, 10) == $nonce )
39
+ return 24;
40
+ return false;
41
+ }
42
+
43
+ // create a nonce
44
+ function create_nonce($action = -1) {
45
+ $i = wp_nonce_tick();
46
+ return substr(wp_hash($i . $action, 'nonce'), -12, 10);
47
+ }
48
+
49
+ // Content for meta box
50
+ function preview_link($post) {
51
+ $preview_posts = get_option('public_post_preview');
52
+ if ( in_array($post->post_status, array('draft', 'pending')) ) {
53
+ ?>
54
+ <p>
55
+ <label for="public_preview_status" class="selectit">
56
+ <input type="checkbox" name="public_preview_status" id="public_preview_status"<?php if ( !isset($preview_posts[$post->ID]) ) echo ' checked="checked"'; ?>/>
57
+ Public Preview
58
+ </label>
59
+ </p>
60
+ <?php
61
+ if ( !isset($preview_posts[$post->ID]) ) {
62
+ $this->id = (int) $post->ID;
63
+ $nonce = $this->create_nonce('public_post_preview_' . $this->id);
64
+
65
+ $url = htmlentities(add_query_arg(array('preview' => 'true', 'preview_id' => $this->id, 'public' => true, 'nonce' => $nonce), get_permalink($this->id)));
66
+
67
+ echo "<p><a href='$url'>$url</a><br /><br />\r\n";
68
+ }
69
+ } else {
70
+ echo '<p>This post is already public. Public post preview not available.</p>';
71
+ }
72
+ }
73
+
74
+ // Register meta box
75
+ function meta_box() {
76
+ add_meta_box('publicpostpreview', 'Public Post Preview', array(&$this, 'preview_link'), 'post', 'normal', 'high');
77
+ }
78
+
79
+ // Update options on post save
80
+ function save_post($post) {
81
+ $preview_posts = get_option('public_post_preview');
82
+ $post_id = $_POST['post_ID'];
83
+ if ( $post != $post_id )
84
+ return;
85
+ if ( (isset($_POST['public_preview_status']) && $_POST['public_preview_status'] == 'on') && in_array($_POST['post_status'], array('draft', 'pending')) && isset($preview_posts[$post_id]) ) {
86
+ unset($preview_posts[$post_id]);
87
+ } elseif ( !isset($_POST['public_preview_status']) && $_POST['original_post_status'] != 'publish' && in_array($_POST['post_status'], array('draft', 'pending')) && !isset($preview_posts[$post_id]) ) {
88
+ $preview_posts[$post_id] = false;
89
+ }
90
+ update_option('public_post_preview', $preview_posts);
91
+ }
92
+
93
+ // Show the post preview
94
+ function show_preview() {
95
+ if ( !is_admin() && isset($_GET['p']) && isset($_GET['preview_id']) && isset($_GET['preview']) && isset($_GET['public']) && isset($_GET['nonce']) ) {
96
+ $this->id = (int) $_GET['preview_id'];
97
+ $preview_posts = get_option('public_post_preview');
98
+
99
+ if ( false == $this->verify_nonce($_GET['nonce'], 'public_post_preview_' . $this->id) || isset($preview_posts[$this->id]) )
100
+ wp_die('You do not have permission to publicly preview this post.');
101
+
102
+ add_filter('the_posts', array(&$this, 'insert_preview'));
103
+ }
104
+ }
105
+
106
+ // Insert the requested preview post into posts array
107
+ function insert_preview($posts) {
108
+ $posts[] = get_post($this->id);
109
+ return $posts;
110
+ }
111
+ }
112
+ $public_post_preview = new Public_Post_Preview();
113
+ ?>
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Public Post Preview ===
2
+ Contributors: sivel
3
+ Donate Link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=C3UA7TDWM4NLQ&lc=US&item_name=Donations%20for%20Sivel%2enet%20WordPress%20Plugins&cn=Add%20special%20instructions%20to%20the%20seller&no_shipping=1&rm=1&return=http%3a%2f%2fsivel%2enet%2fthanks&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
4
+ Tags: public-post-preview, public, post, preview, posts
5
+ Requires at least: 2.7
6
+ Tested up to: 2.7
7
+ Stable tag: 1.0
8
+
9
+ Enables you to give a link to anonymous users for public preview of a post before it is published.
10
+
11
+ == Description ==
12
+
13
+ Enables you to give a link to anonymous users for public preview of a post before it is published.
14
+
15
+ Have you ever been writing a post with the help of someone who does not have access to your blog and needed to give them the ability to preview it before publishing? This plugin takes care of that by generating a URL with an expiring nonce that can be given out for public preview.
16
+
17
+ Props to [Jonathan Dingman](http://www.ginside.com/) for the idea behind this plugin, testing and feedback.
18
+
19
+ == Installation ==
20
+
21
+ 1. Upload the `public-post-preview` folder to the `/wp-content/plugins/` directory or install directly through the plugin installer.
22
+ 1. Activate the plugin through the 'Plugins' menu in WordPress or by using the link provided by the plugin installer
23
+
24
+ NOTE: See "Other Notes" for Upgrade and Usage Instructions as well as other pertinent topics.
25
+
26
+ == Screenshots ==
27
+
28
+ 1. Edit Posts Page
29
+
30
+ == Upgrade ==
31
+
32
+ 1. Use the plugin updater in WordPress or...
33
+ 1. Delete the previous `public-post-preview` folder from the `/wp-content/plugins/` directory
34
+ 1. Upload the new `public-post-preview` folder to the `/wp-content/plugins/` directory
35
+
36
+ == Usage ==
37
+
38
+ 1. By default all posts in draft or pending review status will have public preview links that can be found diretly below the edit post box.
39
+ 1. To disable public post preview for a specific post uncheck the public preview post box and save the post.
40
+
41
+ == Changelog ==
42
+
43
+ = 1.0 (2009-02-20): =
44
+ * Initial Public Release
screenshot-1.png ADDED
Binary file