WP_Importer_Cron

The Tumblr Importer WP Importer Cron class.

Defined (1)

The class is defined in the following location(s).

/class-wp-importer-cron.php  
  1. class WP_Importer_Cron extends WP_Importer { 
  2.  
  3. function __construct() { 
  4. // start the clock 
  5. $this->_importer_started = time(); 
  6. $this->_max_execution_time = 30; // default to 30 seconds of time on the clock 
  7. parent::__construct(); 
  8.  
  9. // add the importer schedule 
  10. add_filter( 'cron_schedules', array( $this, 'importer_schedule' ) ); 
  11.  
  12. // add the importer hook 
  13. add_action( 'wp_cron_importer_hook', array( $this, 'importer_callback' ) ); 
  14.  
  15. //load the variables 
  16. $options = get_option( get_class($this) ); 
  17.  
  18. if ( is_array($options) ) 
  19. foreach ( $options as $key => $value ) 
  20. $this->$key = $value; 
  21.  
  22. // Check to see if you have time remaining on the clock 
  23. function have_time() { 
  24. if ( time() - $this->_importer_started > $this->_max_execution_time ) return false; 
  25. return true; 
  26.  
  27. // add the once every three minute schedule 
  28. function importer_schedule( $schedules ) { 
  29. $schedules['everyminute'] = array( 'interval' => 60, 'display' => __('Every Minute') ); 
  30. return $schedules; 
  31.  
  32. // schedule an importer job 
  33. function schedule_import_job( $function_name, $args=array() ) { 
  34. $this->callback = $function_name; 
  35. wp_schedule_event(time(), 'everyminute', 'wp_cron_importer_hook' , $args); 
  36.  
  37. // internal callback that checks for a finished import and clears old jobs out 
  38. function importer_callback( $args=array() ) { 
  39. $args = (array)$args; 
  40.  
  41. if ( isset($this->callback) ) { 
  42. $complete = call_user_func_array( array( $this, $this->callback ), $args ); 
  43. } else {  
  44. // no callback, force the cron job to end 
  45. $complete = true; 
  46.  
  47. if ( $complete ) { 
  48. // importer is finished, stop the scheduler 
  49. wp_clear_scheduled_hook( 'wp_cron_importer_hook', $args); 
  50.  
  51. // function to let the class save its own variables 
  52. function save_vars() { 
  53. $vars = get_object_vars($this); 
  54. foreach($vars as $var=>$val) { 
  55. if ($var[0] == "_") unset ($vars[$var]); 
  56. update_option( get_class($this), $vars ); 
  57.  
  58. return !empty($vars);