Created
November 6, 2013 12:13
-
-
Save boboldehampsink/7335131 to your computer and use it in GitHub Desktop.
Save profile and user data simultaneously
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 | |
namespace Craft; | |
class SaveProfilePlugin extends BasePlugin | |
{ | |
function getName() | |
{ | |
return Craft::t('Save profile too when saving user'); | |
} | |
function getVersion() | |
{ | |
return '1.0'; | |
} | |
function getDeveloper() | |
{ | |
return 'Bob Olde Hampsink'; | |
} | |
function getDeveloperUrl() | |
{ | |
return 'http://www.itmundi.nl'; | |
} | |
function init() { | |
// Only works on the front-end | |
if(craft()->request->isSiteRequest()) { | |
// Only trigger when an user is saved | |
craft()->on('users.onSaveUser', function(Event $event) { | |
// Get user | |
$user = $event->params['user']; | |
// Set given fields on user | |
$fields = craft()->request->getPost('fields'); | |
$user->getContent()->setAttributes($fields); | |
// Save profile | |
craft()->users->saveProfile($user); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment