WP Multisite and WP_w3all phpBB WordPress integration
Posted: Sun Apr 16, 2017 10:50 am
This topic is for testing purpose about WorPress phpBB integration plugin into a WordPress Multisite installation.
Open class.wp.w3all-phpbb.php file
search for:
immediately AFTER add the follow:
Save. Now open: wp_w3all.php file
search for:
immediately BEFORE add the follow:
i can provide files instead of code if more comfortable. The code need some little adjustment more, but is working fine on my test at moment.
Open class.wp.w3all-phpbb.php file
search for:
Code: Select all
//############################################
// END PHPBB TO WP FUNCTIONS
//############################################
Code: Select all
//############################################
// START X WP MS MU
//############################################
public static function create_phpBB_user_wpms_res($username = '', $user_email = '', $key = '', $meta = ''){
$r = self::create_phpBB_user_wpms($username, $user_email, $key, $meta);
return $r;
}
public static function wp_w3all_wp_after_pass_reset_msmu( $user ) {
global $w3all_config,$wpdb;
$w3db_conn = self::wp_w3all_phpbb_conn_init();
$phpbb_config_file = $w3all_config;
$user_email_hash = self::w3all_phpbb_email_hash($user->user_email);
$res = $w3db_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."users SET user_password = '".$user->user_pass."' WHERE user_email_hash = '".$user_email_hash."'");
}
private static function create_phpBB_user_wpms($username = '', $user_email = '', $key = '', $meta = ''){
global $w3all_config, $w3all_phpbb_lang_switch_yn;
$phpbb_config_file = $w3all_config;
$w3phpbb_conn = self::w3all_db_connect();
$phpbb_config = unserialize(W3PHPBBCONFIG);
$wp_lang = get_option('WPLANG');
if(empty($wp_lang) OR $w3all_phpbb_lang_switch_yn == 0 ){ // wp lang for this user ISO 639-1 Code. en_EN // en = Lang code _ EN = Country code
$wp_lang_x_phpbb = 'en'; // no lang setting, assume en by default
} else {
$wp_lang_x_phpbb = strtolower(substr($wp_lang, 0, strpos($wp_lang, '_'))); // should extract Lang code ISO Code that is phpBB suitable for this lang
}
if( empty($username) OR empty($user_email) ){ return; }
//maybe to be added as option
// if you wish to setup gravatar by default into phpBB profile for the user when register in WP
$uavatar = $avatype = ''; // this not will affect queries if the two here below are or not commented out
//$uavatar = get_option('show_avatars') == 1 ? $wpu->user_email : '';
//$avatype = (empty($uavatar)) ? '' : 'avatar.driver.gravatar';
$username = esc_sql($username);
$u = $phpbb_config["cookie_name"].'_u';
if ( preg_match('/[^0-9]/',$_COOKIE[$u]) ){
die( "Clean up cookie on your browser please!" );
}
$phpbb_u = $_COOKIE[$u];
// only need to fire when user do not exist on phpBB already, and/or user is an admin that add an user manually
if ( $phpbb_u < 2 OR !empty($phpbb_u) && current_user_can( 'manage_options' ) === true ) {
$phpbb_user_type = 1; // set to 1 as deactivated on phpBB on WP MSMU
$user_email_hash = self::w3all_phpbb_email_hash($user_email);
$wpur = time();
$wpul = $username;
$wpup = md5(mt_rand(5,10) . microtime() . str_shuffle("ALEa0bc1AdeOf28P3ghEij4kRlm5nopqrD0Lst9uvwx9yzSSIO" . microtime()) . mt_rand(10,20)); // a temp pass to be updated after signup finished
$wpup = self::phpBB_password_hash($wpup); // a temp pass, even not necessary as the user is not active at this point for wp msmu
$wpue = $user_email;
$time = time();
$wpunn = esc_sql(utf8_encode(strtolower($wpul)));
$wpul = esc_sql($wpul);
$w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."users (user_id, user_type, group_id, user_permissions, user_perm_from, user_ip, user_regdate, username, username_clean, user_password, user_passchg, user_email, user_email_hash, user_birthday, user_lastvisit, user_lastmark, user_lastpost_time, user_lastpage, user_last_confirm_key, user_last_search, user_warnings, user_last_warning, user_login_attempts, user_inactive_reason, user_inactive_time, user_posts, user_lang, user_timezone, user_dateformat, user_style, user_rank, user_colour, user_new_privmsg, user_unread_privmsg, user_last_privmsg, user_message_rules, user_full_folder, user_emailtime, user_topic_show_days, user_topic_sortby_type, user_topic_sortby_dir, user_post_show_days, user_post_sortby_type, user_post_sortby_dir, user_notify, user_notify_pm, user_notify_type, user_allow_pm, user_allow_viewonline, user_allow_viewemail, user_allow_massemail, user_options, user_avatar, user_avatar_type, user_avatar_width, user_avatar_height, user_sig, user_sig_bbcode_uid, user_sig_bbcode_bitfield, user_jabber, user_actkey, user_newpasswd, user_form_salt, user_new, user_reminded, user_reminded_time)
VALUES ('','$phpbb_user_type','2','','0','', '$wpur', '$wpul', '$wpunn', '$wpup', '0', '$wpue', '$user_email_hash', '', '', '', '', '', '', '0', '0', '0', '0', '0', '0', '0', '$wp_lang_x_phpbb', 'Europe/Rome', 'D M d, Y g:i a', '1', '0', '', '0', '0', '0', '0', '-3', '0', '0', 't', 'd', 0, 't', 'a', '0', '1', '0', '1', '1', '1', '1', '230271', '$uavatar', '$avatype', '0', '0', '', '', '', '', '', '', '', '0', '0', '0')");
$phpBBlid = $w3phpbb_conn->insert_id;
$w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('2','$phpBBlid','0','0')");
$w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('7','$phpBBlid','0','0')");
$w3phpbb_conn->query("INSERT INTO ".$phpbb_config_file["table_prefix"]."acl_users (user_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ('$phpBBlid','0','0','6','0')");
$tot_users_count = $w3phpbb_conn->get_var("SELECT COUNT(*) FROM ".$phpbb_config_file["table_prefix"]."users WHERE group_id !='6' AND group_id !='1'");
$w3phpbb_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."config SET config_value = '$tot_users_count' WHERE config_name = 'num_users'");
$newest_member = $w3phpbb_conn->get_results("SELECT * FROM ".$phpbb_config_file["table_prefix"]."users WHERE user_id = (SELECT Max(user_id) FROM ".$phpbb_config_file["table_prefix"]."users) AND group_id != '6'");
$uname = $newest_member[0]->username;
$uid = $newest_member[0]->user_id;
$w3phpbb_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."config SET config_value = '$wpul' WHERE config_name = 'newest_username'");
$w3phpbb_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."config SET config_value = '$uid' WHERE config_name = 'newest_user_id'");
}// if cookie not set
}
//############################################
// END X WP MS MU
//############################################
search for:
Code: Select all
} // END if ( defined('PHPBB_INSTALLED') ){ // 2nd not in admin
Code: Select all
/////////////////////////
// W3ALL WPMS MU START
/////////////////////////
function wpmu_activate_user_phpbb( $user_id, $password, $meta ) {
global $w3all_config,$w3all_phpbb_user_deactivated_yn;
$w3db_conn = WP_w3all_phpbb::wp_w3all_phpbb_conn_init();
$phpbb_config_file = $w3all_config;
$user = get_user_by('id', $user_id);
$user_info = get_userdata($user->ID);
$wp_user_role = implode(', ', $user_info->roles);
$phpbb_user_data = WP_w3all_phpbb::wp_w3all_get_phpbb_user_info($user->user_email);
$password = WP_w3all_phpbb::phpBB_password_hash($password);
if ( $phpbb_user_data[0]->user_type == 1 ) {
$res = $w3db_conn->query("UPDATE ".$phpbb_config_file["table_prefix"]."users SET user_type = '0', user_password = '".$password."' WHERE user_email_hash = '".$phpbb_user_data[0]->user_email_hash."'");
}
}
function w3all_wpmu_new_user_up_pass( $user_id ) {
$wpu = get_user_by('id', $user_id);
$phpBB_user_activate = WP_w3all_phpbb::wp_w3all_wp_after_pass_reset_msmu($wpu); // msmu: the pass updated is the one of WP
}
function w3all_wpmu_new_user_signup( $user, $user_email, $key, $meta ) {
$phpBB_user_add = WP_w3all_phpbb::create_phpBB_user_wpms_res( $user, $user_email, $key, $meta );
}
function w3all_wpmu_validate_user_signup( $result ){
$wp_w3_ck_phpbb_ue_exist = WP_w3all_phpbb::phpBB_user_check($result['user_name'], $result['user_email'], 0);
if($wp_w3_ck_phpbb_ue_exist === true){
temp_wp_w3_error_on_update();
exit;
}
return $result;
}
add_filter( 'wpmu_validate_user_signup', 'w3all_wpmu_validate_user_signup', 10, 1 );
add_action( 'after_signup_user', 'w3all_wpmu_new_user_signup', 10, 4 );
add_action( 'wpmu_activate_user', 'wpmu_activate_user_phpbb', 10, 3 );
add_action( 'wpmu_new_user', 'w3all_wpmu_new_user_up_pass', 10, 1 );
/////////////////////////
// W3ALL WPMS MU END
/////////////////////////