Created
November 25, 2016 18:40
-
-
Save danboh/68290dfcf05b9cd7c329a014f47771ea to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
Plugin Name: TREB RETS Feed Plugin | |
Plugin URI: http://www.moeloubani.com/treb-plugin | |
Description: A plugin made to create a shortcode that pulls in a feed from TREB, now uses PHRETS 2. | |
Version: 0.4 | |
Author: moeloubani | |
Author URI: http://www.moeloubani.com | |
License: GPL | |
*/ | |
if (version_compare(phpversion(), '5.4', '<')) { | |
wp_die('PHP 5.4 or higher required!'); | |
} | |
//Handy function for testing, will remove in later versions | |
function dd($variable) { | |
var_dump($variable); | |
die(); | |
} | |
//Autoload files | |
require_once('vendor/autoload.php'); | |
function checkForPostType() { | |
$property_type = new CPT('property', array( | |
'supports' => array('title', 'editor', 'thumbnail', 'comments', 'custom-fields') | |
)); | |
if (!post_type_exists('property') ) { | |
$property_type->register_taxonomy(array( | |
'taxonomy_name' => 'Property Type' | |
)); | |
} | |
} | |
checkForPostType(); | |
// Get it started | |
$install = new \wptrebrets\inc\Install(); | |
$wptrebrets_settings = new wptrebrets\inc\Options(); | |
$wptrebrets_settings->hooks(); | |
function wptrebrets_get_option( $key = '' ) { | |
return cmb_get_option( wptrebrets\inc\Options::key(), $key ); | |
} | |
function wptreb_startUp() { | |
ini_set('memory_limit','256M'); | |
ini_set('max_execution_time', 3600); | |
$start = new \wptrebrets\inc\Commands(); | |
$start->getInitial(); | |
} | |
function wptreb_IncrementalLoad() { | |
ini_set('memory_limit','256M'); | |
ini_set('max_execution_time', 3600); | |
$time_start = microtime(true); | |
$start = new \wptrebrets\inc\Commands(); | |
$start->getDaily(); | |
$time_end = microtime(true); | |
$execution_time = ($time_end - $time_start)/60; | |
error_log('INFO: Incremental Load has completed successfully in '.round($execution_time).' minutes'); | |
} | |
function wptreb_getDailyCommercial(){ | |
ini_set('memory_limit','96M'); | |
ini_set('max_execution_time', 3600); | |
$time_start = microtime(true); | |
$start = new \wptrebrets\inc\Commands(); | |
$start->getDailyCommercial(); | |
$time_end = microtime(true); | |
$execution_time = ($time_end - $time_start)/60; | |
error_log('INFO: Commercial Incremental Load has completed successfully in '.round($execution_time).' minutes'); | |
} | |
function wptreb_getDailyCondominium(){ | |
ini_set('memory_limit','96M'); | |
ini_set('max_execution_time', 3600); | |
$time_start = microtime(true); | |
$start = new \wptrebrets\inc\Commands(); | |
$start->getDailyCondominium(); | |
$time_end = microtime(true); | |
$execution_time = ($time_end - $time_start)/60; | |
error_log('INFO: Condominium Incremental Load has completed successfully in '.round($execution_time).' minutes'); | |
} | |
function wptreb_getDailyResidential(){ | |
ini_set('memory_limit','96M'); | |
ini_set('max_execution_time', 7200); | |
var_dump(gd_info()); | |
// $time_start = microtime(true); | |
// $start = new \wptrebrets\inc\Commands(); | |
// $start->getDailyResidential(); | |
// $time_end = microtime(true); | |
// $execution_time = ($time_end - $time_start)/60; | |
// error_log('INFO: Residential Incremental Load has completed successfully in '.round($execution_time).' minutes'); | |
} | |
function wptreb_schedule() { | |
$cron = wp_get_schedule( 'wptreb_daily_import' ); | |
$schedule = wptrebrets_get_option('rets_schedule'); | |
if($cron){ | |
//schedule exists, let's update it | |
}else{ | |
//schedule doesn't exist, let's add it | |
add_action('wptreb_daily_import', 'wptreb_IncrementalLoad'); | |
wp_schedule_event(time(), $schedule, 'wptreb_daily_import'); | |
} | |
var_dump($schedule); | |
} | |
function my_update_notice() { | |
?> | |
<div class="notice notice-info is-dismissible"> | |
<p><?php _e('Incremental load has finished!', 'my_plugin_textdomain' ); ?></p> | |
</div> | |
<?php | |
} | |
function schedule_updated() { | |
?> | |
<div class="notice notice-info is-dismissible"> | |
<p><?php _e('Daily schedule has been refreshed to run: ', 'my_plugin_textdomain' ); ?></p> | |
</div> | |
<?php | |
} | |
if (isset($_GET['wptreb_import']) && $_GET['wptreb_import'] === 'initial') { | |
add_action('init', 'wptreb_startUp'); | |
}elseif(isset($_GET['wptreb_import']) && $_GET['wptreb_import'] === 'dailyCommercial'){ | |
add_action( 'init', 'wptreb_getDailyCommercial' ); | |
add_action( 'admin_notices', 'my_update_notice' ); | |
}elseif(isset($_GET['wptreb_import']) && $_GET['wptreb_import'] === 'dailyCondominium'){ | |
add_action( 'init', 'wptreb_getDailyCondominium' ); | |
add_action( 'admin_notices', 'my_update_notice' ); | |
}elseif(isset($_GET['wptreb_import']) && $_GET['wptreb_import'] === 'dailyResidential'){ | |
add_action( 'init', 'wptreb_getDailyResidential' ); | |
add_action( 'admin_notices', 'my_update_notice' ); | |
} elseif(isset($_GET['wptreb_import']) && $_GET['wptreb_import'] === 'schedule'){ | |
add_action( 'init', 'wptreb_schedule' ); | |
add_action( 'admin_notices', 'schedule_updated' ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment