Created
July 3, 2014 09:56
-
-
Save nathanpitman/139bc4e03be874a8dbfb to your computer and use it in GitHub Desktop.
Leverages https://github.com/joshfraser/PHP-Name-Parser to better populate ExpressionEngine member fields when using Charge 'create_member'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* ExpressionEngine - by EllisLab | |
* | |
* @package ExpressionEngine | |
* @author ExpressionEngine Dev Team | |
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc. | |
* @license http://expressionengine.com/user_guide/license.html | |
* @link http://expressionengine.com | |
* @since Version 2.0 | |
* @filesource | |
*/ | |
// ------------------------------------------------------------------------ | |
/** | |
* Charge better create_member Extension | |
* | |
* @package ExpressionEngine | |
* @subpackage Addons | |
* @category Extension | |
* @author Nathan Pitman | |
* @link http://www.ninefour.co.uk | |
*/ | |
class Charge_better_create_member_ext { | |
public $settings = array(); | |
public $description = "Does a better job of populating member fields following creation of a member using the Charge 'create_member' option"; | |
public $docs_url = 'http://www.ninefour.co.uk/labs/'; | |
public $name = 'Charge better create_member'; | |
public $settings_exist = 'n'; | |
public $version = '1.0'; | |
private $EE; | |
/** | |
* Constructor | |
* | |
* @param mixed Settings array or empty string if none exist. | |
*/ | |
public function __construct($settings = '') | |
{ | |
$this->EE =& get_instance(); | |
$this->settings = $settings; | |
}// ---------------------------------------------------------------------- | |
/** | |
* Activate Extension | |
* | |
* This function enters the extension into the exp_extensions table | |
* | |
* @see http://codeigniter.com/user_guide/database/index.html for | |
* more information on the db class. | |
* | |
* @return void | |
*/ | |
public function activate_extension() | |
{ | |
// Setup custom settings in this array. | |
$this->settings = array(); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'charge_better_create_member', | |
'hook' => 'charge_create_member', | |
'settings' => serialize($this->settings), | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
// No hooks selected, add in your own hooks installation code here. | |
} | |
// ---------------------------------------------------------------------- | |
/** | |
* freemember_update_screen_name | |
* | |
* @param | |
* @return | |
*/ | |
public function charge_better_create_member($data) | |
{ | |
// Defaults | |
$member = array(); | |
$member_data = array(); | |
// Split screen name into name and email | |
$screen_name = explode(',',$data['screen_name']); | |
// Parse the name into salutation, fname, initials, lname and suffix | |
// See: https://github.com/joshfraser/PHP-Name-Parser | |
$this->EE->load->library('fullnameparser'); | |
$parser = new FullNameParser(); | |
$split_name = $parser->split_full_name($screen_name[0]); | |
$member['screen_name'] = $split_name['fname'] . ' ' . $split_name['lname']; | |
$member_data['m_field_id_2'] = $split_name['fname']; | |
$member_data['m_field_id_4'] = $split_name['lname']; | |
// Updates the screen_name with the provided 'first_name' and 'last_name' | |
ee()->load->model('member_model'); | |
ee()->member_model->update_member($data['member_id'], $member); | |
ee()->member_model->update_member_data($data['member_id'], $member_data); | |
} | |
// ---------------------------------------------------------------------- | |
/** | |
* Disable Extension | |
* | |
* This method removes information from the exp_extensions table | |
* | |
* @return void | |
*/ | |
function disable_extension() | |
{ | |
$this->EE->db->where('class', __CLASS__); | |
$this->EE->db->delete('extensions'); | |
} | |
// ---------------------------------------------------------------------- | |
/** | |
* Update Extension | |
* | |
* This function performs any necessary db updates when the extension | |
* page is visited | |
* | |
* @return mixed void on update / false if none | |
*/ | |
function update_extension($current = '') | |
{ | |
if ($current == '' OR $current == $this->version) | |
{ | |
return FALSE; | |
} | |
} | |
// ---------------------------------------------------------------------- | |
} | |
/* End of file ext.charge_better_create_member_ext.php */ | |
/* Location: /system/expressionengine/third_party/charge_better_create_member/ext.charge_better_create_member_ext.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment