PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.2.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.2.1
7.2.2 7.2.1 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 All 37 releases
mlsimport / admin / partials / mlsimport-administrative-options.php

mlsimport-administrative-options.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.2.1, at admin/partials/mlsimport-administrative-options.php

251 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $settings_import_value = '';
20
21 // Handle the toggle-form submit: only when the tool-actions nonce is present and valid.
22 if (isset($_POST['mlsimport_tool_actions']) &&
23 wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mlsimport_tool_actions'] ) ), 'mlsimport_tool_actions')) {
24
25 // Persist the "disable system logs" choice.
26 if ( isset( $_POST['mlsimport-disable-logs'] ) ) {
27 $disable_logs = intval( $_POST['mlsimport-disable-logs'] );
28 update_option( 'mlsimport_disable_logs', $disable_logs );
29 }
30 // Persist the "disable property history" choice.
31 if ( isset( $_POST['mlsimport-disable-history'] ) ) {
32 $disable_history = intval( $_POST['mlsimport-disable-history'] );
33 update_option( 'mlsimport-disable-history', $disable_history );
34 }
35 // Persist the WordPress-theme choice (moved here from the retired "MLS
36 // Connection" tab): merge the single key into mlsimport_admin_options so
37 // every other stored value survives untouched.
38 if ( isset( $_POST['mlsimport_admin_options']['mlsimport_theme_used'] ) ) {
39 $mlsimport_admin_options = get_option( 'mlsimport_admin_options', array() );
40 $mlsimport_admin_options = is_array( $mlsimport_admin_options ) ? $mlsimport_admin_options : array();
41 $mlsimport_admin_options['mlsimport_theme_used'] = intval( $_POST['mlsimport_admin_options']['mlsimport_theme_used'] );
42 update_option( 'mlsimport_admin_options', $mlsimport_admin_options );
43 }
44
45 if ( isset( $_POST['mlsimport-import-settings'] ) ) {
46 if ( ! current_user_can( 'manage_options' ) ) {
47 add_settings_error( 'mlsimport_settings_transfer', 'forbidden', __( 'You are not allowed to import plugin settings.', 'mlsimport' ), 'error' );
48 } else {
49 $settings_import_value = isset( $_POST['mlsimport-settings-import'] )
50 ? trim( (string) wp_unslash( $_POST['mlsimport-settings-import'] ) )
51 : '';
52 $settings_import_result = mlsimport_import_settings_json( $settings_import_value );
53 if ( $settings_import_result['success'] ) {
54 $settings_import_value = '';
55 add_settings_error( 'mlsimport_settings_transfer', 'imported', __( 'Settings imported successfully.', 'mlsimport' ), 'updated' );
56 } else {
57 add_settings_error( 'mlsimport_settings_transfer', 'invalid_json', __( 'Paste a valid JSON object exported by MLSImport.', 'mlsimport' ), 'error' );
58 }
59 }
60 }
61
62 }
63 ?>
64
65 <form method="post" name="cleanup_options" action="">
66 <?php
67 global $mlsimport;
68 // Initialise plugin/SaaS state before rendering the tools.
69 $mlsimport->admin->mlsimport_saas_setting_up();
70 //mlsimport_saas_event_mls_import_auto_function();
71 //mlsimport_saas_reconciliation_event_function();
72 ?>
73
74 <h1> <?php esc_html_e( 'Administrative Tools', 'mlsimport' ); ?></h1>
75
76 <?php settings_errors( 'mlsimport_settings_transfer' ); ?>
77
78
79 <?php
80
81
82
83 // Current "disable logs" value; pre-select the matching <option> below.
84 $disable_logs = intval( get_option( 'mlsimport_disable_logs' ) );
85 $selected_no = $selected_yes = '';
86
87 // 0 = logs disabled (default) -> select the "disabled" option; otherwise "enabled".
88 if ( 0 === intval($disable_logs) ) {
89 $selected_no = ' selected ';
90 } else {
91 $selected_yes = ' selected ';
92 }
93
94
95 // Current "disable history" value (defaults to 1); pre-select the matching option.
96 $disable_history = intval( get_option( 'mlsimport-disable-history', 1 ) );
97 $selected_history_no = $selected_history_yes = '';
98
99 // 0 = history disabled -> select the "disabled" option; otherwise "enabled".
100 if ( 0 === intval($disable_history) ) {
101 $selected_history_no = ' selected ';
102 } else {
103 $selected_history_yes = ' selected ';
104 }
105 ?>
106
107 <div class="mlsimport_tool_block">
108 <h4> <?php esc_html_e( 'Disable System Logs (logs should only be enabled during debug process)', 'mlsimport' ); ?> </h4>
109 <select name="mlsimport-disable-logs" class="mlsimport-2025-select" id="mlsimport-disable-logs">
110 <option value="0" <?php echo esc_html( $selected_no ); ?> ><?php esc_html_e( 'logs disabled', 'mlsimport' ); ?></option>
111 <option value="1" <?php echo esc_html( $selected_yes ); ?>><?php esc_html_e( 'logs enabled', 'mlsimport' ); ?></option>
112
113 </select>
114 </div>
115
116
117 <div class="mlsimport_tool_block">
118 <h4> <?php esc_html_e( 'Disable Property History (can be seen by editing a property in WordPress admin)', 'mlsimport' ); ?> </h4>
119 <select name="mlsimport-disable-history" class="mlsimport-2025-select" id="mlsimport-disable-history">
120
121 <option value="1" <?php echo esc_html( $selected_history_yes ); ?>><?php esc_html_e( 'history enabled', 'mlsimport' ); ?></option>
122 <option value="0" <?php echo esc_html( $selected_history_no ); ?> ><?php esc_html_e( 'history disabled', 'mlsimport' ); ?></option>
123
124 </select>
125 </div>
126
127
128
129 <div class="mlsimport_tool_block">
130 <h4> <?php esc_html_e( 'Your WordPress Theme (auto-detected — change only if the detection is wrong)', 'mlsimport' ); ?> </h4>
131 <?php
132 // Theme selector (moved here from the retired "MLS Connection" tab):
133 // rendered from the resolved theme id — saved answer when there is one,
134 // detected theme when there is not (#242).
135 print wp_kses(
136 mlsiport_mls_select_list( 'mlsimport_theme_used', mlsimport_resolve_theme_id(), MLSIMPORT_THEME ),
137 mlsimport_allowed_html_tags_content()
138 );
139 ?>
140 </div>
141
142
143 <?php submit_button( __( 'Save Changes', 'mlsimport' ), 'mlsimport_button button save_data', 'submit', true ); ?>
144
145 <div class="mlsimport_tool_block mlsimport_tool_card">
146 <h3> <?php esc_html_e( 'Clear cached data', 'mlsimport' ); ?> </h3>
147 <input class="button mlsimport_button" type="button" id="mlsimport-clear-cache" value="<?php esc_attr_e( 'Clear Plugin Cached Data', 'mlsimport' ); ?>" />
148 </div>
149
150 <div class="mlsimport_tool_block mlsimport_tool_card">
151 <h3> <?php esc_html_e( 'Clear fields data', 'mlsimport' ); ?> </h3>
152 <input class="button mlsimport_button" type="button" id="mlsimport-clear-fields-data" value="<?php esc_attr_e( 'Clear Field Data', 'mlsimport' ); ?>" />
153 </div>
154
155
156 <div class="mlsimport_tool_block">
157 <h3><?php esc_html_e( 'Cron Jobs', 'mlsimport' ); ?> </h3>
158 <div class="cron_job_explainin">
159 <?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' ); ?>
160
161 </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' ); ?>
162 </br></br><strong><?php esc_html_e( 'Example : 0 */2 * * * wget https://yourwebsite.com/?mlsimport_cron=yes', 'mlsimport' ); ?></strong> .
163 </div>
164 </div>
165
166 <?php
167 // The legacy cron-log partial had no route and assumed the file always existed,
168 // which turned a missing optional log into PHP warnings. Keep the useful viewer
169 // on the existing Tools surface and treat an absent log as the normal empty state.
170 $cron_log_path = MLSIMPORT_PLUGIN_PATH . 'logs/cron_logs.log';
171 $cron_log_size = is_readable( $cron_log_path ) ? (int) filesize( $cron_log_path ) : 0;
172 ?>
173 <div id="mlsimport-cron-log-viewer" class="mlsimport_tool_block mlsimport_tool_card">
174 <h3><?php esc_html_e( 'Property Update logs', 'mlsimport' ); ?></h3>
175 <?php if ( ! is_readable( $cron_log_path ) ) : ?>
176 <p><?php esc_html_e( 'No cron log entries yet.', 'mlsimport' ); ?></p>
177 <?php else : ?>
178 <p>
179 <?php
180 echo esc_html(
181 sprintf(
182 /* translators: %d: cron log file size in bytes. */
183 __( 'Cron Log File Size is %d bytes', 'mlsimport' ),
184 $cron_log_size
185 )
186 );
187 ?>
188 </p>
189 <?php if ( $cron_log_size < 3000000 ) : ?>
190 <pre class="mlsimport-cron-log-content"><?php echo esc_html( (string) file_get_contents( $cron_log_path ) ); ?></pre>
191 <?php else : ?>
192 <p><?php esc_html_e( 'The file is too large to be displayed. You can read it in mlsimport/logs/cron_logs.log.', 'mlsimport' ); ?></p>
193 <?php endif; ?>
194 <?php endif; ?>
195 </div>
196
197 <div id="mlsimport-settings-transfer" class="mlsimport_tool_block mlsimport_tool_card">
198 <h3><?php esc_html_e( 'Export or import settings', 'mlsimport' ); ?></h3>
199 <p><?php esc_html_e( 'Copy the export JSON for a backup, or paste an MLSImport export below to restore its settings.', 'mlsimport' ); ?></p>
200 <label class="mlsimport-label" for="mlsimport-settings-export"><?php esc_html_e( 'Export settings', 'mlsimport' ); ?></label>
201 <textarea id="mlsimport-settings-export" class="large-text code" rows="10" readonly><?php echo esc_textarea( wp_json_encode( mlsimport_export_settings_payload(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); ?></textarea>
202 <label class="mlsimport-label" for="mlsimport-settings-import"><?php esc_html_e( 'Import settings', 'mlsimport' ); ?></label>
203 <textarea id="mlsimport-settings-import" name="mlsimport-settings-import" class="large-text code" rows="10"><?php echo esc_textarea( $settings_import_value ); ?></textarea>
204 <button type="submit" class="button mlsimport_button" name="mlsimport-import-settings" value="1"><?php esc_html_e( 'Import Settings', 'mlsimport' ); ?></button>
205 </div>
206
207 <fieldset class="mlsimport-fieldset mlsimport_tool_block mlsimport_tool_card">
208
209 <h3><?php esc_html_e('Delete Properties','mlsimport'); ?></h3>
210
211 <div id="mlsimport-delete-notification"><?php esc_html_e('Select a taxonomy and terms, then click Delete.','mlsimport');?></div>
212
213 <label class="mlsimport-label"><?php esc_html_e( 'Select Taxonomy', 'mlsimport' ); ?></label>
214 <select id="mlsimport_delete_category" class="mlsimport-select mlsimport-2025-select">
215 <option value=""><?php esc_html_e( '-- Select Taxonomy --', 'mlsimport' ); ?></option>
216 <?php
217 // Populate the taxonomy dropdown with the active property post type's taxonomies.
218 $delete_taxonomies = mlsimport_get_custom_post_type_taxonomies( $mlsimport->admin->env_data->get_property_post_type() );
219 // One <option> per taxonomy (value = slug, label shows name + slug).
220 foreach ( $delete_taxonomies as $tax_slug => $tax_label ) :
221 ?>
222 <option value="<?php echo esc_attr( $tax_slug ); ?>"><?php echo esc_html( $tax_label ); ?> (<?php echo esc_html( $tax_slug ); ?>)</option>
223 <?php endforeach; ?>
224 </select>
225
226 <label class="mlsimport-label"><?php esc_html_e( 'Select Terms', 'mlsimport' ); ?></label>
227 <select id="mlsimport_delete_category_term" class="mlsimport-select mlsimport-2025-select" multiple disabled>
228 <option value="" disabled><?php esc_html_e( 'Select a taxonomy first', 'mlsimport' ); ?></option>
229 </select>
230 <p class="mlsimport-exp"><?php esc_html_e( 'Hold Ctrl (Windows) or Command (Mac) to select multiple terms.', 'mlsimport' ); ?></p>
231
232 <div id="mlsimport-delete-progress" style="display:none;">
233 <div class="mlsimport-delete-progress-track">
234 <div id="mlsimport-delete-progress-bar" style="width:0%;"></div>
235 </div>
236 <span id="mlsimport-delete-progress-text">0 / 0</span>
237 </div>
238
239 <input class="button mlsimport_button error_action" type="button" id="mlsimport-delete-prop" value="<?php esc_attr_e( 'Delete', 'mlsimport' ); ?>" />
240 <input class="button" type="button" id="mlsimport-delete-stop" value="<?php esc_attr_e( 'Stop', 'mlsimport' ); ?>" style="display:none;" />
241 </fieldset>
242 <?php
243 // Nonce for the tools form / delete AJAX actions, emitted as a hidden field below.
244 $ajax_nonce = wp_create_nonce( "mlsimport_tool_actions" );
245 ?>
246
247 <input type="hidden" id="mlsimport_tool_actions" name="mlsimport_tool_actions" value="<?php echo esc_attr($ajax_nonce); ?>" />
248
249 <input type="hidden" name="action" value="mlsimport_form_action">
250 </form>
251