| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin partial: "Tools" tab (Administrative Options). |
| 4 |
* |
| 5 |
* Renders the plugin's administrative tools: toggles for system logs and property |
| 6 |
* history, cache/field-data clearing buttons, cron-job guidance, and a |
| 7 |
* taxonomy-scoped bulk "Delete Properties" tool. Also handles the POST for the two |
| 8 |
* toggle selects at the top (nonce-verified) before rendering the form. |
| 9 |
* |
| 10 |
* @package mlsimport |
| 11 |
* @subpackage mlsimport/admin/partials |
| 12 |
*/ |
| 13 |
|
| 14 |
// Block direct access outside of WordPress. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly |
| 17 |
} |
| 18 |
|
| 19 |
// Handle the toggle-form submit: only when the tool-actions nonce is present and valid. |
| 20 |
if (isset($_POST['mlsimport_tool_actions']) && |
| 21 |
wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mlsimport_tool_actions'] ) ), 'mlsimport_tool_actions')) { |
| 22 |
|
| 23 |
// Persist the "disable system logs" choice. |
| 24 |
if ( isset( $_POST['mlsimport-disable-logs'] ) ) { |
| 25 |
$disable_logs = intval( $_POST['mlsimport-disable-logs'] ); |
| 26 |
update_option( 'mlsimport_disable_logs', $disable_logs ); |
| 27 |
} |
| 28 |
// Persist the "disable property history" choice. |
| 29 |
if ( isset( $_POST['mlsimport-disable-history'] ) ) { |
| 30 |
$disable_history = intval( $_POST['mlsimport-disable-history'] ); |
| 31 |
update_option( 'mlsimport-disable-history', $disable_history ); |
| 32 |
} |
| 33 |
|
| 34 |
} |
| 35 |
?> |
| 36 |
|
| 37 |
<form method="post" name="cleanup_options" action=""> |
| 38 |
<?php |
| 39 |
global $mlsimport; |
| 40 |
// Emit the settings API nonce/hidden fields and any registered sections. |
| 41 |
settings_fields( $this->plugin_name . '_administrative_options' ); |
| 42 |
do_settings_sections( $this->plugin_name . '_administrative_options' ); |
| 43 |
// Load the administrative options and (re)initialise plugin/SaaS state. |
| 44 |
$options = get_option( $this->plugin_name . '_administrative_options' ); |
| 45 |
$mlsimport->admin->mlsimport_saas_setting_up(); |
| 46 |
//mlsimport_saas_event_mls_import_auto_function(); |
| 47 |
//mlsimport_saas_reconciliation_event_function(); |
| 48 |
?> |
| 49 |
|
| 50 |
<h1> <?php esc_html_e( 'Administrative Tools', 'mlsimport' ); ?></h1> |
| 51 |
|
| 52 |
|
| 53 |
<?php |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
// Current "disable logs" value; pre-select the matching <option> below. |
| 58 |
$disable_logs = intval( get_option( 'mlsimport_disable_logs' ) ); |
| 59 |
$selected_no = $selected_yes = ''; |
| 60 |
|
| 61 |
// 0 = logs disabled (default) -> select the "disabled" option; otherwise "enabled". |
| 62 |
if ( 0 === intval($disable_logs) ) { |
| 63 |
$selected_no = ' selected '; |
| 64 |
} else { |
| 65 |
$selected_yes = ' selected '; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
// Current "disable history" value (defaults to 1); pre-select the matching option. |
| 70 |
$disable_history = intval( get_option( 'mlsimport-disable-history', 1 ) ); |
| 71 |
$selected_history_no = $selected_history_yes = ''; |
| 72 |
|
| 73 |
// 0 = history disabled -> select the "disabled" option; otherwise "enabled". |
| 74 |
if ( 0 === intval($disable_history) ) { |
| 75 |
$selected_history_no = ' selected '; |
| 76 |
} else { |
| 77 |
$selected_history_yes = ' selected '; |
| 78 |
} |
| 79 |
?> |
| 80 |
|
| 81 |
<div class="mlsimport_tool_block"> |
| 82 |
<h4> <?php esc_html_e( 'Disable System Logs (logs should only be enabled during debug process)', 'mlsimport' ); ?> </h4> |
| 83 |
<select name="mlsimport-disable-logs" class="mlsimport-2025-select" id="mlsimport-disable-logs"> |
| 84 |
<option value="0" <?php echo esc_html( $selected_no ); ?> ><?php esc_html_e( 'logs disabled', 'mlsimport' ); ?></option> |
| 85 |
<option value="1" <?php echo esc_html( $selected_yes ); ?>><?php esc_html_e( 'logs enabled', 'mlsimport' ); ?></option> |
| 86 |
|
| 87 |
</select> |
| 88 |
</div> |
| 89 |
|
| 90 |
|
| 91 |
<div class="mlsimport_tool_block"> |
| 92 |
<h4> <?php esc_html_e( 'Disable Property History (can be seen by editing a property in WordPress admin)', 'mlsimport' ); ?> </h4> |
| 93 |
<select name="mlsimport-disable-history" class="mlsimport-2025-select" id="mlsimport-disable-history"> |
| 94 |
|
| 95 |
<option value="1" <?php echo esc_html( $selected_history_yes ); ?>><?php esc_html_e( 'history enabled', 'mlsimport' ); ?></option> |
| 96 |
<option value="0" <?php echo esc_html( $selected_history_no ); ?> ><?php esc_html_e( 'history disabled', 'mlsimport' ); ?></option> |
| 97 |
|
| 98 |
</select> |
| 99 |
</div> |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
<?php submit_button( __( 'Save Changes', 'mlsimport' ), 'mlsimport_button button save_data', 'submit', true ); ?> |
| 104 |
|
| 105 |
<div class="mlsimport_tool_block mlsimport_tool_card"> |
| 106 |
<h3> <?php esc_html_e( 'Clear cached data', 'mlsimport' ); ?> </h3> |
| 107 |
<input class="button mlsimport_button" type="button" id="mlsimport-clear-cache" value="<?php esc_attr_e( 'Clear Plugin Cached Data', 'mlsimport' ); ?>" /> |
| 108 |
</div> |
| 109 |
|
| 110 |
<div class="mlsimport_tool_block mlsimport_tool_card"> |
| 111 |
<h3> <?php esc_html_e( 'Clear fields data', 'mlsimport' ); ?> </h3> |
| 112 |
<input class="button mlsimport_button" type="button" id="mlsimport-clear-fields-data" value="<?php esc_attr_e( 'Clear Field Data', 'mlsimport' ); ?>" /> |
| 113 |
</div> |
| 114 |
|
| 115 |
|
| 116 |
<div class="mlsimport_tool_block"> |
| 117 |
<h3><?php esc_html_e( 'Cron Jobs', 'mlsimport' ); ?> </h3> |
| 118 |
<div class="cron_job_explainin"> |
| 119 |
<?php esc_html_e( 'By default a syncronization event runs every hour. The action will be triggered when someone visits your site if the scheduled time has passed. This is the default, "out of the box" way to do things in WordPress and it works very well in 99% of the cases.', 'mlsimport' ); ?> |
| 120 |
|
| 121 |
</br></br><?php esc_html_e( 'If, for some reason, you want to force the syncronization event to run every two hours(minimum time frame permitted by this plugin) you can set a cron job on your server enviroment and call this url : http://yourwebsite.com/?mlsimport_cron=yes.', 'mlsimport' ); ?> |
| 122 |
</br></br><strong><?php esc_html_e( 'Example : 0 */2 * * * wget https://yourwebsite.com/?mlsimport_cron=yes', 'mlsimport' ); ?></strong> . |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
|
| 126 |
<fieldset class="mlsimport-fieldset mlsimport_tool_block mlsimport_tool_card"> |
| 127 |
|
| 128 |
<h3><?php esc_html_e('Delete Properties','mlsimport'); ?></h3> |
| 129 |
|
| 130 |
<div id="mlsimport-delete-notification"><?php esc_html_e('Select a taxonomy and terms, then click Delete.','mlsimport');?></div> |
| 131 |
|
| 132 |
<label class="mlsimport-label"><?php esc_html_e( 'Select Taxonomy', 'mlsimport' ); ?></label> |
| 133 |
<select id="mlsimport_delete_category" class="mlsimport-select mlsimport-2025-select"> |
| 134 |
<option value=""><?php esc_html_e( '-- Select Taxonomy --', 'mlsimport' ); ?></option> |
| 135 |
<?php |
| 136 |
// Populate the taxonomy dropdown with the active property post type's taxonomies. |
| 137 |
$delete_taxonomies = mlsimport_get_custom_post_type_taxonomies( $mlsimport->admin->env_data->get_property_post_type() ); |
| 138 |
// One <option> per taxonomy (value = slug, label shows name + slug). |
| 139 |
foreach ( $delete_taxonomies as $tax_slug => $tax_label ) : |
| 140 |
?> |
| 141 |
<option value="<?php echo esc_attr( $tax_slug ); ?>"><?php echo esc_html( $tax_label ); ?> (<?php echo esc_html( $tax_slug ); ?>)</option> |
| 142 |
<?php endforeach; ?> |
| 143 |
</select> |
| 144 |
|
| 145 |
<label class="mlsimport-label"><?php esc_html_e( 'Select Terms', 'mlsimport' ); ?></label> |
| 146 |
<select id="mlsimport_delete_category_term" class="mlsimport-select mlsimport-2025-select" multiple disabled> |
| 147 |
<option value="" disabled><?php esc_html_e( 'Select a taxonomy first', 'mlsimport' ); ?></option> |
| 148 |
</select> |
| 149 |
<p class="mlsimport-exp"><?php esc_html_e( 'Hold Ctrl (Windows) or Command (Mac) to select multiple terms.', 'mlsimport' ); ?></p> |
| 150 |
|
| 151 |
<div id="mlsimport-delete-progress" style="display:none;"> |
| 152 |
<div class="mlsimport-delete-progress-track"> |
| 153 |
<div id="mlsimport-delete-progress-bar" style="width:0%;"></div> |
| 154 |
</div> |
| 155 |
<span id="mlsimport-delete-progress-text">0 / 0</span> |
| 156 |
</div> |
| 157 |
|
| 158 |
<input class="button mlsimport_button error_action" type="button" id="mlsimport-delete-prop" value="<?php esc_attr_e( 'Delete', 'mlsimport' ); ?>" /> |
| 159 |
<input class="button" type="button" id="mlsimport-delete-stop" value="<?php esc_attr_e( 'Stop', 'mlsimport' ); ?>" style="display:none;" /> |
| 160 |
</fieldset> |
| 161 |
<?php |
| 162 |
// Nonce for the tools form / delete AJAX actions, emitted as a hidden field below. |
| 163 |
$ajax_nonce = wp_create_nonce( "mlsimport_tool_actions" ); |
| 164 |
?> |
| 165 |
|
| 166 |
<input type="hidden" id="mlsimport_tool_actions" name="mlsimport_tool_actions" value="<?php echo esc_attr($ajax_nonce); ?>" /> |
| 167 |
|
| 168 |
<input type="hidden" name="action" value="mlsimport_form_action"> |
| 169 |
</form> |
| 170 |
|