latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

About: Dan Martinez

Sorry, I've not written a description yet. I'll get to it soon!


Topics I'm Subscribed To

Viewing 2 topics - 1 through 2 (of 2 total)
Topic Count Last Reply
BUG REPORT

By:  Dan Martinez in: Community Forum

voices: 4
replies: 5

4 years, 2 months ago  Eduan

profile update hook

By:  Dan Martinez in: Community Forum

voices: 1
replies: 2

4 years, 2 months ago  Dan Martinez

Viewing 2 topics - 1 through 2 (of 2 total)

Topics I've Started

Viewing 3 topics - 1 through 3 (of 3 total)
Topic Count Last Reply
BUG REPORT

By:  Dan Martinez in: Community Forum

voices: 4
replies: 5

4 years, 2 months ago  Eduan

BUG: Forgot Password button borked.

By:  Dan Martinez in: Community Forum

voices: 3
replies: 2

4 years, 2 months ago  Elizabeth (Support Rep)

profile update hook

By:  Dan Martinez in: Community Forum

voices: 1
replies: 2

4 years, 2 months ago  Dan Martinez

Viewing 3 topics - 1 through 3 (of 3 total)

My Latest Replies (From Various Topics)

Viewing 2 replies - 1 through 2 (of 2 total)
Author Replies
Author Replies
Posted: Friday Oct 19th, 2012 at 2:40 am #28968
Dan Martinez
Username: njitc69

IGNORE the above. The method above will only yield the results of the database BEFORE the update. This correct method is to use the hook:
ws_plugin__s2member_during_handle_profile_modifications
Example code below: (this code is put in any new file in the directory: /wp-content/mu-plugins/)

######## SAMPLE CODE #########
### What does eet doo? 
### IT: 
### - Grabs the user ID for the current user
### - Then it connects to the WP database and searchers for their user meta data
### - Subsequently, it strips the specific meta data it needs by de-serializing the WP Data into a php-friendly array
### - Finally, it connects to an alternate database and inserts the new data
### ----- the final step is just an example of how to use the NEW user modified data,
### ------ you can update a database instead of creating a new entry like I did in the example,
### ------ but hey...it's just an example.... =D
############################
add_action("ws_plugin__s2member_during_handle_profile_modifications", "MY_EFFIN_FUNCTION");
function MY_EFFIN_FUNCTION($vars = array()){
	global $conn, $conn_wp; //retrieve global variables defined outside the function
	$agentID = $vars['current_user']->data->ID;
	if($conn_wp){
		$dbConnection2 = mysql_select_db("myDatabase1", $conn_wp);
		if($dbConnection2){
			$sqlUD = "select meta_value from myTable1 where user_id='" . $agentID . "' and meta_key='wp_s2member_custom_fields'";
			$resultsUD = mysql_query($sqlUD, $conn_wp);
			if($resultsUD){
				while ($rowUD = mysql_fetch_array($resultsUD)){
					$UD_array = unserialize($rowUD['meta_value']);
					//retrieve phone number and normalize (strip dashes and parenthesis)
					$agentNumber = $UD_array['phone_number']; $agentNumber = str_replace("-","",$agentNumber);
					$agentNumber = str_replace("(","",$agentNumber); $agentNumber = str_replace(")","",$agentNumber);					
				}
			}
			$resultUI = mysql_query("select user_email from wp_users where ID='" . $agentID . "'", $conn_wp);
			if($resultUI){
				while ($rowUI = mysql_fetch_array($resultUI)){
					$agentEmail = $rowUI['user_email'];
				}
			}
		}
	}
	if($conn){
		mysql_select_db("myDatabase2", $conn);
		$sql = "insert into myTable2(agentNumber,agentEmail) values ('" . $agentNumber . "','" . $agentEmail . "')";
		$result = mysql_query($sql, $conn);
	}
}

Keep in mind that the code above utilizes the OLD method for MYSQL database queries. I just use it to type up a super quick example. It uses the mysql_query extension…. Use of this extension is STRONGLY discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. But, I’m not here to teach MySql… so go google it. =P

Posted: Friday Oct 19th, 2012 at 12:27 am #28963
Dan Martinez
Username: njitc69

I was trying to use:

ws_plugin__s2member_after_handle_profile_modifications

but it didn’t do anything nor capture anything… go figure. I then tried: ws_plugin__s2member_before_handle_profile_modifications

Which seemed to do the trick. However, I don’t know if this captures invalid form data… it appears that javascript is used to validate the form fields which could easily be escaped.. I’d rather a much more definite hook that valid data has been passed and processed prior to running my routines. Alas, however, that would require modding the source and having to redo it every time an s2m update is installed.

Viewing 2 replies - 1 through 2 (of 2 total)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.