Hello, I have a question about how the blog subscription. Is there a way for us to auto subscribe existing users to the blog? Or for them to be subscribed automatically when they sign up?
$user = new JUser;
$user->groups = array(1,2); //set public and registered
$data['sendEmail'] = 1;
$data['requireReset'] = 1;
// Prepare the data for the user object.
$data['email'] = JStringPunycode::emailToPunycode($email);
if ($username && $username !="") {
$data['username'] = $username;
}
if ($name && $name !="") {
$data['name'] = $name;
}
if ($password && $password !="") {
$data['password'] = $password;
}
// Bind the data.
if (!$user->bind($data))
{
//echo JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED',$user->getError());
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Store the data.
if (!$user->save())
{
//echo JText::_('COM_USERS_REGISTRATION_SAVE_FAILED').'<br />';
//echo $user->getError().'<br />';
return false;
}
require_once(JPATH_ADMINISTRATOR . '/components/com_easyblog/includes/easyblog.php');
$model = EB::model('Subscription');
$model->addSiteSubscription('UserEmail', 'UserId', 'User Name');
$data = array();
$data['type'] = 'site';
$data['userid'] = $userId;
$data['email'] = $userEmail;
$data['cid'] = '0';
$data['member'] = '1';
$data['name'] = $subscriberName;
// e.g. you have to store these subscription interval type -> instant / daily / weekly / monthly
$data['interval'] = $subscriptionInterval;
$model = ED::model('Subscribe');
$model->addSubscription($data);