true, 'read' => true ); if (bb_get_option('bb_anon_write_topics') == 'Y') $perm_array['write_topics'] = true; $bb_roles->add_role('anonymous', $perm_array, 'Anonymous'); if ('bb-post' == bb_get_location()) bb_anon_spoof_user(); } // remove auth function for the bb-post page // !function_exists is used only during plugin activation if (!function_exists('bb_auth') && 'bb-post' == bb_get_location()) { function bb_auth() {} } // meat of the plugin function bb_anon_spoof_user() { global $bb_current_user; if (!$bb_current_user) { $anon_id = bb_get_option('bb_anon_user_id'); if (!$anon_id) { bb_anon_activate_plugin(); $anon_id = bb_get_option('bb_anon_user_id'); } $bb_current_user = new BB_User($anon_id); } } // remove meat of the plugin function bb_anon_unspoof_user() { global $bb_current_user, $bb_roles; if ($bb_current_user->has_cap('anonymous')) { $bb_current_user = false; } if (is_forum() && bb_get_option('bb_anon_write_topics') != "Y") { echo '
'; printf(__('You must log in to post.'), attribute_escape( bb_get_option('uri') . 'bb-login.php' )); echo '
'; } } // activate plugin // create a anonymous user // // if the option for the anonmous user id is set, set the user id to that value // this is to keep the user id consitent if you deactivate and activate it a couple of times // // add anonymous roles add_action('bb_activate_plugin_' . bb_plugin_basename(__FILE__), 'bb_anon_activate_plugin'); function bb_anon_activate_plugin() { global $bbdb; $bbdb->query("INSERT INTO $bbdb->users (user_login,user_nicename, user_registered) VALUES ('anonymous','Anonymous', '" . bb_current_time('mysql') . "')"); if ($anon_id = bb_get_option('bb_anon_user_id')) { $bbdb->query("UPDATE $bbdb->users SET ID = $anon_id where ID = " . $bbdb->insert_id); } else { $anon_id = $bbdb->insert_id; bb_update_option('bb_anon_user_id', $anon_id); } $user = new BB_User($anon_id); $user->add_role('anonymous'); $user->remove_role('member'); $user->add_cap('anonymous'); $user->remove_cap('member'); } // remove user and meta data on deactivation // do note remove the option in case you activate the plugin again later add_action('bb_deactivate_plugin_' . bb_plugin_basename(__FILE__), 'bb_anon_deactivate_plugin'); function bb_anon_deactivate_plugin() { global $bbdb; $anon_id = bb_get_option('bb_anon_user_id'); $bbdb->query("DELETE FROM $bbdb->users WHERE ID = '$anon_id'"); $bbdb->query("DELETE FROM $bbdb->usermeta WHERE user_id = '$anon_id'"); } // fixes the frontpage link to add new post add_filter('new_topic_url', 'bb_anon_filter_new_topic_url'); function bb_anon_filter_new_topic_url($url) { if (is_front() && bb_get_option('bb_anon_write_topics') == "Y") $url = add_query_arg('new', '1', bb_get_option('uri')); return $url; } // this fixes the display name and title for the anonymous user on the topic page add_filter('get_post_author_id', 'bb_anon_filter_poster_id'); function bb_anon_filter_poster_id($poster_id) { if ($poster_id == bb_get_option('bb_anon_user_id')) return 0; else return $poster_id; } // this fixes the display names for topic last poster or topic author add_filter('get_topic_last_poster','bb_anon_filter_poster'); add_filter('get_topic_author','bb_anon_filter_poster'); add_filter('post_author', 'bb_anon_filter_poster'); function bb_anon_filter_poster($last_poster) { if ($last_poster == 'Anonymous' || $last_poster == 'anonymous') return bb_anon_get_user_text(); else return $last_poster; } function bb_anon_get_user_text() { return ($user_text = bb_get_option('bb_anon_user_text')) ? $user_text : "Anonymous"; } // admin functionality if (!BB_IS_ADMIN) return; add_action( 'bb_admin_menu_generator', 'bb_anon_add_admin_page' ); function bb_anon_add_admin_page() { bb_admin_add_submenu(__('Anonymous Posting'), 'use_keys', 'bb_anon_settings_page', 'options-general.php'); } function bb_anon_settings_page() { $write_topics = bb_get_option('bb_anon_write_topics'); ?>