title: Understanding crons in wordpress & a snippet of code
body: <p>I'm looking for some help understanding this code with some comments if possible, I'm trying to figure out how it works exactly.</p>
  
  <p>It's located in a plugin and I have had a look at Wordpress's codex but it hasn't really helped me much.</p>
  
  <p>The pages I looked at are/were:</p>
  
  <p><a href="https://codex.wordpress.org/Function_Reference/wp_schedule_event" rel="nofollow">https://codex.wordpress.org/Function_Reference/wp_schedule_event</a>
  <a href="https://codex.wordpress.org/Function_Reference/wp_next_scheduled" rel="nofollow">https://codex.wordpress.org/Function_Reference/wp_next_scheduled</a></p>
  
  <p>And also: <a href="http://codex.wordpress.org/Plugin_API/Action_Reference/wp" rel="nofollow">http://codex.wordpress.org/Plugin_API/Action_Reference/wp</a></p>
  
  <p>Code Snippet:</p>
  
  <pre><code>add_action('wp','prefix_setup_schedule');
  function prefix_setup_schedule() {
      if (!wp_next_scheduled('prefix_hourly_event')){
          wp_schedule_event(time(), 'hourly', 'prefix_hourly_event');
      }
      if (!wp_next_scheduled('daily_prefix_hourly_event')){
          //wp_schedule_event(time(), 'daily', 'daily_prefix_hourly_event');
          wp_schedule_event(time(), 'wpo_daily', 'daily_prefix_hourly_event');
      }
  }
  
  add_action('prefix_hourly_event','filter_mem');
  
  $t = time();
  $hour = date('G');
  if(get_option('cronhour') != null){
      $hcron = (int)get_option('cronhour');
      if($hcron &gt; 0 &amp;&amp; $hcron &lt;= 23){
          if($hour &lt; $hcron){
              $on = mktime($hcron, 0, 0, date('m'), date('d'), date('Y'));
          }else{
              $on = mktime($hcron, 0, 0, date('m'), date('d')+1, date('Y'));
          }
      }else{
          $hcron = 0;
          if($hour &lt; $hcron){
              $on = mktime($hcron, 0, 0, date('m'), date('d'), date('Y'));
          }else{
              $on = mktime($hcron, 0, 0, date('m'), date('d')+1, date('Y'));
          }
      }
  } else {
      $hcron = 0;
      if($hour &lt; $hcron){
          $on = mktime($hcron, 0, 0, date('m'), date('d'), date('Y'));
      }else{
          $on = mktime($hcron, 0, 0, date('m'), date('d')+1, date('Y'));
      }
  }
  
  if ($t&gt;=$on){
      add_action('daily_prefix_hourly_event', 'filter_temp');
  }
  </code></pre>
  
  <p>As far as I can tell, it seems to be comparing the current time to the "cronhour" and somehow adding the cron.</p>
  
  <p>I also noticed the plugin has no unschedule / clear schedule hook so surely it would keep firing even when plugin is disabled?</p>
  
  <p>I looked at the following</p>
  
  <p><a href="https://codex.wordpress.org/Function_Reference/wp_unschedule_event" rel="nofollow">https://codex.wordpress.org/Function_Reference/wp_unschedule_event</a>
  <a href="https://codex.wordpress.org/Function_Reference/wp_clear_scheduled_hook" rel="nofollow">https://codex.wordpress.org/Function_Reference/wp_clear_scheduled_hook</a></p>
  
  <p>Not sure what one I should be using, it isn't very clear. I'd greatly appreciate some help understanding what this is doing, with some comments and explaining the differences.</p>