PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.2
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.2
7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 6.0.7 All 35 releases
mlsimport / includes / live / live-guards.php

live-guards.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.2, at includes/live/live-guards.php

64 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Live mode: deregister the write paths.
4 *
5 * Live mode stores nothing, so nothing may import: the hourly import cron,
6 * the daily reconciliation import, the Action Scheduler media mover and the
7 * ?mlsimport_cron=yes server trigger all detach while the gate is on, and
8 * the Import Tasks UI hides. Toggling live off puts everything back on the
9 * next request — the registrations themselves are untouched.
10 *
11 * @package Mlsimport
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Detach every import/write handler while live mode is on.
20 *
21 * Runs at init 0 — before the server-cron trigger (init 10) and before
22 * WP-Cron dispatches its due events, so a scheduled fire finds no handler.
23 *
24 * @return void
25 */
26 function mlsimport_live_guards(): void {
27 // Gate off: leave all the normal import/write handlers registered.
28 if ( ! mlsimport_live_mode_active() ) {
29 return;
30 }
31
32 // Detach the two scheduled imports and the server-cron init trigger.
33 remove_action( 'event_mls_import_auto', 'mlsimport_saas_event_mls_import_auto_function' );
34 remove_action( 'mlsimport_reconciliation_event', 'mlsimport_saas_reconciliation_event_function' );
35 remove_action( 'init', 'mlsimport_trigger_cron_job' );
36
37 // Detach the Action Scheduler media-mover handlers, which hang off the
38 // admin instance rather than a bare function.
39 global $mlsimport;
40 if ( is_object( $mlsimport ) && isset( $mlsimport->admin ) && is_object( $mlsimport->admin ) ) {
41 remove_action( 'mlsimport_background_process_per_item', array( $mlsimport->admin, 'mlsimport_background_process_per_item_function' ) );
42 remove_action( 'mlsimport_background_process_per_item_inital_batch', array( $mlsimport->admin, 'mlsimport_background_process_per_item_inital_batch_function' ) );
43 }
44 }
45 add_action( 'init', 'mlsimport_live_guards', 0 );
46
47 /**
48 * Hide the Import Tasks (mlsimport_item) admin UI while live mode is on.
49 *
50 * @param array $args Post type registration args.
51 * @param string $post_type Post type slug.
52 * @return array
53 */
54 function mlsimport_live_hide_import_ui( $args, $post_type ) {
55 // Only the Import Tasks CPT, and only while live mode is on.
56 if ( 'mlsimport_item' === $post_type && mlsimport_live_mode_active() ) {
57 // Hide the CPT's admin screens + menu entry (registration is untouched).
58 $args['show_ui'] = false;
59 $args['show_in_menu'] = false;
60 }
61 return $args;
62 }
63 add_filter( 'register_post_type_args', 'mlsimport_live_hide_import_ui', 10, 2 );
64