MyBB Hacks

Full Version: How to make pm automatically?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How can I make it so when an user is a member of my forum for say one year it receives a pm automatically with some text like Hello username. You have been a member here for one year etc etc.

What hook should I use and what code? I would appreciate some help.
It depends on how you want to approach the issue.
What do you exactly want to trigger the sending of the PM?  Perhaps a task?  When the user logs in?  That will determine where you should apply your modifications.
Well, the basic code for a fuction would be along the lines of this, but I'm not 100% sure it works:

PHP Code:
function happybday($to)
  {
      global $mybb
      require_once(MYBB_ROOT . "inc/datahandlers/pm.php");
      $pmhandler = new PMDataHandler();
      $pmhandler->admin_override = true;

      $pm = array(
          "subject" => "Hi",
          "message" => "You've been a member for a year. Have some pie.",
          "icon" => "-1",
          "toid" => array(),
          "fromid" => '1', //Change this to a uid
          "do" => "",
          "pmid" => ""
      );
      $pm["options"] = array(
          "signature" => "0",
          "disablesmilies" => "0",
          "savecopy" => "0",
          "readreceipt" => "0"
      );
      
      if(!is_array($to))
      {
          array_push($pm["toid"], $to);
      }
      else
      {
          foreach($to as $uid)
          {
              array_push($pm["toid"], $uid);
          }
      }

      $pmhandler->set_data($pm);

      if($pmhandler->validate_pm())
      {
          $pmhandler->insert_pm();
          return true;
      }
      else
      {
          return false;
      }
  }

^ Does not contain a trigger.
(12-01-2012 09:13 AM)ZiNgA BuRgA Wrote: [ -> ]It depends on how you want to approach the issue.
What do you exactly want to trigger the sending of the PM?  Perhaps a task?  When the user logs in?  That will determine where you should apply your modifications.

I would like for the pm to be sent automatically as soon as an user is a member at my forum for one year. No task or any other criteria such when they log in or anything. Thank you in advance Smile

What is trigger btw? That the code above does not have it? And what hook should I use?
My previous post became moderate because it said that it triggered the spam filter but I was not spamming.
(12-02-2012 04:16 AM)tony Wrote: [ -> ]I would like for the pm to be sent automatically as soon as an user is a member at my forum for one year. No task or any other criteria such when they log in or anything.
That isn't a trigger, that's a condition.  There is no such trigger as "user is a member for one year".

A triggered action requires three things:
- triggers
- conditions
- actions

You've given a condition (member registration date is at least one year in the past and PM has not previously been sent) and an action (send PM and indicate not to send the PM again), but you haven't given a trigger to cause this event to occur.
If you actually intend to code this, this is a basic concept you need to be very well aware of.

(12-02-2012 04:16 AM)tony Wrote: [ -> ]That the code above does not have it? And what hook should I use?
If you don't understand the basic concepts of triggers, don't even bother trying to think about hooks because it's not going to make sense.
A trigger is an activation of an action in response to some external influence.  A user visiting a page is an example of an external influence.


Of course, if you're really just asking someone to make this modification for you, we won't help you.  Neither will we hand hold you with PHP etc - that's obviously a required knowledge for coding it in the first place.
Thank you for explaining it to me. Now I am not asking anyone to code it for me. I can code it for myself but I am stuck at which hook name to use. I have condition ready to get the anniversary of the user and I have the code to send the pm automatically. What I miss is the hook name. Can you help me with that please?
(12-02-2012 09:19 AM)ZiNgA BuRgA Wrote: [ -> ]you haven't given a trigger to cause this event to occur.
You could maybe use a daily task that looks for users with a start date of one year ago and then send a pm which will be in the inbox next time they log in - you could even add a column in the user table for the PM sent so it would only query on those users who had not already had a PM.
Pages: 1 2
Reference URL's