admin->mlsimport_saas_get_mls_api_token_from_transient(); if ( trim( $token ) === '' ) { return; } $is_mls_connected = get_option( 'mlsimport_connection_test', '' ); if ( 'yes' !== $is_mls_connected ) { return; } $logs =''; mlsimport_debuglogs_per_plugin( $logs ); $args = array( 'post_type' => 'mlsimport_item', 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'mlsimport_item_stat_cron', 'value' => 1, 'compare' => '=', ), ), ); $prop_selection = new WP_Query( $args ); if ( $prop_selection->have_posts() ) { while ( $prop_selection->have_posts() ) : $prop_selection->the_post(); $prop_id = get_the_ID(); $logs = ' Loop custom post : ' . $prop_id . PHP_EOL; mlsimport_debuglogs_per_plugin( $logs ); $mlsimport->admin->mlsimport_saas_start_cron_links_per_item( $prop_id ); endwhile; } } /* * Reconciliation Mechanism * * * **/ if ( ! wp_next_scheduled( 'mlsimport_reconciliation_event' ) ) { wp_schedule_event( time(), 'daily', 'mlsimport_reconciliation_event' ); } add_action( 'mlsimport_reconciliation_event', 'mlsimport_saas_reconciliation_event_function' ); /* * Force use of transient * * * **/ function mlsimport_force_use_transient( $value ) { return $value; // return false; } global $mlsimport; $mlsimport = new Mlsimport(); $mlsimport->run(); $supported_theme = array( 991 => 'WpResidence', 992 => 'Houzez', 993 => 'Real Homes', 994 => 'Wpestate', ); define( 'MLSIMPORT_THEME', $supported_theme ); add_filter( 'action_scheduler_failure_period', 'mlsimport_saas_filter_timelimit' ); function mlsimport_saas_filter_timelimit( $time_limit ) { return 3000; } /* * * Write logs * **/ function mlsimport_saas_single_write_import_custom_logs( $message, $tip_import = 'normal' ) { // Check if logging is enabled $enable_logs = intval( get_option( 'mlsimport_disable_logs' ) ); if ( 1 !== $enable_logs) { return; } if ( is_array( $message ) ) { $message = wp_json_encode( $message ); } $formatted_message = gmdate( 'F j, Y, g:i a' ) . ' -> ' . $message; // Determine the log file path based on the import type $log_file_name = 'cron' === $tip_import ? 'cron_logs' : ( 'delete' === $tip_import ? 'delete_logs' : ( 'server_cron' === $tip_import ? 'server_cron_logs' : 'import_logs' ) ); // Construct the full path with a date suffix $log_file_path = WP_PLUGIN_DIR . "/mlsimport/logs/{$log_file_name}-" . gmdate( 'Y-m-d' ) . '.log'; // Error handling for file operations try { // Check and create the directory for logs if it does not exist $log_dir = dirname( $log_file_path ); if ( ! file_exists( $log_dir ) ) { mkdir( $log_dir, 0755, true ); } // Append the formatted message to the log file file_put_contents( $log_file_path, $formatted_message, FILE_APPEND | LOCK_EX ); } catch ( Exception $e ) { // Handle the exception, such as logging the error elsewhere or sending a notification } } /* * * * Write Status logs * * **/ function mlsimport_debuglogs_per_plugin_old( $message ) { if ( is_array( $message ) ) { $message = wp_json_encode( $message ); } global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } $path_status = WP_PLUGIN_DIR . '/mlsimport/logs/status_logs.log'; file_put_contents( $path_status, $message, LOCK_EX ); } function mlsimport_debuglogs_per_plugin( $message ) { if ( is_array( $message ) ) { $message = wp_json_encode( $message ); } if ( empty( $message ) ) { return; // Exit the function if there's nothing to log } $log_file_path = WP_PLUGIN_DIR . '/mlsimport/logs/status_logs.log'; // Check and create the directory for logs if it does not exist $log_dir = dirname( $log_file_path ); if ( ! file_exists( $log_dir ) ) { mkdir( $log_dir, 0755, true ); } // Error handling for file operations try { // Append the message to the log file with a newline and acquire an exclusive lock during writing file_put_contents( $log_file_path, $message . PHP_EOL, LOCK_EX ); } catch ( Exception $e ) { // Handle the exception, such as logging the error elsewhere or sending a notification } } /* * Cron job trigger * * * **/ // */5 * * * * wget http://example.com/check */2 add_action( 'init', 'mlsimport_trigger_cron_job' ); function mlsimport_trigger_cron_job() { // ?mlsimport_cron=yes if ( isset( $_REQUEST['mlsimport_cron'] ) && 'yes' === sanitize_text_field( wp_unslash( $_REQUEST['mlsimport_cron'] ) ) ) { $last_run = intval( get_option( 'mlsimport_last_server_cron' ) ); $now = time(); if ( 0 === intval($last_run) ) { update_option( 'mlsimport_last_server_cron', $now ); } if ( $last_run < $now - ( 60 * 60 * 2 ) ) { $log = 'Server Cron Job triggered on ' . date( 'l jS \of F Y h:i:s A', $last_run ) . ' vs ' . gmdate( 'l jS \of F Y h:i:s A', $now ) . PHP_EOL; // mlsimport_saas_event_mls_import_auto_function(); update_option( 'mlsimport_last_server_cron', $now ); } else { $log = 'Server Cron Job Called but not triggered. Last run on ' . gmdate( 'l jS \of F Y h:i:s A', $last_run ) . ' vs ' . gmdate( 'l jS \of F Y h:i:s A', $now ) . PHP_EOL; } mlsimport_saas_single_write_import_custom_logs( $log, 'server_cron' ); } } function mlsimport_show_signup() { $affiliate_url = 'https://mlsimport.com'; if ( function_exists( 'wp_estate_init' ) ) { $affiliate_url = 'https://mlsimport.com/ref/1/?campaign=wpresidence'; } ?>
'; } else { echo 'First batch event already scheduled.