By Donnie Rollins on Friday, 15 March 2019
Posted in General Issues
Replies 7
Likes 0
Views 818
Votes 0
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?
Hey there,

I am really sorry for the delay of this reply as it is a weekend for us here.

May i know which registration form are you using on your site?

Is it Joomla registration form?
·
Saturday, 16 March 2019 21:40
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello, users are created either from administrator > com_users > create new user or from a cron process that creates new users from Salesforce data. The process creates the user in according to Joomla best practices manner:


$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;
}


As you can see above we're calling the user plugin group which should trigger the user plugins to fire.
·
Friday, 22 March 2019 05:52
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Donnie,

If you create new user from administrator > com_users > create new user , you should able to see this 'subscribe to the blog' option from there.

But ensure that you got enable this plugin 'User - EasyBlog Users' and inside the setting 'Show Subscribe To Blog In Profile', you can check my attached screenshot below.

If those new user created automatically through your cron process, i think you have to add some of the customisation code in order to achieve this.

You can take a look this plugin code file how to make that new register user automatically subscribe on the blog sitewide. JoomlaFolder/plugins/user/easyblogusers/easyblogusers.php under this onUserAfterSave method.

Basically this is the code you need :

require_once(JPATH_ADMINISTRATOR . '/components/com_easyblog/includes/easyblog.php');

$model = EB::model('Subscription');
$model->addSiteSubscription('UserEmail', 'UserId', 'User Name');


This function addSiteSubscription located at this file JoomlaFolder/administrator/components/com_easyblog/models/subscription.php , you can see what requirement it need from this function when you call.
·
Friday, 22 March 2019 10:17
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks so much for your answer. How would this work for the EasyDiscuss forum? is there a similar use case (or file/plugin) we could use to get a similar code?
·
Wednesday, 26 June 2019 01:24
·
0 Likes
·
0 Votes
·
0 Comments
·
You're most welcome, you can try this following code but you have ensure that you have enable this setting 'Allow Non Registered Users To Subscribe' from backend > Easydiscuss > Setting > notification > subscriptions :


$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);
·
Wednesday, 26 June 2019 13:29
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post