Trying to make 2 wordpress plugins compatible
-
Hi there, maybe im trying to do somthing that no-one has thought of yet or maybe im just rubbish at researching on the internet.
I have a wordpress blog and I have restricted the login to only allow people to join via a facebook connect button (Plugin: Facebook AWD)
I am also trying to create an afilliate page for people to refer their friends using Affiliate Plus Plugin
I cant seem to work out how to insert the affiliate plus hooks to work when someone registers with the facebook connect plugin
Below is the facebook login process file:
<?php /* * * login AWD FCBK * (C) 2011 AH WEB DEV * Hermann.alexandre@ahwebdev.fr */ /* * Version for PHP SDK 3.1.1 */ if($this->uid){ //if user is logged in, then we just need to associate FB account with WordPress account if(is_user_logged_in()){ $step = 'logged'; }else{ //check if user has account in the website. get id $existing_user = $this->wpdb->get_var( 'SELECT DISTINCT <code>u</code>.<code>ID</code> FROM <code>' . $this->wpdb->users . '</code> <code>u</code> JOIN <code>' . $this->wpdb->usermeta . '</code> <code>m</code> ON <code>u</code>.<code>ID</code> = <code>m</code>.<code>user_id</code> WHERE (<code>m</code>.<code>meta_key</code> = "fb_uid" AND <code>m</code>.<code>meta_value</code> = "' . $this->uid . '" ) OR user_email = "' . $fcbk_user_infos['email'] . '" OR (<code>m</code>.<code>meta_key</code> = "fb_email" AND <code>m</code>.<code>meta_value</code> = "' . $fcbk_user_infos['email'] . '" ) LIMIT 1 '); //if the user exists - set cookie, do wp_login, redirect and exit if($existing_user > 0){ $step = 'sync'; //if user don't exist - create one and do all the same stuff: cookie, wp_login, redirect, exit }else{ $step = 'register'; } } switch($step){ /*********************************************/ // User logged in /*********************************************/ case 'logged': $fb_uid = get_user_meta($this->current_user->ID,'fb_uid', true); $fb_email = get_user_meta($this->current_user->ID,'fb_email', true); if(!$fb_uid OR $fb_email == '' OR count($this->me)==0){ $this->me = $this->fcbk->api('/me'); update_user_meta($this->current_user->ID,'fb_uid',$this->uid);//refetch data form Facebook api update_user_meta($this->current_user->ID,'fb_email',$this->me['email']);//refetch data form Facebook api update_user_meta($this->current_user->ID,'fb_user_infos',$this->me); } $this->debug_echo[] = "User connected"; return true; break; /*********************************************/ // User sync and logged in (After Log in process) /*********************************************/ case 'sync': $fb_uid = get_user_meta($existing_user, 'fb_uid', true); $fb_email = get_user_meta($existing_user, 'fb_email', true); //update user fb infos $this->me = $this->fcbk->api('/me'); update_user_meta($this->current_user->ID,'fb_user_infos',$this->me); if(!$fb_uid) update_user_meta($existing_user, 'fb_uid', $this->uid ); if(!$fb_uid){ update_user_meta($existing_user, 'fb_uid', $this->me['email'] ); } //get user infos $user_info = get_userdata($existing_user); //connect the user $this->connect_the_user($user_info); $this->debug_echo[] = "User login"; $current_url = $this->get_current_url(); if(preg_match('@wp-login.php@',$current_url)) if($_REQUEST['redirect_to'] !='') wp_redirect($_REQUEST['redirect_to']); else wp_redirect(home_url()); else wp_redirect($current_url); exit(); break; /*********************************************/ // User register /*********************************************/ case 'register': $this->me = $this->fcbk->api('/me'); //sanitize username $username = sanitize_user($this->me['first_name'], true); //check if username is taken //if so - add something in the end and check again $i=''; while(username_exists($username . $i)){ $i=absint($i); $i++; } //this will be new user login name $username = $username.$i; //test if we get email, if not call WP die to prevent empty user. if($this->me['email'] ==''){ return false; wp_die(__('Fb connect need email permission to work. You should logout from facebook and try again, then accept email permission',$this-plugin_text_domain)); } //put everything in nice array $userdata = array( 'user_pass' => wp_generate_password(), 'user_login' => $username, 'user_nicename' => $username, 'user_email' => $this->me['email'], 'display_name' => $this->me['name'], 'nickname' => $username, 'first_name' => $this->me['first_name'], 'last_name' => $this->me['last_name'], 'role' => get_option('default_role') ); //create new user $new_user = wp_insert_user($userdata); if($new_user->errors){ wp_die($this->Debug($new_user->errors)); }elseif(is_int($new_user)){ //add user meta fb_uid update_user_meta( $new_user, 'fb_uid', $this->uid ); $user_info = get_userdata($new_user); //send email new registration wp_new_user_notification($user_info->ID, $userdata['user_pass']); //connnect the user $this->connect_the_user($user_info); //do_action('wp_login', $user_info->user_login); $this->debug_echo[] = "User register and was logged in"; if(preg_match('@wp-login.php@',$current_url)) if($_REQUEST['redirect_to'] !='') wp_redirect($_REQUEST['redirect_to']); else wp_redirect(home_url()); else wp_redirect($this->get_current_url()); exit(); } break; default : break; }//end switch } ?>And this is the affiliate plus plugin:
<?php /* Plugin Name: Affiliate Plus Plugin URI: http://blogio.net/blog/affiliate-plus/ Description: Affiliate Plus lets your registered users get credit for new users they recruit Author: Nico Version: 1.3.1 Author URI: http://www.blogio.net/blog/ Questions, sugestions, problems? Let me know at nico@blogio.net */ function affiplus_install() { global $wpdb; //set the options $newoptions['affp_override'] = '1'; $newoptions['affp_expire'] = '30'; $newoptions['affp_trkpar'] = 'affid'; $newoptions['affp_usrpage'] = '1'; $newoptions['affp_showid'] = '1'; add_option('affiliate_plus_cfg', $newoptions); // create table $table = $wpdb->prefix."affp_referrals"; $structure = "CREATE TABLE $table ( affp_id BIGINT(20) unsigned NOT NULL, affp_referral VARCHAR(100) NOT NULL, UNIQUE KEY affp_id (affp_id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($structure); } register_activation_hook(__FILE__,'affiplus_install'); // process incomming referral function affiplus_getreferral() { global $wpdb; $affiliate_plus_cfg = array( 'affp_override' => '', 'affp_expire' => '', 'affp_redir' => '', 'affp_trkpar' => '', 'affp_usrpage' => '', 'affp_land' => '', 'affp_showid' => '' ); $affiliate_plus_cfg = get_option('affiliate_plus_cfg'); if(!($affiliate_plus_cfg['affp_trkpar'])){ $affiliate_plus_cfg['affp_trkpar'] = 'affid'; } foreach ($_GET as $key => $value) { if ($key == $affiliate_plus_cfg['affp_trkpar']) { $affid = $value; } } if(isset($affid)) { if (!$affiliate_plus_cfg['affp_override']){ // check if cookie already exists if(isset($_COOKIE['affiplus'])){ return; } } if($affiliate_plus_cfg['affp_expire']){ $exp = time()+60*60*24*$affiliate_plus_cfg['affp_expire']; } $wp_root = get_option('home'); $htp = "http://"; $htps = "https://"; $affp_domain = str_replace($htp, ".", $wp_root); $affp_domain = str_replace($htps, ".", $affp_domain); $affp_domain = explode("/",$affp_domain); // set cookie setcookie('affiplus', $affid, $exp, '/', $affp_domain[0]); if($affiliate_plus_cfg['affp_land']) { header("Location: ".$affiliate_plus_cfg['affp_land']); exit(0); } } } add_action("init", "affiplus_getreferral"); function affiplus_signupform() { global $wpdb; $affiliate_plus_cfg = array( 'affp_override' => '', 'affp_expire' => '', 'affp_redir' => '', 'affp_trkpar' => '', 'affp_usrpage' => '', 'affp_showid' => '' ); $affiliate_plus_cfg = get_option('affiliate_plus_cfg'); // check if we have a cookie if(isset($_COOKIE['affiplus'])){ $form_referral = $_COOKIE['affiplus']."\" readonly=\"readonly"; if ($affiliate_plus_cfg['affp_showid']){ echo'<p> <label>Referral ID<br /> <input type="text" name="affiplus_referral" id="user_login" class="input" value="'.$form_referral.'" size="20" tabindex="30" /></label> </p>'; } else { echo'<input type="hidden" name="affiplus_referral" id="user_login" class="input" value="'.$form_referral.'" size="20" tabindex="30" />'; } } else { echo'<p> <label>Referral ID<br /> <input type="text" name="affiplus_referral" id="user_login" class="input" value="'.$form_referral.'" size="20" tabindex="30" /></label> </p>'; } } add_action("register_form", "affiplus_signupform"); function affiplus_register($userid) { global $wpdb; $reffered = $_POST['affiplus_referral']; //$reffered = $wpdb->escape($_COOKIE['affiplus']); $table = $wpdb->prefix."affp_referrals"; $wpdb->query("INSERT INTO $table(affp_id, affp_referral) VALUES('$userid', '$reffered')"); } add_action("user_register", "affiplus_register"); function affiplus_settings() { global $wpdb; include 'affipsettings.php'; } function affiplus_menu() { add_submenu_page('options-general.php', 'Affiliate Plus Settings', 'Affiliate Plus', 9, 'affiplus_settings', 'affiplus_settings'); } add_action("admin_menu", "affiplus_menu"); function affiplus_redirect($redirect_to, $requested_redirect_to, $user) { if ( !isset ( $user->user_login ) ) { return $redirect_to; } if($user->user_level){ if($user->user_level > 7){ return $requested_redirect_to; } } $affiliate_plus_cfg = array( 'affp_override' => '', 'affp_expire' => '', 'affp_redir' => '', 'affp_trkpar' => '', 'affp_usrpage' => '', 'affp_showid' => '' ); $affiliate_plus_cfg = get_option('affiliate_plus_cfg'); if ($affiliate_plus_cfg['affp_redir']){ return $affiliate_plus_cfg['affp_redir']; } else { return $requested_redirect_to; } } add_filter("login_redirect", "affiplus_redirect", 10, 3); // Add new column to the user list function affiplus_addcolumn( $columns ) { // This requires WP 2.8+ $columns['affiplus_refbycol'] = __('referred by', 'user-locker'); $columns['affiplus_refcountcol'] = __('referred', 'user-locker'); return $columns; } add_filter("manage_users_columns", "affiplus_addcolumn"); // Add column content for each user on user list function affiplus_fillcolumn( $value, $column_name, $user_id ) { global $wpdb; if ( $column_name == 'affiplus_refbycol' ) { // get referral name $user_info = get_userdata($user_id); $table = $wpdb->prefix."affp_referrals"; $referral = $wpdb->get_var("SELECT affp_referral FROM $table WHERE affp_id=$user_id"); if($referral){ return $referral; }else{ return "-"; } } if ( $column_name == 'affiplus_refcountcol' ) { // count referrals by this user $user_info = get_userdata($user_id); $table = $wpdb->prefix."affp_referrals"; $ref_count = $wpdb->get_var("SELECT COUNT(*) FROM $table WHERE affp_referral = '$user_info->user_login'"); if($ref_count){ return $ref_count; }else{ return "-"; } } return $value; } add_filter("manage_users_custom_column", "affiplus_fillcolumn", 10, 3 ); function affiplus_userpage($user_id) { global $wpdb; $affiliate_plus_cfg = array( 'affp_override' => '', 'affp_expire' => '', 'affp_redir' => '', 'affp_trkpar' => '', 'affp_usrpage' => '', 'affp_showid' => '' ); $affiliate_plus_cfg = get_option('affiliate_plus_cfg'); if(!($affiliate_plus_cfg['affp_trkpar'])){ $affiliate_plus_cfg['affp_trkpar'] = 'affid'; } if ($affiliate_plus_cfg['affp_usrpage']){ $affurl = get_option('siteurl').'/?'.$affiliate_plus_cfg['affp_trkpar'].'='.$user_id->user_login; // count referrals by this user $table = $wpdb->prefix."affp_referrals"; $ref_count = $wpdb->get_var("SELECT COUNT(*) FROM $table WHERE affp_referral = '$user_id->user_login'"); if(!$ref_count){ $ref_count = "-"; } // get referral name $referral = $wpdb->get_var("SELECT affp_referral FROM $table WHERE affp_id = '$user_id->ID'"); if(!$referral){ $referral = '-'; } echo"<h3>Affiliate Plus</h3> <table class=\"form-table\"> <tr> <th>referred by</th> <td>$referral</td> </tr> <tr> <th>number of members referred</th> <td>$ref_count</td> </tr> <tr> <th>referral URL</th> <td><input type=\"text\" value=\"$affurl\" class=\"regular-text\"/><br/> <span class=\"description\">send people to this URL to get credit for new signups</span></td> </tr> </table>"; } } add_action("profile_personal_options", "affiplus_userpage"); ?>Im probly asking too much of you guys but I thought id come and see if anyone wanted the challenge
Regards
Martin
The topic ‘Trying to make 2 wordpress plugins compatible’ is closed to new replies.