Last active
December 20, 2015 12:49
-
-
Save sachac/6134428 to your computer and use it in GitHub Desktop.
Patch for shareadraft to add a box to the post edit page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/shareadraft.php b/shareadraft.php | |
index 4db1751..8fd329e 100644 | |
--- a/shareadraft.php | |
+++ b/shareadraft.php | |
@@ -23,7 +23,8 @@ class ShareADraft { | |
add_action('admin_menu', array($this, 'add_admin_pages')); | |
add_filter('the_posts', array($this, 'the_posts_intercept')); | |
add_filter('posts_results', array($this, 'posts_results_intercept')); | |
- | |
+ add_action('add_meta_boxes', array($this, 'add_meta_boxes')); | |
+ add_action('save_post', array($this, 'save_postdata')); | |
$this->admin_options = $this->get_admin_options(); | |
$this->admin_options = $this->clear_expired($this->admin_options); | |
$this->user_options = ($current_user->id > 0 && isset($this->admin_options[$current_user->id]))? $this->admin_options[$current_user->id] : array(); | |
@@ -411,6 +412,56 @@ SELECT; | |
</script> | |
<?php | |
} | |
+ | |
+ function add_meta_boxes() { | |
+ add_meta_box('shareadraft', | |
+ __('Share a Draft', 'shareadraft'), | |
+ array($this, 'shareadraft_custom_box'), | |
+ 'post'); | |
+ } | |
+ | |
+ function shareadraft_custom_box($post) { | |
+ if ($post->status == "publish") { | |
+ echo _e('The post is published!', 'shareadraft'); | |
+ return; | |
+ } | |
+ | |
+ wp_nonce_field(plugin_basename(__FILE__), 'shareadraft_nonce' ); | |
+ $shared = $this->get_shared(); | |
+ $found = null; | |
+ foreach ($shared as $share) { | |
+ if ($share['id'] == $post->ID) { | |
+ $found = $share; | |
+ break; | |
+ } | |
+ } | |
+ if ($found) { | |
+ echo '<label for="shareadraft_link">'; | |
+ _e("Link", 'shareadraft' ); | |
+ echo '</label> '; | |
+ $url = get_bloginfo('url') . '/?p=' . $post->ID . '&shareadraft='. $found['key']; | |
+ echo '<input name="shareadraft_link" value="' . esc_url($url) . '" /><br />'; | |
+ echo _e('Expires after', 'shareadraft') . ': ' . $this->friendly_delta($found['expires'] - time()) . '<br />'; | |
+ } else { | |
+ echo $this->tmpl_measure_select(); | |
+ echo '<input type="submit" name="shareadraft_submit" value="' . __('Share a Draft', 'shareadraft') . '" class="button shareadraft" />'; | |
+ } | |
+ } | |
+ | |
+ function save_postdata() { | |
+ // check if this isn't an auto save | |
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
+ return; | |
+ | |
+ // security check | |
+ if ( !wp_verify_nonce( $_POST['shareadraft_nonce'], plugin_basename( __FILE__ ) ) ) | |
+ return; | |
+ if ($_POST['shareadraft_submit']) { | |
+ $this->process_post_options(array('post_id' => $_POST['post_ID'], | |
+ 'expires' => $_POST['expires'], | |
+ 'measure' => $_POST['measure'])); | |
+ } | |
+ } | |
} | |
endif; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment