Created
June 2, 2023 15:10
-
-
Save propertyhive/30da236791df1990498e9a0664947ec4 to your computer and use it in GitHub Desktop.
Custom property import frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'propertyhive_property_import_frequencies', 'add_custom_import_frequency' ); | |
function add_custom_import_frequency($frequencies) | |
{ | |
$new_frequencies = array('every_five_minutes' => 'Every Five Minutes'); | |
// if anything other than 'every_five_minutes' a custom cron schedule will need to be added | |
// 'every_five_minutes' is already an established schedule setup by the import add on | |
// https://developer.wordpress.org/reference/hooks/cron_schedules/ | |
return array_merge( $new_frequencies, $frequencies ); | |
} | |
add_filter( 'propertyhive_property_import_next_due', 'get_next_due', 10, 3 ); | |
function get_next_due( $got_next_due, $next_due, $last_start_date ) | |
{ | |
if ( ( ($next_due - $last_start_date) / 60 / 60 ) >= 0.083333 ) // 0.083333 = a twelth (i.e. five minutes) of an hour | |
{ | |
$got_next_due = $next_due; | |
} | |
return $got_next_due; | |
} | |
add_filter( 'propertyhive_property_ok_to_run_import', 'check_ok_to_run_import', 10, 2 ); | |
function check_ok_to_run_import( $ok_to_run_import, $diff_secs ) | |
{ | |
if (($diff_secs / 60 / 60) < 0.083333) // 0.083333 = a twelth (i.e. five minutes) of an hour | |
{ | |
$ok_to_run_import = false; | |
} | |
return $ok_to_run_import; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment