Ticket #438: bbpress-integration.php

File bbpress-integration.php, 2.8 kB (added by mdawaffe, 2 years ago)
Line 
1 <?php
2 /*
3 Plugin Name: bbPress Integration
4 Plugin URI: http://bbpress.org/#
5 Description: Synchronizes registrations on your bbPress installation with your WordPress blog.
6 Author: Michael Adams
7 Version: 0.72
8 Author URI: http://blogwaffe.com/
9 */
10
11 // Backend
12
13 function bb_int_set_current_user() {
14     global $current_user;
15     if ( !is_user_logged_in() || $current_user->caps ) // Only hit logged in users with no caps
16         return;
17     if ( !$bb_table_prefixen = get_option( 'bbpress-integration' ) ) // Only hit these prefixes
18         return;
19
20     foreach ( (array) $bb_table_prefixen as $prefix ) {
21         if ( $caps = get_usermeta( $current_user->ID, $prefix . 'capabilities' ) ) {
22             $current_user->set_role( get_option( 'default_role' ) );
23             continue;
24         }
25     }
26
27     if ( empty($current_user->data->display_name) ) {
28         require_once( ABSPATH . WPINC . '/registration-functions.php' );
29         wp_update_user( array('ID' => $current_user->ID) ); // Sets up nicename and display_name
30     }
31 }
32
33 // UI
34
35 function bb_int_admin_menu() {
36     add_submenu_page( 'plugins.php', __('bbPress Integration'), __('bbPress'), 'manage_options', 'bbpress-integration', 'bb_int_admin_page' );
37 }
38
39 function bb_int_admin_page() {
40     if ( !current_user_can('manage_options') ) : ?>
41 <div id="message" class="error fade-ff0000">
42     <p><?php _e("Now, you aren't supposed to be here, are you?"); ?></p>
43 </div>
44 <?php    return; endif;
45
46     if ( isset($_POST['bbpress-integration']) ) :
47         $bb_table_prefixen = explode(',', $_POST['bbpress-integration']);
48         foreach ( array_keys($bb_table_prefixen) as $p ) {
49             $bb_table_prefixen[$p] = preg_replace('/[^A-Za-z0-9_]/', '', $bb_table_prefixen[$p]);
50             if ( empty($bb_table_prefixen[$p]) )
51                 unset($bb_table_prefixen[$p]);
52         }
53         update_option( 'bbpress-integration', $bb_table_prefixen ); ?>
54 <div id="message" class="updated fade">
55     <p><?php _e("bbPress integration options updated"); ?></p>
56 </div>
57 <?php    endif;
58
59     if ( $bbpress_integration = get_option( 'bbpress-integration' ) )
60         $bbpress_integration = join(', ', $bbpress_integration);
61     else
62         $bbpress_integration = '';
63 ?>
64 <div class="wrap">
65     <h2><?php _e('bbPress Integration'); ?></h2>
66     <form action="" method="post">
67         <p>
68             <?php _e("Enter the table prefix for your bbPress installation below.  The table prefix is found in your bbPress installation's <code>config.php</code> file.  You may list multiple table prefixes by separating them with commas."); ?>
69         </p>
70         <p>
71             <?php _e('Example'); ?>: <code>bb_</code>
72         </p>
73         <h3><label for='bbpress-integration'><?php _e('bbPress table prefixes'); ?></label></h3>
74         <input type="text" name="bbpress-integration" id="bbpress-integration" value="<?php echo $bbpress_integration; ?>" />
75         <p class="submit">
76             <input type="submit" value="<?php _e('Update bbPress Integration Options &raquo;'); ?>" />
77         </p>
78     </form>
79 </div>
80 <?php
81 }
82
83 add_action( 'admin_menu', 'bb_int_admin_menu' );
84 add_action( 'set_current_user', 'bb_int_set_current_user' );
85 ?>
86