| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
function ppac_filter($opt) { |
|---|
| 30 |
global $post; |
|---|
| 31 |
global $comment_post_ID; |
|---|
| 32 |
if (!$opt || is_admin()) return $opt; |
|---|
| 33 |
$id = 0; |
|---|
| 34 |
if ($post && $post->ID) { |
|---|
| 35 |
$id = $post->ID; |
|---|
| 36 |
} else { |
|---|
| 37 |
$id = $comment_post_ID; |
|---|
| 38 |
} |
|---|
| 39 |
$allow = get_post_meta($id, "_anonymous_comments", true); |
|---|
| 40 |
return $allow == 1 ? 0 : 1; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
function ppac_checkbox() { |
|---|
| 44 |
if (!get_settings("comment_registration")) return; |
|---|
| 45 |
$allow = get_post_meta($_REQUEST['post'], '_anonymous_comments', true); |
|---|
| 46 |
$check = $allow ? 'checked="checked" ' : ''; |
|---|
| 47 |
echo '<fieldset id="ppac_dbx" class="dbx-box">'; |
|---|
| 48 |
echo '<h3 class="dbx-handle">', __('Anonymous comments', 'ppac'), '</h3>'; |
|---|
| 49 |
echo '<div class="dbx-content">'; |
|---|
| 50 |
echo '<label for="ppac" class="selectit"><input type="checkbox" name="ppac" id="ppac" value="1" '. $check . '/> '. __('Allow anonymous comments', 'ppac') . '</label></div></fieldset>'; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
function ppac_update_post($id) { |
|---|
| 54 |
delete_post_meta($id, '_anonymous_comments'); |
|---|
| 55 |
$setting = (isset($_POST["ppac"]) && $_POST["ppac"] == "1") ? 1 : 0; |
|---|
| 56 |
add_post_meta($id, '_anonymous_comments', $setting); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
load_plugin_textdomain('ppac', 'wp-content/plugins/per-post-anonymous-comments'); |
|---|
| 60 |
|
|---|
| 61 |
add_filter("option_comment_registration", "ppac_filter"); |
|---|
| 62 |
add_action("dbx_post_sidebar", "ppac_checkbox"); |
|---|
| 63 |
add_action("dbx_page_sidebar", "ppac_checkbox"); |
|---|
| 64 |
add_action('save_post', 'ppac_update_post'); |
|---|
| 65 |
add_action('edit_post', 'ppac_update_post'); |
|---|
| 66 |
add_action('publish_post', 'ppac_update_post'); |
|---|
| 67 |
|
|---|
| 68 |
?> |
|---|