root/per-post-anonymous-comments/trunk/per-post-anonymous-comments.php

Revision 6834, 2.7 kB (checked in by choan, 2 years ago)

Added plugin URL

Line 
1 <?php
2 /*
3 Plugin Name: Per post anonymous comments
4 Plugin URI: http://dev.wp-plugins.org/browser/per-post-anonymous-comments/
5 Description: Wordpress has a setting called "Users must be registered and logged in to comment". This setting is system wide, so there is no option to allow anonymous comments in desired posts or pages (such as a guestbook). This plugin adds a checkbox to the edit screen to bypass the system wide restriction.
6 Version: 0.1
7 Author: Choan C. Gálvez <choan.galvez@gmail.com>
8 Author URI: http://dizque.lacalabaza.net/
9 */
10
11 /* 
12     Copyright 2006  Choan C. Gálvez  (email: choan.galvez@gmail.com)
13
14     This program is free software; you can redistribute it and/or modify
15     it under the terms of the GNU General Public License as published by
16     the Free Software Foundation; either version 2 of the License, or
17     (at your option) any later version.
18
19     This program is distributed in the hope that it will be useful,
20     but WITHOUT ANY WARRANTY; without even the implied warranty of
21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22     GNU General Public License for more details.
23
24     You should have received a copy of the GNU General Public License
25     along with this program; if not, write to the Free Software
26     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 ?>
Note: See TracBrowser for help on using the browser.