| 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 |
|