Ticket #438: bbpress-integration.2.php

File bbpress-integration.2.php, 3.1 kB (added by mdawaffe, 2 years ago)

NEW version

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.74
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         if ( file_exists(ABSPATH . WPINC . '/registration-functions.php') )
29             require_once( ABSPATH . WPINC . '/registration-functions.php' );
30         elseif ( file_exists(ABSPATH . WPINC . '/registration.php' ) )
31             require_once( ABSPATH . WPINC . '/registration.php' );
32         if ( function_exists('wp_update_user') )
33             wp_update_user( array('ID' => $current_user->ID) ); // Sets up nicename and display_name
34     }
35 }
36
37 // UI
38
39 function bb_int_admin_menu() {
40     add_submenu_page( 'plugins.php', __('bbPress Integration'), __('bbPress'), 'manage_options', 'bbpress-integration', 'bb_int_admin_page' );
41 }
42
43 function bb_int_admin_page() {
44     if ( !current_user_can('manage_options') ) : ?>
45 <div id="message" class="error fade-ff0000">
46     <p><?php _e("Now, you aren't supposed to be here, are you?"); ?></p>
47 </div>
48 <?php    return; endif;
49
50     if ( isset($_POST['bbpress-integration']) ) :
51         $bb_table_prefixen = explode(',', $_POST['bbpress-integration']);
52         foreach ( array_keys($bb_table_prefixen) as $p ) {
53             $bb_table_prefixen[$p] = preg_replace('/[^A-Za-z0-9_]/', '', $bb_table_prefixen[$p]);
54             if ( empty($bb_table_prefixen[$p]) )
55                 unset($bb_table_prefixen[$p]);
56         }
57         update_option( 'bbpress-integration', $bb_table_prefixen ); ?>
58 <div id="message" class="updated fade">
59     <p><?php _e("bbPress integration options updated"); ?></p>
60 </div>
61 <?php    endif;
62
63     if ( $bbpress_integration = get_option( 'bbpress-integration' ) )
64         $bbpress_integration = join(', ', $bbpress_integration);
65     else
66         $bbpress_integration = '';
67 ?>
68 <div class="wrap">
69     <h2><?php _e('bbPress Integration'); ?></h2>
70     <form action="" method="post">
71         <p>
72             <?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."); ?>
73         </p>
74         <p>
75             <?php _e('Example'); ?>: <code>bb_</code>
76         </p>
77         <h3><label for='bbpress-integration'><?php _e('bbPress table prefixes'); ?></label></h3>
78         <input type="text" name="bbpress-integration" id="bbpress-integration" value="<?php echo $bbpress_integration; ?>" />
79         <p class="submit">
80             <input type="submit" value="<?php _e('Update bbPress Integration Options &raquo;'); ?>" />
81         </p>
82     </form>
83 </div>
84 <?php
85 }
86
87 add_action( 'admin_menu', 'bb_int_admin_menu' );
88 add_action( 'set_current_user', 'bb_int_set_current_user' );
89 ?>
90